akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root=NIL;

Node treeMinimum(Node);
Node treeMaximum(Node);
Node treeSearch(Node,int);
Node treeSuccessor(Node);
void treeDelete(Nodedf);
void insert(int);
void inorder(Node);
void preorder(Node);

int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ )
  {
    scanf("%s", com);
    if ( com[0] == 'f' )
    {
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' )
    {
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' )
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' )
    {
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Node treeMinimum(Node x)
{
  if(x->left == NIL) return x;
  else treeMinimum(x->left);
}

Node treeMaximum(Node x)
{
  if(x->right == NIL) return x;
  else treeMaximum(x->right);
}

Node treeSearch(Node u, int k)
{
  if(u == NIL || k == u->key) return u;
  else if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x)
{
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x->key == y->right->key){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z)
{
  Node y; 
  Node x; 
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left!=NIL) x = y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;
}

void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL)
  {
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right;
    
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u)
{
  if(u!=NIL)
  {
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u)
{
  if(u==NIL) return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


Measured memory_bytes: 20556
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
int n,m,ans[100010];
std::vector<int> vec[100010];
bool used[100010];
int main(){
	std::cin>>n>>m;
	rep(i,m){
		int a,b;
		std::cin>>a>>b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	std::queue<int> que;
	que.push(1);
	used[1]=true;
	while(!que.empty()){
		int node=que.front();
		que.pop();
		for(int i:vec[node]){
			if(!used[i]){
				ans[i]=node;
				used[i]=true;
				que.push(i);
			}
		}
	}
	puts("Yes");
	for(int i=2;i<=n;i++){
		std::cout<<ans[i]<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 10648
//pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
#define AC 0
#define mod 1000000007
vector< vector<int> > dp, g;
void dfs(int u, int p) {
	for(int i=0;i<g[u].size();i++)
		if (g[u][i] != p) {
			dfs(g[u][i], u);
			dp[u][0] = 1ll * dp[u][0] * (dp[g[u][i]][0] + dp[g[u][i]][1]) % mod % mod;
			dp[u][1] = 1ll * dp[u][1] * dp[g[u][i]][0] % mod;
		}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	dp.resize(n, vector<int>(2, 1));
	g.resize(n);
	for (int x, y; --n > 0;) {
		cin >> x >> y;
		g[x - 1].push_back(y - 1);
		g[y - 1].push_back(x - 1);
	}
	dfs(0, -1);
	cout << (dp[0][0] + dp[0][1]) % mod << '\n';
	return AC;
}

Measured memory_bytes: 21072
#include<bits/stdc++.h>
#define ll long long
#define fs first
#define sec second
#define md 1000000007
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
using namespace std;
ll power(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p  
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T=1;
    // cin>>T;
    while(T--){
    	ll d,t,s;
        cin>>d>>t>>s;
        if(t*s>=d){
            cout<<"Yes";
        }
        else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;

int i, n, x, y, grad[100005], m;

int main() {
  ios_base::sync_with_stdio(0);

  for(cin >> n >> m; m; --m) {
    cin >> x >> y;
    ++grad[x]; ++grad[y];
  }

  for(i = 1; i <= n; ++i) if(grad[i] & 1) return cout << "NO\n", 0;

  cout << "YES\n";

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        a[i]--;
    }
    vector<bool> was(n, false);
    long long cycle = 1, now = 0;
    vector<long long> path;
    while(!was[now]){
        was[now] = true;
        now = a[now];
        k--;
        if(!k){
            cout << now + 1;
            return 0;
        }
    }
    long long st = now;
    path.push_back(st);
    now = a[now];
    while(now != st){
        path.push_back(now);
        cycle++;
        now = a[now];
    }
    k %= cycle;
    cout << path[k] + 1;
}

Measured memory_bytes: 5904
import java.io.BufferedReader;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.IOException;


public class Main{
   public static void main(String[] args) {
      Scanner kb = new Scanner(System.in);
      out = new PrintWriter(new BufferedOutputStream(System.out));
      
      int height[] = new int[10];
      for(int i = 0 ; i < 10 ; i++){
    	  height[i] = kb.nextInt();
      }
      
      Arrays.sort(height);
      
      System.out.println(height[9]);
      System.out.println(height[8]);
      System.out.println(height[7]);

   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;
      
   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
   try {
      str = br.readLine();
   } catch (IOException e) {
      e.printStackTrace();
   }
   return str;
      }

   }
   //--------------------------------------------------------
}

Measured memory_bytes: 26168
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<61;
int iinf=1<<30;
double pi=3.14159265358979323846;
double pi2=pi/2.0;
double eps=1e-8;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,0,-1,0};
int dw[4]={0,1,0,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<0)a=-a;
    if(b<0)b=-b;
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    string s;cin>>s;
    int r=0;
    rep(i,0,n){
        if(s[i]=='R')r++;
    }
    int ans=r;
    rep(i,0,r)if(s[i]=='R')ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 3776
<?php
$first = true;
while ($line = trim(fgets(STDIN))) {
  list($a, $b) = explode(' ', $line);
  if ($a == 0 && $b == 0) {
    break;
  }
  if ($first) {
    $first = false;
  } else {
    echo "\n";
  }
  $na = true;
  for ($y = $a; $y <= $b; ++$y) {
    $uruu = false;
    if ($y % 4 == 0) {
      $uruu = true;
      if ($y % 100 == 0) {
        $uruu = false;
      }
      if ($y % 400 == 0) {
        $uruu = true;
      }
    }
    if ($uruu) {
      $na = false;
      echo "$y\n";
    }
  }
  if ($na) {
    echo "NA\n";
  }
}

Measured memory_bytes: 15176
#include<bits/stdc++.h>
using namespace std;
#include<math.h>
#define ll long long
#define ld long double
#define all(a) (a.begin(),a.end())
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e15 + 1;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1 ;
  //cin>>t ;
  while(t--)
  {
    ll n;
    cin>>n;
    vector<ll> a(n);
    map<ll,ll> mp ;
    ll sum =  0;
    for( ll i = 0 ; i<n ; i++ )
    {
        cin>>a[i];
        sum+=a[i];
        mp[a[i]]++;
    }
    ll q;
    cin>>q;
    vector<pair<ll,ll> > b(q);
    for( ll i = 0 ; i<q ; i++ )
    {
        cin>>b[i].first>>b[i].second ;

    }
    for( ll i = 0 ; i<q ; i++ )
    {
        ll x = mp[b[i].first] ;
        ll y = b[i].second - b[i].first ;
        sum += x*y ;
        cout<<sum<<endl;
        mp[b[i].first] = 0 ;
        mp[b[i].second] += x ;
    }


  }
  return 0;

}


Measured memory_bytes: 11672
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
a = []
a.append(10-(A % 10))
a.append(10-(B % 10))
a.append(10-(C % 10))
a.append(10-(D % 10))
a.append(10-(E % 10))
b = [0]
for i in range(5):
    if a[i] != 10:
        b.append(a[i])
c = A+B+C+D+E+sum(b)-max(b)
print(c)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<string.h>
#include<stdlib.h>
#include<cstdio>
#define ll long long
using namespace std;
ll x[1000001];
ll C(ll m,ll n){
	ll i,j,sum=1;
	for (i=m,j=0;j<n;j++,i--)
		sum=sum*i/(j+1);
	return sum;
}
int main(){
	ll t,n,m;
//	scanf("%lld",&t);
////	while(t--){
		scanf("%lld%lld",&n,&m);
		x[0]=0;
		ll cnt=0;
		ll w;
		for(ll i=1;i<=n;++i){
			cin>>w;
			x[i]=((x[i-1]+w)%m+m)%m; //因为w有可能是负的 
		}
		sort(x,x+n+1);
		ll s=1;
		for(ll i=1;i<=n;++i){
			if(x[i]==x[i-1])
				s++;
			else{
				cnt+=C(s,2);
			    s=1;
			}
		}
		cnt+=C(s,2);
		printf("%lld\n",cnt);
//	}
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;
 
const int Nmax = 501;
int N;
int C[Nmax], S[Nmax], F[Nmax];
 
int main() {
	cin >> N;
	for (int i = 1; i < N; i++) {
		cin >> C[i] >> S[i] >> F[i];
	}
 
	for (int i = 1; i <= N; i++) {
		int t = 0;
		for (int j = i; j < N; j++) {
			int t_dep = S[j];
			while (t_dep < t) {
				t_dep += F[j];
			}
			t = t_dep + C[j];
		}
		cout << t << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
using usize = std::size_t;
template<typename T>
using Vector = std::vector<T>;
using String = std::string;
template<typename T>
using UniquePointer = std::unique_ptr<T>;
using namespace std;

#define rep(i, max) for(usize i = 0; i < max; ++i)
#define loop while(true)

UniquePointer<String> readLine() {
    UniquePointer<String> line(new String());
    getline(cin, *line);
    return line;
}

template<typename T>
UniquePointer<Vector<T>> readVector(usize num) {
    UniquePointer<Vector<T>> list(new Vector<T>(num));
    rep(i, num) {
        cin >> (*list)[i];
    }
    readLine();
    return list;
}


template<typename T>
void writeLine(T arg) {
    cout << arg << endl;
}

template<typename T>
void write(T arg) {
    cout << arg << std::flush;
}

void program();

int main()
{
    ios::sync_with_stdio(false);
    program();
}

void program() {
    i32 n = stoi(*readLine());
    auto a = *readVector<i32>(n);
    i64 sum = 0;
    i32 oldHeight = 0;
    rep(i, n){
        if(a[i] < oldHeight){
            sum += oldHeight - a[i];
        }else{
            oldHeight = a[i];
        }
    }
    writeLine(sum);
}

Measured memory_bytes: 4856
def solve():
    global S, N
    N = int(input())

    S = []
    for n in range(N):
        S.append(list(input()))


    res = 0
    for n in range(N):
        if check(n):
            res += N

    print(res)

def check(move):
    for i in range(N):
        for j in range(i+1, N):
            if S[(i-move)%N][j] != S[(j-move)%N][i]:
                return False
    return True


if __name__ == "__main__":
    solve()

Measured memory_bytes: 44664
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    int f[n+1];
    f[1]=0;
    f[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
        f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
    }
    cout << f[n];
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <cmath>
#include <float.h>
using namespace std; 

int main(void){
  	long double PI=3.1415926535897932;
  	long double A,B,H,M;
  	scanf("%llf%llf%llf%llf",&A,&B,&H,&M);
  	long double XA,YA,XB,YB;
  	
  	long double Arad = PI*5/2-H*2*M_PI/12-M*2*M_PI/720;
  	long double Brad = PI*5/2-M*2*M_PI/60;
  	long double eps = 100;
  	XA = A*cos(Arad);
  	YA = A*sin(Arad);
  	XB = B*cos(Brad);
  	YB = B*sin(Brad);
	long double x_dis = XA-XB;
	long double y_dis = YA-YB; 
  	long double xhoge = x_dis*x_dis;
  	long double yhoge = y_dis*y_dis;

      	printf("%20.20llf",sqrt(xhoge+yhoge));
  	
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,p;cin >> n >> p;
	if(n==1){
		cout << p << endl;
		return 0;
	}
	vector<int> prime(1000000);
	for(ll i=2;i*i<=p;++i){
		while(p%i==0){
			prime.at(i)++;
			p/=i;
		}
	}
	ll ans=1;
	rep(i,1000000){
		if(prime.at(i)>=n){
			ans*=(ll)pow(i,(prime.at(i)/n));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4224
#include <iostream>
using namespace std;

int main()
{
	int n, debt = 100000;
	double risi = 1.05;

	cin >> n;
	for(int i = 0; i < n; i++){
		// ???????????????
		debt *= risi;
		//cout << debt << endl;

		// 1000?????????????????????
		if(debt % 1000 > 0)
			debt += 1000 - (debt % 1000);
	}
	cout << debt << endl;

	return 0;
}

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const int N = 505;
int n;
char arr[N][N];
bool ok;
int main(){
    scanf("%d" , &n);
    ok = 0;
    for(int i = 1 ; i <= n ; ++i){
        scanf("%s" , arr[i] + 1);
        for(int j = 1 ; j <= n ; ++j){
            if(arr[i][j] == '#'){
                ok = 1;
            }
        }
    }
    if(!ok){
        printf("-1\n");
        return 0;
    }
    int mn = n + 1;
    for(int i = 1 ; i <= n ; ++i){
        int cnt = 0;
        for(int j = 1 ; j <= n ; ++j){
            if(arr[i][j] == '.'){
                ++cnt;
            }
        }
        bool ok = 0;
        for(int j = 1 ; j <= n ; ++j){
            if(arr[j][i] == '#'){
                ok = 1;
            }
        }
        if(ok){
            mn = min(mn , cnt);
        }
        else{
            mn = min(mn , cnt + 1);
        }
    }
    for(int j = 1 ; j <= n ; ++j){
        for(int i = 1 ; i <= n ; ++i){
            if(arr[i][j] == '.'){
                ++mn;
                break;
            }
        }
    }
    printf("%d\n" , mn);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if((a+b)%2==0){
		cout<<(a+b)/2<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll n, k, x;
    scl(n);
    scl(k);
    vector<ll> v;
    v.push_back(0);
    for (int i = 1; i <= n; i++)
    {
        scl(x);

        v.push_back(x);
    }

    ll i = k + 1;
    ll y, tmp = 1, z, w;
    while (i <= n)
    {
        if (v[i] > v[tmp])
        {
            puts("Yes");
        }
        else
        {
            puts("No");
        }
        tmp++;
        i++;
    }

    return 0;
}

Measured memory_bytes: 5368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

const int N = 2e5 + 10;

V<V<int>> tree(N);
V<ll> c(N);
V<ll> ans(N);

void dfs(int i, int src) {
  ans[i] += c[i];
  for (auto n : tree[i]) {
    if (n == src) continue;
    ans[n] += ans[i];
    dfs(n, i);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  V<int> a(n), b(n);

  rep(i, n - 1) cin >> a[i] >> b[i];

  V<int> pa(n + 1);
  rep(i, n - 1) {
    tree[a[i]].push_back(b[i]);
    tree[b[i]].push_back(a[i]);
  }

  rep(i, q) {
    int p, x;
    cin >> p >> x;
    c[p] += x;
  }

  dfs(1, -1);

  for (int i = 1; i <= n; i++) printf("%ld ", ans[i]);
  printf("\n");
}


Measured memory_bytes: 29048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    int n,m,k;
    cin>>n>>m>>k;
    
    int ans = 0;
    
    rep(i,n+1)rep(j,m+1){
        ans = i*j + (n-i)*(m-j);
        if(ans==k){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
  std::string S;
  std::cin >> S;
  if (S == "Sunny") std::cout << "Cloudy" << std::endl;
  else if (S == "Cloudy") std::cout << "Rainy" << std::endl;
  else std::cout << "Sunny" << std::endl;
  return 0;
}

Measured memory_bytes: 3468
#include<bits/stdc++.h>
#define ll long long int 
#define RD(v,n) for(ll i =0;i<n;i++ ) cin>>v[i]
#define bolt ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
	bolt;
	ll n;
	cin>>n;
    string s,t;
    cin>>s>>t;
    string ans = "";
    for( ll i=0;i<n;i++ ){
        ans += s[i];
        ans += t[i];
    }
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll N=505;
bool Q;
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const {
        return Q ? p < o.p : k < o.k;
    }
};
struct LineContainer : multiset<Line> {
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b){
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        Q = 1; auto l = *lower_bound({0,0,x}); Q = 0;
        return l.k * x + l.m;
    }
};
void solve(){
	ll n, k;
	cin>>n>>k;
	vector<ll> h(n+1), dp(n+1);
	rep(i,1,n+1)cin>>h[i];
	LineContainer CHT;
	rep(i,1,n+1){
		if(i==1)dp[i]=0;
		else
			dp[i]=-CHT.query(h[i])+h[i]*h[i];
		ll m=-2*h[i], c=dp[i]+h[i]*h[i]+k;
		CHT.add(-m,-c);
	}
	cout<<dp[n];
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 15872
import java.util.*;
 
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
         
        int[][] Nissu = new int[1001][11];
         
        for(int i=1;i<=1000;i++){
            if((i%3)==0){
                for(int j=1;j<=10;j++){
                    Nissu[i][j]=20;
                }
            }else{
                for(int j=1;j<=10;j++){
                    if((j%2)==0){
                        Nissu[i][j]=19;
                    }else{
                        Nissu[i][j]=20;
                    }
                }
            }
        }
        
        int n=sc.nextInt();
        for(int i=0;i<n;i++){
            int Y = sc.nextInt();
            int M = sc.nextInt();
            int D = sc.nextInt();
            int count = 1;
             
            for(int j=999;j>Y;j--){
                for(int k=1;k<=10;k++){
                    count += Nissu[j][k];
                }
            }
             
            for(int j=10;j>M;j--){
                count += Nissu[Y][j];
            }
             
            if((Y%3)==0){
                count += (20-D);
            }else if((Y%3)!=0){
                if((M%2)==0){
                    count += (19-D);
                }else{
                    count += (20-D);
                }
            }
            System.out.println(count);
        }
         
    }
} 

Measured memory_bytes: 21540
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll x;
  x = min(a,min(b,min(c,min(d,e))));
  cout << ((n+x-1)/x)+4;
 return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j]


def nC2(n):
    return n * (n - 1) // 2


N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))

unconv = nC2(N)
revans = []
uf = UnionFind(N + 1)

for a, b in reversed(AB):
    revans.append(unconv)
    if uf.connected(a, b):
        continue
    unconv += nC2(uf.groupsize(a))
    unconv += nC2(uf.groupsize(b))
    uf.unite(a, b)
    unconv -= nC2(uf.groupsize(a))

for v in reversed(revans):
    print(v)


Measured memory_bytes: 125656
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

struct edge {
  int to, cap, rev, id;
  edge(int to, int cap, int rev, int id) : to(to), cap(cap), rev(rev), id(id) {}
};
vector<vector<edge>> G;
vector<bool> used;
void add_edge(int from, int to, int cap, int id) {
  G[from].pb(edge(to, cap, G[to].size(), id));
  G[to].pb(edge(from, cap, G[from].size() - 1, -1 - id));
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    for (int i = 0; i < used.size(); i++) used[i] = false;
    int f = dfs(s, t, INF);
    if (f == 0) return flow;
    flow += f;
  }
}

void solve() {
  int N, M;
  cin >> N >> M;
  G.resize(N);
  for (int i = 0; i < N; i++) G[i].clear();
  used.assign(N, false);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    add_edge(a, b, 1, i);
  }
  int S, T;
  cin >> S >> T;
  S--;
  T--;
  int f = max_flow(S, T);
  vector<int> ans;
  for (int i = 0; i < N; i++) {
    for (const edge &e : G[i]) {
      if (e.cap == 0 && e.id < 0) { ans.push_back(-e.id - 1); }
    }
  }
  cout << f << endl;
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) { cout << ans[i] + 1 << endl; }
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}



Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int n;
	cin >> n;
	int a[2][n];
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> a[i][j];
		}
		
	}
	int res=0;
	for (int i = 0; i < n; i++)
	{
		int cnt=0;
		for (int j = 0; j <= i; j++)
		{
			cnt+=a[0][j];
		}
		for (int j = i; j < n; j++)
		{
			cnt+=a[1][j];
		}
		res = max(res, cnt);
	}
	cout << res << endl;
	
	
}

Measured memory_bytes: 764
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long n;
long a[200005];
long sum[200005];

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		scanf("%ld", &a[i]);
	}
	sum[0] = a[0];
	for(int i = 1; i < n; i++){
		sum[i] = sum[i-1] + a[i];
	}
	sum[n] = 0;
	std::sort(sum, sum+n+1);
	sum[n+1] = LINF;
	/*
	for(int i = 0; i <= n+1; i++){
		printf("%ld ", sum[i]);
	}
	printf("\n");
	//*/
	long ans = 0;
	long cnt = 1;
	for(int i = 1; i <= n+1; i++){
		if(sum[i] == sum[i-1]){
			cnt++;
		}else{
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);  

    ll x;
    cin >> x;
    ll tmp = 100;
    ll cnt=0;
    while(true){
        if(x<=tmp){break;}
        cnt++;
        tmp *= 1.01;
        //cout << tmp << endl;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define count_one(a) __builtin_popcount(a)  // Returns the number of set bits(1) in a number(a). In long long use __builtin_popcountll(a)
#define parity(i)   __builtin_parity(i)  //even parity 0 and odd parity 1
#define blz(a)   __builtin_clz(a) //Returns the number of leading zeroes in a number(a)
#define btz(a)   __builtin_ctz(a) //Returns the number of trailing zeroes in a number(a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
     IOS
     int a,b,c;
     cin>>a>>b>>c;
     cout<<c<<" "<<a<<" "<<b<<endl;
     return 0;
}


Measured memory_bytes: 256
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        long ans = 0;

        long[,] cnt = new long[10, 10];

        for (int i = 1; i <= n; i++)
        {
            var s = i.ToString();
            int f = s[0] - '0';
            int l = s[s.Length - 1] - '0';
            cnt[f, l]++;
        }
        
        for (int i = 1; i <= n; i++)
        {
            var s = i.ToString();
            int f = s[0] - '0';
            int l = s[s.Length - 1] - '0';
            if (f != 0 && l != 0)
            {
                ans += cnt[l, f];
            }
        }


        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 15304
import Data.List
import Control.Monad

type Matrix = [[Int]]

(|*|) :: Matrix -> Matrix -> Matrix
ma |*| mb = [[sum $ zipWith (*) mai mbti | mbti <- mbt] | mai <- ma]
  where mbt = transpose mb

getList :: Read a => IO [a]
getList = fmap (map read . words) getLine

main = do
  [n, m, l] <- getList
  mat1 <- replicateM n getList
  mat2 <- replicateM m getList
  mapM_ putStrLn $ map (unwords . map show) $ mat1 |*| mat2

Measured memory_bytes: 12116
bills = [
    [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    ],
    [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    ],
    [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    ],
    [
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    ],

]


def resolve():
    n = int(input())
    for _ in range(n):
        b, f, r, v = map(int, input().split())
        bills[b - 1][f - 1][r - 1] += v

    count = 0
    for bill in bills:
        count += 1
        for floor in bill:
            [print(" {}".format(r), end='') for r in floor]
            print('')
        if count < len(bills):
            print('####################')


resolve()


Measured memory_bytes: 5640
N, M = map(int, input().split())
d = {}
p = {}
INF = 9999999
for i in range(1, N + 1):
  for j in range(1, N + 1):
    if i == j:
      continue
    d[i, j] = INF
    p[i, j] = []
e = set([])
for i in range(M):
  a, b, c = map(int, input().split())
  e.add((a, b))
  d[a, b] = c
  d[b, a] = c
  p[a, b] = [a, b]
  p[b, a] = [b, a]
for k in range(1, N + 1):
  for i in range(1, N + 1):
    if i == k:
      continue
    for j in range(1, N + 1):
      if i == j or j == k:
        continue
      if d[i, j] > d[i, k] + d[k, j]:
        d[i, j] = d[i, k] + d[k, j]
        p[i, j] = p[i, k] + p[k, j][1:]
for i in range(1, N + 1):
  for j in range(1, N + 1):
    if i == j:
      continue
    q = p[i, j]
    for k in range(len(q) - 1):
      r = q[k], q[k + 1]
      s = q[k + 1], q[k]
      if r in e:
        e.remove(r)
      if s in e:
        e.remove(s)
print(len(e))

Measured memory_bytes: 8680
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
#sys.setrecursionlimit(3**12)


class TRAMP:
    def __init__(self,arg_mark,arg_number,arg_input_index):
        self.mark = arg_mark
        self.number = arg_number
        self.input_index = arg_input_index

N = int(input())
table = []
for input_index in range(N):
    mark,number = map(str,input().split())
    table.append(TRAMP(mark,int(number),input_index))

def Partition(left,right):
    global table
    i = left-1
    pivot = table[right].number
    for start in range(left,right):
        if table[start].number <= pivot:
            i += 1
            table[i],table[start] = table[start],table[i]
    table[i+1],table[right] = table[right],table[i+1]
    return i+1

def quickSort(left,right):
        if left < right:
            q = Partition(left,right)
            quickSort(left,q-1)
            quickSort(q+1,right)

quickSort(0, N-1)
stable_FLG = True

for i in range(1,N):
    if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:
        stable_FLG = False
        break

if stable_FLG:
    print("Stable")
else:
    print("Not stable")

for i in range(N):
    print("%s %d"%(table[i].mark,table[i].number))



Measured memory_bytes: 30296
#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long l, r; cin >> l >> r;

	if (r - l >= 2018) {
		cout << 0 << endl;
		return 0;
	}

	l = l % 2019;
	r = r % 2019;

	int ans = 3000;
	for (int i = l; i <= r -1; i++) {

		for (int j = i + 1; j <= r; j++) {

			ans = min(ans, ( i * j ) % 2019 );

		}

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int now = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] == now+1) now++;
  }
  if(now == 0) cout << -1 << endl;
  else cout << N-now << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ld,ld>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
    map<ll,ll> kosu; //A[i],個数
    rep(i,N){
        kosu[A[i]]++;
    }
    deque<P> dq;
    for(auto x: kosu){
        dq.emplace_back(x.first,x.second);
    }
    vector<ll> check;
    vector<ll> checki;
    ll maxs=0;
    check.emplace_back(0);
    checki.emplace_back(0);
    rep(i,N){
        if(maxi(maxs,A[i])) {
            check.emplace_back(A[i]);
            checki.emplace_back(i+1);
        }
    }
    ll num=0;
    ll ans[N]={};
    //cout<<check.size()<<" "<< 0 <<" "<< 0 <<endl;
    repr(i,check.size()-1,1){
        ll buf=0;
        buf+=num*(check[i]-check[i-1]);
        while(!dq.empty() and check[i-1]<dq.back().first){
            num+=dq.back().second;
            buf+=dq.back().second*(dq.back().first-check[i-1]);
            dq.pop_back();
        }
        //cout<<check[i]<<" "<< i <<" "<< buf <<endl;
        ans[checki[i]-1]=buf;
    }
    rep(i,N){
        cout<< ans[i] <<"\n";
    }
    

}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 13080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  vector<long> monsters;
  for(auto index=0;index<n;++index){
    long monster;
    cin>>monster;
    monsters.push_back(monster);
  }
  sort(monsters.begin(),monsters.end());
  for(auto index=0;index<k;++index)
  {
    if(monsters.size()) {
      monsters.pop_back();
    }
  }
  unsigned long long result{0};
  for_each(cbegin(monsters),cend(monsters),[&](int monster)
  {
    result+=monster;
  });
  cout<<result<<endl;
  return 0;
}


