akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
inline int dsum(int sum[][2005],int x1,int y1,int x2,int y2){
	return sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
}
int a[2005][2005],sum[2005][2005],sumr[2005][2005],sumc[2005][2005];
int main(){
	int n,m,q;
	scanf("%d%d%d",&n,&m,&q);
	char ch;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			cin>>ch;
			a[i][j]=ch-'0';
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+a[i][j];
			sumr[i][j]=sumr[i-1][j]+sumr[i][j-1]-sumr[i-1][j-1]+(a[i][j]&&a[i-1][j]);
			sumc[i][j]=sumc[i-1][j]+sumc[i][j-1]-sumc[i-1][j-1]+(a[i][j]&&a[i][j-1]);
		}
	int x1,x2,y1,y2,ans;
	while(q--){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		ans=dsum(sum,x1,y1,x2,y2);
		ans-=dsum(sumr,x1+1,y1,x2,y2);
		ans-=dsum(sumc,x1,y1+1,x2,y2);
		printf("%d\n",ans);
	}
	return 0;
} 

Measured memory_bytes: 64640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
 


int main() {
    ios_base::sync_with_stdio(false);
 
    string t;
    cin >> t;
    rep(i,t.size()) {
        if (t[i]=='?') t[i]='D';
    } 
    cout << t << endl;

 
    return 0;   
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    for (ll i=1; i<=N; i++) {
        if (i%3 == 0 || i%5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef double db;

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, MOD = 1e9 + 7, N = 1e5 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);

void test() {
    int n; cin >> n;
    map<int, int> mp;
    ll sum = 0;
    while (n--) {
        int k; cin >> k;
        sum += k;
        ++mp[k];
    }
    int q; cin >> q;
    while (q--) {
        int b, c; cin >> b >> c;
        int l = mp[b], m = mp[c];
        mp[b] = 0, mp[c] += l;
        sum += l * (c - b);
        cout << sum << "\n";
    }
}

int main() {
      fast_io();
      #ifdef HOME
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
      #endif
      cout << fixed << setprecision(15);
      int t = 1;
      // cin >> t;
      for (int i = 1; i <= t; ++i) {
          test();
      }
      #ifdef HOME
          cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
      #endif
      return 0;
}


Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
int n , a , b;
typedef long long ll;
int main()
{
	cin >> n >> a >> b;ll ans = 0;
	for(int i = 1 ; i <= n ; ++i)
	{
		int m = i , tp = 0;
		while(m)
		{
			tp += m % 10;
			m /= 10;
		}
		if(tp <= b && tp >= a) ans += i * 1ll;
	}
	printf("%lld\n" , ans);
}


Measured memory_bytes: 256
// Problem : A - Not
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int x; cin >> x;
	cout << 1 - x;
	return 0;
}
 


Measured memory_bytes: 3608
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
A,B,m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)

ans = INF
m.times do
  x,y,c = gets.chomp.split.map(&:to_i)
  yen = a[x-1] + b[y-1] - c
  ans = yen if ans > yen
end

yen = a.min + b.min
ans = yen if ans > yen

puts ans


Measured memory_bytes: 20620
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;


int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0; i <n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(ll i=0; i<n; i++){
		if(a[i]==a[i+1]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	Main m = new Main();
	m.answer();
    }

    private Scanner scan = new Scanner(System.in);
    private final int N;
    private final int T;
    private final int[] end;
    private final int[] start;

    public Main() {
	N = Integer.parseInt(scan.next());
	T = Integer.parseInt(scan.next());
	end = new int[N];
	start = new int[N];
	
	for (int i = 0; i < N; i++) {
	    int t = Integer.parseInt(scan.next());
	    start[i] = t;
	    end[i] = start[i] + T;
	}

	scan.close();
    }

    public final void answer() {
	int ans = end[N-1];
	int blank = 0;
	for (int i = 1; i < N; i++) {
	    int tmp = start[i] - end[i-1];
	    if(tmp > 0) blank += tmp;
	}
	ans -= blank;
	System.out.println(ans);
    }
}


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


