akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scs(s) scanf("%s",s)
#ifndef GET_MACRO

#define GET_MACRO(__1,__2,__3,NAME,...) NAME

#endif // GET_MACRO

#define sci(...) GET_MACRO(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define ll long long
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
#define LSB(i) ((i)&(-i))
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define infl  0x7ffffffffffffff
#define infi  0x7fffffff
#define fill_(a,b) fill(a.begin(),a.end(),b)
#define pb push_back
#define xx first
#define yy second

int main(){
    ll data[7];
    int i;
    ll ans=0;
    for(i=0;i<7;i++)cin>>data[i];
    ans+=data[1];
    if(data[0]%2){
        ans+=data[0]-1;
        if((data[3]%2||data[4]%2)&&data[3]>0&&data[4]>0){
            ans+=3;
            data[3]--;
            data[4]--;
        }
    }
    else{
        if(data[3]%2&&data[4]%2&&data[0]>0){
            ans+=data[0]-2;
            ans+=3;
            data[3]--;
            data[4]--;
        }
        else{
            ans+=data[0];
        }
    }
    ans+=(data[3]/2)*2;
    ans+=(data[4]/2)*2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int a,b,c;
int x;
void compare()
{
    if(a==b)
    {
        x=c;
    }

    else
        if(a==c)
        {
           x=b;
        }
        else
           x=a;
}
int main()
{
    scanf("%d %d %d",&a,&b,&c);
    compare();
    printf("%d\n",x);
    return 0;
}

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

int cur = 0, A, B, n, dif;
vector<int> ans;

void gray(deque<int> pos, deque<int> care) {
    int sz = pos.size();
    if(sz == 0) return;
    
    int fr = pos.front();
    pos.pop_front();
    gray(pos, care);

    gray(care, deque<int>());
    cur ^= (1 << fr);
    ans.push_back(cur ^ A);

    gray(pos, care);
}

void mono(deque<int> ones, deque<int> care) {
    if(ones.size() == 0) return;
    if(ones.size() == 1) {
        care.push_front(ones.front());
        gray(care, deque<int>());
        return;
    }
    int fr = ones.front();
    ones.pop_front();
    gray(ones, care);

    int se = ones.front();

    gray(care, deque<int>());
    cur ^= (1 << fr);
    ans.push_back(cur ^ A);
    care.push_back(se);
    ones.pop_front();
    mono(ones, care);
}

void solve() {
    deque<int> cg, ncg;
    for(int i = 0; i < n; ++i) {
        if(dif >> i & 1) cg.push_back(i);
        else ncg.push_back(i);
    }
    mono(cg, ncg);
}

bool vis[1<<18];
int last ;

int main() {
    cin >> n >> A >> B;
    dif = A ^ B;
    if(__builtin_popcount(dif) & 1) {
        puts("YES");
        ans.push_back(cur ^ A);
        solve();
        for(auto g : ans) printf("%d ", g);
    } else puts("NO");

    return 0;
}

Measured memory_bytes: 1652
N = int(input())
arr = sorted([input() for _ in range(N)])

dict ={}
for i in arr:
    if i not in dict:
        dict[i] = 1
    else:
        dict[i] += 1

max_n = max(dict.values())

ans =[]
for i in dict:
    if dict[i] == max_n:
        ans.append(i)

ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 99100
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    for (int i = 1; i < 10; i++)
    {
        if (N % i == 0 && N / i <= 9)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())

i = 0
while n - 7 * i > 0:
     x = n - 7 * i
     if x % 4 ==0:
         print("Yes")
         break
     i += 1
else:
    if n % 7 ==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	int dp[3100][3100];
	



	void solve(){

		
		ini(n,n1);
		FOR(i,0,3100)FOR(i1,0,3100)dp[i][i1] = inf;
		FOR(i,0,3100)dp[i][i] = 0;
		FOR(i,0,n1){
			ini(tmpx,tmpx1,tmpp);
			dp[tmpx][tmpx1] = tmpp;
		}
		FOR(i,0,n){
			FOR(i1,0,n){
				FOR(i2,0,n){
					if(dp[i1][i] == inf or dp[i][i2] == inf)continue;
					dp[i1][i2] = min(dp[i1][i2],dp[i1][i]+dp[i][i2]);
					//out(i1,i2,dp[i1][i2]);
				}
			}
		}
		FOR(i,0,n)if(dp[i][i]<0)	return out("NEGATIVE CYCLE");
		FOR(i,0,n){
			FOR(i1,0,n){
				if(dp[i][i1] == inf)cout<<"INF";
				else cout<<dp[i][i1];
				if(i1!=n-1)cout<<" ";
			}
			out();
		}		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



Measured memory_bytes: 78304
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  b--;
  REP(i, n) {
    ll c, d;
    cin >> c >> d;
    d--;
    if (a <= c && c <= b) {
      return !printf("%lld\n", 1);
    } else if (a <= d && d <= b) {
      return !printf("%lld\n", 1);
    } else if (a >= c && d >= b) {
      return !printf("%lld\n", 1);
    }
  }
  cout << 0 << endl;
}



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

int main(){
  char q,w,e,r,t,y,u,i;
  cin>>q>>w>>e>>r>>t>>y;
  int count=0;
  if(q==r){
    count++;
  }
  if(w==t){
    count++;
  }
  if(e==y){
  count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n,m;
int a[10];
int b[]={2,5,5,4,5,6,3,7,6};
int c[10];
int dp[19][114514];
signed main(){
	cin>>n>>m;
	rep(i,m){
		cin>>a[i];
	}
	sort(a,a+m);
	rep(i,m){
		c[i]=b[a[i]-1];
	}
	rep(i,m+1){
		rep(j,n+1){
			dp[i][j]=-1;
		}
	}
	dp[0][0]=0;
	rep(i,m){
		rep(j,n+1){
			if(dp[i][j]==-1)continue;
			rep(k,5001){
				dp[i+1][j+(c[i]*k)]=max(dp[i+1][j+(c[i]*k)],dp[i][j]+k);
			}
		}
	}
	int x=n;
	for(int i=m-1;i>=0;i--){
		int cnt=0;
		for(int j=0;j<=5000;j++){
			if(x<j*c[i])break;
			if(dp[i][x-(j*c[i])]==-1)continue;
			if(dp[i][x-(j*c[i])]+j==dp[i+1][x])cnt=j;
		}
		x-=cnt*c[i];
		for(int j=0;j<cnt;j++)cout<<a[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 8832
#include <stdio.h>
#include <stdlib.h>
#define P (1000000007) //10^9+7
#define N (200010)

long mfac(long,long);		// a! mod p
long mpow(long,long,long);	// a^b mod p
long mcom(long,long,long);	// aCb mod p

long fact[N]={1};
long invfact[N]={1};

int main(){
	long n,k;
	long count=0;
	scanf("%ld %ld",&n,&k);
	k = k<n?k:n;
	for(int i=1;i<=n;i++){
		fact[i] = fact[i-1]*i%P;
		invfact[i] = mpow(fact[i],P-2,P);
	}
	for(int i=0;i<=k;i++){
		count += mcom(n,i,P)*mcom(n-1,i,P)%P;
		count %= P;
	}
	printf("%ld",count);
	return 0;
}

long mfac(long a,long p){
	if(a==0) return 1;
	return a*mfac(a-1,p)%p;
}

long mpow(long a,long b,long p){
	long n=1;
	while(b){
		if(b&1) n = n*a%p;
		b = b>>1;
		a = a*a%p;
	}
	return n;
}

long mcom(long a,long b,long p){
	long n = 1;
	n = n*fact[a]%p;
	n = n*invfact[a-b]%p;
	n = n*invfact[b]%p;
	return n;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=n1;i<(int)(n2);i++)
using namespace std;

signed main()
{
  string S;
  cin >> S;
  int N = S.size();
  int R = 1;
  int L = 0;
  int Rind = 0;
  int Lind = 0;
  vector<int> C(N, 0);
  For(i, 1, N){
	if(S[i-1] == 'L' && S[i] == 'R'){
      C[Rind] = R/2 + L/2 + R%2;
      C[Lind] = R/2 + L/2 + L%2;

      //initialization
      R = 1;
      L = 0;
      Rind = 0;
      Lind = 0;
    }else if(S[i-1] == 'R' && S[i] == 'R'){
      R += 1;
    }else if(S[i-1] == 'R' && S[i] == 'L'){
      L += 1;
      Rind = i-1;
      Lind = i;
    }else if(S[i-1] == 'L' && S[i] == 'L'){
      L += 1;
    }
  }

  C[Rind] = R/2 + L/2 + R%2;
  C[Lind] = R/2 + L/2 + L%2;

  Rep(i, C.size()) cout << C[i] << " ";
  return 0;
}


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

int d[100010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", d+i);
	sort(d, d+n);
	printf("%d\n", d[n/2] - d[n/2-1]);
}


Measured memory_bytes: 640
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	string s,t,ans="";
	cin>>s>>t;
	REP(i,0,n-1) {
		ans+=s[i],ans+=+t[i];
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3620
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxn 200005
#define maxm 1000006
#define maxc 1000000007
#define pii pair <int,int>
#define Task ""
#define double long double
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
const double Pi = acos(-1);
using namespace std;
int n,t[55][55];
pii a[maxn];
long long ans;
int Get(int u,int v)
{
    if (!u || !v) return 0;
    int res = 0;
    while (u)
    {
        int temp = v;
        while (temp)
        {
            res += t[u][temp];
            temp -= temp & -temp;
        }
        u -= u & -u;
    }
    return res;
}
void Update(int u,int v,int val)
{
    while (u <= 50)
    {
        int temp = v;
        while (temp <= 50)
        {
            t[u][temp] += val;
            temp += temp & -temp;
        }
        u += u & -u;
    }
}
int main()
{
    srand(time(NULL));
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie();
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    cin >> n;
    FOR(i,1,n)
    {
        double x;cin >> x;
        long long u = round(x * 1e9);
        while (u % 2 == 0)
        {
            ++a[i].F;
            u >>= 1;
        }
        while (u % 5 == 0)
        {
            ++a[i].S;
            u /= 5;
        }
    }
    FOR(i,1,n)
    {
        int need2 = max(1,18 - a[i].F + 1),
            need5 = max(1,18 - a[i].S + 1);
        ans += Get(50,50);
        ans -= Get(need2 - 1,50);
        ans -= Get(50,need5 - 1);
        ans += Get(need2 - 1,need5 - 1);
        Update(a[i].F + 1,a[i].S + 1, 1);
    }
    cout << ans;
    return 0;
}


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

int main(void) {
	string s;
	cin >> s;
	if(s.length()==2){
		cout << s << endl;
	}else {
		cout << s[2] << s[1] << s[0] << endl;
	}
	return 0;
}

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

int main() {
  int N, i, key;
  int cnt = 0, flag = 0;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
  cin >> N;
  vector<int> vec(N);
  vector<int> vec_2(N);
  for (i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  for (int j = 0; j < pow(10, 9); j++) {
    for (i = 0; i < N; i++) {
      key = vec.at(i) % 2;
      if (key == 0) {
        vec_2.at(i) = vec.at(i) / 2;
        vec.at(i) = vec_2.at(i);
      } else
        flag++;
    }
    if (flag > 0) 
      break;
    cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


//--https://kenkoooo.com/atcoder/#/table/soma62jp


#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[])
{

	char a,b;

	cin >> a >> b;

	if(a=='H'){
		if(b=='H'){
			cout << "H" << endl;
		}else{
			cout << "D" << endl;
		}
	}else{
		if(b=='H'){
			cout << "D" << endl;
		}else{
			cout << "H" << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int n, a[1000], i, b, s, m;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    
    b=a[0];
    s=a[0];
    for(i=1;i<n;i++){
        if(b<a[i]) b=a[i];
        else if(s>a[i]) s=a[i];
    }
    m=b-s;
    printf("%d\n",m);
    return 0;
}

Measured memory_bytes: 128
S=input()
N=len(S)
prezero=0
preone=0
for i in range(N):
    s=S[i]
    if s=="0":
        if preone>0:
            preone-=1
        else:
            prezero+=1
    if s=="1":
        if prezero>0:
            prezero-=1
        else:
            preone+=1
print(N-prezero-preone)


Measured memory_bytes: 39664
n = int(input())

lb, ub = 0, n
print(lb, flush=True)
s = str(input())
if s == 'Vacant':
    exit()
for i in range(19):
    mid = (lb + ub) // 2
    print(mid, flush=True)
    t = str(input())
    if t == 'Vacant':
        exit()
    if (mid - lb) % 2 == 0 and s == t:
        lb = mid
    elif (mid - lb) % 2 == 0 and s != t:
        ub = mid
    elif s == t:
        ub = mid
    else:
        lb, s = mid, t


Measured memory_bytes: 3660
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static int sumatory(String a, String b){
        List<Character> lista = new ArrayList<>();
        for (int i = 0; i < a.length(); i++){
            for (int j = 0; j < b.length(); j++){
                if (lista.contains(a.charAt(i))) continue;
                if (a.charAt(i) == b.charAt(j)){
                    lista.add(a.charAt(i));
                    break;
                }
            }
        }
        return lista.size();
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        String str = in.next();
        int start = 0, end = n;
        int max = 0;
        for (int i = 0; i < n; i++){
            String str1 = str.substring(start, i);
            String str2 = str.substring(i, end);
            max = Math.max(max, sumatory(str1, str2));
        }
        System.out.println(max);
    }

}

Measured memory_bytes: 24148
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    #t=int(input())
    t=1
    for _ in range(t):

        n=int(input())
        #x,k,d=inar()
        arr=inar()
        arr.sort()
        ans=0
        for i in range(n):
            for j in range(i+1,n):
                for k in range(j+1,n):
                    if (arr[i]+arr[j])>arr[k] and arr[i]!=arr[j]!=arr[k]:
                        ans+=1

        print(ans)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()


Measured memory_bytes: 74884
import collections
n = int(input())

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
a = prime_factorize(n)
#print(a)
c = collections.Counter(a)
#print(c)
ans = 0
for v in c.values():
    x = 1
    while True:
        v -=x
        x += 1
        if (v<x):
            ans += (x-1)
            break
print(ans)
            

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

int main() {
  string s; cin >> s;
  int N = s.size();
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (s.at(i) == 'p') cnt++;
  }
  cout << N / 2 - cnt << endl;
}

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

using namespace std;

using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;


pair<long long,long long> dp[110][110*1100];
//long long dpv[110][110*11000];
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);

	int n = 0;
	int w = 0;
	cin >> n >> w;
	vector<pll> data(n);
	long long vs = 0;
	for(int i = 0;i < n;++i){
		cin >> data[i].first >> data[i].second;
		vs+=data[i].second;
	}
	for(int i = 0;i < 110; ++i){
		for(int j = 0; j < 110*1100; ++j){
			dp[i][j].first = 1e18;
		}
	}
/*	for(int i = 0;i < 110; ++i){
		dp[i][0].first = 0;
	}*/
	dp[0][0].first = 0;
/*	for(int i = 0;i < 110 * 1100; ++i){
		dp[0][i].first = 0;
	}*/

	//dp[0][0].first = 0;

	for(int i = 0;i <= vs;++i){
		for(int j = 0;j < n; ++j){
			if(dp[j][i].first /*+ data[j].first*/ < w){
				dp[j + 1][i + data[j].second].first = min(dp[j + 1][i + data[j].second].first,dp[j][i].first + data[j].first);
				dp[j+1][i].first = min(dp[j+1][i].first,dp[j][i].first);
			}
		}
	}
	for(int i = vs; i >=0; --i){
			if(dp[n][i].first <= w)
			{
				cout << i;
				return 0;
			}
	}

	return 0;
}

Measured memory_bytes: 208256
// 5/14
// 過去問ガリガリ
#include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    vector<int> P(N);
    rep(i, N) cin >> P[i];

    int minv = 1000000009;
    int ans = 0;

    rep(i, N) {
        if (P[i] <= minv) {
            ans++;
            minv = P[i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef long long llint;
typedef pair < int, int> pii;
typedef pair < llint, llint> pll;
 
const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
 
int n,a[N],nep,ind;
llint sum = 0;
 
int main(){
    scanf("%d",&n);
    for(int i = 0;i<n;i++){
        scanf("%d",a+i);
        if(a[i]&1) {nep++;ind=i;}
        sum += (llint)a[i];
    }
    for(int koji = 1;;koji = !koji){
        int allgcd = a[0];
        for(int i = 1;i<n;i++)
            allgcd = __gcd(a[i], allgcd);
        int nw = 0,ind = 0, jed = 0;
        llint nsum = -n;
        for(int i = 0;i<n;i++){
            a[i] /= allgcd;
            nsum += a[i];
            if(a[i] == 1) jed++;
            if(a[i]&1) {nw++;ind = i;}
        }
        if(nsum%2 == 1){
            if(koji) printf("First\n");
            else printf("Second");
            break;
        }
        else if(nw == 1 && !jed){
            a[ind]--;
            continue;
        }
        else{
            if(!koji) printf("First\n");
            else printf("Second");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;

int main(){
    int64_t H;
    cin >> H;
    int64_t n=1;
    int64_t sum=0;
    while(H>0){
        sum += n;
        H /= 2;
        n *= 2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = [int(x) for x in input().split()]
B = sorted(A)
ans = 0
for i in range(N-1):
    ans = (B[0] + B[1]) / 2
    B.pop(0)
    B.pop(0)
    bisect.insort_left(B, ans)
print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int n,cnt = 0;
    string a,b,c;
    cin >> n >> a >> b >> c;
    
    for(int i = 0;i < n;i++){
        if(a[i] == b[i] && b[i] == c[i]) cnt+=0;
        else if(a[i] == b[i]) cnt++;
        else if(b[i] == c[i]) cnt++;
        else if(c[i] == a[i]) cnt++;
        else cnt+=2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#define llint long long
#define inf 1e18

using namespace std;

llint k;
double r, l;
double p, e, t;
double L, R;

double calc(double l, double r, llint k)
{
	if(r < L || R < l) return 0;
	if(L <= l && r <= R) return 1;
	
	double h = (l+r)/2;
	if(k == 0){
		if(L <= h && h <= R) return 1;
		else return 0;
	}
	
	if(h <= t) return (1-p)*calc(h, r, k-1) + p*calc(l, h, k-1);
	else return p*calc(h, r, k-1) + (1-p)*calc(l, h, k-1);
	
}

int main(void)
{
	cin >> k >> l >> r;
	cin >> p >> e >> t;
	L = t - e, R = t + e;
	
	printf("%.11f\n", calc(l, r, k));
	
	return 0;
}


Measured memory_bytes: 3296
from collections import Counter

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

if len(set(v)) != 1:
    a = Counter(v[0::2]).most_common()
    b = Counter(v[1::2]).most_common()
    if a[0][0] != b[0][0]:
        print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[0][1]))
    else:
        if a[0][1] < b[0][1]:
            print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
        elif a[0][1] > b[0][1]:
            print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
        elif a[0][1] == b[0][1]:
            if len(a) != 1 and len(b) != 1:
                if a[1][1] > b[1][1]:
                    print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
                elif a[1][1] < b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
                elif a[1][1] == b[1][1]:
                    print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
            elif len(a) != 1:
                print((len(v[0::2]) - a[1][1]) + (len(v[1::2]) - b[0][1]))
            elif len(b) != 1:
                print((len(v[0::2]) - a[0][1]) + (len(v[1::2]) - b[1][1]))
else:
    print(len(v[1::2]))


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

	cout << min(b/a, c) << endl;

	return 0;

}


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

int main(){
  string st;
  int c = 1;
  string as = "Yes";
  cin >> st;
  sort(st.begin(),st.end());
  if (st.size()==1){as="No";}
  for (int i=1; i < st.size(); i++){
    if (st.at(i)==st.at(i-1)){
      c++;
    }
    else{
      if (c%2==1){
        as="No";
      }
      c=1;
    }
  }
  cout << as << endl;
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String line = bufferedReader.readLine();
        int K = Integer.parseInt(line);
        String S = bufferedReader.readLine();
        if (S.length() > K) {
            System.out.println(S.substring(0, K) + "...");
        } else {
            System.out.println(S);
        }
    }
}


Measured memory_bytes: 36160
import heapq
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

rrn = lambda n: [ rr() for _ in xrange(n)]

N = rri()
arr = rrm()
arr = sorted(arr)
def solve(N, arr):
    pq = []
    cur1 = arr.pop()
    ans = cur1
    cur2 = arr.pop()
    heapq.heappush(pq, (-cur2, (cur2, cur1)))
    heapq.heappush(pq, (-cur2,(cur1, cur2)))
    while arr:
        neg_max, (start, end) = heapq.heappop(pq)
        ans-=neg_max
        cur = arr.pop()
        heapq.heappush(pq, (-cur, (start, cur)))
        heapq.heappush(pq, (-cur, (cur, end)))
    return ans
print(solve(N, arr))

Measured memory_bytes: 128720
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   string s;
   cin >> s;
   int n = (int)s.size();
   cout << string(n , 'x') << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
typedef long long int ll;

int N, M;
int a, b;
int num[50 + 1];

int main(void){
	for(int i = 1; i <= 50; i++){
		num[i] = 0;
	}
	cin >> N >> M;
	for(int i = 1; i <= M; i++){
		cin >> a >> b;
		num[a]++; num[b]++;
	}
	for(int i = 1; i <= N; i++){
		cout << num[i] << endl;
	}
	return 0;
}


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

typedef long long LL;

const int N = 1e5;
const LL MOD = 1e9+7;

int n,k;
int li[N+5];
LL dp[105][N+5];

int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&li[i]);
	for(int i=0;i<=k;i++) dp[n+1][i] = 1;
	for(int i=n;i>=1;i--){
		for(int j=0;j<=k;j++){
			dp[i][j] = dp[i+1][j];
			if(j-li[i] > 0) dp[i][j]-=dp[i+1][j-li[i]-1];
			dp[i][j] =(dp[i][j]+MOD)%MOD;
//			cout << "DP " << i << " , " << j << " = " << dp[i][j] << endl;
		}
		if(i==1) printf("%lld\n",dp[1][k]);
		for(int j=1;j<=k;j++) dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
	}
//	printf("%lld\n",dp[1][n]);
	return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#pragma GCC optimize("O999")
//示例：#define ll long long
//unsigned long long ;
const int INF=0x3f3f3f3f;
const int maxn=50000005;
using namespace std;

int main(){
	//freopen(".in", "r",stdin );
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	int n, m, t=0;
	cin >> n >> m;
	int a[n+1];
	double sum=0;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		sum+=a[i];
	}
	sum=sum*(1.00/(4.00*m));
	for(int i=1; i<=n; i++)
		if(a[i]>=sum)
			t++;
	if(t<m)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	int n, m, a[20][20], b[20], c,ans=0;
	cin >> n >> m >> c;
	for (int i = 0; i < m; i++)cin >> b[i];
	for (int i = 0; i < n; i++) {
		int memo = 0;
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			memo += a[i][j] * b[j];
		}
		memo += c;
		if (memo > 0)ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <set>
#include <fstream>
#include <cstring>
#include <climits>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define ll long long
#define mod 1000000007

ll dp[3001][3001];

int main() {

	int n;
	cin >> n;
	ll a[n];

	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	memset(dp, 0, sizeof(dp));

	for (int l = n-1; l >= 0; l--) {
		for (int r = l; r < n; r++) {
			if (l == r) {
				dp[l][r] = a[l];
			} else {
				dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
			}
		}
	}
	cout << dp[0][n - 1];

	return 0;
}


Measured memory_bytes: 70656
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	vi cnt(n + 1, 1); //initially each has 1
	vi red(n + 1, 0);
	red[1] = 1; //the first one has the red ball
	rep(i, m){
		int x, y;
		cin >> x >> y;
		if(!cnt[x]) assert(0); //shouldn't happen?
		if(cnt[x] == 1){
			if(red[x]){
				cnt[x]--;
				cnt[y]++;
				red[x] = 0;
				red[y] = 1;
			}
			else{
				cnt[x]--;
				cnt[y]++;
			}
		}
		else if(cnt[x] > 1){
			if(red[x]){
				cnt[x]--;
				cnt[y]++;
				red[y] = 1;
			}
			else{
				cnt[x]--;
				cnt[y]++;
			}
		}
	}
	int ans = 0;
	rep(i, n + 1) if(red[i]) ans++;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1024
fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(args: Array<String>) {
    readLine()
    var x = 0
    readInts().forEach {
        var y = it
        while (y and 1 == 0) {
            x++
            y = y shr 1
        }
    }
    println(x)
}


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

int main () {
  ll N;
  cin >> N;
  int ans = 0;

  for (int A = 1; A < N; A++) {
    ans += max(N / A, (ll)1);
    if (N % A == 0) {
      ans--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

int k, s;
signed main() {
	cin >> k >> s;
	int cnt = 0;

	if (k > s) k = s;
	for (size_t x = 0; x <= k; ++x)
	{
		for (size_t y = 0; y <= k; ++y)
		{
			int z = s - x - y;
			if(z <= k && 0 <= z) ++cnt;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    cins(all(a));
    cins(all(b));
    ll c1 = 0,c2 = 0;
    rep(i,n){
        if (a[i] >= b[i]) c1 += a[i]-b[i];
        else{
            if ((b[i]-a[i])%2){
                c1 += 1;
                c2 += (b[i]-a[i])/2+1;
            }
            else{
                c2 += (b[i]-a[i])/2;
            }
        }
    }
    Yes(c1 <= c2);
}


Measured memory_bytes: 384
import           Control.Monad
import           Data.List
main = do
    n <- readLn :: IO Int
    l <- map words <$> replicateM n getLine :: IO [[String]]
    let xs = map (\(t1, t2) -> (t1, t2!!0, (read (t2!!1) :: Int))) (zip [1..] l)
    mapM_ print .  map sel1 . join . map (sortBy (flip cmp3)) . groupBy eq2 . sortBy cmp2 $ xs
  where
    sel1 (x,_,_) = x
    sel2 (_,x,_) = x
    sel3 (_,_,x) = x
    eq2 a b = sel2 a == sel2 b
    cmp2 a b = compare (sel2 a) (sel2 b)
    cmp3 a b = compare (sel3 a) (sel3 b)


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n;
    cin >> n;
    string ans = "";
    while (n != 0)
    {
        if (n % 2 != 0)
        {
            n--;
            ans = "1" + ans;
        }
        else
            ans = "0" + ans;
        n /= -2;
    }
    if (ans == "")
        ans = "0";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll n,m,q,a[105],b[105],c[105],d[105],val[15],res;
void func(ll i){
	if(i==n){
		ll sum=0;
		for(ll j=0;j<q;j++)
		if(val[b[j]]-val[a[j]]==c[j])
		sum+=d[j];
		res=max(res,sum);
		return;
	}
	ll cnt=(i==0?1:val[i-1]);
	for(ll j=cnt;j<=m;j++){
		val[i]=j;
		func(i+1);
	}
}
void solve(){
	cin>>n>>m>>q;
	for(ll i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;
		b[i]--;
	}
	func(0);
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 3660
from math import gcd
def gcd_ext(a, b):
  x,y,lastx,lasty = 0,1,1,0
  while b!=0:
    q=a//b
    a,b=b,a%b
    x,y,lastx,lasty=lastx-q*x,lasty-q*y,x,y
  return (lastx,lasty)
a,b=map(int,input().split())
c=gcd(a,b)
a,b=a//c,b//c
x,y=gcd_ext(a,b)
ans=[(x,y)]
for i in [-1,0,1]:
  ans+=[(-b*i+x,a*i+y)]
print(*min(ans,key=lambda x:abs(x[0])+abs(x[1])))


Measured memory_bytes: 5668
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef int Int;
typedef pair<Int,Int> pii;
typedef pair<Int,double> pid;
typedef pair<double,double> pdd;
typedef pair<Int,pii> pip;
typedef pair<double,Int> pdp;
#define A first
#define B second
#define pb(x) push_back(x)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (x).size()
#define CLR(x) memset(x,0,sizeof x)
#define pdebug() printf("%d\n",__LINE__)
#define Itype(a) typeof(a.begin()) 
#define REP(i,a,b) for(int i = (a);i <= (b);i++)
#define FORO(i,n) REP(i,0,(int)n-1)
#define FORI(i,n) REP(i,1,(int)n)
#define FORIT(i,t) for(Itype(t) i = t.begin();i != t.end();i++)
#define eps 1e-6
#define sqr(x) ((x)*(x))
#define dist(_a,_b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B))
#define abs(x) (x < 0 ? -x : x) 
#define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B))
template<typename T>void getMin(T &a,T b) { if(a > b) a = b; }
template<typename T>void getMax(T &a,T b) { if(a < b) a = b; }
const ll inf = 1000000000007LL;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    vector<int> A(N + 1);
    
    FORI(i, N) cin >> A[i];

    ll dp[N + 1][2];
    dp[0][0] = dp[0][1] = 0;
    dp[1][0] = A[1]; dp[1][1] = -inf;
    for(int i = 2;i <= N;i++) {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + A[i];
        dp[i][1] = max(dp[i - 2][0], dp[i - 2][1]) -(A[i] + A[i - 1]);
        getMax(dp[i][1], dp[i - 1][1] + 2 * A[i - 1] - A[i]);
    }
    
    cout << max(dp[N][0], dp[N][1]) << endl;

    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
using namespace std;
int N;
int S[500],T[500];
unsigned long A[500][500],U[500],V[500];
int tx[500],ty[500];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>S[i];
	for(int i=0;i<N;i++)cin>>T[i];
	for(int i=0;i<N;i++)cin>>U[i];
	for(int i=0;i<N;i++)cin>>V[i];
	for(int k=0;k<64;k++)
	{
		const unsigned long now=1uL<<k;
		int xc[4]={},yc[4]={};
		for(int i=0;i<N;i++)
		{
			if(S[i]==0)
			{
				if(U[i]&now)tx[i]=3;
				else tx[i]=1;
			}
			else
			{
				if(U[i]&now)tx[i]=2;
				else tx[i]=0;
			}
			xc[tx[i]]++;
			if(tx[i]==3)
			{
				for(int j=0;j<N;j++)A[i][j]|=now;
			}
		}
		for(int j=0;j<N;j++)
		{
			if(T[j]==0)
			{
				if(V[j]&now)ty[j]=3;
				else ty[j]=1;
			}
			else
			{
				if(V[j]&now)ty[j]=2;
				else ty[j]=0;
			}
			yc[ty[j]]++;
			if(ty[j]==3)
			{
				for(int i=0;i<N;i++)A[i][j]|=now;
			}
		}
		if(xc[0]>0&&yc[3]>0||xc[3]>0&&yc[0]>0)
		{
			cout<<-1<<endl;
			return 0;
		}
		if(xc[2]==0&&yc[2]==0)continue;
		if(xc[3]>0&&yc[3]>0)continue;
		vector<int>xi,yi;
		for(int i=0;i<N;i++)if(tx[i]>=2)xi.push_back(i);
		for(int j=0;j<N;j++)if(ty[j]>=2)yi.push_back(j);
		int xa=0,ya=0;
		if(xi.size()==0)
		{
			if(yc[2]==1)xa=1;
			else if(yc[2]>=2)xa=2;
		}
		else if(xi.size()==1)
		{
			if(yc[2]>=2)ya=1;
		}
		if(yi.size()==0)
		{
			if(xc[2]==1)ya=1;
			else if(xc[2]>=2)ya=2;
		}
		else if(yi.size()==1)
		{
			if(xc[2]>=2)ya=1;
		}
		for(int i=0;i<N;i++)if(tx[i]==1&&xa>0)
		{
			xa--;
			xi.push_back(i);
		}
		for(int j=0;j<N;j++)if(ty[j]==1&&ya>0)
		{
			ya--;
			yi.push_back(j);
		}
		for(int id=0;id<xi.size()||id<yi.size();id++)
		{
			A[xi[id%xi.size()]][yi[id%yi.size()]]|=now;
		}
	}
	for(int i=0;i<N;i++)
	{
		if(S[i]==0)
		{
			unsigned long now=A[i][0];
			for(int j=1;j<N;j++)now&=A[i][j];
			if(now!=U[i])
			{
				cout<<-1<<endl;
				return 0;
			}
		}
		else
		{
			unsigned long now=A[i][0];
			for(int j=1;j<N;j++)now|=A[i][j];
			if(now!=U[i])
			{
				cout<<-1<<endl;
				return 0;
			}
		}
		if(T[i]==0)
		{
			unsigned long now=A[0][i];
			for(int j=1;j<N;j++)now&=A[j][i];
			if(now!=V[i])
			{
				cout<<-1<<endl;
				return 0;
			}
		}
		else
		{
			unsigned long now=A[0][i];
			for(int j=1;j<N;j++)now|=A[j][i];
			if(now!=V[i])
			{
				cout<<-1<<endl;
				return 0;
			}
		}
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)cout<<A[i][j]<<(j+1==N?'\n':' ');
	}
}


Measured memory_bytes: 7288
def calc n, x
  return 0 if x < 0
  if n == 1
    return (0..9).include?(x) ? 1 : 0
  end
  (0..9).to_a.inject(0){|result, mem| result += calc(n-1, x-mem)}
end

while input = gets do
  puts calc(4, input.to_i)
end

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second

int n;
int arr[3005];
int dp[3005][3005];

int find(int l, int r, int turn){
	if(l>r)
		return -1;

	if(dp[l][r]!=-1)
		return dp[l][r];

	if(l==r){
		if(turn)
			return dp[l][r] = arr[l];
		else
			return dp[l][r] = -arr[l];
	}

	if(turn){
		 return dp[l][r] = max(find(l+1,r,1-turn)+arr[l], arr[r] + find(l,r-1,1-turn));
	}
	else{
		return dp[l][r] = min(find(l+1,r,1-turn)-arr[l], find(l,r-1,1-turn)-arr[r]);
	}


}

void solve(){
	
	cin>>n;
	rep(i,0,n)
		cin>>arr[i];

	memset(dp,-1,sizeof dp);
	cout<<find(0,n-1,1)<<endl;;
}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 70912
from collections import deque

K = int(input())
d = deque()
for i in range(1, 10):
    d.append(i)

cnt = 0
while d:
    tmp = d.popleft()
    cnt += 1
    if cnt == K:
        print(tmp)
        break
    r = tmp % 10
    if r != 0:
        d.append(tmp * 10 + r - 1)
    d.append(tmp * 10 + r)
    if r != 9:
        d.append(tmp * 10 + r + 1)

Measured memory_bytes: 40816
#include <bits/stdc++.h>
using namespace std;
int dp[2000][2000];
int main(){
  int n,d;
  cin >> n >> d;
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> dp[i][j];
    }
  }
  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      int res = 0;
      for(int k=0;k<d;k++){
        res += (dp[i][k] - dp[j][k]) * (dp[i][k] - dp[j][k]);
      }
      //cout << res << endl;
      int c = sqrt(res);
      if(c * c == res)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
N =int(input())
k1 = make_divisors(N)
k2 = make_divisors(N-1)
ans = 0
n = N

for x in k1:
    
    if x == 1:continue
    if n%x == 1:ans+=1
    while n%x == 0:
        n//=x
        if n%x == 1:
            ans+=1
            
    n = N
for x in k2:
    if x == 1:continue
    if n%x == 1:ans+=1
    while n%x == 0:
        n//=x
        if n%x == 1:
            ans+=1
            
    n = N
print(ans)

Measured memory_bytes: 39152
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int h=sc.nextInt();
    sc.close();
    int s=(a+b)*h/2;
    System.out.println(s);
  }
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
#define MOD 10007
#define W(a) (a == 'J' ? 1 : (a == 'O' ? 2 : 4))
#define C(a, b) ((a & W(b)) == W(b))
int main() {
	int N, n, i, j;
	char p, q;
	cin >> n;
	int dp[1001][8] = {};
	dp[n][1] = 1;
	q = 'J';
	for (; n--;) {
		cin >> p;
		for (i = 1; i < 8; i++) {
			if ((i & W(p)) == 0) {
				continue;
			}
			for (j = 1; j < 8; j++) {
				if ((i & j) == 0) {
					continue;
				}
				//dp[n + 1][j] && (cout << n << ": " << i << " <= " << j << endl);
				dp[n][i] += dp[n + 1][j];
				dp[n][i] %= MOD;
			}
		}
		q = p;
	}
	int r = 0;
	for (i = 1; i < 8; i++) {
		r += dp[0][i] % MOD;
	}
	cout << r % MOD << endl;
	return 0;
}

Measured memory_bytes: 1200
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

static const int MOD = 1e9 + 7;

int main() {

    int N;
    cin >> N;
    vector<int>d(N);
    for (int i = 0; i < N; i++)cin >> d[i];

    int ans = 0;
    for (int i = 0; i <N-1 ; i++) {
        for (int j = i + 1; j < N; j++)ans += d[i] * d[j];
    }

    cout << ans;
}

Measured memory_bytes: 256