Measured memory_bytes: 2420
#include<iostream>
using namespace std;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n,W;
    cin>>n>>W;

    int v[n], w[n];
    for(int i=0; i<n; i++) {
        cin>>w[i]>>v[i];
    }

    long dp[n+1][W+1];

    for(int i=0;i<W+1;i++) {
        dp[0][i] = 0;
    }

    for(int i=0; i<n+1; i++) {
        dp[i][0] = 0;
    }

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=W; j++) {
            

            if(w[i-1] > j) {
                dp[i][j] = dp[i-1][j];
            }

            else {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]]+v[i-1]); 
            }

        }
    }

   cout<<dp[n][W];

    
}

Measured memory_bytes: 82312
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(n - 2):
        tmp = p[i: i + 3]
        tmp.sort()
        if tmp[1] == p[i + 1]:
            ans += 1

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int INF=1e9;

int ans, N;
int A[3];
vector<int> l(10);
int sep[10];
void dfs(int size){
	if(size==N){
		int res=0;
		int sum[4]={0}, num[4]={0};
		rep(i,N){
			sum[sep[i]]+=l[i];
			num[sep[i]]++;
		}
		rep(i,3) if(num[i]==0) return;
		rep(i,3){
			res+=abs(A[i]-sum[i]);
			res+=10*(num[i]-1);
		}
		ans=min(ans,res);
		return;
	}
	rep(i,4){
		sep[size]=i;
		dfs(size+1);
	}
}

int main(){
	cin >> N;
	rep(i,3) cin >> A[i];
	rep(i,N) cin >> l[i];
	ans=INF;
	rep(i,N) sep[i]=0;
	dfs(0);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256