akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

const int x = sqrt (3 * MAX);
int v[3 * MAX], w[3 * MAX], dp[x][MAX];
int main () {
	ios_base :: sync_with_stdio (false);
	cin.tie (nullptr);
	int n, q;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}
	int x = sqrt (n);
	for (int i = 0; i <= x; i++) {
		for (int j = 0; j < MAX; j++) {
			dp[i][j] = -MOD;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= x; i++) {
		for (int j = 0; j < MAX; j++) {
			dp[i][j] = max (dp[i / 2][j], dp[i][j]);
			if (j) {
				dp[i][j] = max (dp[i][j], dp[i][j - 1]);
			}
			if (j - w[i] >= 0) {
				dp[i][j] = max (dp[i / 2][j - w[i]] + v[i], dp[i][j]);
			}
		}
	}
	cin >> q;	
	for (int i = 0; i < q; i++) {
		int vv, l;
		cin >> vv >> l;
		vector<int> ve;
		while (vv > x) {
			ve.push_back (vv);
			vv = vv / 2;
		}
		int y = (1 << ve.size ()), ma = 0;
		for (int i = 0; i < y; i++) {
			int ww = 0, lx = 0;
			for (int j = 0; j < ve.size (); j++) {
				if ((i >> j) & 1) {
					ww += w[ve[j]], lx += v[ve[j]];
				}
			}
			if (ww <= l) {
				ma = max (lx + dp[vv][l - ww], ma);
			}
		}
		cout << ma << "\n";
	}
}


Measured memory_bytes: 205704
while True:
    (n, x) = [int (i) for i in input().split()]
    if n == x == 0:
        break

    count = 0
    for a in range(1, n + 1 -2):
        for b in range(a + 1, n + 1 - 1):
            for c in range(b + 1, n + 1):
                if (a + b + c) == x:
                    count += 1
    print(count)

Measured memory_bytes: 6720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		OriginScanner os = new OriginScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		String s = os.next();
		
		Map<String, Integer> week = new HashMap<>();
		week.put("MON", 6);
		week.put("TUE", 5);
		week.put("WED", 4);
		week.put("THU", 3);
		week.put("FRI", 2);
		week.put("SAT", 1);
		week.put("SUN", 7);
		
		pw.println(week.get(s));
		pw.close();
	}
	
	static class OriginScanner {
		private BufferedReader br;
		private StringTokenizer st;
		
		public OriginScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String nextLine() {
			String str = null;
			try {
				str = br.readLine();
			}
			catch (IOException e) {
				System.out.println(e);
			}
			return str;
		}
		String next() {
			if (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(nextLine());
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

int main()
{
    int k, n, distance, max = 0;
    cin >> k >> n;

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

    for (int i = 0; i < n; ++i) {
        distance = a[i+1] - a[i];
        if (distance > max) {
            max = distance;
        }
    }

    distance = k - a[n] + a[1];
    if (distance > max) {
        max = distance;
    }

    cout << k - max << endl;
    return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int P, Q, R;
	cin >> P >> Q >> R;

	int A = P + Q;
	int B = Q + R;
	int C = R + P;

	int ans = min({A, B, C});


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

n = len(S)
c1s = {}
c2s = {}
ans = True
for i in range(n):
    if not ans:
        break

    if S[i] in c1s:
        if c1s[S[i]] != T[i]:
            ans = False
            break
    else:
        c1s[S[i]] = T[i]
    if T[i] in c2s:
        if c2s[T[i]] != S[i]:
            ans = False
            break
    else:
        c2s[T[i]] = S[i]


print('Yes' if ans else 'No')



Measured memory_bytes: 3632
my $N =  <STDIN>;
chomp ($N);
my @A;
foreach (split(/ /o, <STDIN>)) {
  chomp($_);
  push(@A, $_) if ($_ ne '');
}
my @B;
foreach (split(/ /o, <STDIN>)) {
  chomp($_);
  push(@B, $_) if ($_ ne '');
}
my @C;
foreach (split(/ /o, <STDIN>)) {
  chomp($_);
  push(@C, $_) if ($_ ne '');
}
my $tot = 0;
my $before = -1;
foreach my $a (@A) {
  my $i = $a - 1;
  $tot += $B[$i];
  if ( $i == $before ) {
    my $j = $before - 1;
    $tot += $C[$j];
  }
  $before = $a;
}
print $tot;

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int M = 200200;
const ll inf = 1e18;

ll d[M][5];
vector<int> a;
int n;

void read() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  //while (!a.empty() && a.back() == 0)
    //a.pop_back();
  //reverse(all(a));
  //while (!a.empty() && a.back() == 0)
    //a.pop_back();

  //n = a.size();
  //for (int i = 0; i < n; ++i)
    //if (a[i] == 0) {
      //++bon;
      //++a[i];
    //}
}

int cost(int x, int t) {
  if (t == 0 || t == 4) {
    return x;
  }
  if (t == 1 || t == 3) {
    if (x == 0)
      return 2;
    else
      return x % 2;
  }
  if (t == 2) {
   
    return (x + 1) % 2;
  }
  assert(false);
}

ll uin(ll &x, ll y) {
  return x = min(x, y);
}

void kill() {
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < 5; ++j)
      d[i][j] = inf;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 5; ++j) {
      for (int nx = j; nx < 5; ++nx) {
        uin(d[i + 1][nx], d[i][j] + cost(a[i], nx));
      }
    }
  }

  ll ans = inf;
  for (int j = 0; j < 5; ++j)
    ans = min(ans, d[n][j]);
  cout << ans << "\n";
}

