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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  ll a, b, x;
  cin >> a >> b >> x;
  ll a1 = (a + x - 1) / x;
  ll b2 = b / x;
  cout << b2 - a1 + 1;
  return 0;
}


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

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<Int> B(N - 1);
	for (int i = 0; i < N - 1; ++i) { cin >> B[i]; }

	vector<Int> A(N, 0);
	A[0] = B[0];
	A[N-1] = B[N-2];
	for (int i = 1; i < N - 1; ++i) {
		A[i] = min(B[i], B[i-1]);
	}
	Int ans = 0;
	for (auto a : A) { ans += a; }
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(998244353);

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[100100],cnt[16],memo[1<<16];
bool done[1<<16];

int solve(int st){
	int i,j,k;
	if(done[st]){
		return memo[st];
	}
	done[st] = true;
	if(!st){
		return memo[st] = 0;
	}
	memo[st] = INF;
	for(i=1; i<16; ++i){
		if(!(st&(1<<i))){
			continue;
		}
		for(j=1; j<i; ++j){
			if(!(st&(1<<j))){
				continue;
			}
			k = i^j;
			if(st&(1<<k)){
				memo[st] = min(memo[st],solve(st-(1<<i)-(1<<j)-(1<<k))+2);
			}else{
				memo[st] = min(memo[st],solve(st-(1<<i)-(1<<j)+(1<<k))+1);
			}
		}
	}
	return memo[st];
}