void solve(long long N){
    vector<long long> bases;
    vector<long long> dp(N+1,LLONG_MAX);

    bases.push_back(1);
    long long tmp=6l;
    while(tmp<=N){
        bases.push_back(tmp);
        tmp*=6;
    }
    tmp=9;
    while(tmp<=N){
        bases.push_back(tmp);
        tmp*=9;
    }

    dp[0] = 0l;
    for(auto i=0; i<=N; i++){
        for(auto base: bases){
            if(i+base <= N)
                dp[i+base] = min(dp[i+base], dp[i]+1);
        }
    }
    
    cout << dp[N] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	int a,b;
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		int c=a+b;
		if(a+b>=24)System.out.println(c-24);
		else System.out.println(c);
	}
}

Measured memory_bytes: 22868
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
////////////////////////////////
 
#define int long long

const int mod = 1e9 + 7;

void multiply(vector<vector<int>> &a , vector<vector<int>> &b){
	int m = a.size();
    vector<vector<int>> res(m , vector<int>(m , 0));
    for(int i = 0 ; i < m ; ++i){

        for(int j = 0 ; j < m ; ++j){

            for(int k = 0 ; k < m ; ++k){

                res[i][j] += a[i][k]*b[k][j];
                res[i][j]%=mod;
            }
        }
    }
    a = res;
}
// Matrix Exponiantiation ..
vector<vector<int>> power(vector<vector<int>> &a , int n){

	int m = a.size();
    vector<vector<int>> res(m , vector<int> (m , 0));
    for(int i = 0 ; i < m ; ++i)
        res[i][i] = 1;
    while(n){

        if(n&1)
            multiply(res , a);
        multiply(a , a);

        n/=2;
    }

    return res;
}

void solve(){

	int n , k;
	cin>>n>>k;

	vector<vector<int>> a(n , vector<int>(n , 0));

	for(int i = 0 ; i < n ; ++i)
		for(int j = 0 ; j < n ; ++j)
			cin>>a[i][j];

	a = power(a , k);

	int ans = 0;
	for(int i = 0 ; i < n ; ++i){

		for(int j = 0 ; j < n ; ++j){

			ans += a[i][j];
		}
	}

	ans%=mod;

	cout<<ans<<endl;
}
 
signed main(){
 
    fast;
    int t = 1;
    //cin>>t;
    while(t--)
        solve();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int a;
  cin>>a;
  cout<<3*a*a<<endl;
 
}

Measured memory_bytes: 256
import numpy as np
# your code goes here
def main():
	buf = input().split()
	n = int(buf[0])
	m = int(buf[1])
	
	py = np.zeros((m, 4), dtype="int")#num, p, year, num in p
	for i in range(m):
		py[i][0] = i+1#################
		buf = input().split()
		py[i][1] = int(buf[0])
		py[i][2] = int(buf[1])
		
	py = np.array(sorted(py, key=lambda x:(x[1],x[2])))
	bufp = 0
	for i in range(m):
		if(py[i][1] != bufp):
			bufp = py[i][1]
			py[i][3] = 1#1-origin
		else:
			py[i][3] = py[i-1][3]+1
	#py = np.sort(py, axis=0)
	py = py[np.argsort(py[:, 0])]
	
#	print(py)
	for i in range(m):
		ans = "{0:06d}".format(py[i][1])+"{0:06d}".format(py[i][3])
		print(ans)
	
main()

