akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

/* メモリ食い過ぎ注意 */
#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[100000];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n, greater<ll>());

    int aa = -1, bb = -1;
    ;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == a[i + 1])
        {
            if (aa < 0)
            {
                aa = a[i];
                i++;
            }
            else
            {
                bb = a[i];
                break;
            }
        }
    }
    if (aa > 0 && bb > 0)
        cout << aa * bb << endl;
    else
        cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B; cin >> A >> B;
    int taps = 0, num = 1;
    while (true) {
        if (num >= B) break;
        num += A-1;
        taps++;
    }
    cout << taps << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>x(n),y(n);
    map<pair<int,int>,int>mp;
    rep(i,n)cin>>x[i]>>y[i];
    rep(i,n){
        rep(j,n){
            if(i==j)continue;
            mp[make_pair(x[i]-x[j],y[i]-y[j])]++;
        }
    }
    int ans=0;
    for(auto&p:mp){
        ans=max(ans,p.second);
    }
    cout<<n-ans<<endl;
}

Measured memory_bytes: 384
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
//#include <unordered_map>
#include <numeric>
 
using namespace std;
 
const int mod = 1e9 + 7;

int n, m, q;
vector <int> g[5000];
int calc[1000][1000];

int main() {
	
	memset(calc, -1, sizeof(calc));
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 1; i <= m; i++) {
		int l, r;
		scanf("%d %d", &l, &r);
		g[l].push_back(r);
	}
	for(int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());
	while(q--) {
		int l, r;
		scanf("%d %d", &l, &r);
		if(calc[l][r] != -1) printf("%d\n", calc[l][r]);
		else{
		int res = 0;
		for(int i = l; i <= r; i++) {
			int lo = 0, hi = g[i].size() - 1;
			int ans = -1;
			while(lo <= hi) {
				int mid = (lo + hi) / 2;
				if(g[i][mid] <= r) lo = mid + 1, ans = mid;
				else hi = mid - 1;
			}
			res += ans + 1;
		}
		calc[l][r] = res;
		printf("%d\n", res);
		}
	}
} 

Measured memory_bytes: 6144
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
K=int(input())
ans=[]
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans.append(gcd(i,j,k))
print(sum(ans))   

Measured memory_bytes: 188952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
#define N (int)1e6+1

int main()
{
	ios
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int dp[k+1]={0};
	for(int i=1;i<=k;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i-a[j]>=0 && dp[i-a[j]]==0)
			{
				dp[i]=1;
			}
		}
	}
	if(dp[k])cout<<"First"<<nl;
	else cout<<"Second"<<nl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <list>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int MOD = 1000000007;
const ll INF = 1e18;

