akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string nm;
  cin>>nm;
  int cnt=0;
  int ans=0;
  for(int i=0;i<3;i++)
  {
    if(nm[i]=='R')
      cnt++;
    else
    {
      if(cnt>ans)
		ans=cnt;
      cnt=0;
    }
  }
  if(cnt>ans)
    ans=cnt;
  cout<<ans<<endl;
}

Measured memory_bytes: 3540
#include<iostream>
using namespace std;
int a[4][3][10] = {0};
int main() {
	int b, f, r, v, n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1] += v;
	}
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 3; j++){
			for (int k = 0;  k < 10; k++){
				cout << " " << a[i][j][k];
			}
		cout << endl;	
		}
	if (i < 3) cout << "####################" << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  string s;cin>>s;
  int c=0;
  rep(i,3)if(s[i]=='1')c++;
  cout<<c<<endl;
  return 0;
}

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

using namespace std;

//#define MD 100010

int main(){
    int n;
    cin>>n;
    vector<long int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    long int ansl=0,ansr=0,ma=0;
    sort(v.begin(),v.end());
    
    ansl=v[n-1];
    
    auto l = lower_bound(v.begin(),v.end(),ansl/2);
    if(*l==ansl/2){
        ansr=*l;
    }else if(*l==ansl){
        ansr=v[distance(v.begin(),l)-1];
    }else{
        if(distance(v.begin(),l)==0){
            ansr=*l;
        }else if(ansl%2==0){
            long int tmp1=abs(ansl/2-v[distance(v.begin(),l)]);
            long int tmp2=abs(ansl/2-v[distance(v.begin(),l)-1]);
            if(min(tmp1,tmp2)==tmp1){
                ansr=v[distance(v.begin(),l)];
            }else{
                 ansr=v[distance(v.begin(),l)-1];
            }
        }else{
            long int tmp1=abs((ansl/2+1)-v[distance(v.begin(),l)]);
            long int tmp2=abs((ansl/2+1)-v[distance(v.begin(),l)-1]);
            if(min(tmp1,tmp2)==tmp1){
                ansr=v[distance(v.begin(),l)];
            }else{
                 ansr=v[distance(v.begin(),l)-1];
            }
        }
    }
    
    cout<<ansl<<" "<<ansr<<endl;
    return 0;
}

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

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

using namespace std;

const int N = (int)1e5 + 7;

int dp[N];
int used[N];
int n, m;
vector < int > gr[N];

void dfs(int v) {
	used[v] = 1;
	for (int to : gr[v]) {
		if (!used[to]) {
			dfs(to);
		}
		dp[v] = max(dp[v], dp[to] + 1);
	}
}

main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		gr[a].push_back(b);
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			dfs(i);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
		//cout << dp[i] << ' ';
	}
	//cout << endl;
	cout << ans;
}


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

typedef long long ll;

const int mod = 1000000007;
const int INF = 101234567;



int main() {
    ll A, B;
    ll g;
    ll ans = 0;
    cin >> A >> B;
    g = __gcd(A, B);
    vector<ll>v;
    for (ll i = 2; i*i <= g; i++) {
        if (g % i == 0) {
            ans++;
        }
        while (g % i == 0) {
            g /= i;
        }
    }
    if (g != 1) {
        ans++;
    }
    cout << ans+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
    int N;

    cin >> N;

    vector<int> x(N), y(N);

    for(int i = 0; i < N; i ++){
        cin >> x[i] >> y[i];
    }
    double r_min = 2000;

    for(int i = 0; i < N - 1; i ++){
        for(int j = i + 1; j < N; j ++){
            double r = 0.5 * sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i]));
            double c_x = 0.5 * (x[j] + x[i]);
            double c_y = 0.5 * (y[j] + y[i]);

            if(r >= r_min){
                continue;
            }
            int l;

            for(l = 0; l < N; l ++){
                if((x[l] - c_x) * (x[l] - c_x) + (y[l] - c_y) * (y[l] - c_y) > r * r + 1e-8){
                    break;
                }
            }
            if(l < N){
                continue;
            }
            if(r < r_min){
                r_min = r;
            }
        }
    }
    for(int i = 0; i < N - 2; i ++){
        for(int j = i + 1; j < N - 1; j ++){
            for(int k = j + 1; k < N; k ++){
                double a = 2 * (x[j] - x[i]);
                double b = 2 * (y[j] - y[i]);
                double d = x[i] * x[i] - x[j] * x[j] + y[i] * y[i] - y[j] * y[j];
                double e = 2 * (x[k] - x[j]);
                double f = 2 * (y[k] - y[j]);
                double g = x[j] * x[j] - x[k] * x[k] + y[j] * y[j] - y[k] * y[k];

                double r, c_x, c_y;
                
                if(abs(a * f - b * e) <= 1e-8 || abs(b * e - a * f) <= 1e-8){
                    r = 0.5 * sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
                    c_x = 0.5 * (x[i] + x[j]);
                    c_y = 0.5 * (y[i] + y[j]);

                    double r2 = 0.5 * sqrt((x[i] - x[k]) * (x[i] - x[k]) + (y[i] - y[k]) * (y[i] - y[k]));

                    if(r2 > r){
                        r = r2;
                        c_x = 0.5 * (x[i] + x[k]);
                        c_y = 0.5 * (y[i] + y[k]);
                    }
                    r2 = 0.5 * sqrt((x[j] - x[k]) * (x[j] - x[k]) + (y[j] - y[k]) * (y[j] - y[k]));

                    if(r2 > r){
                        r = r2;
                        c_x = 0.5 * (x[j] + x[k]);
                        c_y = 0.5 * (y[j] + y[k]);
                    }
                }else{
                    c_x = (-f * d + b * g) / (a * f - b * e);
                    c_y = (-d * e + a * g) / (b * e - a * f);
                    r = sqrt((x[i] - c_x) * (x[i] - c_x) + (y[i] - c_y) * (y[i] - c_y));
                }
                if(r >= r_min){
                    continue;
                }
                int l;

                for(l = 0; l < N; l ++){
                    if((x[l] - c_x) * (x[l] - c_x) + (y[l] - c_y) * (y[l] - c_y) > r * r + 1e-8){
                        break;
                    }
                }
                if(l < N){
                    continue;
                }
                if(r < r_min){
                    r_min = r;
                }
            }
        }
    }
    cout << fixed;
    cout << setprecision(8) << r_min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

