akhauriyash/Code-Regression huggingface dataset:
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=2e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int dir[4][2] = {0,1,-1,0,1,0,0,-1};
int n,m;
ll ans;

char s[405][405];
int p[MAX],cnt[MAX],sum[MAX];

int Hash(int x,int y)
{
    return x*400+y;
}
int Find(int x)
{
    return x==p[x]?x:p[x]=Find(p[x]);
}
void Merge(int x,int y)
{
    int fx=Find(x);
    int fy=Find(y);
    if(fx!=fy)
    {
        p[fx]= fy;
        cnt[fy]+=cnt[fx];
        sum[fy]+=sum[fx];
    }
}
void Init()
{
    for(int i=0;i<MAX;i++)
    {
        p[i]=i;
        cnt[i]=1;
    }

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]=='#')
                sum[Hash(i,j)]=1;
}
int main()
{

    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);

    Init();

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            for(int k=0;k<4;k++)
            {
                int fx=i+dir[k][0];
                int fy=j+dir[k][1];
                if(fx>=1 && fx<=n && fy>=1 && fy<=m && s[i][j]!=s[fx][fy])
                    Merge(Hash(fx,fy),Hash(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int h=Find(Hash(i,j));
            if(cnt[h]>1)
            {
                ans+=1LL*sum[h]*(cnt[h]-sum[h]);
                cnt[h]=-1;
            }
        }
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include  <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long lint;
#define SZ(x) ((int)(x).size())

int n;
int a[20000];
int rec(int i,int key) {
	if (key==0) {
		return 1;
	}
	if (i >= n)return 0;
	
	//cout << key - a[i] << " ";
	int res = rec(i + 1, key) || rec(i + 1,key-a[i]);

	return res;
}
int main()
{
	int q;
	int m;
	cin >> n;
	rep(i, n) cin >> a[i];
	cin >> q;
	rep(i, q) {
		cin >> m;
		if (rec(0,m)==1) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}



Measured memory_bytes: 3084
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)


AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB.sort(reverse=True)
AB = AB[:K]

ans = []
for ab in AB:
    for c in C:
        ans.append(ab + c)
        
ans.sort(reverse=True)
print(*ans[:K], sep='\n')


Measured memory_bytes: 145644
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (y == 0)return x;
	int res = gcd(y, x%y);
	return res;
}
int main() {
	int n, x;
	cin >> n >> x;
	vector<int> a(n), num(n+1);
	rep(i, 0, n) {
		cin >> a[i];
		num[i] = abs(a[i] - x);
	}
	rep(i, 1, n) num[i]=gcd(num[i], num[i-1]);
	cout << num[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	// Code for B - Painting Balls with AtCoDeer
	var N, K int
	fmt.Scanf("%d %d", &N, &K)

	var ans int = K
	for i := 1; i < N; i++ {
		ans *= K - 1
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1836
from collections import deque

S = input()
l = len(S)

a = list(map(list,['dream','dreamer','erase','eraser']))
q = deque()
q.append(["",0])

while len(q):
    b,i = q.pop()
    if i == l:
        print('YES')
        exit()
    x = 0
    f = True
    for B in b:
        if i+x >= l or S[i+x] != B:
            f = False
        x += 1
    if f:
        for A in a:
            q.append([A,i+x])

print('NO')


Measured memory_bytes: 6952
// This is the start of  template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
void input(){
#ifndef ONLINE_JUDGE 
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout); 
#endif
}
#define INF LONG_LONG_MAX
#define mod 1000000007
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
int power(int a,int n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a)%mod,n/2))%mod;
    }
    return power((a*a)%mod,n/2)%mod;
}

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  input();
  int s;
  cin>>s;
  int dp [2001]={};
  dp[0] = 1;
  for(int i = 1;i<=s ;i++)
  {
  	for(int j = 3 ;j<=i ;j++)
  	{
  		dp[i] += dp[i-j];
  		dp[i] %= mod;
  	}
  }
  cout<<dp[s];
}

//

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    double n,x;
    cin >> n ;
    x=floor(n/1.08);
    if(x*1.08>=n && x*1.08 <(n+1)) cout << x << endl;
    else if((x+1)*1.08>=n && (x+1)*1.08<(n+1)) cout << x+1 << endl;
    else cout << ":(\n";
    
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3764
def main(length_num,num_list):
    count_num = 0
    min_num = int(num_list[0])
    for i in num_list:
        if int(min_num) >= int(i):
            min_num = i
            count_num += 1           
    return count_num
    