int main() {
    int n;
    cin >> n;
    vi a;
    int cnt = 0;
    forn(i, n) {
        int t; cin >> t;
        if (t != i + 1) cnt++;
    }
    
    if (cnt == 0 || cnt == 2) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
//10の1/2乗（ルート）pow(10, 0.5)
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  int ma = 0;
  for(int i=1;i<=pow(n,0.5);i++){
    ma = max(ma,(int)pow(i,2));
  }
  cout << ma << endl;
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e18;
ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll i,a,b,c,r,k,n;
   cin>>n>>a>>b;
   ll dp[200001];
   dp[0]=1;
   for(i=1;i<=200000;i++)
   {
       dp[i]=(dp[i-1]*(n-i+1))%mod;
       dp[i]=(dp[i]*power(i,mod-2))%mod;
   }
   r=(power(2,n)-1+mod)%mod;
   r=(r-dp[a]+mod)%mod;
   r=(r-dp[b]+mod)%mod;
   cout<<r<<endl;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = 0
for i in range(n):
	if a[i] >= b[i]:
		ans += b[i]
	else:
		ans += a[i]
		if a[i+1] < b[i] - a[i]:
			ans += a[i+1]
			a[i+1] = 0
		else:
			ans += b[i] - a[i]
			a[i+1] -= b[i] - a[i]

print(ans)


Measured memory_bytes: 19156
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

char victory(char x) {
    if (x == 's')
        return 'r';
    if (x == 'r') {
        return 'p';
    }
    return 's';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    int R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    string ans_S = "";

    rep(i, N) {
        char x = victory(T[i]);
        if (i - K >= 0) {
            if (ans_S[i - K] == x) {
                x = victory(x);
                if (i + K < N) {
                    if(victory(T[i + K]) == x)
                        x = victory(x);
                }
            }
        }
        ans_S += x;
    }
    ll ans = 0;
    rep(i, ans_S.size()) {
        if (ans_S[i] == 'r' && T[i] == 's') ans += R;
        if (ans_S[i] == 's' && T[i] == 'p') ans += S;
        if (ans_S[i] == 'p' && T[i] == 'r') ans += P;
    }

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

Measured memory_bytes: 640
#include<iostream>

using namespace std;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {

	long long A, B, C, D, G;
	long long L;
	long long cnt;

	cin >> A >> B >> C >> D;

	G = GCD(C,D);
	L = C * D/G;

	A = A - 1;
	//cnt = (B - B / C - B / D + B / L)-((A-1)- (A - 1)/C-(A-1)/D+(A-1)/L);
	cnt = (B - B / C - B / D + B / L) - (A - A / C - A / D + A / L);

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


num_query = int(input())

for _ in range(num_query):
    A = list(map(int,input()))
    B = list(map(int,input()))

    if len(A) > 80 or len(B) > 80:
        print("overflow")
        continue

    if len(B) > len(A): #len(B) <= len(A)にする
        A,B = B,A
    A.reverse()
    B.reverse()

    ANS = deque()
    add = 0

    for digit in range(len(A)):
        if digit >= len(B):
            tmp = add+A[digit]
            add = tmp//10
            ANS.append(tmp%10)
        else:
            tmp = add+B[digit]+A[digit]
            add = tmp//10
            ANS.append(tmp%10)

    if len(A) == 80 and add == 1:
        print("overflow")
    else:
        if add == 1:
            ANS.append(1)

        while len(ANS) > 0:
            print("%d"%(ANS.pop()),end="")
        print()



Measured memory_bytes: 6396
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()
l = []
for i in range(1, N):
    a = S[0:i]
    b = S[i:]
    a_set = set(a)
    b_set = set(b)
    # c = intersection(a_set, b_set)
    c = a_set & b_set
    l.append(len(c))
print(max(l))
    # a_l = len(Counter(a))
    # b_l = len(Counter(b))
    # print(a_l)
    # print(b_l)


Measured memory_bytes: 5256
#include <iostream>
#include <climits>
#include <cstdlib>
using namespace std;
const long long INF = INT_MAX;

const int MAX_N = 110;
const int MAX_V = 100100;

int N;
long long W, w[MAX_N], v[MAX_N];

long long dp[MAX_N][MAX_V];

int main()
{
  cin >> N >> W;
  for (int i = 0; i < N; i++)
  {
    cin >> w[i] >> v[i];
  }

  // init
  for (int i = 0; i < MAX_N; i++)
  {
    for (int j = 0; j < MAX_V; j++)
    {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;
  
  for (int i = 0; i < N; ++i)
  {
    for (int sv = 0; sv < MAX_V; ++sv)
    {
      if (sv - v[i] >= 0)
      {
        if (dp[i + 1][sv] > dp[i][sv - v[i]] + w[i])
        {
          dp[i + 1][sv] = dp[i][sv - v[i]] + w[i];
        }
      }
      
      if (dp[i + 1][sv] > dp[i][sv])
      {
        dp[i + 1][sv] = dp[i][sv];
      }
    }
  }

  long long res = 0;
  for (int sv = 0; sv < MAX_V; ++sv) {
    if (dp[N][sv] <= W)
    {
      res = sv;
    }
  }

  cout << res << endl;
  return 0;
}

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

int main() {
    char alpha;
    cin >> alpha;
    vector<char> A = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
    'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    char ans = 'a';
    for (int i=0; i<26; i++) {
        if (alpha == A[i]) {
            ans = 'A';
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3532
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  string s;cin>>s;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int c[26] = {};
  char ch;
  while (cin >> ch) {
    if (isalpha(ch)) {
      c[tolower(ch) - 'a']++;
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char) ('a' + i) << " : " << c[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3132
import Data.Array.IArray

solve :: Int -> Array Int (Int,Int,Int) -> [Int]
solve n a = map (go 0) [1..n]
  where
    go :: Int -> Int -> Int
    go t i
      | i == n = t
      | t <= s = go (s+c) (i+1)
      | t `mod` f == 0 = go (t+c) (i+1)
      | otherwise = let t' = t + f - (t `mod` f) 
                     in go (t' + c) (i+1)
      where
        (c,s,f) = a!i

main :: IO ()
main = do
    n <- readLn :: IO Int
    a <- listArray (1,n-1) . map ((\[a,b,c] -> (a,b,c)) . (map read . words))
       . lines <$> getContents :: IO (Array Int (Int,Int,Int))
    mapM_ print $ solve n a

Measured memory_bytes: 1148
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

class Node {
public:
	int location;
	int l, r;
	//Node() {}
};

class Point {
public:
	int id, x, y;
	Point() {}
	Point(int id, int x, int y) :id(id), x(x), y(y) {}
	bool operator<(const Point&p) const {
		return id < p.id;
	}

	void print() {
		printf("%d\n", id);
	}
};

static const int MAX = 500000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;
Point ans[MAX];
int NANS;

bool lessX(const Point &p1, const Point &p2) {
	return p1.x < p2.x;
}

bool lessY(const Point &p1, const Point &p2) {
	return p1.y < p2.y;
}

int makeKDTree(int l, int r, int depth) {
	if (l == r) {
		return NIL;
	}
	int mid = (l + r) / 2;
	int t = np++;
	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	}
	else {
		sort(P + l, P + r, lessY);
	}
	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		ans[NANS++] = P[T[v].location];
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL) {
			if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1);
		}
		if (T[v].r != NIL) {
			if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1);
		}
	}
	else {
		if (T[v].l != NIL) {
			if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1);
		}
		if (T[v].r != NIL) {
			if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1);
		}
	}
}

int main() {
	int x, y;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].l = T[i].r = NIL;
	}

	np = 0;

	int root = makeKDTree(0, N, 0);

	int q;
	scanf("%d", &q);
	int sx, tx, sy, ty;
	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		NANS = 0;
		find(root, sx, tx, sy, ty, 0);
		sort(ans, ans + NANS);
		for (int j = 0; j < NANS; j++) {
			ans[j].print();
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 14356
from collections import Counter
import bisect

N = int(input())
S = [input() for _ in range(N)] ## 縦一列


cnt = list(Counter(S).items())
cnt = sorted(cnt, key=lambda x: (-x[1], x[0]))

max_cnt = cnt[0][1]

lst = [cnt[i][1] for i in range(len(cnt))][::-1]
n_print = len(cnt) - bisect.bisect_left(lst, max_cnt)

for i in range(n_print):
  print(cnt[i][0])

Measured memory_bytes: 122192
#include <bits/stdc++.h>
#define endl '\n'
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define IT set<node>::iterator
#define mem(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef long long ll;
using namespace std;

int main() {
    ll d, t, s; cin >> d >> t >> s;
    if(t * s >= d) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 3632
#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         INT_MAX
#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

LL arr[100];
LL valChk[111][111]; /// minus these values
int chk(int n)
{
    int cnt = 0;
//    for(int i=0;i<n;i++)
//    {
//        cout << arr[i] << " ";
//    }
//    cout << endl;

    while(1)
    {
        sort(arr,arr+n);
        if(arr[n-1] <= n-1)return cnt;
        for(int i=0;i<n;i++)
        {
            if(i != n-1)arr[i]++;
            else arr[i] -= n;
//            cout << arr[i] << " ";
        }
//        cout << endl;

        bool shobSoman = true;
        for(int i=0;i<n-1;i++)
        {
            if(arr[i] != arr[i+1])shobSoman = false;
        }

        for(int i=0;i<n;i++)valChk[cnt][i] -= arr[i];

//        if(shobSoman)break;

        cnt++;
    }
}

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


    LL n = 50;
    for(int i=0;i<n;i++)
    {
        arr[i] = n;
    }

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

//    arr[0] = 11;
//    arr[1] = 11;
//    arr[2] = 11;
    chk(n);
//    YOLO;
//    for(int i=0;i<n;i++)
//    {
//        for(int j=0;j<n;j++)
//        {
//            cout << valChk[i][j] << " ";
//        }
//        cout << endl;
//    }


    LL k;
    cin >> k;

    cout << n << endl;
    if(k % n == 0)
    {
        for(int i=0;i<n;i++)cout << (k/n)+ (n-1) << " ";
        cout << endl;
    }
    else
    {
        LL shrt = n - (k%n);
        LL newN = (k/n)+1;
//        D(shrt);
//        for(int i=0;i<n;i++)cout << (k/n)+1 + (n-1) << " ";
//        cout << endl;

        for(int i=0;i<n;i++)cout << (k/n)+1 + (n-1) - valChk[shrt-1][i] << " ";
        cout << endl;
    }



#ifdef JAMILPC
//	}
#endif


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >>N;
    vector<int> A(N+1);
    vector<int> B(N);
    for (int i=0;i<N+1;i++){
        cin >> A.at(i);
    }
    long long int c =0;
    for (int i=0;i<N;i++){
        cin >> B.at(i);
    }
    for (int j=0;j<N;j++){
        if(A.at(j)>=B.at(j)){
            c += B.at(j);
        }
        else {
            c+= A.at(j);
            if (A.at(j+1)>(B.at(j)-A.at(j))){
                c += B.at(j)-A.at(j);
                A.at(j+1)-=B.at(j)-A.at(j);
            }
            else{
                c+= A.at(j+1);
                A.at(j+1)=0;
            }
        }
    }
    cout << c <<"\n";
    
}

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

int main()
{
    int n, k,ans=0;
    cin >> n >> k;
    while(n>0){
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
n = int(input())
abc = [".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"]
for i in range(n):
  s = input()
  ans = ""
  cur = -1
  num = -1
  for e in s:
    e = int(e)
    if cur ==-1 and e==0:
      continue
    elif e==0:
      t = len(abc[cur-1])
      ans += abc[cur-1][num%t]
      num = -1
      cur = -1
    else:
      cur = e
      num += 1
  print(ans)


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

int main(){
    int n,m,sum=0;
    cin>>n>>m;
    int a[n+1][m+1];

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

        for(int i=0;i<n;i++){
            for(int j=0;j<=m;j++){
                if(j!=m){
                    cin>>a[i][j];
                    sum+=a[i][j];
                }else{
                    a[i][m]=sum;
                    sum=0;
                }
            }
        }
        
        for(int j=0;j<=m;j++){
            for(int i=0;i<=n;i++){
                if(i!=n){
                    sum+=a[i][j];
                }else{
                    a[i][j]=sum;
                    sum=0;
                }
            }
        }

        for(int i=0;i<=n;i++){
            for(int j=0;j<=m;j++){
                if(j!=m) cout<<a[i][j]<<" "<<flush;
                else cout<<a[i][j]<<flush;
            }
            cout<<endl;
        }
}


Measured memory_bytes: 3104
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int sum,n,ans;
	static int[][] card,dp;
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		while(true){
			n=cin.nextInt();
			if(n==0)break;
			card=new int[n][2];
			for(int i=0;i<n;i++){
				card[i][0]=cin.nextInt();
				card[i][1]=cin.nextInt();
			}
			for(int games=cin.nextInt();games--!=0;){
				sum=cin.nextInt();
				ans=0;
				dp=new int[n][1001];
				for(int i=0;i<n;i++){
					Arrays.fill(dp[i],-1);
					
				}
				System.out.println(search(0,0));
//				System.out.println(ans);
			}
		}
	}
	static int search(int a,int b){
		if(b>sum)return 0;
		if(a!=n&&dp[a][b]!=-1)return dp[a][b];
		if(b==sum){
//			ans++;
			return 1;
		}
		if(a==n)return 0;
		int add=0;
		int re=0;
		re+=search(a+1,b+add);
		for(int i=0;i<card[a][1];i++){
			add+=card[a][0];
			re+=search(a+1,b+add);
		}
		return dp[a][b]=re;
	}
}

Measured memory_bytes: 26252
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    cout << min(min(a-1, N-a), min(b-1, N-b)) % 3 + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void)
{
	int i,j,h,w;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0 && w==0) break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
program sequence_sum
  implicit none
  integer(8) :: n, num, tmp, a(0:100000) = 0
  integer :: x, m, b(0:100000) = 0, period, offset, rem, i
  read(*,*) n, x, m
  tmp = m
  if (n <= 2 * m) then
    num = x
    rem = int(n)
    do i = 2, rem
      x = mod(int(x, 8) * x, tmp)
      if (x == 0) exit
      num = num + x
    end do
    write(*,'(i0)') num
    stop
  end if
  a(1) = x
  b(x) = 1
  do i = 2, m + 1
    x = int(mod(int(x, 8) * x, tmp))
    a(i) = a(i - 1) + x
    if (b(x) > 0) then
      offset = b(x) - 1
      period = i - offset - 1
      exit
    end if
    b(x) = i
  end do
  num = (n - offset) / period
  rem = int(n - offset - num * period)
  write(*,'(i0)') (a(offset + period) - a(offset)) * num + a(offset + rem)
end program sequence_sum

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

class UnionFind{
private: 
	vi rank,p,setSize;
	int numset,i;
public:
	UnionFind(int n){
		numset=n; setSize.assign(n,1); rank.assign(n,0); p.assign(n,0);
		for(i=0;i<n;i++){p[i]=i;}
	}

	int findSet(int i){return (p[i]==i) ? i : (p[i]=findSet(p[i]));}
	bool isSameSet(int i, int j){return findSet(i)==findSet(j);}
	void unionSet(int i, int j){
		if(!isSameSet(i,j)){
			numset--;
			int x=findSet(i), y=findSet(j);
			if(rank[x] > rank[y]){p[y]=x; setSize[x]+=setSize[y];}
			else{
				p[x]=y;
				setSize[y]+=setSize[x];
				if(rank[x]==rank[y]){rank[y]++;}
			}
		}
	}
	int numDisjointSet(){return numset;}
	int sizeSetOf(int i){return setSize[findSet(i)];}
};

int main(){
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	UnionFind UF(n+1);
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		UF.unionSet(a,b);
	}

	int maks = 1;
	for(i=1;i<=n;i++){
		maks = max(maks, UF.sizeSetOf(i));
	}
	printf("%d\n",maks);
	
	return 0;
};

Measured memory_bytes: 5564
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            int n = scanner.nextInt();
            int x = scanner.nextInt();
            if (n==0 && x==0) break;
            int i, j, k;
            int count = 0;
            for (i=1; i<n; i++) {
                for (j=i+1; j<n; j++) {
                    for (k=j+1; k<=n; k++) {
                        if ((i+j+k)==x) {
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}



Measured memory_bytes: 26460
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::collections::HashMap;

fn main() {
    scan!(_n; usize);
    scan!(array; Vec<i128>);

    let mut book: HashMap<i128, i128> = HashMap::new();
    let mut sum: i128 = 0;
    for &a in array.iter() {
        sum += a;
        let elm = book.entry(a).or_insert(0);
        *elm += 1;
    }

    scan!(q; usize);

    for _ in 0..q {
        scan!(b, c; i128);

        let b_num = match book.get(&b) {
            Some(v) => *v,
            None => 0,
        };
        sum -= b_num * b;
        sum += b_num * c;
        let c_num = match book.get(&c) {
            Some(v) => *v,
            None => 0,
        };
        book.insert(b, 0);
        book.insert(c, b_num + c_num);

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


Measured memory_bytes: 10740
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   


int32_t main() 
{ 
    fastio
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i,s.size()){
    s[i] = (s[i]-'A'+n)%26 + 'A';
  }
  
  cout << s << endl; 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
      int sum=0,n,c=0;
      cin>>n;
      while(n>0){
            sum=n%10;

        if(sum==2){
            c++;
        }

            n=n/10;
      }

      cout<<c<<endl;


   return 0;

      }




Measured memory_bytes: 256
# coding: utf-8

def mul(p1, p2):
    return (p1[0] - p2[0]) * (p1[1] + p2[1]) * 1.0

n = input()
cnt = 1

while n != 0:
    data = []
    for i in range(n):
        data.append(map(int, raw_input().split()))
    data.append(data[0])

    areaSum = 0.0
    for i in range(n):
        areaSum = areaSum + mul(data[i],data[i+1])
    print cnt, abs(areaSum) / 2
    cnt = cnt + 1
    
    raw_input()
    n = input()

Measured memory_bytes: 4720
a,b,money=list(map(int,input().split()))
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
for i in range(1,a+1):
  A[i]+=A[i-1]
for j in range(1,b+1):
  B[j]+=B[j-1]
ans=0
b_cnt=b
for a_cnt in range(a+1):
  if A[a_cnt]>money:
    continue
  while A[a_cnt]+B[b_cnt]>money:
    b_cnt-=1
  ans=max(ans,a_cnt+b_cnt)
print(ans)

Measured memory_bytes: 118696
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;
  if(s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[0]) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main()
{
   map<string,int>m;
  int n,i;
  cin>>n;
  for(i=0;i<n;i++){
    string s;
    cin>>s;
    m[s]++;
  }
  cout<<"AC"<<" "<<"x "<<m["AC"]<<endl;
  cout<<"WA"<<" "<<"x "<<m["WA"]<<endl;
  cout<<"TLE"<<" "<<"x "<<m["TLE"]<<endl;
  cout<<"RE"<<" "<<"x "<<m["RE"]<<endl;

   return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=4e5+9;
	int head[N],nex[N],to[N],cnt,st[N],top;
	inline void adde(int u,int v){
		nex[++cnt]=head[u];
		head[u]=cnt,to[cnt]=v;
	}
	int col[N];
	inline void dfs(int u){
		for(int i=head[u];i;i=nex[i]) 
			if(!col[to[i]]) col[to[i]]=-col[u],dfs(to[i]);
	}
	struct Graph{
		int head[N],nex[N],to[N],deg[N],cnt,rt;
		inline void add(int u,int v){
			nex[++cnt]=head[u];
			head[u]=cnt,to[cnt]=v;
		}
		inline void dfs(int u){
			for(int i=head[u];i;i=nex[i]){
				dfs(to[i]);
				if(!(deg[to[i]]&1)) st[++top]=to[i];
			}
			while(top>=2)
				adde(st[top],st[top-1]),adde(st[top-1],st[top]),top-=2;
		}
	}A,B;
	int n;
	int main(){
		n=read<int>();
		for(int i=1;i<=n;i++){
			int fa=read<int>();
			if(fa==-1) A.rt=i;
			else A.add(fa,i),A.deg[fa]++;
		}
		for(int i=1;i<=n;i++){
			int fa=read<int>();
			if(fa==-1) B.rt=i;
			else B.add(fa,i),B.deg[fa]++;
		}
		for(int i=1;i<=n;i++)
			if((A.deg[i]&1)^(B.deg[i]&1)) puts("IMPOSSIBLE"),exit(0);
		puts("POSSIBLE");
		A.dfs(A.rt),top=0,B.dfs(B.rt);
		for(int i=1;i<=n;i++) if(!(A.deg[i]&1) && !col[i]) col[i]=1,dfs(i);
		for(int i=1;i<=n;i++)
			printf("%d%c",col[i]," \n"[i==n]);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 12096
#include <stdio.h>


int main(void)
{
 
  int num1, num2, r, tmp;
 
  
  scanf("%d", &num1);
  scanf("%d", &num2);
 
  
  if(num1<num2){
    tmp = num1;
    num1 = num2;
    num2 = tmp;
  }
 
  
  r = num1 % num2;
  while(r!=0){
    num1 = num2;
    num2 = r;
    r = num1 % num2;
  }
 
  
  printf("%d\n", num2);
 
  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a  >> b ;
  int x;
  
  if(a*b%2==x){
    cout << "Even" << endl;
  }
  
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long ans = 0;
		long[][] mat = new long[3][n];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < n; j++) {
				mat[i][j] = scanner.nextInt();
			}
			Arrays.sort(mat[i]);
		}
		long[] r01 = new long[n];
		long[] r12 = new long[n];

		for (int i = n-1,j=n-1; i >= 0 && j>=0;) {
			if (mat[0][i] < mat[1][j]) {
				r01[j] = i + 1;
				j--;
			}else{
				i--;
			}
		}
		for (int i = 0,j=0; i < n && j < n;) {
			if (mat[1][i] < mat[2][j]) {
				r12[i] = n-j;
				i++;
			}else{
				j++;
			}
		}
		for (int i = 0; i < n; i++) {
			ans += r01[i] * r12[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 99228
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

    vector<vector<int>> S(N);
    for (int m = 0; m < M; m++) {
        int K;
        cin >> K;
        for (int k = 0; k < K; k++) {
            int s;
            cin >> s;
            S[s - 1].push_back(m);
        }
    }

    vector<int> P(M);
    for (int m = 0; m < M; m++) {
        cin >> P[m];
    }

    int res = 0;
    for (int n = 0; n < (1 << N); n++) {
        vector<int> count(M);
        fill(count.begin(), count.end(), 0);
        for (int i = 0; i < N; i++) {
            if ((n >> i) % 2) {
                for (auto const & m: S[i]) count[m]++;
            }
        }
        bool flag = true;
        for (int m = 0; m < M; m++) {
            if (count[m] % 2 != P[m]) flag = false;
        }
        if (flag) res++;
    }

    cout << res << endl;


    return 0;
}


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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fa(x,y) for(auto x:y)
#define endl '\n'
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fr(i,x,n) for(i=x;i>=n;--i)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    auto x=abs(a-c);
    auto y=abs(a-b);
    auto z=abs(b-c);
    if(x<=d||(y<=d&&z<=d)) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,t,n,x,s;
	while(scanf("%d %d",&n,&x)!=EOF&&n+x)
	{
		s=0;
		for(i=1;i<=n;i++)
			for(j=i+1;j<=n;j++)
				for(t=j+1;t<=n;t++)
					if(i+j+t==x)
						s++;
		printf("%d\n",s);
	}
	return 0;
}



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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    rep(i,n){
        int a;
        cin >> a;
        sum += a-1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include <iomanip>
using namespace std;


int main()
{
    double n,tmp;
    cin>>n;
    vector<double>v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    sort(v.begin(),v.end(),greater<int>());//降順
    
    int N=n;
    for(int i=0;i<n-1;i++){
        tmp=(v[N-1]+v[N-2])/2;
        v.pop_back();
        v.pop_back();
        v.push_back(tmp);
        N--;
    }
    
    cout<<v[0]<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <tuple>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <cmath>

using namespace std;
using lint = long long int;


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

	lint count = 0;
	for (int i = 1; i < n; i++)
		count += i;

	cout << count;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <cstdio>

using namespace std;

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

    int count = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            count++;
        }
    }

    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 2748
D, N = map(int, raw_input().split())
if N == 100:
 if D == 0:
    print(101)
 elif D == 1:
    print(10100)
 elif D == 2:
    print(1010000)
elif D == 0:
  print(N)
elif D == 1:
  print(N*100)
elif D == 2:
  print(N*10000)

Measured memory_bytes: 2568
D = sorted(list(map(int,input().split())))
A,B,C = D
if (C-B)%2==0 and (B-A)%2==0:
    n = (C-B)//2+(C-A)//2
elif (C-B)%2==1 and (B-A)%2==0:
    n = (B-A)//2+(C-B)
elif (C-B)%2==0 and (B-A)%2==1:
    n = (C-B)//2+1 +(C+1-A)//2
elif (C-B)%2==1 and (B-A)%2==1:
    n = 1+(C-B-1)//2+1+(C-A)//2
print(n)

Measured memory_bytes: 61440
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

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

int main()
{
    string s, ans = "AC";
    cin >> s;

    if (s[0] != 'A')
    {
        ans = "WA";
    }

    string subs = s.substr(2, s.size() - 2 - 1);
    // cout << subs << endl;

    int flag2 = 0;

    rep(i, subs.size())
    {
        if (subs[i] == 'C')
        {
            flag2++;
        }
    }
    if (flag2 != 1)
    {
        ans = "WA";
    }

    rep(i, s.size())
    {
        if (s[i] != 'C' && s[i] != 'A')
        {
            if (s[i] < 'a' || s[i] > 'z')
            {
                ans = "WA";
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <iostream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    string s;
    ll q;
    cin >> s >> q;
    
    int t, f;
    string c;
    bool rev = false;
    string s2;
    rep(i,q){
        cin >> t;
        if(t==1){
            //反転
            //rev = !rev;
            swap(s,s2);
        }
        if(t==2){
            cin >> f >> c;
            if(f==1){
                s2 += c;
            }
            if(f==2){
                //後方にc追加
                s += c;
            }
        }
    }
    reverse(s2.begin(),s2.end());
    cout << s2 << s;
    return 0;
}


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

typedef pair<int, int> ii;

int A[100005];
int B[100005];
long long prefixSum[100005];

long long sum(int a, int b){
    return prefixSum[b]-prefixSum[a-1];
}

int main(){
    int N, M, V, P;
    scanf("%d%d%d%d", &N, &M, &V, &P);

    for(int i = 1; i <= N; i ++){
        scanf("%d", &A[i]);
        B[i] = A[i];
    }

    sort(A+1, A+(1+N));
    sort(B+1, B+(1+N));
    reverse(A+1, A+(1+N));

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

    int ans = 0;
    int indx = -1;
    for(int i = 1; i <= N; i ++){
        if(A[i] >= A[P]){
            // all such problems have a chance
            ans ++;
        }else{
            indx = i;
            break;
        }
    }

    if(ans == N){
        printf("%d", N);
        return 0;
    }

    long long maxVotes = (long long)(V-1)*M; // best case always to vote for yourself

    for(int i = 1; i <= N; i ++){
        //printf("A[%d]=%d\n", i, A[i]);
    }

    for(int i = indx; i <= N; i ++){
        //printf("A[%d]=%d\n", i, A[i]);

        if(A[i] + M < A[P]){break;}

        // It's best to increase the number of votes of those in the top P-1
        long long votesCnt1 = (long long)(P-1)*M;

        long long cutoff = A[i]+M;

        long long votesCnt2 = cutoff*(i-P) - sum(P, i-1);
        long long votesCnt3 = (long long)(N-i)*M;

        //printf("votesCnt1=%lld votesCnt2=%lld votesCnt3=%lld\n", votesCnt1, votesCnt2, votesCnt3);

        long long curVotes = votesCnt1+votesCnt2+votesCnt3;
        if(curVotes >= maxVotes){
            ans ++;
        }
    }

    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

// const int mod = 1e9 + 7;
// const int mod = 998244353;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

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

int main(){
  lint d,t,s;
  cin>>d>>t>>s;
  if(t*s>=d)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<sstream>
#include<list>
#include<algorithm>
using namespace std;
 
int main(int argc,char* argv[]){
  std::ios_base::sync_with_stdio(false);
  int n,key;
  list<int> li;
  string str;
  list<int>::iterator itli;
 
  cin>>n;
 
   
  while(n--){
    cin>>str;
 
    if(str[6]=='F') li.pop_front();
    else if(str[6]=='L') li.pop_back();
    else{
      cin>>key;
      if(str[0]=='i')
    li.push_front(key);
      else{
    itli=find(li.begin(),li.end(),key);
    if(itli!=li.end())
      li.erase(itli);
      }
    }
  }
 
  itli=li.begin();
  cout<<*itli++;
  while(itli!=li.end()){
    cout<<" "<<*itli++;
  }
  cout<<endl;
}

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

#define MAX 2000000

int A[MAX + 1], heap_size;

void maxHeapify(int i) {
    int l, tmp;
    if (i*2 <= heap_size && A[i*2] > A[i]) l = i*2;
    else l = i;
    if (i*2+1 <= heap_size && A[i*2+1] > A[l]) l = i*2+1;
    if (l != i) {
        tmp = A[i];
        A[i] = A[l];
        A[l] = tmp;
        maxHeapify(l);
    }
}

int heapMaximum() {
    return A[1];
}

void heapExtractMax() {
    int max = heapMaximum();
    printf("%d\n", max);
    A[1] = A[heap_size];
    heap_size--;
    maxHeapify(1);
    return;
}

void heapIncreaseKey(int k) {
    int i = heap_size, tmp;
    A[i] = k;
    while (i > 1 && A[i/2] < A[i]) {
        tmp = A[i];
        A[i] = A[i/2];
        A[i/2] = tmp;
        i /= 2;
    }
}

void maxHeapInsert(int k) {
    A[++heap_size] = -1;
    heapIncreaseKey(k);
}

int main(void){
    int n;
    char command[8];
    
    heap_size = 0;
    
    while (1) {
        scanf("%s", command);
        if (!strcmp("insert", command)) {
            scanf("%d", &n);
            maxHeapInsert(n);
            continue;
        }
        if (!strcmp("extract", command)) {
            heapExtractMax();
            continue;
        }
        break;
    }
    
    return 0;
}




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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  vi arr(n);
  REP(i, 0, n)  cin >> arr[i];

  int cnt = 0;
  REP(i, 0, n){
      if(arr[i] != i + 1)
        cnt++;
  }
  if(cnt <= 2)
    cout << "YES\n";
  else
    cout << "NO\n";

  return 0;
}


Measured memory_bytes: 256