akhauriyash/Code-Regression huggingface dataset:
K = int(input())

S = [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]
print(S[K - 1])

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

namespace AtCoder.Contest.A
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

            Console.WriteLine(cin.ArrayInt(3).Distinct().Count());

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13280
fun main(args: Array<String>) {
    while (true) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        if (x == 0 && y == 0)
            break
        if (x < y)
            println("${x} ${y}")
        else
            println("${y} ${x}")
    }
}


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

int main() {
  int N,sum;
  sum = 0;
  cin >> N;
  vector<int> card(N);
  for(int i=0;i<N;i++){
    cin >> card.at(i);
  }
  sort(card.begin(), card.end());
  reverse(card.begin(),card.end());
  for(int i=0;i<N;i++){
    if(i%2==0){
      sum += card.at(i);
    }
    if(i%2==1){
      sum -= card.at(i);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

S = set([])
T = []
for a in A:
    if a in S:
        T.append(a)
        S.remove(a)
    else:
        S.add(a)
if len(T) <= 1:
    print("0")
    exit()
T.sort(reverse=True)
ans = T[0] * T[1]
print(ans)


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

const int N = 1e5 + 6;
#define LL long long int

LL w[N], v[N];
int n, W;
LL dp[102][123456];

LL solve(int idx, int left)
{
	if(idx > n)return 0;
	LL &ret = dp[idx][left];
	if(ret != -1)return ret;
	
	ret = 0;
	//cout << idx << " " << left << endl;
	//takes this item
	if(w[idx] <= left)
	ret = max(ret, v[idx] + solve(idx + 1, left - w[idx]));
	
	ret = max(ret, solve(idx + 1, left));
	
	
	return ret;
}


int main()
{
	cin >> n >> W;
	for(int i = 1; i <= n; i++)
	{
		cin >> w[i] >> v[i];
	}
	
	for(int i = 0; i < 102; i++)for(int j = 0; j < 123456; j++)dp[i][j] = -1;
	
	cout << solve(1, W);
}


Measured memory_bytes: 98688
#include <stdio.h>
 
int Partition(int *,int,int);
void swap(int *,int,int);
 
int main(){
  int i,n;
  int ce;
  int a[100000];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++) scanf("%d",&a[i]);
 
  ce = Partition(a,0,n-1);
 
  for(i=0;i<n-1;i++){
    if(i == ce) printf("[%d] ",a[i]);
    else printf("%d ",a[i]);
  }
  if(i == ce)printf("[%d]\n",a[i]);
  else printf("%d\n",a[i]);
 
  return 0;
}

int Partition(int *a,int p,int r){
  int i,j,x,box;
 
  x=a[r];
  j=p-1;
 
  for(i=p;i<r;i++){
    if( a[i] <= x){
      j++;
      swap(a,j,i);
    }
  }
  swap(a,j+1,r);
 
  return j+1;
}
 
void swap(int *a,int p,int q){
  int box;
 
  box = a[p];
  a[p]=a[q];
  a[q]=box;
}

Measured memory_bytes: 988
#include<stdio.h>
int main()
{
	int h,m,i,j;
	char s[105][105];
	scanf("%d %d",&h,&m);
	for(i = 0;i < h;i++)
	{
		scanf("%s",s[i]);
	}
	for(i = -1;i < h + 1;i++)
	{
		for(j = -1;j < m + 1;j++)
		{
			if(i == -1 || j == -1 || i == h || j == m)
				printf("#");
			else
				printf("%c",s[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n = 4;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(ALL(a));
  if(a[0] == 1 and a[1] == 4 and a[2] == 7 and a[3] == 9) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main(){
ll x,k,d,ans;
cin>>x>>k>>d;
if(x<0)x=-x;
ll y=x;
ll i=0;
i=y/d;

if(i>=k)ans=x-k*d;
else if((k-i)%2==0){
    ans=x-i*d;
}
else ans=abs(x-i*d-d);
cout<<ans<<endl;

}

Measured memory_bytes: 3636
N, A, B, C, D = map(int, input().split())

## setX
if N % A == 0 :
    X = N // A * B
else : 
    X = (N // A + 1) * B

## setY
if N % C == 0 :
    Y = N // C * D
else :
    Y = (N // C + 1) * D
    
print(min(X, Y))


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli t,n,k,i;
	cin>>n>>k;
	vector<lli>v;
	n--;
	t=n;
	v.pb(k);
	for(i=n;i>=1;i--){
		v.pb(k-i);
	}
	for(i=t;i>=1;i--) v.pb(k+i);
	sort all(v);
	for(i=0;i<v.size();i++) cout<<v[i]<<" ";	
	return 0;
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
import sys
from heapq import heappush,heappop,heapify

N=int(sys.stdin.readline().strip())
V=[]    #頂点の集合 (x座標、y座標、頂点番号)
for v in range(N):   #v:頂点番号
    x,y=tuple(map(int, sys.stdin.readline().split()))
    V.append((x,y,v+1))

#頂点をy軸でソート
V.sort(key=lambda x:(x[0]) )
E=[]    #辺の集合 (辺の長さ、頂点番号、頂点番号)
for i in range(N-1):
    fro_x,fro=V[i][0],V[i][2]
    to_x,to=V[i+1][0],V[i+1][2]
    E.append( (abs(fro_x-to_x),fro,to))

#頂点をx軸でソート
V.sort(key=lambda x:(x[1]) )
for i in range(N-1):
    fro_y,fro=V[i][1],V[i][2]
    to_y,to=V[i+1][1],V[i+1][2]
    E.append( (abs(fro_y-to_y),fro,to))


al=[[] for _ in range(N+1)]
for cost,fro,to in E:
    al[fro].append((cost,to))
    al[to].append((cost,fro))


#確定した頂点のリスト
fixed_v=[ 0 for _ in range(N+1) ]
hq=[]   #最短の辺を取得するためのヒープキュー
V=[1]   #次に処理する頂点が常に1つだけ入る、頂点1が常にスタート地点

ans=0
while V:
    cur=V.pop()
    #確定した頂点の更新
    fixed_v[cur]=1
    #頂点curから出て行く辺を全てhqに入れる
    for cost,to in al[cur]:
        heappush(hq,(cost,to))
    while hq:
        #hqから辺を取り出す
        cost,to=heappop(hq)
        #未確定の頂点が見つかれば、次に見る頂点としてVにappendし、whileループはbreak
        if fixed_v[to]==0:
            ans+=cost
            V.append(to)
            break
        #確定済みの頂点の場合は、#未確定の頂点が見つかるまでheapqからpopする

print ans

Measured memory_bytes: 163532
#include <stdio.h>

int main(void) {
    
    int n, x, i, j, k;
    int count;
    
    while(1){
        count = 0;
        scanf("%d %d", &n, &x);
        
        if(n==0 && x==0)
            break;
        
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if (i + j + k == x)
                        count++;
                }
            }
        }
        printf("%d\n", count);
    }
    
}

Measured memory_bytes: 1844
s = input()
mnt_list = []
cnt = 0
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        cnt += 1
        mnt_list.append(cnt)
        cnt = 0
    else:
        cnt += 1

if s[-2] == 'L':
    mnt_list.append(cnt+1)
else:
    mnt_list.append(1)
    
ans_list = [0]*len(s)

state = 0
for n,i in enumerate(mnt_list):
    state += i
    if n%2 == 0:
        if i%2 == 0:
            ans_list[state-1] += int(i/2)
            ans_list[state] += int(i/2)

        else:
            ans_list[state-1] += int(((i-1)/2)+1)
            ans_list[state] += int((i-1)/2)
            
    else:
        if i%2 == 0:
            ans_list[state-1-i] += int(i/2)
            ans_list[state-i] += int(i/2)

        else:
            ans_list[state-i] += int(((i-1)/2)+1)
            ans_list[state-1-i] += int((i-1)/2)
            
print(*ans_list)

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

using namespace std;

int main() {
  vector<int> A(3);
  for (int i = 0; i < 3; i++) cin >> A[i];
  sort(A.rbegin(), A.rend());
  cout << A[0] * 10 + A[1] + A[2] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double PI = 3.141592653589793238462643383279;

int main(){
    int a,b,x;
    scanf("%d%d%d", &a, &b, &x);
    double o;
    if(x*2 <= a*a*b) {
        o = atan2(b*b*a, 2*x);
    }else {
        o = atan2(2*(a*a*b-x), a*a*a);
    }
    printf("%.10lf\n", o/PI*180);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n,k;
 cin>>n>>k;
 vector<int> a(n);
 for(int i=0;i<n;i++) cin>>a[i];
 vector<bool> dp(k+1);
 dp[0]=0;
 for(int i=1;i<=k;i++){
  for(int j=0;j<n;j++){
   if(i>=a[j]) dp[i]=dp[i]||(!dp[i-a[j]]);
  }
 }
 if(dp[k]){
  cout<<"First"<<endl;
 }
 else cout<<"Second"<<endl;
 return 0;
}

Measured memory_bytes: 256
def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n - 2)


def count5(n):
    d = 5
    while d < n:
        d *= 5
    c = 0
    while d != 1:
        c += n / d
        d /= 5
    return c


def main():
    n = input()
    if n % 2 == 1:
        print 0
    else:
        print min(count5(n / 2), n / 2)


main()


Measured memory_bytes: 28012
import math

N = int(input())
P = list(map(int,input().split()))
S = list(map(int,input().split()))
Psum = 0
Ssum = 0
Pma = []
Sma = []
for i in range(N):
    p = P[i]
    s = S[i]
    for j in Pma:
        if P[i] > j:
            p -= 1
    for k in Sma:
        if S[i] > k:
            s -= 1
    Psum += math.factorial(N-(i+1))*(p-1)
    Ssum += math.factorial(N-(i+1))*(s-1)
    Pma.append(P[i])
    Sma.append(S[i])
print(abs(Psum-Ssum))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import math
 
def Strider():
 
    NumA = int(input())
 
    count = 360/NumA
    
    NumB = 1
    
    while ((360*NumB % NumA) != 0):
        NumB = NumB + 1
        count = 360*NumB/NumA
    
    print(int(count))
 
if __name__ == '__main__':
    Strider()

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

int ul[10];
bool used[10];

int dfs(int x, int n, int s) {
  int r = 0;
  if (!used[x]) {
    if (s < n*x) return 0;
    else if (s == n*x && n == 1) return 1;
    else if (n > 1 && ul[n-1] >= s-n*x) {
      used[x] = true;
      r = dfs(0, n-1, s-n*x);
      used[x] = false;
    }
  }
  if (x<9) {
    r += dfs(x+1, n, s);
  }
  return r;
}

int main() {
  int n, s;

  for (int i=1; i<=10; i++) {
    ul[i-1] = i*(i+1)*(28-i)/6;
  }

  while (cin >> n >> s) {
    for (int i=0; i<n; i++) used[i] = false;
    cout << dfs(0, n, s) << endl;
  }

  return 0;
}

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

using namespace std;

// DP[i][w][m] : i???????????§??????????????\???????????????w?????¨??????????????°????????????????????§??????????°?????????????m
long long DP[2][10001][201];

int main(){
    int n,w;
    cin >> n >> w;
    vector<int> v;
    for(int i=0;i<n;i++){
        int t;
        cin >> t;
        v.push_back(t);
    }
    DP[0][0][200] = 1;
    for(int i=0;i<n;i++){
        int dp_a = i % 2;
        int dp_b = (i + 1) % 2;
        for(int j=0;j<=w;j++){
            for(int k=0;k<=200;k++){
                DP[dp_b][j][k] = 0;
            }
        }
        for(int j=0;j<=w;j++){
            for(int k=0;k<=200;k++){
                if(DP[dp_a][j][k] == 0)
                    continue;
                //??\?????????
                {
                    int m;
                    if(k == 200 || v[i] < v[k]){
                        m = i;
                    }else{
                        m = k;
                    }
                    DP[dp_b][j][m] += DP[dp_a][j][k];
                    DP[dp_b][j][m] %= 1000000007;
                }
                //??\??????
                if(v[i] + j <= w){
                    DP[dp_b][v[i]+j][k] += DP[dp_a][j][k];
                    DP[dp_b][v[i]+j][k] %= 1000000007;
                }
            }
        }
    }
    long long ans=0;
    for(int j=0;j<=w;j++){
        for(int k=0;k<=200;k++){
            if(k != 200 && n <= k)
                continue;
            if(k == 200 || w-j < v[k]){
                ans = (ans + DP[n%2][j][k]) % 1000000007;
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 32620
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >>= putStrLn . which "Yes" "No" . not . null . filter ( 3 <= ) . map length . group


Measured memory_bytes: 380
n, m = map(int, input().split())
c = []
for i in range(m):#h:高さ
    c.append([int(m) for m in input().split()])
ball = []
for i in range(n + 1):
    if i == 1:
        ball.append([1, 1])
    else:
        ball.append([0, 1])
for i in range(m):
    if ball[c[i][0]][0] == 0:#赤ボールがないとき
        ball[c[i][0]][1] -= 1
        ball[c[i][1]][1] += 1
    elif ball[c[i][0]][1] == 1:#赤ボールがひとつ，白が0のとき
        ball[c[i][0]][1] -= 1
        ball[c[i][1]][1] += 1
        ball[c[i][1]][0] = 1
        ball[c[i][0]][0] -= 1
    else:#白がひとつ以上のとき
        ball[c[i][0]][1] -= 1
        ball[c[i][1]][1] += 1
        ball[c[i][1]][0] = 1

ans = 0
for i in range(n + 1):
    if ball[i][0] >= 1:
        ans += 1
print(ans)

Measured memory_bytes: 31396
//fifer a tak luboin
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mb make_pair
#define se second
#define fi first
#define INF 1e18

using namespace std;


int a[100100];
int cnt1=0;
int cnt2=0;
int main()
{

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("arithmetic.in", "r", stdin);
    //freopen("arithmetic.out", "w", stdout);
    int n;
    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            cnt2++;
        }
        else
        {
            cnt1++;
        }
    }

    if(cnt1%2==0 && cnt2%2==0)
    {
        cout<<"YES";
    }
    else if(cnt1%2!=0 && cnt2%2!=0)
    {
        cout<<"NO";
    }
    else if(cnt1%2==0 && cnt2%2!=0)
    {
        cout<<"YES";
    }
    else if(cnt1%2!=0 && cnt2%2==0)
    {
        cout<<"NO";
    }























return 0;}


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

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

    int res = 100 * (N - M) + 1900 * M;
    for(int i=0; i<M; ++i) res *= 2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<pair<int, int>> p(n);
  vector<int> x(n), y(n);
  for (int i : range(n)) cin >> p[i].first >> p[i].second;
  for (int i : range(n)) x[i] = p[i].first, y[i] = p[i].second;
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  long long res = 1e18;
  int rx = -1, ry = -1;
  for (int i : range(max(0, n / 2 - 3), n / 2 + 3)) {
    for (int j : range(max(0, n / 2 - 3), n / 2 + 3)) {
      int xx = x[i], yy = y[j];
      long long r = 0;
      for (int k : range(n)) r += abs(x[k] - xx) + abs(y[k] - yy);
      int d = 0;
      for (int k : range(n)) d = max(d, abs(p[k].first - xx) + abs(p[k].second - yy));
      r = 2 * r - d;
      if (res > r || (res == r && (xx < rx || (xx == rx && yy < ry)))) {
        res = r;
        rx = xx;
        ry = yy;
      }
    }
  }
  cout << res << endl << rx << " " << ry << endl;
}

Measured memory_bytes: 2584
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll C[100007];

map<pair<ll,ll>,pair<ll,ll>> M;

int main(){
  ll N,ma=0;
  vector<vector<ll>> Edge(100007);
  cin >> N;
  rep(i,N-1){
    ll a,b;
    cin>>a>>b;
    M[mp(a,b)]=mp(i,0);
    Edge[a].pb(b);
    Edge[b].pb(a);
  }
  queue<pair<ll,ll>> Q;
  Q.push(mp(1,0));
  C[1]=1;
  while(!Q.empty()){
    ll T=1;
    auto X = Q.front();
    Q.pop();
    rep(j,Edge[X.fr].size()){
      if(C[Edge[X.fr][j]]==0){
        if(T==X.sc){
          T++;
        }
        M[mp(X.fr,Edge[X.fr][j])].sc=T;
        C[Edge[X.fr][j]]=1;
        Q.push(mp(Edge[X.fr][j],T));
        ma = max(ma,T);
        T++;
      }
    }
  }
  cout << ma << endl;
  for(auto P : M){
    C[P.sc.fr]=P.sc.sc;
  }
  rep(i,N-1){
    cout << C[i] << endl;
  }
}

Measured memory_bytes: 15360
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

class UnionFind {
private:
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	bool is_same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -data[root(x)]; }

	bool unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
			return true;
		}
		return false;
	}
};

int main() {

	int N, M, K;
	cin >> N >> M >> K;

	vector<int> ans(N, -1);
	vector<pair<int, int>> ab(M);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		ab[i] = { a, b };
		ans[a]--;
		ans[b]--;
	}
	vector<pair<int, int>> cd(K);
	for (int i = 0; i < K; i++) {
		int c, d;
		cin >> c >> d;
		c--, d--;
		cd[i] = { c, d };
	}
	
	UnionFind uf(N);
	for (int i = 0; i < M; i++) {
		const auto& [a, b] = ab[i];
		uf.unify(a, b);
	}

	for (int i = 0; i < K; i++) {
		const auto& [c, d] = cd[i];
		if (uf.is_same(c, d)) {
			ans[c]--;
			ans[d]--;
		}
	}

	for (int i = 0; i < N; i++) {
		cout << uf.size(i) + ans[i] << "\n";
	}

	return 0;
}



Measured memory_bytes: 5512
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
ans = 0
hand = [-1]*n
mk = -1
for i in range(n):
    if i>=k:
        mk = hand[i-k]
    if t[i] =="r" and mk!=2:
        ans+=p
        hand[i] =2
    if t[i] =="s" and mk!=0:
        ans+=r
        hand[i] =0
    if t[i] =="p" and mk!=1:
        ans+=s
        hand[i] =1
print(ans)


Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;

int n,m,r;
const int INF=1e7;
int land[200][200],sea[200][200],z[1000];
typedef pair<int,int> P;

int main(){


	while(cin>>n>>m,n){
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) land[i][j]=sea[i][j]=INF;
			land[i][i]=sea[i][i]=0;
		}
		
		for(int i=0;i<m;i++){
			int x,y,t;
			string s;
			cin>>x>>y>>t>>s;
			x--; y--;
			if(s=="S"){
				sea[x][y]=min(sea[x][y],t);
				sea[y][x]=min(sea[y][x],t);
			}else{
				land[x][y]=min(land[x][y],t);
				land[y][x]=min(land[y][x],t);			}
		}
		
		for(int k=0;k<n;k++){
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					sea[i][j]=min(sea[i][j],sea[i][k]+sea[k][j]);
					land[i][j]=min(land[i][j],land[i][k]+land[k][j]);
				}
			}
		}
		
		cin>>r;
		for(int i=0;i<r;i++){
			cin>>z[i];
			z[i]--;
		}
		
		vector<vector<int> > dp(1001,vector<int>(201,INF));
		dp[0][z[0]]=0;

		for(int i=1;i<r;i++){
			for(int j=0;j<n;j++){
				
				//z[i]???????????????????????¨??°???z[i-1]
				
				for(int k=0;k<n;k++){
					//????????????j?????§?§???????j??????k????????????k??????z[i]?????????				
					dp[i][k]=min(dp[i][k],dp[i-1][j]+land[z[i-1]][j]+sea[j][k]+land[k][z[i]]);
					
				}
				
				//????????§?§????
				dp[i][j]=min(dp[i][j],dp[i-1][j]+land[z[i-1]][z[i]]);
			}
		}


		int res=INF;		
		for(int i=0;i<n;i++){
			res=min(res,dp[r-1][i]);
		}
		
		cout<<res<<endl;
		
	}
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int L,R,d;
    cin>>L>>R>>d;
    int ans=0;
    for(int i=L;i<=R;i++){
        if((i%d)==0)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		long [][][] dp = new long[10][1001][101];

		for(int i = 0; i < 101; ++i){
			dp[1][i][i] = 1;
		}
		
		for(int i = 1; i < 9; ++i){
			for(int j = 0; j < 1001; ++j){
				for(int k = 0; k < 101; ++k){
					for(int l = k+1; l <= 100; ++l){
						if( j+l < 1001 ) {
							dp[i+1][j+l][l] += dp[i][j][k];
						}
					}
				}
			}
		}
		
		
		while(sc.hasNextInt()){
			int n = sc.nextInt();
			int s = sc.nextInt();
			long res = 0;
			
			if( n == 0 && s == 0 ) break;
			
			for(int i = 0; i < 101; ++i){
				res += dp[n][s][i];
			}
			
			
			System.out.println(res);
		}
	}
}

