akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Graph {
    struct Vertex { int n, d; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, int p, int d) {
        v[i].d = d % 2 + 1;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;
            dfs(o.i, i, d + 1);
        }
    }
    void solve() {
        int p[3];
        p[1] = (n + 2) / 3;
        p[2] = (n + 1) / 3;
        p[0] = n / 3;

        int q[3] = {};
        for (int i = 0; i < n; i++) {
            q[v[i].d]++;
        }

        for (int h = 1; h < 3; h++) {
            if (q[h] < p[h]) {
                int h1 = 3 - h, k = p[h];
                for (int i = 0; i < n; i++) {
                    if (v[i].d == h) {
                        v[i].d = 0;
                    } else {
                        v[i].d = --k >= 0 ? h : h1;
                    }
                }
                q[0] = q[1] = q[2] = 0;
                for (int i = 0; i < n; i++) {
                    q[v[i].d]++;
                }
                break;
            }
        }

        for (int h = 1; h < 3; h++) {
            int t = q[h] - p[h];
            if (t > 0) {
                for (int i = 0; i < n; i++) {
                    if (v[i].d == h) {
                        v[i].d = 0;
                        if (--t == 0) break;
                    }
                }
            }
        }

        int r[3] = { 3, 1, 2 };
        for (int i = 0; i < n; i++) {
            int &t = r[v[i].d];
            v[i].d = t;
            t += 3;
        }

        for (int i = 0; i < n; i++) {
            cout << v[i].d << " \n"[i == n - 1];
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n;
    cin >> n;

    if (n <= 3) {
        for (int i = 0; i < n; i++) {
            cout << i + 1 << " \n"[i == n - 1];
        }
        exit(0);
    }

    Graph g(n, (n - 1) * 2);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.dfs(0, -1, 0);
    g.solve();

    //1201201201
    //ダメなのは11と22のみ
    //否定とってみるか あるijについて11,22かつ距離が3
    //1と2だけ見ればいい n/3個くらいある1を距離3にならないよう配置できるか
    //枝分かれがなかったら？ 
    //あれ、交互にやればいいのでは しかし個数に偏りが出たら？
    //うに同士をくっつけたやつ考えても無理なケース思いつかんがこれを構成するのもしんどそう
    //ジャッジどうやって書くんだこれ
    //根付き木の深さの偶奇で頂点を分けて2つの木を作る サイズに差があるときが問題
    //大きいほうの木を
    //隣に1がある頂点と隣に1がある頂点を結んではいけない

    //D問題
    //aがでかいほど先に回りたくなる まあ両方小さいのがいいけど aもbも小さいとあとで行ける
    //店毎に、いつまでに入店しないといけないかがわかる
    //最後に店iに行くとするとその前に行くならいつまでに入店するか各店についてわかる
    //店は1秒早く行くと1+a_i秒早く買える

    return 0;
}

Measured memory_bytes: 7936
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll dp[410][410] = {},A[410],S[410] = {0};

int main(){
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		S[i] = S[i-1]+A[i];
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			if(i==j) dp[i][j] = 0;
			else dp[i][j] = 1e18;
		}
	}
	for(int i=1;i<N;i++){
		for(int j=1;j<=N-i;j++){
			for(int k=j;k<j+i;k++){
				dp[j][j+i] = min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]);
			}
			dp[j][j+i] += S[j+i]-S[j-1];
		}
	}
	cout << dp[1][N] << endl;
}

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

int main(){
  ll N;
  cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  for(ll i=0;i<N;i++){
    ll x,y;
    cin >> x >> y;
    X[i]=x;
    Y[i]=y;
  }
  ll tot=1;
  for(ll i=1;i<=N;i++){
    tot *= i;
  }
  double dist=0;
  vector<ll> Root(N,0);
  iota(Root.begin(),Root.end(),1);
  do{
    for(ll i=0;i<N-1;i++){
      dist += sqrt( (X[Root[i]-1]-X[Root[i+1]-1])*(X[Root[i]-1]-X[Root[i+1]-1]) + 
                  (Y[Root[i]-1]-Y[Root[i+1]-1])*(Y[Root[i]-1]-Y[Root[i+1]-1]));
    }
  }while(next_permutation(Root.begin(),Root.end()));
  cout << fixed << setprecision(10);
  cout << dist/(double)tot << endl;
}



