akhauriyash/Code-Regression huggingface dataset:
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
#include <bits/stdc++.h>
using namespace std;
//fold
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
//using ll = long long;
typedef long double ld;
const ll INF = 1e18 + 10;
#if defined(ONLINE_JUDGE)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define push_back pb
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//endfold
int main(){
    speed;
    ll x,y,ans=0;
    cin>>x>>y;
    for(ll i=0;i<=x;i++){
        for(ll j=0;j<=x;j++){
            ll z= y - (i+j);
            if( z>=0 && z<=x ){ans++;}
        }
    }
    cout<<ans<<endl;
return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define ll long long
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=true;

set<string>se;

void divide(string s){
  string a;
  a=s[0];
  s.erase(s.begin());
  while(s.size()){
    se.insert(a+s);
    se.insert(s+a);
    reverse(all(a));
    //if(debug)cout<<s<<"+"<<a<<endl;
    se.insert(s+a);
    se.insert(a+s);
    reverse(all(s));
    se.insert(s+a);
    se.insert(a+s);
    reverse(all(a));
    //if(debug)cout<<s<<"+"<<a<<endl;
    se.insert(s+a);
    se.insert(a+s);
    reverse(all(s));
    a=a+s[0];
    s.erase(s.begin());
    //cout<<s<<endl;
  }
}


int main(){
  int m;
  string s;
  cin>>m;
  rep(i,m){
    cin>>s;
    divide(s);
    cout<<se.size()<<endl;
    se.clear();
  }

  return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    vector<vector<int>> v(m);
    for(int i = 0; i < n; i++) {
        cin >> x[i];
        v[x[i] % m].emplace_back(x[i]);
    }
    for(int i = 0; i < m; i++) {
        sort(ALL(v[i]));
    }
    int ans = 0;
    for(int j = 0; j <= m / 2; j++) {
        if(j == 0 || (m % 2 == 0 && j == m / 2)) {
            map<int, int> cnt;
            for(auto i : v[j]) {
                cnt[i]++;
                // cout << i << " ";
            }
            // cout << endl;
            int sum = 0, tmp = 0;
            for(auto p : cnt) {
                sum += p.second - (p.second / 2) * 2;
                tmp += p.second / 2;
            }
            tmp += sum / 2;
            // cout << tmp << endl;
            ans += tmp;
        } else {
            auto v1 = v[j];
            auto v2 = v[m - j];
            if(v1.size() > v2.size()) {
                swap(v1, v2);
            }
            // for(auto i : v1) {
            //     cout << i << " ";
            // }
            // cout << endl;
            // for(auto i : v2) {
            //     cout << i << " ";
            // }
            // cout << endl;
            int tmp = v1.size();
            int pcnt = 0;
            map<int, int> cnt;
            for(auto i : v2) {
                cnt[i]++;
            }
            for(auto p : cnt) {
                pcnt += p.second / 2;
            }
            int diff = v2.size() - v1.size();
            tmp += min(diff / 2, pcnt);
            ans += tmp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6144
#include<stdio.h>

void Max_h(int);
void build();

int n;
int Key[1000000];

int main(){
  int i;

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

  build();

  for(i = 1; i <= n; i++){
    printf(" %d", Key[i]);
  }

  printf("\n");
  
  return 0;
}

void build(){
  int i;

  for(i = n/2; i >= 1; i--){
    Max_h(i);
  }
}

void Max_h(int i){
  int left, right, largest = 0;
  int temp;

  left = i*2;
  right = i*2 + 1;

  if(left <= n && Key[left] > Key[i]) largest = left;
  else largest = i;

  if(right <= n && Key[right] > Key[largest]) largest = right;

  if(largest != i){
    temp = Key[i];
    Key[i] = Key[largest];
    Key[largest] = temp;

    Max_h(largest);
  }
}



Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> v(N), idx(N);
    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        v[x] = y;
        idx[y] = i;
    }

    dsu d(N);
    set<int> st;
    st.insert(v[0]);
    for (int i = 1; i < N; ++i) {
        int mi = v[i];
        auto itr = st.begin();
        while (itr != st.end() && *itr < v[i]) {
            mi = min(*itr, mi);
            d.merge(idx[*itr], idx[v[i]]);
            auto icpy = itr;
            itr++;
            st.erase(icpy);
        }
        st.insert(mi);
    }

    for (int i = 0; i < N; ++i)
        cout << d.size(i) << '\n';

    return 0;
}


Measured memory_bytes: 10592
import math
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if a < b or b > d:  # 1手目から不可能、りんごが単調減少
        print("No")
        continue

    # ダメな場合とは　➡　bより小さいのに補充しない
    # (aから始まり、dを足していく) mod b > c
    # となる場合があったら無理
    g = math.gcd(b, d)
    max_rem = b - g + a % g
    if max_rem > c:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 9000
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;

typedef long long ll;

vector<ll> v;
map<ll, ll> M;

int main(void)
{
	ll n, i, ans = 0;

	scanf("%lld", &n);

	for (i = 2; i * i <= n; i++)
		if (n % i == 0)
		{
			ll tmp = n;
			while (tmp % i == 0)
				tmp /= i;

			if (tmp % i == 1)
			{
				// ++ans;
				M[i]++;
				v.push_back(i);
			}

			tmp = n;
			while (tmp % (n / i) == 0)
				tmp /= (n / i);

			if (tmp % (n / i) == 1)
			{
				// ++ans;
				M[n / i]++;
				v.push_back(n / i);
			}
		}
	
	ll cnt = 0;
	for (i = 1; i * i <= n - 1; i++)
		if ((n - 1) % i == 0)
		{
			++cnt;
			M[i]++;
			M[(n - 1) / i]++;
			v.push_back(i);
			v.push_back((n - 1) / i);
		}
	/*
	if (i * i == n - 1)
		cnt = cnt * 2 - 1;
	else
		cnt *= 2;*/

	for (i = 0; i < v.size(); i++)
		if (M[v[i]])
		{
			++ans;
			M[v[i]] = 0;
		}
	
	printf("%lld", ans);
	return 0;
}

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


void dj(vector<vii>& adj, vi& d, int st) {
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > p;
	p.push({0,st});
	d[st]=0;
	while(!p.empty()) {
		ii pr = p.top(); p.pop();
		int u = pr.ss; int c = pr.ff;
		if(d[u] < c) continue;
		// cout<<u<<" fr "<<c<<endl;
		for(int i = 0; i < adj[u].size(); i++) {
			ii v = adj[u][i];
			if(d[u]+v.ss < d[v.ff]) {
				d[v.ff] = d[u]+v.ss;
				p.push({d[v.ff], v.ff});
			}
		}
	}
}
signed main(void) {
	IOS;
	int n; cin>>n;
	vector<vii> g(n);
	for(int i = 0; i < n-1; i++) {
		g[i].pb({i+1,1});
		g[i+1].pb({i,1});
	}
	int x,y; cin>>x>>y;
	x--;
	y--;
	g[x].pb({y,1});
	g[y].pb({x,1});
	vi ans(n,0);
	for(int i = 0; i < n; i++) {
		vi d(n,inf);
		dj(g,d,i);
		for(int j = i+1; j < n; j++) {
			ans[d[j]]++;
		}
	}
	for(int i = 1; i <= n-1; i++)
		cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 384
//嘘っぽいのに通ってたやつでいこう

#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[100000], *ci = cn, c;
const char* owa = cn + 100000;
inline char getcha() {
	if (ci == owa) {
		fread(cn, 1, 100000, stdin);
		ci = cn;
	}
	return *ci++;
}

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


	fread(cn, 1, 100000, stdin);
	int N = 0;
	while ((c = getcha()) >= '0') N = N * 10 + c - '0';
	int sL[1001] = {}, sR[1001] = {};
	pair<int, int> RR[500], LL[500];
	int rr = 0, ll = 0;
	int tot = 0;
	rep(i, N) {
		int l = 0, r = 0;
		while ((c = getcha()) >= '(') {
			if (c == '(') r++;
			else {
				if (r > 0) r--;
				else l++;
			}
		}
		tot += r - l;
		if (l < r) {
			if (l <= 1000) sR[l] += r;
			else RR[rr++] = { l,r };
		}
		else {
			if (r <= 1000) sL[r] += l;
			else LL[ll++] = { r,l };
		}
	}

	if (tot != 0) {
		printf("No");
		return 0;
	}

	sort(RR, RR + rr);
	sort(LL, LL + ll);

	int OK = 1;
	int k = 0;
	rep(i, 1001) {
		if (sR[i]) {
			if (k < i) OK = 0;
			k += sR[i];
		}
	}
	rep(i, rr) {
		if (k < RR[i].first) OK = 0;
		k += RR[i].second - RR[i].first;
	}
	k = 0;
	rep(i, 1001) {
		if (sL[i]) {
			if (k < i) OK = 0;
			k += sL[i];
		}
	}
	rep(i, ll) {
		if (k < LL[i].first) {
			OK = 0;
		}
		k += LL[i].second - LL[i].first;
	}

	if (OK) printf("Yes");
	else printf("No");

	Would you please return 0;
}

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

int main(){
    string n, k;
    int m, s, i;
    
    while(true){
        cin >> n;
        if(n == "-") break;
        cin >> m;
        for(i = 0; i < m; i++){
            cin >> s;
            k = n.substr(0, s);
            n.erase(0, s);
            n = n + k;
        }
        cout << n << endl;
    }
}



Measured memory_bytes: 3192
#include<stdio.h>

int main(){
	int A,B;
	scanf("%d%d",&A,&B);
	if(A==1)A+=13;
	if(B==1)B+=13;
	if(A==B)printf("Draw\n");
	else if(A>B)printf("Alice\n");
	else printf("Bob\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

int n, el;

void solve() {
    cin >> n >> el;
    int i = 1-el;
    i = min(max(i, 1), n);
    cout << n*el - n + n*(n+1)/2 - (el+i-1) ;
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define Int long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> 

Int N,M,K;
Int X,Y,Z,D;

Int B,C;

const long MOD=(long)(1e9+7);
const int MAXN=500005;


vector<Int> adj[MAXN];
vector<Int> degree;
vector<Int> SZ,ID;
bool VIS[MAXN];     

Int find(Int x){
    if(ID[x]==x) return x;
    return find(ID[x]);
}
void Union(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(SZ[x]>SZ[y]){
        ID[y]=x;
        SZ[x]+=SZ[y];
    }
    else{
        ID[x]=y;
        SZ[y]+=SZ[x];
    }
    return;
}

Int mul(Int x,Int y){
    return ((x%MOD)*(y%MOD))%MOD;
}


long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;
    
    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}

long long ModInv(long long n){
    return ModExpo(n,MOD-2,MOD);
}

int main()
{
        Int ans=0;
        cin>>N>>M;
        
        for(int i=0;i<N+1;++i) adj[i].clear();
        
        ID.resize(N+1);SZ.resize(N+1);
        
        for(int i=1;i<N+1;++i){
            ID[i]=i;
            SZ[i]=1;
        }
        
        for(int i=0;i<M;++i){
            Int u,v;
            cin>>u>>v;
            Union(u,v);

        }
        map<int,vector<int>> mp;
        for(int i=1;i<N+1;++i){
            mp[find(i)].pb(i);
        }
        for(auto itr:mp){
            ans=max(ans,(Int)itr.second.size());
        }
        cout<<ans<<"\n";
}

Measured memory_bytes: 39752
#include <cstdio>
#include <cstring>
char s[100010]; int n, ans;
int main() {
	scanf("%s", s); n = strlen(s);
	for (int i = 1; i < n; ++ i) {
		if (s[i] != s[i - 1]) ++ ans;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr ll MOD = 1'000'000'007LL;

int main(){
	int n; scanf("%d", &n);
	ll sm = 0, sn = 0;
	REP(i, n){
		ll a; scanf("%lld", &a);
		sm += a;
		sn += a*a % MOD;
	}
	sm %= MOD;
	sn %= MOD;
	ll ans = (sm*sm % MOD - sn + MOD) % MOD;
	if(ans%2) ans += MOD;
	ans = ans / 2 % MOD;
	printf("%lld\n", ans);
}


Measured memory_bytes: 3744
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

ll mod = 1e9 + 7;

ll power(ll base, ll exponent, ll modx = mod) {
    ll ret = 1 % modx; 
    base %= modx; 
    while(exponent) {
        if(exponent & 1) {
            ret = (ret * base) % modx;
        }
        base = (base * base) % modx;
        exponent >>= 1;
    }
    return ret;
}
ll inv(ll val, ll modx = mod) {
    return power(val, modx - 2, modx);
}
vector <ll> ans, sub, sub_val;
vector <vector <int> > T;

void dfs(int u, int par) {
	sub[u] = 1;
	for(auto v : T[u]) {
		if(v != par) {
			dfs(v, u);
			sub[u] += sub[v];
			sub_val[u] = (sub_val[u] * sub_val[v]) % mod;
		}
	}
	sub_val[u] = (sub_val[u] * sub[u]) % mod;
}
int N;

void dfs2(int u, int par) {
	if(par != -1) {
		ans[u] = (ans[par] * inv(sub[u])) % mod;
		ans[u] = (ans[u] * (N - sub[u])) % mod;
	} else {
		ans[u] = sub_val[u];
	}
	for(auto v : T[u]) {
		if(v != par) {
			dfs2(v, u);
		}
	}

}

int main() {fio;
	cin >> N;
	T.resize(N);	
	ans.resize(N);
	sub.resize(N);
	sub_val.resize(N, 1);
	for(int i = 0; i < N - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		T[u].push_back(v);
		T[v].push_back(u);
	}
	dfs(0, -1);
	dfs2(0, -1);
	ll nf = 1;
	for(int i = 1; i <= N; i++) {
		nf = (nf * i) % mod;
	}
	for(int i = 0; i < N; i++) {
		// cout << ans[i] << " -> ";
		cout << (inv(ans[i]) * nf) % mod << endl;
	}
    return 0;
}

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

string next(string s){
	string s_;
	int cnt = 0;
	char state;
	
	for(int i=0 ; i < (int)s.size() ; i++ ){
		char c = s[i];
		
		if( i == 0 ){
			state = c;
			cnt++;
		}else{
			if( c != state ){
				if( cnt >= 10 )
					s_.push_back( (cnt/10)+'0' );
				s_.push_back( (cnt%10)+'0' );
				s_.push_back( state );
					
				state = c;
				cnt = 1;
				if( i == (int)s.size()-1 ){
					s_.push_back( cnt+'0' );
					s_.push_back( state );
				}
			}else{
				cnt++;
				if( i == (int)s.size()-1 ){
					if( cnt >= 10 )
						s_.push_back( (cnt/10)+'0' );
					s_.push_back( (cnt%10)+'0' );
					s_.push_back( state );
				}
			}
		}
	}
	return s_;
}

int main(){
	int n;
	string s;
	while( cin >> n , n ){
		cin >> s;
		for(int i=0 ; i<n ; i++ ){
			s = next(s);
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 0
// finish date: 2018/05/20

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>




int main() {
    int N;
    cin >> N;
    vvi A(N, vi(N));
    rep(i, N) rep(j, N) cin >> A[i][j];
    vvi dist(N, vi(N, INF));
    vvi flag(N, vi(N, false));
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                if (A[i][k] + A[k][j] < A[i][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if (A[i][k] + A[k][j] == A[i][j] && i != k && j != k){
                    flag[i][j] = true;
                }
            }
        }
    }
    ll sum = 0;
    rep(i, N) {
        rep(j, N) {
            if (!flag[i][j]) sum += A[i][j];
        }
    }
    cout << sum / 2 << endl;

    return 0;
}




Measured memory_bytes: 1280
#include<iostream>
#include<math.h>
#include<algorithm>
typedef long long ll;
const ll mod=1e9+7;
using namespace std;
ll n,a,b;
ll dp[2010];
int main(){
cin>>n;
for (int i=3;i<10;i++)
dp[n-i]= 1;
dp[n]=1;
for (int i=n-3;i>=0;i--){
for (int j= 3;j<10;j++){
dp[i-j]=(dp[i-j+1]+dp[i])%mod;
}
}
cout<<dp[0];
return 0;
} 



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	bool flag = false;
	for(int i = 0; i < s.size() - 1; i++){
		if(s[i] == s[i+1])flag = true;
	}
	if(flag)cout << "no" << endl;
	else cout << "yes" << endl; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            int a = scanner.nextInt();
            String operator = scanner.next();
            int b = scanner.nextInt();
            switch (operator) {
            case "+":
                System.out.println(a + b);
                break;
            case "-":
                System.out.println(a - b);
                break;
            case "*":
                System.out.println(a * b);
                break;
            case "/":
                System.out.println(a / b);
                break;
            case "?":
                scanner.close();
                return;
            }
        }
    }
}



Measured memory_bytes: 26176
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
d1 = (A1-B1)*T1
d2 = (A2-B2)*T2

if d1*d2>0:
    print(0)
    exit()

if d1<0:
    d1 *= -1
    d2 *= -1

if d1+d2>0:
    print(0)
    exit()

if d1+d2==0:
    print('infinity')
    exit()

t = -d2-d1

if d1%t==0:
    print(d1//t*2)
else:
    print(d1//t*2+1)

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

#define int long long

signed main(){

    int n;
    cin >> n;

    int p[300];
    int q[300];

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

    int cnt = 0;
    for(int i = 0;i < n;i++){
        if(p[i] != q[i]){
            cnt++;
        }
    }
    
    if(cnt <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }



    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mod 1000000007
using namespace std;

long long x,y;

int main()
{
	scanf("%lld%lld",&x,&y);
	if(abs(x-y)<=1)
	{
		puts("Brown");
	}
	else
	{
		puts("Alice");
	}
}

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

namespace ABC144A
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b;
			int c = 0;
			var word = Console.ReadLine().Split(' ');
			a = int.Parse(word[0]);
			b = int.Parse(word[1]);

			if (a <= 9 && b <= 9)
				c = a * b;
			else
				c = -1;
			Console.WriteLine(c);

		}
	}
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll a, b; cin >> a >> b;
	ll d = 10;
	while (b / d != 0) d *= 10;
	b += a * d;
	for (int c = 2; c*c <= b; c++) {
		if (b == c * c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
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 string dir = "DRUL";
*/


int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<ll> A(M);
    vector<int> cnt(N+1, 0);
    rep(i,M){
        cin >> A[i];
        cnt[A[i]]++;
    }
    int ans = INF;
    int tmp = 0;
    for(int i = 0; i <= X; i++){
        tmp += cnt[i];
    }
    chmin(ans, tmp);
    tmp = 0;
    for(int i = X; i <=N; i++){
        tmp += cnt[i];
    }
    chmin(ans, tmp);

    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<int> x(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &x[i]);
    }
    int L,Q;
    scanf("%d%d", &L, &Q);
    
    vector<vector<int> > ne(n), pr(n);
    int j;
    for(i=0; i<n; i++) {
        ne[i].resize(20); pr[i].resize(20);
        for(j=0; j<20; j++) {
            ne[i][j]=INF; pr[i][j]=-INF;
        }
    }
    for(i=0; i<n; i++) {
        int k=lower_bound(x.begin(), x.end(), x[i]+L+1)-x.begin()-1;
        ne[i][0]=k;

        k=lower_bound(x.begin(), x.end(), x[i]-L)-x.begin();
        pr[i][0]=k;
    }
    for(j=1; j<20; j++) {
        for(i=0; i<n; i++) {
            if(ne[i][j-1]<INF) {
                ne[i][j]=ne[ne[i][j-1]][j-1];
            }
            if(pr[i][j-1]>-INF) {
                pr[i][j]=pr[pr[i][j-1]][j-1];
            }
        }
    }

    for(i=0; i<Q; i++) {
        int a,b;
        scanf("%d%d", &a, &b); a--; b--;

        if(b>a) {
            int curr=a;
            int ans=0;
            for(j=19; j>=0; j--) {
                if(ne[curr][j]<b) {
                    ans+=(1<<j);
                    curr=ne[curr][j];
                }        
            }
            printf("%d\n", ans+1);
        }
        else {
            int curr=a;
            int ans=0;
            for(j=19; j>=0; j--) {
                if(pr[curr][j]>b) {
                    ans+=(1<<j);
                    curr=pr[curr][j];
                }        
            }
            printf("%d\n", ans+1);
        }

    }


    return 0;
}

Measured memory_bytes: 24704
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

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

const long long mod = 1e9 + 7;

long long pow(const long long &v, const long long &n, const long long &mod)
{
    long long ret = 1;
    long long num = n;
    long long now = v;
    
    while (num > 0)
    {
        if (num & 1)
        {
            ret = ret * now % mod;
        }
        now = now * now % mod;
        num = num >> 1;
    }
    
    return ret;
}

long long calc(const long long &n, const long long &k, const long long &mod)
{
    long long ret;
    vector<long long> fac = vector<long long>(n + 1, 1);
    vector<long long> inv = vector<long long>(n + 1, 1);
    
    for (int i = 1; i <= n; ++i)
    {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = pow(fac[i], mod - 2ll, mod);
    }
    
    ret = fac[n] * inv[k] % mod * inv[n - k] % mod;
    
    return ret;
}


int main() {
    

    
    ll x, y;
    cin >> x >> y;
    ll c = 0;
    for (int i = 0; i <= y + 1; ++i)
    {
        if (y * 2 == x)
        {
            break;
        }
        x++;
        y--;
        c++;
    }
    if (y < 0 || y < c)
    {
        cout << 0 << endl;
        return 0;
    }
    
    ll ret = calc(y, c, mod);
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 10624
A,B = map(int,input().split())
if A % 2 == 0:
    n = (B-A+1) % 4
    if n == 0:
        ans = 0
    elif n == 1:
        ans = B
    elif n == 2:
        ans = (B-1)^B
    else:
        ans = (B-2)^(B-1)^B
else:
    n = (B-A+1-1) % 4 
    if n == 0:
        ans = A 
    elif n == 1:
        ans = A^B
    elif n == 2:
        ans = A^(B-1)^B
    else:
        ans = A^(B-2)^(B-1)^B

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
#include <list>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, nums[100009];
    cin>>N;
    rep(i,N) cin>>nums[i];
    
    sort(nums,nums+N);
    
    int fr=nums[0], bk=nums[N-1], idf=1, idb=N-2;
    ll sum = bk-fr;
    while(idf<=idb){
        ll mxf = max(abs(fr-nums[idf]), abs(bk-nums[idf]));
        ll mxb = max(abs(fr-nums[idb]), abs(bk-nums[idb]));
        ll idx;
        if(mxf>mxb){
            idx=idf;
            idf++;
        }else{
            idx=idb;
            idb--;
        }
        
        ll fv = abs(fr-nums[idx]);
        ll bv = abs(bk-nums[idx]);
        sum += max(fv,bv);
        if(fv>bv){
            fr=nums[idx];
        }else{
            bk=nums[idx];
        }
    }
    cout1(sum)
}


Measured memory_bytes: 640
n, m = gets.split( " " ).map { | val | val.to_i }
ai = Array.new( n )
ai.each_index { |i|
	ai[i] = gets.split( " " ).map { | val | val.to_i }
}
bi = Array.new( m )
bi.each_index { |i|
	bi[i] = gets.chomp!.to_i
}

ci = Array.new( n, 0 )
ai.each_index { |i|
	ai[i].each_index { |j|
		ci[i] += ( ai[i][j] * bi[j] )
	}
	puts( ci[i] )
}

Measured memory_bytes: 6128
N = int(input())
A = list(map(int,input().split()))
mi = min(A)
ma = max(A)
g = 1
if mi > 0:
    g = 1
elif ma < 0:
    g = -1
elif abs(mi) < abs(ma):
    g = 1
else:
    g = -1

print(2*N-1)
if g == 1:
    mai = A.index(ma)
    print(mai+1,mai+1)
    A[mai] += A[mai]
    #print(A)
    for i in range(N):
        if i != mai:
            print(mai+1,i+1)
            A[i] += A[mai]
            #print(A)
    for i in range(N-1):
        print(i+1,i+2)
        A[i+1] += A[i]
        #print(A)
else:
    mii = A.index(mi)
    print(mii+1,mii+1)
    A[mii] += A[mii]
    #print(A)
    for i in range(N):
        if i != mii:
            print(mii+1,i+1)
            A[i] += A[mii]
            #print(A)
    for i in range(N-1,0,-1):
        print(i+1,i)
        A[i-1] += A[i]
        #print(A)


Measured memory_bytes: 38384
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#define lowbit(x) (x)&(-x)
using namespace std;
int n,m;
long long ans;
priority_queue<int>q;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)
	{
		int a=read();
		q.push(a);
	}
	for(int i=1;i<=m;i++)
	{
		int a=q.top();
		q.pop();
		q.push(a/2);
	}
	for(int i=1;i<=n;i++)
	{
		int a=q.top();
		q.pop();
		ans+=a;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 892
fn main() {
    let mut inputs = Vec::new();    
    loop {
        let s = {
            let mut s = String::new(); 
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().to_string()
        };

        let num = s.parse::<i32>().unwrap();
        if num == 0 { break; }
        inputs.push(num);
    }

    for i in 0..inputs.len() {
        println!("Case {}: {}", i + 1, inputs[i]);
    }
}



Measured memory_bytes: 5048
// D - String Equivalence
// DFS version
#include <bits/stdc++.h>
using namespace std;

int N;

void dfs(string pre){
	if(pre.size() >= N){
		cout<< pre <<endl;
		return;
	}
	char mx='a'; for(auto c:pre) mx = max(mx, char(c+1));
	for(char c='a'; c<=mx; ++c) dfs(pre+c);
}

int main(){
	cin>>N;
	dfs("a");
}

Measured memory_bytes: 1536
a, b, c, d = map(int, input().split())
if b < c or d < a:
    print(0)
elif a <= c and d <= b:
    print(d-c)
elif c <= a and b <= d:
    print(b-a)
elif a <= c and b <= d:
    print(b-c)
elif c <= a and d <= b:
    print(d-a)

Measured memory_bytes: 9072
n = gets.to_i
a = gets.split.map &:to_i
MOD = 10**9 + 7
cum = [0]
(1...n).each do |i|
	cum[i] = (cum[i-1] + a[i]) % MOD
end

sum = 0
(0..n-2).each do |i|
	sum = (sum + a[i] * (cum[n-1] - cum[i])) % MOD
end

p sum

Measured memory_bytes: 29912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		String n = String.valueOf(N);
		boolean f = true;
		for (int i = 1; i < n.length(); i++) {
			if (n.charAt(i) != '9') {
				f = false;
			}
		}
		int ans = Integer.parseInt(n.substring(0, 1));
		for (int i = 1; i < n.length(); i++) {
			ans += 9;
		}
		if (f) {
			System.out.println(ans);
		} else {
			System.out.println(ans - 1);
		}
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
vector<ll>a,b,c;
bool cmp(ll a,ll b)
{
    return a>b;
}

int main()
{
    int n,k;
    ll x,ans=1;
    cin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        cin>>x;
        if(x>0)a.push_back(x);
        if(x<0)c.push_back(x);
        if(x==0)b.push_back(x);
    }
    sort(a.begin(),a.end(),cmp);
    sort(c.begin(),c.end());
    if(k==n)
    {
        if(b.size()!=0)
        {
            ans=0;
            cout<<ans<<endl;
            return 0;
        }
        else
        {
            for(int i=0;i<a.size();++i){ans*=a[i],ans%=mod;}
            for(int i=0;i<c.size();++i){ans*=c[i],ans%=mod;}
            ans=(ans+mod)%mod;
            cout<<ans<<endl;
            return 0;
        }
    }
    else
    {
        if(a.size()+c.size()<k)
        {
            ans=0;
            cout<<ans<<endl;
            return 0;
        }
        if(a.size()==0)
        {
            if(c.size()>=k)
            {
                if(k&1)
                {
                    if(b.size()==0)
                    {
                        for(int i=1;i<=k;++i){ans*=c[c.size()-i],ans+=mod,ans%=mod;}
                        cout<<ans<<endl;
                        return 0;
                    }
                    else
                    {
                        cout<<0<<endl;
                        return 0;
                    }
                }
                else
                {
                    for(int i=0;i<k;++i){ans*=c[i],ans%=mod;}
                    cout<<ans<<endl;
                    return 0;
                }
            }
        }
        else
        {
            int al=0,cl=0;
            ll ans=1;
            if(k&1)
            {
                ans*=a[al++];
                k--;
                while(k>1)
                {
                    if(cl+2>c.size()||a[al]*a[al+1]>c[cl]*c[cl+1]) ans*=a[al]%mod*a[al+1]%mod,ans%=mod,al+=2;
                    else ans*=c[cl]%mod*c[cl+1]%mod,ans+=mod,ans%=mod,cl+=2;
                    k-=2;
                }
            }
            else
            {
                while(k)
                {
                    if(cl+2>c.size()||a[al]*a[al+1]>c[cl]*c[cl+1]) ans*=a[al]%mod*a[al+1]%mod,ans%=mod,al+=2;
                    else ans*=c[cl]%mod*c[cl+1]%mod,ans+=mod,ans%=mod,cl+=2;
                    k-=2;
                }
            }
            cout<<ans<<endl;
            return 0;
        }

    }
}


Measured memory_bytes: 5524
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    double ans = 0;
    REP(i,n){
        double x; string u; cin >> x >> u;
        if(u=="JPY") ans+=x;
        else ans+=x*380000;
    }
    out(ans);

    return 0;
}

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

main(){
	//          0  1  2  3  4  5  6  7  8  9 10 11 12
	int days[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
	
	for(int i=2; i<=12; ++i){
		days[i] += days[i-1];
	}
	
	char day[][20]={
		"Thursday",
		"Friday",
		"Saturday",
		"Sunday",
		"Monday",
		"Tuesday",
		"Wednesday"
	};
	
	while(true){
		// 月, 日
		int m, d;
		cin >> m >> d;
		
		if(m == 0){
			break;
		}
		
		cout << day[(days[m-1]+d-1)%7] <<endl;
	}
}


Measured memory_bytes: 3080
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

struct Manager{
  map<string, int> m;
  int size(){
    return m.size();
  }
  int get_id(string s){
    if(m.count(s)) return m[s];
    int id = m.size();
    return m[s] = id;
  }
};

struct Edge{
  int to, cost;
  Edge(int a, int b) : to(a), cost(b) {}
};
typedef vector<Edge> Node;
typedef vector<Node> Graph;

int main(){
  int N;
  while(cin >> N && N){
    Manager manager;
    bool exist[300][300] = {};
    REP(i, N){
      string s;
      cin >> s;
      string t1, t2;
      REP(i, s.size()) if(s[i] == '-') t1 = s.substr(0, i), t2 = s.substr(i + 1);
      int x = manager.get_id(string(t1));
      int y = manager.get_id(string(t2));
      exist[x][y] = true;
    }
    int L = manager.size();
    cout << L << endl;
    Graph G(L);
    REP(i, L) REP(j, L) if(i != j) {
      bool ok = false;
      REP(k, L) if(exist[i][k] && exist[j][k]) ok = true;
      REP(k, L) if(exist[k][i] && exist[k][j]) ok = true;
      REP(k, L) if(exist[i][k] && exist[k][j]) ok = false;
      REP(k, L) if(exist[k][i] && exist[j][k]) ok = false;
      if(ok){
        assert(!exist[i][j]);
        G[i].push_back(Edge(j, 0));
      }else if(exist[i][j]){
        G[i].push_back(Edge(j, 1));
      }
    }
    int M;
    cin >> M;
    REP(_, M){
      string s;
      cin >> s;
      string t1, t2;
      REP(i, s.size()) if(s[i] == '-') t1 = s.substr(0, i), t2 = s.substr(i + 1);
      int x = manager.get_id(string(t1));
      int y = manager.get_id(string(t2));
      if(x >= L || y >= L){
        cout << "NO" << endl;
        continue;
      }
      queue<int> que;
      int dist[300] = {};
      memset(dist, -1, sizeof dist);
      que.push(x);
      dist[x] = 0;
      while(!que.empty()){
        int u = que.front(); que.pop();
        REP(i, G[u].size()){
          int v = G[u][i].to;
          int d = dist[u] + G[u][i].cost;
          if(dist[v] == -1 || dist[v] > d){
            dist[v] = d;
            que.push(v);
          }
        }
      }
      if(dist[y] > 0 && dist[y] % 2 == 1){
        cout << "YES" << endl;
      }else{
        cout << "NO" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1388
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var inp = new string[n];
        var ans = new int['z' - 'a' + 1];
        for (int i = 0; i < n; i++) inp[i] = Console.ReadLine();
        for (int i = 0; i < ans.Count(); i++) ans[i] = int.MaxValue;
        for (int i = 0; i < n; i++)
        {
            for (char c = 'a'; c <= 'z'; c++)
            {
                ans[c - 'a'] = Math.Min(ans[c - 'a'], inp[i].Count(x => x == c));
            }
        }
        string result = string.Empty;
        for (int i = 0; i < ans.Count(); i++) result += string.Join("", Enumerable.Repeat((char)('a' + i), ans[i]));
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	vector<ll> A(5);
	rep(i,5)cin>>A[i];
	rep(i,5)if(A[i] == 0){cout<<i+1<<endl;break;}
	return 0;
}

Measured memory_bytes: 3624
from fractions import gcd
def gen(x):
    i = 2
    while i * i <= x:
        yield i
        i += 1

def main():
    a,b = map(int,input().split())
    g = gcd(a,b)
    ans = 1
    for i in gen(g):
        if g % i == 0:
            ans += 1
            while(g % i == 0):g //= i
    if g != 1:ans += 1

    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        //入力を保持する
        var NK = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
        //果物の種類
        var N = NK[0];
        //選択する数
        var K = NK[1];
        //価格をあらかじめソートしておく
        var Ps = Console.ReadLine().Split().Select(e => int.Parse(e)).OrderBy(e => e).ToArray();
        var ans = 0;
        //小さい順になっているのでK回ループして回答とする
        for (var n = 0; n < K; n++)
        {
            ans += Ps[n];
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 28576
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

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

    int n;
    int a[200001];
    int b[200001];
    int num = 0;
    int Max = -1;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> a[i];
        b[i] = a[i];
        if(Max < a[i]){
            Max = a[i];
            num = i;
        }
    }

    sort(b,b+n);

    for(int i = 0; i < n; i ++){
        if(num != i) cout << Max;
        else cout << b[n-2];
        
        cout << "\n";
    }



    return 0;
}









Measured memory_bytes: 5140