akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){c=Getchar();rev|=c=='-';if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=2005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,k,dp[2][N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&k);
	n--;k--;
	dp[0][0]=1;
	for(int i=1;i<=k;i++)
		for(int j=0,sum=0;j<=n;j++){
			if(i+j>n){dp[i&1][j]=0;continue;}
			ch(sum,dp[i-1&1][j]),dp[i&1][j]=(sum+dp[i-1&1][j+1])%mod;
		}
	int ans=0;
	for(int i=0;i<=n-k;i++)
		ch(ans,dp[k&1][i]);
	debug(ans);
	for(int i=1;i<n-k;i++) 
		ans=ans*2%mod;
	print(ans);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<double, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}else if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

int main(void){
	int i,t;
	ll a,b,c,d,g;
	cin >> t;
	for(i=0; i<t; ++i){
		cin >> a >> b >> c >> d;
		if(a < b){
			cout << "No" << endl;
			continue;
		}else if(a%b > c){
			cout << "No" << endl;
			continue;
		}
		g = gcd(b,d);
		if((a%g)+d<b){
			cout << "No" << endl;
			continue;
		}
		cout << ((b<=c+g)?"Yes":"No") << endl;
	}
	return 0;
}


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

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<> string read<string>() {
	string s;
	getline(cin, s);
	return s;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto n = read<sint>();
	writeln(n * n * n);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>s;i--)
#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
ll MOD = 1e9+7;