Measured memory_bytes: 3816
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  int i=0;
  char s[100];
  int x[101];

  while(scanf("%s", s)!= EOF){
    if(s[0]==' ')
      continue;
    else if(s[0]=='+'){
      x[i-2] = x[i-2]+x[i-1];
      i--;
    }else if(s[0]=='-'){
      x[i-2] = x[i-2]-x[i-1];
      i--;
    }else if(s[0]=='*'){
      x[i-2] = x[i-2]*x[i-1];
      i--;
    }else{
      x[i] = atoi(s);
      i++;
    }
  }

  printf("%d\n",x[0]);
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int n;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int p_i = 0, m_i = 0;
    REP(i, n) if(a[p_i] < a[i]) p_i = i;
    REP(i, n) if(a[m_i] > a[i]) m_i = i;
    
    cout << n*2-1 << endl;
    if(abs(a[p_i]) >= abs(a[m_i])){
        REP(i, n) if(i != p_i) cout << p_i+1 << " " << i+1 << endl;
        cout << p_i+1 << " " << p_i+1 << endl;
        REP(i, n-1) cout << i+1 << " " << i+2 << endl;
    }else{
        REP(i, n) if(i != m_i) cout << m_i+1 << " " << i+1 << endl;
        cout << m_i+1 << " " << m_i+1 << endl;
        REP(i, n-1) cout << n-i << " " << n-i-1 << endl;
    }
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = [i for i in range(n+1)]
a.reverse()
s = 0
l = k-1
c = sum(a[:k])
for i in range(k,n+2):
	#print (a[-1*i:])
	s += c - (i-1)*i//2 + 1
	s %= 10**9+7
	l += 1
	if l >= n+1:
		break
	c += a[l]
print (s)

Measured memory_bytes: 18304
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  vector<double> v(N);
  for (int i = 0; i < N; i++) cin >> v.at(i);
  sort(v.begin(), v.end());
  while(v.size() > 1) {
    double new_v = (v[0] + v[1])/2;
    v.erase(v.begin());
    v[0] = new_v;
  }
  cout << v[0] << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

class SegTree():
	def __init__(self, a, func, idem):
		#the number of nodes is 2n-1
		self.n = 1 << len(a).bit_length()
		self.size = len(a)
		self.func = func
		self.idem = idem
		self.node = [idem] * (2*self.n-1)
		for i in range(len(a)+self.n-2, -1, -1):
			if i >= self.n-1:
				self.node[i] = a[i-self.n+1]
			else:
				self.node[i] = self.func(self.node[2*i+1], self.node[2*i+2])

	def get(self, x):
		return self.node[x+self.n-1]

	def set(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)>>1
			self.node[x] = self.func(self.node[2*x+1], self.node[2*x+2])
		return

	#[l, r)
	def prod(self, l, r):
		L, R = l+self.n, r+self.n
		s_l, s_r = self.idem, self.idem
		while L<R:
			if R & 1:
				R -= 1
				s_r = self.func(self.node[R-1], s_r)
			if L & 1:
				s_l = self.func(s_l, self.node[L-1])
				L += 1
			L >>= 1
			R >>= 1
		return self.func(s_l, s_r)

	#maximum of r (within [l, n)) which satisfies val(prod(l, r))
	def max_right(self, l, val):
		if l == self.size:
			return self.size
		L = l + self.n
		s = self.idem
		while True:
			while (L % 2 == 0):
				L >>= 1
			if not val(self.func(s, self.node[L-1])):
				while L < self.n:
					L <<= 1
					if val(self.func(s, self.node[L-1])):
						s = self.func(s, self.node[L-1])
						L += 1
				return L - self.n
			s = self.func(s, self.node[L-1])
			L += 1
			if (L & -L) == L:
				return self.size

	#minimum of l (within [0, r)) which satisfies val(prod(l, r))
	def min_left(self, r, val):
		if r == 0:
			return 0
		R = r + self.n
		s = self.idem
		while True:
			R -= 1
			while R > 1 and R % 2:
				R >>= 1
			if not val(self.func(self.node[R-1], s)):
				while R < self.n:
					R = (R << 1) + 1
					if val(self.func(self.node[R-1], s)):
						s = self.func(self.node[R-1], s)
						R -= 1
				return R + 1 - self.n
			s = self.func(self.node[R-1], s)
			if (R & -R) == R:
				return 0


n, q = map(int, input().split())
a = list(map(int, input().split()))
st = SegTree(a, max, 0)
for _ in range(q):
	t, x, y = map(int, input().split())
	if t == 1:
		st.set(x-1, y)
	elif t == 2:
		print(st.prod(x-1, y))
	else:
		print(st.max_right(x-1, lambda z: z < y) + 1)

