akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;
	vector<int> L(k+1);
	vector<int> R(k+1);
	int work = 0, i = 0;
	while (work < k){
		if (s[i] == 'o'){
			L[work] = i;
			work++;
			i += c+1;
		}else{
			i++;
		}
	}
	work = k-1, i = n-1;
	while (work >= 0){
		if (s[i] == 'o'){
			R[work] = i;
			work--;
			i -= c+1;
		}else{
			i--;
		}
	}
	for (int i = 0; i < k; i++){
		if(L[i] == R[i]) cout << L[i]+1 << endl; 
	}
	return 0;
}

Measured memory_bytes: 3332
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
	ll N;
	cin >> N;
	cout << N * (N - 1) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007


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

Measured memory_bytes: 3592
// abc.cpp : 此檔案包含 'main' 函式。程式會於該處開始執行及結束執行。
//

#include <iostream>
using namespace std;
int main()
{
	long long int X ,K,D,a,N,N1;
	N = 0;
	
	cin >> X>>K>>D;
	
	if (X < 0) {
		X = -X;
	}
	if (X == 0) {
		if (K % 2 == 0) {
			printf("0");
			return 0;
		}
		else {
			printf("%lld", D);
			return 0;
		}
	}
	if (K < X / D) {
		printf("%lld", X - K * D);
		return 0;
	}
	
	if (X % D != 0) {
			
			if ((X - D * (X / D) ) < (-(X - D * ((X / D) + 1)) )) {
				
				if ((K - X / D) % 2==0) {
					printf("%lld", X - D * (X / D));
					return 0;
				}
				else {
					printf("%lld", -(X - D * ((X / D) + 1)));
					return 0;
				}
			}
			else {
				
				if ((K - ((X / D) + 1)) % 2 == 0) {
					printf("%lld", -(X - D * ((X / D) + 1)));
					return 0;
				}
				else {
					printf("%lld", X - D * (X / D));
					return 0;
				}

			}
		}
		else {
			if ((K - X / D) % 2 == 0) {
				printf("0");
				return 0;
			}
			else {
				printf("%lld", D);
				return 0;
			}
		}
	
	
		
	
	
	return 0;
}

// 執行程式: Ctrl + F5 或 [偵錯] > [啟動但不偵錯] 功能表
// 偵錯程式: F5 或 [偵錯] > [啟動偵錯] 功能表

// 開始使用的提示: 
//   1. 使用 [方案總管] 視窗，新增/管理檔案
//   2. 使用 [Team Explorer] 視窗，連線到原始檔控制
//   3. 使用 [輸出] 視窗，參閱組建輸出與其他訊息
//   4. 使用 [錯誤清單] 視窗，檢視錯誤
//   5. 前往 [專案] > [新增項目]，建立新的程式碼檔案，或是前往 [專案] > [新增現有項目]，將現有程式碼檔案新增至專案
//   6. 之後要再次開啟此專案時，請前往 [檔案] > [開啟] > [專案]，然後選取 .sln 檔案


Measured memory_bytes: 3724
from operator import mul
from functools import reduce
def combinations_count(n, r):
    if n<r: return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    K,S = map(int, input().split())
    ans = 0
    # x+y<=Sとなるように回す
    for x in range(K+1):
        for y in range(K+1):
            z = S-(x+y)
            if x+y<=S and 0<=z and z<=K: ans += 1
    print(ans)

main()


Measured memory_bytes: 3700
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
#define N (int)1e5
#define INF (int)1e9
#define mod (int)1e9 + 7
#define LL long long
LL n, a[N], c, d, cnt, cnt2, gyo;
map<LL, LL> b;
int main()
{
	cin >> n;
	gyo = (n + 1) * (n / 2);
	if (n % 2)
		gyo += n / 2 + 1;
	for (int i = 0; i < n; i++)
	{
		scanf("%ld", a + i);
		cnt += a[i];
		cnt2 += cnt / gyo;
		cnt %= gyo;
		if (i)
			b[a[i] - a[i - 1]] = 1;
	}

	if (cnt)
	{
		cout << "NO" << endl;
		return 0;
	}
	for (auto i = b.begin(); i != b.end(); i++)
	{
		d = i->first;
		while (d < cnt2)
		{
			d += n;
		}
		if (d != cnt2)
		{
			cout << "NO" << endl;
			return 0;
		}
	}


	cout << "YES" << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int h, n;
  cin >> h >> n;
  const int nax = 40000 + 42;
  vector<i64> dp(nax, INF);
  dp[0] = 0;
  for (int p = 0; p < n; ++p) {
    int a, b; cin >> a >> b;
    for (int i = 1; i < nax; ++i) {
      i64 cur = b;
      if (i >= a) cur += dp[i - a];
      uin(dp[i], cur);
    }
  }
  i64 ans = INF;
  for (int i = h; i < nax; ++i) uin(ans, dp[i]);
  kek(ans);
}


Measured memory_bytes: 640
///A drunk man will find his way home, but a drunk bird may get lost forever...i
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define pf push_front
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
//const int mx = 1000 * 100 + 5;
int32_t main(){		
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int a, b;
	cin >> a >> b;
	for(int i = 1; i <= 3; i++)
		if(i != a && i != b)
			cout << i << endl;
	return 0;
}


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