int main(void){
	int n,i,x,y,z,ans=0,left=0;
	cin >> n;
	for(i=1; i<n; ++i){
		cin >> x >> y >> z;
		a[x] ^= z;
		a[y] ^= z;
	}
	for(i=0; i<n; ++i){
		++cnt[a[i]];
	}
	for(i=1; i<16; ++i){
		ans += cnt[i]/2;
		if(cnt[i]%2){
			left += (1<<i);
		}
	}
	ans += solve(left);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>

int arry[ 44 ] ;

int main()
{
	int n ;
	scanf( "%d" ,&n ) ;
	arry[ 0 ] = arry[ 1 ] = 1 ;

	int i = 1 ;
	while( i++ < n )
		arry[ i ] =  arry[ i - 1 ] + arry[ i - 2 ] ;

	printf( "%d\n" ,arry[ n ] ) ;
	return 0 ;
}

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

int main() {
   string S;
   cin >> S;
   deque<char> ds(S.size());
   for(int i = 0; i < S.size(); i++) {
       ds[i] = S[i];
   }

   int Q;
   cin >> Q;
   int rev = 0;
   for(int i = 0; i < Q; i++) {
       int type; cin >> type;
       if(type == 2) {
           int f; char c;
           cin >> f >> c; --f;
           if(rev) f = 1 - f;
           if(f == 0) ds.push_front(c);
           else ds.push_back(c);
       }
       else rev = 1 - rev;
   }

   if(rev) reverse(ds.begin(), ds.end());
   for(auto c : ds) cout << c;
   
    return 0;
}

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

int main(void)
{
  bool flag = false;
  while (true)
  {
    vector<int> result;
    int a, b;
    cin >> a >> b;
    if (a==0 and b==0) break;
    if (flag) cout << endl;
    flag = true;
    for (int i = a; i <= b; ++i)
    {
      if ((i % 4 == 0 and i % 100 != 0) or i % 400 == 0)
      {
        result.push_back(i);
      }
    }
    if (result.empty())
    {
      cout << "NA" << endl;
    }
    else
    {
      for (int year : result)
      {
        cout << year << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
using namespace std;
const int INF = 1e9;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int c[n];
    int a[n][m];

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

    int ans = INF;
    for(int bit = 0; bit < (1 << n); bit++) {
        int understood[m] = {};
        int price = 0;
        for(int i = 0; i < n; i++) {
            if((bit >> i) & 1) {
                price += c[i];
                for(int j = 0; j < m; j++) {
                    understood[j] += a[i][j];
                }
            }
        }

        bool ok = true;
        for(int i = 0; i < m; i++) {
            if(understood[i] < x) {
                ok = false;
                break;
            }
        }

        // cout << price << ' ' << ok << endl;
        if(ok) ans = min(ans, price);
    }

    if(ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int>a(n);
  rep(i, n)cin>>a[i];

  int result=0;
  rep(i, n){
    if((i+1)%2==1 && a[i]%2==1)result++;
  }

  cout<<result<<endl;

  return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){ 
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B && B==C){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char X,Y;
  cin>>X>>Y;
  int i=0;
  int j=0;
  if(X=='A'){
    i=0;
  }
  if(X=='B'){
    i=1;
  }
  if(X=='C'){
    i=2;
  }
  if(X=='D'){
    i=3;
  }
  if(X=='E'){
    i=4;
  }
  if(X=='F'){
    i=5;
  }
  if(Y=='A'){
    j=0;
  }
  if(Y=='B'){
    j=1;
  }
  if(Y=='C'){
    j=2;
  }
  if(Y=='D'){
    j=3;
  }
  if(Y=='E'){
    j=4;
  }
  if(Y=='F'){
    j=5;
  }
  
  if(i>j){
    cout<<'>'<<endl;
  }else if(i==j){
    cout<<'='<<endl;
  }else if(i<j){
    cout<<'<'<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b ? "true" : "false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vector<bool> v) {
	string res;
	for(int i = 0; i < (int) v.size(); i++)
		res += char('0' + v[i]);
	return res;
}
 
template<size_t S> string to_string(bitset<S> b) {
	string res;
	for(int i = 0; i < S; i++)
		res += char('0' + b[i]);
	return res;
}

template<class T> string to_string(T v) {
    bool f = 1;
    string res;
    for(auto& x : v) {
		if(!f)
			res += ' ';
		f = 0;
		res += to_string(x);
	}
    return res;
}
 
void DBG() {
	cerr << "]" << endl;
}

template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h);
	if(sizeof...(t))
		cerr << ", ";
	DBG(t...);
}

#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};

long long mod = 1e9 + 7;

void solve() {
	int n, k, mod = 998244353;
	cin >> n >> k;
	vector<long long> dp(n + 2);
	vector<pair<int, int>> v;
	for(int i = 0; i < k; i++){
		int x, y; cin >> x >> y;
		v.emplace_back(x, y);
	}
	sort(v.begin(), v.end());
	dp[0] = 1;
	for(int i = 1; i < n; i++){
		(dp[i] += dp[i - 1]) %= mod;
		for(auto p: v){
			if(p.first + i <= n) (dp[p.first + i] += dp[i]) %= mod;
			if(p.second + i <= n) (dp[p.second + i + 1] -= dp[i]) %= mod;	
		}
	}
	if(dp[n] < 0) dp[n] += mod;
	cout << dp[n];
}	
 
int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
 	
	int t = 1;
	//cin >> t;
	for(int i = 1; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
}

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

int main(){

  int a[10], b[10], g, cnt;

  for(int i=0; i<10; i++){
    a[i] = pow(2, i);
  }

  fill(b, b+10, 0);
  cnt = 0;
  while(cin >> g){
    for(int i=9; i>=0 && g != 0; i--){
      if(a[i] <= g){
        b[i] = 1;
        g -= a[i];
        cnt++;
      }
    }

    for(int i=0; i<10; i++){
      if(b[i] == 1){
        cnt--;
        cout << a[i] << (cnt? " " : "");
        b[i] = 0;
      }
    }
    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

vec kmp_table(string &Pattern) {
    ll i = 2, j = 0;
    vec T(Pattern.size(), -1);
    T[1] = 0;

    while (i < (ll)Pattern.size()) {
        if (Pattern[i-1] == Pattern[j]) {
            T[i] = j+1;
            i++;
            j++;
        } else if (j > 0) {
            j = T[j];
        } else {
            T[i] = 0;
            i++;
        }
    }

    return T;
}

vec kmp_search (string &Text, string &Pattern, vec &kmptable) {
    vec ret;
    ll m = 0, i = 0;
    while (m+i < (ll)Text.size()) {
        if (Pattern[i] == Text[m+i]) {
            i++;
            if (i == (ll)Pattern.size()) {
                ret.push_back(m);
                i--;
                m = m+i-kmptable[i];
                if (i > 0) i = kmptable[i];
            }
        } else {
            m = m+i-kmptable[i];
            if (i > 0) i = kmptable[i];
        }
    } 
    return ret;
}

mat graph;
vec dp;
vec status;

vec L;
ll dfs (ll v) {
    if (status[v] == 0) {
        cout << "-1\n";
        exit(0);
    }
    status[v] = 0;
    for (ll nv : graph[v]) {
        ll ret = dfs(nv);
        dp[v] = ret + 1;
    }
    status[v] = 1;
    return dp[v];
}

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

    string s, t, u;
    cin >> s >> t;
    while (u.size() <= t.size()) {
        u += s;
    }
    ll n = u.size();
    u += u;

    // cout << s << "\n";
    // cout << t << "\n";

    vec T = kmp_table(t);
    // printvec(T);
    vec result = kmp_search(u, t, T);
    // printvec(result);
    graph.assign(n, vec());
    for (ll e : result) {
        if (e < n) graph[e].push_back((e+t.size())%n);
    }

    dp.assign(n, 0);
    status.assign(n, -1);

    Rep (i, n) {
        if (status[i] == -1) {
            dfs(i);
        }
    }

    ll ans = 0;
    Rep (i, n) {
        chmax(ans, dp[i]);
    }

    cout << ans << "\n";
}

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

int n;
vector<long long> a;
long long gcd(long long x, long long y){
	while(x % y != 0){
		long long r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for(auto &i:a) cin >> i;
	long long ans = a[0];
	for(int i=1; i<n; ++i)
		ans = gcd(ans, a[i]);
	cout << ans << "\n";
}

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

#define ll long long
#define P pai<ll, ll>

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    ll sum[n + 1];
    sum[0] = 0;
    for (int i = 0; i < n; ++i) {
        sum[i + 1] = sum[i] + a[i];
    }
    map<ll, ll> mp;
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        if (0 <= i - k) {
            mp[(sum[i - k] - (i - k)) % k]--;
        }
        ans += mp[(sum[i] - i) % k];
        mp[(sum[i] - i) % k]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
//#define mod 1000000007
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 100001;
const ll M = 1;
ll mod = 1000000007;
struct point {
    ll x, y;
    ll i;
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    else if(n & 1)
        return fast_exp(x, n - 1) * x % mod;
    else
    {
        ll tmp = fast_exp(x, n >> 1);
        return tmp * tmp % mod;
    }
}

vector<int> p;
void soe(int n = 1000001)
{
    bool P[n];
    P[0] = P[1] = 1;
    for(int i = 2; i < n; i++)
    {
        if(!P[i])
        {
            p.pb(i);
            for(int j = i + i; j < n; j += i)
            P[j] = 1;
        }
    }
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m, x = 0, y = 0, ans = INF, k = 0;
        cin >> n >> m >> x;
        ll a[n][m], c[n];
        for(int i = 0; i < n; i++)
        {
            cin >> c[i];
            for(int j = 0; j < m; j++) cin >> a[i][j];
        }
        for(ll i = 0; i < (1ll << n); i++)
        {
            ll tmp[m] = {};
            y = 0;
            for(int j = 0; j < n; j++)
            {
                if(i & (1ll << j))
                {
                    for(int k = 0; k < m; k++) tmp[k] += a[j][k];
                    y += c[j];
                }
            }
            k = 1;
            for(int j = 0; j < m; j++) if(tmp[j] < x) k = 0;
            if(k)
                ans = min(ans, y);
        }
        if(ans == INF)
            cout << "-1\n";
        else cout << ans << "\n";
    }
    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		String str2;
		boolean result;

		while(true) {
			result=true;
			str = br.readLine();

			if(str.equals(".")) {
				break;
			}

			str=str.replaceAll("[a-z]", "");
			str=str.replaceAll("[A-Z]", "");
			str=str.replaceAll(" ", "");
			while(str.matches(".*\\[.*")||str.matches(".*\\(.*")||str.matches(".*\\].*")||str.matches(".*\\).*")) {
				str2=str.replaceAll("\\(\\)", "");
				str2=str2.replaceAll("\\[\\]", "");
				if(str2.equals(str)) {
					if(str2.matches(".*\\[.*")||str2.matches(".*\\(.*")||str.matches(".*\\].*")||str.matches(".*\\).*")) {
						result=false;
						break;
					}else {
						break;
					}
				}
				str=str2;
			}


				if(result) {
				System.out.println("yes");
				}else {
					System.out.println("no");
				}
		}
	}
}



Measured memory_bytes: 73484
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		int s1 = Integer.parseInt(sc.next());
		int s2 = Integer.parseInt(sc.next());
		int w1 = Integer.parseInt(sc.next());
		int w2 = Integer.parseInt(sc.next());

		String ans = "No ";

		while(s1 > 0 && w1 > 0) {
			w1 -= s2;
			s1 -= w2;
			if(w1 <= 0) {
				ans = "Yes";
			}

		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 26948
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	unsigned long long a, b2;
	double b;
	cin >> a >> b;
	b2 = (unsigned long long)(b * 1000);
	printf("%lld\n", (unsigned long long)(a * b2 / 1000));
	return 0;
}


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

int main()
{
    int r, c;
    cin >> r >> c;
    vector<vector<int>> mat(r+1, vector<int>(c+1));
    for (int i=0; i<r; i++)
    {
        for (int j=0; j<c; j++)
        {
            cin >> mat.at(i).at(j);
        }
    }
    //cout << r << c << endl;
    
    int all_sum = 0;
    for (int i=0; i<r; i++)
    {
        int sum = 0;
        for (int j=0; j<c; j++)
        {
            sum += mat.at(i).at(j);
        }
        mat.at(i).at(c)=sum;
        all_sum += sum;
    }
    mat.at(r).at(c) = all_sum;

    for (int j=0; j<c; j++)
    {
        int sum = 0;
        for (int i=0; i<r; i++)
        {
            sum += mat.at(i).at(j);
        }
        mat.at(r).at(j)=sum;
    }

    for (int i=0; i<r+1; i++)
    {
        for (int j=0; j<c+1; j++)
        {
            cout << mat.at(i).at(j);
            if (j<c)
            {
                cout << " ";
            }
        }
        cout << endl;
    }

}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,T;
  cin >> n >> T;
  vector<ll> t(n);
  rep(i,n){
    cin >> t.at(i);
  }
  ll ans=0,sum=0;
  for(ll i=1;i<n;i++){
    if(t.at(i)-t.at(i-1)<=T){
      ans+=t.at(i)-t.at(i-1);
    }else{
      ans+=T;
    }
  }
  cout << ans+T;
}

Measured memory_bytes: 4764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == s[i + 1])
        {
            cout << "Bad" << endl;
            break;
        }
        else if(i==2)
        {
            cout << "Good" << endl;
          break;
        }
    }
 
    return 0;
}

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