int main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  read();
  kill();
}



Measured memory_bytes: 8832
/*
ID: alec3
LANG: C++14
PROG: pprime
CLASSIFICATION: brute force
*/

#include <bits/stdc++.h>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long ll;
typedef unsigned long long ull;

using namespace std;

bool isPrime(int n){
    bool prime = true;
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;

    for (int i = 3; i < sqrt(n) + 1; i+= 2){
        if (n % i == 0){
            prime = false;
            break;
        }
    }
    return prime;
}

int main() {

	//ifstream fin("pprime.in");
	//ofstream fout("pprime.out");
    io;
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& it : a) cin >> it;

    int ans = 0;
    for (int i = 0; i < a.size(); i++){
        if ((i + 1) % 2 != 0 && a[i] % 2 != 0) ans ++;
    }
    cout << ans << endl;



    return 0;

}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int n,a[100010];
int b[100010],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]++;
		b[a[i]-1]++;
		b[a[i]]++;
		b[a[i]+1]++;
	}
	for (int i=0;i<100005;i++)
	{
		ans=max(ans,b[i]);
	}
	cout<<ans<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 1272
import collections
from collections import deque

def Dfs(now):
    flag = True
    d = deque()
    d.append(now)
    visited[now]=0
    while len(d):
        now = d.pop()
        for i,j in vec[now]:
            if visited[i]==INF:
                d.append(i)
                visited[i]=visited[now]+j
            else:
                if visited[i]==visited[now]+j:
                    continue
                else:
                    flag=False
                    break
    return flag


n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
vec= [[] for i in range(n)]

for i in range(m):
    vec[a[i][0]-1].append((a[i][1]-1,a[i][2]))
    vec[a[i][1]-1].append((a[i][0]-1,-a[i][2]))

INF=float('inf')
visited=[INF]*n

for i in range(n):
    if visited[i]==INF:
        if not Dfs(i):
            print('No')
            exit()
print('Yes')

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

int main() {
  
  std::vector<std::string> keys; 
  std::vector<int> scores;
  
  string str; // dummy 
  
  int N;
  cin >> N;
  for(int i = 0; i < N; i++)
  {
   	cin >> str; 
    std::vector<string>::iterator iter = std::find(keys.begin(), keys.end(), str);
    if( iter == keys.end() )
    {
      keys.push_back(str);
      scores.push_back(1);
    }
    else
    {
      scores.at(iter - keys.begin()) += 1;
    }     
  }
  
  int M;
  cin >> M;
  for(int i = 0; i < M; i++)
  {
    cin >> str; 
    std::vector<string>::iterator iter = std::find(keys.begin(), keys.end(), str);
    if( iter == keys.end() )
    {
      keys.push_back(str);
      scores.push_back(-1);
    }
    else
    {
      scores.at(iter - keys.begin()) -= 1;
    }     
  }

  int maxval = 0;              
  for(int i = 0; i < scores.size(); i++)
  {
    maxval = max(maxval, scores.at(i));
  }

  cout << maxval << endl;              
}


