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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W)), B(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> A.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> B.at(i).at(j);
        }
    }

    vector<vector<int>> d(H, vector<int>(W));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            d.at(i).at(j) = abs(A.at(i).at(j) - B.at(i).at(j));
        }
    }

    auto to_id = [&](int i, int j) {
        return i * W + j;
    };
    vector<vector<bool>> dp(H * W, vector<bool>(80 * 160 + 1));
    dp.at(to_id(0, 0)).at(d.at(0).at(0)) = true;
    for (int i = 1; i < H; i++)
    {
        for (int k = 0; k < 80 * 160 + 1; k++)
        {
            if (dp.at(to_id(i - 1, 0)).at(k))
            {
                dp.at(to_id(i, 0)).at(abs(k + d.at(i).at(0))) = true;
                dp.at(to_id(i, 0)).at(abs(k - d.at(i).at(0))) = true;
            }
        }
    }
    for (int j = 1; j < W; j++)
    {
        for (int k = 0; k < 80 * 160 + 1; k++)
        {
            if (dp.at(to_id(0, j - 1)).at(k))
            {
                dp.at(to_id(0, j)).at(abs(k + d.at(0).at(j))) = true;
                dp.at(to_id(0, j)).at(abs(k - d.at(0).at(j))) = true;
            }
        }
    }
    for (int i = 1; i < H; i++)
    {
        for (int j = 1; j < W; j++)
        {
            for (int k = 0; k < 80 * 160 + 1; k++)
            {
                if (dp.at(to_id(i - 1, j)).at(k))
                {
                    dp.at(to_id(i, j)).at(abs(k + d.at(i).at(j))) = true;
                    dp.at(to_id(i, j)).at(abs(k - d.at(i).at(j))) = true;
                }
                if (dp.at(to_id(i, j - 1)).at(k))
                {
                    dp.at(to_id(i, j)).at(abs(k + d.at(i).at(j))) = true;
                    dp.at(to_id(i, j)).at(abs(k - d.at(i).at(j))) = true;
                }
            }
        }
    }
    for (int k = 0; k < 80 * 160 + 1; k++)
    {
        if (dp.at(to_id(H - 1, W - 1)).at(k))
        {
            cout << k << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 13816
#include <cstdio>
#include <vector>
#include <limits>

using namespace std;

namespace {
// workspace for Merge.
size_t L[250001] = {0};
size_t R[250001] = {0};

static size_t Merge(size_t* A, size_t left, size_t mid, size_t right) {
  const size_t n1 = mid - left;
  const size_t n2 = right - mid;

  // When sorting large arrays, allocating L and R in heap for
  // each Merge call makes a bit the program slower.
  //
  // In the real application, we should use std::vectors instead of
  // fixed sized arrays, though.
  // vector<size_t> L(n1+1);
  // vector<size_t> R(n2+1);

  for (size_t i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (size_t i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }

  static const size_t kInf = numeric_limits<size_t>::max();
  L[n1] = kInf;
  R[n2] = kInf;

  size_t i = 0;
  size_t j = 0;
  for (size_t k = left; k < right; ++k) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
  }
  return right - left;
}

static size_t MergeSortInternal(size_t* A, size_t left, size_t right) {
  if (left + 1 >= right) return 0;

  const size_t mid = (left + right) / 2;
  size_t ret = MergeSortInternal(A, left, mid);
  ret += MergeSortInternal(A, mid, right);
  return ret + Merge(A, left, mid, right);
}

static size_t MergeSort(size_t* A, size_t n) {
  return MergeSortInternal(A, 0, n);
}
} // namespace

int main() {
  size_t n;
  size_t S[500000];
  scanf("%lu", &n);
  for (size_t i = 0; i < n; ++i) {
    scanf("%lu", &S[i]);
  }

  const size_t swapped = MergeSort(S, n);
  for (size_t i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%lu", S[i]);
  }
  printf("\n");
  printf("%lu\n", swapped);

  return 0;
}

Measured memory_bytes: 8848
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	static int n=s.nextInt();
	public static void main(String[] $){
		System.out.println(f(0,0,0));
	}
	static int f(long v,int f,int d){
		return v>n?0:f/7+f(v*10+7,f|1,d+1)+f(v*10+5,f|2,d+1)+f(v*10+3,f|4,d+1);
	}
}


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

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,x,t;
    cin >> n >> x >> t;
    int ans = 0;
    while(n > 0) {
        ans+=t;
        n-=x;
        debug(n);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define fork(a,b) for(int k=a;k<b;k++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define seto(x,i) memset(x,i,sizeof x)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pf first
#define ps second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int a,b;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("", "r", stdin);
    cin>>a>>b;
    cout<<max(0,a-2*b);
    return 0;
}


Measured memory_bytes: 256
//2008dC
I;int parse(char *p){switch(*p){
	case'F':return 0;
	case 'T':return 1;
	case '-':return !parse(p+1);
	case '(':{
		int x=0;
		char *q=++p;
		for(;;p++){
			if(*p=='(')x++;
			if(*p==')')x--;
			if(x==0&&*p!='-')break;
		}
		switch(*(++p)){
			case '*':return parse(q)&parse(p+1);
			case '+':return parse(q)|parse(p+1);
			case '-':return !parse(q)|parse(p+2);
		}
	}
}return (I>>(*p-97))&1;}
char p[1001],*q;main(){for(;scanf("%s",p),*p-'#';puts(I==2048?"YES":"NO")){
for(q=strchr(p,'=')+1,I=0;I<2048;I++)if(parse(p)!=parse(q))break;
}exit(0);}

Measured memory_bytes: 552
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        Dictionary<string, int> dic = new Dictionary<string, int>();
        dic.Add("AC", 0);
        dic.Add("WA", 0);
        dic.Add("TLE", 0);
        dic.Add("RE", 0);
        for(int i = 0; i < N; i++)
        {
            var r = Console.ReadLine();
            dic[r]++;
        }
        foreach(var i in dic)
        {
            Console.WriteLine($"{i.Key} x {i.Value}");

        }

    }
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll h, w;
    cin >> h >> w;
    ll a[h][w];
    rep(i, h) {
        rep(j, w) { cin >> a[i][j]; }
    }
    vector<pair<pair<ll, ll>, pair<ll, ll>>> ans;

    rep(i, h) {
        rep(j, w - 1) {
            if (a[i][j] % 2 == 0) {
                continue;
            }
            a[i][j + 1]++;
            pair<ll, ll> before, after;
            before = make_pair(i, j);
            after = make_pair(i, j + 1);
            ans.push_back(make_pair(before, after));
        }
    }

    rep(i, h - 1) {
        if (a[i][w - 1] % 2 == 0) {
            continue;
        }
        a[i + 1][w - 1]++;
        pair<ll, ll> before, after;
        before = make_pair(i, w - 1);
        after = make_pair(i + 1, w - 1);
        ans.push_back(make_pair(before, after));
    }

    cout << ans.size() << endl;
    for (auto p : ans) {
        cout << p.first.first + 1 << " " << p.first.second + 1 << " "
             << p.second.first + 1 << " " << p.second.second + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 9420
# encoding: "utf-8"

from collections import defaultdict
from functools import reduce
from itertools import groupby, chain

class Stdin:
    @staticmethod
    def read_line(converter=str):
        return [converter(x) for x in input().split()]
    
    @staticmethod
    def read_lines(n, converter=str):
        result = list()
        for _ in range(n):
            result.append(Stdin.read_line(converter))
        return result
    
    @staticmethod
    def convert(data, converter):
        assert(len(data) == len(converter))
        return tuple(map(lambda x, f: f(x), data, converter))

    @staticmethod
    def convert_lines(datas, n, converter):
        return [converter(data, n, converter) for data in datas]

def main():
    _ = input()
    xs = Stdin.read_line(converter=int)
    ys = chain.from_iterable([[x-1, x, x+1] for x in xs])
    ys = sorted(list(ys))
    cnt = 0
    m = 0
    prev = ys[0]
    for y in ys:
        if y == prev:
            cnt += 1
        else:
            if m < cnt:
                m = cnt
            prev = y
            cnt = 1
    print(m)

if __name__ == "__main__":
    main()

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

void Main() {
    // input
    int N;
    cin >> N;

    // translate
    switch (N % 10){
    case 2: 
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    case 3:
        cout << "bon" << endl;
        break;
    default:
        break;
    }

    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	string S=in<string>();
	int N=S.size();
	int K=in();

	// dp[i][j][k]: 上からi桁目までを取り出した時、すでに0ではない数がk個ある場合の数
	vector<vector<vector<ll>>> dp(N+1,vector<vector<ll>>(2,vector<ll>(K+1,0)));
	dp[0][0][0]=1;
	REP(i,N){
		ll digit = S[i]-'0';
		for(int smaller=0;smaller<2;smaller++){
			for(int j=0;j<K+1;j++){
				for(int x=0;x<=(smaller?9:digit);x++){
					if(x==0){
						dp[i+1][smaller || x<digit][j]+=dp[i][smaller][j];
					}
					else{
						if(j+1<=K) dp[i+1][smaller || x<digit][x>0?j+1:j]+=dp[i][smaller][j];
						//else dp[i+1][smaller || x<digit][K]+=dp[i][smaller][j];
					}
				}
			}
		}
	}

	out(dp[N][0][K]+dp[N][1][K]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define int __int128
template<class T>inline void read(T& x) {
	T f=1;x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+(s&15);s=getchar();}
	x*=f;
}
inline void print(int x) {
    if(x>=10) { print(x/10); }
    putchar(x%10+'0');
}
inline int gcd(int a,int b) { return a%b==0?b:gcd(b,a%b); }
inline int lcm(int a,int b) { return (a*b)/gcd(a,b); }
int a,b,ans;
signed main() {
	read(a); read(b);
	while(a) {
		a/=b;
		ans++;
	}
	print(ans);
}

Measured memory_bytes: 256
#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,k;
    cin>>n>>k;
    ll aaaaa;
    vi v;
    rep(i,n){
        cin>>aaaaa;
        v.pb(aaaaa);
    }
    ll ans=0;
    n -= k;
    ans++;
    ans += n/(k-1) ;
    if(n%(k-1)!=0){
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n!=-1) 
	{
		double x=0,y=0,rad=0,pi=3.14159265;
		for(int i = 0; i < n; ++i)
		{
			x+=cos(rad); y+=sin(rad);
			rad=atan2(y,x)+pi/2;
		}
		cout<<x<<endl;
		cout<<y<<endl;
	}
  return 0;
}

Measured memory_bytes: 1304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  while(cin>>h>>w,h+w!=0){
    for(int i=0;i<w;++i) cout<<'#';
    cout<<endl;
    for(int i=1;i<h-1;++i){
      cout<<'#';
      for(int j=1;j<w-1;++j) cout<<'.';
      cout<<'#'<<endl;
    }
    for(int i=0;i<w;++i) cout<<'#';
    cout<<endl<<endl;
  }
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int count=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]==t[i])
        {
            count++;
        }
    }
    cout<<count;
    return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
