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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int MOD = 1'000'000'000 + 7;
const int INF = 1'000'000'000 + 5;

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

	int n; std::cin >> n;
	string s; std::cin >> s;
	if (n & 1) {
		std::cout << "No" << "\n";
		return 0;
	}
	bool ok = true;
	rep(i, n/2) {
		if (s[i] != s[i+n/2])
			ok = false;
	}
	if (ok)
		std::cout << "Yes" << "\n";
	else
		std::cout << "No" << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const double PI  = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
const int mod=1e9+7;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); }
inline LL read(){LL x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}return x*f;}
inline LL qpow(LL x,LL k=mod-2,LL m=mod){LL res=1;while(k){if(k&1) res=res*x%m;x=x*x%m;k>>=1;}return res;}
/*=================================================================================================================*/
LL f[700][2010];

int main(){
    // int S;cin>>S;
    // f[0][0]=1;
    // for(int i=1;i<=S/3;i++)
    //     for(int j=S;j>=0;j--)
    //         for(int k=j;k>=3;k--)
    //             f[i][j]=(f[i][j]+f[i-1][j-k])%mod;
                
    // LL ans=0;
    // for(int i=1;i<=S/3;i++) ans=(ans+f[i][S])%mod;
    // cout<<ans<<endl;

    int S;cin>>S;
    LL ans=0;
    f[0][0]=1;
    for(int i=0;i<=S;i++) f[0][i]=1;
    for(int i=1;i<=S/3;i++){
        for(int j=S;j>=3;j--)
            f[i][j]=(f[i][j]+f[i-1][j-3])%mod;
        ans=(ans+f[i][S])%mod;
        for(int j=1;j<=S;j++) f[i][j]=(f[i][j-1]+f[i][j])%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14080
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;


class A
{
    static int[] F=new int[45];
    public static void Main() {
        int n = int.Parse(System.Console.ReadLine());
        F[0] = 1;
        F[1] = 1;
        Console.WriteLine(fibonacchi(n));
    }
    static int fibonacchi(int n) {
        if (n == 0||n==1) {
            return F[n];
        }
        if (F[n] != 0) {
            return F[n];
        }
        F[n] = fibonacchi(n - 1) + fibonacchi(n - 2);
        return F[n];
    }
}


Measured memory_bytes: 15968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> memo(n, 0);
    int num = 0;
    for(int i = 1; i < n; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            num++;
        }
        memo[i] = num;
    }
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << memo[r-1] - memo[l-1] << endl;
    }


    return 0;
}


Measured memory_bytes: 1408
N,W = map(int,input().split())

items = [tuple(map(int,input().split())) for i in range(N)]

from collections import defaultdict
dp = defaultdict(int) # w -> v
dp[0] = 0

for w,v in items:
  for tw,tv in list(dp.items()):
    if tw+w <= W:
      dp[tw+w] = max(tv+v, dp[tw+w])

print(max(dp.values()))

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
int dp[100005];
int solve(int a[],int k1,int j){
//base case
  if(j==0)
    return 0;
  
  if(dp[j]!=-1){
    return dp[j]; 
  }
  int ans=INT_MAX;
  for(int k=1;k<=k1;k++){
    if(j-k>=0)
    ans=min(ans,abs(a[j]-a[j-k])+solve(a,k1,j-k));
  }
  return dp[j]=ans;
    
 }
  
int main(){
   memset(dp, -1, sizeof(dp)); 
  int n,k1;
  cin>>n>>k1;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
 
  cout<<solve(a,k1,n-1);
 
  return 0;
  
}

Measured memory_bytes: 13664
def f(n):
    if n % 2 == 0:
        return n / 2
    else:
        return 3 * n + 1


s = int(input())

a = []

for i in range(1, 1000000):
    if i == 1:
        a.append(s)
    else:
        ai = f(a[-1])
        if ai in a:
            print(i)
            break
        else:
            a.append(ai)


Measured memory_bytes: 2940
import numpy as np
N,Q = map(int,input().split())
S = np.array([b' '] + list(input()), dtype='S1')
A = (S == b'A')
C = (S == b'C')
AC = (A[:-1] & C[1:])
AC_cum = list(AC.cumsum())

for _ in range(Q):
  L,R = map(int,input().split())
  print(AC_cum[R-1] - AC_cum[L-1])


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b && a == c) {
        cout << "No" << endl;
    } else if (a == b || a == c || b == c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
(n,m),a,*q=[map(int,t.split())for t in open(0)]
t=[-1]*n
def r(x):
 while-1<t[x]:x=t[x]
 return x
def u(x):
 x,y=map(r,x)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
[*map(u,q)]
i=c=0
k,*b=n+~m<<1,
*d,=eval('[],'*n)
for v in a:d[r(i)]+=v,;i+=1
print(k<1and'0'or(k>n)*'Impossible'or exec('for p in d:x,*y=sorted(p)+[0];c+=x;b+=y[:-1];k-=p>[]')or c+sum(sorted(b)[:k]))

Measured memory_bytes: 138788
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 
		int n = sc.nextInt();
		boolean flg = true;
		String[] s = new String[n];
		for(int i = 0;i < n;i++) {
			String S = sc.next();
			if(Arrays.asList(s).contains(S)) flg = false;
			s[i] = S;
		}
		for(int i = 1;i < n;i++) {
			if(!(s[i-1].substring(s[i-1].length()-1).equals(s[i].substring(0,1)))) flg = false;
		}
		System.out.println(flg ? "Yes" : "No");
        sc.close();
	}
}

