akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)

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

  int train = min(A, B);
  int bus = min(C, D);

  cout << train + bus << endl;
}

Measured memory_bytes: 3624
N = gets.to_i
array = gets.split.map(&:to_i)
Q = gets.to_i
b_c = []
Q.times do
  b_c << gets.split.map(&:to_i)
end

sum = array.sum

a=Array.new(10**5+1,0)
array.each do |i|
  a[i] += 1
end

b_c.each do |j|
  count = a[j[0]]
  sum += (count*j[1] - count*j[0])
  a[j[1]] += a[j[0]]
  a[j[0]] = 0
  puts sum
end


Measured memory_bytes: 29392
#include <stdio.h>
#include <math.h>
// 入力a,bの平均値の小数点以下を切上げた値を出力
int main(void) {
  int a, b, c;
  scanf("%d%d",&a,&b);
  c = ceil((a + b) / 2.0);
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 128
n, k = [int(input()) for _ in range(2)]

result = 10 ** 9

for bit in range(2 ** n):
  
  tmp = 1
  for i in range(n):
    if bit & (1 << i):
      tmp *= 2
    else:
      tmp += k
  
  result = min(result, tmp)
  
print(result)

Measured memory_bytes: 9092
n = int(input())
c = 2
tmp = 26
b4 = 0
while(n > tmp):
  b4 = tmp
  tmp = tmp + (26 ** c)
  c+=1
#97

ans = ""
tt = n-b4-1
mod = 26**(c-1)
for i in range(c):
  ans += chr(97+int(tt/mod))
  tt -= int(tt/mod)*mod
  mod = mod//26
print(ans[1:])

Measured memory_bytes: 61892
while True:
    data = list(input().split(" "))
    a = int(data[0])
    b = int(data[2])
    if data[1] == "?":
        break
    elif data[1] == "+":
        print(a+b)
    elif data[1] == "-":
        print(a-b)
    elif data[1] == "*":
        print(a*b)
    else:
        print(a//b)

Measured memory_bytes: 7700
import numpy as np
n,q=map(int,input().split())
s=list(input())
t=np.zeros(n+1,dtype=int)
for i in range(n-1):
    if s[i]+s[i+1]=="AC":
        t[i+1]=1
t=t.cumsum()
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

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

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

using ll = long long;
using P = pair<ll,ll>;
using grid = vector<vector<int>>;

const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int INF = 1<<30;
const ll mod = 998244353LL;

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

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

int main() {
    ll N,A,B,K;
    cin>>N>>A>>B>>K;
    queue<P> q;
    rep(i,N+1){
        ll t = K - A*i;
        if(t<0) break;
        if(t%B!=0) continue;
        if(t/B>N) continue;
        q.push(make_pair(i,t/B));
    }
    ll ans = 0;
    vector<ll> C(N+1,1LL);
    rep(i,N){
        C[i+1] = (((C[i]*(N-i))%mod)*pow(i+1,mod-2,mod))%mod;
    }
    while(!q.empty()){
        P p = q.front();
        q.pop();
        ans = (ans + C[p.first]*C[p.second])%mod;
    }
    if(ans<0) ans+=mod;
    cout<<ans<<endl;
}

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

int main() {
	int a;
int ans;
cin>>a;
int b=(a-a%100)/100;
int c=a%100;
if(c<=b*5){
ans=1;}
else{
ans=0;
}
cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String w = br.readLine();
    	int count = 0;
    	int owari = 0;
    	while (true)
    	{
    		String[] si = br.readLine().split(" ");
        	for (int i = 0; i < si.length; i++)
        	{
        		if (si[i].equals("END_OF_TEXT"))
        			{
        				owari++;
        				break;
        			}
        		String so = si[i];
        				if (w.equalsIgnoreCase(so))
                    		{
        						count++;
                    		}
        	}
        	if (owari == 1)
        		break;
    	}
    	System.out.println(count);
	}

}

Measured memory_bytes: 24364
/*
Stay innocent, be naive. 
But still dream big. 
Dream big to the point that it is beyond your ability and endeavour to achieve it. 
So dream big and don’t lose your innocence.
*/
import java.util.*;
import java.io.*;

   public class Main
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int M = Integer.parseInt(st.nextToken());
         int D = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int m=1; m <= M; m++)
            for(int d=21; d <= D; d++)
            {
               int x = d/10;
               int y = d%10;
               if(x*y == m && x >= 2 && y >= 2)
               {
                  res++;
                  //System.out.println(m+" "+d);
               }
            }
         System.out.println(res);
      }
   }

Measured memory_bytes: 22612
x = int(input())
for a in range(-300,301):
  if(a<0):
    for b in range(-300,a):
      if(a**5-b**5==x):
        print(a,b)
        break
    else: continue
    break
  else:
    for b in range(-300,a):
      if(a**5-b**5==x):
        print(a,b)
        break
    else: continue
    break