int main(){

	int n, x, y, pt1, pt2;

	while(cin >> n){
		pt1 = 0;
		pt2 = 0;
	
		if(n == 0) break;
		
		for(int i=0; i<n; i++){
			cin >> x >> y;
			
			if(x > y) pt1 += x + y;
			else if(x < y) pt2 += x + y;
			else {
				pt1 += x;
				pt2 += y;
			}
		}
		
		cout << pt1 << " " << pt2 << endl;
	}

	return 0;

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define mn 2022
#define mod 924844033
using namespace std;
int i,j,k,l,r,t,n,m,s,f[mn][mn][4],g[mn],h[mn],fac[mn];
int main()
{
    scanf("%d%d",&n,&m);
    fac[0]=1;
    for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
    f[1][0][0]=f[1][1][2]=1;
    for (i=1;i<n;i++)
    for (j=0;j<=i;j++)
    for (k=0;k<=3;k++)
    if (f[i][j][k])
	{
        (f[i+1][j][k>>1]+=f[i][j][k])%=mod;
        if (!(k&1)) (f[i+1][j+1][k>>1]+=f[i][j][k])%=mod;
        (f[i+1][j+1][(k>>1)+2]+=f[i][j][k])%=mod;
    }
    g[0]=1;
    for (r=1;r<=m;r++)
	{
        l=1; t=r;
        while (t+m<=n) {l++; t+=m;}
        for (i=0;i<=n;i++) h[i]=0;
        for (i=0;i<=n;i++) for (j=0;j<=l;j++) for (k=0;k<=1;k++) if (i+j<=n) (h[i+j]+=1ll*g[i]*f[l][j][k]%mod)%=mod;
        for (i=0;i<=n;i++) g[i]=h[i];
    }
    for (i=0;i<=n;i++)
	{
        t=1ll*g[i]*fac[n-i]%mod;
        if (i&1) (s-=t)%=mod; else (s+=t)%=mod;
    }
    printf("%d\n",(s+=mod)%=mod);

}

Measured memory_bytes: 61952
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<string> w(n);
  string ans;
  for(int i=0;i<n;i++) cin>>w[i];
  int len=w[0].size();

  bool flag=true;
  for(int i=1;i<n;i++)
  {
    if(w[i-1].at(len-1)!=w[i].at(0)) flag=false;
    for(int j=0;j<i;j++)
    {
      //同じ文字の判定
      if(w[i]==w[j]) flag=false;
    }
    len=w[i].size();
  }
  if(flag) ans="Yes";
  else ans="No";

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mm(a,b) memset(a,b,sizeof(a))
#define ACCELERATE (ios::sync_with_stdio(false),cin.tie(0))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<long long,long long>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
#define E exp(1.0)
#define db double
#define ll long long
#define ld long double
#define ull unsigned long long
//#define io
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
//#define gc getchar
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
//inline int read()
//{
//    int ret=0,f=0;char c=gc();
//    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
//    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
//    if(f)return -ret;return ret;
//}
string s;
int main()
{
    #ifdef io
    freopen("in.txt","r",stdin);
    #endif
    cin>>s;
    int len=s.size();
    for(int i=0;i<len;i+=2){
        if(s[i]=='L'){puts("No");return 0;}
    }
    for(int i=1;i<len;i+=2){
        if(s[i]=='R'){puts("No");return 0;}
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for(ll i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 0⊕…⊕nを求める関数
ll f(ll n) {
	switch(n%4) {
		case 0:
			return n;
		case 1:
			return 1;
		case 2:
			return (ll)1 ^ n;
		case 3:
			return 0;
	}
	return -1;
}

int main() {
	ll a,b;
	cin >> a >> b;
	ll ans = f(b) ^ f(a-1);
	if (a == 0) ans = f(b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace String
{
    class Card_Game
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var t = 0;
            var h = 0;
            for (int i = 0; i < n; i++)
            {
                var token = Console.ReadLine().Split(' ');
                int com = string.Compare(token[0], token[1], true);
                if (com == 0) { t++; h++; }
                else if (com > 0) t += 3;
                else if (com < 0) h += 3;
            }
            Console.WriteLine(t + " " + h);
        }
    }
}

Measured memory_bytes: 9880
#include<bits/stdc++.h>
using namespace std;
const int maxn = 110;
int a[maxn], b[maxn], a1[maxn], b1[maxn];
int  v[maxn], match[maxn];
int n;
vector < int > g[maxn];
bool dfs(int x){
	int y;
	for(int i = 0; i < g[x].size(); i++){
		y = g[x][i];
		if(!v[y]){
			v[y] = 1;
			if(!match[y] || dfs(match[y])){
				match[y] = x;
				return true;
			}
		}
	}
	return false;
}
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d%d", a + i, b + i);
	}
	for(int i = 1; i <= n; i++){
		scanf("%d%d", a1 + i, b1 + i);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(a[i] < a1[j] && b[i] < b1[j]){
				g[i].push_back(j);
			}
		}
	}
	int ans = 0;
	for(int i  = 1; i <= n; i++){
		memset(v, 0, sizeof(v));
		if(dfs(i))ans++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<cctype>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#pragma GCC optimize(2)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=55;
const int M=3005;
const LL inf=1e18;
const int mod=300;
const double eps=1e-9;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while(!isdigit(ch=getchar())) if(ch=='-') t=-1;
    while(isdigit(ch)){ x=10*x+ch-'0'; ch=getchar(); }
    return x*t;
}
struct edge
{
    LL t,c,v;
    edge(){}
    edge(LL V,LL T,LL C){ v=V; t=T; c=C; }
};
struct node
{
    LL id,co,disx;
    node(){}
    node(LL T,LL C,LL D){ id=T; co=C; disx=D; }
    friend bool operator < (node x,node y)
    {
        return x.disx>y.disx;
    }
};
int vis[N][M];
LL dis[N][M],n,m,s;
priority_queue<node,vector<node>,less<node> > q;
vector<edge> e[N];
void dijk()
{
    for(int i=1;i<=n;i++)
        for(int j=0;j<=2500;j++) dis[i][j]=inf;
    dis[1][min(s,2500LL)]=0;
    q.push(node(1,min(s,2500LL),0));
    while(!q.empty())
    {
        node u=q.top();
        q.pop();
        if(vis[u.id][u.co]) continue;
        vis[u.id][u.co]=1;
        for(auto x:e[u.id])
        {
            LL tmp=min(2500LL,x.c+u.co);
            if(tmp>=0&&dis[x.v][tmp]>dis[u.id][u.co]+x.t)
            {
                dis[x.v][tmp]=dis[u.id][u.co]+x.t;
                q.push(node(x.v,tmp,dis[x.v][tmp]));
            }
        }
    }
}
int main()
{
    n=read(),m=read(),s=read();
    for(int i=1;i<=m;i++)
    {
        LL u=read(),v=read(),c=read(),t=read();
        e[u].pb(edge(v,t,-c));
        e[v].pb(edge(u,t,-c));
    }
    for(int i=1;i<=n;i++)
    {
        LL c=read(),t=read();
        e[i].pb(edge(i,t,c) );
    }
    dijk();
    for(int i=2;i<=n;i++)
    {
        LL mi=inf;
        for(int j=0;j<=2500;j++)
            mi=min(dis[i][j],mi);
        printf("%lld\n",mi);
    }
    return 0;
}



Measured memory_bytes: 7364
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#ifdef __GNUC__
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#endif

#ifdef MSC_VER
#pragma comment(linker, "/STACK:400000000")
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#endif

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())
#define vc vector

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

int H,W,K;
char c[55][55];
int dp[55][55][4][1<<12];
int dy[]={0,1,0,-1};
int dx[]={1,0,-1,0};

int f(int y,int x,int k,int mask){
	int& res=dp[y][x][k][mask];
	if(res!=-1)return res;
	if(y==H && x==W && k==0)return res=0;
	res=0;
	if(isdigit(c[y][x])){
		int Y=y,X=x,d;
		rep(i,2*K){
			d=mask>>(2*i)&3;
			Y-=dy[d],X-=dx[d];
			if(Y==y && X==x)goto fail;
		}
		res=c[y][x]-'0';
		fail:;
	}
	
	int res2=-INF,ny,nx;
	rep(d,2){
		ny=y+dy[d],nx=x+dx[d];
		if(c[ny][nx]!='#'){
			res2=max(res2,f(ny,nx,k,(mask<<2 | d)  & ((1<<4*K)-1)));
		}
	}
	if(k)rep2(d,2,4){
		ny=y+dy[d],nx=x+dx[d];
		if(c[ny][nx]!='#'){
			res2=max(res2,f(ny,nx,k-1,(mask<<2 | d)  & ((1<<4*K)-1)));
		}
	}
	return res+=res2;
}

int main(){
	ios_base::sync_with_stdio(0);
	
	cin>>H>>W>>K;
	rep(i,H+2)rep(j,W+2)c[i][j]='#';
	rep2(i,1,H+1)rep2(j,1,W+1)cin>>c[i][j];
	memset(dp,-1,sizeof(dp));
	cout<<f(1,1,K,0)<<endl;
}

Measured memory_bytes: 194812
n,m = map(int,input().split())
a = list(map(int,input().split()))

bc =[]
for i in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))