Measured memory_bytes: 29544
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    long l = scan.nextLong();
    long r = scan.nextLong();

    if (l == 0){
      System.out.println(0);
      return;
    }

    if (r-l >= 2018){
      System.out.println(0);
      return;
    }

    int a1 = (int) l%2019;
    int a2 = (int) r%2019;
    
    int small = 2019;
    for (int j=a1; j < a2; j++){
      for (int k = j+1;k<=a2;k++){
        int kk = (int) (j*k)%2019;
        if (kk<small){
          small = kk;
        }
      }
    }

    System.out.println(small%2019);
  }

}


Measured memory_bytes: 35672
#include <algorithm>
#include <stdio.h>
using namespace std;
struct Apple{
	long value;
	int type;
};
Apple apple[300100];

bool judge(Apple a,Apple b){
	return a.value>b.value;
}

int main()
{
	int X,Y,A,B,C;
	scanf("%d%d%d%d%d",&X,&Y,&A,&B,&C);
	for(int i=0;i<A;i++){
		scanf("%ld",&apple[i].value);
		apple[i].type=1;
	}
	for(int i=A;i<A+B;i++){
		scanf("%ld",&apple[i].value);
		apple[i].type=2;
	}
	for(int i=A+B;i<A+B+C;i++){
		scanf("%ld",&apple[i].value);
		apple[i].type=0;
	}
	sort(apple,apple+A+B+C,judge);


	long long sum=0;
	int count_X=X,count_Y=Y,num=X+Y;
	for(int i=0;i<A+B+C;i++,num--){
		if(num==0) break;
		if(apple[i].type==0)
			sum+=apple[i].value;
		else if(apple[i].type==1&&count_X){
			sum+=apple[i].value;
			count_X--;
		}
		else if(apple[i].type==2&&count_Y){
			sum+=apple[i].value;
			count_Y--;
		}
		else num++;
	}
	printf("%ld",sum);
	return 0;
}


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

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

  for(int i=0;i<N;i++){
    cin >>S;
    if(S=='Y'){
      cout << "Four" << endl;
      break;
    }
    if(i == N-1 && S != 'Y'){
      cout << "Three" << endl;
    }
  }
}


