akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.*;


class Main {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n=Integer.parseInt(br.readLine());
        
        int d=n%10;
        
        
        if(d==3)
        {
        	System.out.println("bon");
        }
        else if(d==0 || d==1 || d==6 || d==8)
        {
        	System.out.println("pon");
        }
        else 
        {
        	System.out.println("hon");
        }

    }
}

Measured memory_bytes: 32652
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(i,arr)       for(int& i:arr)cin>>i;
#define output(i,arr)      for(int& i:arr)cout<<i<<" ";
#define for_each(arr)      for(auto& it:arr)
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  //  #endif
    int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin>>n;
    cout<<arr[n-1]<<endl;
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    for(int i=0;i<3;i++){
        if(s[i]=='a')a++;
        if(s[i]=='b')b++;
        if(s[i]=='c')c++;

    }
    if(a==1&&b==1&&c==1)
        cout<<"Yes"<<"\n";
    else 
        cout<<"No"<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vi b(n), ans;
    rep(i, n) cin >> b[i];
    
    // 逆順に考える。添え字と番号が一致する最右のものを取り除く
    for(ll i=0; i<n; i++){
        bool chk = false;
        for(ll pos=b.size()-1; pos>=0; pos--){
            if(pos == b[pos]-1){
                ans.push_back(pos+1);
                b.erase(b.begin()+pos);
                chk = true;
                break;
            }
        }
        if(!chk){
            cout << -1 << endl;
            return 0;
        }
    }
    for(ll i=ans.size()-1; i>=0; i--) cout << ans[i] << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b,c;
	cin>>a>>b>>c;

	if(c-(a-b)<0)cout<<"0"<<endl;
	else cout<<c-(a-b)<<endl;
	return 0;

}


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

int dep[200010], dp[200010];
vector<int> adj[200010];
int d;

void dfs(int cur, int prev = -1) {
    for (int to : adj[cur]){
        if (to == prev) continue;
        
        dep[to] = dep[cur] + 1;
        dfs(to, cur);
        d = max(d, dp[cur] + 1 + dp[to]);
        dp[cur] = max(dp[cur], 1 + dp[to]);
    }
}

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

    for (int i = 1, a, b; i < n; i++) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1);
    puts(d % 3 != 1 ? "First" : "Second");
}