bc.sort(key=lambda x:x[1],reverse=True)
newcard=[]
for b,c in bc:
    newcard.extend([c]*b)
    if(len(newcard)>=n):
        break

size = min(n,len(newcard))
a.sort()
for i in range(size):
    if(newcard[i]>a[i]):
        a[i]=newcard[i]
    else:
        break
print(sum(a))

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

#define FOR(x,n) for(int x=0;x<n;x++)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> iPair;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  ll sum = 0;
  vector<int> arr(n);
  FOR(i,n) {
    cin >> arr[i];
    sum += arr[i];
  }

  bool ok = true;
  sort(arr.rbegin(), arr.rend());
  FOR(i,m) {
    if(arr[i]*4*m < sum) ok = false;
  }

  cout << (ok ? "Yes\n" : "No\n");
}

// UPDATE N WHEN UR DONE AAAAAAAAAAAAAAAAAAAAAAAAAAA (if it applies lol)

Measured memory_bytes: 256
c = [list(map(int, input().split())) for i in range(3)]

a = c[1][0] - c[0][0]
b = c[2][0] - c[0][0]
string = "Yes"

for i in range(3):
    x = c[1][i] - c[0][i]
    if x != a:
        string = "No"

    y = c[2][i] - c[0][i]
    if y != b:
        string = "No"

print(string)