ll a[3][3] = {};
bool v[3][3] = {};
ll n;
ll b[10] = {};
int main() {
	rep(i, 0, 3) {
		rep(j, 0, 3) {
			cin >> a[i][j];
		}
	}
	cin >> n;
	rep(i, 0, n) {
		cin >> b[i];

		rep(j, 0, 3) {
			rep(k, 0, 3) {
				if (a[j][k] == b[i]) {
					v[j][k] = true;
				}
			}
		}
	}
	rep(i, 0, 3) {
		if (v[i][0] == true &&
			v[i][1] == true &&
			v[i][2] == true) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	rep(j, 0, 3) {
		if (v[0][j] == true &&
			v[1][j] == true &&
			v[2][j] == true) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (v[0][0] == true &&
		v[1][1] == true &&
		v[2][2] == true){
		cout << "Yes" << endl;
		return 0;
	}
	else if (v[0][2] == true &&
		v[1][1] == true &&
		v[2][0] == true) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#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[n-1-i];
        if(i!=n-1)
        {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 3060
h,w=map(int,input().split())
s=[0]*h
t=[0]*h
for i in range(h):
  st=str(input())
  st=list(st)
  s[i]=st
  tt=[0]*w
  t[i]=tt
if s[0][0]=="#":
  t[0][0]=1
for i in range(1,h):
  t[i][0]=t[i-1][0]
  if s[i-1][0]=="." and s[i][0]=="#":
    t[i][0]=t[i-1][0]+1
for i in range(1,w):
  t[0][i]=t[0][i-1]
  if s[0][i-1]=="." and s[0][i]=="#":
    t[0][i]=t[0][i-1]+1
for i in range(1,w):
  for j in range(1,h):
    if s[j-1][i]=="." and s[j][i]=="#":
      t1=t[j-1][i]+1
    else:
      t1=t[j-1][i]
    if s[j][i-1]=="." and s[j][i]=="#":
      t2=t[j][i-1]+1
    else:
      t2=t[j][i-1]
    t[j][i]=min(t1,t2)
print(t[h-1][w-1])

Measured memory_bytes: 9388
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> d(n);
    for(int i = 0; i < n; i++) std::cin >> d[i];

    long long sum = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            sum += d[i] * d[j];
        }
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
if s[k-1] == "A":
    if k != 1 or k != n:
        print(s[:k-1] + "a" + s[k:])
    elif k == 1:
        print("a" + s[1:])
    elif k == n:
        print(s[:n-1] + "a")
elif s[k-1] == "B":
    if k != 1 or k != n:
        print(s[:k-1] + "b" + s[k:])
    elif k == 1:
        print("b" + s[1:])
    elif k == n:
        print(s[:n-1] + "b")
elif s[k-1] == "C":
    if k != 1 or k != n:
        print(s[:k-1] + "c" + s[k:])
    elif k == 1:
        print("c" + s[1:])
    elif k == n:
        print(s[:n-1] + "c")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int palindromic(int n) {
	int digits[5];
	for (int i = 0; i < 5; i++) {
		digits[i] = n % 10;
		n /= 10;
	}

	return (digits[0] == digits[4]) && (digits[1] == digits[3]);
}

int main(int argc, char *argv[]) {
	int A, B;

	cin >> A >> B;

	int cnt = 0;
	for (int i = A; i <= B; i++) {
		if (palindromic(i)) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll k,t;
 cin>>k>>t;
 vector<ll>a;ll ans,sum=0,b;
 rep(i,0,t){
  sc(b);
  push(a,b);
  sum+=b;
 }
 sort(all(a));
 sum-=a[t-1];
 ans=max((ll)0,(a[t-1]-1)-sum);
 pr(ans);
return 0;}

Measured memory_bytes: 3664
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List
import Data.Function

readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  n <- getInt
  xs <- getIntList
  putStrLn $ unwords (map (show.snd) (sortBy (compare `on` fst) (zip xs [1..n])))


Measured memory_bytes: 28284
#include<stdio.h>
int main()
{
  int n, m, k, i, j, l, cnt;
  int a[1000], b[1000];
  scanf("%d%d",&n, &m);

  for(i=0; i<2*n+1; i++){
    a[i] = i;
  }

  for(i=0; i<m; i++){
    scanf("%d", &k);
  
  //cut
    if(k!=0){
      for(j=0; j<k; j++){
	for(l=1; l<2*n+1; l++){
	  a[l-1] = a[l];
	}
	a[2*n] = a[0];
      }
    }else{
      //liful
      cnt = 1;
      for(l=1; l<2*n+1; l++){
	if(l%2==1){
	  b[l]=a[cnt];
	  
	}else{
	  b[l]=a[n+cnt];
	  cnt++;
	}
      }     
      for(l=1; l<2*n+1; l++) a[l]=b[l];
    }
  }

  for(i=1; i<2*n+1; i++) printf("%d\n",a[i]);  
  
  return 0;

}

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

#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const ll N = 5e5 +9;

ll a, b[N], c, n, mn=9999999, mx=-999999;

int main(){

    for(int i = 1; i <= 3; ++i){
        cin >> b[i];
    }
    sort(b+1,b+3+1);
    reverse(b+1,b+3+1);
    for(int i = 1; i <3; ++i){

        c +=(b[i]-b[i+1]);
        
    }
    cout<<c;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, m; cin >> n >> m;
    VL a(n); cin >> a;
    ll sum = accumulate(all(a), 0);

    rSORT(a, greater<int>());
    ll cnt = 0;
    each(i, a) {
        if (i * 4LL * m < sum)break;
        else ++cnt;
    }
    cout << (cnt >= m ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<ll,ll>
int main()
{
    boost;
    ll x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b))
    {
        cout<<"A";
    }
    else
    {
        cout<<"B";
    }
    
}

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

using ll=long long;
const ll z=0;

int main() {
  ll A,B,C;
  cin >> A >> B >> C;
  ll k;
  if((A%2)*(B%2)*(C%2)==0){
    cout << 0 << endl;
  }
  else{
    k=min(A*B,min(B*C,C*A));
    cout << k << endl;
  }
}

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

int main(){
    ll N;
    cin >> N;
    set<ll> rec;
    rep(i, 0, N){
        ll a;
        cin >> a;
        if(rec.count(a) > 0) rec.erase(a);
        else rec.insert(a);
    }
    cout << rec.size() << endl;
    return 0;
}

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

int main() {
  int64_t N,count=1,temp;
  cin >> N;
  vector<long int> vec(N-1),ans(N);
  for(int64_t i=0;i<N-1;i++) cin >> vec.at(i);

  if(N==2){
    cout << 1 << endl << 0 << endl;
    return 0;
  }

  for(int64_t i=0;i<N-2;i++){
    if(vec.at(i) == vec.at(i+1)) count++;
    else{
      temp=vec.at(i) - 1;
      ans.at(temp) += count;
      count=1;
    }
    if(i != N-3) continue;

    if(vec.at(i) != vec.at(i+1)){
      temp=vec.at(i+1) - 1;
      ans.at(temp) += count;
    }else{
      temp=vec.at(i) - 1;
      ans.at(temp) += count;
      count=1;
    }  
  }
  for(int64_t i=0;i<N;i++){
    cout << ans.at(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 6428
def print_frame(H, W):
    print('#' * W)
    for _ in range(H - 2):
        print('#' + '.' * (W - 2) + '#')
    print('#' * W)


while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    print_frame(H, W)
    print()



Measured memory_bytes: 5612
import numpy as np

A = np.array([list(map(int, input().split())) for _ in range(3)])
n = int(input())
for i in range(n):
  b = int(input())
  A = np.where(A == b, -1, A)

if -3 in np.sum(A, axis=0) or -3 in np.sum(A, axis=1) or A[0,0] + A[1,1] + A[2,2] == -3 or A[0,2] + A[1,1] + A[2,0] ==-3:
  print("Yes")
else:
  print("No")

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

using namespace std;

int main() {

	int n;
	cin >> n;
	string s;
	cin >> s;

	vector<long> a(n);

	long long r, g, b;
	r = 0;
	g = 0;
	b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') { r++; a[i] = 1; }
		else if(s[i] == 'G') { g++; a[i] = 2;}
		else if(s[i] == 'B') { b++; a[i] = 4;}
	}

	long long total;
	total = r * g * b;

	for (int i = 0; i < n-1; i++) {
		for (int j = i+1; j < n; j++) {
			if (j + j - i < n) {
				if (a[i]+a[j]+a[j+j-i]==7) {
					total--;
				}
			}
		}
	}

	cout << total << endl;

}

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

typedef long long LL;

int n;
LL ans = (LL)1;

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


    cin >> n;
    LL x, y;
    if(n == 1)
    {
        cin >> x;
        cout << x;
        return 0;
    }
    cin >> x >> y;
    LL nn = __gcd(x, y);
    ans = (x / nn) * y;
    //cout << ans << endl;
    for(int i = 2; i < n; i++)
    {
        LL a; cin >> a;
        LL nwd = __gcd(ans, a);
        ans = (a / nwd) * ans;
        //cout << ans << endl;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

cost_list = []
for i in range(0, max([X, Y]) * 2 + 1, 2):
    AB_cost = C * i
    A_cost = A * (X - int(i / 2))
    B_cost = B * (Y - int(i / 2))
    if A_cost < 0 and B_cost >= 0:
        A_cost = 0

    elif A_cost >= 0 and B_cost < 0:
        B_cost = 0
    elif A_cost >= 0 and B_cost >= 0:
        pass
    else:
        A_cost = 0
        b_cost = 0
    cost = AB_cost + A_cost + B_cost
    cost_list.append(cost)
#print(cost_list)
print(min(cost_list))


Measured memory_bytes: 12780
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    string s1;
    cin>>s1;
    if(s1=="ARC")
        cout<<"ABC\n";
    else
        cout<<"ARC\n";

    return 0;
}


Measured memory_bytes: 3640
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM = 
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x;
	cin>>x;
	ll one=x/500;
	x%=500;
	ll two=x/5;
	cout<<(one*1000+two*5);
    return 0;
}


//252908XL

/*
comments:-

*/


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

using namespace std;
priority_queue< pair<double , pair<int,int> > > pq;

int main(){
	int n, w;
	scanf("%d %d", &n, &w);
	for(int i = 0 ; i < n ; i++){
		int nI;
		int wI;
		double satuan;
		scanf("%d %d", &nI, &wI);
		satuan = (double) nI / (double) wI;
		pq.push(make_pair(satuan, make_pair(nI, wI)));
	}
	
	double out = 0;
	
	while(w != 0){
		pair< double, pair<int,int> > current = pq.top();
		double satuan = current.first;
		int n_i = current.second.first;
		int w_i = current.second.second;
		pq.pop();
		
		if(w >= w_i){
			out += n_i;
			w -= w_i;
		}
		else if(w < w_i){
			out = out + (satuan*w);
			w = 0;
		}
		
		if(pq.empty()) break;
	}
	
	printf("%lf\n", out);
	
	return 0;
}


Measured memory_bytes: 4448
import java.util.*;
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      if (a*b%2 == 0) {
        System.out.println("Even");
      } else {
        System.out.println("Odd");
      }
    }
}

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

#define INF 1234567890
#define ll long long

int N, M, K, A, B, C, D, L, R;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> L >> R >> D;
	cout << R/D - (L-1)/D;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

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

long long prime_factor(long long num){
	long long bak = num;
	set<long long> nums;
	for(long long i = 2; i*i <= num; i++){
		while(bak % i == 0){
			nums.insert(i);
			bak /= i;
		}
	}
	if(bak > 1){
		nums.insert(bak);
	}
	nums.insert(1);

	return (long long) nums.size();
}

long long A, B;
int main(){
	cin >> A >> B;
	long long num = gcd(A, B);
	cout << prime_factor(num) << endl;
}

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

template <class T>
inline void read(T &res)
{
	res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	if (bo) res = ~res + 1;
}

template <class T>
inline T Min(const T &a, const T &b) {return a < b ? a : b;}

typedef long long ll;

const int N = 2e5 + 5, E = 62;
const ll INF = 1e18;

int n, a[N], nxt[N], lst[N], top, stk[N], to[N][E];
ll k, dis[N][E], cur;
bool vis[N];

int main()
{
	read(n); read(k); k *= n;
	for (int i = 0; i < n; i++) read(a[i]);
	for (int i = n - 1; i >= 0; i--) lst[a[i]] = n + i;
	for (int i = n - 1; i >= 0; i--) nxt[i] = lst[a[i]] - i + 1, lst[a[i]] = i;
	for (int i = 0; i < n; i++) dis[i][0] = to[i][0] = nxt[i];
	for (int T = 0; T < 60; T++)
		for (int i = 0; i < n; i++)
			to[i][T + 1] = (to[i][T] + to[(i + to[i][T]) % n][T]) % n,
			dis[i][T + 1] = Min(INF, dis[i][T] + dis[(i + to[i][T]) % n][T]);
	for (int T = 60; T >= 0; T--)
		if (cur + dis[cur % n][T] <= k) cur += dis[cur % n][T];
	for (int i = n - (k - cur); i < n; i++)
		if (vis[a[i]]) while (vis[a[i]]) vis[stk[top--]] = 0;
		else vis[stk[++top] = a[i]] = 1;
	for (int i = 1; i <= top; i++) printf("%d ", stk[i]);
	return puts(""), 0;
}

Measured memory_bytes: 152284
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

a,b,c = map(int,input().split())
if a%2 == 0 and b%2 == 0 and c%2 == 0 and a == b and b == c:
    print(-1)
    sys.exit()
else:
    cnt = 0
    while True:
        if a%2 == 1 or b%2 ==1 or c%2 == 1:
            break
        a,b,c = b//2 + c//2,a//2+c//2,a//2+b//2
        cnt += 1    
    print(cnt)

Measured memory_bytes: 21156
#include <stdio.h>

#define N 8
#define SAFE -1
#define OUT 1

int a[N][N];

int gyou[N],retsu[N],dp[2*N-1],deng[2*N-1];

void initialize(){
  int i;

  for(i=0;i<N;i++) {gyou[i] = SAFE; retsu[i] = SAFE;}
  for(i=0;i<2*N-1;i++) {dp[i] = SAFE; deng[i] = SAFE;}
}

void print(){
  int   i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(a[i][j]){
	if(retsu[i]!=j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(retsu[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;

  if(i==N){
    print();
    return;
  }

  for(j=0;j<N;j++){
    if( OUT==gyou[j] || OUT==dp[i+j] || OUT==deng[i-j+N-1]) continue;

    retsu[i] = j;gyou[j]=dp[i+j] = deng[i-j+N-1] = OUT;
    recursive(i+1);
    retsu[i] = gyou[j] = dp[i+j] = deng[i-j+N-1] = SAFE;
  }

}
      
  

int main(){
  int n,i,j,r,c;

  initialize();

  scanf("%d",&n);

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      a[i][j] = 0;
    }
  }

  for(i=0;i<n;i++) {
    scanf("%d%d",&r,&c);
    a[r][c] = 1;
  }

  recursive(0);
  
   return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

const int MAXA = (1 << 20) - 1;
const int NONE = -1;

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

    vector<int> a(n);
    vector<int> xor_sum(n + 1, 0);
    vector<int> prv(MAXA + 1, NONE);
    vector<ll> cnt0(n + 1, 0);
    vector<ll> sum0(MAXA + 1, 0), sumx(MAXA + 1, 0);
    prv[0] = 0;
    cnt0[0] = 1;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        xor_sum[i + 1] = (xor_sum[i] ^ a[i]);
        ll tar = xor_sum[i + 1];

        if (prv[tar] == NONE) {
            sumx[tar] = 1;
        } else {
            ll cnt = cnt0[i] - cnt0[prv[tar]];
            (sumx[tar] += cnt * sum0[tar] % MOD) %= MOD;
        }

        prv[tar] = i + 1;

        (sum0[tar] += sumx[tar]) %= MOD;

        cnt0[i + 1] = cnt0[i] + (xor_sum[i + 1] == 0);
    }

    ll ans = 0;
    if (xor_sum[n] == 0) {
        for (int i = 1; i <= MAXA; i++) {
            (ans += sum0[i]) %= MOD;
        }
        (ans += modpow(2, cnt0[n] - 2)) %= MOD;
    } else {
        ans = sumx[xor_sum[n]];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 28544
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if(N % 2 != 0){
    cout << N / 2 + 1 <<endl;
  }
    
  else{
    cout << N / 2 << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N, M;
  while(cin >> N >> M, N && M) {
    vector<vector<i64>> sum(M, vector<i64>(1260 + 1, 0));
    i64 R;
    cin >> R;
    rep(r, 0, R) {
      i64 t, n, m, s;
      cin >> t >> n >> m >> s;
      m--;
      if(s == 1) {
        sum[m][t]++;
      }
      else {
        sum[m][t]--;
      }
    }
    rep(i,0,M) rep(j,1,1260 + 1) {
      sum[i][j] += sum[i][j - 1];
    }

    rep(i,0,M) rep(j,1,1260 + 1) {
      sum[i][j] = !!sum[i][j];
    }

    rep(i,0,M) rep(j,1,1260 + 1) {
      sum[i][j] += sum[i][j - 1];
    }


    i64 Q;
    cin >> Q;
    rep(q, 0, Q) {
      i64 s, e, m;
      cin >> s >> e >> m;
      m--;
      cout << sum[m][e - 1] - sum[m][s - 1] << endl;
    }
  }
}



Measured memory_bytes: 98372
/*二次元DP*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
  IOS;
  ll n,w;
  cin>>n>>w;
  vector<ll> value(n),weight(n);
  rep(i,n) cin>>weight[i]>>value[i];
  ll dp[n+1][w+1];
  rep(i,n+1) rep(j,w+1) dp[i][j]=0;
  rep(i,n) rep(j,w+1){
    if(j>=weight[i]) dp[i+1][j]=max(dp[i][j],dp[i][j-weight[i]]+value[i]);
    else dp[i+1][j]=dp[i][j];
  }
  cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79232
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

#include <vector>

using namespace std;

const int maxN = 50 + 10;
long long dp[maxN][2], arr[maxN];
int n, p;

int main(){
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	memset(dp, 0, sizeof(dp));
	
	cin>>n>>p;
	for(int i=1;i<=n;i++)cin>>arr[i];
	
	dp[0][0] = 1, dp[0][1] = 0;
	for(int i=1;i<=n;i++){
		if(arr[i]%2==0){
			dp[i][0] += dp[i-1][0] * 2;
			dp[i][1] += dp[i-1][1] * 2;
		}
		if(arr[i]%2==1){
			dp[i][0] += dp[i-1][1] + dp[i-1][0];
			dp[i][1] += dp[i-1][0] + dp[i-1][1];
		}
	}
	//long long ans = 0;
	//for(int i=0;i<=n;i++)ans += dp[i][p];
	cout<<dp[n][p]<<endl;
	//for(int i=0;i<=n;i++)cout<<dp[i][0]<<' ';cout<<endl;
	//for(int i=0;i<=n;i++)cout<<dp[i][1]<<' ';cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Integer> d = new HashSet<Integer>();
		for(int i = 0; i < N; i++) {
			d.add(sc.nextInt());
		}
		System.out.println(d.size());
	}
}


Measured memory_bytes: 22740
N = int(input())
Ts = [int(x) for x in input().split()]
M = int(input())
for i in range(M):
    p,x = list(map(int,input().split()))
    time = 0
    for j in range(N):
        if j == (p-1):
            time += x
        else:
            time += Ts[j]
    print(time)


Measured memory_bytes: 3060
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
C = [int(_) for _ in input().split()]
res = 0
pre = -1
for i in A:
    res += B[i-1]
    if i - pre == 1:
        res += C[pre-1]
    
    pre = i

print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    string w;
    cin >> w;
    int num[30] = {0};

    for(int j=0;j<w.size();j++){
        num[w.at(j) - 'a']++;
    }

    for(int i=0;i<26;i++){
       // cout << i << ' ' << num[i] << endl;
        if(num[i] % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }

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

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

#define int long long
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, M;
int a[100100], b[100100];
int c[100100];

int par[100100], sise[100100];

void init()
{
    for(int i = 0; i < N; i++){
        par[i] = i;
        sise[i] = 1ll;
    }
    return;
}

int root(int x)
{
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
}

bool same(int x, int y)
{
    x = root(x);
    y = root(y);
    return x == y;
}

void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if(x == y)return;
    if(x < y){
        par[y] = x;
        sise[x] += sise[y];
    }
    else {
        par[x] = y;
        sise[y] += sise[x];
    }
}

signed main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    init();
    int ans = N * (N - 1) / 2;
    for(int i = M - 1; i >= 0; i--){
        c[i] = ans;
        if(!same(a[i], b[i])){
            ans -= sise[root(a[i])] * sise[root(b[i])];
            unite(a[i], b[i]);
        }
    }
    for(int i = 0; i < M; i++){
        printf("%lld\n", c[i]);
    }


    return 0;
}
/*



*/


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int  main()
{
	string s;
	cin >> s;
	int a,b;
	a = stoi(s.substr(0, 2));
	b = stoi(s.substr(2, 2));
	// cout << a <<  endl;
	// cout << b <<  endl;
	if ((a == 0 && b > 12) || (b == 0 && a > 12) || (a > 12 && b > 12) || (a==0 && b==0))
		cout << "NA\n";
	else if (!(a >= 1 && a <=12) && (b >= 1 && b <= 12))
		cout << "YYMM\n";
	else if ((a >= 1 && a <=12) && !(b >= 1 && b <= 12))
		cout << "MMYY\n";
	else if ((a >= 1 && a <=12) && (b >= 1 && b <= 12))
		cout << "AMBIGUOUS\n";
	return (0);
}


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

int main(void){

    long double A = 0.0;
    long double B = 0.0;
    scanf("%Lf %Lf", &A, &B);
    B = A * B;
    B = floorl(B);
    printf("%0.0Lf\n", B);

    return 0;
}

Measured memory_bytes: 1756
#include<bits/stdc++.h>
#define rep(X,Y) for(int X=0;X<(Y); ++X)
#define reps(X,O,Y) for(int X=O;X<(Y); ++X)
#define pb push_back
#define eb emplace_back
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const ll MOD=1e9+7;

int mp[333][333];

int main(){
  int n;
  while(cin>>n, n){
    fill(mp[0],mp[333],0);
    vector<pii> ps(n);
    rep(i,n) cin>>ps[i].X>>ps[i].Y;
    ps.pb(ps[0]); ++n;
    int x,y,X,Y;
    cin>>x>>y; {int a,b; cin>>a>>b;}
    cin>>X>>Y; {int a,b; cin>>a>>b;}
    vector<int> xs{x,X},ys{y,Y};
    for(pii p:ps) xs.pb(p.X), ys.pb(p.Y);
    sort(all(xs)); xs.erase(unique(all(xs)),xs.end());
    sort(all(ys)); ys.erase(unique(all(ys)),ys.end());
    for(pii &p:ps){
      p.X=lower_bound(all(xs),p.X)-xs.begin();
      p.Y=lower_bound(all(ys),p.Y)-ys.begin();
    }
    x=lower_bound(all(xs),x)-xs.begin();
    y=lower_bound(all(ys),y)-ys.begin();
    X=lower_bound(all(xs),X)-xs.begin();
    Y=lower_bound(all(ys),Y)-ys.begin();
    if(x>X) swap(x,X);
    if(y>Y) swap(y,Y);
    //rep(i,n) cout<<i<<","<<ps[i].X<<","<<ps[i].Y<<endl;
    rep(i,n)if(i && ps[i-1].X==ps[i].X){
      //cout<<i<<","<<ps[i].X<<":"<<ps[i-1].Y<<","<<ps[i].Y<<endl;
      reps(y,min(ps[i-1].Y,ps[i].Y),max(ps[i-1].Y,ps[i].Y)) mp[y][ps[i].X]^=1;
    }
    reps(i,y,Y) mp[i][x]^=2;
    reps(i,y,Y) mp[i][X]^=2;
    //rep(i,10){rep(j,10)cout<<mp[i][j];cout<<endl;} cout<<endl;
    rep(i,330)rep(j,330) mp[i][j+1]^=mp[i][j];
    // for(int x:xs) cout<<x<<",";cout<<x<<","<<X<<endl;
    // for(int y:ys) cout<<y<<",";cout<<y<<","<<Y<<endl;
    // rep(i,10){rep(j,10)cout<<mp[i][j];cout<<endl;}
    ll re=0;
    rep(i,330)rep(j,330)if(mp[i][j]==1){
      re+=1ll*(xs[j+1]-xs[j])*(ys[i+1]-ys[i]);
    }
    cout<<re<<endl;
  }
  return 0;
}

Measured memory_bytes: 3536
fun main(args:Array<String>):Unit{
    val string = readLine()!!.trim()
    val k = readLine()!!.toInt()
    val res = search(string, k, (-1 until string.length - 1).toList(), "")
    println(when(res){
        is Right-> res.value
        else -> ""
    })
}
open class Either<out L, out R>
class Left<out L>(val value:L):Either<L, Nothing>()
class Right<out R>(val value:R):Either<Nothing, R>()
fun search(string:String, k:Int, index:List<Int>, substring:String):Either<Int, String>{
    if (index.isEmpty()) return Left(k + 1)
    if (k == 0) return Right(substring)
    else {
        var next = k
        for (c in "abcdefghijklmnopqrstuvwxyz") {
            val r = search(string, next - 1, indexSuccWithChar(string, index, c), substring + c)
            when(r){
                is Right -> return r
                is Left -> next = r.value
            }
        }
        return Left(next)
    }
}
fun indexSuccWithChar(string:String, index:List<Int>, char:Char):List<Int>{
    return index.map{it + 1}.filter{it < string.length && string[it] == char}
}


Measured memory_bytes: 39280
while 1:
    n=input()
    if n==0: break
    for i in xrange(n):
        pm,pe,pj=map(int,raw_input().split())
        if max(pm,pe,pj)==100 or (pm+pe)>=180 or (pm+pe+pj)>=240:
            print "A";
        elif (pm+pe+pj)>=210 or ((pm+pe+pj)>=150 and max(pm,pe)>=80):
            print "B";
        else:
            print "C";

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




int main(void){
  long int N, M;
  cin >> N;
  M = 10;
  long int count = 0;
  if (N % 2 == 0){
    while(N >= M){
      count += N / M;
      M *= 5;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
using ll = long long int;

const ll INF = 1000010;
string get_string(string s, int l, int r) {
    string ret = "";
    int cur = l;
    while(cur < r) {
        ll num = 0;
        while(isdigit(s[cur])) {
            num *= 10;
            num += s[cur++] - '0';
        }

        // printf("cur = %d\n", cur);
        if(s[cur] == '(') {
            // s[cur] = '('
            int level = 1; cur++;
            int nl = cur, nr = -1;
            for(; level != 0; cur++) {
                if(s[cur] == '(') level++;
                if(s[cur] == ')') level--;
            }
            // s[cur] は ')' のあと
            nr = cur - 1;

            string tmp = get_string(s, nl, nr);
            for(int i=0; i<num && ret.length() < INF; i++) {
                ret += tmp;
            }
        }
        else {
            // s[cur] = alphabet
            num = max(1LL, num);
            string tmp(1, s[cur]);
            for(int i=0; i<num && ret.length() < INF; i++) {
                ret += tmp;
            }
            cur++;
        }
    }
    // printf("str = %s, ret = %s\n", s.substr(l, r-l).c_str(), ret.c_str());
    return ret;
}

int main() {
    while(1) {
        string s; int N; cin >> s >> N;
        if(s == "0") break;

        int len = s.length();
        string ans = get_string(s, 0, len);

        if(ans.length() <= N) cout << 0 << endl;
        else cout << ans[N] << endl;
    }
    return 0;
}


Measured memory_bytes: 7856
def main():
    x = int(input())
    if 400<=x<600:
        print('8')
    elif 600<=x<800:
        print('7')
    elif 800<=x<1000:
        print('6')
    elif 1000<=x<1200:
        print('5')
    elif 1200<=x<1400:
        print('4')
    elif 1400<=x<1600:
        print('3')
    elif 1600<=x<1800:
        print('2')
    else:
        print('1')

if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

ll N, M;
int col[101010];
vector<int>E[101010];
int fl = 0;
void dfs(int now) {
	fore(x, E[now]) {
		if (col[x] == -1) {
			col[x] = 1-col[now];
			dfs(x);
		}
		else if (col[x] == col[now])fl = 1;
	}
}

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

	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].pb(b);
		E[b].pb(a);
	}
	for (int i = 0; i < 101010; i++)col[i] = -1;
	col[0] = 0;
	dfs(0);

	ll w = 0, b = 0;
	for (int i = 0; i < N; i++)((col[i] == 0) ? w : b) += 1;
	if (fl)puts(N*(N - 1LL) / 2LL - M);
	else puts(N*(N-1LL)/2LL - M - w*(w-1)/2LL - b*(b-1)/2LL);
	
	return 0;
}


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

int main()
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<vector<int>> ans(H, vector<int>(W, 0));
    for (int i = 0; i < B; i++)
    {
        for (int j = A; j < W; j++)
        {
            ans[i][j] = 1;
        }
    }

    for (int i = B; i < H; i++)
    {
        for (int j = 0; j < A; j++)
        {
            ans[i][j] = 1;
        }
    }

    for (vector<int> row : ans)
    {
        for (int elem : row)
        {

            cout << elem;
        }
        cout << endl;
    }
}


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

// 10000円札、5000円札、1000円札が合計でN枚ある。
// 適当に組み合わせて、Y円になることが可能か?

int main(){
    int N, Y;
    cin >> N >> Y;
    for (int x=0; x <= N; x++){
        for (int y=0; y <= N-x; y++){
            int z = N-x-y; //これにより、x+y+z=Nが補償される。
            if (10000*x + 5000*y + 1000*z == Y){
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

// 和がx+y+z=Yなる条件があるので、3重ループでなくても2重ループでzはおのずと決まってくることを使う!


Measured memory_bytes: 3636
N = int(input())
rest = []
for i in range(N):
  S,P = input().split()
  inrest = [ i + 1 , str(S) , int(P)]
  rest.append(inrest)

rest = sorted(rest , key = lambda x:x[2] , reverse = True)
rest = sorted(rest , key = lambda x:x[1])

for i in range(N):
  print(rest[i][0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,k,c[2][200],*f=c[0],*s=c[1];
    cin>>n>>m;
    iota(f,f+n*2,1);
    for(int j=0;j<m;j++){
        cin>>k;
        if(k==0)
            for(int i=0;i<2*n;i++)
                s[i]=f[i/2+i%2*n];
        else
            for(int i=0;i<2*n;i++)
                s[i]=f[(i+k)%(2*n)];
        swap(f,s);
    }
        for(int i=0;i<2*n;i++)
            cout<<f[i]<<(i+1==2*n?'\n':'\n');
}



Measured memory_bytes: 3076
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan_ = new Scanner(System.in);
        int i = 1;
        int x;
        while(scan_.hasNext()){
            x = scan_.nextInt();
            if(x != 0){
            System.out.println("Case " + i++ +": " + x );
            }
        }
}
}



Measured memory_bytes: 42332
n = int(input())
w = list(map(int,input().split()))

min_s = 1000

for t in range(n-1):
    s1 = sum(w[:t+1])
    s2 = sum(w[t+1:])
    
    tmp = abs(s1-s2)
    min_s = min(min_s,tmp)
    
print(min_s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long a,b,c[200005],n,d,ans,x[200005],y[200005],l,k;
struct node
{
    long long x,y;
} w[200005];
inline bool cmp(node x,node y)
{
    return x.x<y.x;
}
int main()
{
    scanf("%lld%lld%lld",&n,&d,&a);
    d*=2;
    for(int i=1; i<=n; ++i)
    {
        scanf("%lld%lld",&w[i].x,&w[i].y);
        w[i].y=(w[i].y+a-1)/a;
    }
    sort(w+1,w+n+1,cmp);
    l=1;
    for(int i=1; i<=n; ++i)
    {
        while(l<i&&w[i].x-w[l].x>d)
            k-=c[l++];

        c[i]=w[i].y-k;
        if(c[i]<0)
            c[i]=0;
        ans+=c[i];
        k+=c[i];
    }
    printf("%lld",ans);
}

Measured memory_bytes: 5888
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int X, t;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> X >> t;

  cout << max(X - t, 0) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int y = scan.nextInt();
        int max;
        int min;
        if(x < y){
            min = x;
            max = y; 
        } 
        else{
            min = y;
            max = x;
        }
        while(max % min != 0){
            int hold = min;
            min = max % min;
            max = hold;
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 26180
# -*- coding: utf-8 -*-
N = int(input())
S = input()

forward, backward = 0, 0
v = 0
for i in range(N):
    if S[i] == '(':
        v += 1

    else:
        v -= 1

    if v < 0:
        forward += 1
        v = 0

if v > 0:
    backward = v

ret = '(' * forward + S + ')' * backward
print(ret)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#define int long long
using namespace std;
signed main()
{
  vector<int> v;
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      int a;
      cin>>a;
    v.push_back(a);
  }

  vector<int> b(n,INT_MAX);
  b[n-1]=0;
  for(int i=n-2;i>=0;i--)
  {
    if(i+1<n)
    {
      b[i]=min(b[i],(abs(v[i+1]-v[i])+b[i+1]));
    }
    if(i+2<n)
    {
      b[i]=min(b[i],(abs(v[i+2]-v[i])+b[i+2]));
    }
    
  }
  
    cout<<b[0];
    //return 0;
}


Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
int st[1000003][5];
string q;
int dmc(int g,int k)
{
    if(g==q.length())return k;
    if(st[g][k]!=1e9)return st[g][k];
    int z=1e8;
    if(!k)z=min((dmc(g+1,0)+(q[g]-'0')),(dmc(g+1,1)+10-(q[g]-'0')));
    else{
        z=min(z,dmc(g+1,0)+1+(q[g]-'0'));
        z=min(z,dmc(g+1,1)+10-((q[g]-'0')+1));
    }
    return st[g][k]=z;
}
int main()
{
    int g;
    cin>>q;
    reverse(q.begin(),q.end());
    for(g=0;q[g];g++)st[g][0]=st[g][1]=1e9;
    printf("%d\n",dmc(0,0));
    return 0;
}


Measured memory_bytes: 70716
def main():
    S=input()
    T=input()
    max_count = 0
    for i in range(len(S)-len(T)+1):
        tmp_count = 0
        for j in range(len(T)):
            if S[i+j] == T[j]:
                tmp_count = tmp_count+1
        if tmp_count > max_count:
            max_count = tmp_count

    print(len(T)-max_count)
    #N = int(input())
    #A = [int(s) for s in input().split()]
    #

main()


Measured memory_bytes: 9048
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
	int N, num[100001] = { 0 };
	int count = 1, ans = 1;

	cin >> N;

	int n;
	for (int i = 0; i < N; i++)
	{
		cin >> n;
		num[n]++;
		count = max(count, n);
	}

	for (int i = 1; i < count + 1 ; i++)
	{
		ans = max(ans, num[i - 1] + num[i] + num[i + 1]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
x, k ,d = map(int,input().split())
q = abs(x) // d
mod = abs(x) % d
time = k - q
if time >= 2:
  if time % 2 == 0:
    ans = mod
  else:
    ans = abs(mod) - d
else:
  ans = abs(x) - k * d
print(abs(ans))

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    ll n; cin >> n;
    set<ll> a;
    rep(i,n){
        int b; cin >> b;
        a.insert(b);
    }
    if(a.size() == n)print("YES");
    else print("NO");
}


Measured memory_bytes: 9600