akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = ["AC", "WA", "TLE", "RE"]
s2 = [0, 0, 0, 0]
for i in range(n):
    s2[s.index(input())] += 1

print("AC x %d\nWA x %d\nTLE x %d\nRE x %d" % (s2[0], s2[1], s2[2], s2[3]))

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
	cin >> n >> k;
	ari
	int kk;
	vector<int> dp_arr(n, INT_MAX);
	dp_arr[0] = 0;
	for(int i = 1; i < n; i++){
		for(int j = 1; j <= k && i - j >= 0; j++){
			dp_arr[i] = min((ll)dp_arr[i-j]+llabs(a[i] - a[i - j]), (ll)dp_arr[i]);
		}
	}
	cout << dp_arr[n-1] << endl;
	
	return(0);
}

Measured memory_bytes: 6784
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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


main(){
  int n;

  while(cin>>n,n){
    long double heya[20][3][3]={{{0.0}}};

    char s,t,b;
    cin>>s>>t>>b;
    s-='A';
    t-='A';
    b-='A';

    heya[0][s/3][s%3]=1.0;
    //cout<<n<<" "<<s/3<<" "<<s%3<<endl;


    rep(k,n){

      rep(i,9){
	int cx=i/3,cy=i%3;

	rep(j,4){
	  int nx=cx+dx[j],ny=cy+dy[j];
	  if(nx<0 || 2<nx || ny<0 || 2<ny || (nx==b/3 && ny==b%3))heya[k+1][cx][cy]+=heya[k][cx][cy]/4.0;
	  else heya[k+1][nx][ny]+=heya[k][cx][cy]/4.0;
	}
      }
    }

    printf("%.10Lf\n",heya[n][t/3][t%3]);
  }
}
    

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    string t;
    cin >> t;

    int f = 1, b = n+1;
    REP(i,n){
        string s1, s2;
        REP(j,s[i].length()){
            if (s[i][j] == '?'){
                s1 += 'a';
                s2 += 'z';
            }else{
                s1 += s[i][j];
                s2 += s[i][j];
            }
        }
        if (s2 < t) f++;
        if (s1 > t) b--;
    }
    FOR(i,f,b){
        cout << i;
        if (i != b) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
long a, b, c, d, M=-1e18; cin >> a >> b >> c >> d;
M=max(M, a*c); M=max(M, b*d); M=max(M, a*d); M=max(M, b*c);
cout << M << "\n";
}

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

int q1,b,c1,c2,q2;
int i,j,k;

int main(){
	while(scanf("%d",&q1)*q1){
		scanf("%d %d %d %d",&b,&c1,&c2,&q2);
		for(i=((b/c1<q2)?b/c1:q2),b-=i*c1,j=0;i>0;i--,b+=c1){
			k=b/c2;
			j+=k;
			b-=k*c2;
			if(i+j>=q1)break;
		}
		if(i==0)printf("NA\n");
		else printf("%d %d\n",i,j);
	}
	return 0;
}

Measured memory_bytes: 612
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int [] height = new int[n + 1];
        for (int i = 1; i <= n; ++i) {
            height[i] = scanner.nextInt();
        }
        Map<Integer, Map<Integer, Integer>> graph = new HashMap<>();
        for (int i = 0; i < m; ++i) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            if (!graph.containsKey(a)) {
                graph.put(a, new HashMap<>());
            }
            if (!graph.containsKey(b)) {
                graph.put(b, new HashMap<>());
            }
            Integer aToB = graph.get(a).getOrDefault(b, 0);
            graph.get(a).put(b, aToB + 1);
            graph.get(b).put(a, aToB + 1);
        }
        int[] good = new int[n + 1];
        for (int i = 1; i <= n; ++i) {
            if (good[i] == -1) {
                continue;
            }
            if (!graph.containsKey(i)) {
                good[i] = 1;
                continue;
            }
            Map<Integer, Integer> neighbors = graph.get(i);
         //   System.out.println("i: " + i);
            for (Map.Entry<Integer, Integer> neighborRoads : neighbors.entrySet()) {
                int neighbor = neighborRoads.getKey();
             //   System.out.println("neighbor:  " + neighbor + " roads: " + neighborRoads.getValue());
                if (height[neighbor] >= height[i]) {
                    good[i] = -1;
                    break;
                }
            }
            if (good[i] == 0) {
                good[i] = 1;
           //     System.out.println("good: " + i);
            }
        }
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
            if (good[i] == 1) {
                ++ans;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 88976
from bisect import bisect_left
import array

n = int(input())
p = []

for i, x in enumerate(map(int, input().split())):
    p.append([x, i])

p.sort(reverse=True)

s = array.array('i', [-1, -1, p[0][1], n, n])

#print(p)

ans = 0
i = 2
for a, x in p[1:]:
    t = bisect_left(s, x)
    ans += a * ((x - s[t-1]) * (s[t+1] - s[t]) + (s[t] - x) * (s[t-1] - s[t-2]))
    #print(t, s)
    s.insert(t, x)
    i += 1


print(ans)




Measured memory_bytes: 25972
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  if i!=0:
    a[i]=a[i]+a[i-1]
b=0
ans,bns=0,0
for i in range(n):
  if i%2==0:
    if a[i]+b>=0:
      ans+=(a[i]+1+b)
      b-=(a[i]+1+b)
  else:
    if a[i]+b<=0:
      ans+=(1-a[i]-b)
      b+=(1-a[i]-b)
b=0
for i in range(n):
  if i%2==0:
    if a[i]+b<=0:
      bns+=(1-a[i]-b)
      b+=(1-a[i]-b)
  else:
    if a[i]+b>=0:
      bns+=(a[i]+b+1)
      b-=(a[i]+b+1)
print(min(ans,bns))

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

template <int MOD_>
struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");
 
private:
	using ll = long long;
 
	int v;
 
	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}
 