Measured memory_bytes: 3064
import java.lang.Math
fun main(args: Array<String>) {
    val (A, B) = readLine()!!.split(" ").map(String::toInt)
    if (A == B) {
        println(2 * Math.max(A, B))
    } else {
        println(2 * Math.max(A, B) - 1)
    }
}

Measured memory_bytes: 37876
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;

int32_t main()
{ int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        cin >> b[i];
        cin >> c[i];
    }
    vector<int> dpa(n), dpb(n), dpc(n);
    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    for (int i = 1; i < n; i++)
    {
        dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a[i];
        dpb[i] = max(dpa[i - 1], dpc[i - 1]) + b[i];
        dpc[i] = max(dpb[i - 1], dpa[i - 1]) + c[i];
    }
    cout << max(dpa[n - 1], max(dpb[n - 1], dpc[n - 1])) << endl;
    return 0;
}

Measured memory_bytes: 4992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true) {
			String[] set = br.readLine().split(" ");
			int m = Integer.parseInt(set[0]);
			int f = Integer.parseInt(set[1]);
			int r = Integer.parseInt(set[2]);
			int sum = m + f;
			if(m == -1 && f == -1 && r == -1) {
				break;
			} else if (m == -1 || f == -1) {
				sb.append("F\n");
			} else if ( sum >= 80) {
				sb.append("A\n");
			} else if (sum >= 65 && sum < 80) {
				sb.append("B\n");
			} else if (sum >= 50 && sum < 65) {
				sb.append("C\n");
			} else if (sum >= 30 && sum < 50) {
				if (r >= 50) {
					sb.append("C\n");
				} else {
					sb.append("D\n");
				}
			} else if (sum < 30) {
				sb.append("F\n");
			}
		}
		System.out.print(sb);
	}
}

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

#define MAX_N (1e8)+1

int main(void){
  vector<bool> eratos(MAX_N, true);
  eratos[0] = eratos[1] = false;
  for(int i = 2; i * i < MAX_N; i++){
    if(eratos[i]){
      for(int j = 2; i * j < MAX_N; j++){
        eratos[i * j] = false;
      }
    }
  }
  
  int n, input, ans = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> input;
    if(eratos[input]){
      ++ans;
    }
  }

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

Measured memory_bytes: 14784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   long a,b,n;
   cin >> a >> b >> n;
   long c = min(b-1,n);
   cout << (a*c)/b-a*(c/b) << endl;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int K;
  cin>>K;
  int ans=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
        ans+=gcd(i,gcd(j,k));
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3632
// Created by Tanuj Jain
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = 3002;

double dp[MAXN][MAXN],prob[MAXN];
bool vis[MAXN][MAXN],N;

double recursive(int N, int heads)
{
	//base case
	if(N<heads)
		return 0.0;
	if(N==0)
		return (heads==0);

	if(vis[N][heads])
		return dp[N][heads];
	else
	{
		//mark the node as visited
		vis[N][heads]=true;
		//find the left and right child values and save it in dp table
		//if i toss the nthe coin i can get a head and a tail
		//if i get a head then i need the ansewer for n-1 and heads-1 
		//if i get a tailt thena i need the answer for n-1 and heads
		return dp[N][heads]=(prob[N]*(recursive(N-1,heads-1))+ (1.0-prob[N])*(recursive(N-1,heads)));
	}
}
int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

	//#ifndef ONLINE_JUDGE
	//freopen("inputf.in","r",stdin);
	//freopen("outputf.in","w",stdout);
	//#endif

	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
		cin>>prob[i];
	double ans=0;
	for(int heads=0;heads<=N;heads++)
	{
		int tails=N-heads;
		if(heads>tails)
		{
			ans+=recursive(N,heads);
		}
	}
	cout<<fixed<<setprecision(9)<<ans;
	
}

Measured memory_bytes: 79232
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    
    def all_group_members(self):
        return_list = [list() for i in range(n)]
        for i in range(n):
          return_list[self.find(i)].append(i)
        return return_list
      
      
n,m = map(int, input().split())
p = [x-1 for x in list(map(int, input().split()))]
key = dict()
for k,v in enumerate(p):
  key[v] = k
Union = UnionFind(n)
xy = [list(map(int, input().split())) for i in range(m)]
for x,y in xy:
  Union.union(x-1,y-1)
a = Union.all_group_members()
ans = 0
for i in a:
  x = set()
  for j in i:
    x.add(key[j])
  y = set(i)
  ans += len(x & y)
print(ans)

Measured memory_bytes: 125556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

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

    int ans = 0;
    if (b >= c + 1) {
        ans = b + c;
    } else {
        if (a + b >= c) {
            ans = b + c;
        } else {
            ans = a + 2 * b + 1;
        }
    }
    cout<<ans<<endl;

    return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

