/**
 *Submitted for verification at Etherscan.io on 2021-06-27
*/

// SPDX-License-Identifier: Free-to-use

pragma solidity 0.8.5;
 
contract MillionWall{
    address payable owner;
  
    struct advSpace{
        string base64code;
        string caption;
        string url;
        address occupiedBy;
    }
   
    mapping (uint => advSpace) pic;
    
    // setting up the prices for the advertising space. 1414 adv spaces in total
	uint8[1414] prices = [0,1,2,3,4,5,5,6,7,8,9,10,11,12,13,14,15,16,17,5,18,19,3,20,21,22,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,25,9,9,9,9,9,4,26,27,28,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,31,31,32,33,34,35,36,37,38,39,40,32,6,7,41,41,41,41,41,41,10,10,10,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,43,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,44,18,4,39,45,46,16,13,5,47,48,49,3,50,9,9,9,9,9,51,45,9,9,9,9,9,9,12,17,52,53,29,43,54,55,56,6,6,6,50,57,58,58,59,22,6,60,61,62,63,64,49,18,65,65,9,9,9,9,9,9,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,42,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,16,5,18,66,21,21,21,21,67,13,13,68,21,69,69,70,71,9,9,10,10,3,72,73,38,74,75,40,65,75,76,77,78,3,79,69,80,17,81,1,82,83,83,4,21,46,84,9,85,5,86,13,4,45,13,4,78,1,13,9,85,85,14,87,14,8,17,21,81,88,89,90,91,58,58,79,14,14,14,13,85,85,85,4,14,14,8,46,92,18,75,93,94,58,95,58,96,52,36,36,36,97,40,6,18,50,13,59,68,32,1,22,17,1,5,5,5,5,14,96,96,74,4,14,4,78,4,14,4,14,29,8,8,54,84,98,99,100,41,41,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,78,13,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,3,10];
	uint[101] prices_types = [2500000000000000000,9000000000000000000,4900000000000000000,4000000000000000000,1200000000000000000,2100000000000000000,4200000000000000000,7700000000000000000,1800000000000000000,1600000000000000000,2000000000000000000,11700000000000000000,4500000000000000000,3600000000000000000,2400000000000000000,7500000000000000000,2800000000000000000,5600000000000000000,8000000000000000000,10750000000000000000,8750000000000000000,3000000000000000000,7000000000000000000,10500000000000000000,100000000000000000,150000000000000000,7175000000000000000,15000000000000000000,5775000000000000000,5400000000000000000,400000000000000000,7225000000000000000,10200000000000000000,1575000000000000000,2625000000000000000,1225000000000000000,1750000000000000000,8075000000000000000,5100000000000000000,2200000000000000000,4600000000000000000,5000000000000000000,6000000000000000000,12000000000000000000,5800000000000000000,3200000000000000000,1000000000000000000,3150000000000000000,6650000000000000000,10000000000000000000,5200000000000000000,3500000000000000000,11500000000000000000,19200000000000000000,4950000000000000000,3850000000000000000,16000000000000000000,3900000000000000000,1050000000000000000,1500000000000000000,26000000000000000000,14000000000000000000,40000000000000000000,47700000000000000000,17000000000000000000,2600000000000000000,6900000000000000000,6400000000000000000,8100000000000000000,2250000000000000000,3300000000000000000,11000000000000000000,10800000000000000000,12600000000000000000,6800000000000000000,7200000000000000000,7800000000000000000,6600000000000000000,4800000000000000000,750000000000000000,3250000000000000000,8250000000000000000,8500000000000000000,600000000000000000,2700000000000000000,800000000000000000,11250000000000000000,1400000000000000000,3800000000000000000,4750000000000000000,4050000000000000000,1900000000000000000,7250000000000000000,9450000000000000000,5750000000000000000,1350000000000000000,8400000000000000000,9250000000000000000,1300000000000000000,2450000000000000000,4550000000000000000];
	
    constructor() payable{
        owner = payable(msg.sender);
    }
  
    function save(uint i, string memory code, string memory caption, string memory url) public payable{
        // check if space is free
        require ( (pic[i].occupiedBy == address(0) || msg.sender == pic[i].occupiedBy) && i<1414);
        
        // check if payment is enough, caption/URL length meets the limits 
        require ( (msg.value >= prices_types[prices[i]] || msg.sender == pic[i].occupiedBy) && bytes(caption).length <= 30 && bytes(url).length <= 50);
        
        // saving the picture in the blockchain
        pic[i].base64code = code;
        pic[i].caption = caption;
        pic[i].url = url;
        pic[i].occupiedBy = msg.sender;
    }
    
    function get(uint i) public view returns (string memory, uint, string memory, address, string memory){
        return (pic[i].base64code, prices_types[prices[i]], pic[i].caption, pic[i].occupiedBy, pic[i].url);
    }
    
    function payoff(uint amount) public payable {
        require(msg.sender == owner);
        owner.transfer(amount);
    }
    
}