Measured memory_bytes: 24704
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int mod=1e9+7;
const int N=1e6+5;
int n,m,a[N],inv[N];
char s[N];
//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;
}
int kuai(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=res*a%mod;
		b=b/2;
		a=a*a%mod;
	}
	return res;
}
int C(int n,int m)
{
	int res=1;
	for(int i=1;i<=m;i++)res=res*inv[i]%mod;
	for(int i=n-m+1;i<=n;i++)res=res*i%mod;
	return res;
}
signed main()
{
	n=read();
	inv[0]=inv[1]=1;
	for(int i=2;i<=200005;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	int A=read(),B=read();
	int ans=kuai(2,n);
	ans=(ans-C(n,A)+mod)%mod;
	ans=(ans-C(n,B)+mod)%mod;
	ans=(ans-1+mod)%mod;
	cout<<ans;	
}

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

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

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

   string S,T;
   cin>>S>>T;

   int t;
   bool ok=false;
   for(int i=0;i<S.size()-T.size()+1;i++){
      bool flg = true;
      for(int j=0;j<T.size();j++){
         if(S[i+j]=='?')continue;
         if(S[i+j]!=T[j])flg=false;
      }
      if(flg){
         ok=true;
         t = i;
      }
   }
   if(ok){
      for(int i=0;i<S.size();i++){
         if(i==t)cout<<T,i+=T.size()-1;
         else if(S[i]=='?')cout<<'a';
         else cout<<S[i];
      }
      return 0;
   }
   else cout<<"UNRESTORABLE";
   return 0; 
}


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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	ll ans = 0;
	for (int i = 0; i < n-1; i++) {
		for (int j = i + 1; j < n; j++) {
			ans += a.at(i) * a.at(j);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(void){
    int N,K,S;
    scanf("%d %d %d",&N,&K,&S);
    int S2;
    if(S==1000000000){
        S2 = 0;
    }else{
        S2 = S;
    }

    if(K!=0){
        for(int i=0;i<K-1;i++){
            printf("%d ",S);
        }
        if(K==N){
            printf("%d",S);
            return 0;
        }else{
            printf("%d ",S);
        }
        for(int i=K;i<N-1;i++){
            printf("%d ",S2+1);
        }
        printf("%d",S2+1);
        return 0;
    }
    if(K==0){
        for(int i=K;i<N-1;i++){
            printf("%d ",S2+1);
        }
        printf("%d",S2+1);
        return 0;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#define INF 100000000
using namespace std;
int main(){
  while(1){
    int n,m,t[101],h[101];
    cin>>n>>m;
    if(n==0&&m==0)break;
    int ts=0,hs=0;
    for(int i=0;i<n;i++)cin>>t[i],ts+=t[i];
    for(int i=0;i<m;i++)cin>>h[i],hs+=h[i];
    int ans=INF;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(ts-t[i]+h[j]==hs-h[j]+t[i]&&ans>t[i]){
	  ans=t[i];
	}
      }
    }
    if(ans==INF)cout<<"-1"<<endl;
    else cout<<ans<<" "<<(hs-ts)/2+ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main(){
  ll n,x;
  cin>>n>>x;
  ll X[n];
  
  for(int i=0;i<n;i++){
    cin>>X[i];
  }
  if(n==1){
    cout<<abs(X[0]-x)<<endl;
    return 0;
  }
  ll ans=gcd((ll)abs(X[0]-x),(ll)abs(X[1]-x));
  for(int i=2;i<n;i++){
    ans=gcd(ans,(ll)abs(X[i]-x));
  }
  cout<<ans<<endl;
  return 0;
}

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

#define MAX 10000
#define NIL -1

struct Node {int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse(int u) {
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u) {
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(void) {
    int i, v, l, r, root;
    cin >> n;

    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++) {
        cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if ( l != NIL) T[l].p = v;
        if ( r != NIL) T[r].p = v;
    }


    for (i = 0; i < n; i++) if (T[i].p == NIL) root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(long i=0;i<n;i++)
#define rn(i,n) for(long i=1;i<=n;i++)

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

  bool flag=1;
  r(i,s.size()){
    if(i%2!=0){
      if(s.at(i)=='R')flag=0;
    }else{
      if(s.at(i)=='L')flag=0;
    }

  }
  
  if(flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

vector<vector<ll>> conbination(int n) {
	auto ans = vector<vector<ll>>(n + 1);
	ans[0].push_back(1);
	rep(i, n) {
		rep(j, i + 2) {
			if (j == 0 || j == i + 1) {
				ans[i+1].push_back(1);
			}
			else {
				ans[i + 1].push_back(ans[i][j - 1] + ans[i][j]);
			}
		}
	}
	return ans;
}



int main() {
	auto C = conbination(50);
	int n, a, b;
	cin >> n >> a >> b;
	vector<ll> v(n);
	rep(i, n) {
		cin >> v[i];
	}
	sort(v);
	reverse(v);
	ll t = v[a - 1];
	int cupt = 0;
	int ct = 0;
	rep(i, n) {
		if (v[i] > t) {
			cupt++;
		}
		else if (v[i] == t) {
			ct++;
		}
	}
	int y = a - cupt;
	int x = ct;
	ct = min(b - cupt, ct);

	if (cupt != 0) {
		ll ans0 = 0;
		rep(i, a) {
			ans0 += v[i];
		}
		cout << fixed << (long double)ans0 / a << endl;
		cout << C[x][y] << endl;
		return 0;
	}

	ll ans = 0;
	FOR(i, y, ct + 1) {
		ans += C[x][i];
	}
	ll ans0 = 0;
	rep(i, a) {
		ans0 += v[i];
	}
	cout << fixed << (long double)ans0 / a << endl;
	cout << ans << endl;

}



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

int main(){
    int a, b, c, min=5000; 
    cin>>a>>b>>c;
    vector<int> v(3); 
    v[0] = a+b;
    v[1] = b+c;
    v[2] = c+a;
    sort(v.begin(), v.end());
    cout<<v[0]<<endl;
    return 0;
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	printf("%.9lf ", 1.0 * a * b / 2);
	if (a % 2 == 0 && b % 2 == 0 && a / 2 == c && b / 2 == d) printf("1\n");
	else printf("0\n");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int input[5];
  int k;
  for ( int i = 0; i < 5; i++ ) {
    scanf("%d",&input[i]);
  }
  scanf("%d",&k);
  for ( int i = 0; i < 5; i++ ) {
    for ( int j = i + 1; j < 5; j++ ) {
     if ( input[j] - input[i] > k ) {
       printf(":(\n");
       return 0;
     }
    }
  }
  printf("Yay!\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

int main(){
    int n;
    while(cin >> n && n){
        map<char, int> mp;
        int i;
        char cc[110];
        set<char> sss;
        sss.insert('1');
        rep(i, n){
            string s;
            cin >> s;
            cc[i] = s[0];
            sss.insert(cc[i]);
        }

        for(i = 0; i < n; ++i){
            char c = cc[i];
            ++mp[c];
            vector<char> v(all(sss));
            sort(all(v), [&](char a, char b){
                    return mp[a] > mp[b];
                });
            if(mp[v[0]] > mp[v[1]] + n-i-1){
                cout << v[0] << ' ' << i+1  << '\n';
                break;
            }
        }
        if(i == n){
            cout << "TIE" << endl;
        }
    }
}

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

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

    int a = n / 1000;
    n -= a * 1000;
    int b = n / 100;
    n -= b * 100;
    int c = n / 10;
    n -= c * 10;
    int d = n;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k;
	cin>>n>>k;
	ll ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
		ch[i]--;
	}
	ll ru[200010]={};
	for(ll i=0;i<n;i++){
		ru[i+1]=ru[i]+ch[i];
	}
	for(ll i=0;i<=n;i++){
		ru[i]%=k;
	}
	map<ll,ll>cnt;
	ll ans=0;
	for(ll i=0;i<=n;i++){
		if(i>=k){
			cnt[ru[i-k]]--;
		}
		ll now=ru[i];
		ans+=cnt[now];
		cnt[now]++;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 19224
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    vector<bool> used(N);
    vector<pair<int, int>> arenas;

    for (int i = 0; i < M; i++) {
        int left = i + 1;
        int right = N - i;
        if (N % 2 == 0 && left * 2 * 2 > N) {
            left++;
        }
        arenas.push_back(make_pair(left, right));
    }

    for (int i = 0; i < M; i++) {
        int left = arenas[i].first;
        int right = arenas[i].second;
        printf("%d %d\n", left, right);
    }

    return 0;
}


Measured memory_bytes: 4312
local bit=require"bit"
N=io.read"*n"
M=io.read"*n"
X=io.read"*n"
C={}
A={}
for i=1,N do
	C[i]=io.read"*n"
	A[i]={}
	for j=1,M do
		A[i][j]=io.read"*n"
	end
end

local min=math.huge
for i=0,2^N-1 do
	local t={0,0,0,0,0,0,0,0,0,0,0,0}
	local c=0
	for j=0,N-1 do
		if(bit.band(bit.rshift(i,j),1)~=0)then
			for k=1,M do
				t[k]=t[k]+A[j+1][k]
			end
			c=c+C[j+1]
		end
	end
	local b=true
	for k=1,M do
		if(t[k]<X)then b=false break end
	end
	if(b)then min=math.min(min,c)end
end
print(min==math.huge and -1 or min)


Measured memory_bytes: 3132
n = int(input())
a = [int(x) for x in input().split()]
key = 0
ans = 0
for i in range(n):
  sub = key + a[i]
  if i == 0 and sub == 0:
    ans += 1
    sub = 1
  if i != 0 and sub*key >= 0:
    if key > 0:
      ans += sub+1
      sub = -1
    else:
      ans += 1-sub
      sub = 1
  key = sub

ans2 = 0
key2 = 0
for i in range(n):
  sub = key2 + a[i]
  if i == 0:
    if sub == 0:
      ans2 += 1
      sub = -1
    elif sub > 0:
      ans2 += sub+1
      sub = -1
    else:
      ans2 += 1-sub
      sub = 1
  if i != 0 and sub*key2 >= 0:
    if key2 > 0:
      ans2 += sub+1
      sub = -1
    else:
      ans2 += 1-sub
      sub = 1
  key2 = sub
      
print(min([ans, ans2]))

Measured memory_bytes: 14468
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define pb push_back
#define lb lower_bound
#define sf scanf
#define pf printf
typedef long long ll;

inline void read(int &input)
{
	char ch;
	int value=0,sign=1;
	do{
		ch=getchar();
		if(ch=='-')
			sign=-1;
	}while(ch<'0'||ch>'9');
	while(ch>='0'&&ch<='9'){
		value=value*10+ch-'0';
		ch=getchar();
	}
	input=value*sign;
}
inline void write(int output)
{
	if(output<0){
		putchar('-');
		output*=-1;
	}
	if(output>=10)
		write(output/10);
	putchar(output%10+'0');
}
string solve(int r)
{
	if(r>=2800) return "AGC";
	if(r>=1200) return "ARC";
	return "ABC";
}
int main()
{
	int r;
	read(r);
	cout<<solve(r);
	return 0;
}

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

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

  int ans = 0;

  if(a < b) swap(a, b);

  ans = a;
  a -= 1;
  ans += max(a, b);

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define pii pair<int, int>
#define mp make_pair
#define ll long long
#define ld long double
#define pb push_back
#define S second
#define F first
using namespace std;



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

	
	int n;
	cin >> n;
	string str;
	cin >> str;
	int cnt = 0;
	int p1 = 0, p2 = n - 1;
	while (p1 < p2) {
		while (p1 < n && str[p1] == 'R') {
			p1++;
		}

		while (p2 >= 0 && str[p2] == 'W') {
			p2--;
		}

		if (p1 < p2) {
			swap(str[p1], str[p2]);
			cnt++;
		}
	}

	cout << cnt << '\n';

}

Measured memory_bytes: 3768
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> A){
    rep(i, N){
        A[i] -= i+1;
    }
    sort(A.begin(), A.end());
    ll b = A[N/2];
    ll ans = 0;
    rep(i, N){
        ans += abs(A[i]-b);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

main()
{
    ll n,d;
    cin>>n>>d;
    d*=d;
    ll ans=0;
    while(n--)
    {
       ll x,y;
       cin>>x>>y;
       if(x*x+y*y<=d) ans+=1;
    }
    cout<<ans;
}



Measured memory_bytes: 3568
N = int(input())
a = list(map(int,input().split(' ')))
a.sort()
 
 
fathers = [a.pop()]
for _ in range(N):
    sons = list()
    b = list()

    for father in fathers:
        while a:
            x = a.pop()
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                
    a = a + b[::-1]
    fathers.extend(sons)
    fathers.sort(reverse = True)
    


if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')


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

int main(){
  int s;
  cin >> s;
  int a[1000000];
  bool flag=false;
  a[0] = s;
  rep(i,999999){
    if(a[i]%2==0){
      a[i+1] = a[i]/2;
    }else{
      a[i+1] = 3*a[i] + 1;
    }
    
    rep(j,i+1){
      if(a[i+1]==a[j]){
        cout << (i+2) << endl;
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  return 0;
}


Measured memory_bytes: 256
n = list(input())
sList = list(map(int, input().split()))
sList = list(set(sList))
sList.sort()

q = list(input())
tList = list(map(int, input().split()))

tCount = 0


def middle_idx(tmin, tmax):
    return int((tmin + tmax) / 2)


for tmp_t in tList:
    tmp_min = 0
    tmp_max = len(sList) - 1
    if (tmp_t >= sList[tmp_min] and tmp_t <= sList[tmp_max]):
        while ( tmp_max - tmp_min > 1 ):
            tmp_mid = middle_idx(tmp_max, tmp_min)
            if sList[tmp_mid] > tmp_t:
                tmp_max = tmp_mid
            elif sList[tmp_mid] < tmp_t:
                tmp_min = tmp_mid
            elif sList[tmp_mid] == tmp_t:
                tmp_min = tmp_max
        if(sList[tmp_max] == tmp_t or sList[tmp_min] == tmp_t or sList[tmp_mid] == tmp_t):
            tCount += 1
    else:
        pass

print(tCount)

Measured memory_bytes: 18784
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int A = s.indexOf("A");
		int Z = 0;
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'Z')
				Z = i;
		}
		System.out.println(Z - A + 1);
	}
}

Measured memory_bytes: 26636
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map<ll,ll> mp;
ll bit[1000000];
class Query
{
public:
	ll l,r,index;
};
void update(ll i,ll value,ll n)
{
	while(i<=n)
	{
		bit[i]+=value;
		i+=i&(-i);
	}
}
bool compare(Query q1,Query q2)
{
	return q1.r<q2.r;
}
ll query(ll index,ll n)
{
	ll ans=0;
	while(index>0)
	{
		ans+=bit[index];
		index-=index&(-index);
	}
	return ans;
}
int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	ll n,q;
	cin>>n>>q;
	ll a[n];
	ll last_visited[1000000];
	ll query_counter=0;
	memset(last_visited,-1,sizeof(last_visited));
	memset(bit,0,sizeof(bit));
	ll ans[q];
	for(ll h=0;h<n;h++)
	{
		cin>>a[h];
	}
	vector<Query> v;
	ll i=0;
	ll z=q;
	while(q--)
	{
		ll lk,rk;
		cin>>lk>>rk;
		lk--;
		rk--;
		Query qw;
		qw.l=lk;
		qw.r=rk;
		qw.index=i;
		i++;
		v.push_back(qw);
	}

	sort(v.begin(),v.end(),compare);

	for(ll h=0;h<n;h++)
	{
		if(last_visited[a[h]]!=-1)
		{
			update(last_visited[a[h]]+1,-1,n);
		}
		last_visited[a[h]]=h;
		update(h+1,1,n);
		while(query_counter<z&&v[query_counter].r==h)
		{
			ans[v[query_counter].index]=query(v[query_counter].r + 1,n)-
									    query(v[query_counter].l,n);
			query_counter++;
		}
	}
	for(ll p=0;p<z;p++)
	{
		cout<<ans[p]<<endl;
	}
	

}


Measured memory_bytes: 39088
from collections import deque
import sys
input = sys.stdin.readline

def solve():
  n,q = (int(i) for i in input().split())
  graph = [[] for _ in range(n)]

  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  ans = [0]*n
  
  for i in range(q):
    p,x = (int(i) for i in input().split())
    ans[p-1] += x

  query = deque([(0,-1)])
  while query:
    nowplace,parent = query.popleft()
    nowvalue = ans[nowplace]   
    for node in graph[nowplace]:
      if node == parent:
        continue
      else:
        ans[node] += nowvalue
        query.append([node,nowplace])
      
  print(*ans)
  
solve()

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

int a[200000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

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

	if(a[0] != 0){
		cout << -1 << endl;
		return 0;
	}

	for(int i = 0; i < N - 1; i++){
		if(a[i] < a[i + 1] && a[i + 1] - a[i] >= 2){
			cout << -1 << endl;
			return 0;
		}
	}

	ll ans = a[N - 1];
	int h = a[N - 1];
	for(int i = N - 2; i >= 0; i--){
		h--;
		if(h == a[i]) continue;
		h = a[i];
		ans += h;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = 0;
    int b = 0;
    for(int i = 0; i < s.length(); i++) {
      if(s.charAt(i) == 'A') {
        a = i;
        break;
      }
    }
    for(int i = s.length() - 1; i >= 0; i--) {
      if(s.charAt(i) == 'Z') {
        b = i;
        break;
      }
    }
    System.out.println(b - a + 1);
  }
}

Measured memory_bytes: 26424
A, B, C = map(int, input().split())

count = 0
while True:
    if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
        break
    a = B // 2 + C // 2
    b = C // 2 + A // 2
    c = A // 2 + B // 2
    if a == A and b == B and c == C:
        print(-1)
        exit()
    A = a
    B = b
    C = c
    count += 1

print(count)


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

#define count_ones __builtin_popcountl
typedef long long ll;
using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        s[i] = 'A' + (((int) (s[i] - 'A') + n) % 26);
    }
    cout << s;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    
    int a, b;
    char op;

    while (1)
    {
        scanf("%d %c %d", &a, &op, &b);
        if(op == '?'){
            break;
        }
        else{
            if(op == '+'){
                printf("%d\n", a+b);
            }
            else if(op == '-'){
                printf("%d\n", a-b);
            }
            else if(op == '*'){
                printf("%d\n", a*b);
            }
            else if(op == '/'){
                printf("%d\n", a/b);
            }
        }
    }
    

    return 0;
}


Measured memory_bytes: 2052
# coding: utf-8
# Here your code !
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: 
            mark(s, x)
    return [i for i in range(0,n) if s[i] and i > 1]

# primes = []
# maxn = 0

while True:
    n = int(input())
    if n == 0:
        break
    # if n > maxn:
    #     maxn = n
        
    primes = sieve(n)
    # print(primes)
    
    count = 0
    for prime in primes:
        if prime > (n // 2):
            print(count)
            break
        else:
            if (n - prime) in primes:
                count += 1
 
    

Measured memory_bytes: 8324
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if(a*b%2==1) cout<<"Odd"<<'\n';
  else cout<<"Even"<<'\n';
  return 0;
}


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

int main()
{
    int n;
    scanf("%d",&n);
    vector<int> h(n);
    for(int &x:h)
    {
        scanf("%d",&x);
    }
    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));

    }

   cout<<dp[n-1];

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
vector<int> l[101];
int matrix[100][100];
pair<int,int> t[101];
bool visited[101];
int tim=0;
void dfs(int cur)
{
    tim+=1;
    t[cur].first=tim;
    //cerr<<"visiting "<<cur<<' '<<tim<<endl;
    visited[cur]=true;
    
    for(int i=0;i<l[cur].size();i++)
    {
        if((matrix[cur-1][l[cur][i]-1]==1)&&(visited[l[cur][i]]==false))
        {
            dfs(l[cur][i]);
        }
    }
    
    tim+=1;
    t[cur].second=tim;
    
    
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            int tmp;
            cin>>tmp;
            l[u].push_back(tmp);
        }
    }
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            matrix[i][j]=0;
        }
    }
    
    visited[0]=false;
    for(int i=1;i<n+1;i++)
    {
        visited[i]=false;
        for(int j=0;j<l[i].size();j++)
        {
            matrix[i-1][l[i][j]-1]=1;
        }
    }
    
    for(int i=1;i<n+1;i++)
    {
        if(visited[i]==false)
            dfs(i);
    }
    
    for(int i=1;i<n+1;i++)
    {
        cout<<i<<" "<<t[i].first<<" "<<t[i].second<<endl;
    }
}

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

