akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> llll;
typedef vector<llll> vllll;

int main(){
  int N;cin>>N;
  int M=(int)pow(2, N);
  vll A;
  for (int i=0;i<M;++i){ll a;cin>>a;A.push_back(a);}
  vi vertices[M];
  vi layers[N+1];
  for (int i=0;i<M;++i){
    int count=0;
    for (int j=0;j<N+1;++j){
      int d=(i>>j)&1;
      if (d==1){
        vertices[i].push_back(i-(int)pow(2, j));
        count++;
      }
    }
    layers[count].push_back(i);
  }


  vllll first(M);
  for (int i=0;i<M;++i){
    first[i]=make_pair(A[i],i);
  }
  
  vllll second(M);
  second[0]=make_pair(0,0);
  vllll candidates[M];

  for (int layer=1;layer<N+1;++layer){
    int L=layers[layer].size();
    for (int l=0;l<L;++l){
      int i=layers[layer][l];
      int S=vertices[i].size();
      llll p=make_pair(A[i], i);
      candidates[i].push_back(p);
      for (int j=0;j<S;++j){
        llll q=first[vertices[i][j]];
        candidates[i].push_back(q);
      }
      sort(candidates[i].begin(), candidates[i].end(), greater<llll>());
      
      first[i]=candidates[i][0];
      int T=candidates[i].size();
      for (int t=0;t<T;++t){
        if (candidates[i][t]==candidates[i][0]){continue;}
        second[i]=candidates[i][t];
        break;
      }  
    }
  }

  
  vll ans;
  ans.push_back(first[1].first+second[1].first);
  if(M!=2){
    for (int k=2;k<M;++k){
      ll a=max(first[k].first+second[k].first,ans[k-2]);
      ans.push_back(a);
    }
  }

  for (int k=0;k<M-1;++k){
    cout << ans[k] << endl;
  }
  return 0;
}



Measured memory_bytes: 108212
#include <iostream>
using namespace std;
int main(){

int a,b;
cin>>a>>b;

if (a>b){
	cout <<"a > b"<<endl;
}
else if (a<b){
	cout<<"a < b"<<endl;
}
else if(a==b){
	cout<<"a == b"<<endl;
}	

return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define v vector<ll>
#define st stack<ll>
#define pq  priority_queue <int>
#define q queue<ll>
#define mod 1000000005
using namespace std;
 char ch[1000000];
int main(){
    int a,b;
    cin>>a>>b;
    if(a==b){
    	cout<<"Yes"<<endl;
    	return 0;
    }
    cout<<"No"<<endl;
    return 0;
   }


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<int,int>
#define LL long long
using namespace std;

LL fpow(LL a, LL b, LL k) {
    LL ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
            ans %= k;
        }
        a *= a;
        a %= k;
        b >>= 1;
    }
    return ans;
}

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    LL k;
    cin >> k;
    int ans = -2;
    LL p = 0;
    for (int i=0;i<=1000000;i++) {
        // cout << (7 * (fpow(10,i,k)-1) / 9) << endl;
        p += 7 * fpow(10,i, k);
        p %= k;
        if (p == 0) {
            ans = i;
            break;
        }
    }
    cout << ans+1 << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 3640
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 55;

int n;
ll x, d;
ll m[MAXN];
int p[MAXN];
int sz[MAXN];