Measured memory_bytes: 97224
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int N, K, A[100000];
	cin >> N >> K;
	REP(i, N) {
		cin >> A[i];
	}

	int ans = 1 + (N - 2) / (K - 1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll h(ll n,ll j){
  ll k=1;
  if(n-j>=j){
  for(int i=n;i>=n-j+1;i--){
    k*=i;
  }
  for(int i=j;i>0;i--){
    k/=i;
  }
  return k;
  }
  else{
    ll g=n-j;
    ll k=1;
    for(int i=n;i>=j+1;i--){
      k*=i;
    }
    for(int i=g;i>=1;i--){
      k/=i;
    }
    return k;
  }
}
ll kk(ll n){
  ll k=1;
  rep(i,n){
    k*=2;
  }
  return k;
}
int main(){
  ll n,p;
  cin>>n>>p;
  vll a(n);
  ll a0=0;
  ll a1=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]%2==0) a0++;
    else a1++;
  }
  sort(all(a));
  ll ans=0;
  if(a1==0){
    if(p){
      COUT(0);
    }
    else{
      COUT(kk(n));
    }
  }
  else{
    COUT(kk(n-1));
  }
}
    


Measured memory_bytes: 256
from itertools import accumulate


def main():
    number, operations = [int(x) for x in input().split()]
    dists = [int(x) for x in input().split()]

    for _ in range(operations):
        temp = [0] * (number + 1)
        for i, v in enumerate(dists):
            left = max(i - v, 0)
            right = min(i + v + 1, number)
            temp[left] += 1
            temp[right] -= 1
        templi = list(accumulate(temp))
        if templi == dists:
            break
        else:
            dists = templi
    dists.pop()
    print(*dists)


if __name__ == '__main__':
    main()

# Pypy 3 なら通る。Python 3 では無理。


Measured memory_bytes: 178836
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    long long N;
    cin >> N;
    if (N <= 2) {
        cout << 0 << endl;
        return 0;
    }
    
    long long ans = N-1;
    for (long long i = 2; i <= sqrt(N); i++) {
        if (N/(i-1) == N%(i-1)) ans += (i-1);
        long long temp = N/i;
        if (N/(temp-1) == N%(temp-1)) ans += (temp-1);
    }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] s = new int[n + 1];
        for (int i = 0; i < n; i++) {
            s[i] = scanner.nextInt();
        }
        int q = scanner.nextInt();
        int[] t = new int[q];
        for (int i = 0; i < q; i++) {
            t[i] = scanner.nextInt();
        }
        int count = 0;
        for (int i = 0; i < q; i++) {
            if (LinearSearch(s, t[i])) {
                count++;
            }
        }
        System.out.println(count);
    }

    static boolean LinearSearch(int[] a, int key) {
        int i = 0;
        a[a.length - 1] = key;
        while (a[i] != key) {
            i++;
        }
        if (i == a.length - 1) {
            return false;
        }
        return true;
    }
}


Measured memory_bytes: 40136
import bisect
    
def main():
    while True:
        d = int(input())
        if d == 0:
            break
        n = int(input())
        m = int(input())
        s = [0] + [int(input()) for i in range(n - 1)] + [d]
        s.sort()
        
        print(sum(dist(s, int(input())) for i in range(m)))

def dist(s, o):
    return min(o- s[bisect.bisect_right(s, o) - 1], s[bisect.bisect_left(s,o)] - o)
        
if __name__=="__main__":
	main()


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