if __name__ == "__main__":
    input_length_num = int(input())
    input_num2 = input()
    input_num_list = input_num2.split()
    print(main(input_length_num,input_num_list))

Measured memory_bytes: 17940
#include<stdio.h>
int main(void)
{
	double chance;
	double number;
	scanf("%lf",&number);
	
	int count = 0 ;
	for( int i = 1 ; i <= number ; i++ )
	{
		if( i%2==1 )
		{
			count++;
		}
	}	
	
	chance=count/number;
	printf("%.10f", chance);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B, C, K; cin >> A >> B >> C >> K;
    if (K <= A) {
        cout << K << endl;
        return 0;
    } else {
        K -= A;
        K -= B;
        if (K <= 0) {
            cout << A << endl;
            return 0;
        } 
        cout << A - K << endl;
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,d,D,ans=0;
cin >> n >> d;
D = 2*d+1;
ans = (n-1)/D+1;
cout << ans << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
from sys import stdin,stdout

n,m = map(int,stdin.readline().split())
grid = []
for i in range(n):
    row = input()
    grid.append(row)
dp = [ [0 for j in range(m)] for i in range(n) ]
for i in range(m):
    if grid[0][i]=='#':
        break
    dp[0][i] = 1
for i in range(n):
    if grid[i][0]=='#':
        break
    dp[i][0] = 1
for i in range(1,n):
    for j in range(1,m):
        if grid[i][j]=='#':
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]
        dp[i][j] %= 10**9+7
print(dp[n-1][m-1])


Measured memory_bytes: 44628
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}


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

    Int n;
    cin >> n;
    Int a[100002];
    Int b[100002];
    for(Int i=0; i<=n; i++){
        cin >> a[i];
    }
    for(Int i=0; i<n; i++){
        cin >> b[i];
    }
    Int sum = 0;
    for(Int i=0; i<n; i++){
        Int kill = a[i] > b[i] ? b[i] : a[i];
        Int rest = b[i] - a[i];
        sum += kill;
        if(rest > 0){
            kill = a[i+1] > rest ? rest : a[i+1];
            a[i+1] -= kill;
            sum += kill;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
NX = [int(i) for i in input().split()]
L = [int(i) for i in input().split()]
L.insert(0,0)
answer = 0
sum = 0
for i in range(len(L)):
    sum += L[i]
    if(sum > NX[1]):
        break
    else:
        answer += 1
print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  cout << (m1 != m2) << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
a=list(map(int,input().split()))
q=deque()
for i in range(n):
  if i%2==0:
    q.append(a[i])
  else:
    q.appendleft(a[i])
if n%2==1:
  q.reverse()
print(*q)

Measured memory_bytes: 25412
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
#define ll long long
#define fi first
#define se second
#define inf (999999999)
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
string s;
int main() {
	cin >> s;
	string t = s.substr(0, 4);
	string t1 = s.substr(4, 8);
	cout << t << " " << t1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	int m,d,ans=0;
	scanf("%d%d",&m,&d);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=d;j++)
		{
			if(j/10>=2&&j%10>=2&&j/10*(j%10)==i)
				ans++;
		}
	printf("%d",ans);
    return 0;
}

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

#define lli long long int
#define ld long double
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)

////////////////////////////////////////////////////////    By: Umang Srivastava

/*
lli extgcd(lli a, lli b, lli *x , lli *y)
{
	if(a==0)
	{
		*x=0;
		*y=1;
		return b;
	}
	lli x1 , y1;
	lli gcd = extgcd(b%a , a , &x1 , &y1);
	*x=y-(b/a)*x1;
	*y=x1;
	return gcd;
}

lli modinv(lli a, lli m)
{
	lli x,y;
	lli g = extgcd(a,m,&x,&y);
	if(g!=1)
		return -1;
	return (x%m+m)%m;
}

lli moddiv(lli a, lli b, lli m)
{
	a=a%m;
	lli inv = modinv(b,m);
	if(inv!=-1)
		return ((a*inv + m)%m);
	else
		return -1;
}
*/
// lli binpow(lli a, lli b, lli m)
// {
// 	lli res=1;
// 	a=a%m;
// 	while(b>0)
// 	{
// 		if(b & 1)
// 		{
// 			res = (res * a)%m;
// 		}
// 		b=b>>1;
// 		a=(a*a)%m;
// 	}
// 	return res;
// }
/*
lli gcd(lli a, lli b)
{
    // if(b<a)
    // {
    //     lli t=a;
    //     a=b;
    //     b=t;
    // }
    if(a==0)
        return b;
    return gcd(b%a,a);
}
*/
/////////////////////////////////////////////////////////

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli t;
    cin>>t;
    if(t==0)
        cout<<"1\n";
    else if(t==1)
        cout<<"0\n";

}