ll dp[105][100005];
int main() {
	ll N,W;
  cin >> N >> W;
  rep(i,W+1)dp[0][i]=0;

  rep(i,N){
    ll w,v;
    cin >> w >> v;

    rep(j,W+1){
      if(j>=w)dp[i+1][j]=max(dp[i][j-w]+v,dp[i][j]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  
  cout << dp[N][W]<< endl;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
int a[12][12];
int c[12];
int main(){
  int n, m, X;
  std::cin >> n >> m >> X;
  int ans = 1<<30;
  
  for(int i = 0; i < n; ++i){
  	std::cin >> c[i];
    for(int j = 0; j < m; ++j){
    	std::cin >> a[i][j]; 
    }
  }
  
  for(int b = 0; b < 1<<n; ++b){
    int tmp = 0;
    std::vector<int> us(m, 0);
    for(int i = 0; i < n; ++i){
      if(b>>i & 1){
        tmp += c[i];
        for(int j = 0; j < m; ++j){
          us[j] += a[i][j];
        }	
      }
    }
    if(std::all_of(us.begin(), us.end(), [&](int x){return x >= X;})){
    	ans = std::min(ans, tmp);
    }
  }
  
  if(ans == 1<<30) ans = -1;
  std::cout << ans << '\n';

  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}


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

int Judge(int x){
    for(int i=2;i<=x/2;i++){
        if(x%i==0)
            return 0;
    }
    return 1;
}

int main()
{
    int N,count=0,k;
    int a[55];
    scanf("%d",&N);
    for(int i=2;i<=55555;i++){
        if(Judge(i)==1&&i%10==3)
        {
            a[count++]=i;
            if(count==N)
                break;
        }
    }
    for(int i=0;i<N;i++){
        cout<<a[i];
        if(i<N-1)
            cout<<" ";
    }




    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

const MODULO: u64 = 1_000_000_007;

struct Combination {
    MOD: u64,
    size: usize,
    fact: Vec<u64>,
    inv_fact: Vec<u64>,
}
impl Combination {
    fn new(size: usize, MOD: u64) -> Self {
        let mut fact = vec![1; size + 1];
        let mut inv_fact = vec![1; size + 1];
        for i in 1..size + 1 {
            fact[i] = fact[i - 1] * i as u64 % MOD;
        }
        inv_fact[size] = Self::modpow(fact[size], MOD - 2, MOD);
        for i in (1..size + 1).rev() {
            inv_fact[i - 1] = inv_fact[i] * i as u64 % MOD;
        }
        Combination {
            MOD,
            size,
            fact,
            inv_fact,
        }
    }
    fn modpow(mut x: u64, mut y: u64, m: u64) -> u64 {
        let mut res: u64 = 1;
        while y > 0 {
            if y & 1 > 0 {
                res = res * x % m;
            }
            x = x * x % m;
            y >>= 1;
        }
        res
    }
    fn modinv(x: u64, m: u64) -> u64 {
        Self::modpow(x, m - 2, m)
    }
    fn nPr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[n - r] % self.MOD
    }
    fn nCr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[r] % self.MOD * self.inv_fact[n - r] % self.MOD
    }
}

#[fastout]
fn main() {
    input!{
        N: usize
    }
    let ncr = Combination::new(N * 2, MODULO);
    let mut ans = 0;
    for i in 1..N/3+1 {
        ans = (ans + ncr.nCr(N-i*3+i-1, i-1)) % MODULO;
    }
    println!("{}", ans);

}


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

int main(){
	int X, Y;
	cin >> X >> Y;

	int ans;
		for(int i=0; i <= X; i++){
			ans = 0;
			
			ans += 2*i;
			ans += 4*(X-i);

			if( ans == Y ){
				cout << "Yes" << endl;
				return 0;
			}
		}

		cout << "No" << endl;
}


Measured memory_bytes: 3616
n = gets.chomp.to_i

array = Array.new(n).map{Array.new(n,0)}
# p array
n.times do |i|
  retu = gets.chomp.split(" ").map(&:to_i)
  retu[1].times do |j|
    array[i][retu[j+2]-1] = 1
  end
end

array.each do |arr|
  output = ""
  arr.each_with_index do |char, i|
    if i == arr.length-1
      output = output + char.to_s + "\n"
    else
      output = output + char.to_s + " "
    end
  end
  print output
end



Measured memory_bytes: 7632
using System;

namespace AGC020
{
    class A
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int N = int.Parse(input[0]);
            int A = int.Parse(input[1]);
            int B = int.Parse(input[2]);
            if ((B - A - 1) % 2 != 0) Console.WriteLine("Alice");
            if ((B - A - 1) % 2 == 0) Console.WriteLine("Borys");
        }
    }
}


Measured memory_bytes: 11092
from scipy import ndimage
import numpy as np

 
H, W = map(int, input().split())
 
A_array = np.array(
    [[0 if s == "#" else 1 for s in input()] for i in range(H)])
# print(A_array)
 
# print(A_array)
b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))

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

int h,w,n;
int sr,sc;
string s,t;

int lr,lc,mr,mc;

int main(){

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

    cin>>h>>w>>n;
    cin>>sr>>sc;
    cin>>s;
    cin>>t;

    lr=mr=sr;
    lc=mc=sc;

    for(int i=0;i<n;i++){
        if(s[i]=='L')lc--;
        if(s[i]=='R')mc++;
        if(s[i]=='U')lr--;
        if(s[i]=='D')mr++;
        if(lc<1||mc>w||lr<1||mr>h){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t[i]=='L'&&mc>w/2)mc--;
        if(t[i]=='R'&&lc<w/2)lc++;
        if(t[i]=='U'&&mr>h/2)mr--;
        if(t[i]=='D'&&lr<h/2)lr++;
        //cout<<lc<<' '<<mc<<' '<<lr<<' '<<mr<<endl;
    }
    cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 920
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define mod 1000000007
#define all(v) v.begin(),v.end()

ll pow(ll x,ll n,ll p,ll res)
{
    if(n==0)
        return res%p;
    if(n&1)
    {
        res=((res%p)*(x%p))%p;
        n--;
    }
    x=((x%p)*(x%p))%p;
    n>>=1;
    return pow(x,n,p,res);
}





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

//ll t;
//cin>>t;
//while(t--)
{

  ll k,a,b,p=0;
  cin>>k>>a>>b;
  for(ll i=a;i<=b;i++)
  {
      if(!(i%k))
        p=1;
  }
     if(p==1)
        cout<<"OK";
     else
        cout<<"NG";


    cout<<endl;

}
    return 0;
}





Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

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