const int MX = 150000;
array<ll, MX> dp;
int lst[MAXN];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> x >> d;
	cin >> m[0];
	for (int i = 1; i < n; ++i) {
		cin >> m[i] >> p[i];
		--p[i];
	}
	for (int i = n - 1; i >= 0; --i) {
		sz[i] += 1;
		if (i != 0) {
			m[p[i]] += m[i];
			sz[p[i]] += sz[i];
		}
	}
	vector<array<ll, 3>> vv;
	vv.push_back({m[0], sz[0], x});
	for (int i = 1; i < n; ++i)
		vv.push_back({m[i], sz[i], d});
	assert(n <= 50);
	for (int i = 0; i < vv.size(); ++i)
		assert(vv[i][1] <= 50);
	sort(vv.begin(), vv.end(), [] (array<ll, 3> a, array<ll, 3> b) {
			return a[0] * b[1] < a[1] * b[0];
			});

	ll add = 0;
	for (int i = 0; i < vv.size(); ++i) {
		if (vv[i][2] <= n)
			continue;
		ll lf = x;
		for (int j = 0; j < i; ++j) {
			lf -= vv[j][0] * vv[j][2];
			if (lf < 0)
				break;
		}
		for (int j = i + 1; j < vv.size() && lf >= 0; ++j) {
			int k = 0;
			while ((k + 1) * vv[j][0] / vv[i][0] * vv[i][1] < (k + 1) * vv[j][1])
				++k;
			lf -= vv[j][0] * k;
		}
		if (lf >= 0) {
			ll go = min(vv[i][2] - n, lf / vv[i][0]);
			add += vv[i][1] * go;
			x -= vv[i][0] * go;
			lf -= vv[i][0] * go;
			vv[i][2] -= go;
			if (vv[i][2] > n)
				break;
		}
		else {
			break;
		}
	}
	dp.fill(x + 1);
	dp[0] = 0;
	for (int i = 0; i < vv.size(); ++i) {
		int n = vv[i][1];
		ll cs = vv[i][0];
		ll av = vv[i][2];
		for (int j = 0; j < n; ++j)
			lst[j] = j;
		auto dp2 = dp;
		for (int i = 0; i < MX; ++i) {
			int g = i % n;
			if (lst[g] <= i)
				lst[g] = i + n;
			int k = (lst[g] - i) / n;
			for (; lst[g] < MX && k <= av; lst[g] += n, ++k) {
				if (dp2[lst[g]] > dp[i] + cs * k)
					dp2[lst[g]] = dp[i] + cs * k;
				else
					break;
			}
		}
		dp = dp2;
	}
	ll ans = add;
	for (int i = 0; i < MX; ++i)
		if (dp[i] <= x)
			ans = max(ans, add + i);
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int K = scan.nextInt();
		int X = scan.nextInt();
		int Y = scan.nextInt();
		int cost = 0;
		
		if (N >= K) {
			for (int i = 0; i < K; i++) {
				cost += X;
			}
			for (int i = K; i < N; i++) {
				cost += Y;
			}
		} else {
			for (int i = 0; i < N; i++) {
				cost += X;
			}
		}
		
		System.out.println(cost);
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long a,b,c;
  cin >> a >> b >> c;
  a = a - c;
  if(a < 0){ b = b + a;
            a = 0;}
           
  if(b < 0){b = 0;}
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int ans = 0;			
		int search = d * 2 + 1;
		
		ans = n / search;
		if (n % search > 0)
		ans++;
		out.println(ans);
	}
}

