akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> W >> H >> K;
	vector<int>y(K);
	vector<int>x(K);
	for (int i = 0; i < K; i++) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}
	vector<vector<long long int>>dis(K, vector<long long int>(2, MOD*MOD));
	vector<set<pair<int, int>>>xx(W);
	vector<set<pair<int, int>>>yy(H);
	for (int i = 0; i < K; i++) {
		xx[x[i]].insert({ y[i],i });
		yy[y[i]].insert({ x[i],i });
	}

	priority_queue<pair<long long int, pair<int, int>>, vector<pair<long long int, pair<int, int>>>, greater<pair<long long int, pair<int, int>>>>PQ;
	for (int i = 0; i < K; i++) {
		if (!x[i]) {
			dis[i][0] = y[i];
			PQ.push({ dis[i][0],{i,0} });
		}
	}
	while (!PQ.empty()) {
		auto box = PQ.top();
		PQ.pop();
		int cn = box.second.first;
		int dir = box.second.second;
		long long int cost = box.first;
		if (dis[cn][dir] < cost)continue;
		if (!dir) {
			auto it = xx[x[cn]].lower_bound({ y[cn],cn });
			auto nx = next(it);
			if (nx != xx[x[cn]].end()) {
				if (dis[nx->second][dir] > cost + abs(y[cn] - nx->first)) {
					dis[nx->second][dir] = cost + abs(y[cn] - nx->first);
					PQ.push({ dis[nx->second][dir] ,{nx->second,dir} });
				}
			}
			if (it != xx[x[cn]].begin()) {
				auto pv = prev(it);
				if (dis[pv->second][dir] > cost + abs(y[cn] - pv->first)) {
					dis[pv->second][dir] = cost + abs(y[cn] - pv->first);
					PQ.push({ dis[pv->second][dir] ,{ pv->second,dir } });
				}
			}
		}
		else {
			auto it = yy[y[cn]].lower_bound({ x[cn],cn });
			auto nx = next(it);
			if (nx != yy[y[cn]].end()) {
				if (dis[nx->second][dir] > cost + abs(x[cn] - nx->first)) {
					dis[nx->second][dir] = cost + abs(x[cn] - nx->first);
					PQ.push({ dis[nx->second][dir] ,{ nx->second,dir } });
				}
			}
			if (it != yy[y[cn]].begin()) {
				auto pv = prev(it);
				if (dis[pv->second][dir] > cost + abs(x[cn] - pv->first)) {
					dis[pv->second][dir] = cost + abs(x[cn] - pv->first);
					PQ.push({ dis[pv->second][dir] ,{ pv->second,dir } });
				}
			}
		}
		if (dis[cn][dir ^ 1] > cost + 1) {
			dis[cn][dir ^ 1] = cost + 1;
			PQ.push({ cost + 1,{cn,dir ^ 1} });
		}
	}
	long long int ans = MOD * MOD;
	for (int i = 0; i < K; i++) {
		if (x[i] == W - 1) {
			ans = min(ans, dis[i][0] + H - 1 - y[i]);
		}
		if (y[i] == H - 1) {
			ans = min(ans, dis[i][1] + W - 1 - x[i]);
		}
	}
	if (ans == MOD * MOD)ans = -1;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 44396
#include <iostream>
#define rep(i,n) for(int i = 0; i < n; i++)
#define print(a) cout << a << endl
using namespace std;
int distance(int x1, int y1, int x2, int y2){
    return abs(x1 - x2) + abs(y1 - y2);
}

int main(void){
    int n;
    cin >> n;
    int t[n], x[n], y[n];
    rep(i, n){
        cin >>t[i] >> x[i] >> y[i];
    }
    int nowx = 0;
    int nowy = 0;
    int nowt = 0;
    rep(i, n){
        int d = distance(nowx, nowy, x[i], y[i]);
        int t_diff = t[i] - nowt;
        if(t_diff < d or (t_diff-d) % 2 != 0){
            print("No");
            return 0;
        }
        nowx = x[i];
        nowy = y[i];
        nowt = t[i];
    }
    print("Yes");
    return 0;
}


Measured memory_bytes: 1408
n = int(input())

a = int(n ** 0.5) + 1

m = {}
for x in range(1, a):
    for y in range(1, a):
        for z in range(1, a):
            v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            m[v] = m.get(v, 0) + 1
for i in range(1, n + 1):
    print(m.get(i, 0))


Measured memory_bytes: 11768
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         String lol = N+"";
         if(lol.charAt(0) == '7' || lol.charAt(1) == '7' || lol.charAt(2) == '7')
            System.out.println("Yes");
         else
            System.out.println("No");
      }
   }