const int MAXN = 3030;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
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;}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}

int n, t, h;
double p[MAXN];
vector<vector<double>> dp(MAXN);

double solve(int i, int h) {
	if(i == n) {
		if(h > n - h)
			return 1;
		return 0;
	}
	if(dp[i][h] != -1) return dp[i][h];
	return dp[i][h] = p[i] * solve(i + 1, h + 1) + (1 - p[i]) * solve(i + 1, h);
}

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

	for(vector<double> &v : dp) {
		v.resize(MAXN, -1);
	}

	cout << setprecision(10) << fixed;

	cin >> n;

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

	cout << solve(0, 0) << endl;

	return 0;
}



Measured memory_bytes: 74368
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = LLONG_MAX;
/* テンプレートここまで */

int main() {
  ll N; cin >> N;
  vector<ll> sum(N+1, 0);
  map<ll, ll> mp;
  mp[0]++;
  REP(i, N){
    ll a; cin >> a;
    sum[i+1] = sum[i] + a;
    mp[sum[i+1]]++;
  }

  ll ans = 0;
  FOREACH(x, mp){
    ll k = x.second;
    ans += k*(k-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 14336
class Node
  attr_accessor :parent, :rank

  def initialize(n)
    @parent = n
    @rank = 0
  end
end

class UnionFindTree
  # 0 から n まで（計 n+1個）のNodeを作る
  def initialize(n)
    @nodes = (0..n).to_a.map { |i| Node.new(i) }
  end

  # x要素のルート親を返す
  def find(x)
    return x if @nodes[x].parent == x

    @nodes[x].parent = find(@nodes[x].parent)
  end

  # a,b を同一グループ化する
  def unite(a, b)
    a = find(a)
    b = find(b)
    return if a == b

    if @nodes[a].rank < @nodes[b].rank
      @nodes[a].parent = b
    else
      @nodes[b].parent = a
      @nodes[a].rank += 1 if @nodes[a].rank == @nodes[b].rank
    end
  end

  # a,b が同一グループ？
  def same?(a, b)
    find(a) == find(b)
  end
end

def main
  c_num, p_num, r_num = gets.split.map(&:to_i)

  # 道路で行ける都市をグループ化
  path_tree = UnionFindTree.new(c_num)
  p_num.times do
    path_tree.unite(*gets.split.map(&:to_i))
  end

  # 鉄道で行ける都市をグループ化
  rail_tree = UnionFindTree.new(c_num)
  r_num.times do
    rail_tree.unite(*gets.split.map(&:to_i))
  end

  # 同じ親セットを持つ都市をカウントアップしていく
  groups = Hash.new(0)
  1.upto(c_num) do |i|
    pp = path_tree.find(i)
    rp = rail_tree.find(i)
    groups[[pp, rp]] += 1
  end

  # 同じ親セットをもつ都市数を出力
  nums = (1..c_num).inject([]) do |s, i|
    pp = path_tree.find(i)
    rp = rail_tree.find(i)
    s << groups[[pp, rp]]
  end
  puts nums.join(" ")
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 58984
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            # print("{} {} {} gcd{}".format(a, b, c, gcd((a, b, c))))
            ans += gcd(a, gcd(b, c))

print(ans)

Measured memory_bytes: 75728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;

ll N,A,B,b[100010],tb=1000100000,res,an;
ll sumb=0;

bool check(ll T)
{
    ll sum= 0;
    for(int i=0;i<N;i++)
    {
        if(b[i]-T*B>0)
        {
            if((b[i]-T*B)%(A-B)==0)
            {
                sum+=((b[i]-T*B)/(A-B));
            }
            else
            {
                sum+=((b[i]-T*B)/(A-B)+1);
            }
        }
    }
    if(sum>T)return false;
    return true;
}
int main()
{

    scanf("%lld%lld%lld",&N,&A,&B);
    for(ll i=0;i<N;i++)
    {
        scanf("%lld",&b[i]);
        sumb+=b[i];
    }
    ll l=1,r=1000000005;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid))
        {
            r=mid-1;
        }
        else
        {
            l=mid+1;
        }
    }
//    for(ll i=0;i<N;i++)
//    {
//        if((b[i]*(A-B)+B*((sumb-b[i])-(N-1)*b[i]))%((A+(N-1)*B)*(A-B))==0)
//            an=(b[i]*(A-B)+B*((sumb-b[i])-(N-1)*b[i]))/((A+(N-1)*B)*(A-B));
//        else
//            an=(b[i]*(A-B)+B*((sumb-b[i])-(N-1)*b[i]))/((A+(N-1)*B)*(A-B))+1;
//        if(((sumb-b[i])-(N-1)*b[i])%(A-B)==0)
//            res=((sumb-b[i])-(N-1)*b[i])/(A-B)+N*an;
//        else
//            res=((sumb-b[i])-(N-1)*b[i])/(A-B)+N*an+1;
//        if(tb>res)tb=res;
//    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <map>
#define pb push_back
#define ll long long
using namespace std;
int T;
string s;
int mod = 1e9+7;
const int siz = 100010;
vector <ll> G[siz];
int n;
ll dp[siz][3];
bool viz[siz];
ll radacina;
void dfs(int nod)
{
    dp[nod][0] = dp[nod][1] = 1;
    viz[nod]=true;
    for(int i = 0; i<G[nod].size() ; i++){
        int fiu;
        fiu=G[nod][i];
        if(viz[fiu] == false){
                dfs(fiu);
            //if(fiu!=nod){//ne asiguram ca vecinul e fiu si nu parinte
                dp[nod][1] = (1LL * dp[nod][1] * dp[fiu][0]) %mod;
                dp[nod][0] = (1LL * dp[nod][0] * (dp[fiu][0]+dp[fiu][1])) %mod;
            //}
        }
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<n;i++){
        ll x,y;
        cin>>x>>y;
        G[x].pb(y);
        G[y].pb(x);
    }
    /*for(i=1;i<=n;i++)
    {
        if(G[i].size()==1)
        {

        }
    }*/
    dfs(1);
    cout<<(dp[1][0]+dp[1][1])%mod;
    return 0;
}


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

const int N = 1000;

int best[2][N + 1];
bool dp[N + 1][N + 1];

int main()
{
  for (int o = 0; o < 2; ++ o) {
    memset(dp, 0, sizeof(dp));
    dp[1][o] = true;
    for (int i = 1; i < N; ++ i) {
      for (int j = 0; j <= i; ++ j) {
        if (dp[i][j]) {
          dp[i + 1][j] = true;
          if (j < i) {
            dp[i + 1][j + 2] = true;
          }
          if (j) {
            dp[i + 1][j] = true;
          }
        }
      }
    }
    for (int i = 1; i <= N; ++ i) {
      int &j = best[o][i] = i;
      while (!dp[i][j]) {
        j --;
      }
    }
  }
  std::ios::sync_with_stdio(false);
  int T;
  std::cin >> T;
  while (T --) {
    int n, d;
    std::cin >> n >> d;
    int result = 0;
    for (int i = 0; i < 7; ++ i) {
      result += best[d >> i & 1][n] << i;
    }
    std::cout << result << "\n";
  }
}


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

int main(){
  int a;
  cin>>a;
  if(a>=64)
    cout<<"64"<<endl;
  else if(a>=32)
    cout<<"32"<<endl;
  else if(a>=16)
    cout<<"16"<<endl;
  else if(a>=8)
    cout<<"8"<<endl;
  else if(a>=4)
    cout<<"4"<<endl;
  else if(a>=2)
    cout<<"2"<<endl;
  else 
    cout<<"1"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const LL INF = 1LL<<50;
const int MAXN = 2e5;
const double eps = 1e-13;

LL f[MAXN],invf[MAXN];

LL expo(LL a,LL b){
	if(b==0)return 1;
	LL h=expo(a,b/2);
	h=(h*h)%MOD;
	if(b%2)h=(h*a)%MOD;
	return h;
}

LL choose(int a,int b){
	if(b>a)return 0;
	return ((f[a]*invf[b])%MOD*invf[a-b])%MOD;
}

LL ans[100009];
int has[100009];

int main(){
	f[0]=invf[0]=1;
	REPP(i,1,MAXN){
		f[i]=(f[i-1]*i)%MOD;
		invf[i]=expo(f[i],MOD-2);
	}
	DRI(n);
	MS1(has);
	int p1=0,p2=0;
	REP(i,n+1){
		DRI(x);
		if(has[x]!=-1){p1=has[x],p2=i;}
		has[x]=i;
	}
	REPP(k,1,n){
		ans[k]=choose(n-1,k);//neither
	}
	REPP(k,2,n+2){
		ans[k]=(ans[k]+choose(n-1,k-2))%MOD;
	}
	REPP(k,1,n+1){
		ans[k]=(ans[k]+choose(n-1,k-1)*2)%MOD;
		ans[k]=(ans[k]-choose(n-(p2-p1),k-1)+MOD)%MOD;
	}
	REPP(k,1,n+2){
		printf("%lld\n",(ans[k]%MOD+MOD)%MOD);
	}
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
//#define mod 1000000007
using namespace std;

ll ipow(ll x, ll n,ll mod) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    } 
    return result; 
} 

int main(){
	int s,w;
	cin>>s>>w;
	if(w>=s)
	cout<<"unsafe"<<endl;
	else
	cout<<"safe"<<endl;
return 0;
}

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

int main(void){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if((abs(b-a)<=d && abs(c-b)<=d) || abs(c-a) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define    endl        '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  10000
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



void solve(){
	ll n,m;
	cin>>n>>m;
	ll a[n+1];
	rep(i,1,n+1) cin>>a[i];
	vi v[n+5];
	rep(i,0,m){
		ll a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	ll an=0;
	rep(i,1,n+1){
		ll co=1;
		for(auto j:v[i]){
			if(a[j]>=a[i])
				co=0;
		}
		if(co) an++;
	} 
	cout<<an;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll TESTS=1,an=1,f;
    // cin>>TESTS;
    while(TESTS--){
        // cout<<"Case #"<<an<<": ";
        an++;
        solve();

    }
    return 0;
}

Measured memory_bytes: 10260
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>
 
using namespace std;
 
void Solution()
{
    int n;
    int a[1000] = {0};
    
    cin>>n;
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    
    for(int i = n - 1; i > 0; i--)
    {
        cout<<a[i]<<" ";
    }
    
    cout<<a[0]<<endl;
     
     
}
 
int main()
{
    Solution();
    return 0;
}

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

#define LL long long int
#define mp make_pair
#define FOR(i, n) for(i = 0; i < n; ++i)
typedef vector <int> vi;
typedef vector <LL> vll;
typedef pair<LL, LL> iPair;
const int MOD = 1e9+7;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);

    LL t = 1;
    LL i,j;
    // cin>>t;
    
    while(t--)
    {
        LL n, w;
        cin >> n >> w;
        vector <LL> weight(n);
        vector <LL> value(n);
        FOR(i, n) cin >> weight[i] >> value[i];

        LL val = accumulate(value.begin(), value.end(), 0);
        LL dp[n][val+1];
        
        for(LL i = 0; i <= val; ++i)
            dp[0][i] = (i <= value[0])? weight[0] : INT_MAX;

        for(LL i = 1; i < n; ++i)
        {
            for(LL j = 0; j <= val; ++j)
            {
                if(j - value[i] <= 0) dp[i][j] = min(weight[i], dp[i-1][j]);
                else
                {
                    LL taken, not_taken;
                    if(dp[i-1][j - value[i]] == INT_MAX)
                    {
                        taken = INT_MAX;
                    }
                    else
                    {
                        taken = weight[i] + dp[i-1][j - value[i]];
                    }

                    not_taken = dp[i-1][j];
                    dp[i][j] = min(taken, not_taken);    
                }              
            }
        }
        // for(LL i = 0; i < n; ++i)
        // {
        //     for(LL j = 0; j <= val; ++j)
        //     {
        //         cout<<dp[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        for(LL i = val; i >= 0; --i)
        {
            if(dp[n-1][i] <= w)
            {
                cout<<i;
                break;
            }
        }
    }

	return 0;
}


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

using namespace std;

int main() {
  string r;
  cin >> r;
  vector<char> ans;
  for (auto c : r) {
    ans.push_back(c);
  }
  sort(ans.begin(), ans.end());
  if (ans[0] == ans[1] && ans[2] == ans[3] && ans[1] != ans[2]) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 0;
}

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

#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 1e5 + 5;

template <typename T>
inline void read(T &x) {
    int f = 1;
    x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int n, val[4], u[MAXN], v[MAXN];
string opt[MAXN];
vector<char> choice;

int main() {
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    boost;
    cin >> n;
    cin >> val[1] >> val[2] >> val[3];
    for (int i = 1; i <= n; i++) {
        cin >> opt[i];
        if (opt[i] == "AB") u[i] = 1, v[i] = 2;
        else if (opt[i] == "AC") u[i] = 1, v[i] = 3;
        else u[i] = 2, v[i] = 3;
    }
    for (int i = 1; i < n; i++) {
        if (!val[u[i]] && !val[v[i]]) {
            cout << "No" << endl;
            return 0;
        }
        if (val[u[i]] < val[v[i]]) {
            val[u[i]]++, val[v[i]]--;
            choice.push_back(u[i] - 1 + 'A');
        } else if (val[u[i]] > val[v[i]]) {
            val[u[i]]--, val[v[i]]++;
            choice.push_back(v[i] - 1 + 'A');
        } else {
            val[u[i]]++, val[v[i]]--;
            if (!val[u[i + 1]] && !val[v[i + 1]]) {
                val[u[i]]--, val[v[i]]++;
            } else {
                choice.push_back(u[i] - 1 + 'A');
                continue;
            }
            val[u[i]]--, val[v[i]]++;
            if (!val[u[i + 1]] && !val[v[i + 1]]) {
                val[u[i]]++, val[v[i]]--;
            } else
                choice.push_back(v[i] - 1 + 'A');
        }
    }
    if (!val[u[n]] && !val[v[n]]) {
        cout << "No" << endl;
        return 0;
    }
    if (val[u[n]]) choice.push_back(v[n] - 1 + 'A');
    else choice.push_back(u[n] - 1 + 'A');
    cout << "Yes" << endl;
    for (auto &c : choice) cout << c << endl;
    return 0;
}

Measured memory_bytes: 7700
N, M, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]+[10**18]
B = [int(x) for x in input().split()]+[10**18]

A_total = 0
i = 0
while A_total+A[i] <= K:
	A_total += A[i]
	i += 1

ans = i
B_total = 0
for j in range(M):
	B_total += B[j]
	if B_total > K:
		break
	while A_total+B_total > K:
		i -= 1
		A_total -= A[i]
	ans = max(ans,i+(j+1))
print(ans)


Measured memory_bytes: 41904
import copy
S = list(input())
diff = len(S)-len("keyence")
for i in range(len(S)-diff):
    S_tmp = copy.deepcopy(S)
    #print(i)
    del S_tmp[i:(i+diff)]
    #print(str(S_tmp))
    if "keyence" == "".join(S_tmp):
        print("YES")
        exit(0)
print("NO")

Measured memory_bytes: 3572