Measured memory_bytes: 65992
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n,k,ar[N],ans,cnt;
ll sum[N];
ll seg[4*N];
vector < ll > vals;
map < ll,ll > mapper;

ll get_sum(ll i,ll j)
{
    if(i == 0)
        return sum[j];

    return sum[j] - sum[i-1];
}

ll query(ll low,ll high,ll pos,ll slow)
{
    if(high <= slow)
        return seg[pos];
    if(low > slow)
        return 0;

    ll mid = (low+high)/2;

    return query(low,mid,pos*2+1,slow)+query(mid+1,high,pos*2+2,slow);
}

void update(ll low,ll high,ll pos,ll slow)
{
    if(low == slow && low == high)
    {
        seg[pos]++;
        return;
    }
    if(low > slow || high < slow)
        return;

    ll mid = (low+high)/2;

    update(low,mid,pos*2+1,slow);
    update(mid+1,high,pos*2+2,slow);
    seg[pos] = seg[pos*2+1] + seg[pos*2+2];
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> k;

    rep(i,0,n)
    {
        cin >> ar[i];

        ar[i] -= k;

        if(i == 0)
            sum[i] = ar[i];
        else
            sum[i] = sum[i-1] + ar[i];

        vals.push_back(sum[i]);
    }

    vals.push_back(0);
    sort(vals.begin(),vals.end());

    rep(i,0,vals.size())
    {
        if(!mapper[vals[i]])
        {
            mapper[vals[i]] = cnt;
            cnt++;
        }
    }

    update(0,cnt,0,mapper[0]);

    rep(i,0,n)
    {
   //     cout << sum[i] << " " << mapper[sum[i]] << " " << query(0,cnt,0,mapper[sum[i]]) << endl;
        ans += query(0,cnt,0,mapper[sum[i]]);
        update(0,cnt,0,mapper[sum[i]]);
    }

    cout << ans;

    return 0;
}