Measured memory_bytes: 42716
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();
        for(int i = 0;i<s.length;i++){
            if(i % 2 == 0){
                if(s[i] == 'R' ||
                s[i] == 'U' ||
                s[i] == 'D' ){
                    continue;
                }else{
                    System.out.println("No");
                    return;
                }
            }else{
                if(s[i] == 'L' ||
                s[i] == 'U' ||
                s[i] == 'D' ){
                    continue;
                }else{
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23508
/*
input:
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
output:
YES
NO
*/

#include <cstdio>

//&#36755;入
int a[10];

//深度&#20248;先放第K个球
bool dfs(int k, int B, int C){
	//若10个球都放完
	if(k == 10) return true;
	if(a[k] > B){
		//能放&#36827;B道
		if(dfs(k + 1, a[k], C))
			return true;
	}
	if(a[k] > C){
		//能放&#36827;C道
		if(dfs(k + 1, B, a[k]))
			return true;
	}
	//都不能放
	return false;
}

void solve(){
	if(dfs(0, 0, 0))
		printf("YES\n");
	else
		printf("NO\n");
}

int main(int argc, char const *argv[]){

	int t;
	scanf("%d", &t);
	while(t --){
		for(int i = 0; i < 10; i ++)
			scanf("%d", &a[i]);
		solve();
	}

	return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <string>
#include <vector>
#include <queue>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int H, W;

void move(int y, int x, int c, vector<vector<int>> &S, std::queue<std::pair<std::pair<int, int>, int>> &q)
{
  if (x >= 0 && x < W && y >= 0 && y < H)
  {
    if (S[y][x] == -1 || S[y][x] > c)
    {
      S[y][x] = c;
      q.push(std::make_pair(std::make_pair(y, x), c));
    }
  }
}

int main()
{
  cin >> H >> W;
  int sy, sx;
  cin >> sy >> sx;
  int gy, gx;
  cin >> gy >> gx;

  vector<vector<int>> S(H);
  rep(i, H)
  {
    S[i].resize(W);
    rep(j, W)
    {
      char tmp;
      cin >> tmp;
      if (tmp == '#')
        S[i][j] = -2;
      else
        S[i][j] = -1;
    }
  }

  std::queue<std::pair<std::pair<int, int>, int>> q;
  std::queue<std::pair<std::pair<int, int>, int>> q2;

  q.push(std::make_pair(std::make_pair(sy - 1, sx - 1), 0));
  S[sy - 1][sx - 1] = 0;

  int tbl1_y[] = {0, 0, -1, 1};
  int tbl1_x[] = {-1, 1, 0, 0};

  int tbl2_y[] = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
  int tbl2_x[] = {-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};

  while (!q.empty() || !q2.empty())
  {
    std::pair<std::pair<int, int>, int> e;
    if (!q.empty()) {     
      e = q.front();
      q.pop();
    } else {
      e = q2.front();
      q2.pop();
    }

    auto p = e.first;
    int y = p.first;
    int x = p.second;
    int c = e.second;

    rep(i, 4)
    {
      move(y + tbl1_y[i], x + tbl1_x[i], c, S, q);
    }

    rep(i, 20)
    {
      move(y + tbl2_y[i], x + tbl2_x[i], c + 1, S, q2);
    }
  }

  cout << S[gy - 1][gx - 1] << endl;

  return 0;
}


Measured memory_bytes: 7668
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,t[101];
    double v[101];
    std::cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> t[i];
        sum += t[i];
    }
    ll now = 0;
    std::map<double, double> minr;
    for (double i = 0; i <= sum; i+=0.5) {
        minr[i] = sum-i;
    }
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
        
        for (double j = 0; j <= now; j+=0.5) {
            minr[j] = min(minr[j],v[i]+now-j);
        }
        for (double j = now; j <= now+t[i]; j+=0.5) {
            minr[j] = min(minr[j],v[i]);
        }
        now += t[i];
    }
    
    
    double a=0;
    double result = 0;
    double b=0;
    for (double i = 0.5; i <= sum; i+=0.5) {
        b = a;
        if(a <= minr[i]-0.5){
            a+=0.5;
        }else if(a == minr[i]){
            
        }else{
            a-=0.5;
        }
        // std::cout << a<<" "<<minr[i]<< std::endl;
        result += (b+a)/4.0;
    }
    std::cout << setprecision(10)<<result << std::endl;
}


Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, M;
	cin >> N >> M;
	vector<vector<int> > V(N);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		V[A].push_back(B);
		V[B].push_back(A);
	}
	for (int i = 0; i < N; i++) {
		if (V[i].size() % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = 0; i < N; i++) {
		if (V[i].size() >= 6) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	int C4 = 0;
	for (int i = 0; i < N; i++) {
		if (V[i].size() >= 4) {
			C4++;
		}
	}
	if (C4 >= 3) {
		cout << "Yes" << endl;
		return 0;
	}
	if (C4 <= 1) {
		cout << "No" << endl;
		return 0;
	}
	int S = -1, T = -1;
	for (int i = 0; i < N; i++) {
		if (V[i].size() == 4) {
			if (S == -1) S = i;
			else T = i;
		}
	}
	for (int i = 0; i < 4; i++) {
		int P = V[S][i], Q = S;
		while (1) {
			if (P == S) {
				cout << "Yes" << endl;
				return 0;
			}
			if (P == T) {
				break;
			}
			for (int j = 0; j < 2; j++) {
				if (V[P][j] != Q) {
					Q = P;
					P = V[P][j];
					break;
				}
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <limits>

using namespace std;

int path[201][201];

int dfs(int d, int p, vector<int> &r) {
	int result = numeric_limits<int>::max();
	bool flag = false;
	for (int i = 0; i < r.size(); i++) {
		if (r[i] == 0) continue;
		int n = r[i];
		r[i] = 0;
		result = min(result, dfs(d + path[p][n], n, r));
		r[i] = n;
		flag = true;
	}
	if (!flag) return d;
	return result;
}

int main(int argc, char *argv[]) {
	int N, M, R;
	cin >> N >> M >> R;

	vector<int> r;
	for (int i = 0; i < R; i++) {
		int ri;
		cin >> ri;
		r.push_back(ri);
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i != j) path[i][j] = 1e9 + 1;
		}
	}

	for (int i = 0; i < M; i++) {
		int A, B, C;
		cin >> A >> B >> C;
		path[A][B] = path[B][A] = C;
	}

	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				if (path[i][j] > path[i][k] + path[k][j]) {
					path[i][j] = path[i][k] + path[k][j];
				}
			}
		}
	}

	int ans = dfs(0, 0, r);

	cout << ans << endl;
}

