akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    string s;
    cin >> s;

    string t;
    cin >> t;

    bool check = true;

    for(char c = 'a'; c <= 'z'; c++){
        int ind = -1;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == c){
                ind = i;
                break;
            }
        }
        char x = t[ind];
        for(int i = ind+1; i < s.size(); i++){
            if(s[i] == c && t[i] != x){
                check = false;
            }
        }
    }

    for(char c = 'a'; c <= 'z'; c++){
        int ind = -1;
        for(int i = 0; i < t.size(); i++){
            if(t[i] == c){
                ind = i;
                break;
            }
        }
        char x = s[ind];
        for(int i = ind+1; i < t.size(); i++){
            if(t[i] == c && s[i] != x){
                check = false;
            }
        }
    }

    if(check){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

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

long long gcd(long x, long y)
{    if (y == 0)
        return x;
    return gcd(y, x % y);}
long long lcm(long x, long y){ return x * y / gcd(x, y);}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}


int main()
{
    int N,sum=0,m;
    cin>>N;

    for(int i=1;i<=N;i++){
        sum+=i;
        m=i;
        if(sum>=N)break;
    }

    int d = sum-N;

    for(int i=1;i<=m;i++){
        if(i!=d)cout<<i<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); for(int i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
int main()
{
	fio;
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a<3200)
	{
		cout<<"red\n";
	}
	else
	cout<<s<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n; cin>>n;
    vector<pair<ll,ll>> xy;

    rep(i,n){
        ll x,y;
        cin>>x>>y;
        pair<ll,ll> v={x,y};
        xy.push_back(v);
    }

    vector<pair<ll,ll>> f;
    rep(i,n){
        ll f0=xy[i].first-xy[i].second;
        ll f1=xy[i].first+xy[i].second;
        pair<ll,ll> v={f0,f1};
        f.push_back(v);
    }

    ll max0=-INF;
    ll min0=INF;
    ll max1=-INF;
    ll min1=INF;

    rep(i,n){
        max0=max(max0,f[i].first);
        min0=min(min0,f[i].first);
        max1=max(max1,f[i].second);
        min1=min(min1,f[i].second);
    }

    ll ans=max((max0-min0),(max1-min1));
    cout<<ans<<endl;
}

Measured memory_bytes: 12440
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def linear_search(S, n, key):
    i = 0
    S[n] = key
    while S[i] != key:
        i += 1
    return i != n


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

    N = ii()
    S = il()
    Q = ii()
    T = il()

    ret = 0
    for t in T:
        for s in S:
            if t == s:
                ret += 1
                break
    print(ret)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7928
#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;
}
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");
    int n; cin >> n;
    vl a(n+1);
    rep(i,n+1) cin >> a[i];

    vl pa(n+1);
    pa[0] = 1 - a[0];
    REP(i,1,n+1){
        pa[i] = min(2 * pa[i-1] - a[i], (ll)1e17);
    }
    rep(i,n+1){
        if(pa[i] < 0){
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0ll;
    ll ch = 0;
    rrep(i,n+1){
        if(pa[i]*2 < ch){
            cout << -1 << endl;
            return 0;
        }
        ch = min(ch, pa[i]) + a[i];
        ans += ch;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4768
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <stack>
#include <deque>
using namespace std;

int main(){
    string s;
    cin >> s;
    deque<char> x(s.begin(), s.end());
    bool r = 0;
    char c;
    int q, t, a;
    cin >> q;
    while(q--){
        cin >> t;
        if(t == 1){
            r = !r;
        } else {
            cin >> a >> c;
            a--;
            if(r) a = !a;
            if(a) x.push_back(c);
            else x.push_front(c);
        }
    }
    if(r) reverse(x.begin(), x.end());
    for(auto& i : x) cout << i;
    cout << '\n';
}


Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c) cout << "Yes" << endl;
    else if (b + c == a) cout << "Yes" << endl;
    else if (a + c == b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main()
{
int la,lb,i,lc,count=0;
char a[1000],b[1000],c[1000];

scanf("%s",a);
scanf("%s",b);
scanf("%s",c);

la=strlen(a);
lb=strlen(b);
lc=strlen(c);

if(a[la-1]==b[0] && b[lb-1]==c[0] )
printf("YES");
else printf("NO");
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int n;
    cin>>n;

    vi a(n+1);
    rep(i,1,n+1) cin>>a[i];

    sort(all(a));

    int sum = 0;
    for(int i = 1;i<n;i++){
    	sum += a[n-i/2];
    }
    cout<<sum<<"\n";
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 4808
let input = "8 8";

const main = lines => {
  const data = lines.split(" ");
  let division = parseInt(data[0], 10);
  let targetValue = parseInt(data[1], 10);

  console.log(Math.floor((division - 2 + (targetValue - 1)) / (division - 1)));
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
using System;
using System.IO;
using System.Collections.Generic;

namespace AtCoder {
    class Program {
        static void Main() {
            int[,] Cs = new int[3, 3];
            for (int i = 0; i < 3; i++) {
                string[] Keys = Console.ReadLine().Split(' ');
                for (int j = 0; j < 3; j++) {
                    Cs[i, j] = int.Parse(Keys[j]);
                }
            }
            vector Row1 = new vector(Cs[0, 0], Cs[0, 1], Cs[0, 2]);
            vector Row2 = new vector(Cs[1, 0], Cs[1, 1], Cs[1, 2]);
            vector Row3 = new vector(Cs[2, 0], Cs[2, 1], Cs[2, 2]);
            vector Col1 = new vector(Cs[0, 0], Cs[1, 0], Cs[2, 0]);
            vector Col2 = new vector(Cs[0, 1], Cs[1, 1], Cs[2, 1]);
            vector Col3 = new vector(Cs[0, 2], Cs[1, 2], Cs[2, 2]);
            if((Row1-Row2).Same()&&(Row2-Row3).Same()&&(Row3-Row1).Same()&& (Col1 - Col2).Same() && (Col2 - Col3).Same() && (Col3 - Col1).Same()) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }

    class vector {
        public int A, B, C;
        public vector(int a, int b, int c) {
            A = a;
            B = b;
            C = c;
        }
        public static vector operator -(vector a, vector b) {
            return new vector(a.A - b.A, a.B - b.B, a.C - b.C);
        }
        public bool Same() {
            return A == B && B == C && A == C;
        }
    }
}



Measured memory_bytes: 13140
var
  a,b,c,d,e,f,tx,ty:longint;
  g:array[0..3000,0..3000]of integer;

  procedure s(su,wa:longint);
  begin
    if g[su,wa]>-1 then exit;    g[su,wa]:=0;
    if su+wa*100>f then exit;
    if su>wa*e then exit;
    if (ty=0)or(su*(tx+ty*100)>(su+wa*100)*tx) then begin tx:=su; ty:=wa; end;
    s(su,wa+a);    s(su,wa+b);
    s(su+c,wa);    s(su+d,wa);
  end;

begin
  readln(a,b,c,d,e,f);
  tx:=0; ty:=0;
  fillchar(g,sizeof(g),255);
  s(0,0);
  writeln(tx+ty*100,' ',tx);
end.

Measured memory_bytes: 35328
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

const int MOD=998244353;
//const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

vll fac(300001),ifac(300001);

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

int main(){
    fac[0]=ifac[0]=1;
    for(ll i=0;i<300000;i++){
        fac[i+1] = fac[i]*(i+1) % MOD;
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD;
    }

    int N,M,K;
    cin>>N>>M>>K;
    ll ans=0;
    for(int i=0;i<=K;i++){
        ll C=comb(N-1,N-1-i);
        ll nurikata=(M*mpow(M-1,N-1-i))%MOD;
        ll aa=(C*nurikata)%MOD;
        //cout<<i<<" "<<C<<" "<<nurikata<<" "<<aa<<endl;
        ans+=aa;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7868
calculator = []
while True:
    a_, op, b_ = input().split(' ')
    a = int(a_)
    b = int(b_)
    if op == '?':
        break
    calculator.append([a, op, b])

for line in calculator:
    a, op, b = line
    if op == '+':
        res = a + b
    elif op == '-':
        res = a - b
    elif op == '*':
        res = a * b
    elif op == '/':
        res = a // b
    else:
        print(f"{a},{op},{b}")
        raise RuntimeError
    print(res)



Measured memory_bytes: 5612
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;
    string p[h];
    string p2[2 * h];
    for (int i = 0; i < h; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < h; i++)
    {
        p2[2 * i] = p[i];
        p2[2 * i + 1] = p[i];
    }
    for (int i = 0; i < 2 * h; i++)
    {
        cout << p2[i] << endl;
    }

    return 0;
}

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

int main() {
    ll K;
    cin >> K;
    //MAXが 50*10^16 に対し、最大が 10^16+1000 までしか許されていないので
    //最低でも上限の50分割する必要がある(と思う)
    const ll NUM = 50;
    ll count[NUM];
    if (K < NUM) {
        //K未満は例外。途中まで階段状にして、そこからは0Fillし余計にすすめない
        //0 0 0 0 0 0 0 0 0 10   : K=1だとこう
        //0 0 0 0 0 0 0 0 9 10   : K=1
        //0 0 0 0 0 0 0 8 9 10   : K=2
        rep(i, NUM) {
            if (i < NUM - K) {
                count[i] = 0;
            } else {
                count[i] = i + 1;
            }
        }
    } else {
        //1 2 3 4 5 6 7 8 9 10 : K = 10
        //1 2 3 4 5 6 7 8 9 11 : K = 11
        //1 2 3 4 5 6 7 8 10 11 : K = 12
        //階段状に定義。そのほうが1ずつ処理しやすい。
        //最大値をN減らしそれ以外を+1する＝1ステップでは全体として1しか減らない ことに注目
        //あとは上記のベースに対し、各項目を(K-10)回まで足せばいい
        //全項目を+1すると、ステップ数が+10される。
        ll base = K / NUM - 1;
        ll mod = K % NUM;
        rep(i, NUM) {
            count[i] = i + 1 + base;
            if (i >= NUM - mod) {
                count[i] += 1;
            }
        }
    }
    cout << NUM << endl;
    rep(i, NUM - 1) {
        cout << count[i] << " ";
    }
    cout << count[NUM - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
k=int(input())
x,y=map(int,input().split())

if k%2==0 and (x+y)%2!=0:
    print(-1)
    exit()

def f(x,y):
    if x<0:
        a,b=f(-x,y)
        return -a,b
    if y<0:
        a,b=f(x,-y)
        return a,-b
    if x<y:
        a,b=f(y,x)
        return b,a
    if x+y==k:
        return x,y
    if x+y<=k*2 and (x+y)%2==0:
        return (x+y)//2,(x+y)//2-k
    return k,0

p,q=0,0
ans=[]
while (p,q)!=(x,y):
    a,b=f(x-p,y-q)
    p+=a
    q+=b
    ans.append(str(p)+" "+str(q))

print(len(ans))
print('\n'.join(ans))

Measured memory_bytes: 24216
#include<stdio.h>

int main(){
	int A,B,C,day;
	int M,N,O;
	scanf("%d%d%d",&A,&B,&C);
	M=C/(7*A+B),N=C%(7*A+B);
	O=N/A;
	if (N/A>6) O=7;
	else if(N/A*A!=N) O=N/A+1;
	printf("%d\n",7*M+O);
	return 0;
}


Measured memory_bytes: 2112
def gcd(a,b):
	a,b=max(a,b),min(a,b)
	return a if b==0 else gcd(b,a%b)
def lcm(a,b):
	g=gcd(a,b)
	return a*b//g
n=int(input())
t=[int(input()) for _ in range(n)]
t=list(set(t))
l=t[0]
for i in t[1:]:
	l=lcm(l,i)
print(l)

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int H,W;
  cin>>H>>W;
  vector<string>S(H);
  for(int i=0;i<H;i++)cin>>S[i];
  int dh[4]={0,1,0,-1};
  int dw[4]={1,0,-1,0};
  ll ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        queue<pii>q;
        q.push({i,j});
        ll white=0;
        ll black=0;
        while(q.size()){
          int h=q.front().first;
          int w=q.front().second;
          q.pop();
          if(S[h][w]!='#')continue;
          black++;
          S[h][w]='b';
          for(int k=0;k<4;k++){
            int nh=h+dh[k];
            int nw=w+dw[k];
            if(0<=nh&&nh<H&&0<=nw&&nw<W&&S[nh][nw]=='.'){
              white++;
              S[nh][nw]='w';
              for(int l=0;l<4;l++){
                int nnh=nh+dh[l];
                int nnw=nw+dw[l];
                if(0<=nnh&&nnh<H&&0<=nnw&&nnw<W&&S[nnh][nnw]=='#'){
                  q.push({nnh,nnw});
                }
              }
            }
          }
        }
        ans+=white*black;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
xyh = []
xyh.sort(key=lambda x: x[2])
for _ in range(n):
    xyh.append(ai())

for cx in range(101):
    for cy in range(101):
        H = []
        d = []
        for x,y,h in xyh:
            H.append(h+abs(cx-x)+abs(cy-y))
            d.append(abs(cx-x)+abs(cy-y))
        hh = min(H)
        f = 0
        for i in range(n):
            if H[i] == d[i] > hh or (d[i] <= hh and H[i] == hh):
                continue
            else:
                f = 1
                break
        if f == 0:
            print(cx,cy,hh)
            exit()


Measured memory_bytes: 3064
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

// Mod int
// const int MOD = 1000000007;
struct mint{
    ll x;
    mint():x(0){}
    mint(ll x):x((x%MOD+MOD)%MOD){}
    mint operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
    mint operator+(const mint& a)const{ return mint(*this) += a;}
    mint operator-(const mint& a)const{ return mint(*this) -= a;}
    mint operator*(const mint& a)const{ return mint(*this) *= a;}
    bool operator==(const mint& a)const{ return x == a.x;}
    friend ostream& operator<<(ostream& os, const mint& mi)  
    {  
        os << mi.x;  
        return os;  
    }
};

mint func(int n){
	ll x;
	cin>>x;
	mint suf,sum;
	rep(i,n-1){
		ll t;
		cin>>t;
		suf += mint(t-x)*mint(i+1);
		sum += suf;
		x = t;
	}
	return sum;
}

void mainmain(){
	int n,m;
	cin>>n>>m;
	mint a = func(n);
	mint b = func(m);
	cout<<a*b<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,tmp;
  cin >> n;
  int a[100];
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n; i++){
    if(i>0) cout << " ";
    cout << a[i];
  }
  cout << endl;
  for(int i=1; i<n; i++){
    for(int j=0; j<i; j++){
      if(a[j] > a[i]){
        tmp = a[j];
        a[j] = a[i];
        a[i] = tmp;
      }
    }
    for(int j=0; j<n; j++){
      if(j>0) cout << " ";
      cout << a[j];
    }
    cout << endl;
  }
  return 0;
}



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

#define INF 1e9+1

int main(){
  int N; cin >> N;
  int dp[N+1][3] = {};
  for(int i=0; i<N+1; ++i){
    int a, b, c;
    cin >> a >> b >> c;
    if(i==0){
      dp[i][0] = a;
      dp[i][1] = b;
      dp[i][2] = c;
    }else{
      dp[i][0] = max(dp[i-1][1]+a, dp[i-1][2]+a);
      dp[i][1] = max(dp[i-1][0]+b, dp[i-1][2]+b);
      dp[i][2] = max(dp[i-1][1]+c, dp[i-1][0]+c);
    }
  }
  int ans = max({dp[N-1][0],dp[N-1][1],dp[N-1][2]});
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
    int N, L;
    string S[100];
    cin >> N >> L;
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }
    
    sort(S, S + N);
    string ans = "";
    for (int i = 0; i < N; i++)
    {
        ans += S[i];
    }
    

    cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	stack<int> s;
	for(int i=0;i<n;i++){
		int a;cin >> a;
		s.push(a);
	}
	for(int i=0;i<n;i++){
		if(i!=0) cout << " ";
		cout << s.top();
		s.pop();
	}
	cout << endl;
}

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

using namespace std;

int main()
{
  int N, K;
  cin>>N>>K;
  int A[N];
  int index;
  for (int i = 0; i < N; i++) {
      cin>>A[i];
  }

  if (N==K) {
    cout<<1<<endl;
    exit(0);
  }

  int x = 0;
  int min = (N+x)/K;
  while (true) {
      x++;
      min = (N+x)/K;
      if ((N+x)%K == 0 && x >= min-1) {
          break;
      }
  }

  cout<<min<<endl;
  
  return 0;
}



Measured memory_bytes: 640
N = gets.to_i
P = gets.split.map(&:to_i)
Q = gets.split.map(&:to_i)

a = b = nil
[*1..N].permutation(N).each_with_index do |n,i|
  a = i + 1 if P == n
  b = i + 1 if Q == n
  break if a && b
end
puts (a-b).abs


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

bool check(int count);

using namespace std;

int main() {
    int a, b;
    cin >> a;
    cin >> b;

    if (a <= 9 && b <= 9) {
        cout << a * b << endl;
        return 0;
    }
    cout << -1 << endl;


}


Measured memory_bytes: 256
n = int(input())
ds = {"hoge" : 0}
dt = {"hoge" : 0}
a = set()
for i in range(n):
    s = input()
    if s not in a:
        a.add(s)
        ds[s] =1
        dt[s] = 0
    else:
        ds[s] += 1
m = int(input())
for i in range(m):
    t = input()
    if t not in a:
        a.add(t)
        ds[t] = 0
        dt[t] = 1
    else:
        dt[t] += 1
b = 0
for i in a:
    c = ds[i] - dt[i]
    if b <= c:
        b = c
print(b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m,s;
  cin>>n;
  m=n;
  s=0;
  while (m>0) {
    s+=m%10;
    m/=10;
  }
  if (n%s==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){

    while(1){
        string s,t;
        cin >> s;
        if(s==".")break;
        cin >> t;
        vector<string> ss,tt;
        string te="";
        for(int i=0;i<s.size();i++){
            te+=s[i];
            if(s[i]=='"'||i==s.size()-1){
                ss.push_back(te);
                te="";
            }
        }
        te="";
        for(int i=0;i<t.size();i++){
            te+=t[i];
            if(t[i]=='"'||i==t.size()-1){
                tt.push_back(te);
                te="";
            }
        }
        bool dif=false;
        int cl=0;
        if(tt.size()!=ss.size()){
            dif=true;
        }
        for(int i=0;i<min(ss.size(),tt.size());i++){
            if(i%2==0){
                if(tt[i]!=ss[i]){
                    dif=true;
                }
            }else{
                if(tt[i]!=ss[i]){
                    cl++;
                }
            }
        }
        if(dif){
            cout << "DIFFERENT" << endl;
        }else{
            if(cl==1){
                cout << "CLOSE" << endl;
            }else if(cl>1){
                cout << "DIFFERENT" << endl;
            }else{
                cout << "IDENTICAL" << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3228
turn = int(input())
taropt = 0
hanapt=0
for i in range(turn):
    [taro, hanako] = input().split()
    if taro > hanako:
        taropt+=3
    elif taro < hanako:
        hanapt+=3
    else:
        taropt += 1
        hanapt+=1

print("{} {}".format(taropt,hanapt))


Measured memory_bytes: 5596
#include <cstdio>
#include <iostream>
#include <iomanip>
using namespace std;

int main(void)
{
    double r,a,b;
	cin >>r;
	a=r*r*3.141592653590;
	b=2*r*3.141592653590;
	printf("%.10lf", a);
	cout <<" ";
	printf("%.10lf\n", b);
	return 0;
}

Measured memory_bytes: 1252
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d,e,f,sec,g,h,j,k;

        for(int i=0;i<3;++i){
        cin>>a>>b>>c>>d>>e>>f;
        sec=3600*d+60*e+f-3600*a-60*b-c;
        g=sec/3600;
        h=sec%3600;
        j=h/60;
        k=h%60;

   cout<<g<<" "<<j<<" "<<k<<endl;}

    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    string str;
    cin >> str;
    
    vector<int> vec(N+1, 0);
    for(int i=0; i<N; i++) {
        if(str[i]=='W') vec[i+1]=vec[i]+1;
        else vec[i+1]=vec[i];
    }
    int ans=N;
    for(int i=0; i<N; i++) {
        ans = min(ans, (vec[i]-vec[0])+(N-1-i-(vec[N]-vec[i+1])));
    }
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 1796
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	int A,B,C,X;
	cin >> A >> B >> C;
	cin >> X;

	int cnt = 0;
	FOR(i,0,A+1){
		FOR(j,0,B+1){
			int p = X - 500 * i - 100 * j;
			if(p%50 == 0){
				int c = p/50;
				if(0<=c && c<= C) cnt++;
			}
		}
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

type data struct {
	s     string
	count int
}

type direction struct {
	x, y int
}

var S []string
var d []*data
var dpx [][]bool
var dpy [][]bool
var goalX, goalY int

func main() {
	tmp := ""
	fmt.Scan(&tmp)
	var x, y int
	fmt.Scan(&x, &y)
	length := len(tmp)
	goalX = length + x
	goalY = length + y
	var xFlag, yFlag bool
	S = strings.Split(tmp, "T")

	xMove := make([]int, 0)
	yMove := make([]int, 0)
	for i, s := range S {
		if i%2 == 0 {
			xMove = append(xMove, len(s))
		} else {
			yMove = append(yMove, len(s))
		}
	}

	if len(xMove) != 0 {
		dpx = make([][]bool, len(xMove))
		for i := 0; i < len(xMove); i++ {
			dpx[i] = make([]bool, length*2+1)
		}

		for x := 0; x <= length*2; x++ {
			if x == xMove[0]+length {
				dpx[0][x] = true
			} else {
				dpx[0][x] = false
			}
		}

		for i := 1; i < len(xMove); i++ {
			for x := 0; x <= length*2; x++ {
				if (x-xMove[i] >= 0 && dpx[i-1][x-xMove[i]]) || (x+xMove[i] < length*2 && dpx[i-1][x+xMove[i]]) {
					dpx[i][x] = true
				} else {
					dpx[i][x] = false
				}
			}
		}
		xFlag = goalX <= length*2 && dpx[len(xMove)-1][goalX]
	} else {
		xFlag = (goalX == length)
	}

	if len(yMove) != 0 {
		dpy = make([][]bool, len(yMove))
		for i := 0; i < len(yMove); i++ {
			dpy[i] = make([]bool, length*2+1)
		}

		for y := 0; y <= length*2; y++ {
			if y == yMove[0]+length || y == length-yMove[0] {
				dpy[0][y] = true
			} else {
				dpy[0][y] = false
			}
		}

		for i := 1; i < len(yMove); i++ {
			for y := 0; y <= length*2; y++ {
				if (y-yMove[i] >= 0 && dpy[i-1][y-yMove[i]]) || (y+yMove[i] < length*2 && dpy[i-1][y+yMove[i]]) {
					dpy[i][y] = true
				} else {
					dpx[i][y] = false
				}
			}
		}
		yFlag = goalY <= length*2 && dpy[len(yMove)-1][goalY]
	} else {
		yFlag = (goalY == length)
	}
	if xFlag && yFlag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 101248
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*切り上げの計算！*/
int maxtime(int x) {
	return(x + 9) / 10 * 10;

}
int main() {
	string s;
	cin >> s;
	int cnt = 0;
	int big = 0;
	for (int i = 0; i <= s.size() - 1; i++) {
		if (s[i] == 'A'|| s[i] == 'T'||s[i] == 'G'||s[i] == 'C') {
			cnt++;
		}
		else {
			big = max(cnt, big);
			cnt = 0;
		}
	}
	big = max(cnt, big);
	cout << big;
}

Measured memory_bytes: 256
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys



N = int(input())


def solve(l):
  td,xd,yd = [0,0,0]
  for i in range(N):
    t,x,y = l[i]
    td,xd,yd = [t-td, abs(x-xd), abs(y-yd)]
    if td < xd+yd:
      return False
    elif (td - xd - yd) & 1 > 0:
      return False
  return True


txy = [[0 for j in range(3)] for i in range(N)]
for i in range(N):
  txy[i] = list(map(int, input().split()))

if solve(txy):
  print("Yes")
else:
  print("No")



Measured memory_bytes: 69340
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize, m: usize,
    }
    let mut a = Vec::new();
    let mut c = Vec::new();
    for _ in 0..m {
        input!(aa: i64, b: usize);
        input!(cc: [Usize1; b]);
        a.push(aa);
        c.push(cc);
    }

    let mut keybit = Vec::new();
    for (i, cc) in c.into_iter().enumerate() {
        let mut bit = 0;
        for id in cc {
            bit += 1<<id;
        }
        keybit.push((bit, a[i]));
    }
    
    let mut dp = vec![vec![1<<50; 1<<n]; m + 1];
    dp[0][0] = 0;
    for i in 0..m {
        let (bit, value) = keybit[i];
        for j in 0..1<<n {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j | bit] = min(dp[i+1][j | bit], dp[i][j] + value);
        }
    }

    if dp[m][(1<<n) - 1] > 1<<40 {
        println!("-1");
    } else {
        println!("{}", dp[m][(1<<n) - 1]);
    }

}

Measured memory_bytes: 34132
#include<stdio.h>
int main(void){
  int A,B,i=0;
  char N[12]={'\0'};
  scanf("%d %d",&A,&B);
  scanf("%s",N);
  while(N[i]!='\0'){
    if((i!=A && N[i]=='-') || (i==A && N[i]!='-')){
      printf("No\n");
      return 0;
    }
    i++;
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    let keyence = "keyence";

    let ans = if s
        .chars()
        .zip(keyence.chars())
        .take_while(|&(c1, c2)| c1 == c2)
        .count()
        + s.chars()
            .rev()
            .zip(keyence.chars().rev())
            .take_while(|&(c1, c2)| c1 == c2)
            .count()
        >= keyence.len()
    {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main() {
  int N,T,A;
  cin>>N>>T>>A;
  
  vector<int> meruru(N);
  for(int i=0;i<N;i++){
    cin>>meruru.at(i);
  }
  
  vector<int> mimi(N);
  for(int i=0;i<N;i++){
    mimi.at(i)=1000*T-6*meruru.at(i);
  }
  
  int totori =0;
  int rorona=mimi.at(0);
  for(int i=1;i<N;i++){
    if(abs(rorona-1000*A)>abs(mimi.at(i)-1000*A)){
      rorona=mimi.at(i);
      totori=i;
    }
  }
  cout<<totori+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>

using namespace std;
const long long INF = 1e18;

struct Node {
	vector<int> to;
	vector<long long> edgeCost;
	long long cost;
	bool done;

	Node() : cost(INF), done(false){
	}
};

int main() {

	int n, m;

	cin >> n >> m;

	vector<Node> nodes(n);
	
	int a, b, c;
	while (cin >> a >> b >> c) {
		nodes[a - 1].to.push_back(b - 1);
		nodes[a - 1].edgeCost.push_back(-c);
	}
	nodes[0].cost = 0;

	int minus = false;

	for (int cnt = 0; cnt < n + 1; cnt++) {
		for (int i = 0; i < n; i++) {
			for (int e = 0; e < nodes[i].to.size(); e++) {
				if (nodes[i].cost != INF && nodes[nodes[i].to[e]].cost > nodes[i].cost + nodes[i].edgeCost[e]) {
					nodes[nodes[i].to[e]].cost = nodes[i].cost + nodes[i].edgeCost[e];
				
				}
			}
		}
	}		

	vector<Node> nodes2(nodes);

	for (int cnt = 0; cnt < n + 1; cnt++) {
		for (int i = 0; i < n; i++) {
			for (int e = 0; e < nodes2[i].to.size(); e++) {
				if (nodes2[i].cost != INF && nodes2[nodes2[i].to[e]].cost > nodes2[i].cost + nodes2[i].edgeCost[e]) {
					nodes2[nodes2[i].to[e]].cost = nodes2[i].cost + nodes2[i].edgeCost[e];

				}
			}
		}
	}


	if (nodes2[n - 1].cost < nodes[n - 1].cost) {
		cout << "inf";
	} else {
		cout << -nodes[n - 1].cost;
	}

	cout << endl;


	return 0;
}



Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        List<int> L = new List<int>() { Capacity = 2 * N };
        var s = Console.ReadLine().Split(' ');
        for(int i = 0; i < N; i++)
        {
            L.Add(int.Parse(s[2 * i]));
            L.Add(int.Parse(s[2 * i + 1]));
        }
        L.Sort((x, y) => x - y);
        int ctr = 0;
        for (int i = 0; i < N; i++)
            ctr += Math.Min(L[2 * i], L[2 * i + 1]);
        Console.WriteLine(ctr);
    }
}


Measured memory_bytes: 13268
import java.util.Scanner
import kotlin.system.exitProcess

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val arr = Array(n){Pair(scanner.nextInt(), scanner.nextInt())}
	arr.sortBy{it.second}
	var t = 0
	arr.forEach {
		t += it.first
		if (t>it.second) {
			println("No")
			exitProcess(0)
		}
	}
	println("Yes")
}

Measured memory_bytes: 131324
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/17/20 20:48:51
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,a,b; cin>>n>>a>>b;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    int k = i;
    while (k) {
      sum += k%10;
      k/=10;
    }
    if (sum >= a and sum <= b)
      ans += i;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>

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

using namespace std;

char *add(const char *aa,const char *bb){
	int m=strlen(aa),n=strlen(bb);
	int a[128]={},b[128]={};
	rep(i,m) a[i]=aa[m-i-1]-'0';
	rep(i,n) b[i]=bb[n-i-1]-'0';

	m=max(m,n);
	int c[128]={};
	rep(i,m){
		int tmp=c[i]+a[i]+b[i];
		c[i]=tmp%10;
		c[i+1]=tmp/10;
	}
	if(c[m]!=0) m++;

	static char cc[128];
	rep(i,m) cc[i]=c[m-i-1]+'0';
	cc[m]='\0';
	return cc;
}

int main(){
	for(char s[128];~scanf("%s",s);){
		char a[128],b[128],c[128];
		for(int i=0,p=0;;i++){
			if(s[i]=='+'){
				strncpy(a,s+p,i-p);
				a[i-p]='\0';
				p=i+1;
			}
			else if(s[i]=='='){
				strncpy(b,s+p,i-p);
				b[i-p]='\0';
				p=i+1;
			}
			else if(s[i]=='\0'){
				strncpy(c,s+p,i-p);
				c[i-p]='\0';
				break;
			}
		}

		vector<int> xa,xb,xc;
		for(int i=0;a[i];i++) if(a[i]=='X') xa.push_back(i);
		for(int i=0;b[i];i++) if(b[i]=='X') xb.push_back(i);
		for(int i=0;c[i];i++) if(c[i]=='X') xc.push_back(i);

		int x;
		for(x=0;x<10;x++){
			rep(i,xa.size()) a[xa[i]]=x+'0';
			rep(i,xb.size()) b[xb[i]]=x+'0';
			rep(i,xc.size()) c[xc[i]]=x+'0';
			if(strcmp(add(a,b),c)==0) break;
		}
		if(x<10) printf("%d\n",x);
		else     puts("NA");
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;



int H,W;
char c[10][10];
int gr[10][10];

string dir = "LURD";

int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};
int usd[32];

int getIndex(int x,int y,int dx,int dy){
	x += dx;
	y += dy;
	while( !(x < 0 || y < 0 || x >= W || y >= H) ){
		if( gr[y][x] != -1 && usd[gr[y][x]] == 0 ){
			return gr[y][x];
		}
		x += dx;
		y += dy;
	}
	//cout << x << " " << y << "(" << dx << " " << dy << ")" << endl;
	return -1;
}
int kx[32];
int ky[32];
int done2[32];
int test(int g,int d){
	if( done2[g]++ ) return 0;
	int ans = 1;
	for(int i = 0 ; i < 4 ; i++){
		if( i == 2 ) continue;
		int p = getIndex(kx[g],ky[g],dx[(d+i)&3],dy[(d+i)&3]);
		//cout << g << " " << dir[(d+i)&3] << " " << p << endl;
		if( p == -1 ) continue;
		ans += test(p,(d+i)&3);
	}
	return ans;
}
char doit[32];
int cnt = 0;

int dfs(int g,int d,int r){
	if( r == 1 ){
		cout << doit << endl;
		exit(0);
	}
	memset(done2,0,sizeof(done2));
	int w = test(g,d);
	/*if( w != r ){
		return 0;
	}*/
	usd[g] = 1;
	for(int i = 0 ; i < 4 ; i++){
		doit[cnt-r] = dir[(d+i)&3];
		if( i == 2 ) continue;
		int p = getIndex(kx[g],ky[g],dx[(d+i)&3],dy[(d+i)&3]);
		if( p == -1 ) continue;
		dfs(p,(d+i)&3,r-1);
	}
	usd[g] = 0;
}
int main(){
	memset(gr,-1,sizeof(gr));
	cin >> H >> W;
	int sd,sp;
	for(int i = 0 ; i < H ; i++){
		for(int j = 0 ; j < W ; j++){
			cin >> c[i][j];
			if( c[i][j] != '.' ){
				kx[cnt] = j;
				ky[cnt] = i;				
				gr[i][j] = cnt++;
				
				if( c[i][j] != 'o' ){
					sd = dir.find(c[i][j]);
					sp = cnt-1;
				}
			}
		}
	}
	dfs(sp,sd,cnt);
	while(1){}
}

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

int main() {
  vector<char> vec(3);
  int a = 0, b = 0, c = 0;
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
    if (vec.at(i) == 'a') a++;
    else if (vec.at(i) == 'b') b++;
    else if (vec.at(i) == 'c') c++;
      
  }
  if (a == 1 && b == 1 && c == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll A, B, C, K; cin >> A >> B >> C >> K;
    ll ans = 0;
    ll t = 0;
    t = min(A, K);
    ans += t;
    K -= t;

    t = min(B, K);
    K -= t;

    t = min(C, K);
    ans -= t;
    K -= t;

    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int N=1e6+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int n;
int a[N];
int ans[N];
int main(){Accel
	cin>>n;
	int p=0,s=0;
	FOR(i,1,n){
		cin>>a[i];
		s+=abs(a[i]-p);
		p=a[i];
	}
	s+=abs(p);
	//cout<<s<<endl;
	FOR(i,1,n){
		int k=abs(a[i]-a[i-1])+abs(a[i]-a[i+1]);
		cout<<s-k+abs(a[i-1]-a[i+1])<<endl;
	}
}

Measured memory_bytes: 5376
#include<stdio.h>
#include<math.h>
  
int main(void){
  int a[10],i,j,k;
  while(scanf("%d",&k)!=EOF){
    if(k==0){
      break;
    }
    if(k>=1024){
      break;
    }
    for(i=0;k>1;k/=2,i++){
      a[i]=k%2;
    }
    for(j=0;j<i;j++){
      if(a[j]==1) {
    printf("%d ",(int)pow(2,j));
      }
    }
    if(k==1){
      printf("%d\n",(int)pow(2,j));
    }else{
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1876
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = LLONG_MAX;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
int f(int a,int b,int c) {
    return a*a+b*b+c*c+a*b+b*c+c*a;
}
int main() {
    int n;cin>> n;
    vector<tuple<int,int,int>> ans;
    rep1(i, n) {
        int count = 0;
        for(int x= 1;x<=sqrt(i);x++) {
            for(int y = x;y<=sqrt(i);y++){
                for(int z=y;z<=sqrt(i);z++) {
                    if(f(x,y,z)==i){
                        // cout << "ok" << endl;
                        set<int> st;
                        st.insert(x);st.insert(y);st.insert(z);
                        if(st.size()==1) count+=1;
                        else if(st.size()==2) count+=3;
                        else if(st.size()==3) count+=6;
                        continue;
                    }
                }
            }
        }
        cout << count << endl;
    }
    // cout << f(2,3,4) << endl;
    return 0;
}

Measured memory_bytes: 3720
#include "cstdio"
long long f[300][8000]={1},a,x,n,s,i,j,k;
int main(){
	scanf("%lld%lld",&n,&a);
	for(i=1;i<=n;i++){
		scanf("%lld",&x);
		for(j=i;j>=1;j--)
		for(k=a*n;k>=x;k--)
		f[j][k]+=f[j-1][k-x];
	}
	for(i=1;i<=n;i++)
	s+=f[i][a*i];
	printf("%lld\n",s);
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<queue>
#define ll long long
using namespace std;
int main() {
	ll n,x=LLONG_MAX;
	cin >> n;
	for (ll i = 1; i <=sqrt(n); i++) {
		if (n%i == 0) {
			x = min(x, (i + n / i - 2));
			//cout << x << endl;
		}
	}

	cout << x << endl;
}

Measured memory_bytes: 384