Measured memory_bytes: 3624
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    private static final PrintStream ps = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n + 1];
        for (int i = 1; i <= n; i++)
            a[i] = sc.nextInt();
        
        DisjointSet ds = new DisjointSet(n+1);
        for (int i = 0; i < m; i++) 
            ds.unite(sc.nextInt(), sc.nextInt());
        for (int i = 1; i <= n; i++) 
            ds.findSet(i);
        
        Map<Integer, ArrayList> map = new HashMap<Integer, ArrayList>();
        for (int i = 1; i <= n; i++) {
            int key = ds.p[i];
            if (!map.containsKey(key)) {
                map.put(key, new ArrayList<Integer>());
            }
            map.get(key).add(i);
        }
        
        int count = 0;
        for (int key: map.keySet()) {
            ArrayList<Integer> al1 = map.get(key);
            ArrayList<Integer> al2 = new ArrayList<Integer>();
            
            for (int alIdx: al1) {
                al2.add(a[alIdx]);
            }
            Collections.sort(al1);
            Collections.sort(al2);
            
            int al2Idx = 0;
            int al1Idx = 0;
            while (al1Idx < al1.size() && al2Idx < al2.size()) {
                int a1 = al1.get(al1Idx);
                int a2 = al2.get(al2Idx);
                if (a1 == a2) {
                    count++;
                    al1Idx++;
                    al2Idx++;
                    
                } else if (a1 > a2) {
                    al2Idx++;
                } else if (a1 < a2) {
                    al1Idx++;
                }
            }
        }
        ps.println(count);
   }
    
    static class DisjointSet {
        public int[] rank;
        public int[] p;
        
        DisjointSet(int size) {
            rank = new int[size];
            p = new int[size];
            for (int i = 0; i < size; i++) makeSet(i);
        }
        
        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }
        
        boolean same(int x, int y) {
            return findSet(x) == findSet(y);
        }
        
        int findSet(int x) {
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
        
        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
    }

}


Measured memory_bytes: 90476
n = int(input())
A = list(map(int, input().split()))

ans = -1
f = True