Measured memory_bytes: 36512
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=3e5+5;
typedef unsigned long long ull;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int n,x;
int l=0;
int main(){
    cin>>n>>x;
    int ans=1;
    for(int i=0;i<n;i++){
        int u;cin>>u;
        l+=u;
        if(l<=x)ans++;
    }
    o(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 2147400000
using namespace std;
string s;
int fg1=inf,fg2;
int main(){
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='C') fg1=min(fg1,i);
        else if(s[i]=='F') fg2=max(fg2,i);
    }
    printf("%s",fg1<fg2?"Yes":"No");
    return 0;
}

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

ll N, X, a[51], p[51]; // a: all num, p: only p num

ll f(ll n, ll x) {
    if (x == 0){
        return 0;
    } else if (n == 0) {
        return 1;
    } else if (x <= a[n-1] + 1) {
        return f(n-1, x-1);
    } else if (x == a[n-1]+2) {
        return p[n-1] + 1;
    } else if (x <= 2 * a[n-1] + 2) {
        return p[n-1] + 1 + f(n-1, x - a[n-1] - 2);
    } else {
        return p[n];
    }
}

int main() {
    cin >> N >> X;
    a[0] = p[0] = 1;
    
    rep(i, N) {
        a[i+1] = a[i] * 2 + 3;
        p[i+1] = p[i] * 2 + 1;
    }
    cout << f(N, X) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n,m;
	cin>>n>>m;
	if(n>=10){
		cout<<m<<endl;
	}else{
		cout<<m+100*(10-n)<<endl;
	}
	return 0;
}


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