Measured memory_bytes: 256
n, k = map(int, input().split())
k = min(k, n - 1)
p = 10 ** 9 + 7
size = n + 100
f_list = [1] * size
if_list = [1] * size
for i in range(1, size):
    f_list[i] = (f_list[i - 1] * i) % p
    if_list[i] = pow(f_list[i], p-2, p)

def cmb(n, r):
    return f_list[n] * if_list[r] * if_list[n-r] % p

# 初期値は0人の部屋が0個の場合
ans = 1
for i in range(1, k + 1):
    ans += cmb(n, i) * cmb(n - 1, i)
    ans = ans % p
print(ans)

Measured memory_bytes: 18764
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int X;
int A[100];
int main(){
  int i, res, x, y;
  rd(N);
  rd(M);
  rd(X);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<M;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  x = y = 0;
  for(i=0;i<M;i++){
    if(A[i]<X){
      x++;
    }
    else{
      y++;
    }
  }
  res =min_L(x, y);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, M, X, A[100];
// {
//   int i, x, y, res;
//   rd(N,M,X,A(M));
//   x = y = 0;
//   rep(i,M) if[A[i]<X, x, y]++;
//   res = min(x,y);
//   wt(res);
// }


Measured memory_bytes: 256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <iostream>
using namespace std;
long long int a, b, ans, mod = 1e9 + 7;
long long int kaijo(long long int x) {
	long long int yojo = 1;
	for (int i = 1; i <= x; i++) {
		yojo *= i;
		yojo %= mod;
	}
	return yojo;
}
int main()
{
	cin >> a >> b;
	if (abs(a - b) > 1) {
		cout << 0 << endl;
	}
	else if (a == b) {
		ans = 2 * kaijo(a) % mod*kaijo(b) % mod;
		cout << ans << endl;
	}
	else {
		ans = kaijo(max(a, b)) % mod*kaijo(min(a, b)) % mod;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
x = list(map(int, input().split()))
x.sort()
x=x[::-1]
if x[0]%2==x[1]%2==x[2]%2:print((x[0]*2-x[1]-x[2])//2)
elif x[0]%2!=x[1]%2==x[2]%2:print((x[0]*2-x[1]-x[2]-1)//2+1)
else:print((x[0]*2-x[1]-x[2]-1)//2+2)

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

namespace ABC099
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>();
            while (true)
            {
                string line = Console.ReadLine();
                if (line == null) break;
                list.Add(line);
            }
            var str = list[0].ToCharArray();
            int count =str.Where(x => x == 'C').Count();
            int ucount=0;
            foreach (var item in str)
	        {
		        if (char.IsUpper(item))
	            {
		            ucount++;
	            }
	        }

            if (!str[0].Equals('A'))
            {
                Console.WriteLine("WA");
            }
            else if(str.Last().Equals('C'))
            {
                Console.WriteLine("WA");
            }
            else if (str[1].Equals('C'))
            {
                Console.WriteLine("WA");
            }
            else if (str.First().Equals('A') && str.Contains('C') && count==1 && ucount==2)
            {
                Console.WriteLine("AC");
            }
            else 
            {
                Console.WriteLine("WA");
            }
  

        }
    }
}


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

long long n;
vector<long long> a;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  sort(a.begin(), a.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long id = n - 2, x = n - 2, res = a[n - 1];
  while (x) {
    res += a[id] * min(2LL, x);
    x -= min(2LL, x);
    --id;
  }
  return res;
}

Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)1e9+7)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)1e5+5)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //test
  {
    int n;
    cin>>n;
    
    set<string> st;
    while(n--){
      string str;
      cin>>str;
      st.insert(str);
    }
    cout<<st.size();
  }
  return 0;
}