vector<vector<int>> to(2500);
vector<vector<int>> ot(2500);
vector<bool> toreach(2500, false);
vector<bool> otreach(2500, false);
vector<bool> reach(2500, false);

void dfs(int u){
    if (toreach[u]) return;
    toreach[u] = true;
    for (int i = 0; i < to[u].size(); i++) dfs(to[u][i]);
}
void rdfs(int u){
    if (otreach[u]) return;
    otreach[u] = true;
    for (int i = 0; i < ot[u].size(); i++) rdfs(ot[u][i]);
}

int INF = 1'000'000'000;

int main(){
    int n, m, p;
    cin >> n >> m >> p;
    vector<tuple<int, int, int>> edge(m);
    for (int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--; c -= p; c = -c;
        edge[i] = tie(a, b, c);
        to[a].push_back(b);
        ot[b].push_back(a);
    }
    dfs(0); rdfs(n - 1);
    for (int i = 0; i < n; i++) reach[i] = toreach[i] & otreach[i];
    vector<long long> d(n, INF);
    d[0] = 0;
    for (int i = 0; i < n; i++){
        bool update = false;
        for (int j = 0; j < m; j++){
            int a, b, c;
            tie(a, b, c) = edge[j];
            if (!reach[a] || d[a] == INF || !reach[b]) continue;
            if (d[b] > d[a] + c){
                update = true;
                d[b] = d[a] + c;
            }
        }
        if (!update) break;
        if (i == n - 1) {
            cout << - 1 << endl;
            exit(0);
        }
    }
    if (d[n - 1] != INF) cout << max((long long)0, - d[n - 1]) << endl;
    else cout << - 1 << endl; 
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> cnt(100'001, 0);
	long long sum = 0;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		cnt[x]++;
		sum += x;
	}
	int q;
	cin >> q;
	while(q--){
		int b, c;
		cin >> b >> c;
		sum -= 1ll * cnt[b] * b;
		sum += 1ll * cnt[b] * c;
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << '\n';
	}
	return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  string s;
  cin >> s;
  int n=s.size();
  string ans="";
  rep(i,n){
    if(s[i]=='B'&&ans.size()>0)ans=ans.substr(0,ans.size()-1);
    if(s[i]=='0')ans+='0';
    if(s[i]=='1')ans+='1';
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
typedef int ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define orz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);    
#define inp freopen("input.txt","r",stdin);freopen("out.txt","w",stdout); 
ll mod1=1e9+7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout.tie(NULL);    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
}