sum_a = sum(a)

rets = []
flg = False
for i in range(m):
  if a[i] < sum_a / (4 * m):
    pass
  else:
    rets.append(a[i])
    if len(rets) == m:
      flg = True
      break
  
if flg:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
import sys
def divisor(a,b): #nの約数を全て求める
  if a>b:
  	a,b = b,a
  i = 2
  table = []
  table2 = []
  table3 = []
  
  while i * i <= min(a**2,b):
    if a%i==0:
      table2.append(a//i)
      if b%i==0:
        table.append(i)
        table3.append(b//i)
    else:
      if b%i==0:
        table3.append(b//i)
    i += 1
    
  table2.append(a)
  table3.append(b)
  #print(table)
  #print(table2)
  #print(table3)
  s_inter = set(table) | (set(table2) & set(table3))
  table = list(s_inter)
  return table

 
a,b = map(int, input().split())
if a==1 and b==1:
  print(1)
  sys.exit(0)
if a>b:
  a,b = b,a

ret = divisor(a,b)
#print(ret)
if 2 in ret:
  ret = [2] + [t1 for t1 in ret if t1%2!=0]
elif 3 in ret:
  ret = [3] + [t1 for t1 in ret if t1%3!=0]
elif 5 in ret:
  ret = [5] + [t1 for t1 in ret if t1%5!=0]
elif 7 in ret:
  ret = [7] + [t1 for t1 in ret if t1%7!=0]
elif 11 in ret:
  ret = [11] + [t1 for t1 in ret if t1%11!=0]
elif 13 in ret:
  ret = [13] + [t1 for t1 in ret if t1%13!=0]

ret = [t1 for t1 in ret if sum([t1%t2==0 for t2 in ret])==1]
#print(ret)
print(1+len(ret))


Measured memory_bytes: 4076
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] X = new int[M];
		for (int i = 0; i < M; i++) {
			X[i] = sc.nextInt();
		}
		Arrays.sort(X);
		if (N >= M) {
			System.out.println(0);
			return;
		}
		int[] s = new int[M-1];
		for (int i = 0; i < M-1; i++) {
			s[i] = X[i+1] - X[i];
			
		}
		Arrays.sort(s);
		int ans = 0;
		for (int i = 0; i < M-N; i++) {
			ans += s[i];
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23260
# coding: utf-8
# Your code here!
import sys

N = int(input())

B = list(map(int,input().split()))

# print(B)
ans = []

while B:
    # print(ans)
    flag = True
    for i in reversed(range(len(B))):
        # print(i)
        if B[i] == i+1:
            flag = False
            ans.append(B[i])
            B.pop(i)
            break
            
    if flag:
        print(-1)
        sys.exit()
        
for a in reversed(ans):
    print(a)

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

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end());
    int ans = 0;
    int mae = 0;
    rep(i, n) {
        if (mae != a[i]) {
            ans++;
            mae = a[i];
        }
        else {
            ans--;
            mae = 0;
        }
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, K;
    cin >> N >> K;
    ll A[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    int length[N];
    for(int i = 0; i < N; i++) length[i] = -1;
    length[0] = 0;
    ll target = A[0], heiro = 0;
    while(true) {
        heiro++;
        if(length[target] != -1) {
            heiro -= length[target];
            break;
        }
        length[target] = heiro;

        target = A[target];
    }
    if(K <= length[target]) {
        target = 0;
        for(int i = 0; i < K; i++) target = A[target];
        cout << target + 1;
        return 0;
    }
    ll amari = (K - length[target]) % heiro;

    for(int i = 0; i < amari; i++) target = A[target];
    cout << target + 1;
    return 0;
}


Measured memory_bytes: 5980
#include<iostream>
using namespace std;
int main()
{
	int k,s;
	cin>>k>>s;
	long long sum=0;
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if(s-i-j<=k&&s-i-j>=0)
				sum++;
		}
	}
	cout<<sum;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v;
    for (int i = 0; i < H; i++){
        string str;
        cin >> str;
        v.push_back(str);
    }
    vector<string> answer(H);
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            int tmp = 0;
            if (v.at(i).at(j) == '.'){
                if (i > 0 && v.at(i - 1).at(j) == '#') tmp++;
                if (i < H - 1 && v.at(i + 1).at(j) == '#') tmp++;
                if (j > 0 && v.at(i).at(j - 1) == '#') tmp++;
                if (j < W - 1 && v.at(i).at(j + 1) == '#') tmp++;
                if (i > 0 && j > 0 && v.at(i - 1).at(j - 1) == '#') tmp++;
                if (i > 0 && j < W - 1 && v.at(i - 1).at(j + 1) == '#') tmp++;
                if (i < H - 1 && j > 0 && v.at(i + 1).at(j - 1) == '#') tmp++;
                if (i < H - 1 && j < W - 1 && v.at(i + 1).at(j + 1) == '#') tmp++;
                answer.at(i).push_back(char(tmp + '0'));
            }
            else{
                answer.at(i).push_back('#');
            }
        }
    }
    for (int i = 0; i < H; i++){
        cout << answer.at(i) << endl;
}
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define REPR(i,n) for(int i = n; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    int A, B, C, N,K, ans;
    cin >> N >> K;
    if(K == 1) p(0);
     else p(N - K);
}

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

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