Measured memory_bytes: 23252
#include <queue>
#include <map>
#include <cstdio>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	vector<int>start(n),end1(n),end2(n);
	for(int i=0;i<n;i++)scanf("%d",&start[i]);
	{
		vector<int>p(m);
		for(int i=0;i<m;i++)scanf("%d",&p[i]);
		for(int i=0,c=0,x=0;i<m;i++,x^=1)for(int j=0;j<p[i];j++,c++)end1[c]=x;
		for(int i=0,c=0,x=1;i<m;i++,x^=1)for(int j=0;j<p[i];j++,c++)end2[c]=x;
	}
	map<vector<int>,int>depth;
	queue<vector<int> >q;
	depth[start]=1,depth[end1]=depth[end2]=-1;
	q.push(start),q.push(end1),q.push(end2);
	for(;!q.empty();){
		vector<int>cur=q.front();q.pop();
		int d=depth[cur];
		for(int i=0;i<n-1;i++)if(cur[i]!=cur[i+1]){
			swap(cur[i],cur[i+1]);
			map<vector<int>,int>::iterator it=depth.find(cur);
			if(it==depth.end()){
				depth[cur]=d+(d>0?1:-1);
				q.push(cur);
			}else if(it->second*d<0){
				d-=it->second;
				if(d<0)d=-d;
				printf("%d\n",d-1);
				return 0;
			}
			swap(cur[i],cur[i+1]);
		}
	}
	puts("0");
}

Measured memory_bytes: 2648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
const int N = 2e6 + 5 ;

int gcd( int a ,int  b ){
	//cout << a <<" " << b << endl ;
	
	if( b == 0 )
		return  b - a ; 
	if(a > b ) swap(a , b) ;
	
	return 2*a*(b/a) + gcd(a , b%a ) ; 
}
signed main(){
	int n , x ;
	cin >> n >> x ;
	cout << n + gcd( n-x , x) ;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <bitset>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define MOD 10007

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

ll dp[1005][8];

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

	string s;
	cin >> s;

	map<char, int> id;
	id['J'] = 2; id['O'] = 1, id['I'] = 0;

	memset(dp, 0, sizeof(dp));
	dp[0][1 << 2] = 1;

	REP(i, 1, n + 1) {
		int d = id[ s[i-1] ];
		rep(j, 1 << 3) {
			if(!(j & (1 << d))) continue;
			rep(k, 1 << 3) {
				if(j & k) { 
					dp[i][j] += dp[i-1][k];
					dp[i][j] %= MOD;
				}
			}
		}
	}

	ll ans = 0;
	rep(i, 1 << 3) {
		ans += dp[n][i];
	}
	
	cout << ans % MOD << endl;


	return 0;
}

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

int main() {
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 3584
#include<stdio.h>
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100

void dijkstra(void);
int n,M[MAX][MAX];

  int main()
{
  int i,j,k,u,v,a;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
        {
          M[i][j]=INFTY;
        }
    }
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&k);
      for(j=0;j<k;j++)
        {
          scanf("%d%d",&v,&a);
          M[u][v]=a;
        }
    }
  dijkstra();
  return 0;
}

void dijkstra(void)
{
  int i,j,u,min,d[100],color[100];

  for(i=0;i<n;i++)
    {
      d[i]=INFTY;
      color[i]=WHITE;
    }
  d[0]=0;
  color[0]=GRAY;
  while(1)
    {
      min=INFTY;
      u=-1;
      for(i=0;i<n;i++)
        {
          if(min>d[i] && color[i]!=BLACK)
            {
              u=i;
              min=d[i];
            }
        }
      if(u==-1)break;
      color[u]=BLACK;
      for(j=0;j<n;j++)
        {
          if(color[j]!=BLACK && M[u][j]!=INFTY)
            {
              if(d[j]>d[u]+M[u][j])
                {
                  d[j]=d[u]+M[u][j];
                  color[j]=GRAY;
                }
            }
        }
    }
  for(i=0;i<n;i++)
    {
      printf("%d",i);
      printf(" ");
      d[i]=(d[i]==INFTY) ? -1 : d[i];
      printf("%d\n",d[i]);
    }
}