Measured memory_bytes: 19212
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
unsigned long long MOD = 1e9 + 7;
ll INF = 1e18;
long long modMult(long long a, long long b, long long m)
{
    long long res = 0;
    long long exp = a % m;
    while (b)
    {
        if (b & 1)
        {
            res += exp;
            if (res > m)
                res -= m;
        }
        exp <<= 1;
        if (exp > m)
            exp -= m;
        b >>= 1;
    }
    return res;
}
long long powMod(long long a, long long b, long long m)
{
    long long res = 1;
    long long exp = a % m;
    while (b)
    {
        if (b & 1)
            res = modMult(res, exp, m);
        exp = modMult(exp, exp, m);
        b >>= 1;
    }
    return res;
}
//powMod(a,b,MOD)
//O(log(b))?
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> vec(n);
  //  vector<ll> reg(30000,0);
    rep(i, n) cin >> vec[i];
    ll g=1;
    ll res=0;
    rep(i,61){
        ll h=0;
        rep(j,n){
            if((vec[j]&g)==g){
                h++;
            }
        }
        res+=(((h)*(n-h))%MOD)*(g%MOD)%MOD;
        g*=2;
    }
    cout<<res%MOD<<endl;
}


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

void insert_sort(int A[],int n,int g,int *cnt){
    for(int j=g;j<n;j++){
        int k=A[j];
        int i=j-g;
        while(i>=0&&A[i]>k){
            A[i+g]=A[i];
            i-=g;
            (*cnt)++;
        }
        A[i+g]=k;
    }
}