const int INF  = 1000001;

int main() {
    int n; cin>>n;
    
    vector<int> to[100];
    rep(i,n){
        int a,m;
        cin>>a>>m;
        --a;
        
        rep(j,m){
            int b;cin>>b;
            --b;
            to[a].push_back(b);
//            to[b].push_back(a);
//          cout<<a<<" "<<b<<endl;
        }
    }

    queue<int> q;
    vector<int> dist(n, INF);
    dist[0]=0;
    q.push(0);

    while(!q.empty()){
        int v = q.front(); q.pop();
      for(int u : to[v]){
        if (dist[u] != INF) continue;
            dist[u] = dist[v] + 1;
            q.push(u);
//          cout<<u<<" "<<dist[u]<<endl;
        }
    }
  
    rep(i,n){
        int res1 = i+1;
        int res2 = dist[i];
        if(i == 0)res2 = 0;
        if(res2 == INF) res2 = -1;
        cout<<res1<<" "<<res2<<endl;
    }
    
	return 0;
}


Measured memory_bytes: 3156
import bisect
from collections import deque

n = int(input())
A = []
dq_A = deque(A)
count = 0
for _ in range(n):
    a = int(input())
    if len(dq_A) == 0:
        dq_A.appendleft(a)
        count += 1
        continue
    i = bisect.bisect_left(dq_A, a)
    if i == 0:
        dq_A.appendleft(a)
        count += 1
    else:
        dq_A[i-1] = a