using namespace std;
int main()
{
	int A, B, C, D, L, R;
	cin >> A >> B >> C >> D;
	L = A + B;
	R = C + D;

	if(L > R)
		cout << "Left" << endl;
	else if(L == R)
		cout << "Balanced" << endl;
	else
		cout << "Right" << endl;
}

Measured memory_bytes: 3580
eval'N,M,*A='+`dd`.split*?,
l=1
A.map!{|a|a/=2}
A.map{|a|
	l=l.lcm(a)
	if l>M
		p 0
		exit
	end
}
x=A.map{|a|
	c=0
	(a/=2;c+=1)while a>0&&a%2==0
	c
}
if x.all?{|y|y==x[0]}
	p M/l-M/(2*l)
else
	p 0
end


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int H, W, h, w;
int main() {
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,i,a[500000],sum=0,c;
	cin>>n;
	for(i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	sum+=a[n-1];
	c=1;
	for(i=n-2;i>0;i--) {
		c++;
		sum+=a[i];
		if(c==n-1) break;
		c++;
		sum+=a[i];
		if(c==n-1) break;
	}
	cout<<sum;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

int mod = 1e9 + 7;

void solution(){
	int n; cin >> n;
	int a[n][n];
	for(int i = 0 ; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	// what matters is the combination of girls to be used for boys upto a certian position
	// state -- mask of girls used
	// position is not a part of state as it directly comes from the number of set bits in the current mask
	// for each mask, iterate over every girl and check if it is compatible 
	// with the ith boy, if yes, add num of ways from previous mask
	int N = (1 << n);
	vector<ll> dp(N,0LL);
	dp[0] = 1LL;
	for(int mask = 1; mask < N; mask++){
		int i = bitcnt(mask) - 1;
		for(int j = 0; j < n; j++){
			if(a[i][j] && (mask & (1 << j))){
				int prev = mask ^ (1 << j);
				dp[mask] += dp[prev];
				dp[mask] %= mod;
			}
		}
	}
	cout << dp.back() << endl;

}	


int main(){ 

	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

// 4近傍
int dy[]={0, 1, 0, -1};
int dx[]={1, 0, -1, 0};

// 8近傍
// int dy[]={0,0,1,-1,1,1,-1,-1};
// int dx[]={1,-1,0,0,1,-1,1,-1};

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

void solve() {
    int n,a,b; cin >> n >> a >> b;
    string s; cin >> s;
    int cnt = 0, cnt2 = 0;
    rep(i,s.size()){
        if(s[i] == 'b') cnt2++;
        if(s[i] == 'a' && cnt < a + b){
            cnt++;
            cout << "Yes" << endl;
        }else if(s[i] == 'b' && cnt < a + b && cnt2 <= b){
            cnt++;
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 848
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        final Map<String, List<Integer>> map = new HashMap<>();
        try (Scanner scanner = new Scanner(System.in)) {
            while (scanner.hasNext()) {
                String str = scanner.next();
                int i = scanner.nextInt();

                if (!map.containsKey(str)) {
                    map.put(str, new ArrayList<>());
                }
                map.get(str).add(i);
            }
            map.keySet().stream().sorted().forEach(it -> {
                System.out.println(it);
                String s = map.get(it).stream().sorted().map(String::valueOf).collect(Collectors.joining(" "));
                System.out.println(s);
            });
        }
    }
}

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string temp;
            string[] suuji = new string[2];
            int[] number = new int[2];
            int small,large;
            temp = Console.ReadLine();
            suuji = temp.Split(' ');
            number[0] = int.Parse(suuji[0]);
            number[1] = int.Parse(suuji[1]);
            if (number[0] > number[1])
            {
                small = number[1];
                large = number[0];
            }
            else
            {
                small = number[0];
                large = number[1];
            }
            int remainder;
            while (small != 0)
            {
                remainder = large % small;
                large = small;
                small= remainder;
            }
            Console.WriteLine("{0}", large);
        }
    }
}



Measured memory_bytes: 18004
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    int cost=0;
    int tmp=min(n,k);
    cost=cost+(tmp*x);
    if(n>k)
    {
       tmp=n-k;
       cost+=(tmp*y);
    }
    cout<<cost<<endl;
    return 0;

}





































Measured memory_bytes: 3616
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int a,b;
    scanf("%d %d", &a,&b);
    if (a == b)printf("a == b\n");
    if (a > b)printf("a > b\n");
    if (a < b)printf("a < b\n");
    return 0;
}