const static int INF = 1e8;
const static D EPS = 1e-8;

int main(){
  int n;
  cin >> n;
  vector<pii> a(n);
  rep(i,n){
    cin >> a[i].fs; a[i].sc = i;
  }

  sort(all(a));

  int ans = 0;
  rep(i,n){
    if( (i&1) ^ (a[i].sc&1) ) ans++;
  }
  cout << ans/2 << endl;
}


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

int main() {

    int n; cin >> n;
	int accumIndex = 0;
	vector<int> startIndex(n);
	vector<int> endIndex(n);
	vector<pair<int, int>> c;
	for (int i = 0; i < n; i++) {
		startIndex[i] = accumIndex;
		int a; cin >> a;
		for (int j = accumIndex; j < accumIndex + a; j++) {
			int x, y; cin >> x >> y;
			--x;
			c.push_back({ x,y });
		}
		accumIndex += a;
		endIndex[i] = accumIndex;
	}	
	int ans = 0;
	for (int bit = 0; bit < (1 << n); ++bit) {
		int truePersonCnt = 0;
		vector<int> truePerson(n, false);
		for (int i = 0; i < n; ++i) {
			if (bit & (1 << i)) {
				truePerson[i] = true;
				truePersonCnt++;
			}
		}
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (!truePerson[i]) continue;
			for (int j = startIndex[i]; j < endIndex[i]; j++) {
				int x = c[j].first;
				int y = c[j].second;
				if (y == 1) {
					if (!truePerson[x]) ok = false;
				}
				else { // y == 0
					if (truePerson[x]) ok = false;
				}
			}
		}
		if(ok) ans = max(ans, truePersonCnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
import math

A, B, H, M = map(int, input().split())

H_x = A*math.sin(math.radians(30*H+0.5*M))
H_y =  A*math.cos(math.radians(30*H+0.5*M))
M_x = B*math.sin(math.radians(6*M))
M_y =  B*math.cos(math.radians(6*M))
print(math.sqrt((H_x-M_x)**2+(H_y-M_y)**2))

Measured memory_bytes: 9512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

int A[52][52];
int B[52][52];

void keisan(int x, int y) {
	if ((B[x - 1][y] == 0 || B[x - 1][y] > B[x][y] + 1) && A[x - 1][y] == 1) {
		B[x - 1][y] = B[x][y] + 1;
		keisan(x - 1, y);
	}
	if ((B[x + 1][y] == 0 || B[x + 1][y] > B[x][y] + 1) && A[x + 1][y] == 1) {
		B[x + 1][y] = B[x][y] + 1;
		keisan(x + 1, y);
	}
	if ((B[x][y - 1] == 0 || B[x][y - 1] > B[x][y] + 1) && A[x][y - 1] == 1) {
		B[x][y - 1] = B[x][y] + 1;
		keisan(x, y - 1);
	}
	if ((B[x][y + 1] == 0 || B[x][y + 1] > B[x][y] + 1) && A[x][y + 1] == 1) {
		B[x][y + 1] = B[x][y] + 1;
		keisan(x, y + 1);
	}
}

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

	int H, W;
	cin >> H >> W;
	int black = 0;
	rep1(i, H) {
		string S;
		cin >> S;
		rep1(ii, W) {
			if (S[ii - 1] == '.') A[i][ii] = 1;
			else black++;
		}
	}

	B[1][1] = 1;
	keisan(1, 1);

	//rep1(i, H) {
	//	rep1(ii, W) {
	//		if (B[i][ii] < 10) cout << " ";
	//		if (B[i][ii] < 100) cout << " ";
	//		cout << B[i][ii];
	//	}
	//	cout << endl;
	//}





	if (B[H][W] == 0) co(-1);
	else co(H*W - B[H][W] - black);

	Would you please return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<map>
#include<string>

using namespace std;
const int INF = 1<<30;
typedef long long int ll;

int main(){
	int n;ll ans=1;cin>>n;
	string s;cin>>s;
	map<char, int> count;
	for(int i=0;i<n;i++){
		count[s[i]]++;
	}
	for(auto itr=count.begin();itr!=count.end();itr++){
		ans*=(ll)max(1, itr->second+1);
        ans%=(ll)1e9+7;
	}
	cout << (ans-1+(ll)1e9+7)%ll(1e9+7) << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int now[60];
int main(){
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		queue<int>A;
		queue<int>B;
		queue<int>C;
		for(int i=0;i<a;i++)now[i]=i;
		while(b--){
			int c;scanf("%d",&c);
			for(int i=0;i<a/2;i++)B.push(now[i]);
			for(int i=a/2;i<a;i++)A.push(now[i]);
			while(C.size()!=a){
				for(int i=0;i<c;i++)if(A.size()){
					C.push(A.front());A.pop();
				}
				for(int i=0;i<c;i++)if(B.size()){
					C.push(B.front());B.pop();
				}
			}
			for(int i=0;i<a;i++){
				now[i]=C.front();C.pop();
			}
		}
		printf("%d\n",now[a-1]);
	}
}

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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  string s1,s2,s3;

  cin >> s1 >> s2 >> s3;
  cout << (char)(s1[0] - 32) << (char)(s2[0] - 32) << (char)(s3[0] - 32) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string O,E,D;
  cin>>O>>E;
  int N,M;
  N=O.size();
  M=E.size();
  for(int i=0;i<M;i++){
    D+=O.at(i);
    D+=E.at(i);
  }
  if(N!=M)
    D+=O.at(N-1);
    cout<<D<<endl;
}

Measured memory_bytes: 3624
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
div = [0] * 1000005

A = list(map(int, input().split()))

for num in A:
    if div[num] == 0:
        for i in range(num, 1000005, num):
            div[i] += 1
    else:
        div[num] += 1
ans = 0
for num in A:
    if div[num] == 1:
        ans += 1

print(ans)

Measured memory_bytes: 132540
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include<queue>
#include <sstream>
#include <set>
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    string S;
    cin >> S;
    int size = S.size();
    int c;
    vector<int> ans(size);
    int z=0;
    for(int i=0;i<size;i++){
        
        if(S[i] == '0'){
            ans[z]=0;
            z++;
        }else if(S[i]=='1'){
            ans[z]=1;
            z++;
        }else{
            if(z>0){
                z--;
            }else{
                continue;
            }
        }
        if(i==size-1){
            c = z;
        }
    }
    
    REP(i,c){
        cout << ans[i];
    }
    cout << endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static int[] g,f;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var h=new int[26];
		int p=0;
		for(int i = 0;i<s[0];i++) {
			var e=sc.S;
			if(h[e[0]-'A']==0){p++;}
			h[e[0]-'A']++;
		}
		g=new int[p];
		f=new int[p];
		var li=new List<int>();
		for(int i = 0,j=0;i<26;i++) {
			if(h[i]!=0){
				g[j]=h[i];
				j++;
			}
		}
		Array.Sort(g);
		f[0]=g[0];
		for(int i = 1;i<f.Length;i++) {f[i]=g[i]+f[i-1];}
		int lb=-1,ub=s[0]+1,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(!Fu(mid,s[1])){ub=mid;}
			else{lb=mid;}
		}
		Console.WriteLine(lb);
	}
	static bool Fu(long n,long k){
		int p=g.Bs((int)n,true);
		return (p==-1?0:f[p])+(g.Length-p-1)*n>=n*k;
	}
}
static class Ex1{
	public static int Bs(this int[] a,int x,bool b){return Bs2(a,x,b,a.Length);}
	public static int Bs(this int[] a,int x,bool b,int ub){return Bs2(a,x,b,ub+1);}
	private static int Bs2(int[] a,int x,bool b,int ub){
		int lb=-1,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(a[mid]>=x){ub=mid;}
			else{lb=mid;}
		}
		return b?lb:ub;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#include<iostream>
using namespace std;
int main()
{
    long long n,m,sum=0;
    long long a;
    cin>>n>>m;
    while(m--)
    {
        cin>>a;
        sum+=a;
    }
    if(sum<=n)
    {
        cout<<n-sum<<endl;
    }
    else if(n<sum)
    {
        cout<<"-1"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3616
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;

int main(){
	int x, n;
	cin>>x>>n;
	if(n==0){
		cout<< x <<'\n';
		return 0;
	}	
	std::vector<int> p(n);
	for(int i=0; i<n; i++)cin>>p[i];
	

	int min = *std::min_element(p.begin(), p.end());
	int max = *std::max_element(p.begin(), p.end());
	//cout<<"max:"<<max<<" min:"<<min<<'\n';
	int diff=1000;
	int ans=0;
	for(int i=0; i<=101; i++){
		if(std::find(p.begin(), p.end(), i)==p.end()){
			// not inclued

			if(diff>=abs(x-i)){
				diff=abs(x-i);
				if(ans<=i)ans=i;
			}
		}
	}
	for(int i=0; i<=101; i++){
		if(std::find(p.begin(), p.end(), i)==p.end()){
			// not inclued
			//cout<<"i:"<<i<< " diff:"<<diff<<" abs(x-i):"<<abs(x-i)<<'\n';
			if(diff==abs(x-i)){
				cout<<i<<'\n';
				return 0;
			}
			
		}
	}
	cout<<x<<'\n';
	return 0;
	
}

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

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,n,a) for (int i=n-1;i>=a;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define SZ(x) ((x).size())
#define i0(x) memset(x,0,sizeof(x))
#define i1(x) memset(x,-1,sizeof(x))
#define el cout<<endl
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007
#define N 100000
#define M 500000

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
typedef long double lld;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n>>m;
    ll cnt=0;
    rep(i,0,m)
    {
        ll x;
        cin>>x;
        cnt+=x;
    }
    cout<<max(ll(-1),n-cnt);
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  if(S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  if(S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  if(S == "Rainy"){
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}

ll modinv(ll a, ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
ll calc_d(ll n,ll a){
  ll v = 1;
  for(ll i=1;i<=a;i++){
    v *= (n-i+1);
    v %= MOD;
    v *= modinv(i,MOD);
    v %= MOD;
  }
  return v;
}
ll calc(ll n, ll p){
    if(p==0) return 1;
    if(p%2==0){
        ll t = calc(n, p/2);
        return t*t % MOD;
    }
    return n * calc(n, p-1);
}
signed main(){
  init_io();
  ll n,a,b,ans=1;
  cin >> n >> a >> b;
  ans = calc(2,n);
  ans -= 1;
  ans -= calc_d(n,a);
  ans -= calc_d(n,b);
  while(ans<0) ans += MOD;
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc168/tasks/abc168_c

import math


# A: 時針の長さ B: 分針の長さ 
# H時M分
A, B, H, M = map(int, input().split())


# AとBの間の角度
A_degree = H*60*(1/360) + M*(1/360)
B_degree = M*(1/30)
AB_degree = abs((A_degree - B_degree)) * math.pi

if AB_degree >= math.pi:
    AB_degree = 2*math.pi - AB_degree


# 余弦定理
d = math.sqrt(A**2 + B**2 - 2*A*B * math.cos(AB_degree))

print(d)



Measured memory_bytes: 9436
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb push_back;
#define sp " ";
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    map<lli,lli> plus,mins;
    int n;
    cin>>n;
    lli ans=0;
    rep(i,n){
        int ai;
        cin>>ai;
        (plus.count(ai+i+1)?plus.at(ai+i+1)+=1:plus[ai+i+1]=1);
        (mins.count(i+1-ai)?mins.at(i+1-ai)+=1:mins[i+1-ai]=1);
    }
    for(auto v:mins){
        if(v.first<0) continue;
        if(plus.count(v.first)){
            ans+=v.second*plus.at(v.first);
        }
    }
    out(ans);
}

Measured memory_bytes: 26796
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x <<  " " << x << endl;
#define all(x) x.begin(), x.end()
typedef std::vector<string> vs;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef long long ll;
typedef std::vector<ll> vl;
typedef std::vector<vector<ll>> vvl;
const int inf = 1e9 + 5;

template <typename T>
void print(T v){ for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(2)<<*i<<" ";cout<<endl; }
template <typename T>
void print_vv(T v, bool same_line=true){
for(auto i= 0; i<v.size(); i++){cout<<"{";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(3)<<v[i][j]<<",";}cout<<"},";if(same_line) cout<<endl;}cout<<endl;}

int main(){
    int n; 
    while(cin>>n){
        vl a(n);
        for(int i=0; i<n; i++)
            cin>>a[i];
        
        vvl dp(n, vl(n));

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

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

Measured memory_bytes: 70784
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

/*
4
10 30 40 20

30

6
30 10 60 10 60 50

40
 */
public class Main {
    // 頂点番号，各頂点から出る複数のエッジ
    static List<Edge>[] graph;

    // 最短コスト
    static int[] dist;
    static long[] mindist;

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

        dist = new int[N];
        for (int i = 0; i < N; i++) {
            dist[i] = scanner.nextInt();
        }

        graph = new List[N];
        for (int i = 0; i < N; i++) {
            graph[i] = new ArrayList<>();
            if (i <= N - 2) {
                graph[i].add(new Edge(i + 1, Math.abs(dist[i] - dist[i + 1])));
            }
            if (i <= N - 3) {
                graph[i].add(new Edge(i + 2, Math.abs(dist[i] - dist[i + 2])));
            }
        }

//        debug();

        mindist = new long[N];
        solve_0();
//        solve_1(0);
        System.out.println(mindist[N - 1]);
//        System.out.println(Arrays.toString(mindist));
    }

    static void solve_0() {
        Arrays.fill(mindist, Long.MAX_VALUE);
        mindist[0] = 0;
        mindist[1] = Math.abs(dist[1] - dist[0]);

        for (int i = 2; i < mindist.length; i++) {
            long a = mindist[i - 1] + Math.abs(dist[i] - dist[i - 1]);
            long b = mindist[i - 2] + Math.abs(dist[i] - dist[i - 2]);
            mindist[i] = Math.min(a, b);
        }
    }


    static void solve_1(int v) {
        Arrays.fill(mindist, Long.MAX_VALUE);
        mindist[v] = 0;

        PriorityQueue<Vertex> pq = new PriorityQueue<>(
                ((v1, v2) -> v1.dist < v2.dist ? -1 : 1)
        );

        pq.add(new Vertex(v, mindist[v]));
        while (!pq.isEmpty()) {
            Vertex now = pq.poll();

            if (now.dist > mindist[now.id]) {
                continue;
            }

            for (Edge edge : graph[now.id]) {
                if (mindist[edge.to] > mindist[now.id] + edge.cost) {
                    mindist[edge.to] = mindist[now.id] + edge.cost;
                    pq.add(new Vertex(edge.to, mindist[edge.to]));
                }
            }
        }

    }

    static void debug() {
        for (int i = 0; i < graph.length; i++) {
            for (Edge edge : graph[i]) {
                System.out.println(i + " -> " + edge.to + ": " + edge.cost);
            }
            System.out.println();
        }
    }
}

// エッジに関するクラス
class Edge {
    int to, cost;

    public Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }
}

// 頂点に関するクラス
class Vertex {
    int id;
    long dist;

    public Vertex(int id, long dist) {
        this.id = id;
        this.dist = dist;
    }
}

Measured memory_bytes: 56908
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int, int>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define INF 1e15
ll dp[105][100005];


int main()
{   
    fastio
    ll mod = 1e9+7;
    int n;cin>>n;
    int k;cin>>k;
    vector< ll> arr(n+1);
    for(int i = 0 ;i<n;i++)
    {
        cin>>arr[i+1];
        
    }

    
    for(int i = 0 ; i<=k;i++)dp[0][i] = 1;
    for(int i = 1 ; i<=n;i++)
    {      
        for(int j = 0;j<=arr[i];j++)
            dp[i][j] = dp[i-1][j];

        for(int j = arr[i]+1;j<=k;j++)
        {
            dp[i][j] = dp[i-1][j]-dp[i-1][j-arr[i]-1];
            dp[i][j] = (mod + dp[i][j])%mod;
        }

        for(int j =1;j<=k;j++)
        {
            dp[i][j] = (dp[i][j]+dp[i][j-1])%mod;
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
        
    }

    dp[n][k] = (dp[n][k]-dp[n][k-1]+mod)%mod;
    cout<<dp[n][k]<<endl;
    return 0;
} 


Measured memory_bytes: 80128
//Symoon
import java.util.Scanner;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		//Scanner myObj = new Scanner(System.in);
		Scanner ret = new Scanner(System.in);
		
		String s,s1="";
		int i,t,n;
		n=ret.nextInt();
		if(n>=30)
		 System.out.println("Yes");
		else
		System.out.println("No");
			
	
	}

}

Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
#define MAXN 2000005
lli f[MAXN];

lli powmod(lli a,lli b){
	lli ans = 1ll;
	while(b){
		if(b&1ll) ans = (ans * a)%mod;
		b>>=1;
		a = (a*a) % mod;
	}
	return ans%mod;
}

lli inv(lli a){
	return powmod(a,mod-2)%mod;
}

lli ncr(lli n, lli r){
	return (f[n] * (inv((f[r] * f[n-r])%mod))%mod ) % mod;
}

void pre(){
	f[0] = 1ll;
	for(int i=1; i < MAXN; i++){
		f[i] = (1ll * i * f[i-1]) % mod;
	}
}

int main(){__
	int k;
	pre();
	cin >> k;
	string s;
	cin >> s;
	int n = k + (int) s.size();
	lli ans = powmod(26ll,n);
	for(int i=0; i < (int)s.size(); i++){
		lli res = ncr(n,i);
		res = (res * powmod(25ll,n-i)%mod)%mod;
		ans = (ans + mod - res) % mod;
	}
	cout << ans%mod << endl;
	return 0;
}


Measured memory_bytes: 19872
use std::io::*;

fn ext_gcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    if b == 0 {
        *x = 1;
        *y = 0;
        a
    } else {
        let d = ext_gcd(b, a % b, y, x);
        *y -= (a / b) * *x;
        d
    }
}
fn mod_inv(a: i64, m: i64) -> i64 {
    let mut x = 0;
    let mut y = 0;
    ext_gcd(a, m, &mut x, &mut y);
    if x < 0 {
        x += m;
    }
    x % m
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let s: Vec<usize> = s
        .trim()
        .chars()
        .map(|c| c.to_digit(10).unwrap() as usize)
        .collect();
    let n = s.len();
    let mut sum = vec![0; 3030];
    let mut now = 0;
    let mut ten = 1;
    let mut ans = 0;
    let teninv = mod_inv(10, 2019);
    sum[0] = 1;
    for i in 0..n {
        now = (now * 10 + s[i]) % 2019;
        ten = ten * teninv % 2019;
        ans += sum[now * ten as usize % 2019];
        sum[now * ten as usize % 2019] += 1;
    }
    println!("{}", ans);
}


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

int y1, m1, d1, y2, m2, d2;

int abss(int a)
{
    if(a < 0)return -a;
    else return a;
}

signed main()
{
    cin >> y1 >> m1 >> d1;
    cin >> y2 >> m2 >> d2;
    if(y1 > y2){
        swap(y1, y2);
        swap(m1, m2);
        swap(d1, d2);
    }
    else if(y1 == y2){
        if(m1 > m2){
            swap(y1, y2);
            swap(m1, m2);
            swap(d1, d2);
        }
        else if(m1 == m2){
            if(d1 > d2){
                swap(y1, y2);
                swap(m1, m2);
                swap(d1, d2);
            }
        }
    }
    if(m1 == m2 && d1 == d2){
        cout << abss(y1 - y2) << endl;
    }
    else if(m1 > m2 || m1 == m2 && d1 > d2){
        cout << abss(y1 - y2) << endl;
    }
    else{
        cout << abss(y1 - y2) + 1 << endl;
    }


    return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(c)      \
	for (auto i : c) \
		cout << i << ' ';

void solve()
{
	int n, i = 0;
	cin >> n;
	deque<int> dq;
	if (n & 1)
	{
		rep(i, 0, n)
		{
			int x;
			cin >> x;
			if (i & 1)
			{
				dq.push_back(x);
			}
			else
			{
				dq.push_front(x);
			}
		}
	}
	else
	{
		rep(i, 0, n)
		{
			int x;
			cin >> x;
			if (i & 1)
			{
				dq.push_front(x);
			}
			else
			{
				dq.push_back(x);
			}
		}
	}
	peek(dq);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)

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

	ll n,a,b;
	cin >> n >> a >> b;
	ll mina=0,biga=0,bigb=0;
	FOR(i,0,n){
		ll k;
		cin >> k;
		if(k<=a){
			mina++;
		}else if(k<=b){
			biga++;
		}else{
			bigb++;
		}
	}
	cout << min({mina,bigb,biga}) << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,K; cin>>N>>K;
	ll ans = K;
	rep(i,N-1)ans *= (K-1);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

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

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  while(cin >> N, N) {
    pair<int,int> x[1001];
    int rsum = 0, wsum = 0;
    rep(i, N) {
      cin >> x[i].first >> x[i].second;
      rsum += x[i].first;
      wsum += x[i].second;
    }
    sort(x, x+N);
    int rx = x[N-1].first;
    if(rsum-rx >= rx) {
      cout << rsum+wsum << endl;
      continue;
    }
    bool dp[1001] = {};
    dp[0] = true;
    rep(i, N-1) {
      for(int j = rx-(rsum-rx); j >= x[i].second; j--) {
	if(dp[j-x[i].second]) dp[j] = true;
      }
    }
    int ans = 0;
    rep(i, rx-(rsum-rx) + 1) {
      if(dp[i]) ans = i;
    }
    cout << rx+rx+wsum-ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;

int main() {
    int N;
    cin >> N;
    bool a = false;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    sort(all(A));
    ll ans = 1;
    for(int i = 0; i < N; i++) {
        ans*=A[i];
        if(ans > (ll)1e18 || ans < 1) {
            a = true;
        }
    }
    if(a) {
        cout << -1 << endl;
    }
    else {
        cout << ans << endl;
        return 0;
    }
}

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

string s;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s;
	bool a = false, b = false;
	for(auto i : s)
		if(i == 'A') a = true;
		else if(i == 'B') b = true;
	if(a && b) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int N,T,C=0;
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
    scanf("%d",&T);
    if(i!=T) C++;
  }
  if(C<=2) printf("YES\n");
  else printf("NO\n");
  return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    long double aa;
    long double bb;
    long double cc;
    cin >> aa >> bb >> cc;

    long double dd = cc - bb -aa;
    if((dd > 0) && ((dd * dd) > (4 * aa * bb))){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
    #define ll long long
    #define ara(A,N) sort(A,A+N)
    #define rev(A,N) sort(A,A+N,greater<long long>())
    using namespace std;
    int main()
{
set<char>s;
int f=0;
string p;
char x;
char i;
cin>>p;
for(i='a';i<='z';i++)
{
    if(p.find(i)==string::npos)
    {    f=1;
        break;
    }
}
if(f)
cout<<i<<endl;
else
{
    cout<<"None"<<endl;
}
}


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


int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);

	for (int i = 1; i <= n; i++) {
		cin >> a[i]; 
	}
	vector<int> b(n + 1);

	int count = 0;
	for (int i = n; i >= 1; i--) {
		int total = 0;
		for (int j = i + i; j <= n; j+= i) {
			total += b[j];
		}
		b[i] = (a[i] + total) % 2;
		if (b[i] == 1) count ++;
	}
	cout << count << endl;
	for (int i = 1; i <= n; i++) {
		if (b[i] == 1)
			cout << i << " ";
	}
	if (count > 0) {
		cout << endl;
	}
	return 0;

}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int d[n+1];
  for(int i=0;i<n;i++){
    cin>>d[i];
    d[i]+=24;
  }
  d[n]=24;
  sort(d,d+n+1);
  vector<int>v,w;
  int ans=100000;
  for(int i=0;i<n+1;i++){
    if(i%2==0){
      v.push_back(72-d[i]);
      v.push_back(48-d[i]);
      w.push_back(d[i]);
    }
    else{
      w.push_back(72-d[i]);
      w.push_back(48-d[i]);
      v.push_back(d[i]);
    }
  }
  sort(v.begin(),v.end());
  sort(w.begin(),w.end());
  for(int i=0;i<v.size()-1;i++){
    ans=min(ans,v[i+1]-v[i]);
  }
  for(int i=0;i<w.size()-1;i++){
    ans=min(ans,w[i+1]-w[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
N, L =map(int, input().split())
cost = 1001
count = 0
for i in range(N):
  c, t =map(int, input().split())
  if t <= L:
    if c < cost:
      cost = c
      count += 1
  elif t > L:
    continue;
if count == 0:
  print("TLE")
else:
  print(cost)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    K=int(input())
    str_N=str(N)
    M=len(str(N))
    dp=[[[0]*2 for _ in range(K+1)] for _ in range(M+1)]
    dp[0][0][0]=1
    for keta in range(M):
        dp[keta+1][0][1]=dp[keta][0][0]+dp[keta][0][1]
        for k in range(K):
            dp[keta+1][k+1][1]=dp[keta][k][0]*(max(int(str_N[keta])-1,0))+dp[keta][k][1]*9+dp[keta][k+1][1]
            if int(str_N[keta])==0:
                dp[keta+1][k+1][0]=dp[keta][k+1][0]
            else:
                dp[keta+1][k+1][0]=dp[keta][k][0]
                dp[keta+1][k+1][1]+=dp[keta][k+1][0]
    ans=sum(dp[M][K])
    print(ans)
                

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
n, k = map(int, input().split())
*A, = map(int, input().split())
A = [0] + A
DP = [[None for j in range(60)] for i in range(n + 1)]
for i in range(n + 1):
    DP[i][0] = A[i]
for j in range(1, 60):
    for i in range(n + 1):
        DP[i][j] = DP[DP[i][j - 1]][j - 1]
K = list(bin(k)[2:][::-1])
i = 1
for j, b in enumerate(K):
    if b == '1':
        i = DP[i][j]
print(i)


Measured memory_bytes: 206616
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  string s, t;
  int q, a, b, c, d;
  cin >> s >> t >> q;
  vector<int> scnt(s.size()), tcnt(t.size());
  if(s[0] == 'A')scnt.at(0) = 1;
  else scnt.at(0) = 2;
  if(t[0] == 'A')tcnt.at(0) = 1;
  else tcnt.at(0) = 2;
  for(int i = 1; i < s.size(); i++) {
    int now;
    if(s[i] == 'A')now = 1;
    else now = 2;
    scnt.at(i) = scnt.at(i-1) + now;
  }
  for(int i = 1; i < t.size(); i++) {
    int now;
    if(t[i] == 'A')now = 1;
    else now = 2;
    tcnt.at(i) = tcnt.at(i-1) + now;
  }
  rep(i, q) {
    cin >> a >> b >> c >> d;
    if((scnt[b-1] - scnt[a-2]) % 3 == (tcnt[d-1] - tcnt[c-2]) % 3)
      cout << "YES" << endl;
    else 
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define all(x) (x).begin(),(x).end()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)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;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	string s; cin >> s;
	int score = 0;
	rep(i, n - 1) {
		if (s[i] == s[i + 1])score++;
	}
	int ans = min(score + 2 * k, n - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

int main(int argc, char const *argv[]) {
  int Mid_score=0,Final_score=0,Retest_score=0;

  while(1){
    int grade=0;
    char rank;
    std::cin >> Mid_score >> Final_score >> Retest_score;
    if(Mid_score==(-1) && Final_score == (-1) && Retest_score == (-1))break;
    grade = Mid_score+Final_score;
    if(grade >= 80){
      rank = 'A';
    }else if(grade >= 65 && grade < 80){
      rank = 'B';
    }else if(grade >= 50 && grade < 65){
      rank = 'C';
    }else if(grade >= 30 && grade < 50){
      if(Retest_score >= 50){
        rank = 'C';
      }else rank ='D';
    }else if(grade < 30){
      rank = 'F';
    }
    
    if(Mid_score==(-1) || Final_score == (-1)){
      rank = 'F';
    }
    std::cout << rank << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

typedef long long LL;
const int N = 1e6 + 10;
LL n, ans, P = 1e9+7;
LL f[N], fac[N], inv[N];

LL lp(LL a, LL b) {
	LL ret = 1;
	for(; b; b >>= 1, a = a * a % P)
		if(b & 1) ret = ret * a % P;
	return ret;
}

int main() {
	LL i;
	scanf("%d", &n); --n;
	if(n == 1) ans = 1;
	else {
		ans = 0;
		fac[0] = 1;
		rep(i, 1, n) fac[i] = fac[i-1] * i % P;
		inv[n] = lp(fac[n], P-2);
		dep(i, n, 1) inv[i-1] = inv[i] * i % P;
		
		
		rep(i, 1, n) 
		if(i-1 >= n-i) {
			f[i] = fac[i-1] /**inv[n-i]%P*/ *inv[i-1-n+i]%P *fac[i]%P /**fac[n-i]%P*/;
			ans = (ans + i * (f[i] - f[i-1] + P) % P) % P;
			//if(f[i] < f[i-1]) printf("%lld %lld %lld\n", i-1, i-1-n+i, i);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<char>>grid(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  vector<vector<long long>>dp(n, vector<long long>(m,0));
  dp[0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] != '#') {
        if (i)
          dp[i][j] = (dp[i][j] + dp[i-1][j]) % ((int) 1e9 + 7);
        if (j)
          dp[i][j] = (dp[i][j] + dp[i][j-1]) % ((int) 1e9 + 7);
      }
    }
  }
  cout << dp[n-1][m-1] << endl;
  return 0;
}

Measured memory_bytes: 9088
N, K = map(int,input().split())
d  = list(map(int,input().split()))

price = N

flag = "like"
ans_flag = 0

while ans_flag == 0:
  for i in range(len(str(price))):
    if int(str(price)[i]) in d:
      flag = "dislike"
  if flag == "dislike":
    price +=1
    flag ="like"
  else:
    ans_flag = 1
print(price)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
 

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

	int debt = 100000;
	for (int i = 0; i < n; ++i)
	{
		debt *= 1.05;
		if (debt % 1000 > 0) debt += 1000;
		debt /= 1000, debt *= 1000;
	}

	cout << debt << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
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 abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int a[5];
	int sum = 0;
	int min = 10;
	REP(i, 5){
		cin >> a[i];
		if (a[i] % 10 != 0 and min > a[i] % 10) min = a[i] % 10;
		if (a[i] % 10 != 0){
			a[i] /= 10;
			a[i]++;
			a[i] *= 10;
		}
		sum += a[i];
	}

	cout << sum - 10 + min << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int x, n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> x >> n;
	pair<int, int> mn = {INT_MAX, -1};
	set<int> inc;
	for(int i = -200; i <= 200; i++) inc.insert(i);
	for(int i = 0; i < n; i++){
		int val;
		cin >> val;
		inc.erase(val);
	}
	for(auto &i : inc) mn = min(mn, make_pair(abs(i - x), i));
	cout << mn.second << "\n";
	return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(b==1)
        cout<<0;
    else{
        int s=a;
        int ans=1;
        while(s<b){
            s+=(a-1);
            ans++;
        }
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

#define ll long long
//FILE *fin = fopen("test.in", "r");
//FILE *fout = fopen("test.out", "w");

int main() {
    int n;
    ll x, y, max = -1, rez;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld%lld", &x, &y);
        if (x > max) {
            max = x;
            rez = x + y;
        }

    }
    printf("%lld", rez);
    return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        List<Integer> A = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> B = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        List<Integer> C = Arrays.stream(sc.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());

//        System.out.println(A.toString());
//        System.out.println(B.toString());
//        System.out.println(C.toString());
        int sum = 0;
        int pre = A.get(0);
        for (Integer a : A) {
            sum += B.get(a - 1);
//            System.out.println(sum);
            if (pre == a - 1) {
//                System.out.println("continue");
                sum += C.get(a - 2);
            }
            pre = a;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 28880