Measured memory_bytes: 2104
import java.io.*;
import java.util.*;

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
    
    public FastReader() 
    { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
    
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
    
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
    
    String nextLine() 
    { 
          String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 

class Solution
{
    void solve()
    {
        FastReader sc = new FastReader();

        int a = sc.nextInt();
        String s = sc.nextLine();

        if(a >= 3200)
            System.out.println(s);
        else
            System.out.println("red");
    }
}
  
public class Main 
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

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

int main(){
    int N, M, i, j, ans, L, R;
    scanf("%d %d", &N, &M);
    int num[N+1]; // 数字と配列要素番号を合わせる
    num[0] = 1;
    for(i=1; i<=N; i++)num[i] = 0;
    for(i=0; i<M; i++){
        getchar(); // \n読み捨て
        scanf("%d %d", &L, &R);
        for(j=L-1; (0 <= j && num[j] == 0); j--)num[j] = 1;
        for(j=R+1; (j < N+1 && num[j] == 0); j++)num[j] = 1;
    }
    ans = 0;
    for(i=0; i<N+1; i++){
        //printf("%d\n", num[i]);
        if(num[i] == 0)ans++;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 512
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  int ans=0;
  cin >> s >> t;
  for(int i=0; i<s.size(); i++) {
    if(s[i]!=t[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3752
a,b,c=[int(i) for i in input().split()]

min = a
max = c

if min-b>0:
    min = b
if (min-c)>0:
    min = c

if max-a<=0:
    max=a
if max-b<=0:
    max=b


if (a!=min and a!=max):
    mid = a

elif b!=min and b!=max:
    mid = b

elif c!=min and c!=max:
    mid = c
else:
    mid = min
print(min, mid, max)


Measured memory_bytes: 5604
import sys

N = int(input())
D = list(map(int,input().split()))

dic = {}
for i in range(N):

    if D[i] not in dic:
        dic[D[i]] = 1
    else:
        dic[D[i]] += 1

M = int(input())
T = list(map(int,input().split()))

for i in T:

    if i not in dic:
        print ("NO")
        sys.exit()

    elif dic[i] == 0:
        print ("NO")
        sys.exit()

    else:
        dic[i] -= 1

print ("YES")


Measured memory_bytes: 125776
from collections import Counter

n = int(input())
s = input()
c = Counter(s)
d = {}

for k, v in c.items():
    d[k] = v

key = set(c.keys())
for i in range(n-1):    
    s = input()
    c = Counter(s)
    key = key.intersection(set(c.keys()))
    for k in key:
        d[k] = min(d[k], c[k])

ans = ''
for k, v in sorted(d.items(), key=lambda x: x[0]):
	if k in key:
	    ans += k*v
    
print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#define INF 100
using namespace std;

int n;
int h[17],w[17];
int dp[1<<16];
int fie[4][4];

int bfs(int s){
	queue<int> que;
	for(int i=0;i<1<<16;i++){
		dp[i]=INF;
	}
	que.push(s);
	dp[s]=0;
	while(que.size()){
		int bit=que.front();
		que.pop();
		for(int i=0;i<n;i++){
			for(int j=-3;j<4;j++){
				for(int k=-3;k<4;k++){
					for(int l=0;l<3;l++){
						int nbit=bit;
						for(int x=max(j,0);x<min(4,j+w[i]);x++){
							for(int y=max(k,0);y<min(4,k+h[i]);y++){
								int nshift=y*4+x;
								if((nbit>>nshift & 1) && fie[x][y]!=l)nbit-=(1<<nshift);
								if(!(nbit>>nshift & 1) && fie[x][y]==l)nbit+=(1<<nshift);
							}
						}
						if(dp[nbit]==INF){
							dp[nbit]=dp[bit]+1;
							que.push(nbit);
						}
					}
				}
			}
		}
	}
	return dp[(1<<16)-1];
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d %d",&h[i],&w[i]);
	}
	for(int i=0;i<4;i++){
		string str;
		cin >> str;
		for(int j=0;j<4;j++){
			if(str[j]=='R')fie[j][i]=0;
			if(str[j]=='G')fie[j][i]=1;
			if(str[j]=='B')fie[j][i]=2;
		}
	}
	printf("%d\n",bfs(0));
	return 0;
}

Measured memory_bytes: 1640
#include <stdio.h>

int main(){
  int x, y, z;
  scanf("%d%d", &x, &y);
  while(z!=0){
    z = x % y;
    if(z==0){
      printf("%d\n", y);
      break;
    }
    x = y;
    y = z;
  }
  return 0;
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

const int N = 1e6 + 100;

int n, a[N];
vector<int> g[20];

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

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

	for (int i = n - 1; i >= 0; --i) {
		int mn = n;
		for (int j = 0; j < 20; ++j) {
			if ((a[i] >> j) & 1) {
				if (g[j].size() > 1) {
					g[j].erase(g[j].begin());
				}
				g[j].push_back(i);
			}
			if (g[j].size() == 2) {
				mn = min(mn, g[j][0]);
			}
		}
		ans += mn - i;
	}
	cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int ans=INT_MAX;
const int N=100010;
int n,k,a[N];
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (int be=1; be+k-1<=n; ++be){
		ans=min(ans,a[be+k-1]-a[be]+min(abs(a[be]),abs(a[be+k-1]))); 
	}
	cout<<ans;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var a = Input();
            var s = Console.ReadLine();
            var ans = "red";
            if (a >= 3200) ans = s;

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 13140
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io

	ll arr[32]={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};
	ll k;
	cin>>k;
	k--;
	cout<<arr[k];
	
}

Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,m,k = I()

for i in range(n+1):
    for j in range(m+1):
        if i*(m-j)+j*(n-i) == k:
            print("Yes")
            exit()

print("No")


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

s = len(S)
t = len(T)
"""
if T in S:
     print(0)
     """
#else:
m = s - t + 1
bag = []
for i in range(m):
     #bag = []
     num2 = t
     for j in range(t):
          #print(S[i+j])
          #print(T[j])
          if S[i+j] == T[j]:
               num2 -= 1
     #print(num2)
     bag.append(num2)

list.sort(bag)
print(bag[0])

Measured memory_bytes: 8948
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	String s=sc.next();
    StringBuffer sb=new StringBuffer(s);
    sb.reverse();
    s=sb.toString();
    String t=s.replaceFirst("LAVITSEF","");
    StringBuffer sb2=new StringBuffer(t);
    sb2.reverse();
    
    System.out.print(sb2);
  }
}


Measured memory_bytes: 21972
S = input()
ACGT = ['A', 'C', 'G', 'T']
length = 0
max_length = 0

for s in range(len(S)):
    #    print(S[s])
    match = 0
    for acgt in ACGT:
        if S[s] == acgt:
            length += 1
            if max_length < length:
                max_length = length
            match = 1
#            print(acgt)
    if match == 0:
        length = 0

print(max_length)

Measured memory_bytes: 3060
//============================================================================
// Name        : b
// Date        : Mon Apr  8 20:56:15 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//============================================================================
#include "bits/stdc++.h"
using namespace std;

#define x first
#define y second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mst(x, y) memset(x, y, sizeof(x))
#define pvar(x) cout << #x << ": "
#define output(v) cout << (v) << '\n'
#define fori(i, a, b) for (int i = a; i < b; ++i)
#define jam(x, n) cout << "Case #" << x << ": " << n << "\n"
#define prt(x, a, n) { cout << x[a]; if (a < n - 1) cout << " "; }
#define par(x, s, n, v) if(v) pvar(x); fori(y, s, n) prt(x, y, n) cout << "\n"
template<class T> inline void amin(T &x, const T &y) { if (y < x) x = y; }
template<class T> inline void amax(T &x, const T &y) { if (x < y) x = y; }

#ifndef _has_trace
#define trace(...)
#define dbstream ostream
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

vi a;
int ret;
void rec(int p, int path, vector<bool>& visit) {
  // trace(p, path);
  if (p == sz(a) - 1) {
    int cnt = 0;
    for (int i = 0; i < sz(a); ++i) {
      if (!visit[i]) {
        path += a[i];
        ++cnt;
      }
    }
    assert(cnt == 1);
    amin(ret, path);
    return;
  }
  for (int i = 0; i < sz(a); ++i) {
    if (!visit[i]) {
      visit[i] = 1;
      int tmp = a[i];
      for (int j = a[i]; j % 10 != 0; ++j) {
        ++tmp;
      }
      rec(p + 1, path + tmp, visit);
      visit[i] = 0;
    }
  }
}

void solve() {
  int n = 5;
  a = vi(n);
  for (int i = 0; i < 5; ++i) {
    cin >> a[i];
  }
  ret = (int) 1e9 + 7;
  vector<bool> visit(n);
  rec(0, 0, visit);
  output(ret);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int x,y,r;
  
  scanf("%d%d",&x,&y);
  
  if(x<y){
    int a;
    a=x;
    x=y;
    y=a;
  }
 
  r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  
  printf("%d\n",y);

  return 0;
}



Measured memory_bytes: 2144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            var rgx = new Regex(@"A.*Z");
            var match = rgx.Match(S);

            Console.WriteLine(match.Length);
        }
    }
}


Measured memory_bytes: 16856
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int x,y,r,w,h,cnt=0;
  cin>>w>>h>>x>>y>>r;
  if(x-r>=0) ++cnt;
  if(y-r>=0) ++cnt;
  if(x+r<=w) ++cnt;
  if(y+r<=h) ++cnt;
  if(cnt==4) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 3112
n,_,_=map(int,input().split())
a,b=list(range(n)),0
for i in map(int,input().split()):
    b-= i if i&1 else -i
    b%=n
    del a[b]
    n-=1
for i in map(int,input().split()):
    print(int(i in a))

Measured memory_bytes: 29500
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <stack>

using ll = long long;

ll gcd_euclid(ll u, ll v) {
    ll r;
    while (0 != v) {
        r = u % v; u = v; v = r;
    }
    return u;
}

ll getLCM(ll u, ll v) {
    ll gcd = gcd_euclid(u, v);
    return u / gcd * v;
}

int main() {
    int N;
    std::cin >> N;
    std::vector<ll> T(N);
    for (int i = 0; i < N; i++) {
        std::cin >> T[i];
    }
    ll lcm = T[0];
    for (int i = 1; i < N; i++) {
        lcm = getLCM(lcm, T[i]);
    }

    std::cout << lcm << std::endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

     static Scanner scanner;

     public static void main(String[] args) {
         scanner = new Scanner(System.in);

         int N=gi();
         int[] p=new int[N];

         boolean bf=false;
         long ans=0;
         for (int i=0; i<N;i++) {
            p[i]=gi();
            if (p[i]==i+1) {
            	if(!bf) {
            		ans++;
            		bf=true;
            	} else {
            		bf=false;
            	}
            } else {
            	bf=false;
            }
         }
         System.out.println(ans);
     }

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 59352
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    for (int i=0; i<s.length()-1; i++)
        if (s.substr(i,2) == "AC") return cout << "Yes" << endl, 0;

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <assert.h>
using namespace std;
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lc(p) p+p+1
#define rc(p) p+p+2
#define md(s,e) (s+e)/2

int n,k;
int A[300005];
int Max[300005*4];
int H[300005*4];
int mo = 998244353;
int po[300005];
int D[11][300005];

void mod( int p, int s, int e, int l, int r, int v ){
	if ( s > r || e < l ) return;
	if ( l <= s && e <= r ){
		Max[p] = v;
		H[p] = D[v][e-s+1];
		return;
	}
	int m = md(s,e);
	if ( Max[p] != 0 ){
		Max[lc(p)] = Max[p];
		Max[rc(p)] = Max[p];
		H[lc(p)] = D[Max[p]][m-s+1];
		H[rc(p)] = D[Max[p]][e-m];
		Max[p] = 0;
	}
	mod(lc(p),s,m,l,r,v);
	mod(rc(p),m+1,e,l,r,v);
	H[p] = (H[lc(p)] * 1LL * po[e-m]) % mo;
	H[p] = ( H[p] + H[rc(p)]) % mo;
}

int main(){

	po[0] = 1;
	for ( int i = 1; i <= 200000; i++ ){
		po[i] = (po[i-1] * 1LL * 10 ) % mo;
	}
	scanf("%d%d",&n,&k);
	Max[0] = 1;

	for ( int i = 1; i <= 9; i++ ){
		D[i][0] = 0;
		for ( int j = 1; j <= n; j++ ){
			D[i][j] = ( D[i][j-1] * 1LL * 10 + i ) % mo;
		}
	}
	H[0] = D[1][n];
	for ( int i = 0; i < k; i++ ){
		int l, r, d;
		scanf("%d%d%d",&l,&r,&d);
		mod(0,1,n,l,r,d);
		printf("%d\n",H[0]);
	}
	return 0;
}

Measured memory_bytes: 15804
D = 3

def main(argv)
  s = gets.chomp
  t = gets.chomp
  
  c = 0
  D.times do |i|
    c += 1 if s[i] == t[i]
  end
  puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {

    long long int a, b;
    cin >> a >> b;
    if ( a - b < 0 ) swap( a, b );

    if ( ( a - b ) % 2 == 0 ) {
        cout << ( a + b ) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long cc;
typedef pair <int, int> pii;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
const int N = 102;
int a[N], b[N], f[N], n;
int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        a[i] = a[i - 1] + x;
    }
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = n; i >= 1; i--) b[i] += b[i + 1];
    int res = 0;
    for (int i = 1; i <= n; i++) res = max(res, a[i] + b[i]);
    cout << res;
    return 0;
}


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

#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
int K;

vvint mul(vvint &a,vvint &b){
    vvint c(N,vint(N,0));
    rep(i,0,N)rep(k,0,N)rep(j,0,N)(c[i][j]+=a[i][k]*b[k][j])%=MOD;
    return c;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N>>K;
    vvint a(N,vint(N)),res(N,vint(N,0));
    rep(i,0,N)rep(j,0,N)cin>>a[i][j];
    rep(i,0,N)res[i][i]=1;//単位行列
    
    while(K){
        if(K&1)res=mul(res,a);
        a=mul(a,a);
        K/=2;
    }
    
    int ans=0;
    rep(i,0,N)rep(j,0,N)(ans+=res[i][j])%=MOD;
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 384
a, b, k = map(int, input().split())
def make_divisor_list(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
      
list_a = make_divisor_list(a) 
list_b = make_divisor_list(b)
a_b = set(list_a) & set(list_b)

print(sorted(list(a_b))[-k])

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline

N = int(input())
upper = 55555
p_flag = [True]*(upper+1)
p_flag[0] = p_flag[1] = False
prime = []

for i in range(2, upper+1):
    if p_flag[i]:
        prime.append(i)
        for j in range(2*i, upper+1, i):
            p_flag[j] = False

ans = []
cnt = 0
for i in prime:
    if i % 5 == 1:
        ans.append(i)
        cnt += 1
    if cnt == N:
        break

print(*ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int N,M;
    cin>>N>>M;
    double sum=0;
    for(int i=1;i<=100000;i++){
        sum += i*((N-M)*100+1900*M)*pow((1-pow(0.5,M)),i-1)*pow(0.5,M);
    }
    cout<<round(sum)<<endl;
}

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

using namespace std;

int main(){

    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);

    ios :: sync_with_stdio(false);
    cin.tie(0);

    string s;

    cin >> s;

    for(auto &ch : s)
        if(ch == '?')
            ch = 'D';
    
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3768
import java.util.Arrays;
import java.util.Scanner;


class Main {
    static Scanner sc = new Scanner(System.in);

    static long[] x = new long[100005];
    static long[] v = new long[100005];
    static long[] s = new long[100005];
    static long n, c;
    static long ans = 0;
    static long sum;
    
    public static void main(String[] args) {
        Arrays.fill(x, 0);
        Arrays.fill(v, 0);
        Arrays.fill(s, 0);
        
        n = sc.nextLong();
        c = sc.nextLong();

        for (int i = 1; i <= n; i++) {
            x[i] = sc.nextLong();
            v[i] = sc.nextLong();
        }
        x[(int)n + 1] = c;

        // origin -> right -> origin -> left
        Arrays.fill(s, Long.MIN_VALUE);

        sum = 0;
        s[0] = 0;
        for (int i = 1; i <= n; i++) {
            sum += v[i];

            s[i] = Math.max(sum - x[i] * 2, s[i - 1]);
        }

        sum = 0;
        for (int i = (int)n + 1; i > 0; i--) {
            sum += v[i];
            ans = Math.max(ans, s[i - 1] + sum - (c - x[i]));
        }

        // origin -> left -> origin -> right
        Arrays.fill(s, Long.MIN_VALUE);

        sum = 0;
        s[0] = 0;
        for (int i = 1; i <= n; i++) {
            sum += v[i];
            s[i] = Math.max(sum - x[i], s[i - 1]);
        }

        sum = 0;
        for (int i = (int)n + 1; i > 0; i--) {
            sum += v[i];
            ans = Math.max(ans, s[i - 1] + sum - (2 * c - 2 * x[i]));
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 87428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;

	vector<vs> s(n,vs(0));
	s[0] = { "" };

	if (n == 1)cout << "a" << endl;
	else {
		s[1] = { "a" };

		rep(i, n - 1) {
			int k = i + 2;

			rep(j, s[k - 1].size()) {
				string ne = s[k - 1][j];
				int last = 0;

				rep(l, ne.size())last = max(last, ne[l] - 'a');

				rep(m, last + 2) {
					string nes = ne;
					char sd = 'a' + m;
					nes += sd;
					if (k == n)cout << nes << endl;
					else s[k].push_back(nes);
				}
			}
		}
	}
}

Measured memory_bytes: 3324
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;

int n;
ll dfs(int cur, vector<vector<int>> &a) {
	if (cur == n) return 1;
	int win = 0;
	int lose = 0;
	int any = 0;
	for (int i = 0; i < n; i++) {
		if (a[cur][i] == 1) win++;
		else if (a[cur][i] == 0) lose++;
		else if(a[cur][i] == -1) any++;
	}
	if (win > n / 2 or lose > n / 2) return 0;
	ll res = 0;
	for (int S = 0; S < (1 << any); S++) {
		queue<int> q;
		int nw = win;
		int nl = lose;
		for (int i = 0; i < any; i++) {
			if (S >> i & 1) q.push(1), nw++;
			else q.push(0), nl++;
		}
		if (nw > n / 2 or nl > n / 2) continue;
		vector<int> tmp;
		for (int i = 0; i < n; i++) {
			if (a[cur][i] == -1) {
				a[cur][i] = q.front();
				a[i][cur] = a[cur][i] ^ 1;
				q.pop();
				tmp.push_back(i);
			}
		}
		res += dfs(cur + 1, a);
		for (auto e : tmp) {
			a[cur][e] = -1;
			a[e][cur] = -1;
		}
	}
	return res;
}

void suzuken() {
	scanf("%d", &n); if (n == 0) exit(0);
	vector<vector<int>> a(n, vector<int>(n, -1));
	int m; scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		int x, y; scanf("%d %d", &x, &y);
		x--; y--;
		a[x][y] = 1;
		a[y][x] = 0;
	}
	for (int i = 0; i < n; i++) a[i][i] = -2;
	ll res = 0;
	res += dfs(0, a);
	cout << res << "\n";
}
int main() {
	int kkt = 89;
	while (kkt) {
		suzuken();
	}
}


Measured memory_bytes: 3212
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

/*
    nCk, nPk, 階乗をmodをとりつつ求めるライブラリ
*/
template <int MAX_N = 100000, long long MOD = 1000000007LL>
class Combination {
    array<long long, MAX_N + 1> _fact;
    array<long long, MAX_N + 1> _fact_inv;

public:
    // xの逆元
    // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
    long long inv(long long a) const {
        long long b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);

            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0)
            u += MOD;
        return u;
    }
    // n!
    long long fact(long long n) const {
        return _fact[n];
    }
    // 1 / n!
    long long fact_inv(long long n) const {
        return _fact_inv[n];
    }
    // nPk
    long long perm(long long n, long long k) const {
        return fact(n) * fact_inv(n - k) % MOD;
    }
    // nCk
    long long comb(long long n, long long k) const {
        return perm(n, k) * fact_inv(k) % MOD;
    }

    Combination() : _fact{}, _fact_inv{} {
        _fact[0] = _fact[1] = 1LL;
        for (int i = 2; i <= MAX_N; ++i) {
            _fact[i] = _fact[i - 1] * i % MOD;
        }
        _fact_inv[MAX_N] = inv(_fact[MAX_N]);
        for (int i = MAX_N - 1; i >= 0; --i) {
            _fact_inv[i] = _fact_inv[i + 1] * (i + 1) % MOD;
        }
    }
};

constexpr ll mod = 1000000007LL;
Combination<1000000, mod> cm;

int main() {
    ll x, y; cin >> x >> y;
    ll ans = 0;
    for (ll a = 0; a <= x; ++a) {
        if ((x - a) % 2 == 1 || y != (x - a) / 2 + 2 * a) continue;
        ans += cm.comb(a + (x - a) / 2, a);
        ans %= mod;
    }

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

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

int main(){
    int n, k;
    while(cin >> n >> k && n > 0 || k > 0){
        vector<int> v(k);
        for(int i = 0; i < k; i++){
            cin >> v[i];
        }
        sort(v.begin(), v.end());
        int tmp = 0, cnt = 1, ans = 0;
        bool f = false, g = false;
        if(v[0] == 0){
            tmp++;
            f = true;
            g = true;
        }
        int right = 0;
        for(; tmp < k; tmp++){
            if(v[tmp + 1] == v[tmp] + 1){
                cnt++;
            }
            else if(v[tmp + 1] == v[tmp] + 2 && f == true){
                right = tmp;
                cnt += 2;
                //tmp++;
                f = false;
            }
            else{
                //cout << cnt << endl;
                ans = max(ans, cnt);
                if(right != 0) tmp = right;
                if(g == true) f = true;
                right = 0;
                cnt = 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int D;
  cin>>D;
  VL C(26);
  rep(i,26) cin>>C[i];
  VVL S(D,VL(26));
  rep(i,D) rep(j,26) cin>>S[i][j];
  VL T(D);
  rep(i,D){
    ll X=0;
    rep(j,26) if(S[i][X]<S[i][j]) X=j;
    T[i]=X+1;
  }
  ll ans=0;
  VL L(26);
  rep(i,D){
    ll tmp=0;
    L[T[i]-1]=i+1;
    rep(j,26) tmp+=C[j]*(i+1-L[j]);
    ans+=S[i][T[i]-1]-tmp;
  }
  
  vector< set<ll> > X(26);
  rep(i,D) X[T[i]-1].insert(i+1);
  rep(i,26) X[i].insert(0);
  rep(i,26) X[i].insert(D+1);
  int M=1000000;
  VI d(M),q(M);
  rep(i,M) d[i]=rand()%D+1;
  rep(i,M) q[i]=rand()%26+1;
  int cnt=0;
  VI A(0),B(0),E(0);
  ll ans2=ans;
  rep(i,M){
    int prv=T[d[i]-1];
    int nxt=q[i];
    auto itr=ub(all(X[prv-1]),d[i]);
    ll tmp=*itr;
    itr--;
    itr--;
    T[d[i]-1]=q[i];
    auto itr2=ub(all(X[nxt-1]),d[i]);
    ll tmp2=*itr2;
    itr2--;
    ans=ans-S[d[i]-1][prv-1]-C[prv-1]*(d[i]-*itr)*(tmp-d[i]);
    X[prv-1].erase(d[i]);
    ans=ans+S[d[i]-1][nxt-1]+C[nxt-1]*(d[i]-*itr2)*(tmp2-d[i]);
    X[nxt-1].insert(d[i]);
    if(ans>ans2){
      ans2=ans;
      cnt=0;
      A.clear();
      B.clear();
      E.clear();
    }else if(cnt<5){
      cnt++;
      A.pb(prv);
      B.pb(nxt);
      E.pb(d[i]);
    }else{
      ans=ans2;
      rep(j,5){
        T[E[4-j]-1]=A[4-j];
        X[B[4-j]-1].erase(E[4-j]);
        X[A[4-j]-1].insert(E[4-j]);
      }
    }
  }
  rep(i,D) cout<<T[i]<<endl;
}

Measured memory_bytes: 11192
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = long long;

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

struct edge {int from, to, cost; };

void solve(){
    ll n, m;
    cin >> n >> m;
    if(n > 2 && m > 2){
        cout << (n-2)*(m-2) << endl;
    }else if(n == 2 || m == 2){
        cout << 0 << endl;
    }else if(n == 1 || m == 1){
        if(n > 1 || m > 1){
            cout << max(n, m)-2 << endl;
        }else{
            cout << 1 << endl;
        }
    }
}

int main(){
    solve();
    return 0;
}


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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    char s[max], t[max], tmp[max];
    int nums, numt;
    int cnt=0;
    int min=INT_MAX;
    
    scanf("%s%s", s, t);
    
    nums=strlen(s);
    numt=strlen(t);
    
    for (int i=0; i<nums-numt+1; i++) {
        cnt=0;
        for (int k=i; k-i<numt; k++) {
            tmp[k-i]=s[k];
        }
        for (int j=0; j<numt; j++) {
            if (tmp[j]!=t[j]) {
                cnt++;
            }
        }
        if (cnt<min) {
            min=cnt;
        }
    }
    
    printf("%d", min);
    
    return 0;
}


Measured memory_bytes: 1744
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define Size 5500
#define intmax 0x7fffffff
using namespace std;
bool a[Size],b[Size];
int A[Size],B[Size],at,bt;
il void get(char&);
int main(){
	int n;char c;scanf("%d",&n);
	for(int i(1);i<=n;++i)get(c),a[i]=c^48;
	for(int i(1);i<=n;++i)get(c),b[i]=c^48;
	for(int i(2);i<=n;++i){
		if(a[i]!=a[i-1])A[++at]=i-1;
		if(b[i]!=b[i-1])B[++bt]=i-1;
	}A[at+1]=B[bt+1]=n;
	int ans(intmax),beg(a[A[1]]==b[B[1]]?1:0);
	for(int i(beg-2*n),j,k,sum;i<=(beg+2*n);i+=2){sum=0;
		for(j=(i<=0?1:2-i),k=(i<=0?i:1);j<=at||k<=bt;++j,++k){
			int u(j),v(k);
			if(u<0)u=0;if(u>at)u=at+1;
			if(v<0)v=0;if(v>bt)v=bt+1;
			sum+=abs(A[u]-B[v]);
		}
		ans=min(ans,sum);
	}printf("%d",ans);
	return 0;
}
il void get(char &c){
	while(c=getchar(),c==' '||c=='\n'||c=='\r');
}


Measured memory_bytes: 256
// for(auto it:m)
//     {
//         cout<<it.second;
//     }
// }
 
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
 
 
int main()
{
      int n,ctr=0;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      for(int i=0;i<n;i++)
      {
          int k;
          for(int j=i+1;j<n;j++)
          {
              for(k=j+1;k<n;k++)
              {
                  if(a[i]+a[j]>a[k])
                  {
                      ctr++;
                  }
              }
              
          }
      }
      cout<<ctr;



}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+100;

int n,d=0,mx[N];
vector<int>mp[N];

void dfs(int x,int fa)
{
	int mx1=0,mx2=0;
	for(int v,i=0;i<mp[x].size();i++)
	{
		v=mp[x][i];
		if(v==fa)continue;
		dfs(v,x),mx2=max(mx2,mx[v]);
		if(mx2>mx1)swap(mx1,mx2);
	}
	mx[x]=1+mx1;
	d=max(d,mx1+mx2+1);
}

int main()
{
    scanf("%d",&n);
    for(int i=1,u,v;i<n;i++)
    {
    	scanf("%d%d",&u,&v);
    	mp[u].push_back(v);
    	mp[v].push_back(u);
    }
    if(n==1)puts("First");
    if(n==2)puts("Second");
    if(n>=3)
    {
	    dfs(1,0),d-=2;
    	if(d%3==0)puts("Second");
    	else puts("First");
    }
}

Measured memory_bytes: 26880
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, K) = nextIntList()
    val A = nextLongList()
    val ans = A.toCountMap().toList().sortedBy { it.second }.dropLast(K).map { it.second }.sum()
    println(ans)
}

fun <T> List<T>.toCountMap(): Map<T, Long> {
    return this.groupBy { it }.mapValues { it.value.size.toLong() }
}

Measured memory_bytes: 111944
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
ans=array(N,0)
A=get_i
A.each do|a|
    a-=1
    ans[a]+=1
end
puts ans.join("\n")

Measured memory_bytes: 36128