Measured memory_bytes: 2120
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll MAX = 100000000000000000;
ll sol(ll i,ll j,vector<ll> &v,vector<vector<ll> > &dp)
{
    if(i==j)
    {
        return dp[i][j]=0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    ll ans = MAX;
    for(ll x=i;x<j;x++)
    {
        ans = min(ans,sol(i,x,v,dp) + sol(x+1,j,v,dp));
    }
    for(ll x=i;x<=j;x++)
    {
        ans+=v[x];
    }
    return dp[i][j]=ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(auto &x:v)
    {
        cin>>x;
    }
    vector<vector<ll> > dp(n+1,vector<ll>(n+1,-1));
    ll ans = sol(0,n-1,v,dp);
    cout<<ans;
    return 0;
}




Measured memory_bytes: 1536
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;
#define int long long

vector<int> A, B;

signed main() {
	IOS
	int a, b, q;
	cin >> a >> b >> q;
	for(int i=0; i<a; i++) {
		int x;
		cin >> x;
		A.push_back(x);
	}
	for(int i=0; i<b; i++) {
		int x;
		cin >> x;
		B.push_back(x);
	}
	A.push_back(1e17);
	A.push_back(-1e17);
	B.push_back(1e17);
	B.push_back(-1e17);
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	while(q--) {
		int x;
		cin >> x;
		int i = lower_bound(A.begin(), A.end(), x) - A.begin();
		int j = lower_bound(B.begin(), B.end(), x) - B.begin();
		int ra = A[i] - x;
		int la = x - A[i-1];
		int rb = B[j] - x;
		int lb = x - B[j-1];
		int ans = 1e18;
		ans = min(ans, max(ra, rb));
		ans = min(ans, ra + lb + min(ra, lb));
		ans = min(ans, la + rb + min(la, rb));
		ans = min(ans, max(lb, la));
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1e6 + 5;
int arr[N];

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rw", stdin);
#endif
	ll n;
	cin >> n;
	vector<char> v;
	while(n) {
		int temp = n % 26;
		n /= 26;
		if(!temp) temp = 26, --n;
		v.push_back(temp + 'a' - 1);
	}
	reverse(v.begin(), v.end());
	for(auto it: v) cout << it;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const int INF = 1001001001;

static const int MAX = 1000;
static const int VMAX = 10000;

int n;
int A[MAX], B[MAX];
bool V[MAX];
int mi;
int T[VMAX+1];

int solve(){
  rep(i, n){
    B[i] = A[i];
    V[i] = false;
  }
  sort(B, B+n);
  rep(i, n) T[B[i]] = i;

  int ans = 0;
  rep(i, n){
    if(V[i]) continue;
    int cur = i;
    int sum = 0;
    int m = INF;
    int an = 0;
    while(1){
      V[cur] = true;
      an++;
      int v = A[cur];
      chmin(m, v);
      sum += v;
      cur = T[v];
      if(V[cur]) break;
    }
    ans += min(sum+(an-2)*m, sum+m+(an+1)*mi);
  }

  return ans;
}

int main(){
  cin >> n;
  mi = INF;
  rep(i, n){
    cin >> A[i];
    chmin(mi, A[i]);
  }

  cout << solve() << endl;

  return 0;
}






Measured memory_bytes: 3180
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

def solve():
    N = int(input())
    l = factorize(N)
    ans = 10 ** 12
    for i in range(1, int(N ** 0.5)+1):
        if N % i == 0:
            a = N // i
            ans = min(ans, a+i)
    return ans-2        
print(solve())

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int[] array = new int[1000];
		int n = scan.nextInt();
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		// ソート
		for(int i = 1; i < n; i++) {
			this.printArray(array, n);
			if(array[i] < array[i-1]) {
				for(int j = i; j > 0; j--) {
					if(array[j] >= array[j-1]) break;
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
				}
			}
		}
		this.printArray(array, n);
	}
	
	void printArray(int[] array, int n) {
		for(int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if(i == n-1) System.out.println();
			else System.out.print(" ");
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 34168
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
// initialize: UnionFind UF(N)

class UnionFind {                                              // OOP style
private:
	vector<int> p, rank, setSize;
	// p = path toward the root of disjoint set; p[i] = i means it is root
	// rank = upper bound of the actual height of the tree; not reliable as accurate measure
	// setSize = size of each disjoint set

	int numSets;
public:
	UnionFind(int N) {
		setSize.assign(N, 1);
		numSets = N;
		rank.assign(N, 0);
		p.assign(N, 0);
		for (int i = 0; i < N; i++) p[i] = i;	// each belongs to its own set
	}

	int findSet(int i) {
		return (p[i] == i) ? i : (p[i] = findSet(p[i]));		// path compression: cut short of the path if possible
	}

	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}

	void unionSet(int i, int j) {
		if (!isSameSet(i, j)) {
			numSets--;
			int x = findSet(i), y = findSet(j);
			// rank is used to keep the tree short
			if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
			else {
				p[x] = y; setSize[y] += setSize[x];
				if (rank[x] == rank[y]) rank[y]++;
			}
		}
	}

	int numDisjointSets() {		// # of disjoint sets
		return numSets;
	}

	int sizeOfSet(int i) {		// size of set
		return setSize[findSet(i)];
	}
};

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

	long long n, m, ans, i, j, k, nm, x, y;
	cin >> n >> m;
	nm = n * m;
	vector<string> s(n);
	for (i = 0; i < n; i++) cin >> s[i]; 
	int v[4][2] = { 1,0,0,1,-1, 0, 0, -1 };

	UnionFind uf(nm);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m;j++) 
			if (s[i][j] == '#') {
				for (k = 0; k < 4; k++) {
					x = i + v[k][0];
					y = j + v[k][1];

					if ((x >= 0) && (x < n) && (y >= 0) && (y < m) && (s[x][y] == '.')) {
						uf.unionSet(x * m + y, i * m + j);
					}
				}
			}
	}

	vector<vector<long long>> ct(nm, vector<long long>(2, 0));
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			x = uf.findSet(i * m + j);
			if (s[i][j] == '#') ct[x][0]++;
			else ct[x][1]++;
		}
	}

	ans = 0;
	for (i = 0; i < nm; i++) ans += ct[i][0] * ct[i][1];
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL; 
typedef long double dd; 
#define endl "\n"
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
LL dp[2000001];
LL mod=1e9+7;
bool vis[100000],ok=1;
using namespace std;
bool isPrime(LL n) {
  LL j; 
  for( j=2;j<=sqrt(n);j++){
    if(n%j==0){
      break;  
    } 
  }
  if(j>sqrt(n)){
    return 1; 
  }
  else{
    return 0; }
}
LL modexpo(LL a, LL b) {
  LL ans=1;
  a=a%mod;
  while(b>0){
    if((b&1)==1){
      ans=((ans%mod)*(a%mod))%mod;
    }
    b=b>>1;
    a=((a%mod)*(a%mod))%mod;
  }
  return ans; 
}
LL invmod(LL n){
  return modexpo(n,mod-2);
}
LL comb(LL n,LL r){
  if(r==0){
    return 1;
  }
  LL fact[n+1];
  fact[0] = 1; 
    for (LL i = 1; i <= n; i++){
       fact[i] = (fact[i - 1] * i) %mod;}
    return (fact[n] * invmod(fact[r]) % mod * invmod(fact[n - r]) % mod) %mod; 
}
LL gcd(LL a, LL b) {
  if (a == 0){
       return b;
       }  
    return gcd(b % a, a);  
}
LL lcm(LL a, LL b) {
  return (a*b)/gcd(a,b);
}
void solve(LL k){
  LL n,f;
  cin>>n>>f; 
  LL a[n];
  for(LL i=0;i<n;i++){
    cin>>a[i];
  }
  LL d[n];
  for(LL i=0;i<n;i++){
    d[i]=INT_MAX;
  }
  d[0]=0,d[1]=abs(a[1]-a[0]);
  for(LL i=2;i<n;i++){
    LL g=i+1;
    for(g=1;g<=f;g++){
      if(i-g>=0){
    d[i]=min(d[i],d[i-g]+abs(a[i]-a[i-g]));
  }
  }
  }
  cout<<d[n-1]<<endl; 
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
 LL t=1;
//cin>>t;
 LL k=1;
while(k<=t){
  if(ok==0){
    break; 
  }
   solve(k);
  k++;
  }
   return 0;
   }