public:
 
	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }
 
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }
 
	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}
 
	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}
 
	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}
 
	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<int(1e9) + 7>;

const int MAXN = 60;
int N;
char G[2][MAXN];
num dp[MAXN][3][3];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> G[0] >> G[1];
	for (int a = 0; a < 3; a++) {
		for (int b = 0; b < 3; b++) {
			if ((a == b) == (G[0][0] == G[1][0])) {
				dp[1][a][b] = 1;
			}
		}
	}
	for (int i = 1; i < N; i++) {
		for (int a = 0; a < 3; a++) {
			for (int b = 0; b < 3; b++) {
				for (int c = 0; c < 3; c++) {
					for (int d = 0; d < 3; d++) {
						if ((a == c) == (G[0][i-1] == G[0][i]) &&
							(b == d) == (G[1][i-1] == G[1][i]) &&
							(c == d) == (G[0][i] == G[1][i])) {
							dp[i+1][c][d] += dp[i][a][b];
						}
					}
				}
			}
		}
	}

	num tot = 0;
	for (int a = 0; a < 3; a++) {
		for (int b = 0; b < 3; b++) {
			tot += dp[N][a][b];
		}
	}
	cout << tot << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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()
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = (1'000'000'000 + 7);

int main()
{
    int n;
    cin >> n;
    VI v(n);
    map<int, ll> mp;
    rep(i, n)
    {
        cin >> v[i];
        v[i]--;
        mp[v[i]]++;
    }
    ll mans = 0;
    rep(i, n)
    {
        mans += mp[i] * (mp[i] - 1) / 2;
    }

    rep(i, n)
    {

        ll ans = mans;
        int val = v[i];
        if (mp[val] >= 2)
            ans = ans - mp[val] * (mp[val] - 1) / 2 + (mp[val] - 1) * (mp[val] - 2) / 2;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 17152
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

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

	int A,B;
	int max1,max2,max3;

	cin >> A >> B;

	cout << max(A + B ,max(A-B , A*B)) << endl;

	return 0;

}

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

using namespace std;

int main(void){
    string input;
    
    while(getline(cin, input), !cin.eof()){
        int H, W;
        
        sscanf(input.c_str(), "%d %d\n", &H, &W);
        
        if((H | W) == 0) break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i + j) % 2 == 0){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return(0);
}



Measured memory_bytes: 3212
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F551C':
    sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    S = read_str()
    T = read_str()
    n = len(S)
    res = 'Yes'
    A = [0] * n
    B = [0] * n
    vu = {}
    for i in range(n):
        if S[i] not in vu:
            vu[S[i]] = i
        A[i] = vu[S[i]]

    vu = {}
    for i in range(n):
        if T[i] not in vu:
            vu[T[i]] = i
        B[i] = vu[T[i]]

    if A != B:
        res = 'No'

    # for i in range(n):
    #     for j in range(n):
    #         if S[i] != S[j] and T[i] == T[j]:
    #             res = 'No'
    #         if S[i] == S[j] and T[i] != T[j]:
    #             res = 'No'
    print(res)


main()


Measured memory_bytes: 7340
import numpy as np


def solve(n, m):
    def prepare(n, m):
        f = 1
        for i in range(1, n + 1):
            f = f * i % m
        fn = f
        inv = [1] * (n + 1)
        f = pow(f, m - 2, m)
        inv[n] = f
        for i in range(n, 0, -1):
            f = f * i % m
            inv[i - 1] = f
        return fn, inv

    def a_x(a, x, m):
        ret = 1
        yield ret
        for _ in range(x):
            ret = ret * a % m
            yield ret

    fn, inv = prepare(n, m)

    stir2 = np.zeros(n + 2, dtype=np.int64)
    stir2[0] = 1
    upd = np.arange(2, n + 3, dtype=np.int64)

    ex2 = [2]
    for i in range(n):
        ex2.append(ex2[-1] ** 2 % m)

    ans = 0
    si = 1

    for i in range(n+1):
        nCi = fn * inv[i] * inv[n-i] % m
        i_with = np.fromiter(a_x(pow(2, n-i, m), i, m), dtype=np.int64) 
        i_on = (stir2[ :i+1] * i_with % m).sum() % m
        ans = (ans + nCi * i_on % m * ex2[n-i] % m * si) % m
        stir2[1 : i+2] = (stir2[1 : i+2] * upd[ :i+1] + stir2[ :i+1]) % m
        si *= -1

    return ans


N, M = map(int, input().split())
print(solve(N, M))


Measured memory_bytes: 29000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a==b) System.out.println("Draw");
        else{
            for(int i=2;i<=13;i++){
                if(i==a){
                    System.out.println("Bob");
                    break;
                }
                else if(i==b) {
                    System.out.println("Alice");
                    break;
                }
            }
        }
	}
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){

    int n;
    cin >> n;
    clock_t st = clock();
    vector<vector<int>> v(n, vector<int>(n - 1, 0));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n - 1; ++j){
            cin >> v[i][j];
            --v[i][j];
        }

    vector<int> c(n, 0), now(n, 0);
    int max_cnt = 0;
    int cnt = 0;
    while(max_cnt != n){
        if(double(clock() - st) / CLOCKS_PER_SEC >= 1.8){
            cout << 499500 << endl;
            return 0;
        }
        ++cnt;
        bool fl = false;
        for(int i = 0; i < n; ++i){
            if(c[i] == n - 1|| now[i] == cnt)
                continue;
            int to = v[i][c[i]];
            if(c[to] == n - 1 || now[to] == cnt)
                continue;
            if(v[to][c[to]] == i){
                now[i] = cnt;
                now[to] = cnt;
                if(++c[i] == n - 1)
                    ++max_cnt;
                if(++c[to] == n - 1)
                    ++max_cnt;
                fl |= true;
            }
        }
        if(!fl){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 4224
import java.io.PrintWriter;
import java.util.*; 
class Main { 
	static char[] ca;
	static PrintWriter out=new PrintWriter(System.out);
	static boolean judge;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
			while(sc.hasNext()){
				judge=true;
				 ca= sc.next().toCharArray();
				 doing('o');
				 if(judge)doing('x');
				 if(judge)out.println('d');
				 out.flush();
			}	
	}
	
	static void doing(char temp){
		if(ca[0]==temp&ca[1]==temp&ca[2]==temp|ca[3]==temp&ca[4]==temp&ca[5]==temp|ca[6]==temp&ca[7]==temp&ca[8]==temp|ca[0]==temp&ca[3]==temp&ca[6]==temp|ca[1]==temp&ca[4]==temp&ca[7]==temp|ca[2]==temp&ca[5]==temp&ca[8]==temp|ca[0]==temp&ca[4]==temp&ca[8]==temp|ca[2]==temp&ca[4]==temp&ca[6]==temp){
			out.println(temp);
			judge=false;
		}
	}
}

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

int main() {
  int n,x;


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

  sort(a,a+n);


  int ans=0;
  for (int i = 0; i < n; i++){
  	x-=a[i];
  	if(x>=0){
  		ans++;
  	}else break;
  }

  if(x>0){
  	ans--;
  }


  cout<<ans<<endl;
}

Measured memory_bytes: 256
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

s = list(range(1, n+1))
s = list(permutations(s))

a, b = 0, 0

for i, v in enumerate(s, start=1):
	if v == p:
		a = i
	elif v == q:
		b = i
	else:
		pass

print(0) if p == q else print(abs(a - b))

Measured memory_bytes: 45040
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long ll;
const int maxN=202000;
const int maxM=maxN<<1;
const int inf=1000000000;

class Edge{
    public:
    int u,v;ll w;
};

int n,m,ufs[maxN];
int edgecnt=-1,Head[maxN],Next[maxM],V[maxM],W[maxM];
int Sz[maxN],Mx[maxN],rt,rtsize,vis[maxN];
Edge E[maxN*20];
ll Nw[maxN],Val[maxN];

void Add_Edge(int u,int v,int w);
void Divide(int start,int size);
void dfs_root(int u,int fa,int size);
void dfs_calc(int u,int fa,ll dst,int &x);
void dfs_push(int u,int fa,int x);
bool cmp(Edge A,Edge B);
int find(int x);
int main(){
    //freopen("in","r",stdin);
    scanf("%d",&n);memset(Head,-1,sizeof(Head));
    for (int i=1;i<=n;i++) scanf("%lld",&Nw[i]);
    for (int i=1;i<n;i++){
        int u,v,w;scanf("%d%d%d",&u,&v,&w);Add_Edge(u,v,w);Add_Edge(v,u,w);
    }
    Divide(1,n);for (int i=1;i<=n;i++) ufs[i]=i;
    sort(&E[1],&E[m+1],cmp);ll Ans=0;
    for (int i=1;i<=m;i++) if (find(E[i].u)!=find(E[i].v)) Ans+=E[i].w,ufs[find(E[i].u)]=find(E[i].v);
    printf("%lld\n",Ans);return 0;
}
void Add_Edge(int u,int v,int w){
    Next[++edgecnt]=Head[u];Head[u]=edgecnt;V[edgecnt]=v;W[edgecnt]=w;
    return;
}
void Divide(int start,int size){
    rt=0;rtsize=inf;dfs_root(start,start,size);
    int u=rt,mn=u;vis[u]=1;Val[u]=Nw[u];
    dfs_calc(u,0,0,mn);dfs_push(u,0,mn);
    for (int i=Head[u];i!=-1;i=Next[i]) if (!vis[V[i]]) Divide(V[i],Sz[V[i]]>Sz[u]?size-Sz[u]:Sz[V[i]]);
    return;
}
void dfs_root(int u,int fa,int size){
    Sz[u]=1;Mx[u]=0;
    for (int i=Head[u];i!=-1;i=Next[i]) if (!vis[V[i]]&&V[i]!=fa) dfs_root(V[i],u,size),Sz[u]+=Sz[V[i]],Mx[u]=max(Mx[u],Sz[V[i]]);
    Mx[u]=max(Mx[u],size-Sz[u]);
    if (Mx[u]<rtsize) rtsize=Mx[u],rt=u;return;
}
void dfs_calc(int u,int fa,ll dst,int &x){
    //cout<<"dfs:"<<u<<" "<<fa<<" "<<dst<<endl;
    Val[u]=Nw[u]+dst;if (Val[u]<Val[x]) x=u;
    for (int i=Head[u];i!=-1;i=Next[i]) if (!vis[V[i]]&&V[i]!=fa) dfs_calc(V[i],u,dst+W[i],x);
    return;
}
void dfs_push(int u,int fa,int x){
    E[++m]=((Edge){u,x,Val[u]+Val[x]});for (int i=Head[u];i!=-1;i=Next[i]) if (!vis[V[i]]&&V[i]!=fa) dfs_push(V[i],u,x);return;
}
bool cmp(Edge A,Edge B){
    return A.w<B.w;
}
int find(int x){
    if (ufs[x]!=x) ufs[x]=find(ufs[x]);
    return ufs[x];
}

Measured memory_bytes: 76416
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//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();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef pair<int, TIII> QIIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b,c))
#define MQ(a,b,c,d) MP(a, MT(b,c,d))
#define Q1 first
#define Q2 second.first
#define Q3 second.second.first
#define Q4 second.second.second

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8
#define MOD 1000000007

LL flag[55];

int main(){
	int n,ans;
	while(cin >> n, n){
		ans = -1;
		LL check = (1LL<<n)-1;
		VI m[31];
		REP(i,n){
			flag[i]=(1LL<<i);
			int t;
			cin >> t;
			REP(j,t){
				int tmp;
				cin >> tmp;
				m[tmp].PB(i);
			}
		}
		REP(i,31){
			LL tmp=0;
			REP(j,m[i].size())tmp |= flag[m[i][j]];
			if(tmp==check){
				ans = i; 
				break;
			}
			REP(j,m[i].size())flag[m[i][j]]=tmp;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
    long long n,k,z;
    cin>>n>>k;
    //z=ceil(n*1.0/k);
    //cout<<min(abs(n-(z*k)),n)<<endl;
    z=n%k;
    cout<<min(z,k-z)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 1000000007; //10^9+7

int myhash(int h){
  int sum=0;
  while(h){
    int dig=h%10;
    sum+=dig;
    h/=10;
  }
  return sum;
}

int main(){
  int n;
  cin>>n;
  if(n%myhash(n)==0){print("Yes");}
  else{print("No");}
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc = 1; 
    //cin >> tc;
    while(tc--){
        int n; cin >> n;
        int ans = 0;
        string s; cin >> s;
        int r = 0, g = 0, b = 0;
        for(auto x:s)
            if(x == 'R')
                r++;
            else if(x == 'G')
                g++;
            else b++;
        ans = r*g*b;
        FOR(i,0,n)
        {
            FOR(k,i,n)
            {
                if((i+k)%2) continue;
                int j = (i+k)/2;
                if(s[i] != s[j] and s[j] != s[k] and s[k] != s[i])
                    --ans;
            }
        }
        cout << ans;
        
    }    
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    VI a(A), b(B);
    int mina = INF, minb = INF;
    REP(i, A){
        cin >> a[i];
        chmin(mina, a[i]);
    }
    REP(i, B){
        cin >> b[i];
        chmin(minb, b[i]);
    }
    int ans = mina + minb;
    REP(i, M){
        int x, y, c; cin >> x >> y >> c;
        --x; --y;
        chmin(ans, a[x]+b[y]-c);
    }
    cout << ans << endl;
    return 0;
}


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

int main(void) {
    int n;
    cin >> n;
    vector<char> a(n);
    int r = 0, w = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int count = 0;
    int i = 0, j = n-1;
    while (true) {
        while (i < n) {
            if (a[i] == 'W') {
                break;
            }
            i++;
        }
        while (j >= 0) {
            if (a[j] == 'R') {
                break;
            }
            j--;
        }
        if (i < j) {
            count++;
            i++;
            j--;
        } else {
            break;
        }
    }


    cout << count  << endl;


    return 0;
}

Measured memory_bytes: 3600
def saiki_wa(S,l,ls,n):
	ret = 0
	if n == l-1:
		s = S[0]
		for i in range(l-1):
			s = s + ls[i] + S[i+1]
		ret = sum([int(i) for i in s.split('+')])
	else:
		ret += saiki_wa(S,l,ls[:],n+1)
		ls[n] = '+'
		ret += saiki_wa(S,l,ls[:],n+1)

	return ret

if __name__ == '__main__':
	S = input()
	l = len(S)

	if l == 1:
		ans = int(S)
	else:
		ls = [''] * (l-1)

		ans = saiki_wa(S,l,ls,0)

	print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>

using namespace std;

int main()
{
    int n, a[1001];
    int ans = 1;
    int no = 1;

    cin >> n;

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

    for (int i = 0; i < n; i++) {
        if (!(a[i] % 2)) {
            no *= 2;
        }
    }

    cout << ans - no << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _20190224AtCoderB
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            double sum = 0;
            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                if (input.ElementAt(1)[0] == 'J')
                {
                    sum += int.Parse(input.ElementAt(0));
                }
                else
                {
                    sum += 380000 * double.Parse(input.ElementAt(0));
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#define MOD 1000000007
#define EPS 1e-10
using namespace std;

int main() {
   int n;
   long long q;
   vector<pair<int,int>> v;
   int a, b;

   cin >> n >> q;
   for (int i = 0; i < n; i++) {
      cin >> a >> b;
      v.push_back(make_pair(a,b));
   }

   sort(v.begin(), v.end());

   int i = 0;
   long long sum = 0;
   while (sum < q) {
      sum += v[i].second;
      if (sum >= q) {
         cout << v[i].first << endl;
         break;
      }
      i++;
   }
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s.length() == 2){
        cout <<s;
    }
    if(s.length() == 3){
        for(int i=s.length()-1; i>=0; i--){
            cout << s[i];
        }
    }
    cout << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;
ll v[maxn];
vector<int>g[maxn];
ll ans[maxn];
void dfs(int now,int pre,ll val){
	val += v[now];
	ans[now] = val;
	for(auto i:g[now]){
		if(i==pre)continue;
		dfs(i,now,val);
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,q;
	cin >> n >> q;
	f(n-1){
		int add1,add2;
		cin >> add1 >> add2;
		g[add1].pb(add2);
		g[add2].pb(add1);
	}
	f(q){
		int a,b;
		cin >> a >> b;
		v[a] += b;
	}
	dfs(1,0,0);
	f1(n){
		cout << ans[i]<<' ';
	}
	cout << endl;
}

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

# define fori(i,n)          for(int i=0;i<n;i++)
# define forl(i,n)          for (ll i=0;i<n;i++)
# define pb                 push_back
# define mp                 make_pair
# define X                  first
# define Y                  second
# define all(v)             v.begin(),v.end()
# define in_ar_int(arr,n)   int arr[n]; fori(i,n) cin >> arr[i];
# define in_ar_ll(arr,n)    ll arr[n]; fori(i,n) cin >> arr[i];
# define endl               "\n"
# define R0                 return 0
# define mod                1000000007
# define pi                 3.1415926536


typedef long long ll;
typedef string str;

 
ll power (ll a, ll b){
    ll ans=1;
    while(b){
		if (b & 1) ans*=a;
		a*=a;
		b/=2;
    }
    return ans;
}

bool isprime(int n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6){
		if (n%i == 0 || n%(i+2) == 0) 
		return false; 
	}
    return true; 
} 

long long nCr(int n,int r){
    if(n==r) return 1;
    else if (r==0) return 1;
    else return nCr(n-1,r-1)+nCr(n-1,r);
}

int sdigit(int x){
    int ans=0;
    while(x){
		ans+=x%10;
		x/=10;
    }
    return ans;
}

int bs(int a[],int b,int l,int r){
    int mid=l + (r-l)/2;
    if(l>r) return -1;
    if(a[mid]==b||l==r)	return mid;
    if(a[mid]>b)	return bs(a,b,l,mid-1);
    else return bs(a,b,mid+1,r);
}

long long  gcd(int a,int b){
    if (b==0) return a;
    return gcd(b,a%b);
}


void solve(){
	int n,k; cin >> n >> k;
	int h[n+1];
	for (int i=0;i<n;i++){
		cin >> h[1+i];
	}
	int dp[n+1];
	dp[n]=0;
	for (int i=n-1;i>0;i--){
		int small=INT_MAX;
		for (int j=1;j<=k;j++){
			if (i+j<n+1){
				small=min(small,dp[i+j]+abs(h[i+j]-h[i]));
			}else{
				break;
			}
		}
		dp[i]=small;
	}
	cout << dp[1] << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int chill=1;
    // cin >> chill;
    while(chill--){
	solve();
    }
} 



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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

/* 
 * * stuff you should look for
 * * int overflow, array bounds
 * * special cases (n=1?), set tle
 * */

int n, d, a;
vector<pii> mon;

struct FW{
    vector<ll > bit;

    FW(){
        bit.resize(n + 1, 0);
    }

    void upd(int k, ll x){
        for(int i = k; i <= n; i += i & (-i)) bit[i] += x;
    }

    void upd(int l, int r, ll x){
        upd(l, x);
        if(r + 1 <= n) upd(r + 1, -x);
    }

    ll query(int k){
        ll sum = 0;
        for(int i = k; i > 0; i -= i & (-i)) sum += bit[i];
        return sum;
    }
};

int main(){
    fcin;

    cin >> n >> d >> a;

    for(int i = 0; i < n; i++){
        int x, h;   cin >> x >> h;

        h = (h + a - 1) / a;

        mon.eb(x, h);
    }

    sort(all(mon));

    FW s;
    for(int i = 0; i < n; i++) s.upd(i + 1, i + 1, mon[i].se);

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll hp = s.query(i + 1);
        if(hp <= 0) continue;

        int x = mon[i].fi;
        int lo = i, hi = n - 1;

        int last = -1;
        while(lo <= hi){
            int mid = (lo + hi) / 2;

            if(x + (ll) 2 * d >= mon[mid].fi){
                last = mid;
                lo = mid + 1;
            } else hi = mid - 1;
        }

        assert(last != -1);

        //printf("bati do %d ao %d com %d\n", i + 1, last + 1, hp);
        ans += hp;
        s.upd(i + 1, last + 1, -hp);
    }

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



Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define LL long long
#define rgi register int
#define rgl register long long
#define il inline

il int read() {
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main() {
	int a = read(), b = read(); int book[5] = {0};
	book[a] = book[b] = 1;
	for(rgi i = 1; i <= 3; ++i) if(!book[i]) printf("%d", i);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vi a(n);
    rep(i,n) cin >> a[i];
    vl sum(n+1);
    rep(i,n) sum[i+1] = sum[i]+a[i];
    rep(i,n+1) sum[i] %= m;
    ll ans = 0;
    map<ll,int> mp;
    rep(i,n+1) {
        ans += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5376
from collections import Counter

N = int(input())
A = [int(i) for i in input().split()]
ca = Counter(A)
ts = 0
for k in ca:
    ts += (ca[k] * (ca[k] - 1)) // 2
ans = [0]*N
for i,a in enumerate(A):
    ans[i] = ts - (ca[a] - 1)
print("\n".join(map(str, ans)))

Measured memory_bytes: 46848
#include<cstdio>
#include<vector>
#define ll long long

using namespace std;

const int N = 55;
const int M = 3000;
int n,m;
int dep[N];
int fa[N];
vector<int> adj[N];
ll record[M];

ll ppow(ll a,ll b){
	ll res = 1;
	while(b){
		if(b&1) res *= a;
		a = a * a;
		b >>= 1;
	}
	return res;
}

void dfs(int u,int pre){
	fa[u] = pre;
	dep[u] = dep[pre]+1;
	for(int i = 0;i < adj[u].size();i++){
		int v = adj[u][i];
		if(v == pre) continue;
		dfs(v,u);
	}
}

int main(){
	//freopen("in","r",stdin);
	scanf("%d",&n);
	for(int i = 1;i < n;i++){ int u,v;scanf("%d%d",&u,&v);adj[u].push_back(v);adj[v].push_back(u);}
	dfs(1,0);
	scanf("%d",&m);
	for(int i = 0;i < m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		if(dep[u]<dep[v]) swap(u,v);
		while(dep[u]>dep[v]) {record[i] |= (1ll<<u),u = fa[u];}
		while(u != v) {record[i] |= (1ll<<u),record[i] |= (1ll<<v),u = fa[u],v = fa[v];}
		//record[i] |= (1<<u);
	}	

	ll res = 1ll << (n-1);
	for(ll i = 1;i < (1ll<<m);i++){
		ll r = 0;
		for(int j = 0;j < m;j++){
			if(i&(1ll<<j)){
				r |= record[j];
			}
		}
		int cnt1 = __builtin_popcountll(i);
		int cnt2 = __builtin_popcountll(r);
		res += ((cnt1&1)? -1 : 1) * (1ll << (n-1-cnt2));
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
 
int main() {
 
  int n,i,j;
  int card[4][13];
  int num;
  long long moji;
 
  scanf("%d", &n);
 
  for(j=0; j<4; j++) {
  for(i=0; i<13 ;i++){
    card[j][i] = 0;
  }
  }
 
  for(i=0; i<2*n ; i++) {
    scanf("%c ",&moji);
    scanf("%d",&num);
    if(moji == 'S') {
      card[0][num-1] = 1;
    } else if(moji == 'H') {
      card[1][num-1] = 1;
    } else if(moji == 'C') {
      card[2][num-1] = 1;
    } else if(moji =='D') {
      card[3][num-1] = 1;
    }
  }
 
  for(j=1;j<=13;j++) {
    if(card[0][j-1] != 1) {
      printf("S %d\n",j);
    }
  }
  for(j=1;j<=13;j++) {
    if(card[1][j-1] != 1) {
      printf("H %d\n",j);
    }
  }
  for(j=1;j<=13;j++) {
    if(card[2][j-1] != 1) {
      printf("C %d\n",j);
    }
  }
  for(j=1;j<=13;j++) {
    if(card[3][j-1] != 1) {
      printf("D %d\n",j);
    }
  }
   return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#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

using namespace std;
typedef long long  ll;
const int N = 1e4 + 4 , MOD = 1e9 + 7;

string s;
int d , memo[N][104][2];

int add(int a , int b){
    return (1ll * a + b) % MOD;
}

int solve(int indx , int rem , bool gr){
    if(indx == (int)s.size())
        return !rem;

    int &ret = memo[indx][rem][gr];
    if(~ret)
        return ret;

    ret = 0;
    int theOne = s[indx] - '0' , en = (gr ? 9 : theOne);
    for(int i = 0 ; i <= en ; ++i)
        ret = add(ret , solve(indx + 1 , (rem + i) % d , gr | (i < theOne)));
    return ret;
}
int main() {
    ios::sync_with_stdio() , cin.tie(0) , cout.tie();
    cin >> s;

    cin >> d;

    memset(memo , -1 , sizeof memo);

    cout << (solve(0 , 0 , false) - 1 + MOD) % MOD << '\n';
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
queue<long long> q;
vector<long long> ans;
long long n,m,i,j,k,l,p,o,s;
int main()
{
    for(i=1;i<=9;i++)
    q.push(i);
    while(ans.size()<111111)
    {
        n=q.front();
        ans.push_back(n);
        q.pop();
        m=n%10;
        if(m>0) q.push(n*10+m-1);
        if(m<9) q.push(n*10+m+1);
        q.push(n*10+m);
    }
    sort(ans.begin(),ans.end());
    scanf("%lld",&k); 
    printf("%lld",ans[k-1]);
    return 0;
}

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

int main() {
	vector<int> nb = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int input;
    cin >> input;
  	cout << nb.at(input-1) << endl;
}

Measured memory_bytes: 256
from collections import Counter

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

oc = Counter(v[0::2]).most_common() + [(0, 0)]
ec = Counter(v[1::2]).most_common() + [(0, 0)]

if oc[0][0] != ec[0][0]:
    print(n - (oc[0][1] + ec[0][1]))
else:
    print(min(n - (oc[1][1] + ec[0][1]), n - (oc[0][1] + ec[1][1])))

Measured memory_bytes: 20572
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2005;
struct node{
    int u,v,nxt;
}edge[N*2];
int head[N],mcnt;
void add_edge(int u,int v){
    mcnt++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
}
int n,k;
int du[N];
int deep[N];
void dfs(int u,int fa,int d){
    deep[u]=d;
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
        if(v==fa)
            continue;
        dfs(v,u,d+1);
    }
}
int main()
{
    //freopen("shorten.in","r",stdin);
    //freopen("shorten.out","w",stdout);
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        add_edge(u,v);
        add_edge(v,u);
        du[u]++;
        du[v]++;
    }
    int ans=n;
    if(k&1)
        for(int u=1;u<=n;u++)
            for(int i=head[u];i;i=edge[i].nxt){
                int v=edge[i].v;
                if(v<u)
                    continue ;
                dfs(u,v,0);
                dfs(v,u,0);
                int cnt=0;
                for(int j=1;j<=n;j++)
                    if(deep[j]>k/2)
                        cnt++;
                ans=min(ans,cnt);
            }
    else
        for(int u=1;u<=n;u++){
            dfs(u,0,0);
            int cnt=0;
            for(int j=1;j<=n;j++)
                if(deep[j]>k/2)
                    cnt++;
            ans=min(ans,cnt);
        }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int n;
	cin >> n;
	cout << n * n * n << endl;
}

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

	solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll K;
    cin >> K;
    ll cnt=0;
    ll t,i;
    queue<ll> que;
    for(i=1;i<=9;i++){
        que.push(i);    
    }
    while(cnt<K){
        t=que.front();
        que.pop();
        cnt++;
        if(cnt==K){
            cout << t;
            return 0;
        }
        if(t%10!=0){
            que.push(t*10+t%10-1);
        }
        que.push(t*10+t%10);
        if(t%10!=9){
            que.push(t*10+t%10+1);
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int l, r, d;	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i += 1) {
		if (i % d == 0)
			ans++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3620
while True:
    a, op, b = input().split()
    if op == '?':
        break
    a, b = int(a), int(b)
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    else:
        print(a // b)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

template<class Type>
llong lcm(Type x,Type y){return x/__gcd(x,y)*y;}

int main(){
	int n;
	cin>>n;
	
	llong ans=1;
	REP(i,n){
		llong t;
		cin>>t;
		ans=lcm(ans,t);
		//cout<<ans<<endl;//!!!
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define PI 3.141592653589793238
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int t=1;
	//cin>>t;
	while(t--){
		string s;
		cin>>s;
		if((int)s.length()==6&&s[3]==s[2]&&s[4]==s[5])
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>

int main(){
  int n;
  std::cin>>n;
  int ans=0;
  std::vector<int>a(n);
  for(int i=0;i<n;i++){
    std::cin>>a[i];
    if(i%2==0&&a[i]%2==1)ans++;
  }
  std::cout<<ans<<std::endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int is_up=0;
    long long int preA=-1;
    int ans=1;
    for(int n=0; n<N; n++) {
        long long int A;
        cin >> A;
        if(preA==-1) {
            preA=A;
        } else {
            if(is_up==0) {
                if(preA<A) {
                    is_up=1;
                } else if(preA>A) {
                    is_up=-1;
                }
            } else if(is_up>0) {
                if(preA>A) {
                    ans++;
                    is_up=0;
                    preA=-1;
                }
            } else {
                if(preA<A) {
                    ans++;
                    is_up=0;
                    preA=-1;
                }
            }
        }
        preA = A;
    }
    
    cout << ans << endl;


    return 0;
    
}

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

const int mod = 1e9 + 7;
long long int fac[1000001],inv[1000001],cnt[1000001];

long long int C(int n,int k){
	return fac[n]*inv[k]%mod*inv[n-k]%mod;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=1000000;i++){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=mod-mod/i*inv[mod%i]%mod;
	}
	for(int i=2;i<=1000000;i++)
		inv[i]=inv[i-1]*inv[i]%mod;
	int n;
	cin>>n;
	if(n==2)	return cout<<1<<endl,0;
	long long int ans = 0, pre = 0;
	for(int i=2;i<n;i++)
		if(n-i-1<=i-1){
			long long int cur = C(i-1,n-i-1)*fac[i]%mod*fac[n-1-i]%mod;
			ans=(ans+(cur-pre)*i)%mod;
			pre=cur;
		}
	cout<<(ans%mod+mod)%mod<<endl;
}


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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  *  */

signed main() {
  int n, k;
  cin >> n >> k;

  V<int> a(n);
  rep(i, 0, n) cin >> a[i];

  int ans = 1LL<<60;
  rep(mask, 0, 1<<n){
    if(__builtin_popcount(mask) < k) continue;
    int cost = 0, h = -1;
    rep(i, 0, n){
      if(mask>>i & 1){
        cost += max(0LL, h+1-a[i]);
        h++;
      }
      chmax(h, a[i]);
    }

    chmin(ans, cost);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256