akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << '\n'
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << '\n'
#define space ' '
#define enter '\n'
using std::make_pair;

template < typename T >
inline T read( )
{
 register T x = 0;
 register char ch = gc( );
 register bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int Maxn = 204001;
 int n, x, a[ Maxn ];
 long long ans;
 void Fakemain( )
 {
  IOS;
  cin >> n >> x;
  For( i, 1, n )
   cin >> a[ i ];
  For( i, 2, n )
  {
   if( a[ i ] + a[ i - 1 ] > x )
   {
    int k = a[ i ] + a[ i - 1 ] - x;
    ans += k; 
    a[ i ] -= std::min( k, a[ i ] );
    k -= std::min( k, a[ i ] );
    a[ i - 1 ] -= k;
   }
  }
  cout << ans;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

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

using namespace std;

bool Verific(char c, int i)
{
    if( i % 2 == 0 )
        if( c == 'L' )
            return false;
        else
            return true;
    else
        if( c == 'R' )
            return false;
        else
            return true;

}

int main()
{
    char S[101];
    cin.getline(S, 101);
    int n = strlen(S);
    for( int i = 0; i < n; i++ ){
        if( !Verific(S[i], i) ){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}



Measured memory_bytes: 256
A, B, M = map(int, input().rstrip().split(' '))
a = list(map(int, input().rstrip().split(' ')))
b = list(map(int, input().rstrip().split(' ')))
coupon = []

for i in range(M):
  x, y, c = map(int, input().rstrip().split(' '))
  temp = a[x-1]+b[y-1]-c
  coupon.append(temp)

min_price = min(coupon)

if min(a)+min(b) < min_price :
  print(min(a)+min(b))
else:
  print(min_price)

Measured memory_bytes: 72300
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
int main(void){
	string str;cin>>str;
	int n,i,j,c;n=str.size();
	reverse(str.begin(),str.end());
	vector<int>naga(n);
	//これを使った場合の長さ　を　求める
	array<bool,26> aru={0};
	int arucou=0;
	int gen=1;
	for(i=0;i<n;i++){
		if(!aru[str[i]-'a']){arucou++;}
		aru[str[i]-'a']=true;
		naga[i]=gen;
		if(arucou==26){
			arucou=0;gen++;
			for(c=0;c<26;c++){aru[c]=false;}
		}
	}
	reverse(str.begin(),str.end());
	reverse(naga.begin(),naga.end());
	string ans;
	char moku='!';
	for(i=0;i<n;i++){
		if(gen>naga[i]){
			//新たに入ったので目標再抽選
			for(c='a';c<='z';c++){if(!aru[c-'a']){moku=c;break;}}
			for(c='a';c<='z';c++){aru[c-'a']=false;}
			gen--;
		}
		if(moku=='!'){aru[str[i]-'a']=true;}
		if(moku==str[i]){ans.pub(moku);moku='!';}
	}
	for(c='a';c<='z';c++){if(!aru[c-'a']){moku=c;break;}}
	for(c='a';c<='z';c++){aru[c-'a']=false;}
	ans.pub(moku);
	cout<<ans<<endl;
}

Measured memory_bytes: 1404
#include <iostream>
#include <string>

int main() {
  std::string s, t, u;
  int a, b;
  std::cin >> s >> t;
  std::cin >> a >> b;
  std::cin >> u;
  
  --((s == u)? a: b);
  std::cout << a << ' ' << b << '\n';
}

Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))


n_l=nl()
inds=n_l.index(0)
print(inds+1)

Measured memory_bytes: 10368
#include <cstdio>
#include <iostream>
#include <vector>
#define DEBUG 0
constexpr int kMax = 3001;

int main() {
  int N; std::cin >> N;
  std::vector<double> p(N+1);
  for (int i = 1; i <= N; ++i) std::cin >> p[i];

  double dp[kMax][kMax];

  dp[0][0] = 1.0;
  for (int j = 1; j <= N; ++j) {
    dp[0][j] = 0.0;
  }

#if DEBUG
  for (int j = 0; j <= N; ++j) {
    std::cout << dp[0][j] << "\t";
  }
  std::cout << std::endl;
#endif

  for (int i = 1; i <= N; ++i) {
    dp[i][0] = dp[i-1][0] * (1-p[i]);
    for (int j = 1; j <= N; ++j) {
      dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]);
    }

#if DEBUG
    for (int j = 0; j <= N; ++j) {
      std::cout << dp[i][j] << "\t";
    }
    std::cout << std::endl;
#endif
  }

  double sum_p = 0.0;
  for (int j = N; j > N/2; --j) {
    sum_p += dp[N][j];
  }
  printf("%.10f\n", sum_p);
}


Measured memory_bytes: 70656
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int k = 0;
    int A [n+1], B [n+1];
    for(int i = 1; i <= n; i++) {
        cin >> A[i];
        if(A[i] > k) k = A[i];
    }
    int C [++k];
    for(int i = 0; i < k; i++) C[i] = 0;
    for(int i = 1; i <= n; i++) C[A[i]]++;
    for(int i = 1; i < k; i++) C[i] += C[i-1];
    for(int i = n; i > 0; i--) B[C[A[i]]--] = A[i];
    for(int i = 1; i < n; i++) cout<< B[i] << " "; cout<< B[n] << "\n";

    return 0;
}


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

