akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}
bool f(pll a , pll b){
	return a.y < b.y ;
}

//check modulo
int main(){
	IOS;
	cout.precision(30) ;
	int n , k ;cin >> n >> k ;
	vll a(n) ; for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	ll ans = 0 ;
	for(int i = -1 ; i < min(n , k + 1) ; i++){
		int nb = 0 ;
		for(int j = n ; j > i && nb + i <= k ;j-- , nb++){
			ll sum = 0 ;
			int move = 0 ;
			priority_queue<int, std::vector<int>, std::greater<int> > pq;
			for(int p = 0 ; p <= i ; p++ , move++) {sum += a[p] ;pq.push(a[p]) ;}
			for(int p = n - 1 ; p >= j ; p--,move++) {sum += a[p] ;pq.push(a[p]) ;}
			while(move < k && pq.size()){
				if(pq.top() >= 0) break ;
				sum -= pq.top() ;
				pq.pop() ;
				move++ ;
			}
			if(move <= k) ans = max(ans , sum) ;
		}
	}
	cout << ans << endl ;
		
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
$count_val = array();

function kumiawase($num){
  return ($num*($num-1))/2;
}

//前処理
for($i=0;$i<$n;$i++){
  $count_val[$a_li[$i]]++;
}
foreach($count_val as $val){
  if($val>=2){
    $sum += kumiawase($val);
  }
}


for($i=0;$i<$n;$i++){
  $tmp_num = $count_val[$a_li[$i]];
  $dif = kumiawase($tmp_num)-kumiawase($tmp_num-1);
  echo ($sum-$dif)."\n";
}
  

Measured memory_bytes: 34580
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

using ll = long long;

ll mod = 998244353;

ll mypow(ll m, ll x) {

    if(x == 0)
        return 1;

    if(x % 2 == 0)
        return mypow((m * m) % mod, x / 2);
    else
        return (m * mypow(m, x - 1) ) % mod;


}


int main() {

    int n;

    cin >> n;

    vector<ll> distanceCount(n, 0);
    ll maxDistance = 0;

    bool flag = true;

    for(ll i = 0; i < n; ++i) {
        ll num;
        cin >> num;

        if(!i && num != 0)
            flag = false;

        distanceCount[num]++;

        maxDistance = max(maxDistance, num);

    }

    if(distanceCount[0] != 1 || !flag) {
        cout << 0 << endl;
        return 0;
    }


    ll answer = distanceCount[0];
    for(ll i = 1; i <= maxDistance; ++i) {
      //  cout << i << " " << distanceCount[i] << endl;
        answer = (answer * mypow(distanceCount[i - 1], distanceCount[i])) % mod;
    }

    cout << answer << endl;

    return 0;

}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

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

int main() {
  int g[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> g[i][j];
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int y = 0; y < 3; y++) {
      for (int x = 0; x < 3; x++) {
        if (g[y][x] == a) g[y][x] = 0;
      }
    }
  }

  bool can = false;
  if (!g[0][0] && !g[0][1] && !g[0][2]) can = true;
  if (!g[1][0] && !g[1][1] && !g[1][2]) can = true;
  if (!g[2][0] && !g[2][1] && !g[2][2]) can = true;
  if (!g[0][0] && !g[1][0] && !g[2][0]) can = true;
  if (!g[0][1] && !g[1][1] && !g[2][1]) can = true;
  if (!g[0][2] && !g[1][2] && !g[2][2]) can = true;
  if (!g[0][0] && !g[1][1] && !g[2][2]) can = true;
  if (!g[2][0] && !g[1][1] && !g[0][2]) can = true;

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


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod =1e+9+7;

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

int main(){
    string s,t; cin>>s>>t;
    ll T=t.size();
    ll S=s.size();
    ll chance=S-T+1;
    ll cnt=0;
    ll ans=T;
    for(int i=0;i<chance;i++){
        rep(j,T){
            if(s[i+j]==t[j])cnt++;
        }
        ans=min(ans,T-cnt);
        cnt=0;
    }
    cout<<ans<<endl;
    }













































































Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string ans = "";
    REP(i,S.size()){
        if(S[i] == '0') ans += '0';
        if(S[i] == '1') ans += '1';
        if(S[i] == 'B' && ans.size() > 0) ans.pop_back();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm;

int gcd(int a, int b, ref int step) {
  int inner(int a, int b, ref int step) {
    if (b == 0) return a;
    else {
      step++;
      return inner(b, a % b, step);
    }    
  }
  return inner(max(a, b), min(a, b), step);
}

void main() {
  for(int a, b; readf("%d %d\n", &a, &b), a + b != 0;) {
    int step = 0;
    int result = gcd(a, b, step);
    writeln(result, " ", step);
  }
}

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

int main(){
  int n;
  cin>>n;
  vector<long long> a(n+1);
  vector<long long> b(n+1);
  b[0]=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    b[i]=b[i-1]+a[i];
  }
  sort(b.begin(),b.end());
  long long ans=0,tmp=1;

  for(int i=1;i<=n;i++){
    if(b[i]==b[i-1]){
      tmp++;
    }else{
      ans+=tmp*(tmp-1)/2;
      tmp=1;
    }
  }
  ans+=tmp*(tmp-1)/2;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
#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 A,B,C,X;
    cin>>A>>B>>C>>X;
    ll ans=0;
    rep(i,0,A+1){
        rep(j,0,B+1){
            rep(k,0,C+1){
                if(X==500*i+100*j+50*k)ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;

int main(){
  const char *left = "qwertasdfgzxcvb";
  int hand[128];
  char buff[64];
  REP(i, 128) hand[i] = 0;
  REP(i, strlen(left)) hand[left[i]] = 1;

  while(scanf("%s", buff), buff[0] != '#'){
    int len = strlen(buff);
    int ans = 0;

    REP(i, len - 1) ans += abs(hand[buff[i]] - hand[buff[i+1]]);

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

  return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		int output = 0;
		for(int a=0;a<=9;a++){
			for(int b=0;b<=9;b++){
				for(int c=0;c<=9;c++){
					for(int d=0;d<=9;d++){
						if(a+b+c+d==n){
							output++;
						}	
					}
				}
			}
		}
		cout << output << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#define MOD 1000000007
using namespace std;

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

	long long ans = 1;
	for (int i=1; i<=N; i++) {
		ans = (ans*i)%MOD;
	}
	cout << ans << endl;

	return 0;
}


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

int main()
{
    string S;
    cin >> S;
    int val = S.size() / 2 - 1;
    while(val > 0) {
        if(S.substr(0, val) == S.substr(val, val)) break;
        val--;
    }

    cout << val * 2 << endl;

    return (0);
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 10

int H, W;
string graph[MAX_N];

bool dfs(int i = 0, int j = 0) {
    if(i == H-1 && j == W-1) { return true; }
    if(i < H-1 && graph[i+1][j] == '#') {
        bool ret = dfs(i+1, j);
        if(ret) { return true; }
    }
    if(j < W-1 && graph[i][j+1] == '#') {
        bool ret = dfs(i, j+1);
        if(ret) { return true; }
    }
    return false;
}

signed main()
{
    cin >> H >> W;
    REP(i, H) {
        cin >> graph[i];
    }
    int cnt = 0;
    REP(i, H) {
        REP(j, W) {
            if(graph[i][j] == '#') { cnt++; }
        }
    }
    if(cnt != H + W - 1) {
        printf("Impossible\n");
        return 0;
    }
    if(dfs()) { printf("Possible\n"); }
    else { printf("Impossible\n"); }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    scanf("%d", &k);
    if(k % 2 == 0) {
        printf("%d\n", (k / 2) * (k / 2));
    }
    else printf("%d\n", (k / 2) * (k / 2 + 1));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;
long long int dp[2][63];
long long int ds[63];
long long int sums[2][63];
long long int as[100003];
int main() {
	// your code goes here
	memset(dp,-1,sizeof(dp));
	memset(ds,0,sizeof(ds));
	memset(sums,0,sizeof(sums));
	int n;
	long long int k,r=1,t=0;
	int p=1;
	int p2=1;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>as[i];
		t=max(t,as[i]);
	}
	
	while((r<=t)||(r<=k)){
		if((k&r)==0){
			ds[p]=0;
		}else{
			ds[p]=1;
		}
		for(int i=0;i<n;i++){
			if((as[i]&r)==0){
				sums[1][p]+=r;
			}else{
				sums[0][p]+=r;
			}
		}
		
		if(r<=k)p2++;
		p++;
		r*=2;
		
	}
	dp[1][p]=0;
	while(p2<p){
		dp[1][p-1]=dp[1][p]+sums[0][p];
		p--;
	}
	
	while(p>0){
		//cout<<p<<" "<<dp[0][p]<<" "<<dp[1][p]<<"\n";
		if(ds[p]==1){
			dp[0][p-1]=dp[1][p]+sums[0][p];
			dp[1][p-1]=dp[1][p]+sums[1][p];
		}else{
			dp[1][p-1]=dp[1][p]+sums[0][p];
		}
		if(dp[0][p]>-1){
			dp[0][p-1]=max(dp[0][p-1],dp[0][p]+max(sums[0][p],sums[1][p]));
		}
		//cout<<p<<" "<<dp[0][p-1]<<" "<<dp[1][p-1]<<"\n";
		p--;
	}
	cout<<max(dp[1][0],dp[0][0])<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#よくわからないがAC

import sys
sys.setrecursionlimit(10**7)

n,m=map(int,input().split())
#G[i]=iに来れるノード
G=[[] for i in range(n)]
for i in range(m):
    s,t,d=map(int,input().split())
    G[t].append((s,d))


dp=[[float('inf')]*n for i in range(2**n)]

#頂点0からとする
dp[0][0]=0
#0からbitを辿ってvに来る(vはSに入っている)
def rec(bit,v):
    if dp[bit][v]!=float('inf'):
        return dp[bit][v]
    
    res=float('inf')
    #Sからvを取る
    prev_bit=bit&~(1<<v)
    #print(bit,v,prev_bit)
    for u,cost in G[v]:
        #下手
        if prev_bit==0 and u==0:
            res=cost
            break
        if not (prev_bit&(1<<u)):
            continue
        
        res=min(res,rec(prev_bit,u)+cost)
    
    dp[bit][v]=res
    return dp[bit][v]

ans=rec(2**n-1,0)
if ans==float('inf'):
    print(-1)
else:
    print(ans)






Measured memory_bytes: 16236
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define MOD 1e9+7

bool comp(pair<int, int> a ,pair<int, int> b)
{
    if(a.first!=b.first)
    {
        return a.first<b.first;
    }
    else
    {
        return a.second>b.second;
    }
}

int main()
{
    int n;cin>>n;
    vector<int> l(n);
    vector<int> r(n);
    int i;
    for(i=0;i<n;i++)
    {
        cin>>l.at(i)>>r.at(i);
        r.at(i)++;
    }
    int lmax,rmin;
    lmax=0;
    rmin=1e9+2;
    long long ans=0;
    for(i=0;i<n;i++)
    {
        if(l.at(i)>lmax)
        {
            lmax=l.at(i);
        }
        if(r.at(i)<rmin)
        {
            rmin=r.at(i);
        }
    }
        vector<int> len(n);
        for(i=0;i<n;i++)len.at(i)=r.at(i)-l.at(i);
        sort(len.begin(),len.end());
        ans=len.at(n-1)+max(rmin-lmax,0);
        vector<int> a(n);
        vector<int> b(n);
        for(i=0;i<n;i++)
        {
            a.at(i)=max(r.at(i)-lmax,0);
            b.at(i)=max(rmin-l.at(i),0);
        }
        vector<pair<int, int>> p(n);
        for(i=0;i<n;i++)
        {
            p.at(i)=make_pair(a.at(i),b.at(i));
        }
        sort(p.begin(),p.end(),comp);
        vector<int> mins(n,0);
        vector<int> mint(n,0);
        mint.at(0)=p.at(0).second;
        mins.at(n-1)=p.at(n-1).first;
        for(i=1;i<n-1;i++)
        {
            mint.at(i)=min(mint.at(i-1),p.at(i).second);
            mins.at(n-1-i)=min(mins.at(n-i),p.at(n-1-i).first);
        }
        for(i=0;i<n-1;i++)
        {
            if(mint.at(i)+mins.at(i+1)>ans)ans=mint.at(i)+mins.at(i+1);
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 3712
A, B, C, D = [int(el) for el in input().split()]

rnd = 0
while A > 0 and C > 0:
    rnd = (rnd + 1) % 2
    if rnd:
        C -= B
    else:
        A -= D

if A > 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(){
    string o,e,ans;
    cin>>o>>e;
    ans="";
    for(int i=0;i<o.length();i++){
        ans+=o[i];
        if(o.length()!=e.length() && i+1==o.length()) break;
        ans+=e[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
int n,ans,x;
int main()
{
cin>>n;
int ans=0;
for (int i=1;i<=n;i++)
{
    scanf("%d",&x);
    while (x%2==0)
    {
        ans++;
        x/=2;
    }
}
printf("%d\n",ans);
    return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
using namespace std;

int main() {
    int n;
    scanInt(n);
    n = (n+1)/2;
    printInt(n);
    return 0;
}


Measured memory_bytes: 3820
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        while (n != 0) {
            for (int i = 0; i < n; i++) {
                int math = scan.nextInt();
                int English = scan.nextInt();
                int japan = scan.nextInt();

                if (math == 100 || English == 100 || japan == 100) {
                    System.out.println("A");

                } else if ((math + English) / 2 >= 90) {
                    System.out.println("A");

                } else if ((math + English + japan) / 3 >= 80) {
                    System.out.println("A");

                } else if ((math + English + japan) / 3 >= 70) {
                    System.out.println("B");

                } else if ((math + English + japan) / 3 >= 50 && math >= 80 || English >= 80) {
                    System.out.println("B");

                } else {
                    System.out.println("C");
                }
            }
            n = scan.nextInt();
        }

    }
}



Measured memory_bytes: 38036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll Q;
    string S;
    cin >>S>>Q;
    ll now = 0;
    string cm,cb;

    rep(i,Q){
        ll opt;
        cin>>opt;
        if(opt==1){
            now ^=1;
        }else{
            ll f;
            char c;
            cin>>f>>c;
            f--;
            if(now^f){
                cb = cb+c;
            }else{
                cm= c+cm;
            }

        }
    }

    if(now){
        reverse(all(S));
        reverse(all(cb));
        reverse(all(cm));
        S = cb+S+cm;
    } else{
        S = cm+S+cb;
    }
    
    cout << S << endl;


    return 0;
    

}

Measured memory_bytes: 4416
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    idx = 0
    target = key[idx]
    for ii in s:
        if target == ii:
            idx += 1
            if idx > 2:
                ans += 1
                break
            target = key[idx]
print(ans)

Measured memory_bytes: 3188
H, W = map(int, input().split())
P = [list(input().split()) for i in range(H)]
list_ALPHABET = [chr(i) for i in range(65,91)]

for i in range(H) :
    for j in range(W) :
        if P[i][j] == "snuke" :
            print(list_ALPHABET[j] + str(i+1))

Measured memory_bytes: 3060
import java.lang.Math.min

fun main(args: Array<String>) {
    val (k, x) = readLine()!!.split(" ").map { Integer.parseInt(it) }
    for(i in Math.max(-1000000, x-k+1)..Math.min(1000000, x+k-1)) {
        print(i)
        print(" ")
    }
}

Measured memory_bytes: 37544
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

string s;

int main() {
    ios_base::sync_with_stdio(0);

    cin >> s;

    if(s == "ABC") {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace paiza2
{
    class Program
    {
        static void Main(string[] args)
        {
            string output = "";
            string read = Console.ReadLine();
            for (int c = 0; c < read.Length; c++)
            {
                if (read[c] == '0')
                    output += "0";
                if (read[c] == '1')
                    output += "1";
                if (read[c] == 'B')
                {
                    if (output.Length != 0)
                    {
                        int length = output.Length;
                        output=output.Substring(0,length-1);
                    }

                }

            }
            Console.WriteLine(output);


        }

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int x; cin >> x;
    if(x < 1200) dunk("ABC");
    else dunk("ARC");
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char x[200005];
int a[200005];
int main()
{
	scanf("%s", x);
	int i;
	int len = strlen(x);
	int cnt = 0;
	for(i = 0; i < len; i++)
	{
		if(x[i] == 'A')
		{
			cnt++;
			a[cnt] = 1;
		}
		else if(x[i] == 'B' && x[i + 1] == 'C')
		{
			cnt++;
			a[cnt] = 2;
			i++;
		}
		else
		{
			cnt++;
			a[cnt] = 3;
		}
	}
	int la = 1;
	long long ans = 0;
	long long p1 = 0, p2 = 0;
	for(i = 1;i <= cnt; i++)
	{
		if(a[i] == 3)
		{
			p1 = 0;
			p2 = 0;
		}
		else if(a[i] == 1)
			p1++;
		else
		{
			p2++;
			ans += p1;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
{
    long long int i, j, x, k, d, p, q, r;
    cin >> x >> k >> d;
    x = abs(x);
    if (x/d >= k)
    {
        cout << x - (k * d) << endl;
        return;
    }
    q = x - (x / d) * d;
    k = k - (x / d);
    r = abs(q - d);
    if (k % 2 == 1)
    {
        cout << r << endl;
    }
    else
    {
        cout << q << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    int i, t = 1;
    //cin>>t;
    for (i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        g[u - 1].pb(v - 1);
        g[v - 1].pb(u - 1);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 10636
var n,t,min,i,a,b:integer;
begin 
	read(n,t);
    min:=maxint;
    for i:=1 to n do
    begin 
    	read(a,b);
        if (b<=t) and (a<min) then min:=a;
    end;
    if min<maxint then write(min)
    	else write('TLE');
end.

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

using namespace std;

const int maxN = 200000;

int N;
int A[maxN];
long long s[maxN + 1];

long long difference(const long long & a, const long long & b, const long long & c, const long long & d) {
	vector<long long> vtr;
	vtr.push_back(a);
	vtr.push_back(b);
	vtr.push_back(c);
	vtr.push_back(d);
	sort(vtr.begin(), vtr.end());
	return vtr[3] - vtr[0];
}

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

	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];

	for (int i = 0; i < N; i++)
		s[i + 1] = s[i] + A[i];

	long long ans = LLONG_MAX;
	for (int i = 2, l = 0, r = 2; i <= N - 2; i++) {
		for (; l < i - 1 && s[l + 1] * 2 <= s[i]; l++);
		for (; r < N - 1 && s[r + 1] * 2 <= s[i] + s[N]; r++);
		for (int x = 0; x < 2; x++) {
			for (int y = 0; y < 2; y++) {
				int a = l + x, b = r + y;
				if (0 < a && a < i && i < b && b < N)
					ans = min(ans, difference(s[a], s[i] - s[a], s[b] - s[i], s[N] - s[b]));
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 2560
//https://atcoder.jp/contests/abc170/tasks/abc170_a
#include <bits/stdc++.h>
using namespace std;

vector<int> x(5);

int main() {
    for (int i = 0 ; i < 5; i++) cin >> x[i];
    int ans;
    for (int i = 0; i < 5; i++) {
        if (x[i] == 0) ans = i+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll r = 0;
    ll b = 0;
    rep(i,n){
        if(s[i]=='R')r++;
        else b++;
    }
    if(r>b)print("Yes");
    else print("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,k,q,ans,a[2007],b[2007],c[2007],cnt[2007],num;
int main()
{
	cin>>n>>k>>q;m=n;
	for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];
	sort(b+1,b+n+1);
	m=unique(b+1,b+m+1)-(b+1);
	for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+m+1,a[i])-b;
	ans=b[m]-b[1];
	a[0]=a[n+1]=0;
	for(int i=1;i<=m;i++)
	{
		int hd=0,tot=0;
		for(int j=1;j<=m;j++)cnt[j]=0;
		for(int j=1;j<=n+1;j++)if(a[j]<i)
		{
			if(j-hd>k)
			{
				tot+=j-hd-k;num=0;
				for(int t=hd+1;t<j;t++)c[++num]=a[t];
				sort(c+1,c+num+1);
				for(int t=1;t<=j-hd-k;t++)cnt[c[t]]++;
			}
			hd=j;
		}
		if(tot<q)continue;
		for(int j=1;j<=m;j++)
		{
			cnt[j]+=cnt[j-1];
			if(cnt[j]>=q){ans=min(ans,b[j]-b[i]);break;}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：
int fct(int m, int k) {
	int ft = 1;
	rep(i, k) ft *= m;
	return(ft);
}

int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

bool has_divisor(int n, int i) {
	// base case 1:
	if (i == n) return false;
	// base case 2:
	if (n % i == 0) return true;
	return has_divisor(n, i+1);
}

bool is_prime(int n) {
	if (n == 1) return false;
	else if (n == 2) return true;
	else {
		return !has_divisor(n, 2);
	}
}

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

	int A, B; cin >> A >> B;
	int mn = min(A, B);
	int mx = max(A, B);
	int gd = gcd(mx, mn);

	int ct = 0;
	for(int i=2; i*i<=gd; i++) {
		if(gd%i == 0) ct += 1;
		while(gd%i == 0) gd /= i; //Remained Only Prime i! 
	}
	if(gd != 1) ct += 1; //?

	cout << ct+1 << endl; //Add i=1 Case.
	return 0;
}
// std::string str;
// str = std::to_string(int i);
// bitset<3> s(N);


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;

using namespace std;

int main() {
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            //グーを出す
            if(s[i] == 'g'){

            }else{
                count--;
            }
        }else{
            //パーを出す
            if(s[i] == 'g'){
                count++;
            }else{

            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
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;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N , M ;
    vector<ll> swit[11];
    vector<ll> p;
    cin >> N >> M ;


    rep(i, M){
        ll k; cin >> k ;
        rep(j, k){
            ll s;
            cin >> s;
            s--;
            swit[s].pb(i);
        }
    }

    rep(i, M){
        ll inp; cin >> inp;
        p.pb(inp);
    }

    ll ans = 0;

    rep(i, 1<<N){
//        cerr << "------stage: " << i << " ----- " << endl;

        vector<ll> light;
        rep(j, M){
            light.pb(p[j]);
        }

        rep(j, N){
            if(i&(1<<j)) {
//                cerr << "onswitch:" << (j+1) << "  light:";
                rep(k, swit[j].size()){
                    light[swit[j][k]] ++;
//                    cerr << light[swit[j][k]] << " ";
                }
//                cerr << endl;
            }
        }

        bool flag = true;
        rep(j, M){
            if(light[j] % 2 == 1) flag = false;
        }
        if(flag) ans ++;
    }

    cout << ans << endl;

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

n = int(input())
a = [int(x) for x in input().split()]
a.sort()
if a[0] == 0:
    print(0)
    sys.exit()
b = 1
for i in a:
    b *= i
    if b > 10**18:
        print(-1)
        sys.exit()
print(b)

Measured memory_bytes: 84796
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    string s;
    cin >> s;
    int f = 0, x = stoi(s);
    REP(i, s.length()){
        f += (int)(s[i] - '0');
    }
    if(x%f == 0) puts("Yes");
    else puts("No");
    return 0;
}


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

const int N = 105, V = 1e5+5;
int n, w, ans, dp[N][V];
std::pair<int, int> a[N];

int32_t main() {
  scanf("%d%d", &n, &w);

  for (int i = 1; i <= n; i++)
    scanf("%d%d", &a[i].first, &a[i].second);

  memset(dp, 0x3f, sizeof dp);
  for (int i = 0; i <= n; i++) dp[i][0] = 0;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < V; j++) {
      const int wt = a[i].first, v = a[i].second;
      dp[i][j] = v > j ? dp[i-1][j] : std::min(wt + dp[i-1][j-v], dp[i-1][j]);
      if (dp[i][j] <= w)
        ans = std::max(ans, j);
    }
  }

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


Measured memory_bytes: 41216
#include <iostream>
#include <functional>
#include <list>
using namespace std;

//0001
int main(){
	list<int> height_list(10);

	for(int i=0; i<10; ++i){
		int height;
		cin >> height;
		height_list.push_back(height);
	}

	height_list.sort(greater<int>());
	list<int>::iterator ite = height_list.begin();
	for(int i=0; i<3; ++i){
		cout << *ite++ << endl;
	}
	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  int ans=0;

  for(int i=0;i<n;i++){
    int tmp=0;
    for(char j='a';j<='z';j++){
      int flag1=0,flag2=0;
      for(int k=0;k<i;k++){
        if(s[k]==j){
          flag1=1;
          break;
        }
      }
      for(int k=i;k<n;k++){
        if(s[k]==j){
          flag2=1;
          break;
        }
      }
      if(flag1&&flag2) tmp++;
    }
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
	string s;
	cin >> s;
	fori(s.length()) {
		if (i % 2 == 1) {
			if (s[i] == 'R') {
				cout << "No";
				return 0;
			}
		} else {
			if (s[i] == 'L') {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main() {
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}



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

int main(){
  // input
  int N; cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  
  // compute
  int ans = 0;
  for (int i = 0; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < i; j++) {
      if (H[i]<H[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
    ++ans;
    }
  }
  
  
  // output
  cout << ans << endl;
}

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

using namespace std;

int main(){
  
  int i,j,n,move,m,jewel_x,jewel_y;
  string houkou;
  
  while(1){
    int map[21][21]={0};
    int count=0;
    int x=10,y=10;
    cin >> n;
    if(n==0)break;
    for( i = 0; i < n; i++){
      cin >> jewel_x >> jewel_y;
      map[jewel_x][jewel_y]=1;
    }

      
    cin >> m;
    for(i = 0; i < m; i++){
      cin >> houkou >> move;
      if(houkou=="N"){
	for(j = 0; j < move; j++){
	  y++;
	  if(map[x][y]==1){
	    map[x][y]=0;
	    count++;
	  }
	}
      }
      if(houkou=="S"){
	for(j = 0; j < move; j++){
	  y--;
	  if(map[x][y]==1){
	    map[x][y]=0;
	    count++;
	  }
	}
      }
      if(houkou=="E"){
	for(j = 0; j < move; j++){
	  x++;
	  if(map[x][y]==1){
	    map[x][y]=0;
	    count++;
	  }
	}
      }
      if(houkou=="W"){
	for(j = 0; j < move; j++){
	  x--;
	  if(map[x][y]==1){
	    map[x][y]=0;
	    count++;
	  }
	}
      }
    }
    
    if(n==count){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    
  }
  return 0;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int h,w;
vector<int> G[910];

#define MAX_V 910
int V = 909;
int d[MAX_V];
void dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d,d+V,INF);
    d[s] = 0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii p = que.top();
        que.pop();
        int v = p.se;
        if(d[v] < p.fi) continue;
        for(auto x:G[v]){
            if(d[x] > d[v]+1){
                d[x] = d[v] + 1;
                que.push(pii(d[x],x));
            }
        }
    }
}

/*----------------------------------------------------------------*/
signed main(){

    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0)break;
        rep(i,910)G[i].clear();
        int in;
        rep(i,h-1){
            rep(j,w-1){
                cin >> in;
                // cerr << in;
                if(in == 0){
                    G[i*w+j].pb(i*w+j+1);
                    G[i*w+j+1].pb(i*w+j);
                }
            }
            // cerr << endl;
            rep(j,w){
                cin >> in;
                // cerr << in;
                if(in == 0){
                    G[i*w+j].pb((i+1)*w+j);
                    G[(i+1)*w+j].pb(i*w+j);
                }
            }
            // cerr << endl;
        }
        rep(j,w-1){
            cin >> in;
            // cerr << in;
            if(in == 0){
                G[(h-1)*w+j].pb((h-1)*w+j+1);
                G[(h-1)*w+j+1].pb((h-1)*w+j);
            }
        }
        // cerr << endl;
        dijkstra(0);
        if(d[h*w-1] == INF)cout << 0 << endl;
        else cout << d[h*w-1]+1 << endl;
        // rep(i,h){
        //     rep(j,w){
        //         cerr << d[i*w+j] << " ";
        //     }cerr << endl;
        // }
    }   
    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https:/joi2012yo.contest.atcoder.jp/tasks/joi2012yo_e


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define N 4
#define N2 16

static const int dx[4]={-1,0,1,0};
static const int dy[4]={0,-1,0,1};
//static const char dir[4]={'u','l','d','r'};
int MDT[N2][N2];

struct Puzzle{
  int f[N2],MD;
  int space,cost;
  bool operator < (const Puzzle &p) const {
    for (int i = 0; i < N2; i++) {
      if (f[i] == p.f[i]) continue;
      return f[i] < p.f[i];
    }
    return false;
  }
};

struct state{
  Puzzle puzzle;
  int estimated;
  bool operator < (const state &s) const{
    return estimated > s.estimated;
  }
};

int getAllMD(Puzzle pz){
  int sum=0;
  for(int i=0;i<N2;i++){
    if(pz.f[i]==N2) continue;
    sum+=MDT[i][pz.f[i]-1];
  }
  return sum;
}
priority_queue<state> PQ;
map<Puzzle,bool> V;
int astar(Puzzle &s){
 
  s.MD=getAllMD(s);
  s.cost=0;
 
  Puzzle v;
  state initial;
  initial.puzzle=s;
  initial.estimated=getAllMD(s);
  PQ.push(initial);

  while(!PQ.empty()){
    state st=PQ.top();PQ.pop();
    if(st.puzzle.MD==0) return st.puzzle.cost;
    int sx=st.puzzle.space/N;
    int sy=st.puzzle.space%N;
    for(int r=0;r<4;r++){
      int tx=sx+dx[r];
      int ty=sy+dy[r];
      if(tx<0 || ty<0 || tx>=N || ty>=N) continue;
      v=st.puzzle;
      v.MD-=MDT[tx*N+ty][v.f[tx*N+ty]-1];
      v.MD+=MDT[sx*N+sy][v.f[tx*N+ty]-1];
      swap(v.f[sx*N+sy],v.f[tx*N+ty]);
      v.space=tx*N+ty;
      if(!V[v]){
	V[st.puzzle]=true;
	v.cost++;
	state news;
	news.puzzle=v;
	news.estimated=v.cost+v.MD;
	PQ.push(news);
      }
    }
  }
  return -1;
}

int main(){
  for(int i=0;i<N2;i++){
    for(int j=0;j<N2;j++){
      MDT[i][j]=abs(i/N - j/N)+abs(i%N - j%N);
    }
  }
  Puzzle in;
  for(int i=0;i<N2;i++){
    cin>>in.f[i];
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  cout<<astar(in)<<endl;
  return 0;
}



Measured memory_bytes: 251652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var str = "";
			while ((str = Console.ReadLine()) != null)
			{
				var ab = str.Split(' ').Select(i => int.Parse(i)).ToArray();
				long gcd = GCD(ab[0], ab[1]);
				long lcm = LCM(ab[0], ab[1], gcd);
				Console.WriteLine("{0} {1}", gcd, lcm);
			}
		}

		static long GCD(long i, long j)
		{
			long r;
			while (j != 0)
			{
				r = i % j;
				i = j;
				j = r;
			}
			return i;
		}

		static long LCM(long i, long j, long k)
		{
			return (i * j) / k;
		}
	}
}

Measured memory_bytes: 5976
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

x, n = MAP()
p = set(LIST())
ans = -100
for i in range(-100, 100):
    a = x + i
    if a in p:
        continue
    if abs(x - a) < abs(x - ans):
        ans = a
print(ans)

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

/* macros */
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve(){
    int n,x,t;
    cin>>n>>x>>t;
    int req = ceil((double)n/x);
    int ans = req * t;
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3752
/*input
6 2 4
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
    ll ans=1;
    while(m){
        if(m%2){
            ans*=a;
            ans%=(mod);
        }
        a=(a*a)%(mod);
        m>>=1;
    }
    return ans;
}


void init(long long* a,long long n,long long val){
    for(long long i=0;i<n;i++)
        a[i]=val;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    ll t=1,i,j;
    ll n,a,b;
    cin>>n>>a>>b;
    ll k=n/(a+b);
    n-=k*(a+b);
    if(n>a)n=a;
    cout<<a*k+n;

    return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
bool ok(string s)
{
	vector<int> h(26);
	for(auto i:s)h[i-'a']=1;
	int res=accumulate(all(h),0LL);
	return res==1;
}
int calc(char c,string s)
{
	int n=s.length();
	string t=s;
	for(int i=1;i<=n;i++)
	{
		if(ok(t))return i-1;
		s=t;
		if(t.length()==0)return 1e18;
		t="";
		for(int j=0;j<s.size()-1;j++)
		if(s[j]==c or s[j+1]==c)t+=c;
		else t+=s[j];
		if(ok(t))return i;
	}
	return 1e18;
	
	
	
}
int32_t main()
{
	string s;
	cin>>s;	
	int ans=1e18;
	
	for(char check='a';check<='z';check++)
	ans=min(ans,calc(check,s));
	cout<<ans;
	
}


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

const int INF = 1e+9;
typedef pair<int, int> P;
typedef pair<int, P> pp;
const int MAX_N = 105000;

bool is_prime[MAX_N + 1];
vector<int> primes;

void calc_prime(int n){
	for(int i = 0; i <= n; ++i)
		is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j = i * 2; j <= n; j += i)
				is_prime[j] = false;
		}
	}
}

int main() {
	calc_prime(MAX_N);
	int m, a, b, p, q;
	while(cin >> m >> a >> b && (m || a || b)){
		int ans = 0;
		double d = (double)a / b;
		for(int i = 0; primes[i] <= m; ++i){
			for(int j = 0; primes[i] * primes[j] <= m && primes[i] >= primes[j]; ++j){
				if((double)primes[j] / primes[i] >= d && primes[i] * primes[j] > ans){
					ans = primes[i] * primes[j];
					p = primes[j];
					q = primes[i];
				}
			}
		}
		cout << p << " " << q << endl;
	}
	return 0;
}

Measured memory_bytes: 1420
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=500000;
const int inf=1e9;
const ll mod=1e9+7;

int T[26][4*MX];

void up(int cr, int p, int l, int h, int x, int vl)
{
    if(l==h)
    {
        T[cr][p]+=vl; return;
    }
    int m=(l+h)/2;
    if(x<=m) up(cr, 2*p, l, m, x, vl);
    else     up(cr, 2*p+1, m+1, h, x, vl);
    T[cr][p]=T[cr][2*p]+T[cr][2*p+1];
}
int Q(int cr, int p, int l, int h, int x, int y)
{
    if(l>y || h<x) return 0;
    if(l>=x && h<=y) return T[cr][p];
    int m=(l+h)/2;
    return Q(cr, 2*p, l, m, x, y)+Q(cr, 2*p+1, m+1, h, x, y);
}

int main()
{
    FasterIO;

    int tc, cs=1, n, m, k;
    string s;

    cin>>n>>s>>m;
    for(int i=0; i<n; i++) up(s[i]-'a', 1, 1, n, i+1, 1);

    while(m--)
    {
        int type, x, y; char c;
        cin>>type;
        if(type==1)
        {
            cin>>x>>c;
            if(s[x-1]==c) continue;
            up(s[x-1]-'a', 1, 1, n, x, -1);
            s[x-1]=c;
            up(s[x-1]-'a', 1, 1, n, x, 1);
        }
        else
        {
            cin>>x>>y;
            int c=0;
            for(int i=0; i<26; i++)
            {
                c+=(Q(i, 1, 1, n, x, y)!=0);
            }
            cout<<c<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 160796
#include<cstdio>

char str[105],ptr[105],btr[105];
int i=0, j=0 , k=0;

void f(char* a, char b, int& d){
    if(a[d]){
        if(a[d]=='a')
            d++,f(str,'A',i);
        else if(a[d]=='b')
            d++,f(ptr,'B',j);
        else if(a[d]=='c')
            d++,f(btr,'C',k);
    }else {
        putchar(b);
    }
}
int main(){

    scanf("%s%s%s",str,ptr,btr);
    f(str,'A', i);
    return 0;
}


Measured memory_bytes: 128