Measured memory_bytes: 25968
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int N;
    cin>>N;
    cout << 800*N-N/15*200 << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint c(n,0);
    vint s(n,0);
    vint f(n,0);
    REP(i,n-1) cin >> c[i] >> s[i] >> f[i];
    REP(i,n){
        int now = i;
        int ret = 0;
        while(now<n-1){
            ret = max(s[now],ret);
            ret = ((ret-1)/f[now]+1)*f[now];
            ret += c[now];
            now++;
        }
        cout << ret << "\n";
    }

    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a[300];
	while(~scanf("%d",&n))
	{
		int sum=0;
		for(int i=0;i<2*n;i++)
		scanf("%d",&a[i]);
		sort(a,a+n*2);
		for(int i=0;i<2*n-1;i=i+2)
		{
			sum=sum+a[i];
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
cost = 0
if X > Y:
    max_index = A
    M = X
else:
    max_index = B
    M = Y

if A + B > 2 * C:
    if max_index > 2 * C:
        cost += C * 2 * M
    else:
        cost += C * 2 * min(X, Y) + max_index * (M - min(X, Y))
else:
    cost += A * X + B * Y

print(cost)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int i=1;
        int x=0;
        while(true){
            x = Integer.parseInt(br.readLine());
            if(x == 0) break;
            sb.append("Case");
            sb.append(" ");
            sb.append(Integer.toString(i++));
            sb.append(":");
            sb.append(" ");
            sb.append(Integer.toString(x));
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26660
#include<bits/stdc++.h>
using namespace std;
int n,a[110],ans=1e9;
int main(){
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++){
		int sum=0,num=0;
		for (int j=1;j<=i;j++) sum+=a[j];
		for (int j=i+1;j<=n;j++) num+=a[j];
		ans=min(ans,abs(sum-num));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {

  string s;
  cin>>s;
  if(s[0]=='7') cout<<"Yes"<<endl;
  else if(s[1]=='7') cout<<"Yes"<<endl;
  else if(s[2]=='7') cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  

}


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

int main (void){
  
    char s[1000001];
    char t[1000000];
    int len;

    scanf("%s",s);
    len = strlen(s);

    for(int i = 0; i<(len+1)/2; i++){
          t[i] = s[2*i];
    }

    printf("%s",t);

    return 0;   
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    if(K <= A){
        cout << K << endl;
    }
    else if ( K <= A + B)
    {
        cout << A << endl;
    }
    else
    {
        cout << 2*A + B - K << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<char>> vec(2,vector<char>(3));
for (int i = 0;i < 2;i++) {
  for (int j = 0;j < 3;j++) {
    cin >> vec[i][j];
  }
}
if (vec[0][0] == vec[1][2] && vec[0][1] == vec[1][1] && vec[0][2] == vec[1][0]) {
  cout << "YES" << endl;
} else cout << "NO" << endl;


return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
count = {}
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
first = 0
for i, c in sorted(count.items(), key = lambda x: x[0], reverse = True):
    if c >= 4 and not first:
        print(i * i)
        exit()
    elif c >= 2:
        if first:
            print(first * i)
            exit()
        else:
            first = i
print(0)

Measured memory_bytes: 22052
#include <bits/stdc++.h>
#define lld long long
#define nmax 1005
#define pii pair<int,int>
#define pb push_back
using namespace std;

int dl[] = {-1,0,1,0};
int dc[] = {0,1,0,-1};
int ans, n, m;
queue<pii>q, q2;
bool st[nmax][nmax];
char a[nmax][nmax];

bool interior(int i, int j){
    return i >= 1 && j >= 1 && i <= n && j <= m;
}

int main() {
    cin>>n>>m;
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            cin>>a[i][j];
            if (a[i][j] ==  '#'){
                st[i][j] = true;
                q.push(make_pair(i,j));
            }
        }
    }
    while (!q.empty()){
        ++ans;
        while (!q2.empty()){q2.pop();}
        while (!q.empty()){
            auto act = q.front();
            int i = act.first, j = act.second;
            q.pop();
            for (int k=0;k<4;++k){
                if (!interior(i+dl[k],j+dc[k])){
                    continue;
                }
                if (st[i+dl[k]][j+dc[k]]){
                    continue;
                }
                if (a[i+dl[k]][j+dc[k]] == '#'){
                    continue;
                }
                st[i+dl[k]][j+dc[k]] = true;
                q2.push(make_pair(i+dl[k],j+dc[k]));
            }
        }
        q = q2;
    }
    --ans;
    if (ans < 0){
        ans = 0;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 10496
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


x, y = MI()

g1 = {1, 3, 5, 7, 8, 10, 12}
g2 = {4, 6, 9, 11}
if (x in g1 and y in g1) or (x in g2 and y in g2) or x == y == 2:
    print('Yes')
else:
    print('No')


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

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

    long long int L1 = 2, L2 = 1;
    for (int i = 0; i < N - 1; i++) {
        long long int tmp = L1;
        L1 = L2;
        L2 = tmp + L2;
    }
    cout << L2 << endl;
}

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

int main(){
    int N; cin >> N;
    int ans = 0, count = 0;
    for (int i = 0; i < N; i++)
    {
        int A; cin >> A;
        if(A % 2 != 0) continue;
        else {
            ans++;
            if(A % 3 == 0 || A % 5 == 0) count++;
        }
    }
    if(count == ans) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;    

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <memory>
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;

  cin >> n;
  std::vector<int> v(n);
  std::vector<int64_t> mxs;
  for (auto& el : v) {
    cin >> el;
  }

  std::sort(v.begin(), v.end());
  int64_t cur_sum = 0;
  for (const auto& el : v) {
    mxs.push_back(max((el - 2 * cur_sum + 1) / 2, (int64_t)0));
    cur_sum += el;
  }
  int ans = 0;
  int last = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (mxs[i] != 0) {
      last = i;
      break;
    }
  }
  int64_t mx = 0;
  for (int i = 0; i < last; i++) {
    mx = max(mx, mxs[i]);
  }
  if (mx <= v[last]) {
    ans = 1;
  }
  mx = max(mx, mxs[last]);

  for (int i = last + 1; i < n; i++) {
    if (mx <= v[i]) {
      ans++;
    }
  }

  cout << ans << endl;
}

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

int main()
{
    int age, charge, res;
    cin >> age >> charge;
    if (age >= 13)
    {
        res = charge;
    }
    else if (age >= 6)
    {
        res = charge / 2;
    }
    else
    {
        res = 0;
    }
    cout << res;
}

Measured memory_bytes: 256
def input_li():
    return list(map(int, input().split()))

def input_int():
    return int(input())

N, K = input_li()
h_li = input_li()
dp = [10 ** 9 + 7] * N
dp[0] = 0
for i in range(N):
    for j in range(1, K + 1):
        if i + j < N:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h_li[i] - h_li[i + j]))
print(dp[-1])


Measured memory_bytes: 84752
N = int(input())
lS = [list(input()) for _ in range(N)]
S = [''.join(sorted(s)) for s in lS]
S = sorted(S)

cnt = 1
S.append('end')
last = S[0]
res = 0
for s in S[1:]:
    if last == s:
        cnt += 1
    else:
        res += cnt * (cnt-1) /2
        last = s
        cnt = 1

print(int(res))


Measured memory_bytes: 32652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
std::vector<string> V(maxn);
struct NODE{
	int ch[26],cnt[26];
	int siz;
}trie[maxn];
int vcnt;
inline void ins(const string &s) {
	int root=0;stack<int> S;
	for(int i=0;i<s.length();i++) {
		int tmp=s[i]-'a';S.push(root);
		if(!trie[root].ch[tmp]) trie[root].ch[tmp]=++vcnt;
		root=trie[root].ch[tmp];trie[root].siz++;
	}
	while(!S.empty()) {
		int temp=S.top();S.pop();
		for(int i=0;i<26;i++) {
			trie[temp].cnt[i]=0;
			for(int j=0;j<26;j++) {
				if(trie[temp].ch[j]) {
					if(i==j) trie[temp].cnt[i]+=trie[trie[temp].ch[j]].siz;
					else trie[temp].cnt[i]+=trie[trie[temp].ch[j]].cnt[i];
				}
			}
		}
	}
}
ll ans=0;
void calc(const string &s) {
	int root=0;
	if(s.length()==1) ans+=trie[root].cnt[s[0]-'a']-1;
	else 
	for(int i=0;i<s.length();i++) {
		root=trie[root].ch[s[i]-'a'];
		if(i==s.length()-2) ans+=trie[root].cnt[s[i+1]-'a']-1;
	}
}
int main() {
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>V[i],reverse(V[i].begin(),V[i].end()),ins(V[i]);
	for(int i=1;i<=n;i++) calc(V[i]);
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 243796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
const ll MOD = 1e+9+7;

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

ll n_mod(ll x){
    ll ans=1;
    while(x>0){
        ans*=(x%MOD);
        ans%=MOD;
        x--;
    }
    return ans;
}
int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll res ;
    res=mod_pow((ll)2,n,MOD)-1;
    vector<int> nCk(2*1e+5+1);
    nCk[0]=1;
    rep2(i,1,2*1e+5+1){
        nCk[i]=((nCk[i-1]*((n-i+1)%MOD))%MOD*mod_pow((ll)i,MOD-2,MOD))%MOD;
    }
    if(res<nCk[a]) res+=MOD;
    res = ( res - nCk[a])%MOD;
    if(res<nCk[b]) res+=MOD;
    res = ( res - nCk[b])%MOD;

    cout << res << endl;
        
    

   
}

Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
--import Data.Array
import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete





main = do
    getInt >>= flip replicateM getInts >>= putStrLn . tjoin . maximumBy (comparing snd <> flip (comparing fst)) . map (apply2 (,))


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1e9+7;
ll add(ll a, ll b)
{
    return ((a%mod)+(b%mod))%mod;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll n,w;
   cin>>n>>w;
   if(n>w) cout<<"safe\n";
   else cout<<"unsafe\n";

}



Measured memory_bytes: 3636
from itertools import permutations
import math

N=int(input())
pts=[list(map(int,input().split())) for _ in range(N)]

cnt=0
ans=0.0
for p in permutations(range(N)):
    cnt+=1
    for i in range(N-1):
        dx=pts[p[i+1]][0]-pts[p[i]][0]
        dy=pts[p[i+1]][1]-pts[p[i]][1]

        ans+=math.sqrt(dx**2+dy**2)

print(ans/cnt)



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

int main()
{
    int res;
    for(int i=0;i<5;i++)
    {
        int data ;
        cin >> data;

        if(data==0)
            res = i+1;
    }
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 3596
public class Main {
	public static void main(String[] args) {
		int N = NI();
		int a[] = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = NI();
		}
		long ans = 0;
		if (a[0] == 0) {
			a[0] = 1;
			ans = solve(a);
			a[0] = -1;
			ans = Math.min(ans, solve(a));
			ans++;
		} else {
			ans = solve(a);
			if (a[0] > 0) {
				int tmp = a[0];
				a[0] = -1;
				ans = Math.min(ans, solve(a) + tmp + 1);
			} else {
				int tmp = a[0];
				a[0] = 1;
				ans = Math.min(ans, solve(a) + -tmp + 1);
			}
		}
		System.out.println(ans);
	}
	private static long solve(int[] a) {
		long ans = 0;
		long sum = a[0];
		for (int i = 1; i < a.length; i++) {
			if (sum > 0) {
				if (sum + a[i] >= 0) {
					ans += sum + a[i] + 1;
					sum = -1;
				} else {
					sum += a[i];
				}
			} else {
				if (sum + a[i] <= 0) {
					ans += -sum - a[i] + 1;
					sum = 1;
				} else {
					sum += a[i];
				}
			}
		}
		return ans;
	}
	static int NI(){
		try {
			int c=System.in.read(),r=0;
			for(;c!='-'&&(c<'0'||'9'<c);)c=System.in.read();
			if(c=='-') return -NI();
			for(;'0'<=c&&c<='9';c=System.in.read())
				r = r * 10 + c - '0';
			return r;
		} catch (Exception e) {
			return -1;
		}
	}
	static String next() {
		try {
			StringBuilder res = new StringBuilder("");
			int c = System.in.read();
			while (Character.isWhitespace(c))
				c = System.in.read();
			do {
				res.append((char) c);
			} while (!Character.isWhitespace(c = System.in.read()));
			return res.toString();
		} catch (Exception e) {
			return null;
		}
	}
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
	int n;
	cin>>n;
	ll minn = LONG_MAX;
	ll sum = 0;
	ll cnt = 0;
	rep(i, 0, n)
	{
		ll x;
		cin>>x;
		if(x < 0) cnt++;
		chmin(minn, abs(x));
		sum += abs(x); 
	}
	//cout<<minn<<" "<<sum<<" "<<cnt<<endl;
	if(cnt%2 == 0) cout<<sum<<endl;
	else cout<<(sum - 2*minn)<<endl;


}


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

int main() {

    int n;
    scanf("%d", &n);

    long mysum = 0;

    int cnt = 1;

    while (cnt <= n) {
        if (!(cnt % 3 == 0 || cnt % 5 == 0)) {
            mysum += cnt;
        }
        cnt++;
    }

    printf("%ld", mysum);

    return 0;

}

Measured memory_bytes: 1736
N = int(input())
A = list(map(int, input().split()))

Q = int(input())

count = [0] * (10**5 + 1)
for a in A:
    count[a-1] += 1

s = sum(A)
ans = []
for i in range(Q):
    a, b = map(int, input().split())

    s = s - a * count[a-1] + b * count[a-1]
    ans.append(s)
    count[b-1] += count[a-1]
    count[a-1] = 0

print(*ans, sep="\n")

Measured memory_bytes: 22024
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using ll = long long;
const ll N = 200500;
using ii = pair <ll , ll>;
ll freq[N],n,a[N],ways[N],pans[N];

ll choose(ll k) {
	return (k * (k - 1)) / 2;
}

ll rp(ll l , ll r) {
	if (l > r) return 0;
	return pans[r] - pans[l - 1];
}

int main() {
	scanf("%lld" , &n);
	for (ll i = 1 ; i <= n ; i++) {
		scanf("%lld" , &a[i]);
		freq[a[i]]++;
	}
	for (ll i = 1 ; i < N ; i++) {
		ways[i] = choose(freq[i] - 1);
		pans[i] = pans[i - 1] + choose(freq[i]);
	}
	for (ll i = 1 ; i <= n ; i++) {
		ll sol = pans[a[i] - 1] + rp(a[i] + 1 , N - 1);
		sol += ways[a[i]];
		printf("%lld\n" , sol);
	}
 	return 0;
}


Measured memory_bytes: 8832
// --------------
// Tejas Pandey  |
// 21 - 03 - 20  |
// AtCoder BC 159|
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 998244353
#define vi vector<int>
typedef long long int ll;

int main (void)
{
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  int n;
  cin >> n;
  ll a[n],fr[n + 1];
  memset(fr,0,sizeof(fr));
  for(int i = 0;i < n;i++)
	cin >> a[i],fr[a[i]]++;
  ll ans = 0;
  for(int i = 1;i <= n;i++)
	ans += (fr[i]*(fr[i] - 1))/2;
	for(int i = 0;i < n;i++){
		ans -= (fr[a[i]]*(fr[a[i]] - 1))/2;
		ans += ((fr[a[i]] - 2)*(fr[a[i]] - 1))/2;
		cout << ans << "\n";
		ans += (fr[a[i]]*(fr[a[i]] - 1))/2;
		ans -= ((fr[a[i]] - 2)*(fr[a[i]] - 1))/2;
	}
  return 0;
}

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

using namespace std;

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

	string s,t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;

	if (s == u){
		a--;
	} else {
		b--;
	}
	cout << a << ' ' << b << endl;
}


Measured memory_bytes: 256
def calc(l):
	A1=2*(l[1][0]-l[0][0])
	B1=2*(l[1][1]-l[0][1])
	C1=l[0][0]**2-l[1][0]**2+l[0][1]**2-l[1][1]**2
	A2=2*(l[2][0]-l[0][0])
	B2=2*(l[2][1]-l[0][1])
	C2=l[0][0]**2-l[2][0]**2+l[0][1]**2-l[2][1]**2
	X=(B1*C2-B2*C1)/(A1*B2-A2*B1)
	Y=(C1*A2-C2*A1)/(A1*B2-A2*B1)
	R=((X-l[0][0])**2+(Y-l[0][1])**2)**0.5
	return tuple(map(round, [X,Y,R], [3]*3))
l=[zip(*[iter(map(float,raw_input().split()))]*2) for i in range(input())]
for ll in l:
	print "%.3f %.3f %.3f"%(calc(ll))

Measured memory_bytes: 4376
#include <stdio.h>

int main(void)
{
    int m;
    int f;
    int r;
    
    while ( 1 ) {
        scanf("%d %d %d", &m, &f, &r);
        if ( (m == -1) && (f == -1) && (r == -1) ) {
            break;
        } else if ( (m == -1) || (f == -1) ) {
            printf("F\n");
        } else if ( 80 <= m + f ) {
            printf("A\n");
        } else if ( (65 <= m + f) && (m + f < 80) ) {
            printf("B\n");
        } else if ( (50 <= m + f) && (m + f < 65) ) {
            printf("C\n");
        } else if ( (30 <= m + f) && (m + f < 50) ) {
            if ( r >= 50 ) {
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else {
            printf("F\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 2068
#include <iostream>
#include <cstdio>

using namespace std;

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



int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int p[n];
    for (int i=0; i < n; i++){
        cin >> p[i];
    }

    int min = p[0];
    int cnt = 1;
    for (int i=1; i < n; i++){
        if (min < p[i]) ;
        else {
            cnt++;
            min = p[i];
        }
    }

    cout << cnt << endl;


    


    

    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 1024
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
    s.append(list(map(int, input().split())))

last = [0] * 26
for d in range(D):
    max = 0
    argmax = -1
    for t in range(26):
        if max < s[d][t]:
            max = s[d][t]
            argmax = t
    print(argmax + 1)

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

int main(void){
        int a, b, c;
        string ans;
        cin >> a >> b >> c;
        if(a == b or b == c or c == a){
                if(a == b and b == c){
                        ans = "No";
                } else {
                        ans = "Yes";
                }
        } else {
                ans = "No";
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int a[100001];
 
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;	int mini=n+5;	int maxi=-1;
	for(int i=0;n>i;i++) {
		cin>>a[i];
		mini=min(mini,a[i]);
		maxi=max(maxi,a[i]);
	}
	if(maxi-mini<=1){
		int s = 0; int b = 0;
		for(int i=0;n>i;i++){
			if(a[i]==maxi){
				b++;
			}
			else if(a[i]==maxi-1){
				s++;
			}
		}
		if(b==1){
			cout << "No\n";  	return 0;
		}
		if(!s && maxi==n-1){
			cout << "Yes\n";    return 0;
		}
		int l = s + 1;		int r = s + (n-s)/2;
		if(maxi>=l && maxi<=r){
                      cout << "Yes\n";    return 0;
                }
		cout << "No\n"; return 0;
	}
	else{
		cout << "No\n";
	}
}

Measured memory_bytes: 640
s = input()

ok = True
if s[0] != "A" or s[-1] == "C" or s[1] == "C":
    ok = False
count = 0
for i in range(1, len(s)):
    if s[i] == "C" and i != len(s)-1:
        count += 1
    elif s[i] not in "abcdefghijklmnopqrstuvwxyz":
        ok = False
        break
if count != 1:
    ok = False

if ok:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define SZ(x) ((int)x.size())
typedef vector<int> vec;typedef long long LL;
const int N=1<<19,M=924844033,G=5;
int n,s[N],f[N],F[N],r[N],t[N];vec A,B,e[N];
void dfs(int f,int x){
	ref(i,0,SZ(e[x])-1){int y=e[x][i];if(y!=f)dfs(x,y),s[x]+=s[y];}
	if(x>1)A[s[x]]++,A[n-s[x]]++;
}
int mi(int a,int b,int s=1){
	for(;b;b>>=1,a=(LL)a*a%M)if(b&1)s=(LL)s*a%M;
	return s;
}
void esbs(int L){
	ref(i,1,L-1)r[i]=r[i>>1]>>1|((i&1)?(L>>1):0);
	for(int i=1;i<L;i<<=1)
		for(int j=0,W=1,w=mi(G,(M-1)/(i<<1));j<i;++j,W=(LL)W*w%M)t[i+j]=W;
}
void dft(vec&a){
	int L=SZ(a);
	for(int i=1;i<L;++i)if(r[i]<i)swap(a[r[i]],a[i]);
	for(int i=1;i<L;i<<=1)
		for(int j=0;j<L;j+=(i<<1))
			for(int k=0;k<i;++k){
				int w=(LL)a[i+j+k]*t[i+k]%M;
				a[i+j+k]=a[j+k]-w;if(a[i+j+k]<0)a[i+j+k]+=M;
				a[j+k]+=w;if(a[j+k]>=M)a[j+k]-=M;
			}
}
void idft(vec&a){
	dft(a);int L=SZ(a),w=mi(L,M-2);
	ref(i,1,(L>>1)-1)swap(a[i],a[L-i]);
	ref(i,0,L-1)a[i]=(LL)a[i]*w%M;
}
int main(){
	cin>>n;
	ref(i,2,n){int x,y;cin>>x>>y;e[x].push_back(y);e[y].push_back(x);}
	f[0]=1;ref(i,1,n)s[i]=1,f[i]=(LL)f[i-1]*i%M;
	A.resize(n);dfs(0,1);ref(i,1,n-1)A[i]=(LL)A[i]*f[i]%M;
	B.resize(n+1);ref(i,0,n)B[n-i]=F[i]=mi(f[i],M-2);
	int l=SZ(A)+SZ(B)-1,L=1;for(;L<l;L<<=1);esbs(L);
	A.resize(L);B.resize(L);dft(A);dft(B);
	ref(i,0,L-1)A[i]=(LL)A[i]*B[i]%M;idft(A);A.resize(n+n+1);
	ref(i,1,n)cout<<(M+(LL)n*f[n]%M*F[i]%M*F[n-i]%M-(LL)F[i]*A[n+i]%M)%M<<endl;
}

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

typedef long long ll;

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

    int n, k[10001];
    int flag = 0;

    cin >> n;

    while (n != 0) {
        flag = 0;
        int work = n;

        for ( int i = 0; i < n; ++i ) {
            cin >> k[i];

            if ( k[i] == 0 ) {
                work -= 1;
            } else if ( k[i] >= 2 ) {
                flag = 1;
            }
        }

        if (! flag) {
            cout << "NA" << endl;
        } else {
            cout << work + 1 << endl;
        }

        cin >> n;
    }

    return 0;
}




Measured memory_bytes: 3164
s=input()
count = 0
ans = 0
for i in range(len(s)):
    if s[i] != "A" and s[i] != "G" and s[i] != "C" and s[i] != "T":
        ans = max(ans,count)
        count = 0
    else:
        count += 1
    ans = max(ans,count)

print(ans)


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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(((C-1)/B)>((A-1)/D)){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <queue>
#include <string>

using namespace std;

vector<int> G[100000];
int dist_w[100000], dist_b[100000];
int N;

void bfs(int start, string color) {
    bool is_visited[100000] = {false};
    queue<pair<int, int>> que;
    que.push(make_pair(start, 0));
    while (!que.empty()) {
        int current_loc = que.front().first;
        is_visited[current_loc] = true;
        int dist = que.front().second;
        que.pop();
        if (color == "white")
            dist_w[current_loc] = dist;
        else
            dist_b[current_loc] = dist;

        for (int i = 0; i < G[current_loc].size(); ++i) {
            if (!is_visited[G[current_loc][i]])
                que.push(make_pair(G[current_loc][i], dist + 1));
        }
    }
}

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

    cin >> N;

    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    bfs(0, "black");
    bfs(N - 1, "white");

    int black, white;
    black = white = 0;
    for (int i = 0; i < N; ++i) {
        if (dist_b[i] <= dist_w[i])
            ++black;
        else
            ++white;
    }

    if (black > white)
        cout << "Fennec" << endl;
    else
        cout << "Snuke" << endl;

//    cout << "Score:" << endl;
//    cout << "Fennec -> " << black << endl;
//    cout << "Snuke -> " << white << endl;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;

	map<string, int> mp;
	string s;

	for(int i = 0; i < n; ++i)
	{
		cin >> s;
		mp[s]++;
	}

	int max_cnt = 0;
	for(auto& m : mp)
	{
		max_cnt = max(max_cnt, m.second);
	}

	map<string, int> mp_ans;
	for(auto& m : mp)
	{
		if (m.second == max_cnt)
		{
			mp_ans[m.first] = m.second;
		}
	}

	for(auto& m : mp_ans)
	{
		cout << m.first << endl;
	}

	

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 36352
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int l,r,flg,i,j,x,l1,r1,mn;
	scanf("%d %d",&l,&r);
	flg=1;
	if(r-l>=2019)	flg=0;
	l1=l%2019;	r1=r%2019;
	if(r1<=l1)	flg=0;
	if(flg==1)	{
		mn=2019;
		for(i=l1;i<=r1-1;i++)	{
			for(j=i+1;j<=r1;j++)	{
				x=(i*j)%2019;
				mn=min(mn,x);
			}
		}
	}
	else mn=0;
	printf("%d\n",mn);
	return 0;
}

Measured memory_bytes: 256
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

#N = int(input())
#s = [input() for i in range(N)]
#M = int(input())
#t = [input() for i in range(M)]
# print(s)
# print(t)

h, w = map(int, input().split())
if (w == 1) or(h == 1):
    print(1)
    exit()

sum = 0

sum += (math.ceil(w/2))*(math.ceil(h/2))  # 切り上げ
sum += (math.floor(w/2))*(math.floor(h/2))  # 切り捨て

print(sum)


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

using namespace std;
int memo[100005],h[100005],n;
int dp(int i){
if(i > n)
    return 1e5;
if(i==n)
    return 0;
    if(memo[i]!=-1)
        return memo[i];
int res,res1;
res=abs(h[i]-h[i+1])+dp(i+1);
res1=abs(h[i]-h[i+2])+dp(i+2);
memo[i]=min(res,res1);
return memo[i];
}

int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>h[i];
    h[n+1]=h[n+2]=1e5;
        memset(memo,-1,sizeof(memo));
    cout<<dp(1);

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    double area = H*W;
    cout << fixed << setprecision(10) << area / 2 << " ";
    if ((2*x == W) && (2*y == H)) {
        print(1);
    } else {
        print(0);
    }
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::LinkedList;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: u64 = read();
    let a: u64 = read();
    let b: u64 = read();

    println!("{}", n / (a + b) * a + std::cmp::min(a, n % (a + b)));
}


Measured memory_bytes: 4352
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    if (!isKaibun(s)) {
      pw.println("No");
      return;
    }
    if (!isKaibun(s.substring(0, (s.length() - 1) / 2))) {
      pw.println("No");
      return;
    }
    if (!isKaibun(s.substring((s.length() + 3 - 1) / 2))) {
      pw.println("No");
      return;
    }
    pw.println("Yes");
  }

  static boolean isKaibun(String s) {
    return s.equals(new StringBuilder((s)).reverse().toString());
  }
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> s >> t;
  swap(s[0], s[2]);
  rep(i, 3)
  {
    if (s[i] != t[i])
    {

      NO();
      return 0;
    }
  }
  YES();

  return 0;
}

Measured memory_bytes: 3648
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N;
  invec<ll> a(N);
  int r = 0;
  
  for (int i = 1; i < N; i++)
    r ^= a[i];
  
  REP(i, N-1) {
    cout << r << endl;
    r = r ^ a[i+1] ^ a[i];
  }

  cout << r << endl;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 4832
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}

inline void solve(void){
  long N,K;
  in(N,K);
  vector<cpp_int>a(N);
  rep(i,N)in(a[i]);
  cpp_int ans=LONG_MAX;
  for(int i=0;i<1<<N;i++){
    if(__builtin_popcount(i)<(int)K)continue;
    cpp_int now=0,cost=0;
    rep(j,N){
      if(i>>j&1&&now>=a[j]){
        cost+=now-a[j]+1;
        now++;
      }
      chmax(now,a[j]);
    }
    chmin(ans,cost);
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

#define rep(i, n) for(i=0;i<(int)(n);i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define bit(n) (1LL<<(n))
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(void){
  long long n,a,b,i,j,result=0;
  scanf("%lld %lld %lld", &n, &a, &b);
  
  i = n / (a+b);
  j = n % (a+b);
  
  result = i*a + min(j, a); 
  
  printf("%lld", result);
  return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

int main() {
    ll A, B;
    cin >> A >> B;
    vector<vector<char>> grid(100, vector<char>(100, '#'));
    for (int i = 0; i < 50; ++i) {
        for (int j = 0; j < 100; ++j) {
            grid[i][j] = '.';
        }
    }
    bool ok = true;
    bool update = false;
    for (int i = 0; i < B - 1; ++i) {
        update = false;
        for (int j = 0; j < 50 - 1; ++j) {
            for (int k = 0; k < 100; ++k) {
                ok = true;
                for (int x = -1; x <= 1; ++x) {
                    for (int y = -1; y <= 1; ++y) {
                        int dj = j + x;
                        int dk = k + y;
                        if (dj >= 0 && dj < 50 - 1 && dk >= 0 && dk < 100 && grid[dj][dk] != '.') {
                            ok = false;
                            break;
                        }
                    }
                    if (!ok) {
                        break;
                    }
                }
                if (ok) {
                    grid[j][k] = '#';
                    update = true;
                    break;
                }
            }
            if (update) {
                break;
            }
        }
    }

    for (int i = 0; i < A - 1; ++i) {
        update = false;
        for (int j = 99; j >= 51; --j) {
            for (int k = 0; k < 100; ++k) {
                ok = true;
                for (int x = -1; x <= 1; ++x) {
                    for (int y = -1; y <= 1; ++y) {
                        int dj = j + x;
                        int dk = k + y;
                        if (dj >= 51 && dj < 100 && dk >= 0 && dk < 100 && grid[dj][dk] != '#') {
                            ok = false;
                            break;
                        }
                    }
                    if (!ok) {
                        break;
                    }
                }
                if (ok) {
                    grid[j][k] = '.';
                    update = true;
                    break;
                }
            }
            if (update) {
                break;
            }
        }
    }
    cout << 100 << " " << 100 << endl;
    for (int i = 0; i < 100; ++i) {
        for (int j = 0; j < 100; ++j) {
            cout << grid[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384