while (f):
    ans += 1
    for i in range(n):
        if (A[i] == 0 or A[i] % 2 != 0):
            f = False
            break
        A[i] /= 2

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

    int N, a[100];
    cin >> N;
    rep(i, N) cin >> a[i];

    bool flag = 1;
    int cnt = 0;

    for(int i = N - 1; i > 0; i--) {
        for(int j = 0; j < i; j++) {
            if(a[j] > a[j + 1]) {
                swap(a[j], a[j + 1]);
                cnt++;
            }
        }
    }

    rep(i, N) {
        if(i == N - 1) cout << a[i];
        else cout << a[i] << " ";
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3164
Ss = input().rstrip()

def getRunLengthEncoding(Ss):
    anss = []
    num = 1
    SPrev = Ss[0]
    for S in Ss[1:]+'$':
        if S == SPrev:
            num += 1
        else:
            anss.append((SPrev, num))
            num = 1
            SPrev = S
    return anss

RLE = getRunLengthEncoding(Ss)

anss = [0] * len(Ss)
accNum = 0
for (_, R), (_, L) in zip(RLE[::2], RLE[1::2]):
    iR = accNum + R
    iL = iR - 1
    anss[iL] += (R+1)//2 + L//2
    anss[iR] += R//2 + (L+1)//2
    accNum += R + L

print(' '.join(map(str, anss)))


Measured memory_bytes: 17656
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

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

typedef long long ll;

int main() {
	//入力;
	int N, W;
	cin >> N >> W;

	vector<int> w;
	vector<ll> v;
	w.resize(N);
	v.resize(N);
	REP(i, N) {	cin >> w[i] >> v[i];}

	//DPテーブル作成(0で初期化済み);
	//dp[i][j] 品物1～iの中で選ぶ重さがW以下になる価値の最大値;
	vector<vector<ll>> dp;
	dp.resize(N+1);
	REP(i, N+1) dp[i].resize(W+1);
	
	//DPテーブルの更新;
	FOR(i, 1, N + 1) {
		FOR(j, 1, W + 1) {
			//品物iの重さと価値はw[i-1],v[i-1]であることに注意して;

			//そもそも品物iが重量jをオーバーして入らない場合;
			if (j - w[i-1]< 0) dp[i][j] = dp[i - 1][j];
			//そうでない場合;
			else {
				dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i - 1][j]);
			}
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

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

vector<string> V;

int dep(int cur){
    int ret=0;
    for(auto c:V[cur]) ret+=(c=='.');
    return ret;
}
int rec(int depth, int &cur){
    if(cur>=V.size()||depth!=dep(cur)) return -1;
    int ret;
    if(V[cur][depth]=='+'){
        ret=0;
        int d;
        while(d=rec(depth+1,++cur),d!=-1) ret+=d;
        cur--;
        return ret;
    }else if(V[cur][depth]=='*'){
        ret=1;
        int d;
        while(d=rec(depth+1,++cur),d!=-1) ret*=d;
        cur--;
        return ret;
    }else{
        ret=0;
        for(int i=depth;i<V[cur].size();i++){
            ret*=10;
            ret+=V[cur][i]-'0';
        }
        return ret;
    }
}


int main(){
    int n;
    while(cin>>n,n){
        V.clear();
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            V.push_back(s);
        }
        int c=0;
        cout<<rec(0,c)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    map<string, int>M;
    while(t--){
        string o, v;
        cin >> o >> v;
        if(o == "insert"){
            M[v]++;
        }else if(o == "find"){
            if(M[v]){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
}


Measured memory_bytes: 52452
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int n, k;
	cin >> n >> k;
	vector<int> cnt(n);

	REP(i, k)
	{
		int d;
		cin >> d;
		REP(j, d)
		{
			int a;
			cin >> a;
			cnt[a - 1]++;
		}
	}

	int ans = 0;
	REP(i, n)
	{
		if (cnt[i] == 0)ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int r = sc.nextInt();
    int s = sc.nextInt();
    int p = sc.nextInt();
    String t = sc.next();
    int ans = 0;
    int[] kati = new int[k];
    for(int i = 0; i < t.length(); i++) {
      if(((i - k) >= 0) && (t.charAt(i - k) == t.charAt(i))) {
        if(kati[i % k] == 1) {
          kati[i % k] = 0;
        } else {
          kati[i % k] = 1;
          if(t.charAt(i) == 'r') {
            ans += p;
          } else if(t.charAt(i) == 's') {
            ans += r;
          } else {
            ans += s;
          }
        }
      } else {
        kati[i % k] = 1;
        if(t.charAt(i) == 'r') {
          ans += p;
        } else if(t.charAt(i) == 's') {
          ans += r;
        } else {
          ans += s;
        }        
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 40232
import java.util.*;

public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int d=sc.nextInt();
    int t=sc.nextInt();
    int s=sc.nextInt();
    double temp=(double)d/(double)s;
    if((double)temp<=(double)t)
    System.out.println("Yes");
    else
    System.out.println("No");
  }
}

Measured memory_bytes: 35692
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> V(n);
    for (auto v = V.begin(); v != V.end(); v++) {
        cin >> *v;
    }

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

    double out = V[0];
    for (int v : V) out = (out + v) / 2;

    cout << setprecision(10);
    cout << out << endl;

}


Measured memory_bytes: 256
import sys
N, M = map(int, input().split())
ls = []
for i in range(2, int(M**(1/2))+1):
    if M%i == 0:
        ls.append(i)
if N == 1:
    print(M)
    sys.exit()
ans = 1
for x in ls:
    if x >= N:
        ans = max(ans, M//x)
        continue
    if M//x >= N:
        ans = max(ans, x)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int A, B;
    cin >> A >> B;
    int K;
    cin >> K;
    int cnt = 0;
    for(int i = A; i >= 1; i--){
        if(A % i == 0 && B % i == 0){
            cnt++;
            if(cnt == K){
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
# 23:05-
n, h = gets.to_s.split.map{|t|t.to_i}
a, b = Array.new(n){ gets.to_s.split.map{|t|t.to_i} }.transpose

a_max = a.max

b.sort!
b.reverse!

idx = b.bsearch_index{ |t| t <= a_max } || n

b[0, idx].each_with_index do |t, i|
  
  h -= t
  
  if h <= 0
    puts i + 1
    exit
  end
end

puts ans = idx + ( h + a_max - 1 ) / a_max

Measured memory_bytes: 11912
# 座標xからk回dだけ移動する
x, times, dist = gets.chomp.split.map(&:to_i)
# 原点からの距離
abst = x.abs
# 原点を通りすぎず最接近するまでの手数
min = abst / dist
# 通り過ぎることができないなら、最大限近づく
if min >= times
  puts abst - times * dist
  # 最接近してから、原点を奇数回またぐ
elsif (times - min).odd?
  puts (min + 1) * dist - abst
  # 最接近してから、原点を偶数回またぐ
else
  puts abst % dist 
end



Measured memory_bytes: 14392
#include <stdio.h>
#define N 100

int selectionSort(int A[N],int n){
	
	int swap = 0,temp,min;
	for( int i = 0; i < n; i++){
		min = i;
		for( int j = i; j < n; j++){
			if( A[j] < A[min] ) min = j;
		}
		if( min != i ){
			temp = A[i];
			A[i] = A[min];
			A[min] = temp;
			swap++;
		}
	}
	
	return swap;
	
}

int main(void){
	
	int A[N];
	int n,swap;
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
	}
	
	swap = selectionSort(A,n);
	
	for(int i = 0; i < n; i++){
		if( i == n-1 ){
			printf("%d\n", A[i]);
			break;
		}
		printf("%d ", A[i]);
	}
	printf("%d\n", swap);
	
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
#define pb push_back
#define endl "\n"
#define ll long long int
using namespace std;
const double pi=3.14159265358;
int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double deg1 = h/12*360 +m/60 *30;
    double deg2=m/60*360;
    double q,w,e,r;
    q=a*sin(deg1*pi/180);
    w=a*cos(deg1*pi/180);
	e=b*sin(deg2*pi/180);
    r=b*cos(deg2*pi/180);
    double answer;
    answer=sqrt((q-e)*(q-e)+(w-r)*(w-r));
    cout<<setprecision(10)<<answer<<endl;
}

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

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

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

    int n, z, w;
    cin >> n >> z >> w;

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

    int ans;
    if (n > 1) {
        ans = max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1]));
    }else{
        ans = abs(a[0] - w);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   string s, str;
   cin>>str;
   cin>>s;
   for(int i=1;i<=s.size();i++)
   {
       str=str[str.size()-1] + str;

       str.erase(str.begin()+str.size()-1);
        int j;
       for(j=0;j<s.size();j++)
       {
        if(str[j]!=s[j])
            break;
       }
       if(j==s.size())
       {
        cout<<"Yes";
        return 0;
       }
   }
   cout<<"No";




 return 0;
}








Measured memory_bytes: 3676
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,a[200005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    rep(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    mll m;
    set<ll>s;
    rep(i,0,n)
        s.insert(a[i]);
    rep(i,0,n)
    {
        if(i and a[i]==a[i-1])
            s.erase(a[i]);
        else
        {
            for(ll j=2*a[i];j<=1000000;j+=a[i])
                s.erase(j);
        }
    }
    cout<<sz(s);
}


Measured memory_bytes: 14504
n = int(input())
a = sorted([int(i) for i in input().split()])

monster = a[0]

while True:
    last = a.pop()
    attacked = last % monster
    if attacked == 0:
        pass
    elif attacked < monster:
        monster = attacked
        a.insert(0, attacked)

    if len(a) == 1:
        print(a[0])
        break


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T,typename Y>
struct Rerooting{

	using F =function<T(T,T)>;
	using G =function<T(T,Y)>;

	vector<vector<int>>g;
	vector<vector<T>>dp;
	vector<T>ans;
	const F merge;
	const G add_root;
	const T identity;

	Rerooting(int n,const F &merge,const G &add_root,const T &identity):merge(merge),add_root(add_root),identity(identity){
		g.resize(n);
		dp.resize(n);
		ans.resize(n,identity);
	}

	void add_edge(int u,int v){
		g[u].emplace_back(v);
	}

	void build(int root=0){
		dfs1(root);
		dfs2(root,identity);
	}

	T dfs1(int v,int par=-1){
		T cul = identity;
		dp[v].resize(g[v].size(),identity);
		for(int i=0;i<g[v].size();++i){
			int u =g[v][i];
			if(u==par)continue;
			dp[v][i]=dfs1(u,v);
			cul=merge(cul,dp[v][i]);
		}
		return add_root(cul,v);
	}

	void dfs2(int v,const T &val ,int par=-1){
		for(int i=0;i<g[v].size();++i){
			if(g[v][i]==par){
				dp[v][i]=val;
			}
		}
		vector<T>dp_l(g[v].size()+1,identity),dp_r(g[v].size()+1,identity);
		for(int i=0;i<g[v].size();++i){
			dp_l[i+1]=merge(dp_l[i],dp[v][i]);
		}
		for(int i=g[v].size()-1;i>=0;--i){
			dp_r[i]=merge(dp_r[i+1],dp[v][i]);
		}

		ans[v]=add_root(dp_l[g[v].size()],v);

		for(int i=0;i<g[v].size();++i){
			int u=g[v][i];
			if(u==par)continue;
			dfs2(u,add_root(merge(dp_l[i],dp_r[i+1]),v),v);
		}
	}
};

void solve()
{
	int n,m;
	cin>>n>>m;
	Rerooting<ll,ll>tree(n,[&](ll a,ll b){return a*b%m;},[&](ll a,ll b){return (a+1)%m;},1);
	rep(i,n-1){
		int x,y;
		cin>>x>>y;
		x--;y--;
		tree.add_edge(x,y);
		tree.add_edge(y,x);
	}
	tree.build();
	rep(i,n)cout<<(tree.ans[i]-1+m)%m<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 34176
use std::cmp;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let q: usize = sc.read();
    let s = sc.chars();
    let td: Vec<(char, bool)> = (0..q)
        .map(|_| (sc.chars()[0], sc.chars()[0] == 'R'))
        .collect();
    let s_rev = s.iter().rev().cloned().collect::<Vec<_>>();
    let td_rev = td.iter().map(|&(t, d)| (t, !d)).collect::<Vec<_>>();

    let to_left = binary_search(s, td);
    let to_right = binary_search(s_rev, td_rev);
    println!("{}", n - cmp::min(to_left + to_right, n));
}

fn binary_search(s: Vec<char>, queries: Vec<(char, bool)>) -> usize {
    let n = s.len();
    let mut ok = 0;
    let mut ng = n + 1;
    while ng - ok > 1 {
        let mid = (ok + ng) / 2;
        if solve(mid - 1, &s, &queries) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok
}

fn solve(mut cur: usize, s: &Vec<char>, queries: &Vec<(char, bool)>) -> bool {
    let n = s.len();
    for &(c, is_right) in queries.iter() {
        if s[cur] == c {
            if is_right {
                if cur == n - 1 {
                    return false;
                } else {
                    cur += 1;
                }
            } else {
                if cur == 0 {
                    return true;
                } else {
                    cur -= 1;
                }
            }
        }
    }
    false
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
open List;;let l()=map float_of_string(Str.split(Str.regexp" ")(read_line()));;let n=read_int()and x,y=l(),l();;let m p=exp(log(fold_left2(fun a b c->a+.abs_float(b-.c)**p)0. x y)/.p);;Printf.printf"%f
%f
%f
%f
"(m 1.)(m 2.)(m 3.)(fold_left2(fun a b c->max a(abs_float(b-.c)))0. x y)

Measured memory_bytes: 2672
#include <stdio.h>

int main(){
  int A[6],i;
  char j;
  for(i=0;i<6;i++){
    scanf("%c", &j);
    A[i]=j;
  }
  if(A[2]==A[3] && A[4]==A[5]){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    long int cn;
    int n, m, l;
    int i, j, k;
    int a[100][100] = {0};
    int b[100][100] = {0};

    scanf("%d %d %d", &n, &m, &l);
    
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(j = 0; j < m; j++){
        for(k = 0; k < l; k++){
            scanf("%d", &b[j][k]);
        }
    }
    
    for(i = 0; i < n; i++){
        for(k = 0; k < l; k++){
            cn = 0;
            for(j = 0; j < m; j++){
                cn += a[i][j] * b[j][k];
            }
            printf("%1ld", cn);
            if(k == l - 1) puts("");
            else printf(" ");
        }
    }
    return 0;
}

Measured memory_bytes: 1936
#include <stdio.h>
#define NUM 100000

int main(void){
    int N, K;
    scanf("%d %d", &N, &K);

    int x;
    for(int i = 0; i < N; i++){
        int A;
        scanf("%d", &A);
        if(A == 1){
            x = i;
            break;
        }
    }

    int a = x;
    int b = N - a - 1;

    int t = (N - 1) / (K - 1);
    int s = (N - 1) % (K - 1);
    int ans;

    if(s == 0){
        ans = t;
    }else{
        ans = t + 1;
    }

    printf("%d\n", ans);
}


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

using namespace std;

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

    while (n--) {
        string str;
        getline(cin, str);

        size_t pos = 0;
        while ((pos = str.find("Hoshino", pos)) != string::npos) {
            str.replace(pos, 7, "Hoshina");
        }

        cout << str << endl;
    }

    return 0;
}

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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int findCount = 0;
		for (int i = 0; i < n; i++) {
			int num = Integer.parseInt(br.readLine());
			if (isPrime(num)) {
				findCount++;
			}
		}
		System.out.println(findCount);
	}

	public static boolean isPrime(int num) {
		if (num < 2) {
			return false;
		} else if (num == 2) {
			return true;
		} else if (num % 2 == 0) {
			return false;
		}

		double sqrtNum = Math.sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2) {
			if (num % i == 0) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 30136
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
vector<ll> v={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;
cout << v[k-1]<<endl;}


Measured memory_bytes: 3624
N=int(input())
A=[int(i) for i in input().split()]
Q=int(input())
B=[0 for i in range(Q)]
C=[0 for i in range(Q)]
for i in range(Q):
    B[i],C[i]=map(int,input().split())
D=dict()
for i in range(N):
    if A[i] in D:
        D[A[i]]+=1
    else:
        D[A[i]]=1
S=sum(A)
for i in range(Q):
    if not(B[i] in D):
        print(S)
        continue
    tmp=D[B[i]]
    D[B[i]]=0
    if C[i] in D:
        D[C[i]]+=tmp
    else:
        D[C[i]]=tmp
    S=S+(C[i]-B[i])*tmp
    print(S)


Measured memory_bytes: 25784
import math

N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

ans = 0

for i in range(N):
    for j in range(i+1, N):
        temp = 0
        for k in range(D):
            temp += abs(X[i][k] - X[j][k])**2
        if int(math.sqrt(temp))**2 == temp:
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define z 1e9 + 7
using namespace std ;
int main(){
    int k , n , i , ans = 0 ;
    cin >> k >> n ;
    vi a(n) ;
    for(i=0;i<n;++i) cin >> a[i] ;
    for(i=0;i<n;++i){
        if(i<n-1) ans = max(ans,a[i+1]-a[i]) ;
        else ans = max(ans,k-a[n-1]+a[0]) ;
    }
    cout << k - ans << "\n" ;
    return 0;
}

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

int main(){
    int n,k;
    int sum = 0;
    cin >> n >> k;
    vector<int> l(n,0),a(n,0);
    for(int i = 0; i < n; i++){
        cin >> l[i];
        for(int j = 0; j < n; j++){
            if(l[i] > a[j]){
                a.insert(a.begin() + j,l[i]);
                break;
            }
        }
    }
    for(int i = 0; i < k; i++){
        sum = sum + a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

//----------------------------------
//----------------------------------

template<typename container>
inline void print_STL(container c)
{
        if(c.size() == 0)
                return;
        std::cout << c[0]; 
        for(int i = 1; i < c.size(); i++)
                std::cout << ' ' << c[i];
        std::cout << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
        int n;
        vector<int> a;
        cin >> n;
        for(int i = 0; i < n; i++)
        {
                int tmp;
                cin >> tmp;
                a.push_back(tmp);
        }
        int count = 0;
        for(int i = 0; i < n; ++i)
        {
                for(int j = n-1; j > i; --j)
                        if(a[j] < a[j-1])
                        {
                                count++;
                                swap(a[j],a[j-1]);
                        }
        }
        print_STL(a);
        cout << count << '\n';

}

Measured memory_bytes: 3164
n, m = map(int, input().split())
groups = [x for x in range(n)]
count = [0]*n

def UnionFind(x):
    a = x
    while a != groups[a]:
        a = groups[a]
    groups[x] = a
    return a

for _ in range(m):
    x, y = map(int, input().split())
    x, y = UnionFind(x-1), UnionFind(y-1)
    if x != y:
        groups[y] = x
    
for i in range(n):
    count[UnionFind(i)] += 1
print(max(count))


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

using namespace std;

const int MX = 500;

int dist[MX][MX], a[MX][MX];

int main() {
	int n;
	ignore = scanf("%d", &n);
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			dist[i][j] = min(min(i, n - 1 - i), min(j, n - 1 - j));
			a[i][j] = 1;
		}
	
	int ans = 0;
	for (int i = 0, p; i < n * n; i++) {
		ignore = scanf("%d", &p);
		
		int x = (p - 1) / n;
		int y = (p - 1) % n;
		
		ans += dist[x][y];
		a[x][y] = 0;
		
		vector<pair<int, int>> queue;
		queue.emplace_back(x, y);
		for (size_t j = 0; j < queue.size(); j++) {
			tie(x, y) = queue[j];
			
			for (int dx = -1; dx <= 1; dx++)
				for (int dy = -1; dy <= 1; dy++) {
					if (abs(dx) + abs(dy) != 1) continue;
					
					int xx = x + dx, yy = y + dy;
					if (xx < 0 || xx >= n || yy < 0 || yy >= n) continue;
					if (dist[xx][yy] > dist[x][y] + a[x][y]) {
						dist[xx][yy] = dist[x][y] + a[x][y];
						queue.emplace_back(xx, yy);
					}
				}
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 9072
import heapq

X, Y, A, B, C = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
r = [int(x) for x in input().split()]

p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = False)

p = p[0:X]   # 大きいものからX個
q = q[0:Y]

# Min heap
heapq.heapify(p)
heapq.heapify(q)


for i in range(C):
    if len(p) > 0 and r[i] > p[0] and p[0] <= q[0]:  # 赤いりんごの方が美味しくない
        heapq.heappop(p)
        heapq.heappush(p, r[i])
    elif len(q) > 0 and r[i] > q[0]:
        heapq.heappop(q)
        heapq.heappush(q, r[i])

ans = 0
while len(p) > 0:
    # red = heapq.heappop(p)
    ans += heapq.heappop(p)
while len(q) > 0:
    # green = heapq.heappop(q)
    ans += heapq.heappop(q)

print(ans)


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

int main() {
    int N; cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; ++i) cin >> L[i];
    
    sort(L.begin(), L.end());
    int res = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N; ++j) {
            for(int k = j+1; k < N; ++k) {
                int a = L[i], b = L[j], c = L[k];
                if(c < a + b) ++res;
            }
        }
    }
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	char c;
	do{
		a=0;
		c='a';
		while(c!='\n'){
			scanf("%c",&c);
			switch(c){
				case '1':
					a+=1;
					break;
				case '2':
					a+=2;
					break;
				case '3':
					a+=3;
					break;
				case '4':
					a+=4;
					break;
				case '5':
					a+=5;
					break;
				case '6':
					a+=6;
					break;
				case '7':
					a+=7;
					break;
				case '8':
					a+=8;
					break;
				case '9':
					a+=9;
					break;
			}
		}
		if(a!=0){
			printf("%d\n",a);
		}
	}while(a!=0);
	return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using namespace __gnu_pbds;
using vl = vector<ll>;
using pll =  pair<ll,ll>;



void solve(){
    string s;
    cin>>s;
    if(s.size()%2!=0){
        cout<<"No";
        return;
    }
    for(int i=0;i<s.size();i+=2){
        if(s[i] =='h'&&s[i+1] == 'i')
            continue;
        else{
            cout<<"No";
            return;
        }    
    }
    cout<<"Yes";
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //int n;cin>>n;for(int i=0;i<n;i++) 
    solve();
    return 0;
}

Measured memory_bytes: 256