void shell_sort(int A[],int n){
    int cnt=0;
    int m=100;
    int G[m];
    int h=1;
    while(h<=(n-2)/3)h=3*h+1;
    G[0]=h;
    for(int i=1;i<m;i++){
        G[i]=G[i-1]/3;
        if(G[i]<1){
            m=i;
            break;
        }
    }
    for(int j=0;j<m;j++){
        insert_sort(A,n,G[j],&cnt);
    }
    cout<<m<<endl;
    for(int i=0;i<m;i++){
        if(i==0)cout<<G[i];
        else cout<<' '<<G[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
}

int main(){
    int n,A[1000000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    shell_sort(A,n);
    for(int i=0;i<n;i++){
        cout<<A[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 7024
N, M, X, Y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

XR = max(xs)
YL = min(ys)

for i in range(X+1, Y+1):
  if XR < i and i <= YL:
    print("No War")
    exit()

print("War")

Measured memory_bytes: 9124
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
using namespace std;
typedef long long int LL;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

bool used[5500];
LL val[5500];
int P[5500];

LL check(vector<LL> v1,int m){
    int n=v1.size();
    int i,j;
    LL a,b;
    LL s=0;
    for(i=0;i<n;i++){
        v1.push_back(v1[i]);
        s+=v1[i];
    }
    for(i=0;i<n;i++){
        v1.push_back(v1[i]);
    }
    a=m/n;
    if(a)a--;
    s*=a;
    m-=a*n;
    s=max(s,(LL)0);
    b=-1e9;
    for(i=0;i<n;i++){
        a=0;
        for(j=0;j<m;j++){
            a+=v1[i+j];
            b=max(b,a);
        }
    }
    return s+b;
}

int main(){
    int n,m;
    int i,j,k;
    LL a,b,c;
    LL s=-1e9;
    vector<LL> v1;
    cin>>n>>m;
    for(i=0;i<n;i++){
        cin>>P[i];
        P[i]--;
    }
    for(i=0;i<n;i++){
        cin>>val[i];
    }
    for(i=0;i<n;i++){
        if(used[i])continue;
        v1.clear();
        v1.push_back(val[i]);
        used[i]=true;
        a=P[i];
        while(a!=i){
            v1.push_back(val[a]);
            used[a]=true;
            a=P[a];
        }
        s=max(s,check(v1,m));
    }
    cout<<s<<endl;
}

Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll t1, t2, a1, a2, b1, b2;
ll sum_a, sum_b;

int main(){

    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    sum_a = t1 * a1 + t2 * a2;
    sum_b = t1 * b1 + t2 * b2;

    if(a1 == b1 || sum_a == sum_b){
        cout << "infinity" << endl;
        return 0;
    }
    if(sum_a < sum_b){
        swap(sum_a, sum_b);
        swap(a1, b1);
        swap(a2, b2);
    }

    if(a1 > b1){
        cout << 0 << endl;
        return 0;
    }

    ll D = sum_a - sum_b;
    ll d = b1 * t1 - a1 * t1;

    ll ans = 1;

    ans += d / D * 2;
    if(d % D == 0)ans--;
    cout << ans << endl;


    return 0;
}

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

int main(){
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin>>vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i < N-1; i++) {
    if(vec.at(i)==vec.at(i+1)){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

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

int main() {
  int R, D, X;
  cin >> R >> D >> X;

  int A = X;
  for (int i = 0; i < 10; i++) {
    int ans = A * R - D;
    cout << ans << endl;
    A = ans;
  }
}

Measured memory_bytes: 256
alphabet = [0]*26
i = 0;
for j in range(97,123):
    alphabet[i] = chr(j)
    i += 1
al_count = [0]*26
while True :
    try :
        words = raw_input().lower().split()
        for k in words :
            for l in list(k):
                if l=='a':
                    al_count[0] += 1
                elif l=='b':
                    al_count[1] += 1
                elif l=='c':
                    al_count[2]+=1  
                elif l=='d':
                    al_count[3] += 1
                elif l=='e':
                    al_count[4]+=1
                elif l=='f':
                    al_count[5] += 1
                elif l=='g':
                    al_count[6]+=1
                elif l=='h':
                    al_count[7] += 1
                elif l=='i':
                    al_count[8]+=1
                elif l=='j':
                    al_count[9] += 1
                elif l=='k':
                    al_count[10]+=1 
                elif l=='l':
                    al_count[11] += 1
                elif l=='m':
                    al_count[12]+=1 
                elif l=='n':
                    al_count[13] += 1
                elif l=='o':
                    al_count[14]+=1
                elif l=='p':
                    al_count[15] += 1
                elif l=='q':
                    al_count[16]+=1
                elif l=='r':
                    al_count[17] += 1
                elif l=='s':
                    al_count[18]+=1
                elif l=='t':
                    al_count[19] += 1
                elif l=='u':
                    al_count[20]+=1
                elif l=='v':
                    al_count[21]+=1
                elif l=='w':
                    al_count[22] += 1
                elif l=='x':
                    al_count[23]+=1
                elif l=='y':
                    al_count[24] += 1
                elif l=='z':
                    al_count[25]+=1
    except :
        break
for i in range(26):
    print '%c : %d' %(alphabet[i],al_count[i])


Measured memory_bytes: 4704
#include "bits/stdc++.h"
using namespace std;
const int maxn = 1024 * 1024;
char s[maxn];
int main(){
	int n;
	scanf("%d %s", &n, s);
	int q;
	scanf("%d", &q);
	for(int e = 0; e < q; e++){
		int x;
		scanf("%d", &x);
		long long ans = 0;
		long long qd = 0, qm = 0, q2 = 0;
		for(int f = 0; f < n; f++){
			if(f >= x){
				if(s[f-x] == 'M'){
					qm--;
				} else if(s[f-x] == 'D'){
					q2 -= qm;
					qd--;
				}
			}
			if(s[f] == 'D'){
				qd++;
			} else if(s[f] == 'M') {
				q2 += qd;
				qm++;
			} else if(s[f] == 'C') {
				ans += q2;
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


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

int findSumOfDigits(int n)
{
    int sum = 0;
    while (n > 0)
    {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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

    int x;
    x = findSumOfDigits(N);
    cout << (x == 1 ? 10 : x) << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int a[21][21], dp[21][1 << 21 + 1];
const int MOD = 1e9 + 7;

long long int solve(int w, int mask_m){
    if( __builtin_popcount(mask_m) != w + 1)
        return 0;
    if(w < 0 && mask_m == 0)
        return 1;
    if(w < 0)
        return 0;

    if(dp[w][mask_m] != -1)
        return dp[w][mask_m];

    dp[w][mask_m] = 0;
    for(int i = 0; i < n; i++){
        if((mask_m & (1 << i)) && a[w][i]){
            dp[w][mask_m] += solve(w - 1, mask_m ^ (1<<i));
            dp[w][mask_m] %= MOD;
        }
    }
    return dp[w][mask_m];
}
int main(){
    //freopen("test.in", "r+", stdin);
    memset(dp, -1, sizeof dp);

    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];

    cout<<solve(n - 1, (1 << n) - 1)<<endl;
}


Measured memory_bytes: 688512
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	char b;
	cin >> b;
	if(b=='A') cout << 'T';
	else if(b=='T') cout << 'A';
	else if(b=='C') cout << 'G';
	else cout << 'C';
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
// Sort I - Stable Sort
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_C
using System;
using System.Linq;

namespace ALDS1_2_C {
    enum Suit {
        S = 'S',
        H = 'H',
        C = 'C',
        D = 'D',
    }

    class Card {
        public Suit suit{ get; private set; }
        public int val{ get; private set; }
        public Card(String str){
            var c = str.ToCharArray();
            suit = (Suit)c[0];
            val = int.Parse(c[1].ToString());
        }
        public override string ToString() {
            return this.suit.ToString() + this.val.ToString();
        }
        public Card Clone(){
            return (Card)MemberwiseClone();
        }
    }

	class Program {
		public Program() {}
		
		public static void Main() {
			new Program().Calc();
		}
		
		void Calc() {
			var N = int.Parse(Input);	// Number of elements
			var CA = Input				// CardArray : N elements
					.Split(' ')
					.Select(i => new Card(i))
					.ToArray();

			var bS = bubbleSort(CA, N);
            Output("Stable");

            var sS = selectionSort(CA, N);

            // Stable Check
            for(int i = 0; i < N; i++) {
                if(bS[i].suit != sS[i].suit) {
                    Output("Not stable");
                    return;
                }
            }
            Output("Stable");
		}
		
		String Input {
			get {
				return Console.ReadLine();
			}
		}
		
		void Output(String str) {
			Console.WriteLine(str);
		}

        Card[] bubbleSort(Card[] A, int N) {
            //int swapCount = 0;
            var CA = A.Select(i => i.Clone())
					.ToArray();
            Card tmp;
            for(int i = 0; i < N -1; i++){
                for(int j = N - 1; j > i; j--){
                    if(CA[j-1].val <= CA[j].val) continue;
                    tmp = CA[j-1];
                    CA[j-1] = CA[j];
                    CA[j] = tmp;
                    //swapCount++;
                }
            }
            Output(CA.Select(i => i.ToString())
						.Aggregate((i, j) => i + " " + j));
            //Output(swapCount.ToString());
            return CA;
        }

        Card[] selectionSort(Card[] A, int N) {
            //int swapCount = 0;
            var CA = A.Select(i => i.Clone())
					.ToArray();
            int minIndex;
            Card tmp;
            for(int i = 0; i < N - 1; i++){
                minIndex = i;
                for(int j = i + 1; j < N; j++){
                    if(CA[j].val < CA[minIndex].val)
                        minIndex = j;
                }
                if(i == minIndex) continue;
                //swapCount++;
                tmp = CA[i];
                CA[i] = CA[minIndex];
                CA[minIndex] = tmp;
            }
            Output(CA.Select(i => i.ToString())
						.Aggregate((i, j) => i + " " + j));
            //Output(swapCount.ToString());
            return CA;
        }
	}
}

Measured memory_bytes: 9964
import collections
import math
N,P=map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
c=collections.Counter(prime_factorize(P))
w=1
for i in c.keys():
  if c[i]>=N:
    k=math.floor(c[i]/N)
    w=w*(i**k)
  else:
    w=w
print(w)

Measured memory_bytes: 3316
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

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

    println!("{}", min(n*a,b));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

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

int main(){
    ll n;cin>>n;
    ll sosuu[25]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
    ll a;
    ll count[25]={};
    for(ll i=1;i<=n;i++){
        a=i;
        for(ll j=0;j<25;j++){
            while(a%sosuu[j]==0){
                a=a/sosuu[j];
                count[j]++;
            }
        }
    }
    ll c3=0,c5=0,c15=0,c25=0,c75=0;
    for(ll i=0;i<25;i++){
        if(count[i]>=2){
            c3++;
        }
        if(count[i]>=4){
            c5++;
        }
        if(count[i]>=14){
            c15++;
        }
        if(count[i]>=24){
            c25++;
        }
        if(count[i]>=74){
            c75++;
        }
    }
    ll ans;
    ans=c75+c25*(c3-1)+c15*(c5-1)+(c5*(c5-1)*(c3-2))/2;
    cout<<ans<<endl;
    return 0;
}



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

int n, m;

int main() {
    cin >> n;
    m=n;
    for (int i=2; i*i<=n; i++) {
        if (n%i == 0) m=(m/i)*(i-1);
        for (;n%i == 0;) n=n/i;
    }
    if (n!=1) m=(m/n)*(n-1);
    cout << m << endl;
}


Measured memory_bytes: 3124
using System;
using System.Text;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int c;
            while((c = int.Parse(Console.ReadLine())) != 0) {
                string value = Console.ReadLine();
                var temp = new StringBuilder(100);
                while(--c >= 0){
                    char last = value[value.Length - 1];
                    int count = 1;
                    for(int l = value.Length - 2; l >= 0; --l) {
                        if(last != value[l]) {
                            temp.Insert(0, last.ToString());
                            temp.Insert(0, count.ToString());
                            count = 1;
                            last = value[l];
                        }
                        else {
                            ++count;
                        }
                    }
                    temp.Insert(0, last.ToString());
                    temp.Insert(0, count.ToString());
                    value = temp.ToString();
                    temp.Length = 0;
                }
                Console.WriteLine(value);
            }
        }
    }
}

Measured memory_bytes: 6284
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef int i;
int main()
{
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
 string s,t;
 cin>>s;
 cin>>t;
 lli x=0,i;
 for(i=0;i<s.size();i++)
 {
     if(s[i]!=t[i])
      x++;
 }
 cout<<x<<"\n";
}

Measured memory_bytes: 3780
s = input()
l =[]
for i in range(len(s)):
    if s[i] == "0":
        l.append("0")
    elif s[i] == "1":
        l.append("1")
    elif s[i] =="B":
        if len(l) == 0:
           pass
        else:
           del l[-1]
print("".join(l))
        

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

def solve(N: int, X: "List[int]", Y: "List[int]", H: "List[int]"):
    def calc_h(cx, cy):
        h = None
        for xx, yy, hh in filter(lambda xyh: xyh[2]>0, zip(X, Y, H)):
            th = hh + abs(cx - xx) + abs(cy - yy)
            if h is not None and th != h:
                return None
            h = th
        h = h if h else 1
        for xx, yy, _ in filter(lambda xyh: xyh[2]==0, zip(X, Y, H)):
            if abs(cx - xx) + abs(cy - yy) < h:
                return None
        return h

    for cx in range(101):
        for cy in range(101):
            h = calc_h(cx, cy)
            if h is not None:
                return cx, cy, h


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    h = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        h[i] = int(next(tokens))
    print(*solve(N, x, y, h))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3064
#!/usr/bin/env python3
def main():
    def expected_val(limit):
        return (1 + limit) / 2

    N, K = map(int, input().split())
    P = [int(x) for x in input().split()]

    lst = [0]
    res = 0
    for p in P:
        res += p + 1
        lst.append(res)
    ans = 0
    for i in range(N - K + 1):
        res = lst[i + K] - lst[i]
        ans = res if res > ans else ans
    print(ans / 2)


if __name__ == '__main__':
    main()


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

const int maxn=6,maxc=50+5;
int n,c,l[maxn],dp[maxn*maxc][maxn*maxc][1<<maxn],rnk[maxn],lim;
long long res;
double ans;

inline int chk(int a,int b){
	if(b>lim)return lim;
	return a>=b?a:b;
}

int main(){
	cin>>n>>c;
	for(int i=0;i<n;++i)
		cin>>l[i];
	sort(l,l+n,greater<int>());
	for(int i=1;i<n;++i)
		rnk[i]=i;
	lim=n*c;
	do{
		memset(dp,0,sizeof(dp));
		dp[0][l[0]*n][0]=1;
		for(int i=0;i<n*c;++i)
			for(int j=i;j<=n*c;++j)
				for(int k=0;k<(1<<n-1);++k){
					dp[i+1][j][k]+=dp[i][j][k];
					if(i%n&&(k>>rnk[i%n]-1&1)==0)
						dp[i+1][chk(j,i+n*l[rnk[i%n]])][k|1<<rnk[i%n]-1]+=dp[i][j][k];
				}
		res+=dp[n*c][n*c][(1<<n-1)-1];
	}
	while(next_permutation(rnk+1,rnk+n));
	ans=res;
	for(int i=1;i<n;++i)
		ans/=i*c;
	printf("%.14f\n",ans);
	return 0;
}

Measured memory_bytes: 27520
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            List<Values> list = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                list.add(new Values(in.next(), in.nextInt(), i + 1));
            }

            Collections.sort(list);
            for (Values val : list) {
                out.println(val.idx);
            }
        }

        class Values implements Comparable<Values> {
            String S;
            int P;
            int idx;

            Values(String S, int P, int idx) {
                this.S = S;
                this.P = P;
                this.idx = idx;
            }

            public int compareTo(Values o) {
                int cmp = S.compareTo(o.S);
                if (cmp != 0) {
                    return cmp;
                }
                return Integer.compare(o.P, P);
            }

        }

    }
}



Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    string s;
    cin>>s;
    int i=0;
    bool mdfy=false;
    int before=s.size();
    do{
        mdfy=false;
        while(s.size()>=2&&i<=(s.size()-1)-1){
        if(s.at(i)!=s.at(i+1)){
            s=s.erase(i,2);
            mdfy=true;
            if(i!=0)i--;
        }
        else{
            i++;
            }
        }
   }while(mdfy);
   int after=s.size();
   cout<<before-after<<endl;
    return 0;
}




Measured memory_bytes: 512
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

from functools import lru_cache

@lru_cache(maxsize=INF)
def ggcd(a, b):
    return math.gcd(a, b)

K = I()

h = [0] * 201
for a in range(1, K+1):
    for b in range(1, K+1):
        h[ggcd(min(a,b), max(a,b))] += 1

ans = 0
for c in range(1, K+1):
    for i, ab in enumerate(h):
        if ab != 0:
            ans += ggcd(min(c,i), max(c,i)) * ab

print(ans)


Measured memory_bytes: 76880
n = gets.to_i
array = gets.split.map(&:to_i)
hash = {}
array.each do |e|
  if hash[e]
    hash[e] += 1
  else
    hash[e] = 1
  end
end

(1..n).each do |i|
  if hash[i]
    puts hash[i]
  else
    puts 0
  end
end


Measured memory_bytes: 39780
#include <iostream>
#include <stdio.h>

#define MAX_N 100'000

using namespace std;

int P[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int p;
    cin >> p;
    P[i] = p - 1;
  }
  int i = 0;
  int res = 0;
  while (i < N) {
    int cnt = 0;
    while (i < N && i == P[i]) {
      ++i;
      ++cnt;
    }
    res += (cnt + 1) / 2;
    while (i < N && i != P[i]) {
      ++i;
    }
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

int main() {
    LL a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k % 2 == 0) cout << a - b << endl;
    else cout << b - a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <time.h>
#include <algorithm>
#include <iostream>
using namespace std;
#define repi(a,b) for (int i=a;i<=b;i++)
#define repj(a,b) for (int j=a;j<=b;j++)
#define repk(a,b) for (int k=a;k<=b;k++)
#define oo 123456789
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define endl '\n'
#define MLV 30
#define N 100005

int n,sum;
int a[N];
int a4,a2,a1;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n;
	repi(1,n) {
		cin>>a[i];
		if (a[i]%4==0) {
			a4++;
			continue;
		}
		if (a[i]%2==0){
			a2++;
			continue;
		}
		a1++;
	}
	
	//cout<<a1<<a2<<a4<<endl;
	
	if (a2==0 && a4==a1-1) {cout<<"Yes"<<endl;return 0;}
	else {
		if (a4>=a1) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string.h>
#include <numeric>

using namespace std;

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    ll n;cin>>n;
    Vi v;
    ll aaa;
    ll ans=0;
    rep(i,n){
        cin>>aaa;
        ans += aaa;
    }
    cout<<ans-n<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m, h, w;
int s[200][200];

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin >> n;
    vi v(n);
    REP(i, n) cin >> v[i];
    vi t = v;
    sort(ALL(t));
    REP(i, n) {
        cout << (t[n / 2 - 1] < v[i] ? t[n / 2 - 1] : t[n / 2]) << endl;
    }

    return 0;
}


Measured memory_bytes: 3840