ans = count
print(ans)

Measured memory_bytes: 7364
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

int main() {
	char a;
	cin >> a;

	if(isupper(a))cout << 'A' << endl;
	else cout << 'a' << endl;
}

Measured memory_bytes: 10960
#include <bits/stdc++.h>
using namespace std;
#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++)
uint64_t h,w;

void solve(){
    if(h==1||w==1) {
        cout<<1<<endl;
    }else{
        cout<<(h*w+1)/2<<endl;
    }
}

int main(){
    cin>>h>>w;

    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    string s;cin >> s;
    string t = s;
    reverse(all(t));
    int count = 0;
    rep(i, (s.size()+1)/2) {
        if(s[i]!=t[i]) count++;
    }
    cout << count <<  endl;
    return 0;
}

Measured memory_bytes: 3616
/*
    文字列検索
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/14/ALDS1_14_A
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string src, dst;
    cin >> src;
    cin >> dst;

    if (src.length() < dst.length())
        return 0;

    for (size_t i = 0; i < src.length() - dst.length() + 1; i++) {
        bool is_found = true;
        for (size_t j = i, k = 0; j < i + dst.length(); j++, k++) {

            if (src.at(j) != dst.at(k)) {
                is_found = false;
                break;
            }
        }
        if (is_found)
            cout << i << endl;
    }
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define MAX_V 100000

struct edge { int to, cost; };

int V;//頂点数
vector<edge> G[MAX_V];//辺の張り方 : G[from].push_back((edge){to, cost});
int dist[MAX_V];
bool used[MAX_V];
bool no;

void DFS(int v, int d){
    if(used[v] == true){
        if(d != dist[v]){
            no = true;
        }
        return;
    }
    dist[v] = d;
    used[v] = true;
    REP(i,G[v].size()){
        DFS(G[v][i].to, d + G[v][i].cost);
    }
    return;
}

signed main(){
    int m;
    cin >> V >> m;
    int l,r,d;
    REP(i,m){
        cin >> l >> r >> d;
        l--;
        r--;
        G[l].push_back(edge{r, d});
        G[r].push_back(edge{l, -d});
    }
    REP(i,V){
        if(!used[i]){
            DFS(i, 0);
            if(no){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 12032
#include <stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  for(int c=0; c<26; c++){
    for(int d=0; d<16; d++){
      if( (4*c + 7*d) == n ){ printf("Yes\n"); return 0; }
    }  
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,D,A;
    cin >> N >> D >> A;
    int imos[N+1];
    rep(i,N+1) imos[i]=0;
    vc<pi> v;
    rep(i,N){
        int a,b; cin >> a >> b;
        v.eb(a,b);
    }
    sort(all(v));
    vi dis(N);
    rep(i,N){
        dis[i]=v[i].fi;
    }
    int damage=0;
    int ans=0;
    rep(i,N){
        damage-=imos[i];
        int time=(v[i].se-damage+A-1)/A;
        chmax(time,(int)0);
        ans+=time;
        damage+=time*A;
        int pos=upper_bound(all(dis),v[i].fi+2*D)-dis.begin();
        imos[pos]+=time*A;
    }
    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, k; cin >> n >> k;
  ll ans = 0;
  vll x(n); rep(i, n) cin >> x[i];
  rep(i, n)
  {
    ll a = 2 * x[i], b = abs(k - x[i]) * 2;
    ans += min(a, b);
  }
  fin(ans)
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main(){
  int ans = 0,x = 0;
  string S;
  cin >> S;
  rep(i,S.size()){
    if(S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T'){
      ans++;
    }
    else{
      x = max(x,ans);
      ans = 0;
    }
  }
  x = max(x,ans);
  cout << x;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main(){
  set<string>st;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    st.emplace(s);
  } 
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 19108
from collections import defaultdict
MOD = 998244353

n = int(input())
d = list(map(int, input().split()))

cnt = defaultdict(int)
m = 0
for i in range(n):
    cnt[d[i]] += 1
    m = max(d[i], m)

if d[0] != 0 or cnt[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, m + 1):
        ans *= cnt[i - 1]**cnt[i]
        ans %= MOD

print(ans)


Measured memory_bytes: 19936
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail =(tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1)% LEN;
  return x;
}

int min(int a, int b){return a < b ? a : b;}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for (i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0)enqueue(u);
    else{
      printf("%s %d\n", u.name, elaps);
    }
  }
  
  return 0;
}



Measured memory_bytes: 11852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, x; cin >> n >> x;
  int mi = 1<<30, an = 0;
  for(int i = 0; i < n; i++){
    int v; cin >> v;
    x -= v;
    mi = min(mi, v);
  }
  cout << n + x / mi << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	m := getNextInt(scanner)
	counter := make([]int, n)

	for i := 0; i < m; i++ {
		a := getNextInt(scanner) - 1
		b := getNextInt(scanner) - 1
		counter[a]++
		counter[b]++
	}

	ans := "YES"
	for i := 0; i < n; i++ {
		if counter[i]%2 == 1 {
			ans = "NO"
			break
		}
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 3072
#include<iostream>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	
	string str;
	cin >> str;

	int ans[2] = { 0 };
	for( char c : str )
	{
		ans[c - '0']++;
	}

	cout << min( ans[0], ans[1] ) * 2  << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(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 (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;cin >> n;
    vector<int> a(n),b(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    vector<vector<int>> dp(1<<n,vector<int>(51,inf));
    dp[0][0]=0;
    REP(t,1<<n){
        int cnt=0;
        REP(i,n) if(t&(1<<i)) cnt++;
        REP(i,n){
            if(t&(1<<i)) continue;
            int in=0;
            REP(j,i){
                if(!(t&(1<<j))) in++;
            }
            REP(j,51){
                if(abs(i-cnt)%2==0){
                    if(j<=a[i]){
                        chmin(dp[t|(1<<i)][a[i]],dp[t][j]+in);
                    }
                }
                else{
                    if(j<=b[i]){
                        chmin(dp[t|(1<<i)][b[i]],dp[t][j]+in);
                    }
                }
            }
        }
    }
    int ans=inf;
    REP(i,51) chmin(ans,dp[(1<<n)-1][i]);
    cout << (ans==inf?-1:ans) << endl;
}

Measured memory_bytes: 66816
program answer
      implicit none
      character(len=1),dimension(100) :: S
      integer :: eof
      integer :: i
      intrinsic mod
      eof = 0
      read(*,'(100A)') (S(i),i=1,100)
      do i=1,100
        if( mod(i,2) == 1) then
          if( S(i) == 'L') then
            eof = 1
            exit
          end if
        else if( mod(i,2) == 0) then
          if( S(i) == 'R') then
            eof = 1
            exit
          end if
        end if
      end do
      if( eof == 0) write(*,'(A)') 'Yes'
      if( eof == 1) write(*,'(A)') 'No'
      stop
      end program answer

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

ll xor_a_bs(ll a, ll bit, const vector<ll>& residual_bs) {
	ll count = 0;
	ll residual_a = a % (1LL << (bit + 1LL));
	
	count += distance(lower_bound(residual_bs.begin(), residual_bs.end(), (1LL << bit) - residual_a), residual_bs.end());
	count -= distance(lower_bound(residual_bs.begin(), residual_bs.end(), (1LL << bit) * 2LL - residual_a), residual_bs.end());
	count += distance(lower_bound(residual_bs.begin(), residual_bs.end(), (1LL << bit) * 3LL - residual_a), residual_bs.end());
	count -= distance(lower_bound(residual_bs.begin(), residual_bs.end(), (1LL << bit) * 4LL - residual_a), residual_bs.end());

	return count % 2LL;
}

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

	vector<ll> as(n);
	vector<ll> bs(n);
	for (ll i = 0; i < n; ++i) cin >> as[i];
	for (ll i = 0; i < n; ++i) cin >> bs[i];

	ll res = 0;
	vector<ll> residual_bs(n);
	for (ll i = 0; i < 30; ++i) {
		for (ll j = 0; j < n; ++j) {
			residual_bs[j] = bs[j] % (1LL << (i + 1LL));
		}
		sort(residual_bs.begin(), residual_bs.end());
		for (ll j = 0; j < n; ++j) {
			res ^= (xor_a_bs(as[j], i, residual_bs) << i);
		}
	}

	cout << res << endl;

	return 0;
}

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

	solve();

	return 0;
}


Measured memory_bytes: 4992
N = int(input())
P = list(map(int, input().split()))
Q=list(map(int, input().split()))
l = [i for i in range(N)]

fac = [0] * 8
fac[1] = 1
for i in range(2, N):
    fac[i] = i * fac[i - 1]

a = 0
l = list(range(1, N + 1))
for i in range(N):
    a += l.index(P[i]) * fac[len(l) - 1]
    l.remove(P[i])

b = 0
l = list(range(1, N + 1))
for i in range(N):
    b += l.index(Q[i]) * fac[len(l) - 1]
    l.remove(Q[i])

print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll N;cin>>N;
	ll ans = 1LL;
	for(ll t = 1; t<=N; ++t){
		ans *= t;
		ans %= MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c,k=map(int,input().split())
sum=0
while k!=0:
	if a!=0:
		if a>=k:
			sum+=k
			break
		else:
			sum+=a
			k-=a
			a=0
	elif b!=0:
		if b>=k:
			break
		else:
			
			k-=b
			b=0
	elif c!=0:
		if c>=k:
			sum-=k
			break
		else:
			sum-=c
			k-=c
print(sum)

Measured memory_bytes: 9072
#![allow(non_snake_case)]

use std::io;

fn main() {
    let sin = io::stdin();

    loop {
        let mut buf = String::new();
        sin.read_line(&mut buf).ok();
        let mut ws = buf.split_whitespace();
        let a = ws.next().unwrap().parse::<i32>().unwrap();
        let op: &str = ws.next().unwrap();
        let b = ws.next().unwrap().parse::<i32>().unwrap();

        let res = match op {
            "+" => a + b,
            "-" => a - b,
            "*" => a * b,
            "/" => a / b,
            "?" => break,
            _ => break,
        };
        println!("{}", res);
    }
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
#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++)

int main() {
  int display = 1;
  
  int N, K;
  cin >> N >> K;
  
  rep(i, N) {
    if (display < K) {
      display *= 2;
    }
    else {
      display += K;
    }
  }
 
  cout << display << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
// #define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

signed main() {

	int n, m;
	cin >> n >> m;
	int arr[n];
	int sm = 0;
	for (int i=0; i<n; i++) {
		cin >> arr[i];
		arr[i] *= (4 * m);
		sm += arr[i];
	}
	
	int at_least = sm / 4 / m;
	
	sort(arr, arr+n);
	reverse(arr, arr+n);
	
	for (int i=0; i<m; i++) {
		if (arr[i] >= at_least) continue;
		cout << "No" << endl;
		exit(0);
	}
	
	cout << "Yes" << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define RANGE(a, l, r) lower_bound(a, a + N, r) - lower_bound(a, a + N, l)
using namespace std;
typedef int ll;

ll N, A[200000], B[200000];
ll pow2[31], l1[29], r1[29], l2[29], r2[29];
ll moda[29][200000], modb[29][200000];

int main(void) {
  scanf("%d", &N);
  REP(i, 0, N) scanf("%d", &A[i]);
  REP(i, 0, N) scanf("%d", &B[i]);

  REP(i, 0, 31) pow2[i] = (1 << i);
  REP(i, 0, 29) {
    l1[i] = pow2[i];
    r1[i] = pow2[i + 1];
    l2[i] = pow2[i + 1] + pow2[i];
    r2[i] = pow2[i + 2];
  }
  REP(i, 0, 29) REP(j, 0, N) moda[i][j] = A[j] & (pow2[i + 1] - 1);
  REP(i, 0, 29) {
    REP(j, 0, N) modb[i][j] = B[j] & (pow2[i + 1] - 1);
    sort(modb[i], modb[i] + N);
  }

  ll ans = 0;
  REP(k, 0, 29) {
    REP(i, 0, N) {
      ll cnt = 0;
      cnt += RANGE(modb[k], l1[k] - moda[k][i], r1[k] - moda[k][i]);
      cnt += RANGE(modb[k], l2[k] - moda[k][i], r2[k] - moda[k][i]);
      if(cnt & 1) ans = ans ^ pow2[k];
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 47104