Measured memory_bytes: 256
from collections import Counter
import sys

N = int(input())
D_list = list(map(int, input().split()))
if D_list[0] != 0:
    print(0)
    sys.exit()
P = 998244353
n = 1
c = Counter(D_list)
if c[0] != 1:
    print(0)
else:
    pre = 1
    for i in range(1, max(D_list) + 1):
        if c[i] == 0:
            print(0)
            sys.exit()
        n = (n * ((pre ** c[i]) % P)) % P
        pre = c[i]
    print(n)

Measured memory_bytes: 19936
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

bool isDigi(string s){
  rp(i,s.length())
    if(s[i] < '0' || s[i] > '9') return false;
  return true;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    string s;
    ll a,b;
    cin >> a >> b;
    cin >> s;
    if(
      !isDigi(s.substr(0,a)) ||
      !isDigi(s.substr(a+1,b)) ||
      s[a] != '-')
    cout << "No";
    else cout << "Yes";
    cout << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 384
S = input()
T = input()
ListS = []
ListT = []
Alphabet = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(26):
    ListS.append(S.count(Alphabet[i]))
    ListT.append(T.count(Alphabet[i]))
ListS.sort()
ListT.sort()
print("Yes" if ListS == ListT else "No")


Measured memory_bytes: 41456
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int gcd(int a, int b, int c){
  int temp;
  for(int i = 1; i <= min(a,b) && i<=min(b,c); ++i){
    if(a%i==0&&b%i==0&&c%i==0){
      temp=i;
    }
  }
  return temp;
}

int main() {
  long long total=0;
  int N; cin>>N;
  for(int i = 1; i <= N; ++i){
    for(int j = 1; j <=N; ++j){
      for(int k = 1; k <= N; ++k){
        total+=gcd(i,j,k);
      }
    }
  }
  cout<<total<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 100000000000007
using namespace std;
using pii=pair<int,int>;




vector<int64_t> dist;
vector<int> pre;


void Bellman_Ford(vector<vector<pii>> adj_list,int start){
    
    
    int n=adj_list.size();
    /*初期化*/
    dist=vector<int64_t>(n,INF);
    pre=vector<int>(n);/*最短経路におけるひとつ前の頂点*/
    
    dist.at(start)=0;
    REP(i,n-1){
        REP(u,n){
            for(auto vpair : adj_list.at(u)){
                int weight_u_to_v,v;
                tie(v,weight_u_to_v)=vpair;
                if(dist.at(u)!=INF && dist.at(v)>dist.at(u)+weight_u_to_v){
                  dist.at(v)=dist.at(u)+weight_u_to_v;
                  pre.at(v)=u;
                  
                }

            }
        }
    }

    REP(i,n){/*ここで更新があったら負閉路が存在*/
        REP(u,n){
            for(auto vpair : adj_list.at(u)){
                int weight_u_to_v,v;
                tie(v,weight_u_to_v)=vpair;
                if(dist.at(u)!=INF && dist.at(v)>dist.at(u)+weight_u_to_v){
                  dist.at(v)=-INF;
                  
                }

            }
        }
    }

  
}
int main() {
  int V,E,p;
  cin>>V>>E>>p;
  vector<vector<pair<int,int>>> adj_list(V);
  
  REP(i,E){
    int s,t,d;
    cin>>s>>t>>d;
    s--;
    t--;/*添字の調整*/
    d-=p;
    adj_list.at(s).push_back(make_pair(t,-d));

  }
  

  Bellman_Ford(adj_list,0);

  if(dist.at(V-1)==-INF){
      cout<<-1<<endl;
      return 0;
  }
  
  
  int64_t score=0;
  if(-dist.at(V-1)>0){
      score=-dist.at(V-1);
  }
  cout<<score<<endl;




  return 0;
}

Measured memory_bytes: 3508
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int n;
vec<int> abc(3), l;

int calcMp(vec<int> v, int x)
{
    int ret = 100000000;
    v.push_back(x);
    if (v.size() == n)
    {
        ret = 0;
        vec<int> sum(3), count(3);
        for (int i = 0; i < n; ++i)
        {
            sum[v[i]] += l[i];
            count[v[i]]++;
        }

        if (any_of(count.cbegin(), count.cend(), [](int e) { return e == 0; }))
        {
            return 100000000;
        }

        for (int i = 0; i < 3; ++i)
        {
            ret += (count[i] - 1) * 10 + abs(abc[i] - sum[i]);
        }
        return ret;
    }

    for (int i = 0; i <= 3; ++i)
        ret = std::min({ret, calcMp(v, i)});

    return ret;
}

int main()
{
    using namespace std;

    cin >> n;
    for (auto &e : abc)
    {
        cin >> e;
    }
    for (int i = 0; i < n; ++i)
    {
        int e;
        cin >> e;
        l.push_back(e);
    }

    int ans {100000000};
    for (int i = 0; i <= 3; ++i)
    {
        ans = min(ans, calcMp({}, i));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, l   l>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

string s;
int x, y, n, c[2], cx1, k, dp[2][16005], dp2[16005];
bool f, d;
void up(int K){
    fox(l, 16004){
        if (dp[d][l] && l+K>=0 && l+K<=16004) dp2[l+K]=1;
    }
}
int main(){
    dp[0][8002]=dp[1][8002]=1;
    cin >> s;
    s+='T';
    fox(l, s.size()){
        if (s[l]=='T'){
            //cout << "*";
            drain(dp2);
            up(k);
            if (f) up(-k);
            fox(l, 16004) dp[d][l]=dp2[l];
            //fox(l, 16004) if (dp[d][l]) cout << l << ' '; cout << endl;
            d=!d;
            f=1; k=0;
        }else {
            ++k;
        }
    }
    cin >> x >> y;
    if (dp[0][x+8002] && dp[1][y+8002]){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 2000000;
int n, s;
vector < int > ans;
vector < int > g[N], b[2];
set < int > h[N];
int a[N], p[N], dep[N], l[N], r[N], color[N];
void dfs1(int v, int c = 1, int p = -1){
    color[v] = c;
    for (auto u: g[v]){
        if (u != p){
            dfs1(u, c ^ 1, v);
        }
    }
}
void dfs2(int v, int p = -1){
    l[v] = -1e9;
    r[v] = 1e9;
    for (auto u: g[v]){
        if (u == p) continue;
        dfs2(u, v);
        l[v] = max(l[v], l[u] - 1);
        r[v] = min(r[v], r[u] + 1);
    }
    if (l[v] > r[v]){
        cout << "No";
        exit(0);
    }
    if (a[v] != N && (l[v] > a[v] || r[v] < a[v])){
        cout << "No";
        exit(0);
    }
    if (a[v] != N) l[v] = r[v] = a[v];
}
void dfs3(int v, int p = -1, int x = 0){
    if (a[v] == N){
        if (x - 1 >= l[v] && x - 1 <= r[v]) a[v] = x - 1; else a[v] = x + 1;
    }
   // cout << "v = " << v << " " << l[v] << " " << r[v] << " " << p << endl;
    for (auto u: g[v]){
        if (u != p) dfs3(u, v, a[v]);
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
        a[i] = N;
    }
    a[n] = N;
    dfs1(1);
    int k;
    cin >> k;
    int r;
    for (int i = 1; i <= k; i++){
        int v, x;
        cin >> v >> x;
        a[v] = x;
        b[x % 2].pb(v);
        r = v;
    }
    for (int i = 0; i < 2; i++){
        for (int j = 1; j < b[i].size(); j++){
            int u = b[i][j];
            int v = b[i][j - 1];
            if (color[u] != color[v]){
                cout << "No";
                return 0;
            }
        }
    }
    dfs2(r);
    cout << "Yes" << endl;
    dfs3(r);
    for (int i = 1; i <= n; i++) cout << a[i] << endl;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N; --N;
	ll val = 26;
	int cnt = 1;
	while (N >= val) {
		N -= val;
		val *= 26;
		cnt++;
	}
	string S(cnt, 'a');
	cnt = 0;
	while (N) {
		S[cnt] = 'a' + (N%26);
		N /= 26;
		cnt++;
	}
	reverse(begin(S), end(S));
	cout << S << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstring>

using namespace std;

int main() {


    char str[50];
    cin>>str;
    
    int len, i,j,k,arr[500] = {0};
    
    len = strlen(str);
    
    
    
    for(i=0; i<len; i++){
        
        
        arr[str[i]]++;
        
    }
    for(i=0; i<500; i++){
        
        if(arr[i] > 1){
            cout<<"no";
            return 0;
        }
    }
    cout<<"yes";
	return 0;
}


Measured memory_bytes: 256
input_line = list(map(int,input().split()))

# 高橋の体力
A = input_line[0]
# 高橋の攻撃
B = input_line[1]
# 青木の体力
C = input_line[2]
# 青木の攻撃
D = input_line[3]

while A > 0 or C > 0:
    C -= B
    if C <= 0:
        print('Yes')
        break
    A -= D
    if A <= 0:
        print('No')
        break

Measured memory_bytes: 9192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Virtual
{
    class ARC097_C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Read();
            int k = ReadInt();
            List<long> vals = new List<long>();
            for(int i = 0; i < s.Length; i++)
            {
                long val = 0;
                for(int j = i; j < Min(i + 5, s.Length); j++)
                {
                    val += (s[j] - 'a' + 1) * (long)Pow(100, 4 - (j - i));
                    vals.Add(val);
                }
            }
            vals.Sort();
            int cnt = 0;
            for(int i = 0; i < vals.Count; i++)
            {
                if (i == 0 || vals[i - 1] != vals[i]) cnt++;
                if (cnt == k)
                {
                    long val = vals[i];
                    //WriteLine(val);
                    for(int j = 4; j >= 0; j--)
                    {
                        long div = (long)Pow(100, j);
                        long v = (val / div) % 100;
                        if (v > 0)
                        {
                            Write((char)(v + 'a' - 1));
                        }
                    }
                    WriteLine();
                    return;
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;

bool check(int x,int y,int z){
    if (x == y || y == z || z == x){
        return false;
    }
    return x+y > z && y+z > x && z+x > y;
}

int main(){
    int n; cin >> n;
    vi l(n); cin >> l;
    int ans = 0;
    rep(i,n-2){
        rep(j,i+1,n-1){
            rep(k,j+1,n){
                ans += check(l[i],l[j],l[k]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
def count_diff(a,b):
    """
    コードを単純化
    """
    cnt = 0
    for c in a:
        if not(c in b):
            return True
    for c in b:
        if not(c in a):
            return True
    return False

def main():
    S = str(input())
    T = str(input())

    if(S==T):
        print('Yes')
        return
    if(count_diff(S,T)):
        print('No')
        return
    
    #操作の時間
    length_S = len(S)
    ch_S = S
    for i in range(length_S):
        ch_S = ch_S[length_S-1] + ch_S[0:length_S-1]
        if(ch_S == T):
            print('Yes')
            return
    print('No')



if __name__ == "__main__":
    main()

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

	int N;
	cin >> N;
	vec(A);
	vec(B);
	fx(N) {
		vecp(A);
		vecp2(B);
	}

	sorts(A);
	sorts(B);
	if (N%2==0) {
		int r = N / 2 - 1, l = N / 2;
		ce((B[l]+B[r]-A[r]-A[l])+1)
	}
	else {
		int i = (N+1)/2-1;
		ce(B[i] - A[i] +1)
	}

    return 0;
}



Measured memory_bytes: 5000
#include <stdio.h>
int main(void){
    int k,s;
    scanf("%d %d",&k,&s);
    int i,j,z,ans;
    for(i=0;i<=k;i++){
        for(j=0;j<=k;j++){
            z=s-i-j;
            if(z>=0&&z<=k)ans++;
            }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
import sys

N = int(sys.stdin.readline())
A = [int(i) for i in sys.stdin.readline().split(' ')]
stocks = [0] * N
money = 1000

for i in range(0, N):
    if i == N - 1:
        for j in range(0, i):
            money += stocks[j] * A[i]
            stocks[j] = 0
    elif A[i+1] < A[i]:
        for j in range(0, i):
            money += stocks[j] * A[i]
            stocks[j] = 0
    elif A[i+1] > A[i]:
        stocks[i], money = divmod(money, A[i])

print(money)

Measured memory_bytes: 9204