Measured memory_bytes: 22740
#include<iostream>
using namespace std;
int main(){
    int h, w, i, j;
    while (cin>>h>>w,h||w){
        for (i=0;i<h;i++){
            for (j=0;j<w;j++)
                cout<<((i!=h-1&&i!=0)?((j!=w-1&&j!=0)?".":"#"):"#");            
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3092
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF = (1LL<<60)-1;
const int maxN = 1000001;
int32_t main(){
    SPEED;
    int k;
    cin >> k;
    string ans = "ACL";
    while(k--){
        cout << ans ;
    }
}


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

using namespace std;

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

    int net[N];

    for(int i = 0; i < N; i++)
    {
        cin >> net[i];
    }
    
    int input;
    for (int i = 0; i < N; i++)
    {
        cin >> input;
        net[i] -= input;
    }

    int max = 0;
    for (int i = 0; i < N; i++)
    {
        if (net[i] > 0)
        {
            max += net[i];
        }
    }

    cout << max;
}


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


def solve(N: int, Y: int):
    for i in range(2000+1):
        for j in range((2000+1)-i):
            k = (Y-10000*i-5000*j)//1000
            if(k == N-i-j and 0 <= k <= 2000):
                print(i,j,k)
                sys.exit()

    print(-1,-1,-1)
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    f = [i*(i+1)*(i+2)//6 for i in range(1,181)]
    n = 10**6-1
    dp = [i for i in range(n+1)]
    dp_odd = [i for i in range(n+1)]
    for i in range(n):
        for j in f:
            ni = i+j
            if ni <= n:
                nd = dp[i]+1
                if nd < dp[ni]:
                    dp[ni] = nd
                if j&1:
                    nd = dp_odd[i]+1
                    if nd < dp_odd[ni]:
                        dp_odd[ni] = nd
    while 1:
        n = I()
        if n == 0:
            break
        print(dp[n],dp_odd[n])
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 85088
#include <iostream>

using namespace std;

int main()
{
    long long a,b,x;
    cin >> a >> b >> x;
    long long n = a;
    bool f = 0;
    if(n)
        a--;
    long long k = b/x;
    long long ans = a/x;
    ans = k - ans;
    if(!n)
        ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = input().rstrip()
    if S == 'Sunny':
        print('Cloudy')
    elif S == 'Cloudy':
        print('Rainy')
    elif S == 'Rainy':
        print('Sunny')


if __name__ == '__main__':
    main()

Measured memory_bytes: 4084
D,G=map(int,input().split())
import math
ans=10**9
prob=[]
for i in range(D):
  p,c=map(int,input().split())
  prob.append((p,c))
for i in range(2**D):
  i=format(i-1,'b').rjust(D,'0')
  alll=[]
  notall=[]
  for j in range(D):
    if i[j]=='1':
      alll.append(j)
    else:
      notall.append(j)
  if notall!=[]:
    maxnotall=notall[-1]  
  point=0
  tans=0
  for i in alll:
    point+=100*(i+1)*prob[i][0]+prob[i][1]
    tans+=prob[i][0]
  if point>=G:
    ans=min(tans,ans)
  if point<G:
    if 100*(maxnotall+1)*(prob[maxnotall][0]-1)>=G-point:
      tans+=math.ceil((G-point)/(100*(maxnotall+1)))
      ans=min(tans,ans)
    else:
      ans=ans

if ans==10**9:
  ans=0
  for i in range(D):
    ans+=prob[i][0]
print(ans)

Measured memory_bytes: 74116
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}



template<class T, class OP>
class Lazy_Segment_Tree {//0-indexed ??????
public:
	vector<T> data, lazy;
	int n;
	Lazy_Segment_Tree(int a) :n(1) {
		while (n < a) n *= 2;
		data.resize(n * 2 - 1);
		lazy.resize(n * 2 - 1);
	}

	void op(int a, int b, T v, int num = 0, int base = 1) {
		int l = (num + 1 - base) * (n / base), r = l + n / base;
		if (a == l && b == r)
			lazy[num] = OP()(lazy[num], v);
		else {
			data[num] += v*(b - a);
			int nr = (l + r) / 2;
			if (nr > a) op(a, min(b, nr), v, num * 2 + 1, base * 2);
			if (nr < b) op(max(a, nr), b, v, num * 2 + 2, base * 2);
		}
	}

	T query(int a, int b, int num = 0, int base = 1) {
		int l = (num + 1 - base) * (n / base), r = l + n / base;
		data[num] = OP()(data[num], lazy[num], 1, (r - l));
		if (num < n - 1) 
			lazy[num * 2 + 1] = OP()(lazy[num], lazy[num * 2 + 1]), lazy[num * 2 + 2] = OP()(lazy[num], lazy[num * 2 + 2]);
		lazy[num] = T();

		if (a == l && b == r)
			return data[num];
		else {
			int nr = (l + r) / 2;
			T ret = T();
			if (nr > a) ret = OP()(ret,query(a, min(b, nr), num * 2 + 1, base * 2));
			if (nr < b) ret = OP()(ret,query(max(a, nr), b, num * 2 + 2, base * 2));
			return ret;
		}
	}
};
template<class T>
class RMQ {
public:
	T operator ()(const T a, const T b, const int ra = 1, int rb = 1) {
		return min(a, b);
	}
};
template<class T>
class SUM {
public:
	T operator ()(const T a, const T b, const int ra = 1, int rb = 1) {
		return a*ra + b*rb;
	}
};
signed main() {
	int n, q;

	scanf("%d %d", &n, &q);
	Lazy_Segment_Tree<int, SUM<int>> seg(n);

	REP(i, q) {
		int a, b, c;
		scnaf("%d %d %d", &a, &b, &c);
		if (a) {
			printf("%d\n", seg.query(b-1, c));
		}
		else
			seg.op(b-1,b, c);
	}

	return 0;
}

Measured memory_bytes: 4932
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue,copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])

def main():
    n=inp()
    a=inplm(n)
    print('second') if all (a[i]%2==0 for i in range(n)) else print('first')

if __name__ == "__main__":
    main()


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;

    vector<vector<int>> G(n);
    vector<bool> vis(n, false);
    for (int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;

        G[x].push_back(y);
        G[y].push_back(x);
    }

    int cnt = 0;
    function<void (int)> dfs = [&](int x){
        vis[x] = true;
        for (auto u: G[x]){
            if (!vis[u]){
                cnt += 1;
                dfs(u);
            }
        }
    };

    int ans = 0;
    for (int i = 0; i < n; i++){
        if (!vis[i]){
            cnt = 1;
            dfs(i);
            ans = max(ans, cnt);
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 26592
S=input()

#0101...
c=0
for i in range(len(S)):
	if i%2==0 and S[i]=="1": c+=1
	if i%2==1 and S[i]=="0": c+=1

#1010...
d=0
for i in range(len(S)):
	if i%2==0 and S[i]=="0": d+=1
	if i%2==1 and S[i]=="1": d+=1

print(min(c,d))

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

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    long long add_a = 0, add_b = 0;
    long long diffs = 0;
    for (int i = 0; i < n; i++) {
        int diff = b[i] - a[i];
        diffs += diff;
        if (diff > 0) add_a += diff / 2;
        else add_b += -1 * diff;
    }

    // cout << add_a << " " << add_b << endl;
    if (add_a >= add_b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;

struct Node{
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;


void insert(int num){
  Node *y = NIL;
  Node *x = root; //start
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = num;
  z->left = NIL;
  z->right = NIL;

  while ( x!=NIL ) {
    y=x; //おや
    if ( z->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y==NIL) { //最初
    root = z;
  }else{
    if( z->key < y->key ){  //親より小さければ左につく
      y->left = z;
    }else{
      y->right = z;
    }
  }

}


void print_in(Node *u){
  if(u==NIL) return;
  print_in(u->left);
  std::cout << " " << u->key;
  print_in(u->right);
}


void print_pre(Node *u){
  if(u==NIL) return;
  std::cout << " " << u->key;
  print_pre(u->left);
  print_pre(u->right);
}


int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, num; std::cin >> k;
  string command;
  for (size_t i = 0; i < k; i++) {
    std::cin >> command;
    if (command=="insert") {
      std::cin >> num;
      insert(num);
    }else{
      print_in(root);
      std::cout << '\n';
      print_pre(root);
      std::cout << '\n';
    }
  }

  return 0;
}



Measured memory_bytes: 26452
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	string N; cin >> N;
	int sum = 0;
	REP(i,N.size()) {
		sum += N[i] - '0';
	}
	cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 3764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    map<ll,ll> x;
    rep(i,N){
        ll c; cin>>c;
        x[c]++;
    }
    ll ans=0;
    for(auto m:x){
        if(m.a<m.b){
            ans+=m.b-m.a;
        }
        else if(m.a>m.b){
            ans+=m.b;
        }
    }
    
    
    cout<<ans<<endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> dist(N, 1e9);
    dist[0] = 0;
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (int v : graph[u]) {
            if (dist[v] > dist[u] + 1) {
                dist[v] = dist[u] + 1;
                que.push(v);
            }
        }
    }

    vector<int> ans(N, 0);
    for (int i = 1; i < N; i++) {
        for (int v : graph[i]) {
            if (dist[v] == dist[i] - 1) {
                ans[i] = v + 1;
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
        cout << ans[i] << endl;
    }
}


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

using namespace std;

#define long long long
#define INF 2e18
#define MOD (long) (998244353)
#define umap unordered_map

int main()
{
    long t = 1;
    //cin >> t;

    while (t--) {
        long n;
        cin >> n;

        vector<long> a(n);
        umap<long, long> d;
        for (auto &x : a) {
            cin >> x;
            d[x]++;
        }
        long total = 0;
        for (auto &p : d) {
            long k = p.second;
            total += k * (k-1) / 2;
        }
        for (auto &x : a) {
            long aux = total - (d[x] * (d[x] - 1)) / 2;
            aux += (d[x] - 1) * (d[x] - 2) / 2;
            long ans = aux;
            printf("%lld\n", ans);
        }
    }
}


Measured memory_bytes: 11864
import java.util.*;

public class Main {

    public static void main (String [] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] X= new int[N];
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<N;i++){
            X[i]=sc.nextInt();
            list.add(X[i]);
        }
        Collections.sort(list);
        for (int i=0;i<N;i++){
            if (X[i]<= list.get((N/2)-1)){
                System.out.println(list.get(N/2));
            }else{
                System.out.println(list.get(N/2-1));
            }
        }
    }
}

Measured memory_bytes: 104916
import collections

N = int(input())
A = list(map(int, input().split()))

c = collections.Counter(A)
cv = c.values()
ck = c.keys()

ori=0
for x in cv:
    ori += (x-1) * ((x-1)+1) // 2


for i in range(N):
    tmp = A[i]
    print(ori - (c[tmp]-1))



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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;

int n,i,a,k,t,w,zz;

signed main(){
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> a >> k;
        for(; a/k ; a -= w*t){
            if(a % k == 0) break;
            t = a/k + 1;
            w = (a-(t-1)*k) / t;
            if(w == 0) w=1;
        }
        zz ^= a/k;
    }
    
    puts(zz ? "Takahashi" : "Aoki");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=4005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

inline bool get(int x,int y){
	x--;y--;
	printf("? %d %d\n",x,y);
	fflush(stdout);
	char s[15];
	scanf("%s",s);
	return s[0]=='Y';
}
int a,b,n,m,s[N];
char ans[N];

int main(){
	scanf("%d%d",&a,&b);n=a+b;
	if(a<=b){puts("Impossible");return 0;}
	s[m=1]=1;
	for(int i=2;i<=n;i++)
		if(!m) s[++m]=i; else
		if(get(s[m],i)) s[++m]=i; else m--;
	for(int i=1;i<=n;i++)
		ans[i]=get(s[m],i)+'0';
	printf("! %s\n",ans+1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 724
import java.util.Scanner;
     
class Main{
    public static void main(String arg[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        
        System.out.println(calc(a,b));
        
    }
    
    public static String calc(int a, int b) {
    	String ans = "Odd";
    	if(a*b % 2 == 0) {
    		ans = "Even";
    	}
    	return ans;
    }
}

Measured memory_bytes: 21844
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)

if n % 2 == 0:
    total = 0
    for i in A[::-1][:n//2]:
        total += i*2
    total = total - A[-1]
    print(total)
else:
    total = 0
    for i in A[::-1][:n//2+1]:
        total += i*2
    total = total - A[-1]
    total = total - A[-(n//2+1)]
    print(total)

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {


    int N, M;
    cin >> N >> M;
    vector<int> food(M, 0);

    REP(i, N){
        int k;
        cin >> k;
        REP(j, k){
            int a; cin >> a; a--;
            food[a]++;
        }
    }
    int ans = 0;
    REP(i, M){
        if(food[i]==N)ans++;
    }
    cout << ans << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
if sum(l)<=x:print(n-int(sum(l)!=x));exit()
if l[0]>x:print(0);exit()
d=[]
now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(br(d,x))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define mod 924844033
#define N 2009
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;
 
int n,m,a[N],bin[N],fac[N],f[N][2],dp[N][N],g[N][N];
int main(){
	scanf("%d%d",&n,&m);
	int i,j,k,x,y;
	for (i=bin[0]=1; i<=n; i++) bin[i]=(bin[i-1]<<1)%mod;
	for (i=fac[0]=1; i<=n; i++) fac[i]=(ll)fac[i-1]*i%mod;
	for (i=1; i<=n && i<=(m<<1); i++){
		a[i]=(n-i)/(m<<1)+1;
		memset(f,0,sizeof(f));
		f[0][i-m<=0]=1;
		for (j=1; j<=a[i]; j++)
			for (k=a[i]+1; k>=0; k--){
				ad(f[k][0],f[k][1]); f[k][1]=0;
				if (k) for (x=0; x<2; x++)
					for (y=0; y<=x; y++) ad(f[k][x],f[k-1][y]);
			}
		x=i+(a[i]-1)*(m<<1);
		for (j=0; j<=a[i]+1; j++){
			dp[i][j]=f[j][0];
			if (x+m<=n) ad(dp[i][j],f[j][1]);
		}
	}
	g[0][0]=1;
	for (i=1; i<=n && i<=(m<<1); i++)
		for (j=0; j<=n; j++)
			for (k=0; k<=j && k<=a[i]+1; k++)
				ad(g[i][j],(ll)g[i-1][j-k]*dp[i][k]);
	int ans=0; x=min(n,m<<1);
	for (i=0; i<=n; i++)
		if (i&1) ans=(ans-(ll)g[x][i]*fac[n-i]%mod+mod)%mod;
		else ad(ans,(ll)g[x][i]*fac[n-i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 31360
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	double d, t, s;
	cin >> d >> t >> s;

	if (t >= (d / s))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3704
program kagami
  implicit none
  integer i,j,n,max_size,ans
  integer,allocatable :: d_i(:)

  read(*,*)n
  allocate(d_i(n))
  d_i=0
  do i=1,n
     read(*,*) d_i(i)
  end do

  ans=0
  do i=1,n
     max_size=maxval(d_i)
     if(max_size == 0) exit
     ans=ans+1
     do j=1,n
        select case (d_i(j)-max_size)
        case (0)
           d_i(j)=0
        end select
     end do
  end do

  write(*,*) ans
end program kagami


Measured memory_bytes: 384
A=[None]*5
for i in range(5):
    A[i]= int(input())

index = -1
min = 9
for i in range(5):
    if A[i]%10!= 0 and min>=A[i]%10:
        min =A[i]%10
        index =i

def func(n):
    if n%10 == 0:
        return n
    else:
        return ((n//10)+1)*10
sum = 0
for i in range(5):
    if i!=index:
        sum+=func(A[i])
    else:
        sum+=A[i]
print(sum)


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

#define MAX 30

main(){
  int bri[MAX],pre[MAX];
  int n;
  int i,j;
  int temp;
  int judge=0,presum=0;

  while(cin >> n){
    judge=0;
    presum=0;
    if(n==0)break;
    for(i=0;i<n;i++){
      cin >> pre[i] >> bri[i];
    }
    //ツ渉ャツつウツつ「ツ渉づ可ソツーツト
    for(i=n-1;i>0;i--){
      for(j=0;j<i;j++){
	if(bri[j]>bri[j+1]){
	  temp = pre[j];
	  pre[j]=pre[j+1];
	  pre[j+1]=temp;
	  temp = bri[j];
	  bri[j] = bri[j+1];
	  bri[j+1] = temp;
	}
      }
    }


    for(i=0;i<n;i++){
      presum += pre[i];
      // cout << bri[i]<<endl;
       if(bri[i]<presum){
	 judge=1;
       }
    }
    
    if(judge==1)cout << "No" << endl;
    else cout << "Yes" << endl;
    
  }


}

Measured memory_bytes: 0
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N, K;
    cin >> N >> K;

    string S;
    cin >> S;

    S[K - 1] = tolower(S[K - 1]);

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
const int INF = 1e9+7, N=2e5+7;

ii tree[N << 2][2];
int a[N];
void build(int v, int tl, int tr) {
    if (tl == tr) {
        for (int t = 0; t < 2; ++t) {
            if (t == (tl&1)) {
                tree[v][t] = mp(a[tl], tl);
            }   
            else {
                tree[v][t] = mp(INF, INF);
            }   
        }   
        return;
    }
    int tm = (tl + tr) >> 1;
    build(v * 2 + 1, tl, tm);
    build(v * 2 + 2, tm + 1, tr);
    for (int t = 0; t < 2; ++t)
        tree[v][t] = min(tree[v*2+1][t], tree[v*2+2][t]);
}   
ii get(int v, int tl, int tr, int l, int r, int t) {
    if (tr < l || r < tl)
        return mp(INF, INF);
    if (l <= tl && tr <= r)
        return tree[v][t];
    int tm = (tl + tr) >> 1;
    return min(get(v*2+1,tl,tm,l,r,t),get(v*2+2,tm+1,tr,l,r,t));
}   

int n;
ii get(int l, int r, int t) {
    return get(0, 0, n - 1, l, r, t);
}   

ii get(int l, int r) {
    ii mn = get(l, r, l&1);
    ii mn2 = get(mn.s+1, r, (mn.s&1)^1);
    return mp(mn.s, mn2.s);
}

struct Seg {
    int l, r, x;
    bool operator < (Seg s) const {
        return x > s.x;
    }   
};  
priority_queue <Seg> q;

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    
    build(0, 0, n - 1);

    auto add = [&](int l, int r) {
        if (r < l)  
            return;
        auto t = get(l,r);
        q.push({l,r,a[t.f]});
    };   

    add(0, n - 1);
    while (q.size()) {
        auto seg = q.top(); q.pop();
        int l = seg.l, r = seg.r;
        auto t = get(l, r);                                    
        cout << a[t.f] << ' ' << a[t.s] << ' ';    
        add(l,t.f-1);
        add(t.f+1,t.s-1);
        add(t.s+1,r);
    }   
    cout << endl;
}


Measured memory_bytes: 22876
import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.Scanner;
     
    public class Main {
     
    	public static void main(String[] args) {
    		// TODO 自動生成されたメソッド・スタブ
     
    		Scanner scan = new Scanner(System.in);
    		
    		//BigDecialでdoubleから生成すると誤差が出るのでNG
    		//使うときは".valueOf()"を使う
    		String a = scan.next();
    		String b = scan.next();
    		
    		BigDecimal a1 = new BigDecimal(a);
    		BigDecimal b1 = new BigDecimal(b);
    		
    		BigDecimal answer = a1.multiply(b1);
    		
    		//小数点以下切り捨て
    		answer = answer.setScale(0, RoundingMode.DOWN);	
    		
    		
    		System.out.println(answer);
    		
    		}
     
    }

Measured memory_bytes: 35968
//copied
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int64 H,W,ans = 1e18;
int64 maxdec(int64 a,int64 b,int64 c) {
    return max(max(abs(a - b),abs(a - c)),abs(b - c));
}
void Solve() {
    read(H);read(W);
    for(int i = 1 ; i < H ; ++i) {
	int64 h = (H - i) / 2;
	ans = min(ans,maxdec(i * W,h * W,(H - i - h) * W));
	int64 t = W / 2;
	ans = min(ans,maxdec(i * W,t * (H - i),(W - t) * (H - i)));
    }
    for(int i = 1 ; i < W ; ++i) {
	int64 h = (W - i) / 2;
	ans = min(ans,maxdec(i * H,h * H,(W - i - h) * H));
	int64 t = H / 2;
	ans = min(ans,maxdec(i * H,t * (W - i),(H - t) * (W - i)));
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	ll a, b;
	cin >> a >> b;
	ll res = 0;
	FOR(i, a, b+1) {
		string s = to_string(i);
		bool f = true;
		REP(j, s.length() / 2) if (s[j] != s[s.length()-1-j]) {
			f = false;
			break;
		}
		if (f) ++res;
	}
	cout << res << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> cards(N);
  for (int i=0; i<N; i++){
    cin >> cards.at(i);
  }
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  int A = 0;
  int B = 0;
  for (int i=0; i<N; i++){
    if (i%2==0){
      A += cards.at(i);
    }
    else{
      B += cards.at(i);
    }
  }
  cout << A - B << endl;
}

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

int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a <= 0&& b >= 0)
	{
		printf("Zero\n");
		return 0;
	}
	if(a >= 0 || (b-a+1)%2 == 0)
	{
		printf("Positive\n");
		return 0;
	}
	else 
	{
		printf("Negative\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

void swap(int *a,int *b){
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;    
    return;
}

int main(void){
    int i,j,N,K,ans=0,p[1000];

    //入力部
    scanf("%d %d",&N,&K);
    for(i=0; i<N; i++){
        scanf("%d",&p[i]);
    }

    //計算部
    for(i=0;i<N-1;i++){
        for(j=N-1;j>i;j--){
            if(p[j-1]>p[j]){
                swap(&p[j-1],&p[j]);
            }
        }
    }

    for(i=0;i<K;i++){
        ans+=p[i];
    }

    //表示部
    printf("%d\n",ans);
    

    return 0;
}




Measured memory_bytes: 1736
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n % 28;
        if(a==1||a==2||a==3||a==5||a==6||a==9||a==10||a==13||a==17||a==21){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 23252
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int[]a=new int[114];
		++a[getInt()];
		--a[getInt()];
		++a[getInt()];
		--a[getInt()];
		Arrays.parallelPrefix(a,Integer::sum);
		System.out.println(Arrays.stream(a).filter(i->i==2).count());
	}
}

Measured memory_bytes: 30548
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// ?¨??????\???????????????????????????????????????
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int n = sc.nextInt();
int[] values = new int[w];
for (int i = 0; i < values.length; i++) {
values[i] = i + 1;
}
for (int i = 0; i < n; i++) {
String str = sc.next();
String[] ab = str.split(",");
int a = Integer.parseInt(ab[0]) - 1;
int b = Integer.parseInt(ab[1]) - 1;
// a??¨b????????£???values??????????????????
int tmp = values[a];
            values[a] = values[b];
            values[b] = tmp;
}
// values??????????????????
for(int i=0;i<w;i++){
System.out.println(values[i]);
}
}
}

Measured memory_bytes: 26256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int a,b;
		Scanner scan = new Scanner(System.in);
		a = scan.nextInt();
		b = scan.nextInt();
		if((a*b)%2 == 1) {
			System.out.println("Odd");
		}else {
			System.out.println("Even");
		}

	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
const ll INF = 1LL << 60;

int main(){
	int a, b, c, k;
	cin >> a >> b >> c >>k;
	int sum = a + b + c;
	int maxv = max({a, b, c});
	sum -= maxv;
	for(int i =1; i <= k;++i){
		maxv  *= 2; 
	}
	cout << sum + maxv << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
  int n, half;
  cin >> n;
  half = (n / 2) + 1;
  vector <double> coins(n);
  ffor(n) cin >> coins[i];
  
  vector <double> dp(half); // dp[i] contains the probability of getting i heads
  dp[0] = 1;
  for(int i = 0; i < coins.size(); i++) {
    double p = coins[i];
    for(int j = dp.size(); j >= 1; j--) {
      /* probablity of getting exactly j heads with the current coin is:
      	p(already gotten heads AND got tails) + p(got j - 1 heads AND got heads)
        */
      dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
    }
    dp[0] *= (1 - p);
  }
  double total = 0;
  for (auto e: dp) total += e;
  cout << setprecision(12) << 1 - total << '\n';
}

Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
	long long x, y, ans = (long long)1e18;
	cin >> x >> y;
	int d[2] = {1, -1};
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 2; j++){
			long long a = x * d[i], b = y * d[j];
			if(a <= b) ans = min(ans, b - a + i + j);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n);
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        if (x != i) cnt++;
    }
    if (cnt == 0 || cnt == 2) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 256