int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    unordered_map<int, int> mp;
    for(int i = 0; i < N; i++) mp[A[i]]++;
    int ans = 0;
    for(int X = 0; X <= 1e5; X++){
        ans = max(ans, mp[X] + mp[X-1] + mp[X+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4772
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
using namespace std;
int a[200000+5];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ABC104A
{
    class ABC104A
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            bool b = Solve(n);

            Console.WriteLine(b ? "Yes" : "No");
        }

        static bool Solve(int n)
        {
            if (n % 4 == 0)
            {
                return true;
            }

            int calc = n;
            while (calc >= 0)
            {
                if (calc % 4 == 0)
                {
                    return true;
                }

                calc -= 7;
            }

            return false;
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int dxy[5]={0,1,0,-1,0};
int main(){
    bool fld[30][30];
    int n,m;
    while(scanf("%d",&n),n){
        fill_n(fld[0],900,false);
        for(int i=0;i<n;i++){
            int y,x;
            scanf("%d%d",&x,&y);
            fld[y][x]=true;
        }
        scanf("%d",&m);
        int cnt=0;
        int y=10,x=10;
        while(m--){
            char d;
            int t;
            scanf(" %c %d",&d,&t);
            int D;
            switch(d){
            case 'N':
                D=0;
                break;
            case 'E':
                D=1;
                break;
            case 'S':
                D=2;
                break;
            default:
                D=3;
            }
            for(int i=0;i<t;i++){
                y+=dxy[D+1];x+=dxy[D];
                if(fld[y][x]){
                    cnt++;
                    fld[y][x]=false;
                }
            }
        }
        if(n==cnt)puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 1012
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;

int Q;

LL Get(LL M)
{
	LL L = 0, R = 1000000010;
	while (L < R - 1) {
		LL mid = (L + R) / 2;
		if (mid * mid <= M) L = mid; else R = mid;
	}
	return L;
}

int main()
{
	scanf("%d", &Q);
	for (int cas = 1; cas <= Q; cas++) {
		LL A, B, ans; scanf("%lld%lld", &A, &B);
		LL M = A * B - 1; LL sq = Get(M);
		if (sq * (sq + 1) > M) ans = 2 * sq - 1; else ans = 2 * sq;
		if (A * A <= M) ans--; if (B * B <= M) ans--;
		printf("%lld\n", ans);
	}
	return 0;	
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////



	
int main() {	
	
	ll M, K;
	cin >> M >> K;

	ll a[MAX];

	ll N = pow(2, M);

	if (M == 0) {
		if (K == 0) { cout << "0 0"; }
		else { cout << "-1"; }
	}

	else if (M == 1) {
		if (K == 0) { cout << "0 0 1 1"; }
		else { cout << "-1"; }
	}

	else if (K >= N) { cout << -1; }

	else {
		rep(i, N) {
			if (i != K) { cout << i<<" "; }
		}
		cout << K <<" ";
		
		rep(i, N) {
			if (N - 1 - i != K) { cout << N - 1 - i << " "; }
		}


		cout << K;

	}

	system("PAUSE");


}

Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll mod = 1e9+7;

ll cnt(ll a, ll x) {
    if (a < 0) return 0;
    return a/x + 1;
}

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll ret = cnt(b, x) - cnt(a-1,x); 
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long long triangular_relationship(int n, int k) {
  if (k % 2 == 0) {
    long long a = n / k;
    long long b = (n + (k/2)) / k;
    return a*a*a + b*b*b;
  }
  long long a = n / k;
  return a*a*a;
}
int main() {
    long long n, k;
    cin >> n >> k;
    cout << triangular_relationship(n, k);
}

Measured memory_bytes: 256
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}

int main(void){
    int i,j,n,m,k,a[262144],b,c,w,r=0,l,t;
    double d;
    char s[262144];
    scanf("%d%d",&n,&k);
    //l=strlen(s);
    //for(i=0;i<n;i++){scanf("%d",&a[i]);}
    //qsort(a,n,sizeof(int),sortfncsj);
    if(lcm(n,k) == n){printf("-1\n");return 0;}
    printf("%d\n",n);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	int size, edge[][];
	int queue[];
	int first, last;

	int[] topologicalSort() {
		int res[] = new int[size];
		int flg[] = new int[size];
		int id = 0;
		boolean isUpdate = true;
		while (isUpdate) {
			isUpdate = false;
			for (int v = 0; v < size; v++) {
				if (flg[v] == 1) continue;
				int u;
				for (u = 0; u < size; u++) {
					if (flg[u] == 0 && u != v && edge[u][v] == 1) {
						break;
					}
				}
				if (u == size) {
					res[id++] = v;
					flg[v] = 1;
					isUpdate = true;
				}
			}
		}
		if (id == size)
			return res;
		else
			return null;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();
		size = n;
		edge = new int[n][n];
		for (int i = 0; i < m; i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			edge[x][y] = 1;
		}
		int top[] = topologicalSort();
		if (top != null) {
			for (int i = 0; i < n; i++) {
				System.out.println(top[i] + 1);
			}
		} else {
			System.out.println("NA");
		}
	}

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

Measured memory_bytes: 18408
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

string s1,s2;
vector<vector<ll>> table;
ll dp(ll n1,ll n2){
  //cout<<n1<<" "<<n2<<endl;
  if(n1<0) return n2+1;
  if(n2<0) return n1+1;
  if(table.at(n1).at(n2)<INF) return table.at(n1).at(n2);
  
  table.at(n1).at(n2)--;
  if(s1.at(n1)==s2.at(n2)){
    chmin(table.at(n1).at(n2),dp(n1-1,n2-1));
    return table.at(n1).at(n2);
  }
  chmin(table.at(n1).at(n2),dp(n1-1,n2)+1);
  chmin(table.at(n1).at(n2),dp(n1,n2-1)+1);
  chmin(table.at(n1).at(n2),dp(n1-1,n2-1)+1);
  return table.at(n1).at(n2);
}

int main()
{
  cin>>s1>>s2;
  ll N1=s1.size(),N2=s2.size();
  //cout<<s1<<" "<<s2<<endl;
  table=vector<vector<ll>>(N1,vector<ll>(N2,INF));
  
  cout<<dp(N1-1,N2-1)<<endl;
  /*
  rep(i,N1){
    rep(j,N2){
      if(j!=0) cout<<" ";
      if(table.at(i).at(j)>1000) cout<<"L";
      else cout<<table.at(i).at(j);
    }
    cout<<endl;
  }
  */
  return 0;
}



Measured memory_bytes: 10796
#include<stdio.h>
int main()
{
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int r=0;
  for(;;)
  {
    if(a%2+b%2+c%2!=0)break;
    if(a==b&b==c)
    {
      printf("-1\n");
      return 0;
    }
    int s=a/2+b/2+c/2;
    a=s-a/2,b=s-b/2,c=s-c/2;
    r++;
  }
  printf("%d\n",r);
}

Measured memory_bytes: 128
x=!!gets,!gets;x.map{|a|x.map{|b|c,d,*k=a,b;$_.chop.chars{|i|d^=c^=i<?p;k<<c^=d};c^a||d^b||k.map{|x|$>.<<x ??S:?W}+exit}};p~0

Measured memory_bytes: 6388
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> b(n-1);
  for(int i=0; i<n-1; i++) cin >> b[i];
  int ans;
  ans += b[0] + b[n-2];
  for(int i=0; i<n-2; i++) ans += min(b[i],b[i+1]);
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char ch = sc.next().trim().charAt(0);
		
		StringBuilder sb = new StringBuilder();
		
		if(ch >= 'A' && ch <='Z')
			sb.append('A' + "\n");
		else if(ch >='a' && ch <= 'z')
			sb.append('a' + "\n");
		
		sc.close();
		
		System.out.println(sb);
	}

}

Measured memory_bytes: 35624
#include <bits/stdc++.h>
using namespace std;
// calculate |gcd|.
// if  ether num is 0, return 0
long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long LCM(long long left, long long right) {
  return left * right / GCD(left, right);
}
long long n, m, x;
string s, t;

long long solve();

int main() {
  cin >> n >> m >> s >> t;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long now = 0;
  x = LCM(n, m);
  n = x / n;
  m = x / m;
  now = n * m;
  for(long long i = 0; i < x; i += now)
    if(s[i / n] != t[i / m]) return -1;
  return x;
}


Measured memory_bytes: 512
until (n = gets.chomp.to_i) == 0 ? true:false
h = Hash.new
n.times do
  line = gets.split{" "}
  h[line[0]] = line[1]
end
n = gets.chomp.to_i
n.times do
  word = gets.chomp
  print ((h[word] == nil) ? word : h[word])
end
print "\n"
end

Measured memory_bytes: 6108
/*
  AtCoder Beginner Contest 091
  A - Two Coins
*/

#include<iostream>
using namespace std;

int A, B, C;

int main() {
  scanf("%d%d%d", &A, &B, &C);
  if (A + B >= C) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

typedef long long ll;

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   
   int n;
   cin>>n;
   bool dp[35][100010];
   dp[0][0]=true;
   rep(i,31)
   rep(j,100001)
   {
     if(dp[i][j]==true){
       dp[i+1][j]=true;
       int s=1;
       for(;s+j<=100000;){
         dp[i+1][j+s]=true;
         s*=6;
         }
       s=9;
       for(;s+j<=100000;){
         dp[i+1][j+s]=true;
         s*=9;
         }
      }
   }
   rep(i,31)
     if(dp[i][n]==true){
     cout<<i<<endl;
     break;
     }
   return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    int c, n = 10;
    c = b;
    while(c/10>0) {
        n *= 10;
        c /= 10;
    }

    n *= a;
    n += b;
    // printf("%d\n", n);

    int t=1, count=1;
    while(t<n) {
        t = count*count;
        count += 1;
    }

    // printf("%d\n", t);

    if(n==t) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  if(s.size()<t.size()) cout<<"No\n";
  else{
    s+=s;
    for (int i = 0; i < s.size()/2; ++i)
    {
      bool f=1;
      for (int j = 0; j < t.size(); ++j) if(s.at(i+j)!=t.at(j)) f=0;
      if(f){
        cout<<"Yes\n";
        break;
      }
      if(i==s.size()/2-1) cout<<"No\n";
    }
  }
}


Measured memory_bytes: 3212
#include<iostream>
using namespace std;
int main()
{
    long n;
    int a,b,c,d;
    cin>>n;
    d=n%10;
    n=n/10;
    c=n%10;
    n=n/10;
    b=n%10;
    n=n/10;
    a=n%10;
    if(a+b+c+d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else if(a-b+c-d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }
    else if(a+b-c+d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }
    else  if(a+b+c-d==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    }
      else  if(a+b-c-d==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
      else  if(a-b-c-d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7<<endl;
    }
      else  if(a-b-c+d==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7<<endl;
    }
      else  if(a-b+c+d==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7<<endl;
    }
}



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

int main() {
int A,B,C;
  cin >> A >> B >> C;
  if ((B-C)>=0){
    cout << "delicious" << endl;
  } else if ((A+B-C)>=0){
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
    
  }

}


Measured memory_bytes: 256
S = str(input())
fr = int(S[0]+S[1])
sc = int(S[2]+S[3])

if fr<=12 and fr!=0:
  if sc<=12 and sc!=0:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if sc<=12 and sc!=0:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
ll c;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s, t;
    cin >> s >> t;
    for(int i = 0;i < s.size();++i)
        c += (s[i] != t[i]);
    cout << c;
    return 0;
}


Measured memory_bytes: 3792
n,k = map(int,input().split())
xarr = list(map(int,input().split()))

minus = []
plus = []
for x in xarr:
    if x < 0:
        minus.append(x)
    else:
        plus.append(x)

ans = 0
if len(minus) == 0:
    ans = plus[k-1]
elif len(plus) == 0:
    ans = abs(minus[-k])
else:
    acm = [0]
    acp = [0]
    ans = 1000000000000000000000
    for i in range(len(minus)):
        acm.append(abs(minus[-i-1]))
    for i in range(len(plus)):
        acp.append(plus[i])

    for i in range(len(minus)+1):
        temp1 = 0
        temp2 = 0
        if i > k:
            break
        lest = k-i
        if lest > len(plus):
            continue
        temp1 = acm[i]*2+acp[lest]
        temp2 = acm[i]+acp[lest]*2
        t = min(temp1,temp2)
        # print(i,lest,temp1,temp2)
        if t < ans:
            ans= t
    # if k <= len(plus):
    #     t = plus[k-1]
    #     if t < ans:
    #         ans = t

print(ans)

Measured memory_bytes: 14452
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

    if(X==2){
        cout << 2;
        return 0;
    }

    vector<int> primes;
    primes.push_back(2);
    for(int i=3; i < X; i+=2){
        int fl = 0;
        for(auto it = primes.begin(); it != primes.end(); ++it){
            if(i % *it == 0){
                fl = 1;
                break;
            }
        }

        if(fl != 1) primes.push_back(i);

    }

    int np = -1;
    while(np==-1){
        int fl = 0;
        for(auto it = primes.begin(); it != primes.end(); ++it){
            if(X % *it == 0){
                fl = 1;
                break;
            }
        }
        if(fl == 0){
            np = X;
            break;
        }
        X++;
    }

    cout << X;

    return 0;
}

Measured memory_bytes: 384
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"; exit $?
exit 0
'''
import sys

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]
mod = 10**9 + 7

n= _i()
a= _ia()
z = [ 0 ] * 60
o = [ 0 ] * 60

for ai in a:
    b = bin(ai)[2:]
    for i,c in enumerate(reversed(b)):
        if c=="0": z[i]+=1
        else: o[i]+=1
    #
    for i in range(len(b),60): z[i]+=1
#
ans = 0
base = 1
for zz,oo in zip(z,o):
    ans = ( ans + ( base * zz*oo ) ) % mod
    base = (base * 2) % mod
#
print(ans)


Measured memory_bytes: 124304
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
q = int(input())

total = sum(A) # これを基に各queryに対応(加算、減算)する

l = [0 for i in range(10**5+1)] # 配列のインデックスを各valueとみなす
for _ in A: # 各インデックスに各keyを加算
    l[_] += 1

for i in range(q):
    b, c = map(int,input().split())
    total += c * l[b] # totalの調整のみ
    total -= b * l[b] # 同上
    print(total)
    l[c] += l[b] # ここでリストの更新
    l[b] = 0 # 同上



Measured memory_bytes: 20188
s=input()
n=len(s)
dp=[[0]*13 for i in range(n+1)]
dp[0][0]=1
mod=10**9+7

for i in range(n):
  if s[i]=="?":
    for j in range(10):
      for k in range(13):
        dp[i+1][(k*10+j)%13]+=dp[i][k]%mod
  else:
    for k in range(13):
      dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
      
print(dp[-1][5]%mod)


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

using namespace std;

typedef pair<string, int> P;

int main()
{
  int N, Q;
  while(cin >> N >> Q, N || Q){
    map<int, P> mp;
    while(N--){
      string eraname;
      int base, west;
      cin >> eraname >> base >> west;
      mp[west] = P(eraname, base);
    }
    while(Q--){
      int y;
      cin >> y;
      map<int, P>::iterator it = mp.lower_bound(y);
      if(it == mp.end()){
	cout << "Unknown" << endl;
      } else if(it->first - (it->second).second < y && y <= it->first){
	cout << (it->second).first << " " << y - it->first + (it->second).second << endl;
      } else {
	cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

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

int H, W;
vector<string> path;

int dh[4] = {-1, 1, 0, 0};
int dw[4] = {0, 0, -1, 1};

int get(int h, int w){
    queue<pair<int, int>> que;
    vector<vector<int>> dist(H, vector<int>(W, 1e9));
    dist[h][w] = 0;
    que.push({h, w});
    while(!que.empty()){
        int h1 = que.front().first;
        int w1 = que.front().second;
        que.pop();

        for(int i=0; i<4; i++){
            int h2 = h1 + dh[i];
            int w2 = w1 + dw[i];
            if(0 <= h2 && h2 < H && 0 <= w2 && w2 < W){
                if(path[h2][w2] == '.' && dist[h2][w2] > dist[h1][w1] + 1){
                    dist[h2][w2] = dist[h1][w1] + 1;
                    que.push({h2, w2});
                }
            }
        }
    }

    int ret = 0;
    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(dist[i][j] != 1e9)
            ret = max(ret, dist[i][j]);
    }
    return ret; 
}

int main(){  
    cin >> H >> W;
    path.resize(H);
    for(int h=0; h<H; h++)
        cin >> path[h];
    
    int ans = 0;
    for(int h=0; h<H; h++) for(int w=0; w<W; w++){
        if(path[h][w] == '.')
            ans = max(ans, get(h, w));
    }
    cout << ans << endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,K;
    cin>>N>>K;
    N-=3;
    int ans=0;
    for(int j=0;j<5;j++){
        int k=(K-81-9*j+11*1000)%11*7%11;
        if(N>=k)ans+=(N-k)/11+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <limits>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <iterator>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef unsigned                    ui;
typedef int                         si;
typedef long                        sl;
typedef long long                   ll;
typedef unsigned long long          ull;

// ----------------

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// ----------------

int main(int argc, char *argv[])
{
    std::ios_base::sync_with_stdio(false);

    ll n, k;
    cin >> n >> k;

    vector<ll> h(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    sort(h.begin(), h.end());
    ll answer = 0;
    for (int i = 0; i + k < n; ++i) {
        answer += h[i];
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int a[200000+10],b[200000+10];

int main()
{
	int x,y;
	int n,m,i,j,k;
	scanf("%d%d",&n,&m);
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	int t=0;
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		if(x==1) a[y]=1;
		if(y==n) b[x]=1;
		if(x==1&&y==n) t=1;
	}
	if(t) printf("POSSIBLE\n");
	else
	{
		for(i=1;i<n;i++)
		if(a[i]==1&&b[i]==1) 
		{
			printf("POSSIBLE\n"); break;
		}
		if(i>=n) printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

#define H 250

int main(void){
  int i,size;
  int A[H];
  scanf("%d",&size);
  
  for(i=1;i<size+1;i++) scanf("%d",&A[i]);

  for(i=1;i<size+1;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i != 1) printf("parent key = %d, ",A[i/2]);
    if(2*i <= size) printf("left key = %d, ",A[2*i]);
    if(2*i+1 <= size) printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define VI vector<int>
#define VII vector<VI>
#define VL vector<LL>
#define VLL vector<VL>
#define VD vector<double>
#define VDD vector<VD>
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<LL,LL>
#define VPII vector<PII>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EP emplace_back
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9;
const int MOD=INF+7;

int main(void){
    int N; cin>>N;
    cout<<N*(N+1)/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100015;
int main(){
	int time;
	int n,k;
	scanf("%d",&n);
	if(n==3|| n==5||n==7)
		printf("YES\n");
	else
	    printf("NO\n");
	return 0;
}

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

using namespace std;

#define READ() 	    freopen("in.txt","r",stdin)
#define WRITE()     freopen("out.txt","w",stdout)
#define sf(n) 	    scanf("%d",&n)
#define sl(x)       scanf("%I64d",&x)
#define lsf(n) 	    scanf("%lld", &n)
#define pb(n) 	    push_back(n)
#define mem(x,y)    memset(x,y,sizeof(x))
#define D(x)      	cout << #x << " = " << x << endl
#define CHKRTE		assert(false)
#define YOLO        cout << "YOLO" << endl
#define NL			printf("\n")
#define EPS 	    1e-10
#define INF         INT_MAX
#define MAX         200010
#define MOD         1000000007
#define LL          long long
#define endl        "\n"
#define pi          2.0*acos(0.0)
#define cnd         tree[idx]
#define lnd         tree[left]
#define rnd         tree[right]
#define callLeft    left,st,mid
#define callRight   right,mid+1,ed

bool vis[MAX];
vector <int> vec[MAX];
void dfs(int u)
{
    vis[u] = true;
    for(int i=0;i<vec[u].size();i++)
    {
        int v = vec[u][i];
        if(!vis[v])
        {
            dfs(v);
        }
    }
}

bool chk(int u,int n)
{
    for(int i=0;i<vec[u].size();i++)
    {
        int v = vec[u][i];
        if(v == n)return true;
    }
    return false;
}

int main()
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(0); /// use "\n" instead of endl

/**
#ifndef ONLINE_JUDGE
    READ();
    WRITE();
#endif
**/

#ifdef JAMILPC
	READ();
//	WRITE();

//    int t;
//    cin >> t;
//    while(t--)
//    {
#endif

    int n;
    int m;
    sf(n);
    sf(m);

    for(int i=0;i<m;i++)
    {
        int u,v;
        sf(u);
        sf(v);
        vec[u].pb(v);
        vec[v].pb(u);
    }

    int iCnt = 0;
//    mem(vis,false);

    for(int i=0;i<vec[1].size();i++)
    {
        int v = vec[1][i];
        if(chk(v,n))
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;


#ifdef JAMILPC
//	}
#endif


    return 0;
}



Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
typedef pair<int,int> pii;

vector<int>color;
vector<vector<pii>>v;
vector<bool>visited;

void c(int node,int distance)
{
  if(distance%2==0)color[node] = 1;
	for(pii a: v[node])
	{
		int n = a.first;
		int w = a.second;
		if(!visited[n]){
			visited[n] = true;
			c(n, distance+w);
		}
	}
}
void solve()
{
  int n;cin>>n;
  color=vector<int>(n);
  v=vector<vector<pii>>(n,vector<pii>());
  visited=vector<bool>(n);
    
    int v1;int v2;int w;
      for(int i=0;i<n-1;i++)
      {
          cin>>v1>>v2>>w;
          v1--;v2--;
          v[v1].push_back(make_pair(v2,w));
          v[v2].push_back(make_pair(v1,w));
      }
  c(0,0);
  for(int i=0;i<(int)color.size();i++)
  cout<<color[i]<<endl;
}
int32_t main()
{
    rapido;
    int t;
     // cin>>t;
    t=1;
    while(t--)
    solve();
}




Measured memory_bytes: 12756
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    if(n%k == 0) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    int ans = 0;
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    char[] t = sc.next().toCharArray();
    for (int cnt = 0; cnt < s.length; cnt++) {
      if (s[cnt] != t[cnt]) {
        ans++;
      }
    }
    System.out.println(ans + "");
    sc.close();
  }
}


Measured memory_bytes: 44184
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n;
mat t;
vll p;
lli s;

void preorder(lli x){
    if(x < 0) return;
    cout << " " << x;
    preorder(t[x][0]);
    preorder(t[x][1]);
}

void inorder(lli x){
    if(x < 0) return;
    inorder(t[x][0]);
    cout << " " << x;
    inorder(t[x][1]);
}

void postorder(lli x){
    if(x < 0) return;
    postorder(t[x][0]);
    postorder(t[x][1]); 
    cout << " " << x;
}

int main(){
    cin >> n;
    p = vll(n,-1);
    t = mat(n,vll(2,-1));
    for(lli i = 0;i < n;i++){
        lli id,left,right;
        cin >> id >> left >> right;
        t[id][0] = left;
        t[id][1] = right;
        if(left >= 0) p[left] = id;
        if(right >= 0) p[right] = id;
    }
    for(lli i = 0;i < n;i++){
        if(p[i] < 0){
            s = i;
            break;
        }
    }
    cout << "Preorder" << endl;
    preorder(s);
    cout << endl;
    cout << "Inorder" << endl;
    inorder(s);
    cout << endl;
    cout << "Postorder" << endl;
    postorder(s);
    cout << endl;

    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<algorithm>
#include<functional>
#include<vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> X(N);
	int maxX = 0;
	for(int i = 0;i < N; i++) {
		cin >> X[i];
		maxX = max(maxX, X[i]);
	}

	int sum;
	int ans = 100 * 100 * 100 + 1;
	for(int p=1; p < 100; p++) {
		sum = 0;
		for(int i=0; i<N; i++) {
			sum += (X[i]-p)*(X[i]-p);
		}
		ans = min(ans, sum);
	}

	cout << ans << endl;
}

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

using namespace std;

int main()
{
  int n,k;
  cin >> n >> k;
  ll h[n];
  for(int i=0; i<n; i++) cin >> h[i];
  ll dp[n];
  dp[0] = 0;
  for(int i=1; i<n; i++) dp[i] = LONG_LONG_MAX;

  for(int i=1; i<n; i++){
    for(int j=1; j<=k && i-j >= 0; j++){
        dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
    }
  }
  cout << dp[n-1];
  return 0;
}


Measured memory_bytes: 1792