Measured memory_bytes: 5208
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    let n = get!(usize);
    
    let mut xs = vec![false; 55556];
    let mut ps = vec![];
    for i in 2..xs.len() {
    	if xs[i] { continue; }
        if i % 5 == 1 {
        	// 解説読後
        	ps.push(i);
        }
        let mut j = i + i;
        while j < xs.len() {
        	xs[j] = true;
            j += i;
        }
    }
    for i in 0..n {
    	let j = ps.len() - 1 - i;
        if i > 0 { print!(" "); }
        print!("{}", ps[j]);
    }
    println!();
}

Measured memory_bytes: 4476
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <deque>
 
using namespace std; 

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

pair<bool,int> is_valid(deque<char> &d){
    int cnt=0;
    for(int i=0;i<d.size();i++){
        if(d[i]=='(') cnt++;
        else if(cnt<1) return make_pair(false,0);
        else cnt--;
    }
    return make_pair(cnt==0,d.size());
}

int main(){

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

    deque<char> d;
    for(int i=0;i<n;i++) d.push_back(s[i]);

/*
    auto pos=is_valid(d);
    if(pos.second!=d.size())d.insert(d.begin()+pos.second,'(');
    else d.push_back(')');
    for(int i=0;i<d.size();i++) cout<<d[i];
    cout<<endl;

    return 0;
*/

    int res=0;
    while(true){
        auto p=is_valid(d);
        if(p.first) break;

        res++;
        if(p.second!=d.size())d.insert(d.begin()+p.second,'(');
        else d.push_back(')');
    }

    for(int i=0;i<d.size();i++) cout<<d[i];
    cout<<endl;

	return 0;
}