Measured memory_bytes: 384
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int n;
long long dp[3333][3333];
bool dp_bool[3333][3333];
vector<int> as;

long long dfs(int a, int b){
    if(dp_bool[a][b]){
        return dp[a][b];
    }

    if(b==0){
        dp[a][0] = 0;
    }else if(b==1){
        dp[a][1] = as[a];
    }else{
        dp[a][b] = max(as[a] - dfs(a+1, b-1), as[a+b-1] - dfs(a, b-1));
    }
    dp_bool[a][b] = true;
    return dp[a][b];
}

int main(){
    cin >> n;
    as.resize(n);
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }

    for(int i = 0; i< n; i++){
        for(int j = 0; j < n; j++){
            dp_bool[i][j] = false;
        }
    }

    long long result = dfs(0, n);

/*
    for(int i = 0; i< n; i++){
        for(int j = 0; j < n; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
*/
    

    
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 90496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    bool flag=true;
    int n,a,b,c,d=0,e=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>a>>b>>c;
    	if(b+c-d-e>a)
    	{
    		cout<<"No"<<endl;
    		return 0;
		}
    	else if((b+c-d-e)%2!=a%2)
    	{
    		cout<<"No"<<endl;
    		return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main(void){
    int a[5][4][11];
    fill(a[0][0], a[5][0], 0);

    int n;
    cin >> n;
    
    for(int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        a[b][f][r] += v;
    }
    for(int i = 1; i <= 4; i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 10; k++) cout << ' ' << a[i][j][k];
            cout << endl;
        }
        if(i != 4) cout << "####################" << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}