map<long long int, long long int> prime_factor(long long int n) {
    map<long long int, long long int> ret;
    for (long long int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    ll A, B;
    cin >> A >> B;

    map<ll, ll> prime_A = prime_factor(A);
    map<ll, ll> prime_B = prime_factor(B);

    int output = 1;
    for (auto var : prime_A) {
        if (prime_B[var.first] != 0) {
            output++;
        }
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3552
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int K;
    string S;
    cin >> K >> S;

    if(K < S.size()){
        cout << S.substr(0,K) << "..." << endl;
    }
    else{
        cout << S << endl;
    }
    
    
}


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (true) {
		int n, ans = 0;
		cin >> n;
		if (n == 0) break;

		REP(i, n) {
			int x, y, h, w;
			scanf("%d %d %d %d", &x, &y, &h, &w);

			int s = x + y + h;
			int size1 = ceil((s - 60) / 20.0);
			if (size1 > 5) continue;
			if (size1 < 0) size1 = 0;

			int dw[] = {2, 5, 10, 15, 20, 25};
			int size2 = 0;
			REP(i, 6) if (w > dw[i]) size2++;
			if (size2 > 5) continue;

			ans += 600 + 200*max(size1, size2);
		}
		cout << ans << endl;
	}
	return 0;
}

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

using namespace std;

const int max_n = 111, inf = 1000111222;

int n, a[max_n];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    int best = inf, pos;
    for (int i = 0; i < n; ++i) {
        int x = abs(sum - a[i] * n);
        if (x < best) {
            best = x;
            pos = i;
        }
    }
    cout << pos << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll a,b,c,n,ans=0;
string s;
void Main(){
    cin>>n;
    cin>>s;
    for(int i=0;i<1000;i++){
        int j=i;
        int r[4];
        r[0]=j/100;j%=100;
        r[1]=j/10;j%=10;
        r[2]=j;
        r[3]=114514;
        b=0;
        for(int k=0;k<n;k++){
            if(s[k]-'0'==r[b]) b++;
        }
        if(b==3) ans++;
    }
    cout<<ans<<endl;
}
main(){
    Main();
}

Measured memory_bytes: 256
N, M = [int(item) for item in input().split()]
now_r = 10000000000
now_l = 0
for i in range(M):
  l, r = [int(item) for item in input().split()]
  now_r = min(r, now_r)
  now_l = max(l, now_l)
  
if (now_l > now_r):
  print (0)
else:
  print (now_r - now_l + 1)

Measured memory_bytes: 3188
n = int(input())

def f(num):
    num = num - int(str(num)[-1])
    count = 0
    i = 1
    while True:
        if ((5 ** i) * (2)) > num:
            break
        count += (num // ((5 ** i) * (2)))
        i += 1
    return count


# 偶数 => 出てくる5の個数
# 奇数 => 0
if n % 2 == 1:
    print(0)
    exit()
else:
    print(f(n))

Measured memory_bytes: 38256
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, L[1 << 18];
int ret = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> L[i];
	sort(L + 1, L + N + 1);

	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			for (int k = j + 1; k <= N; k++) {
				if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
				if (L[i] + L[j] > L[k]) ret++;
			}
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

using llong = long long;

int main() {
    llong n, m;
    cin >> n >> m;
    cout << n * m << endl;

    return 0;
}


Measured memory_bytes: 3108
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>s) {
		deque<ll> q;
		REP(i, s.size()) {
			if(s[i]=='0'||s[i]=='1') q.PB(s[i]);
			else if(q.size()) q.pop_back();
		}
		string t;
		for(auto e: q) t.PB(e);
		cout<<t<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W = list(map(int, sys.stdin.readline().split()))
S = [sys.stdin.readline().rstrip() for _ in range(H)]


def is_ok(h, w):
    dh = [h, h, h - 1, h + 1]
    dw = [w + 1, w - 1, w, w]
    for h, w in zip(dh, dw):
        if 0 <= h < H and 0 <= w < W:
            if S[h][w] == '#':
                return True
    return False


ok = True
for h, w in itertools.product(range(H), range(W)):
    if S[h][w] == '#':
        ok &= is_ok(h, w)
if ok:
    print('Yes')
else:
    print('No')


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

using namespace std;
long long x;
bool check(long long a){
  return 1LL*a*(a+1)/2<x;
}
int main(){
	
 	cin>>x;
	long long l =0 ;
  	long long r= 1e6;
  long long ans = 0;
	while(l<=r){
      long long mid = (l+r)/2;
      if(check(mid)){
        l = mid+1;
        ans = mid;
      }else{
        r= mid-1;
      }
    }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long K = scanner.nextLong();
		long a = scanner.nextLong();
		long b = scanner.nextLong();
		long a1;
		long b1;
		a1 = a/K;
		b1 = b/K;
		if (K == 1) {
			System.out.println("OK");
		} else if(a % K == 0 || b % K == 0) {
			System.out.println("OK");
		} else if (b1 != a1) {
			System.out.println("OK");
		} else {
			System.out.println("NG");
		}
	}
}


Measured memory_bytes: 35800
S = input()
if S[0] == S[1] and S[2] == S[3]  or  S[0] == S[2] and S[1] == S[3]  or  S[0] == S[3] and S[1] == S[2]:
  
  if S[0] == S[1] == S[2] == S[3]:
    print("No")
  
  else:
    print("Yes")

else:
  print("No")
    

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

int main() {
    ll n;cin >> n;
    vector<ll> vec(1000005);
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        ll a;cin >> a;
        vec[a]++;
        sum += a;
    }
    int q;cin >> q;
    vector<pair<ll, ll>> vp(q);
    for (int i = 0; i < q; i++)
    {
        ll b, c;cin >> b >> c;
        vp[i].first = b;
        vp[i].second = c;
    }
    
    for(int i = 0; i < q; i++){
        ll b = vp[i].first, c = vp[i].second;
        vec[c] += vec[b];
        sum = sum - (ll)(b*vec[b]) + (ll)(c*vec[b]);
        vec[b] = 0;
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 12744
<?php
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
$c=trim(fgets(STDIN));
$d=trim(fgets(STDIN));
$e=trim(fgets(STDIN));

$r=0;
$ans=0;
$ans+=ceil($a/10)*10;
$r=max($r,ceil($a/10)*10-$a);
$ans+=ceil($b/10)*10;
$r=max($r,ceil($b/10)*10-$b);
$ans+=ceil($c/10)*10;
$r=max($r,ceil($c/10)*10-$c);
$ans+=ceil($d/10)*10;
$r=max($r,ceil($d/10)*10-$d);
$ans+=ceil($e/10)*10;
$r=max($r,ceil($e/10)*10-$e);

echo $ans-$r;

Measured memory_bytes: 4728
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      b=sorted(set(list([a[i],a[j],a[k]])))
      if len(b)==3 and b[0]+b[1]>b[2]:
        ans+=1
print(ans)

Measured memory_bytes: 73744
#!/usr/bin/env python3
import sys

def isMonth(s):
    if s[0] == "0":
        return s[1] != "0"
    elif s[0] == "1":
        return s[1] == "0" or s[1] == "1" or s[1] == "2"
    return False
        

def solve(S: str):
    first = isMonth(S[:2])
    last = isMonth(S[2:])
    if not first and not last:
        print("NA")
    elif first and last:
        print("AMBIGUOUS")
    elif first and not last:
        print("MMYY")
    else:
        print("YYMM")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

int w,h,n;
int field[16][16];
int check[16][16],output[16][16];
int ans;
struct state{
	int area,x,y;
} memo[16];

bool ok(int x, int y, int zx, int zy, int num){
	rep(i,zy){
		rep(j,zx){
			int tx = x + j;
			int ty = y + i;
			if( tx<0 || ty<0 || tx>=w || ty>=h || check[ty][tx]>0 )return false;
			if( field[ty][tx]!=0 && field[ty][tx]!=num )return false;
		}
	}
	return true;
}

void dfs(int cnt){
#if DEB
	printf("cnt:%d\n",cnt);
	rep(i,h){
		rep(j,w){
			printf("%d ",check[i][j]);
		}
		puts("");
	}
	puts("");
#endif
	
	if( cnt==n ){
		ans++;
		if( ans>=2 ) return;
		rep(i,h)rep(j,w)output[i][j]=check[i][j];

		rep(i,h)rep(j,w)if( check[i][j]==0 )ans=2;
		return;
	}

	for(int i=1; i<=memo[cnt].area; i++){
		if( memo[cnt].area%i!=0 )continue;
		int j = memo[cnt].area / i;
		int si = memo[cnt].y - i + 1;
		int sj = memo[cnt].x - j + 1;

#if DEB
		printf("(i,j)=(%d,%d),  (si,sj)=(%d,%d)\n",i,j,si,sj);
#endif		

		for(int ii=si; ii<=memo[cnt].y; ii++){
			if( ii<0 )continue;
			for(int jj=sj; jj<=memo[cnt].x; jj++){
				if( jj<0 )continue;
				if( ok(jj, ii, j, i, cnt+1) ){
#if DEB
					printf("isok:: jj:%d , ii:%d, j:%d, i:%d\n",jj,ii,j,i);
#endif 					
					rep(k,i)rep(l,j)check[ii+k][jj+l]=cnt+1;
					dfs(cnt+1);
					if( ans>=2 ) return;
					rep(k,i)rep(l,j)check[ii+k][jj+l]=0;
				}
			}
		}
	}
}
int main(){
	
	while(scanf("%d%d%d",&w,&h,&n),w|h|n){
		rep(i,16)rep(j,16)check[i][j]=output[i][j]=0;
		ans = 0;
		
		rep(i,n){
			int b,k; scanf("%d%d",&b,&k);
			memo[b-1].area = k;
		}
		rep(i,h)rep(j,w)scanf("%d",&field[i][j]);
		rep(i,h)rep(j,w)if( field[i][j]>0 ){
			memo[ field[i][j]-1 ].x = j;
			memo[ field[i][j]-1 ].y = i;
		}
		
		dfs(0);

		if( ans==1 ){
			rep(i,h){
				rep(j,w){
					if( j>0 )putchar(' ');
					printf("%d",output[i][j]);
				}
				puts("");
			}
		}else{
			puts("NA");
		}
	}
	
	return 0;
}

Measured memory_bytes: 888
//AtCoder ABC056 B - NarrowRectanglesEasy
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    int W,a,b;
    cin>>W>>a>>b;
    int tmp0 = max(b-(a+W),0);
    int tmp1 = max(a-(b+W),0);
    cout<<max(tmp0,tmp1)<<endl;
    return 0;
}

Measured memory_bytes: 256
def test(A, B):
    if((A > 0 and A <= 12) and (B > 0 and B <= 12)):
        print("AMBIGUOUS")
        return

    if(not(A > 0 and A <= 12) and (B > 0 and B <= 12)):
        print("YYMM")
        return

    if ((A > 0 and A <= 12) and (not (B > 0 and B <= 12))):
        print("MMYY")
        return

    print("NA")


S = list(input())
A = int(S[0] + S[1])
B = int(S[2] + S[3])
# print(A)
# print(B)

# print(A != 0 and A <= 12)
# print(B != 0 and B <= 12)
test(A, B)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main(void){
    // Your code here!
    int H,A;
    cin >> H >> A;
    
    int count = 0;
    
    while(H>0){
        H -= A;
        count++;
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#define rg register

inline void read(int&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();
}

inline void cmax(int&A,int B){A=A>B?A:B;}
const int inv2=500000004,p=1e9+7;
const int bs=2001,N=8007,T=201000;
int fac[N],inv[N],a[T],b[T];
int f[bs+bs+2][bs+bs+2];
int n,ans,ma,mb;

inline int qm(int x){return x<0?x+p:x<p?x:x-p;}
inline int c(int nn,int mm){return 1ll*fac[nn]*inv[mm]%p*inv[nn-mm]%p;}

void init();void work();
int main(){init();work();return 0;}

void work(){
	for(rg int i=bs-ma;i<=bs+ma;++i)
	for(rg int j=bs-mb;j<=bs+mb;++j)
		f[i][j]=qm(f[i][j]+qm(f[i-1][j]+f[i][j-1]));
	for(rg int i=1;i<=n;++i){
		ans=qm(ans+f[a[i]+bs][b[i]+bs]);
		ans=qm(ans-c(a[i]+a[i]+b[i]+b[i],a[i]+a[i]));
	}
	printf("%lld\n",1ll*ans*inv2%p);
}

void init(){
	read(n);
	for(rg int i=1;i<=n;++i){
		read(a[i]),cmax(ma,a[i]);
		read(b[i]),cmax(mb,b[i]);
		++f[bs-a[i]][bs-b[i]];
	}
	fac[0]=inv[0]=1;
	for(rg int i=1;i<N;++i)fac[i]=1ll*fac[i-1]*i%p;
	inv[N-1]=923470334;
	for(rg int i=N-2;i;--i)inv[i]=1ll*inv[i+1]*(i+1)%p;
}

Measured memory_bytes: 64384
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    int n = input(), m = input();
    while(m--) n-=input();
    if(n >= 0) cout << n;
    else cout << -1;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    string s; cin >> s;
    int n = s.size();

    if(s[n-1] == '1' || !(s[0] == '1' && s[n-2] == '1')){
        cout << -1 << endl;
        return 0;
    }
    rep(i,n/2){
        if(s[i] != s[n-2-i]){
            cout << -1 << endl;
            return 0;
        }
    }

    vector<pii> edges;
    int l,r;
    if(n % 2 == 1){
        if(s[n/2-1] == '1'){
            l = n/2 - 1, r = n/2 + 1;
            edges.emplace_back(l,l+1);
            edges.emplace_back(l+1,l+2);
        }else{
            l = n/2 - 1, r = n/2 - 1;
            edges.emplace_back(l,l+1);
            edges.emplace_back(l,l+2);
        }
    }else{
        if(s[n/2-1] == '1'){
            l = n/2 - 1, r = n/2;
            edges.emplace_back(l,l+1);
        }else{
            l = n/2 - 1, r = n/2 - 1;
            edges.emplace_back(l,l+1);
        }
    }
    rep(i,n/2-1){
        int vl = n/2-2-i;
        int vr = (n+1)/2+1+i;
        edges.emplace_back(l,vl);
        edges.emplace_back(r,vr);
        if(s[vl] == '1'){
            l = vl; r = vr;
        }
    }
    for(pii edge : edges){
        cout << edge.fi+1 << " " << edge.se+1 << endl;
    }
    return 0;
}

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

int main() {

    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

char g[55][55];
int main() {
  int h,w; cin>>h>>w;
  REP(i,h) REP(j,w) { cin >> g[i+1][j+1]; }

  int ok = 1;
  for (int i = 1; i<=h; i++) {
    for (int j = 1; j<=w; j++) {
      if (g[i][j] != '#') continue;
      int c1 = g[i][j+1] != '#';
      int c2 = g[i][j-1] != '#';
      int c3 = g[i+1][j] != '#';
      int c4 = g[i-1][j] != '#';
      if (c1&&c2&&c3&&c4) ok = 0;
    }
  }
  COUT(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        ArrayList<Integer> h = new ArrayList<>();
        for (int i=0;i<n;i++){
            h.add(scanner.nextInt());
        }
        int count = 0;

        while (Collections.max(h)>0){
            count += counter(h);
            for (int i=0;i<n;i++){
                if (h.get(i)>0){
                    h.set(i,h.get(i)-1);
                }
            }
        }
        System.out.println(count);

    }
    public static int counter(ArrayList<Integer> num){
        int count = 0;
        for (int i=0;i<num.size()-1;i++){

            if ((num.get(i)==0)!=(num.get(i+1)==0)){
                count++;
            }
        }
        if (num.get(0)>0) count++;
        if (num.get(num.size()-1)>0) count++;
        count /= 2;
        return count;
    }

}


Measured memory_bytes: 21716
def main(S):
    N = len(S)
    if S == S[::-1] and S[:(N - 1) // 2] == S[:(N - 1) // 2][::-1] and S[(N + 1) // 2:] == S[(N + 1) // 2:][::-1]:
        return True
    else:
        return False
S = list(input())
if main(S) == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8788
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF 1001001001001001001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	bool flag = true;
	if (n % 2==0) {
		rep(i, 0, n / 2) {
			if (s[i] != s[n / 2 + i]) {
				flag = false;
				break;
			}
		}
	}
	else {
		flag = false;
	}

	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int N; string M;
int p[50]; long long power[20];
inline long long div(long long k, int m) {
	long long sum = 0;
	while (k >= 1) {
		k /= m; sum += k;
	}
	return sum;
}
int main() {
	while (true) {
		cin >> N >> M; power[0] = 1;
		for (int i = 0; i < 50; i++)p[i] = 0;
		for (int i = 1; i < M.size(); i++)power[i] = power[i - 1] * N;
		if (N == 0)break;
		long long C = 0;
		for (int i = 0; i < M.size(); i++) {
			int V = (char)(M[i] - '0'); if (M[i] >= 'A')V = (char)(M[i] - 'A') + 10;
			C += power[M.size() - 1 - i] * V;
		}
		int L = N;
		for (int i = 2; i <= L; i++) {
			while (L%i == 0) {
				L /= i; p[i]++;
			}
		}
		long long minx = 1LL << 62;
		for (int i = 2; i <= N; i++) {
			if (p[i] == 0)continue;
			minx = min(minx, div(C, i) / p[i]);
		}
		cout << minx << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string o, e;
  cin >> o >> e;
  if (o.length() == e.length()) {
    // 偶数文字
    rep(i, o.length()) { cout << o[i] << e[i]; }
  } else {
    // 奇数文字
    rep(i, e.length()) { cout << o[i] << e[i]; }
    cout << o[o.length() - 1];
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> inputString = Arrays.asList(br.readLine().split(" "));
            int N = Integer.parseInt(inputString.get(0));
            int M = Integer.parseInt(inputString.get(1));
            List<List<String>> nPicture = new ArrayList<>();
            List<List<String>> mPicture = new ArrayList<>();

            for (int i = 0; i < N; i++) {
                nPicture.add(Arrays.asList(br.readLine().split("")));
            }

            for (int i = 0; i < M; i++) {
                mPicture.add(Arrays.asList(br.readLine().split("")));
            }

            boolean exist = false;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    if (i + M - 1 >= N || j + M - 1 >= N) {
                        continue;
                    }

                    boolean match = true;
                    for (int k = 0; k < M; k++) {
                        for (int l = 0; l < M; l++) {
                            if(!nPicture.get(i + k ).get(j + l).equals(mPicture.get(k).get(l))) {
                                match = false;
                            }
                        }
                    }
                    if (match) exist = true;
                }
            }

            if (exist) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 22228
#include <stdio.h>

int main(void) {
	int d_num,c_data;
	int xmin,ymin,xmax,ymax;
	int x,y;
	int num,i,count;
	scanf("%d",&d_num);
	for(c_data=0;c_data<d_num;c_data++) {
		scanf("%d%d%d%d",&xmin,&ymin,&xmax,&ymax);
		xmax+=xmin;ymax+=ymin;
		scanf("%d",&num);
		for(i=0,count=0;i<num;i++) {
			scanf("%d%d",&x,&y);
			if(xmin<=x && x<=xmax && ymin<=y && y<=ymax)count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
//ifstream cin("lineup.in");
//ofstream cout("lineup.out");
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main(){
    bool a[3];
    a[0]=a[1]=a[2]=0;
    int x,y;
    cin>>x>>y;
    a[x-1]=1;
    a[y-1]=1;
    for(int i=0;i<3;i++){
	if(a[i]==0){
	    cout<<i+1<<endl;
	}
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll n;

int main(){
	cin >> n;
	vector<ll> c(n),s(n),f(n);
	rep(i,n-1)cin >> c[i] >> s[i] >> f[i];
	rep(i,n-1){
		ll ans = s[i] + c[i];
		FOR(j,i+1,n-1){
			if(ans - s[j] < 0)ans = s[j] + c[j];
			else {
				ll t = (ans - s[j])/f[j] + ((ans - s[j])%f[j] != 0);
				ans = s[j] + t*f[j] + c[j];
			}
		}
		cout << ans << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve(){
    double L;
    cin >> L;
    //cout << (L*L*L)/27.0 << endl;
    double ans = (L*L*L)/27.0;
    printf("%.9f\n", ans);

}


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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>adj[100100];
ll visited[100100];
ll p=1000000007;
ll ans=1;
ll n,k;
ll dfs(ll x)
{
	visited[x]=1;
	ll cur=2;
	for(ll i=1;i<adj[x].size();i++)
	{
		ans=ans*(k-cur)%p;
		cur++;
	}
	for(ll i:adj[x])
	{
		if(visited[i]==0)
		{
			dfs(i);
		}
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	    cin>>n>>k;
	    ll u,v;
	    for(ll i=1;i<n;i++)
	    {
	    	cin>>u>>v;
	    	adj[u].push_back(v);
	    	adj[v].push_back(u);
	    }
	    ll start;
	    for(ll i=1;i<=n;i++)
	    {
	    	if(adj[i].size()==1)
	    	{
	    		start=i;
	    		break;
	    	}
	    }
	    if(n==1)
	    {
	    	cout<<k;
	    	return 0;
	    }
	    visited[start]=1;
	    ans=k;
	    ans=ans*(k-1)%p;
	    visited[adj[start][0]]=1;
	    dfs(adj[start][0]);
	    cout<<ans;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll ans;
    cin >> N;
    ans = -N * (N + 1) / 2;
    while(N--) {
        ll v;
        cin >> v;
        ans += v;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3208
N=int(input())
revlist=[]
for i in range(N):
    s, p = input().split()
    p=int(p)
    revlist.append([i+1,s,p])
revlist=sorted(revlist, key=lambda x: x[2],reverse=True)
revlist=sorted(revlist, key=lambda x: x[1])
for i, s, p in revlist:
    print(i)

Measured memory_bytes: 3060
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int n;
bool grid[1003][1003];
void solve() {
    rep(i,1003) rep(j,1003) grid[i][j]=false;
    int dx,dy;
    int x=0,y=0;
    while(1) {
        cin>>dx>>dy;
        if(dx==0&&dy==0) break;
        x+=dx;
        y+=dy;
        grid[y][x]=true;
    }
    int maxi=0;
    P ans;

    rep(i,1003) rep(j,1003) {
        if(grid[i][j]) {
            if(maxi < i*i + j*j) {
                maxi = i*i + j*j;
                ans=P(j,i);
            }
        }
    }
    cout<<ans.fr<<" "<<ans.sc<<endl;

}
int main() {
    cin>>n;
    rep(i,n) solve();
    return 0;
}

Measured memory_bytes: 2140
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int N;
int A[MAX];
int ans[MAX];

int hoge(int i, int n) {
    if (i > 0) {
        n += A[i] * 2;
        return hoge((i-1), n);
    } else {
        return n;
    }
}

int main() {
    cin >> N;

    int sum = 0;
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
    }   

    ans[0] = sum;

    for(int i = 1; i < N; i += 2) {
        ans[0] -= 2*A[i];
    }

    for(int i = 1; i < N; i++) {
        ans[i] = 2*A[i-1] - ans[i-1];
    }

    REP(i, N) {
        cout << ans[i] << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<algorithm>
using namespace std;
int q,n;
int rank1[10001],par[10001];
int find(int x){
    return x==par[x]?x:find(par[x]);
}
void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b) return ;
    if(rank1[a]>rank1[b]){
        par[b]=a;
    }
    else{
        par[a]=b;
        if(rank1[a]==rank1[b]){
            rank1[b]++;
        }
    }
}
int main(){
    scanf("%d %d",&n,&q);
    fill(rank1,rank1+n,0);
    for(int i=0;i<n;++i){
        par[i]=i;
    }
    for(int i=0;i<q;++i){
        int temp,a,b;
        scanf("%d %d %d",&temp,&a,&b);
        if(temp){
            printf("%d\n",find(a)==find(b));
        }else{
            unite(a,b);
        }
    }
    return 0;
}



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

int main(){
  int x, y;
  while(1){
    cin >> x >> y;
    if(x == 0 && y == 0)
      break;
    else if(x > y){
      cout << y << " " << x << endl;
    } else {
      cout << x << " " << y << endl;
    }

  }

  return 0;
}



Measured memory_bytes: 3004
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
for(;;){
	string str[30]={""};
	int n,r,a;
	int  cnt,cn;
	string c;
	cin>>n;
	if(n==0)break;
	cin>>str[0];
	for(int i=1;i<=n;i++){
        cnt=1;
        for(int j=0;j<str[i-1].length();j++){
            if(str[i-1][j]==str[i-1][j+1])cnt++;
            else {
                if(cnt>=10){
                    cn=cnt/10;
                    cnt=cnt%10;
                    str[i]+=cn+'0';
                    str[i]+=cnt+'0';
                    str[i]+=str[i-1][j];

                }
                else {str[i]+=cnt+'0';
                str[i]+=str[i-1][j];
                }
                //cout<<str[i]<<"-"<<i<<endl;
                cnt=1;
            }
        }
	}
	cout<<str[n]<<endl;


}
	return 0;
}

Measured memory_bytes: 1460
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define size(a) int((a).size())
#define present(c, x) (c.find(x) != c.end()) 
#define printVerdict(verdict) cout << (verdict ? "YES": "NO") << '\n'
#define printDecimal(d) printf("%.9f\n", d)
#define inrange(val, start, end) (val >= start && val <= end)
 
const int mod = 1e9 + 7; 
 
template <class T1, class T2, class T3> 
void printTuple(tuple<T1, T2, T3> t) { cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << '\n'; }
template <class T1, class T2>
void printPair(pair<T1, T2> p) { cout << p.first << " " << p.second  << '\n'; }
template <class T>
void printArray(vector<T> arr) { for (int i = 0; i<size(arr); i++) {cout << arr[i] << " ";} cout << '\n'; } 

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	ll a[n];
	for (int i =0; i<n; i++) cin >> a[i];
	vector<ll> suff_sum(n,0);
	suff_sum[n-1] = a[n-1]%mod;
	for (int i =n-2; i>=0; i--) {
		suff_sum[i] = suff_sum[i+1] + (a[i]%mod);
		suff_sum[i] %= mod;
	}
	ll ret = 0;
	for (int i =0; i<n-1; i++) {
		ll curr = (a[i]%mod * suff_sum[i+1])%mod;
		ret = (ret + curr)%mod;
	}
	cout << ret << '\n';
}


Measured memory_bytes: 6332
m, d = map(int, input().split())
ans = 0
for i in range(2, d + 1):
    d1 = i % 10
    d10 = i // 10 % 10
    if d1 <= 1 or d10 <= 1:
        continue
    if d1 * d10 in range(2, m + 1):
        ans += 1

print(ans)


Measured memory_bytes: 3060
s = input()
k = int(input())

l = []
for i in range(1, min(len(s)+1,k+1)):
    for j in range(0,len(s)):
        t = s[j:j+i]
        if len(t) != i:break
        if t in l: continue
        l.append(t)
l = sorted(l)
print(l[k-1])



Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll const INF = 1e18;


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

int n;
cin >> n;
vl a(n);
rep(i,n) cin >> a[i];

rep(i,n) {
    if(a[i] == 0) {
        cout << 0 << endl;
        return 0;
    }
}

ll ans = 1;
rep(i,n) {
    if(a[i]> (INF/ans)+1) {
        cout << -1 << endl;
        return 0;
    }
    ans *= a[i];
}
if(ans > INF) cout << -1 << endl;
else cout << ans << endl;
return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   string o,e;
           cin>>o>>e;
           string ans="";
           int no=sz(o),ne=sz(e);
           rep(i,0,no+ne){
            if(i%2==0)ans+=o[i/2];
            else ans+=e[i/2];
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 3624
// Graph: Adjacency list
#include<vector>
typedef std::vector<std::vector<int>> Graph;
// Utility
const Graph reverse(const Graph& g) {
  Graph result(g.size());
  for(int u = 0; u < g.size(); ++u) for(auto v: g.at(u)) result.at(v).push_back(u);
  return result;
}
void postorder_dfs(const Graph& g, int current, std::vector<bool>& visited, std::vector<int>& result) {
  visited.at(current) = true;
  for(auto next: g.at(current)) if(!visited.at(next)) postorder_dfs(g, next, visited, result);
  result.push_back(current);
}
std::vector<int> postorder(const Graph& g) {
  std::vector<bool> visited(g.size(), false);
  std::vector<int> result;
  for(int v = 0; v < g.size(); ++v) if(!visited[v]) postorder_dfs(g, v, visited, result);
  return result;
}
// Strongly Connected Components: Kosaraju's algorithm O(V + E)
void scc_dfs(const Graph& g, int current, int group, std::vector<bool>& visited, std::vector<int>& result) {
  visited.at(current) = true;
  result.at(current) = group;
  for(auto next: g.at(current)) if(!visited.at(next)) scc_dfs(g, next, group, visited, result);
}
std::vector<int> scc(const Graph& g) {
  auto order = postorder(g);
  auto rg = reverse(g);
  std::vector<bool> visited(g.size(), false);
  std::vector<int> result(g.size());
  int group = 0;
  for(auto v = order.rbegin(); v != order.rend(); ++v) if(!visited.at(*v)) scc_dfs(rg, *v, group++, visited, result);
  return result;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int V, E;
  cin >> V >> E;

  Graph g(V);
  for(int i = 0; i < E; ++i) {
    int s, t;
    cin >> s >> t;
    g[s].push_back(t);
  }

  auto group = scc(g);

  int Q;
  cin >> Q;
  for(int i = 0; i < Q; ++i) {
    int u, v;
    cin >> u >> v;
    cout << (group[u] == group[v] ? 1 : 0) << endl;
  }
}

Measured memory_bytes: 3108