Measured memory_bytes: 256
a=list(input())
b=list(input())
c=list(input())
d=a.pop(0)
while True:
  if d=="a" and a!=[]:
    d=a.pop(0)
  elif d=="a" and a==[]:
    flag="A"
    break
  if d=="b" and b!=[]:
    d=b.pop(0)
  elif d=="b" and b==[]:
    flag="B"
    break
  if d=="c" and c!=[]:
    d=c.pop(0)
  elif d=="c" and c==[]:
    flag="C"
    break
print(flag)
  

Measured memory_bytes: 9096
sumOfDigitp :: Int -> Int -> Int
sumOfDigitp total 0 = total
sumOfDigitp total n = sumOfDigitp (total + r) q
  where
    q = n `div` 10
    r = n `mod` 10

sumOfDigit :: Int -> Int
sumOfDigit = sumOfDigitp 0

func :: Int -> Int -> Int -> Int
func minN i n
  | i > (n `div` 2) = minN
  | otherwise = func minNp (i + 1) n
  where
    minNp = min minN $ (+) (sumOfDigit i) (sumOfDigit (n-i))

main = do
  line <- getLine
  let
    n = read line :: Int
    ans = func 1000 1 n
  putStrLn $ show ans


Measured memory_bytes: 508
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;


int main() {
#ifdef LOCAL
  freopen("b.in", "r", stdin);
  freopen("b.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    vector<string> s;
    vector<map<int, vector<int>>> cnts(26);
    for (int i = 0; i < n; i++) {
      static char buf[1'100'100];
      scanf("%s", buf);
      s.emplace_back(buf);
      reverse(s.back().begin(), s.back().end());
    }
    sort(s.begin(), s.end());

    for (char c = 'a'; c <= 'z'; c++) {
      for (int i = 0; i < n; i++) {
        int cnt = std::count(s[i].begin(), s[i].end(), c);
        cnts[c - 'a'][cnt].push_back(i);
      }
    }

    ll ans = 0;

    for (const auto &a : s) {
      string x = a.substr(0, a.size() - 1);
      int l = lower_bound(s.begin(), s.end(), x + 'a') - s.begin();
      int r = lower_bound(s.begin(), s.end(), x + char('z' + 1)) - s.begin();

      int bad = 0;
      int bad_cnt = std::count(x.begin(), x.end(), a.back());
      auto it = cnts[a.back() - 'a'].find(bad_cnt);
      if (it != cnts[a.back() - 'a'].end()) {
        bad = lower_bound(it->second.begin(), it->second.end(), r) -
              lower_bound(it->second.begin(), it->second.end(), l);
      }
      ans += r - l - bad - 1;
    }

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

  return 0;
}


Measured memory_bytes: 32096
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define Min(a,b) ((a)<(b)?(a):(b))

#define Max(a,b) ((a)>(b)?(a):(b))

#define ABS(a) ((a)>(0)?(a):-(a))

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

#define Rep2(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)

int Str_cmpfunc (const void * a, const void * b) {
   return strcmp(*(const char**)a,*(const char**)b );
}

int Int_cmpfunc (const void * a, const void * b) {
   return *(const int*)a-*(const int*)b;
}

int Arrcmp(int *arr1,int *arr2,int len){
	Rep(i,len){
		if(arr1[i]>arr2[i]) return 1;
		if(arr1[i]<arr2[i]) return 0;
	}	
	return 0;
}

void SwapInt(int* v1,int* v2){
	char sw = *v1;
    *v1=*v2;
    *v2=sw;
}

void SwapChar(char* v1,char* v2){
    char sw = *v1;
    *v1=*v2;
    *v2=sw;
}

void SwapStr(char** str1,char** str2){
    char* sw = *str1;
    *str1=*str2;
    *str2=sw;
}

int main(){ 
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int s=a+b+c;
	if(a%2==b%2){
		if((a%2)==(c%2)){
			printf("%d",(3*Max(Max(a,b),c)-s)/2);
		}else{
			printf("%d",1+(3*Max(Max(a+1,b+1),c)-s-2)/2);
		}
	}else
	{
		if((b%2)==(c%2)){
			printf("%d",1+(3*Max(Max(c+1,b+1),a)-s-2)/2);	
		}else
		{
			printf("%d",1+(3*Max(Max(a+1,c+1),b)-s-2)/2);	
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
ll n ,k;
int main()
{
	cin>>n>>k;
	if(n <= k){
		cout<<min(n,k - n);
	}
	else{
		ll d = n - k;
		d%=k;
		ll ans = n;
		n = k + d;
		ans = min(ans, n - k);
		ans = min(ans,abs(k - (n - k)));
		cout<<ans<<"\n";
	}
	return 0;
}



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

int main()
{
    int n;

    cin >> n;

    int dig = 0;
    dig = (int)log10(n) + 1;

    int ans = 0;

    for(int i = 1; i <= dig; i++){
        int temp = 1;
        if(i % 2 != 0){
            if(i == dig){
                if(i == 1){
                    ans += n;
                }
                else{
                    rep(k, i - 1){
                        temp *= 10;
                    }
                    ans += n - temp + 1;
                }
            }
            else{
                if(i == 1){
                    ans += 9;
                }
                else{
                    rep(k, i - 1){
                        temp *= 10;
                    }
                    ans += (temp * 10) - temp;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
N = int(input())
d = {}
mv = 0
mfw = []
for _ in range(N):
    w = input()
    d[w] = d.get(w, 0) + 1
    if d[w] > mv:
        mv += 1
        mfw.clear()
        mfw.append(w)
    elif d[w] == mv:
        mfw.append(w)
[print(w) for w in sorted(mfw)]


Measured memory_bytes: 34052
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	int n; cin >> n;
	vector<int> h(n); rep(i, 0, n) {
		cin >> h[i];
	}
	vector<int> y(n + 1);
	y[0] = 1;

	rep(i, 0, n) {
		y[i + 1] = h[i];
	}

	int m = *max_element(all(h)) * 2;

	vector<vector<double>> dp(n + 1, vector<double>(m, INF));

	dp[0][1] = 0;

	rep(i, 0, n) {
		rep(j, 1, m) {
			rep(k, 1, m) {
				double a = h[i] - j;
				double b = h[i] - k;
				if (a*b < 0) {
					a = abs(a), b = abs(b);
					double add = (a * a + b * b) / (a + b) / 2;
					chmin(dp[i + 1][k], dp[i][j] + add);
				}
				else {
					a = abs(a), b = abs(b);
					chmin(dp[i + 1][k], dp[i][j] + (a + b) / 2);
				}

			}
		}
	}

	dump(dp);

	cout << *min_element(all(dp[n])) << endl;

	return 0;
}


Measured memory_bytes: 3400