int main(){
ll N; cin >> N;
if(N % 2 == 0)	cout << N * (N / 2 - 1) + N / 2 << endl;
else	cout<< N * (N / 2) << endl;
}

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

int main(){
  int n, m;  cin >> n >> m;
  vector<string> a(n), b(m);
  for(int i=0; i<n; i++)  cin >> a[i];
  for(int i=0; i<m; i++)  cin >> b[i];

  string ans = "No";

  for(int i=0; i+m<=n; i++)
    for(int j=0; j+m<=n; j++){
      bool ok = true;
      for(int ii=0; ii<m; ii++)
	for(int jj=0; jj<m; jj++)
	  if(a[i+ii][j+jj] != b[ii][jj])
	    ok = false;
      if(ok)  ans = "Yes";
    }
  
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int n,t,T,c,m;
vector <int> veca;

int main()
{
    cin >> n >> T;
    for (int i=1;i<=n;i++)
    {
        cin >> c >> t;
        if (t<=T)
        {
            veca.push_back(c);
            m=1;
        }
    }
    sort(veca.begin(),veca.end());
    if (m==1)
        cout << veca[0] << endl;
    else
        cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int wa(int num){
    int sum=0;
    while(num>0){
        sum+=num%10;
        num=num/10;//printf("sum:%d\n",num);
    }
    return sum;
}

int main(void)
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int ans=0;

    int i;
    for(i=1;i<=n;i++){
        //printf("[i]sum=%d,%d\n",i,wa(i));
        if(a<=wa(i)&&wa(i)<=b){
            ans+=i;
            //puts("up");
        }
    }

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

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

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

  string S, T;
  cin >> S >> T;
  long long ans = 0;
  for(int i = 0; i < S.size(); ++i) {
    if(S[i] != T[i]) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3776
#include<iostream>

using namespace std;

int main(){
	int D, N, A=1;
	cin >> D >> N;

	int t=0;
	while(t++<D){
		A *= 100;
	}
	if(!(N%100))	cout << A*N + (N/100)*A << endl;
	else	cout << A*N << endl;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

#define INF 1000000000

struct spell{
  LL mp;
  LL damage;
};

struct spell sps[100],spa[100];
LL dps[100001],dpa[100001];

int main(){
  int n;
  while(1){
    cin >> n;
    if(n==0) return 0;
    vector<LL> hp(n);
    for(int i=0;i<n;i++){
      cin >> hp[i];
    }
    int m;
    cin >> m;
    int counts=0,counta=0;
    string name,target;
    LL mp,damage;
    for(int i=0;i<m;i++){
      cin >> name >> mp >> target >> damage;
      if(target=="Single"){
        sps[counts]={mp,damage};
        counts++;
      }else{
        spa[counta]={mp,damage};
        counta++;
      }
    }
    for(int i=0;i<100001;i++){
      dpa[i]=dps[i]=INF;
    }
    dpa[0]=dps[0]=0;
    for(int i=1;i<100001;i++){
      for(int j=0;j<counts;j++){
        if(i-sps[j].damage<0){
          dps[i]=min(dps[i],sps[j].mp);
        }else{
          dps[i]=min(dps[i],dps[i-sps[j].damage]+sps[j].mp);
        }
      }
    }
    for(int i=1;i<100001;i++){
      for(int j=0;j<counta;j++){
        if(i-spa[j].damage<0){
          dpa[i]=min(dpa[i],spa[j].mp);
        }else{
          dpa[i]=min(dpa[i],dpa[i-spa[j].damage]+spa[j].mp);
        }
      }
    }
    LL ans=INF;
    LL count;
    for(int i=0;i<100001;i++){
      count=dpa[i];
      for(int j=0;j<n;j++){
        count+=(hp[j]-i>=0?dps[hp[j]-i]:0);
      }
      ans=min(ans,count);
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 4576
#include <iostream>
#include <algorithm>

using namespace std;

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

int main(){
	int n;
	while(cin >> n, n){
		int smax = 0;
		int smin = 1<<29;
		rep(i, n){
			int sum = 0;
			rep(j, 5){
				int x;
				cin >> x;
				sum += x;
			}
			smax = max(smax, sum);
			smin = min(smin, sum);
		}
		cout << smax << ' ' << smin << endl;
	}
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  int x[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  int m;
  cin>>m;
  int a[m];
  for(int i=0;i<m;i++){
    cin>>a[i];
  }

  for(int i=0;i<m;i++){
    if(x[a[i]-1] != 2019 && x[a[i]-1]+1 != x[a[i]]){
      x[a[i]-1]++;
    }
  }
  for(int i=0;i<n;i++){
    cout<<x[i]<<endl;
  }
  return 0;
}


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

int main()
{ 
  int a, b, c, d, disx, disy, pm_start;
  vector<vector<int>> pm{{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
  
  cin >> a >> b >> c >> d;
  disx = abs(a - c);
  disy = abs(b - d);
  if (c - a >= 0)
  {
    if (d - b >= 0)
      pm_start = 0;
    else
      pm_start = 3;
  }
  else
  {
    if (d - b >= 0)
      pm_start = 1;
    else
      pm_start = 2;
  }
  cout << c + pm[(pm_start + 1) % 4][0] * disy << " " \
      << d + pm[(pm_start + 1) % 4][1] * disx << " " \
      << c + pm[(pm_start + 1) % 4][0] * disy + pm[(pm_start + 2) % 4][0] * disx<< " " \
      << d + pm[(pm_start + 1) % 4][1] * disx + pm[(pm_start + 2) % 4][1] * disy<< endl;
// ++ -+ -- +- 
// ab ba ab ba
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline char nchar() {
	static const int bufl=1<<20;
	static char buf[bufl],*a=NULL,*b=NULL;
	return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
}
inline int read() {
	int x=0,f=1;
	char c=nchar();
	for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=nchar()) x=x*10+c-'0';
	return x*f;
}
const int maxn=2e5+10;
int n,a[maxn],b[maxn],tot=0;
unordered_map<int,int> id;
bool same() {
	static int a[maxn],b[maxn];
	copy(::a,::a+n+1,a);
	copy(::b,::b+n+1,b);
	sort(a,a+n+1),sort(b,b+n+1);
	return equal(a,a+n+1,b);
}
namespace graph {
	vector<int> g[maxn];
	bool vis[maxn];
	inline void add(int x,int y) {
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int dfs(int x) {
		if (!vis[x]) vis[x]=true; else return 0;
		int ret(1);
		for (const int &v:g[x]) ret+=dfs(v);
		return ret;
	}
	int count() {
		int ret(0);
		for (int i=1;i<=tot;++i) if (!vis[i]) {
			int tmp(dfs(i));
			if (tmp==1) vis[i]=false; else ++ret;
		}
		return ret;
	}
}
inline int add_node(int x) {
	int &p=id[x];
	if (!p) p=++tot;
	return p;
}
int main() {
	n=read();
	for (int i=1;i<=n;++i) a[0]^=(a[i]=read());
	for (int i=1;i<=n;++i) b[0]^=(b[i]=read());
	if (!same()) return puts("-1"),0;
	if (equal(a,a+n+1,b)) return puts("0"),0;
	int ans=0;
	for (int i=1;i<=n;++i) {
		int x=add_node(a[i]),y=add_node(b[i]);
		if (x!=y) graph::add(x,y),++ans;
	}
	int p=graph::count();
	int x=add_node(a[0]),y=add_node(b[0]);
	ans=ans+p+(!graph::vis[x])+(x!=y && !graph::vis[y])-1;
	printf("%d\n",ans);
	return 0;
}


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

int main(){
		int n;
		cin >> n;
		int A[n];
		for(int i = 0;i < n;i++){
				cin >> A[i];
		}
		for(int i = 0;i < n;i++){
				cout << A[i] ;
				if(i != n -1) cout << " ";
		}
		cout << endl;
		for(int i = 1;i < n;i++){
				int key = A[i];
				int j = i - 1;
				while(j >= 0 && A[j] > key){
						A[j+1] = A[j];
						j--;
						A[j+1] = key;
				}
				for(int k = 0;k < n;k++){
						cout << A[k] ;
						if(k != n-1) cout << " ";
				}
				cout << endl;
		}
		return 0;
}

Measured memory_bytes: 1164
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 1
 
if 0 in A :
    ans = 0
 
for i in range(N) :
    ans *= A[i]
    if ans > 10**18 :
        ans = -1
        break
 
print(ans)


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

def over(start, i):
    #return the time of the first train that leaves after the start time of the ith station.
    #when f * (n-1) < start <= f * n, return f * n
    f_ = f[i]
    if start % f_ == 0:
        return start
    else:
        return f_ * ((start // f_) + 1)


c,s,f = [], [], []

times = []

for _ in range(n-1):
    c_, s_, f_ = [int(x) for x in input().split()]
    _ = [x.append(y) for x,y in [(c,c_),(s,s_),(f,f_)]]

for i in range(n-1):
    start = 0
    for j in range(n-1-i):
        tmp = over(start,i+j)
        if tmp < s[i+j]:
            tmp = s[i+j]
        start = tmp + c[i+j]
    times.append(start)

for x in times:
    print(x)
print(0)

Measured memory_bytes: 3188
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int r,c,k;
    cin >> r >> c >> k;
    vector<vector<int>> arr(r,vector<int>(c,0));
    for (int i=0;i<k;i++){
        int u,v,val;
        cin >> u >> v >> val;
        arr[u-1][v-1] = val;
    }
    vector<vector<vector<ll>>> dp(r+1,vector<vector<ll>>(c+1,vector<ll>(4,0)));
    for (int i=1;i<r+1;i++){
        for (int j=1;j<c+1;j++){
            if (i>1){
                dp[i][j][0] = maxl(dp[i][j][0],maxl(dp[i-1][j][0],maxl(dp[i-1][j][1],maxl(dp[i-1][j][2],dp[i-1][j][3]))));
            }
            if (j>1){
                dp[i][j][0] = maxl(dp[i][j][0],dp[i][j-1][0]);
                dp[i][j][1] = maxl(dp[i][j][1],dp[i][j-1][1]);
                dp[i][j][2] = maxl(dp[i][j][2],dp[i][j-1][2]);
                dp[i][j][3] = maxl(dp[i][j][3],dp[i][j-1][3]);
            }
            if (arr[i-1][j-1]>0){
                dp[i][j][3] = maxl(dp[i][j][3],dp[i][j][2] + arr[i-1][j-1]);
                dp[i][j][2] = maxl(dp[i][j][2],dp[i][j][1] + arr[i-1][j-1]);
                dp[i][j][1] = maxl(dp[i][j][1],dp[i][j][0] + arr[i-1][j-1]);
            }
        }
    }
    cout << maxl(dp[r][c][0],maxl(dp[r][c][1],maxl(dp[r][c][2],dp[r][c][3]))) << "\n";
}


Measured memory_bytes: 671744
s = list(input())
k = int(input())
l = [[i] for i in range(len(s))]
a = [''.join([s[i] for i in x]) for x in l]
for _ in range(k):
    m = min(a)
    for i,x in enumerate(a):
        if x==m and l[i][-1]+1<len(s):
            l[i].append(l[i][-1]+1)
        elif x==m:
            l.pop(i)
    a = [''.join([s[i] for i in x]) for x in l]
print(m)

Measured memory_bytes: 5344
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
#define INF 1000000001

int m, n;
int p[10001], c[500], e[500];
int dp[501][10001];

int main(){
	for(int i = 0; i < 501; i++) for(int j = 0; j < 10001; j++) dp[i][j] = INF;
	for(int i = 0; i < 501; i++) dp[i][0] = 0;
	scanf("%d%d", &m, &n);
	p[0] = 0;
	for(int i = 0; i < m; i++) scanf("%d", &p[i+1]);
	for(int i = 0; i < n; i++) scanf("%d%d", &c[i], &e[i]);
	sort(p+1,p+m+1,greater<int>());
	for(int i = 1; i <= m; i++) p[i] += p[i-1];
	for(int i = 0; i < n; i++){
		for(int j = 1; j <= m; j++){
			if(j < c[i]) dp[i+1][j] = min(dp[i][j],e[i]);
			else dp[i+1][j] = min(dp[i][j-c[i]]+e[i],dp[i][j]);
			dp[i+1][j] = min(INF,dp[i+1][j]);
		}
	}
	int ans = 0;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			if(dp[i][j] == INF) continue;
			ans = max(ans,p[j]-dp[i][j]);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 20652
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#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 per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; 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();
    string s; cin >> s;
    (s[0] == '9' || s[1] == '9') ? Yes() : No();
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 0x100000)

// SplitSpace 空白で分割設定
func SplitSpace() {
	scanner.Split(bufio.ScanWords)
}

// NextLine 標準入力から１行読み込む
func NextLine() string {
	scanner.Scan()
	return scanner.Text()
}

// NextInt 標準入力から数値を一つ読み込む
func NextInt() int {
	n, _ := strconv.Atoi(NextLine())
	return n
}

// ReadLine 標準入力から長めの1行を読み込む
func ReadLine() string {
	buf := make([]byte, 0, 0x100000)
	for {
		line, isPrefix, err := rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func ChMin(a *int, b int) bool {
	if *a > b {
		*a = b
		return true
	}
	return false
}
func ChMax(a *int, b int) bool {
	if *a < b {
		*a = b
		return true
	}
	return false
}

//================

func main() {
	SplitSpace()
	h := NextInt()
	n := NextInt()
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = NextInt()
		b[i] = NextInt()
	}
	// h := 9
	// n := 3
	// a := []int{8, 4, 2}
	// b := []int{3, 2, 1}

	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, h+1)
		for j := 0; j <= h; j++ {
			dp[i][j] = 0x7fffffff
		}
	}
	dp[0][0] = 0
	for i := 0; i < n; i++ {
		for j := 0; j <= h; j++ {
			ChMin(&dp[i+1][j], dp[i][j])
			ChMin(&dp[i+1][Min(j+a[i], h)], dp[i+1][j]+b[i])
		}
	}
	fmt.Println(dp[n][h])
	// fmt.Println(dp)

}


Measured memory_bytes: 83456
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> count; //それぞれ何個の島を辿れるか

    UnionFind(int N) : par(N+1), count(N+1) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i, count[i] = 1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    int size(int x) {
        return count[root(x)]; 
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if (size(rx) < size(ry)) swap(rx, ry);
        count[rx] += count[ry]; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,ans = 0;
    cin >> N >> M;
    vector<pair<ll,ll>> a(N);
    UnionFind uni(N);
    vector<bool> used(N);

    rep(i,N){
        cin >> a[i].first;
        a[i].second = i;
    }
    rep(i,M){
        int x,y;
        cin >> x >> y;
        uni.unite(x,y);
    }

    if( (N-1-M)*2 > N ){
        cout << "Impossible" << endl;
        return 0;
    }
    if(N-1 == M ){
        cout << 0 << endl;
        return 0;
    }
    sort(ALL(a));
    set<int> st;//木全体の集合
    int cnt = 0;
    rep(i,N){
        //コストの小さい点から見ていく
        if(st.count(uni.root(a[i].second))){
            // a[i].second が集合に含まれていた場合は
            //使える辺の数をcnt++するんだけど
            //たくさん用意しても使わずに全部結べるときもあるから条件分岐する
            if(cnt != N - M - 2) ans += a[i].first, cnt++;
        }else{
            //stの集合に含まれていなかった場合は無条件で連結する
            st.insert(uni.root(a[i].second));
            ans += a[i].first;
        }
    }
    cout << ans << endl;
}

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

long long relu(long long n){
    if(n >= 0){
        return n;
    }else{
        return 0;
    }
}

int main(){
    long long N, M;
    cin >> N >> M;
    if(N > M){
        long long tmp = M;
        M = N;
        N = tmp;
    }
    if(N == 1 && M == 1){
        cout << 1;
    }else if(N == 1){
        cout << relu(M-2);
    }else{
        cout << relu(N-2)*relu(M-2);
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();
const int N=5e5;
int hh[N],ww[N];

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	int h,w,n;
	cin>>h>>w>>n;

	int x=n;

	int a[n],b[n];

	int hmax=0,wmax=0;

	set<pair<int, int>>s;

	for(i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		hmax=max(hmax,++hh[a[i]]);
		wmax=max(wmax,++ww[b[i]]);
		s.insert({a[i],b[i]});
	}

	int i1=0,i2=0;
	vector<int>hms,wms;

	for(i=1;i<=h;i++)
	{
		if(hh[i]==hmax)
		{
			hms.push_back(i);
		}
	}

	for(i=1;i<=w;i++)
	{
		if(ww[i]==wmax)
		{
			wms.push_back(i);
		}
	}

	d(hms,wms,s);

	for(i=0;i<hms.size();i++)
	{
		for(j=0;j<wms.size();j++)
		{

			if(!s.count({hms[i],wms[j]}))
			{
				cout<<hmax+wmax<<endl;
				return;
			}
		}
	}

	cout<<hmax+wmax-1<<endl;




}

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

void call(int n) {
    int i = 1;
    CHECK_NUM:
    int x = i;
    if (x % 3 == 0) {
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    INCLUDE3:
    if (x % 10 == 3) {
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    x /= 10;
    if (x) 
        goto INCLUDE3;
    END_CHECK_NUM:
    if (++i <= n) 
        goto CHECK_NUM;
    cout << endl;
}

int main () {
    int n; cin >> n;
    call(n);
    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,m,dp[3010][3010];
char s[3010],t[3010],ans[3010];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void find(int p1,int p2,int now)
{
	if (!now) return;
	if (s[p1]==t[p2]) {ans[now]=s[p1];find(p1-1,p2-1,now-1);}
	else if (dp[p1-1][p2]>dp[p1][p2-1]) find(p1-1,p2,now);
	else find(p1,p2-1,now);
}

int main()
{
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1);m=strlen(t+1);
	rep(i,1,n)
		rep(j,1,m)
			if (s[i]==t[j]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	find(n,m,dp[n][m]);
	rep(i,1,dp[n][m]) putchar(ans[i]);
	return 0;
}


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

int main(){
  long long N;
  string S;
  cin >> N >> S;
  
  vector<long long> V(N);
  vector<vector<long long>> count(3,vector<long long>(N,0));
  for(int i=0;i<N;i++){
    if(S[i]=='R') V[i] = 0;
    if(S[i]=='G') V[i] = 1;
    if(S[i]=='B') V[i] = 2;
  }
  count[V[0]][0] = 1;
  for(int i=0;i<3;i++){
    for(int j=1;j<N;j++){
      count[i][j] = count[i][j-1];
      if(V[j]==i) count[i][j]++;
    }
  }
  
  long long ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(V[i]==V[j]) continue;
      long long x;
      if(V[i]!=0 && V[j]!=0) x=0;
      else if(V[i]!=1 && V[j]!=1) x=1;
      else x=2;
      
      ans += count[x][N-1] - count[x][j];
      if(j+(j-i)<N) if(V[j+(j-i)]==x) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3716
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 200003
#define M 2003
#define inf 1e18
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;
//int mod=998244353;
int dp[M][M];

signed main()
{
    Arena
        
    int n,m;
    cin>>n>>m;
    int a[n+1],b[m+1];
    int i,j;
    for(i=1;i<=n;++i)
        cin>>a[i];
    for(i=1;i<=m;++i)
        cin>>b[i];
    
  //  dp[0][0]=1;
    for(i=1;i<=n;++i)
    {
        for(j=1;j<=m;++j) 
        { 
            if(a[i] == b[j])  
                dp[i][j] = (1ll + dp[i][j - 1] + dp[i - 1][j])%mod;             
            else 
                dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mod)%mod;             
        } 
    } 
    cout<<(dp[n][m]+1ll)%mod;
    
    
    return 0;
}


Measured memory_bytes: 31616
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007

using namespace std;


void solve()
{
    ll X;
    cin >> X;

    ll dep = 100;
    ll interest = 0;
    int count = 0;
    while (dep < X)
    {
        interest = dep / 100;
        dep += interest;
        count++;
    }
    cout << count << endl;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3652
/*Q-3---ATCODER-BEGINNER-#ROUND_178*/

#include <bits/stdc++.h>
#define M 1000000007
#define MAX 1000001
#define ll long long
using namespace std;

ll mod(ll x){ return ((x%M + M)%M);}
ll add(ll a,ll b){ return mod(mod(a)+mod(b));}
ll sub(ll a,ll b){ return mod(mod(a)-mod(b));}
ll mul(ll a,ll b){ return mod(mod(a)*mod(b));}

ll mod_power(ll x,ll y){  
    ll res = 1;  
    x=mod(x);  
    while(y>0){    
        if(y&1)  
            res=mul(res,x);    
        y = y>>1;  
        x = mul(x,x); 
    }  
    return res;  
} 

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	ll n{0};
	cin>>n;

	//Number of sequences of length-N.
	ll total=mod_power(10,n); 

	//Number of sequences of length-N which do not have Zero.
	ll a=mod_power(9,n); 

	//Number of sequences of length-N which do not have Nine.
	ll b=mod_power(9,n); 

	/*Number of sequences of length-N which do not have Zero and Nine{ie. sequences which cannot have both zero and nine}
	Also INTERSECTION of Set-A and Set-B/*/
	ll c=mod_power(8,n); 

	/*Number of sequences of length-N which do not have Both Zero and Nine at the same time.
	{ie. (sequences which have 0 but not 9) + (sequences which have 9 but not 0) + (sequences which do not have 0 and 9) But the 
	sequence should not have both 0 and 9}.Also UNION of Set-A and Set-B.*/
	ll d=sub(add(a,b),c);

	ll answer=sub(total,d);
	cout<<answer<<endl; 

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

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

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

    vector<long> A(N);
    FOR(i, N) {
        cin >> A[i];
    }

    for (int k = K; k < N; k++) {
        if (A[k - K] >= A[k]) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

///////////////////////////////////////////////////////////

long long N, R, B;

void solve() {
  cin >> N >> B >> R;
  long long BR = B + R;
  long long katamari = (N / BR) * B;
  if(N % BR > B){
    cout << katamari + B <<endl;
  } else{
   cout << katamari + (N % BR) <<endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int x,y;
	
	while(1){
		hata:
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		else{
			if(x < y){
				printf("%d %d\n",x,y);
			}
			else{
			printf("%d %d\n",y,x);
			}
		}
		goto hata;
	}
	return 0;
}

Measured memory_bytes: 600
N = input()
#print(N[-1])
if N[-1]=='2' :
    print('hon')
if N[-1]=='4' :
    print('hon')
if N[-1]=='5' :
    print('hon')
if N[-1]=='7' :
    print('hon')
if N[-1]=='9' :
    print('hon')
if N[-1]=='0' :
    print('pon')    
if N[-1]=='1':
    print('pon')    
if N[-1]=='6' :
    print('pon')    
if N[-1]=='8' :
    print('pon')    
if N[-1]=='3':
    print('bon')

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);


int main(){
  often();
  int n,maximum=0;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  rep(i,n){
    if(h[i] < maximum - 1){
      cout << "No" << endl;
      return 0;
    }
    maximum = max(maximum,h[i]);
  }
  cout << "Yes" << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>

using namespace std;

int main(void){
    int N,Q;
    string S;

    cin>>N;
    cin>>Q;
    cin>>S;

    vector<int> l(Q);
    vector<int> r(Q);
    for(int i=0;i<Q;i++){
        cin>>l[i];
        l[i]--;
        cin>>r[i];
        r[i]--;
    }
    vector<int> memo(N);
    memo[0]=0;
    for(int i=1;i<N;i++){
        if(S[i]=='C'&&S[i-1]=='A'){
            memo[i]=memo[i-1]+1;
        }else{
            memo[i]=memo[i-1];
        }
    }

    int ans=0;
    for(int i=0;i<Q;i++){
        ans=memo[r[i]]-memo[l[i]];
        
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
struct E
{
    int x,y,z,x1,y1;
}s[100005];
bool cmp(E a,E b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    else
        return a.y<b.y;
}
bool cmp1(E a,E b)
{
    return a.z<b.z;
}

int main()
{
    int n,m,i;
    while(~scanf("%d%d",&n,&m))
    {
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&s[i].x,&s[i].y);
            s[i].z=i+1;
        }
        sort(s,s+m,cmp);
        int t=1,t1=0;
        for(i=0;i<m;i++)
        {
            if(s[i].x==t)
            {
                t1++;
                s[i].x1=t;
                s[i].y1=t1;
            }
            else
            {
                t++;
                t1=0;
                i--;
            }
        }
        sort(s,s+m,cmp1);
        for(i=0;i<m;i++)
            printf("%06d%06d\n",s[i].x1,s[i].y1);
    }
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

ll dp[5003][5003];
priority_queue<pair<ll, pair<ll, ll> > > que;
ll INF = 1e18;

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; ++i) {
		ll h, p; cin >> h >> p;
		que.push({ -(h + p), {-p, -h} });
	}
	for (int i = 0; i <= n; ++i) {
		dp[i][0] = 0;
		for (int j = 1; j <= n; ++j) {
			dp[i][j] = INF;
		}
	}
	for (int i = 1; i <= n; ++i) {
		ll h = -que.top().second.second, p = -que.top().second.first;
		que.pop();
		for (int j = 1; j <= n; ++j) {
			dp[i][j] = dp[i - 1][j];
			if (dp[i - 1][j - 1] <= h) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + p);
			}
		}
	}

	for (int i = n; i >= 0; --i) {
		if (dp[n][i] != INF) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 195904
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<char> ans;
  int n,a,b,c;
  cin >> n >>a >>b >>c;
  vector<string> d(n);
  
  bool out=false;
  for(int i=0;i<n;i++){
    cin >> d[i];
  }
  for(int i=0;i<n;i++){
   if(d[i]=="AB"){
     if(i!=n-1 && a==1 && b==1 && c==0){
       if (d[i+1]=="BC"){
         ans.push_back('B');
        a--;
        b++;
       }
       else{
         ans.push_back('A');
        a++;
        b--;
       }
     }
     else if(a==0&&b==0)out=true;
      else if(a >= b){
        ans.push_back('B');
        a--;
        b++;
      }
      else{
        ans.push_back('A');
        a++;
        b--;
      }
    }
    else if(d[i]=="BC"){
      if(i!=n-1 && a==0 && b==1 && c==1){
       if (d[i+1]=="AB"){
         ans.push_back('B');
        c--;
        b++;
       }
       else{
         ans.push_back('C');
        c++;
        b--;
       }
     }
      else if(b==0&&c==0)out=true;
      else if(b >= c){
        ans.push_back('C');
        b--;
        c++;
      }
      else{
        ans.push_back('B');
        b++;
        c--;
      }
    }
    if(d[i]=="AC"){
      if(i!=n-1 && a==1 && b==0 && c==1){
       if (d[i+1]=="AB"){
         ans.push_back('A');
        c--;
        a++;
       }
       else{
         ans.push_back('C');
        c++;
        a--;
       }
     }
      else if(c==0&&a==0)out=true;
      else if(c >= a){
        ans.push_back('A');
        c--;
        a++;
      }
      else{
        ans.push_back('C');
        c++;
        a--;
      }
    }
    if(out)break;
  }
  if(out)cout << "No" <<endl;
  else{
    cout << "Yes" <<endl;
    for(int i=0;i<n;i++){
      cout << ans[i] <<endl;
    }
  }
}



Measured memory_bytes: 6676
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int M=scan.nextInt();
		int s[][]=new int[M][N];
		int po[]=new int[M];
		for(int i=0;i<M;i++) {
			po[i]=scan.nextInt();
			for(int j=0;j<po[i];j++) {
				s[i][j]=scan.nextInt();
			}
		}
		int p[]=new int[M];
		for(int i=0;i<M;i++) {
			p[i]=scan.nextInt();
		}
		boolean bool[]=new boolean[10];
		int ans=0;
		for(int i1=0;i1<2;i1++) {
			if(i1==0) {
				bool[0]=false;
				}
			else {
				bool[0]=true;
			}
			for(int i2=0;i2<2;i2++) {
				if(i2==0) {
				bool[1]=false;
				}
			else {
				bool[1]=true;
			}
				for(int i3=0;i3<2;i3++) {
					if(i3==0) {
						bool[2]=false;
						}
					else {
						bool[2]=true;
					}
					for(int i4=0;i4<2;i4++) {
						if(i4==0) {
							bool[3]=false;
							}
						else {
							bool[3]=true;
						}
						for(int i5=0;i5<2;i5++) {
							if(i5==0) {
								bool[4]=false;
								}
							else {
								bool[4]=true;
							}
							for(int i6=0;i6<2;i6++) {
								if(i6==0) {
									bool[5]=false;
									}
								else {
									bool[5]=true;
								}
								for(int i7=0;i7<2;i7++) {
									if(i7==0) {
										bool[6]=false;
										}
									else {
										bool[6]=true;
									}
									for(int i8=0;i8<2;i8++) {
										if(i8==0) {
											bool[7]=false;
											}
										else {
											bool[7]=true;
										}
										for(int i9=0;i9<2;i9++) {
											if(i9==0) {
												bool[8]=false;
												}
											else {
												bool[8]=true;
											}
											for(int i10=0;i10<2;i10++) {
												if(i10==0) {
													bool[9]=false;
													}
												else {
													bool[9]=true;
												}
												boolean OK=true;
												for(int j=0;j<M;j++) {
													int co=0;
													for(int k=0;k<po[j];k++) {
														if(bool[s[j][k]-1]) {
															co++;
														}
													}
													if(!(co%2==p[j])) {
														OK=false;
													}
												}
												if(OK) {
													ans++;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		switch(N) {
		case 1:System.out.println(ans/512);break;
		case 2:System.out.println(ans/256);break;
		case 3:System.out.println(ans/128);break;
		case 4:System.out.println(ans/64);break;
		case 5:System.out.println(ans/32);break;
		case 6:System.out.println(ans/16);break;
		case 7:System.out.println(ans/8);break;
		case 8:System.out.println(ans/4);break;
		case 9:System.out.println(ans/2);break;
		case 10:System.out.println(ans);break;
		}
	}
}


Measured memory_bytes: 24404
#include <stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define mx 10000008

#define pii pair<int,int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef int ll;
int fx[4]={0,+1,0,-1};
int fy[4]={+1,0,-1,0};
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    char a[n+6][m+7];
    bool vis[n+7][m+8];
    int d[n+7][m+8];
    for(int i=1;i<=n+8;i++){
        for(int j=1;j<=m+8;j++) d[i][j]=123456789;
    }
    int sx,sy,dx,dy;
    cin>>sx>>sy>>dx>>dy;
    memset(vis,false,sizeof(vis));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++) cin>>a[i][j];
    }

    queue<pii>q;
    q.push({sx,sy});

    d[sx][sy]=0;
    while(!q.empty()){
        int x=q.front().ff;
        int y=q.front().ss;

        q.pop();
        for(int i=0;i<4;i++){
            for(int j=1;j<=k;j++){
                int p=x+fx[i]*j;
                int pp=y+fy[i]*j;
                if(a[p][pp]=='@' || p<1 || p>n || pp<1 || pp>m || d[p][pp]<=d[x][y]) break;

                else if(p>=1 && p<=n && pp>=1 && pp<=m && d[p][pp]>d[x][y]+1){

                    d[p][pp]=d[x][y]+1;
                    q.push({p,pp});
                }
            }
        }
    }
    if(d[dx][dy]==123456789){
        cout<<-1<<endl;
        return 0;
    }
    cout<<d[dx][dy]<<endl;

}


Measured memory_bytes: 39760
#include<iostream>
using namespace std;
int main(void)
{
	int x=0,y=0,n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	if(n%a!=0) x=b*(n/a+1);
	else x=b*(n/a);
	if(n%c!=0) y=d*(n/c+1);
	else y=d*(n/c);
	if(x<=y) cout<<x<<endl;
	else cout<<y<<endl;
	return 0;
}


Measured memory_bytes: 3120
from functools import reduce
from fractions import gcd
#from math import gcd

def lcm(a, b):
    return  a//gcd(a, b) * b

n,m=map(int,input().split())
a=list(map(int,input().split()))

b=[0]*n
for i in range(n):
    b[i]=a[i]//2

lcma=reduce(lcm,b)   

yn=""
for i in range(n):
    if (lcma//b[i])%2==0:
        yn="no"
        break
    
if yn=="no":
    print(0)
else:    
    ans=m//lcma
    ans2=ans//2
    if (ans2*2+1)*lcma<=m:
        ans2+=1
    print(ans2)    
    

Measured memory_bytes: 16268
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double n, m, ans=0, k=0;
	cin>>n;
	double a[(int)n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		k+=a[i];
	}
	//cout<<"val of k"<<k<<endl;
	double w = k/n;
	//cout<<"val of w"<<w<<endl;
	int mean = round(w);
	//cout<<mean<<endl;
	for (int i = 0; i < n; ++i)
	{
		ans = ans + (a[i]-mean)*(a[i]-mean);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d,vector<int>(26));
  int i,j;
  for(i=0;i<26;i++){
    cin >> c.at(i);
  }
  
  for(j=0;j<d;j++){
    for(i=0;i<26;i++){
      cin >> s.at(j).at(i);
    }
  }
  
  
  vector<int> last(26,-1);
  for(j=0;j<d;j++){
    vector<int> v(26);
    for(i=0;i<26;i++){
      v.at(i)=s.at(j).at(i);
      int k;
      for(k=0;k<26;k++){
        if(k!=i){
          v.at(i) -= c.at(i)*(j-last.at(i));
        }
      }
    }
    int max=v.at(0),type=0;
    for(i=0;i<26;i++){
      if(max<=v.at(i)){
        max=v.at(i);
        type=i;
      }
    }
    last.at(type)=j;
    cout << type+1 << endl;
  }
}

Measured memory_bytes: 3684
import math
N = int(raw_input())
count = [0 for i in xrange(N)]
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

for n in xrange(2,N+1):
  table = prime_decomposition(n)
  for t in table:
    count[t-2]+=1

C = 1
for c in count:
  if c!=0:
    C*=(c+1)
print C%1000000007

Measured memory_bytes: 2692
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
int n,m,k;
bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
int main()
{
	fast;
    int T;
    T=1;
    //cin>>T;
    while(T--)
    {
    	int i,j;
    	cin>>n>>m>>k;
    	string s[n];
    	int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		x1--;
		y1--;
		x2--;
		y2--;
    	for(i=0;i<n;i++)
    	{
    		cin>>s[i];
		}
		
		int dis[n][m];
		int vis[n][m];
		mem(vis,0);
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				dis[i][j]=INF;
			}
		}
		queue<pii>q;
		if(s[x1][y1]=='@')
		{
			cout<<-1;
			return 0;
		}
		q.push({x1,y1});
		dis[x1][y1]=0;
		vis[x1][y1]=1;
		while(!q.empty())
		{
			pii p=q.front();
			q.pop();
			for(i=0;i<4;i++)
			{
				for(j=1;j<=k;j++)
				{
					int x=p.fi+j*dx[i];
					int y=p.se+j*dy[i];
					if(!valid(x,y))
					break;
					if(s[x][y]=='@')
					break;
					if(dis[x][y]<=dis[p.fi][p.se])
					break;
					dis[x][y]=dis[p.fi][p.se]+1;
					if(vis[x][y]==0)
					{
						vis[x][y]=1;
						q.push({x,y});
					}
				}
			}
		}
		if(vis[x2][y2]==0)
		cout<<-1;
		else
		cout<<dis[x2][y2];
	}
}

Measured memory_bytes: 13212
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int n,m,x,y,par[100005];
vector<int> g[100005];
bool vis[100005];
void bfs(int node){
	vis[node] = 1;
	queue<int> q;
	q.push(1);
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for(auto v:g[u])
		{
			if(vis[v]) continue;	
			par[v] = u;
			vis[v] = 1;
			q.push(v);
		}
	}
}
signed main(){
    int t = 1; //cin >> t;
    while(t--){
    	cin >> n >> m;
    	for (int i = 0; i < m; ++i)
    	{
    		cin >> x >> y;
    		g[x].push_back(y);
    		g[y].push_back(x);
    	}
    	memset(par,-1,sizeof(par));
    	bfs(1);
    	for(int i = 2; i <= n; i++)
    		if(par[i] == -1)
    		{
    			cout << "No";
    			return 0;
    		}
    	cout << "Yes\n";
    	for(int i = 2; i <= n; i++)
    		cout << par[i] << "\n";
    }    
}

Measured memory_bytes: 13136