ll fact_mod(ll n) {
    ll ret=1; 
    for(ll i=2;i<=n;i++) ret=ret*(i%mod)%mod;
    return ret;
} 
ll pow_mod(ll x, ll n){
    if(n==0) return 1;
    ll ret=pow_mod((x*x) % mod, n/2);
    if(n&1) ret=(ret*x)%mod;
    return ret;
}
//O(r)
ll combination_mod(ll n, ll r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    ll a=1;
    for(ll i=0;i<r;i++) a=a*((n-i)%mod)%mod;
    ll b=pow_mod(fact_mod(r), mod-2);
    return (a%mod)*(b%mod)%mod;
}
ll inv_mod(ll n){
    return pow_mod(n,mod-2);
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;
    vector<pair<ll,ll>> v;
    ll after=0;
    rep(i,n){
        pair<ll,ll> p;
        cin>>p.first>>p.second;

        if(p.first==0 and p.second==0){
            after++;
        }
        else{
            v.push_back(p);
        }
    }
    n-=after;
    auto f=[](ll si,ll bo){
        if(si==0)return make_pair(0ll,1ll);
        if(bo==0)return make_pair(1ll,0ll);
        ll g=gcd(abs(si),abs(bo));
        si/=g;bo/=g;

        if(si>0 and bo>0) return make_pair(si,bo);
        if(si<0 and bo<0) return make_pair(abs(si),abs(bo));
        else return make_pair(-abs(si),abs(bo));
    };

    map<pair<ll,ll>,ll> cnt;
    int xl=0,xr=0;
    for(int i=0;i<n;i++){
        if(v[i].second==0)xl++;
        else if(v[i].first==0)xr++;
        else cnt[f(v[i].second,v[i].first)]++;  
    }

    vector<pair<ll,ll>> yabai;
    if(xl and xr)yabai.push_back({xl,xr});
    for(auto pp:cnt){
        auto p=pp.first;
        ll lf=pp.second;

        if(lf==0) continue;

        pair<ll,ll> target;
        if(p.first<0) target=make_pair(p.second,-p.first);
        else target=make_pair(-p.second,p.first);

        if(cnt.count(target)){
            if(cnt[target]) yabai.push_back(make_pair(lf,cnt[target]));
            cnt[target]=0;
        }
    }
    ll s=0;
    ll ans=1;
    for(auto p:yabai){
        ll res=(pow_mod(2,p.first)+pow_mod(2,p.second)-1)%mod;
        ans=ans*res%mod;
        s+=p.first+p.second;
    }
    ans=(ans*pow_mod(2,n-s))%mod;
    ans+=after-1;
    if(ans<0) ans+=mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18620
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin >> N;
    cout << (1000 - N%1000)%1000 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
 
void dfs(int s , vector< vi> &adj , vector< bool > &vis,  vi &dp , vi &indegree){	
	vis[s]=true; 
	for(int u:adj[s]){
		dp[u]=max(dp[u],dp[s]+1); 
		--indegree[u]; 
		if(indegree[u]==0) 
			dfs(u,adj,vis,dp,indegree); 
	}
}


int32_t main(){
  fast; 
 /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif 
*/	
  int T=1; //cin>>T; 
  while(T--){

  	int n,m; cin>>n>>m; 
  	vector< vi > adj(n); 
  	
  	vi indegree(n,0); 
  	
  	for(int i=0;i<m;i++){
  		int x,y; cin>>x>>y; 
  		adj[x-1].pb(y-1);
  		indegree[y-1]++;  
  	}
  	vector< bool > vis(n,false); 
  	vi dp(n,0);  
  	for(int i=0;i<n;i++){
  		if(!vis[i] && indegree[i]==0){
  			dfs(i,adj,vis,dp,indegree); 
  		}
  	}


  	//debug(dp);  
  	int mx=INT_MIN; 
  	for(int i=0;i<n;i++){
  		mx=max(dp[i],mx); 
  	}
  	cout<<mx<<endl; 


  }
    


  return 0; 
} 

Measured memory_bytes: 15104
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-04-27 11:02
# @url:https://atcoder.jp/contests/abc164/tasks/abc164_c
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    t=int(input())
    strlist=[str(input()) for x in range(t)]
    # print ([str(x) for x in strlist])
    ans=set()
    for s in strlist:
        ans.add(s)
    print (len(ans))
if __name__ == "__main__":
    main()

Measured memory_bytes: 99668
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
	int n,m;
	scanf("%d",&n);
	m=(int)sqrt(n);
	if (n==m*m)
          printf("%d\n",n);
          else
            printf("%d\n",m*m);
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll f(ll a){
  if(a<0) return 0;
  
  if(a%2==0){
    return a^(a/2%2);
  }else{
    return (a/2+1)%2;
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll a,b; cin>>a>>b;
  
  // cout<<f(b)<<' '<<f(a-1)<<endl;
  
  cout<<(f(b)^f(a-1))<<endl;
}


Measured memory_bytes: 3584
import math

while True:
    n = int(input())
    if n == 0:
        break

    arr = list(map(int, input().split()))
    m = sum(arr) / n
    t = 0
    for i in range(n):
        t += math.pow(arr[i] - m, 2)
    a = math.sqrt(t/n)
    print("{0:5f}".format(a))



Measured memory_bytes: 5704
def main3():
    s = input()
    k = int(input())

    if len(set(s)) == 1:
        print(len(s)*k//2)
    else:
        s1 = list(s)
        s2 = list(s + s)

        c1, c2 = 0, 0
        for i in range(len(s1) - 1):
            if s1[i] == s1[i + 1]:
                    c1 += 1
                    s1[i + 1] = "-"

        for i in range(len(s2) - 1):
            if s2[i] == s2[i + 1]:
                    c2 += 1
                    s2[i + 1] = "-"

        d = c2 - c1
        print(c1 + (k - 1) * d)

if __name__ == "__main__":
    main3()

Measured memory_bytes: 9112
a, b, c = gets.split.map &:to_i

if a.even? && a == b && b == c
  puts -1
  exit
end

cnt = 0
while a.even? && b.even? && c.even?
  x, y, z = 0, 0, 0
  y += a / 2
  z += a / 2
  x += b / 2
  z += b / 2
  x += c / 2
  y += c / 2
  a, b, c = x, y, z
  cnt += 1
end
p cnt

Measured memory_bytes: 14420
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ll N, P;
    cin >> N >> P;
    map<ll, int> mp;
    ll r = sqrt(P);
    ll t = 2;
    while (t <= r) {
        if (P % t == 0) {
            while (P % t == 0) {
                mp[t]++;
                P /= t;
            }
        }
        t++;
    }
    if (P != 1) mp[P]++;
    auto it = mp.begin();
    ll ans = 1;
    while (it != mp.end()) {
        int r = it->second;
        for (int i = 0; i < r/N; i++) {
            ans *= it->first;
        }
        it++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

const ll M = 1e6;
const ll pv = 1e9;
int n, m;
vector<pair<ll, ll>> py(M);
vector<ll> v;

int main() {
    cin >> n >> m;
    rep(i, m) {
        ll p, y;
        cin >> p >> y;
        py[i] = make_pair(p, y);
        v.push_back(p * pv + y);
    }
    sort(all(v));
    rep(i, m) {
        ll x; 
        x = upper_bound(all(v), py[i].first * pv + py[i].second) - upper_bound(all(v), py[i].first * pv);
        printf("%06lld%06lld\n", py[i].first, x);
    }
}

Measured memory_bytes: 18036
A,B,C = map (int, input ().split ())
S = int (input ())
if A>B>C or A>C>B:
  for i in range (S):
    A = A*2
  print (A+B+C)
elif B>A>C or B>C>A:
  for i in range (S):
    B = B*2
  print (A+B+C)
else:
  for i in range (S):
    C = C*2
  print (A+B+C)

Measured memory_bytes: 9008
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    int ansN=0,anslis[30000][2]={0};
    int topa=0;
    if(((N-1)*(N-2))/2<K){
        puts("-1");
        return 0;
    }
    else{
        for(int i=1;i<=N;i++){
            for(int j=i+1;j<=N;j++){
                if(topa==K||j==N){
                    anslis[ansN][0]=i,anslis[ansN][1]=j;
                    ansN++;
                }
                else{
                    topa++;
                }
            }
        }
    }
    cout<<ansN<<endl;
    for(int i=0;i<ansN;i++)cout<<anslis[i][0]<<" "<<anslis[i][1]<<endl;
    return 0;
}


Measured memory_bytes: 3372
import sys
from operator import itemgetter

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def iif(n): return [int(input()) for _ in range(n)]
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]
def ss(): return input().split()

def main():
    mod = 1000000007
    
    n = ii()
    A = lmi()

    cnt = 0
    for i in range(0, n, 2):
        if A[i] % 2 == 1:
            cnt += 1

    print(cnt)
    
    return

main()


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

bool is_even(string s, int n) {
	string f1=s.substr(0,n/2);
	string f2=s.substr(n/2,n);
	return f1==f2;
}
void go(){
	string s;
	cin>>s;
	cout << string(s.size(), 'x');
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

int seen[200001] = { false };
int a[200001] = { 0 };
int ans[200001] = { 0 };
void dfs(int v, int sum, whei(int)& G) {
	seen[v] = true;
	ans[v] = sum;
	for (auto x : G[v]) {
		if (seen[x])continue;
		dfs(x, sum + a[x], G);
	}
}

int main() {
	int a,b;
	cin >> a>>b;
	hei(int) x(a);
	rep(i, 0, a)cin >> x[i];
	int ans = 1;
	int z = 0;
	rep(i, 0, a) {
		z += x[i];
		if (z <= b)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N, K;
  int value = 1;
  cin >> N >> K;
  
  for(int i=0; i<N; i++){
    if(value * 2 < value + K){
      value *= 2;
      //cout << (i+1) << ":" << value << endl;
    }else{
      value += K;
      //cout << (i+1) << ":" << value << endl;
    }
  }
  
  cout << value << endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    int N;
    cin >> N;

    cout << N * N * N << endl;

    return 0;
}


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

// 最後に勝ち残る石の最後の時点での硬度を計算.
// @param que: 石の情報.
// @return: 最後に勝ち残った石の硬度.
int recursive(queue<int> &que){
    queue<int> q;
    while(!que.empty()){
        int s1 = que.front(); que.pop();
        int s2 = que.front(); que.pop();
        int s3 = (s1 == s2) ? s1 : abs(s1 - s2);
        q.push(s3);
    }
    if(q.size() > 2){
        return recursive(q);
    }else{
        int x1 = q.front(); q.pop();
        int x2 = q.front(); q.pop();
        return (x1 == x2) ? x1 : abs(x1 - x2);
    }
}

int main(){

    // 1. 入力情報.
    int N, a;
    queue<int> q;
    scanf("%d", &N);
    rep(i, 1 << N){
        scanf("%d", &a);
        q.push(a);
    }
    
    // 2. 出力.
    printf("%d\n", recursive(q));
    return 0;
    
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int N;
    cin >> N;
    // vector<ll> arr(N, 0);

    int neg = 0;
    ll abs_min = INT_MAX;
    ll acc = 0;
    ll cur = 0;
    for(int i = 0; i < N; i++) {
        cin >> cur;
        if (cur < 0)
            neg += 1;
        acc += llabs(cur);
        abs_min = min(abs_min, llabs(cur));
    }
    if (neg % 2 != 0)
        cout << acc - abs_min*2 << endl;
    else
        cout << acc << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int active = 0;
    int ans = 0;
    rep(i,n){
        if(active > h[i]){
            active = h[i];
        }
        else{
            ans += h[i] - active;
            active = h[i];
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
# Security

S = gets.chomp.to_s
pre = " " #一つ前
cur = " " #現在
ans = "Good"
for i in 0..S.length-1 do
    if i != 0
    pre = S[i-1]
    end
    cur = S[i]
    if i != 0 && cur == pre
        ans = "Bad"
        break
    end
end
puts ans

Measured memory_bytes: 3836
#include <vector>
#include <iostream>
#include <complex>

#define fs first
#define sc second

using namespace std;

typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
const D EPS=1e-12;


namespace std{
  bool operator<(const P &a, const P &b){
    return real(a)==real(b)?imag(a)<imag(b):real(a)<real(b);
  }
}

D dot(P x, P y){return real(conj(x)*y);}

D cross(P x, P y){return imag(conj(x)*y);}

int ccw(P a, P b, P c){
  b -= a; c -= a;
  if(cross(b, c) > EPS) return 1;
  if(cross(b, c) < -EPS) return -1;
  if(dot(b, c) < -EPS) return 2;
  if(abs(b) < abs(c)) return -2;
  return 0;
}

bool para(L a, L b){return abs(cross(a.fs - a.sc, b.fs-b.sc))<EPS;}

int main(){
    D x1, y1, x2, y2, x3, y3, xp, yp;
    while(cin >>  x1 >> y1 >> x2 >> y2 >>  x3>> y3>> xp >> yp){
    P A = P(x1, y1);
    P B = P(x2, y2);
    P C = P(x3, y3);
    P p = P(xp, yp);
    if(ccw(A, B, p) == ccw(B, C, p) && ccw(B, C, p) == ccw(C, A, p)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
    }
    return 0;
}





Measured memory_bytes: 3268
#include <stdio.h>
#include <ctype.h>
     
int par[100000];
     
void init(int);
int dep(int);
int inp();
    
char *p;
char in[1500000];
int tree[100000][15],idx[100000];
    
int main(void){
  int n,i,j,id,k,c;
    
  fread(in,sizeof(in),1,stdin);  
  p = in;
    
  n = inp(); init(n);
  for(i = 0 ; i < n ; i++){
    id = inp();
    k = inp();
    for(j = 0 ; j < k ; j++){
      c = inp();
      par[c] = id;
      tree[id][idx[id]++] = c;
    }
  }
     
  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, "
           ,i,par[i],dep(i));
        
    if(par[i] == -1){
      printf("root, [");
    }else if(!idx[i]){
      printf("leaf, [");
    }else{
      printf("internal node, [");
    }
    
    for(j = 0 ; j < idx[i] ; j++){
      printf("%d",tree[i][j]);
      if(j < idx[i]-1) printf(", ");
    }
    puts("]");
  }
  return 0;
}
    
void init(int n){
  int i;
  for(i = 0 ; i < n ; i++){
    par[i] = -1;
  }
}
    
int dep(int x){
  if(par[x] == -1) return 0;
  return dep(par[x]) + 1;
}
    
int inp(){
  int v = 0;
  while(!isdigit(*p)) ++p;
  v = *p++&15;
  while(isdigit(*p)){
    v = (v<<3)+(v<<1)+(*p++&15);
  }
  return v;
}


Measured memory_bytes: 5064
// Gear4        
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define ff first
#define ss second
template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;
using ld = long double;
using ll = long long;
#define endl '\n'
const int inf = 1e9, mod = 1e9 + 7;
const ll INF = 9e18;
const ld EPS = 1e-9, PI = acosl(-1.0);
const int N = 1e6 + 6;
int n;
ll fac[N], ifac[N];
ll ch(int n, int r) {
    if(r < 0 || r > n) return 0;
    return fac[n] * 1LL * (ifac[r] * 1LL * ifac[n-r] % mod) % mod;
}
int modexp(ll a, int b, ll p) {
    ll ret = 1;
    for(; b; b>>=1) {
        if(b & 1) ret = ret * a % p;
        a = a * a % p;
    }
    return ret;
}
int main() {
    SYNC
    fac[0] = ifac[0] = 1;
    for(int i = 1; i<N; i++) fac[i] = fac[i-1] * 1LL * i % mod;
    for(int i = 1; i<N; i++) ifac[i] = modexp(fac[i], mod-2, mod);
    cin >> n;
    ll ans = 0, cur = 0, pre = 0;
    for(int i = 1; i < n; i++) {
        cur = ch(i-1, n-i-1) * fac[i] % mod;
        cur = cur * fac[n-i-1] % mod;
        (ans += i * (cur-pre) % mod) %= mod;
        pre = cur;
    }
    if(ans<0) ans += mod;
    cout << ans;
}

Measured memory_bytes: 15872
import sys
from collections import defaultdict
dic1 = defaultdict(int)
dic2 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

for idx,i in enumerate(lst1,1):
    dic1[i-idx] += 1
    dic2[i+idx] += 1

ans = 0

for i,j in dic1.items():
    ans += j*dic2[-i]

print(ans)



Measured memory_bytes: 142152
#include<stdio.h>
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    long long int N,M;
    scanf("%lld %lld",&N,&M);
    long long int ans=0;
    if(N>2&&M>2)ans+=(N-2)*(M-2);//center is always back
    if(N==1||M==1)ans+=(N*M)-2;
    if(N==1&&M==1)ans=1;
    printf("%lld\n",ans); 
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void){
	int member[100][100], leak[100], n, m, i, j, x, count, res;
	scanf("%d",&n);
	while(n){
		memset(member,0,sizeof(member));
		for(i = 0;i < n;i++){
			scanf("%d",&m);
			for(j = 0;j < m;j++){
				scanf("%d",&x);
				member[i][x - 1] = 1;
			}
		}
		scanf("%d",&m);
		memset(leak,0,sizeof(leak));
		for(i = 0;i < m;i++){
			scanf("%d",&x);
			leak[x - 1] = 1;
		}
		count = 0;
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++)
				if(leak[j] && !member[i][j]) break;
			if(j == n){
				count++;
				res = i + 1;
			}
		}
		if(count == 1)
			printf("%d\n",res);
		else
			printf("-1\n");
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main(){   
   int d,n;
   cin>>n>>d;
   int a[n][d];
      for (int j = 0; j < n; j++)
      {
       for (int i = 0; i <d; i++)
       {
      cin>>a[j][i];
       }
      }

   int count=0;

   for (int i = 0; i < n; i++)
   {
      
      for (int j = i+1; j < n; j++)
      {
         int calc=0;
       for (int k = 0; k < d; k++)
       {
          calc+=(a[j][k]-a[i][k])*(a[j][k]-a[i][k]);
         }
         for (int l = 0; l < 500; l++)
         {
            if(l*l==calc) count++;
         }
         
      }
      
   }
   cout<<count;
   

return 0;
}

Measured memory_bytes: 256