int main() {
    orz;
   // inp;
        ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>>p;
    priority_queue<ll>pq;
    ll ans=0;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        p.emplace_back(a,b);
    }
    sort(p.begin(),p.end());
    p.push_back(make_pair(-1,0));
    int i=0;
    for(int t=0;t<=m;++t){
        while(p[i].first==t){
            pq.push(p[i].second);
            ++i;
        }
        if(pq.empty())continue;
        ans+=pq.top();
        pq.pop();
    }
    cout<<ans<<endl;
    return 0;
}





Measured memory_bytes: 1908
#include<stdio.h>

int main(){

int a,b,i,y[1000],j;
char x;
i=0;
while(1){
scanf("%d %c %d", &a, &x, &b);
if(x==63) break;

if(x==43) y[i]=a+b;
if(x==45) y[i]=a-b;
if(x==42) y[i]=a*b;
if(x==47) y[i]=a/b;

i++;
}

for(j=0;j<i;j++){
    printf("%d\n",y[j]);
}

    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

bool check(string &s, int i) {
  bool ret = true;
  rep(j, s.size()) {
    if (s[j] - 'a' != i) {
      ret = false;
      break;
    }
  }
  return ret;
}

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

  string s; cin >> s;
  vector<bool> used(26);
  rep(i, s.size()) {
    used[s[i] - 'a'] = true;
  }

  int ans = INT_MAX;
  rep(i, 26) {
    if (!used[i]) continue;
    //debugln(i);
    string t = s;
    int cnt = 0;
    while(!check(t, i)) {
      cnt++;
      string u;
      for(int j=0; j<t.size()-1; j++) {
        if (t[j] - 'a' == i) {
          u.push_back(t[j]);
        } else if (t[j+1] - 'a' == i) {
          u.push_back(t[j+1]);
        } else {
          u.push_back(t[j]);
        }
      }
      //debugln(u);
      t = u;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a,b,c;
        int assess=0;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        if(a<=c) assess++;
        if(c<=b) assess++;

        if(assess==2) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21844
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
)

func main() {
        var n int
        fmt.Scan(&n)
        sc := bufio.NewScanner(os.Stdin)
        sc.Split(bufio.ScanWords)
        grid := make([][]int, 2)
        getCandies := make([][]int, 2)
        for i := 0; i < 2; i++ {
                grid[i] = make([]int, n)
                getCandies[i] = make([]int, n)
                for j := 0; j < n; j++ {
                        sc.Scan()
                        grid[i][j], _ = strconv.Atoi(sc.Text())
                        max := 0
                        if i > 0 {
                                if v := getCandies[i-1][j]; max < v {
                                        max = v
                                }
                        }
                        if j > 0 {
                                if v := getCandies[i][j-1]; max < v {
                                        max = v
                                }
                        }
                        getCandies[i][j] = max + grid[i][j]
                }
        }
        fmt.Printf("%d\n", getCandies[1][n-1])
}

Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include<math.h>
#include <iomanip>  
using namespace std;
int main() {
	long long a, b, lcm, c, d, mi, ma;
	cin >> a >> b;
	c = a;
	d = b;
	while (1) {
		c = c % d;
		mi = min(c, d);
		ma = max(c, d);
		c = ma;
		d = mi;
		//cout << c << " " << d << endl;
		if (mi == 0)break;
	}
	//cout << a << " " << b << " "<<endl;
	//cout << a*b;
	cout << a * b / (max(c, d));
	//cin >> a;
}

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

int main() {
	long long  n,i,j,k,m;
	string s,t;
	
	cin>>s>>t;
	n=s.length(),m=t.length();
	long long dp[n+1][m+1];
	for(i=0;i<=n;i++)
	{
	    for(j=0;j<=m;j++)
	    {
	         if (i == 0 || j == 0)  
            dp[i][j] = 0;  
            else if (s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	long long ind=dp[n][m]+1;
	char arr[ind+1];
	arr[ind]='\0';
	i=n,j=m;
	while(i>0 && j>0)
	{
	    if(s[i-1]==t[j-1])
	    {arr[ind-1]=s[i-1];
	    i--; j--; ind--; }
	    else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
	}
	for(i=1;i<=dp[n][m];i++)
	cout<<arr[i];
}

Measured memory_bytes: 70656
S = list(input())
a = 0

for i in range(len(S)):
        if S[i] == "U" or S[i] == "D":
            pass
        elif S[i] == "L":
            if (i+1)%2 == 0:
                pass
            else:
                a = 1
                
        elif S[i] == "R":
            if (i+1)%2 == 0:
                a = 1
                
            else:
                pass
        else:
            a = 1
            


    
if a == 1:
    print("No")

else:
    print("Yes")

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

int main(void){
int n,r;
int p,c;
while(true){
cin>>n>>r;
if(n==0&&r==0)return 0;
vector<int> ca(n);
vector<int> t(n,0);
vector<int> t2(n,0);
for(int i=0;i<n;i++)ca[i]=n-i;
for(int i=0;i<r;i++){
	cin>>p>>c;
	for(int j=0;j<c;j++){
		t[p-1+j]=ca[p-1+j];
	}
	for(int k=0;k<p-1;k++){
		t2[c+k]=ca[k];
	}
	for(int k=0;k<p-1;k++){
		ca[c+k]=t2[c+k];	
	}
	for(int j=0;j<c;j++){
		ca[j]=t[p-1+j];
	}
}
cout<<ca[0]<<endl;
}
return 0;
}



Measured memory_bytes: 3076
n = int(input())

xl = [list(map(int, input().split())) for _ in range(n)]

# 計算しやすいように区間を出しておく
position = [(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
position = sorted(position, key=lambda x: x[1])

min_arm = -float('inf')
ans = 0

# 全ロボットを見る
for pos in position:
    # 腕が交わらない場合
    if  min_arm <= pos[0]:
        ans += 1
        min_arm = pos[1]
print(ans)

Measured memory_bytes: 43560
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b){return a.se < b.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; ++i)
#define foris(i, a, b) for(ll i = a; i < b; ++i)
#define forise(i, a, b) for(ll i = a; i <= b; ++i)
#define ford(i, n) for(ll i = n; i >= 0; --i)
#define fords(i, a, b) for(ll i = a; i >= b; --i)
#define fordse(i, a, b) for(ll i = a; i > b; --i)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define uset unordered_set
#define pq(T) priority_queue<T>
#define rpq(T) priority_queue<T, vector<T>, greater<T> >
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;



int main() {
  io();
  
  int a, b, c, d;
  cin >> c >> d;
  a = min(c, d);
  b = max(c, d);
  if(a == 1 && b == 2) cout << 3;
  if(a == 1 && b == 3) cout << 2;
  if(a == 2 && b == 3) cout << 1;
  
  return 0;
}

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

const int inf=INT_MAX/2;

int main(){
    int n,k;
    cin >>n>>k;
    int a[n],dp[n];
    for (int i=0;i<n;++i){
        cin >>a[i];
        dp[i]=inf;
    }
    dp[0]=0;
    for (int i=1;i<n;i++){
        int mini=INT_MAX/2;
        int brPon=0;
        for (int j=i-1;brPon<k && j>=0;j--,brPon++){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout <<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
int a,u=0,l=0,d=0,r=0;
string s;
cin >> s;
for(int i=0;i<(int)s.size();i++){
if(s[i]=='N')u=1;
if(s[i]=='E')r=1;
if(s[i]=='W')l=1;
if(s[i]=='S')d=1;
}
if(u==d && r==l)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}


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

long long a[200002];

long long f( int l, int r ) {
    long long sum = 0;
    int i;
    for ( i = l; i <= r; i++ ) {
        sum += a[i];
    }
    return sum;
}

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

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

    long long sum1 = 0, sum2 = 0;

    long long sumT = f(1, n);

    long long Min = LLONG_MAX;

    sum1 = a[1];
    sum2 = sumT - sum1;
    if ( abs(sum1 - sum2) < Min ) {
            Min = abs(sum1 - sum2);
    }

    for ( i = 2; i < n; i++ ) {
        sum1 += a[i];
        sum2 = sumT - sum1;
        if ( abs(sum1 - sum2) < Min ) {
            Min = abs(sum1 - sum2);
        }
    }

    cout << Min;
    return 0;
}

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

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

using namespace std;

int f(int n){
  if(n%2==0){
    return n/2;
  }else{
    return 3*n+1;
  }
}

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

  set<int> ss;
  ss.insert(last);

  int counter=2;
  while(true){
    int c=f(last);
//cout<<c<<' '<<last<<endl;
    if(ss.count(c)==1){
      cout<<counter;
      break;
    }
    counter++;
    ss.insert(c);
    last=c;
  }

  return 0;
}

Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main Code
int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> g(2 * n - 1);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        int c = n + i;
        g[a].push_back(c); g[c].push_back(a);
        g[b].push_back(c); g[c].push_back(b);
    }
    
    vector<vector<int>> dist(2 * n - 1, vector<int>(2 * n - 1, -1));
    rep(i, 2 * n - 1) {
        queue<int> q;
        q.push(i);
        dist[i][i] = 0;
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int v: g[u]) {
                if (dist[i][v] == -1) {
                    dist[i][v] = dist[i][u] + 1;
                    q.push(v);
                }
            }
        }
    }
    
    int ans = inf;
    rep(i, 2 * n - 1) {
        int res = 0;
        rep(j, n) {
            if (dist[i][j] > k) ++res;
        }
        chmin(ans, res);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 65960
from fractions import gcd
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
List=list(map(lambda x:int(x)//2,map(int, set(input().split()))))

def main():
    LCM=1

    for i in List:
        LCM*=i//gcd(LCM,i)

    for i in List:
        if LCM//i%2==0:
            print(0)
            exit()

    print(int(M//(LCM*2)+M%(LCM*2)//LCM))


if __name__ == '__main__':
    main()


Measured memory_bytes: 13376