akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[200005], D[200005], B[200005];
int main() {
    init();
    ll N,K;
    cin >> N >> K;
    rep(i, N) cin >> A[i], D[i] = A[i];

    rep(k,K){
        bool alln = true;
        fill(B, B + N + 1, 0);

        rep(i, N) B[max(0ll, i - A[i])]++, B[min(N, i + A[i] + 1)]--;

        // verr(B, N+1);

        ll a = 0;
        rep(i,N){
            a += B[i];
            A[i] = a;
            if (a < N) alln = false;
        }

        if(alln){
            rep(i, N) cout << N << " ";
            cout << endl;
            return 0;
        }
    }

    rep(i, N) cout << A[i] << " ";
    cout << endl;
}   

Measured memory_bytes: 8332
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <cmath>
#include <vector>
#include <queue> 
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define db double
#define int LL
using namespace std;
const int N   = 233;
//const int mod = ;
const int INF =numeric_limits<int >::max();

#define rep(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
/*
1
275 204 197 290

*/
int T,A,B,C,D;

int gcd(int a, int b){ return a == 0 ? b : gcd(b % a, a); } 
void solve(int x,int y,int z,int K)
{
	int t=gcd(y,z);
	int k=x/t;
	int tmp=x-k*t;
	if (tmp>t) tmp-=t;
	int tt=z-t+tmp;
	if (tt>K) printf("No\n");
	else printf("Yes\n");
}
/*
1
16 10 5 10

*/
signed main()
{
	//	freopen("data.txt","r",stdin);
//	freopen("Ac.txt","w",stdout);
	read(T);
	int g=1;
	while (T--)
	{
		read(A);read(B);read(C);read(D);
		if (A<B)
		{
			printf("No\n");
			continue;
		}
     	int k=max((A-C)/B,0ll);
		A-=k*B;
		if (A-B<=C&&A>=B) A-=B;
		if (A>C||B>D) 
		{
			printf("No\n");
			continue;
		}
	
		solve(A,D-B,B,C) ;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  //ios::sync_with_stdio(false);
  int n,a,b,c;
  cin>>n>>a>>b>>c;
  deque<string> ans;
  string prev="";
  rep(i,n){
    string s;
    //cout<<prev<<endl;
    //cout<<a<<" "<<b<<" "<<c<<endl;
    cin>>s;
    if(s=="AB"){
      if(a==0 && b==0){
	if(prev=="AC"){
	  if((a==1 && c==0)||(c==1 && a==0)){cout<<"No"<<endl;return 0;}
	  else{
	    swap(a,c);
	    string t=ans[ans.size()-1];
	    ans.pop_back();
	    if(t=="A") ans.push_back("C");
	    else ans.push_back("A");
	  }
	}
	else if(prev=="BC"){
	  if((b==1 && c==0)||(c==1 && b==0)){cout<<"No"<<endl;return 0;}
	  else{
	    swap(c,b);
	    string t=ans[ans.size()-1];
	    ans.pop_back();
	    if(t=="B") ans.push_back("C");
	    else ans.push_back("B");
	  }
	}
	else {cout<<"No"<<endl;
	  return 0;
	}
      }
      if(a>b){
	a--;b++;
	ans.push_back("B");
      }else if(a<=b){
	a++;b--;
	ans.push_back("A");
      }
    }
    if(s=="AC"){
      if(a==0 && c==0){
	if(prev=="AB"){
	  if((a==1 && b==0)||(b==1 && a==0)){cout<<"No"<<endl;return 0;}
	  else{
	    swap(a,b);
	    string t=ans[ans.size()-1];
	    ans.pop_back();
	    if(t=="B") ans.push_back("A");
	    else ans.push_back("B");
	  }
	}
	else if(prev=="BC"){
	  if((b==1 && c==0)||(c==1 && b==0)){cout<<"No"<<endl;return 0;}
	  else{
	    swap(c,b);
	    string t=ans[ans.size()-1];
	    ans.pop_back();
	    if(t=="B") ans.push_back("C");
	    else ans.push_back("B");
	  }
	}
	else {cout<<"No"<<endl;
	  return 0;
	}
      }
      if(a>c){
	a--;c++;
	ans.push_back("C");
      }else if(a<=c){
	a++;c--;
	ans.push_back("A");
      }
    }
    if(s=="BC"){
      if(c==0 && b==0){
	if(prev=="AC"){
	  if(a==1 && c==0){cout<<"No"<<endl;return 0;}
	  if(a==0 && c==1){cout<<"No"<<endl;return 0;}
	 
	    swap(c,a);
	    string t=ans[ans.size()-1];
	    ans.pop_back();
	    if(t=="A") ans.push_back("C");
	    else ans.push_back("A");
	  
	}
	else if(prev=="AB"){
	  if((b==1 && a==0)||(a==1 && b==0)){cout<<"No"<<endl;return 0;}
	  else{
	    swap(a,b);
	    string t=ans[ans.size()-1];
	    ans.pop_back();
	    if(t=="B") ans.push_back("A");
	    else ans.push_back("B");
	  }
	}
	else {cout<<"No"<<endl;
	  return 0;
	}
      }
      if(c>b){
	c--;b++;
	ans.push_back("B");
      }else if(c<=b){
	c++;b--;
	ans.push_back("C");
      }
    }
    prev=s;
  }
  cout<<"Yes"<<endl;
  rep(i,ans.size() ){
    cout<<ans[i]<<endl;
  }
  

  return 0;
}


Measured memory_bytes: 6924
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S; cin >> S;
  if(S == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll k, a, b;
  cin >> k >> a >> b;

  if (b - a <= 2) {
    cout << k + 1 << '\n';
  }
  else {
    if (k <= a - 1) {
      cout << k + 1 << '\n';
    }
    else {
      cout << a + (b - a) * ((k - a + 1) / 2) + (k - a + 1) % 2 << '\n';
    }
  }

  

  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	
	vector<ll> a(n);
	ll suf = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		suf = (suf + a[i]) % P;
	}
	
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		suf = ((suf - a[i]) % P + P) % P;
		ans = (ans + (a[i] * suf) % P) % P;
	}
	
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 4836
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
int main() {
    ll n,x;
    cin>>n>>x;
    vector<ll>a(n+1);
    for(int i=1;i<=n;i++)
    cin>>a[i];
    ll ans=0;
    for(int i=2;i<n;i++)
    {
        if(a[i-1]+a[i]>x)
        {
            int res=a[i-1]+a[i]-x;
            ans+=res;
            if(a[i]>=res) a[i]-=res;
            else
            {
                a[i]=0;
                a[i-1]-=res-a[i];
            }
        }
    }
    if(a[n-1]+a[n]>x)
    {
        ans+=a[n-1]+a[n]-x;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream> 
using namespace std; 
typedef long long ll; 
int main() 
{ 
		ios::sync_with_stdio(false); 
		cin.tie(NULL); 
		ll r;
		cin>>r; 
		const float pi=3.1415; 
		cout<<(float)(2*pi*r); 
		return 0; 
}


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

bool pal(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return (s == t) ? true : false;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  cout << ((pal(S) && pal(S.substr(0, N / 2)) && pal(S.substr(N / 2 + 1))) ? "Yes" : "No") << "\n";
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;

int k,n;
int a[200100];
vector <int> v(200100,0);

int main(){
  cin >> n >> k;
  rep(i,1,n+1)cin >> a[i];
  rep(i,1,n+1){
    v[a[i]]++;
  }
  sort(rall(v));
  ll ans = n;
  rep(i,0,k){
    ans -= v[i];
  }
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include<cstdio>
int main() {
	int a,b;
	char s[12];
	scanf("%d%d", &a,&b);
	scanf("%s", s);
	for (int i = 0; i <= a+b; i++) {
		if (i==a&&s[i]!='-'||i!=a&&('0' > s[i] || s[i] > '9')) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
const int Max=2e5+5;
struct node{
	string s;
}a[Max];
char s1[11];
bool cmp(node a,node b){
	return a.s<b.s;
}
int main()
{
	int t;
	sc(t);
	rep(i,1,t){
		getchar();scs(s1);
		int n=strlen(s1);
		rep(j,0,n-1){
			a[i].s=s1;
		}
	}sort(a+1,a+t+1,cmp);
	int cou=t;
	rep(i,1,t-1){
		if(a[i].s==a[i+1].s)cou--;
	}pf("%d\n",cou);
}


Measured memory_bytes: 10048
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

// using
using namespace std;

// typedef
typedef long long ll;
typedef unsigned long long ull;

// assert
template <typename T>
void assert_between(T val, T min, T max)
{
    assert(min <= val && val <= max);
}

// math
template <typename T>
T euclid(T a, T b)
{
    assert(a > 0 && b > 0);
    T num1 = max(a, b);
    T num2 = min(a, b);
    T mod = num1 % num2;
    return (mod == 0) ? num2 : euclid(num2, mod);
}

int main ()
{
    string str1 = "";
    string str2 = "";
    map<char, char> conv_map_1 {};
    map<char, char> conv_map_2 {};

    char tmp_buffer[200001];
    scanf("%s", tmp_buffer);
    str1 = tmp_buffer;
    scanf("%s", tmp_buffer);
    str2 = tmp_buffer;

    assert_between<int>(str1.size(), 1, 200001);
    assert(str1.size() == str2.size());

    bool result = true;
    for (size_t i = 0; i < str1.size(); i++)
    {
        char c1 = str1[i];
        char c2 = str2[i];

        if (conv_map_1.find(c1) != conv_map_1.end() && conv_map_1[c1] != c2) { result = false; break; }
        if (conv_map_2.find(c2) != conv_map_2.end() && conv_map_2[c2] != c1) { result = false; break; }

        conv_map_1[c1] = c2;
        conv_map_2[c2] = c1;
    }

    if (result) { printf("Yes\n"); } else { printf("No\n"); }
}

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

int main() {
  int N,K,i,x,sum;
  cin >>N>>K;
  for (i = 0;i < N;i++) {
    cin >> x;
    if (x <= K - x) {
      sum += 2 * x;
    }
    else if (x > K - x) {
      sum += 2 * (K - x);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc054/editorial.pdf
・3次元DP
・送るDP
"""
 
import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
N, Ma, Mb = map(int, input().split())
l = [[0] * 3 for i in range(N)]
for i in range(N):
    l[i][0], l[i][1], l[i][2] = map(int, input().split())

# 不可能な組み合わせは0とは区別するのでINF初期化
dp = [[[INF] * 401  for i in range(401)] for i in range(N+1)]
dp[0][0][0] = 0
for i in range(N):
    for j in range(401):
        for k in range(401):
            # あり得ない組み合わせの時は送らない
            if dp[i][j][k] == INF: continue
            dp[i+1][j][k] = min(dp[i][j][k], dp[i+1][j][k])
            dp[i+1][j+l[i][0]][k+l[i][1]] = min(dp[i][j][k] + l[i][2], dp[i+1][j+l[i][0]][k+l[i][1]])

ans = INF
for j in range(1, 401):
    for k in range(1, 401):
        # j/k == Ma/Mb だと分母0が心配なので
        if j * Mb == k * Ma:
            ans = min(dp[N][j][k], ans)

if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 59380
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
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 ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

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

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  int n;
  string a,b,c;
  cin>>n>>a>>b>>c;
  ll ans = 0;
  for(int i = 0; i < n; i++){
    if(a[i]==b[i]&&b[i]==c[i]){
      continue;
    }
    else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
      ans+=1;
    }
    else{
      ans+=2;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
import collections as col
N = int(input())
S = input()
SMae, SAto = '', ''
SCol = col.Counter(S).most_common()
Ans = [0]*(N-1)

for i in range(N-1):
    SMae, SAto = S[:i+1], S[i+1:]
    for j in SCol:
        if j[0] in SMae and j[0] in SAto:
            Ans[i] += 1

print(max(Ans))


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

using namespace std;
using Graph = vector<vector<int>>;

int main(void)
{   
    int N, M, a, b;
    cin >> N >> M;
    Graph G(N);
    //　N；頂点　M；辺
    
    for(int i = 0; i < M; i++) {
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N, -1);
    vector<int> pre(N,-1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front(); 
        que.pop();

        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
            pre[nv] = v; 
        }
    }
    cout << "Yes" << endl;
    for (int v = 1; v < N; ++v) {
        cout << pre[v] + 1 << endl;
    }

    return 0;

}

Measured memory_bytes: 10664
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 ll INF = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1, div = INF;
    rep(i,n){
        if(div / a[i] == 0){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
        div = (div + a[i] - 1) / a[i];
    }
    if(ans > INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3928
#include <iostream>
#include <math.h>
using namespace std;


bool isprime(int x)
{
    int i, xsqri;
    double xsqr;
    if(x == 2) return true;        
    if(x < 2 || x % 2 == 0) return false;

    xsqr = sqrt(x);
    xsqri = (int)xsqr;
    for (i = 3; i <= xsqri; i+=2) {
        if(x % i == 0) {
            return false;
        }
    }
    return true;
}

int main(void){
    int i, n, x, c=0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> x;
        c += isprime(x);
    }
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

ll gcd(ll a, ll b) {
    if ( b > a ) swap(a, b);
    if ( a % b == 0 ) return b;
    return gcd(b, a % b);
}

int main(){
    int n;
    cin >> n;
    ll s;
    cin >> s;
    ll gcd_num;
    rep(i, n) {
        ll x;
        cin >> x;
        if ( i == 0 ) gcd_num = abs(x - s);
        else          gcd_num = gcd(gcd_num, abs(x - s));
    }
    cout << gcd_num << endl;
    return 0;
}


Measured memory_bytes: 256
d = int(input())
c = list(map(int,input().split()))
s = []
p = [1]*d
for i in range(d):
    s.append(list(map(int,input().split())))
    p[i] = s[i].index(max(s[i]))+1
for i in range(d):
    print(p[i])

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	double W, H, x, y;
	cin >> W >> H >> x >> y;
	double ans = W * H / 2.0;
	bool F = x*2==W&&y*2==H;
	printf("%lf %d\n", ans, F);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

vector<vector<int>> g;
vector<int> seen;
void dfs(int now){
  seen[now] = 1;

  for(int v: g[now]){
    if(seen[v] != -1) continue;
    dfs(v);
  }
}

int main(){
  int n,m; cin >> n >> m;
  g.resize(n);
  seen.resize(n,-1);
  for(int i = 0; i < m; i++){
    int x,y,z; cin >> x >> y >> z;
    x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  ll ans = 0;
  for(int i = 0; i < n; i++){
    for(int v: g[i]){
      if(seen[v] != -1) continue;
      ans++;
      dfs(v);
    }
  }
  for(int i = 0; i < n; i++){
    if(seen[i] != -1) continue;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9216
#include <stdio.h>

int main() {
	int in[100][2], i;

	for (i = 0; i < 100; i++) {
		scanf("%d %d", &in[i][0], &in[i][1]);
		if (in[i][0] == 0 && in[i][1] == 0)break;
	}
	int flag = 0;
	for (int j = 0; j < i; j++) {
		for (int k = 0; k < in[j][0]; k++) {
			for (int l = 0; l < in[j][1]; l++) {
				if ((k % 2) == 0) {
					if (flag == 0) {
						printf("#");
						flag = 1;
					}
					else if(flag == 1){
						printf(".");
						flag = 0;
					}
				}
				else if ((k % 1) == 0) {
					if (flag == 1) {
						printf("#");
						flag = 0;
					}
					else if (flag == 0) {
						printf(".");
						flag = 1;
					}
				}
			}printf("\n"); flag = 0;
		}printf("\n");
	}

	return 0;
}


Measured memory_bytes: 2600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[45000];
  int n,l;
  a[1]=1;
  for(int i=2;i<100000;i++){
    a[i]=a[i-1]+i;
    if(a[i]>1000000000){
      break;
    }
  }
  cin>>n;
  for(int i=1;i<45000;i++){
    if(n<=a[i]){
      l=i;
      break;
    }
  }
  for(int i=0;i<n-a[l-1];i++){
    cout<<")";
  }
  cout<<"(";
  for(int i=0;i<a[l]-n;i++){
    cout<<")";
  }
  for(int i=0;i<l-1;i++){
    cout<<"(";
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const double rad = 180/3.14159265358979323846;
int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    double v = x/a;
    if (2*v >= a*b)
    {
        double u = (2*a*b-2*v)/(a*a);
        cout << fixed << setprecision(10) << atan(u)*rad << '\n';
    }
    else 
    {
       cout << fixed << setprecision(10) << atan(b*b/(2*v))*rad << '\n';
    }
}

Measured memory_bytes: 256
N,Y = map(int,input().split())
for i in range(0,N+1):
    for j in range(0,N-i+1):
            if i*10000 + j *5000 +1000*(N - i - j) == Y:
                print(i,j,N-i-j)
                exit()
print('-1 -1 -1')

Measured memory_bytes: 9108
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def f():
    N = 1000
    X = int(input())
    pow5_list = [pow(i, 5) for i in range(N)]
    A, B = 0, 0
    for i in range(N):
        for j in range(i-1, 0, -1):
            if pow5_list[i] - pow5_list[j] == X:
                A, B = i, j
                return A, B
        for k in range(i+1):
            if pow5_list[i] + pow5_list[k] == X:
                A, B = i, -k
                return A, B

def main():
    A, B = f()
    print("{} {}".format(A, B))

if __name__ == "__main__":
    main()




Measured memory_bytes: 9228
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[200005]={},cnt=0,b[200005]={},j,ans=0;
  cin >> n;
  for(int i=1; i<=n; i++) {
    cin >> a[i];
  }
  j=n;
  while(j>0) {
    cnt=0;
    for(int k=j; k<=n; k+=j) {
      cnt+=b[k];
    }
    if(cnt%2!=a[j]) {
      b[j]=1;
    }
    j--;
  }
  for(int i=1; i<=n; i++) {
    if(b[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  for(int i=1; i<=n; i++) {
    if(b[i]) {
      cout << i << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct UnionFind {
  vector<ll> par; 
  vector<ll> siz; 

    
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; 
  }
  void init(ll sz_) {
    par.clear();
    par.resize(sz_);
    siz.clear();
    siz.resize(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) { 
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

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

  int n, m;
  cin >> n >> m;
  vector<array<int, 3>> G(m);
  rep(i, m) {
    cin >> G[i][1] >> G[i][2] >> G[i][0];
    G[i][1]--, G[i][2]--;
  }

  sort(G.begin(), G.end());
  UnionFind uf(n);
  vector<bool> used(m, false);
  int cost = 0;
  rep(i, m) {
    if (uf.merge(G[i][1], G[i][2])) {
      used[i] = true;
      cost += G[i][0];
    }
  }
  vector<int> ans(2, 0);
  rep(i, m) {
    if (!used[i]) continue;
    uf.init(n);
    int cost2 = 0;
    rep(j, m) {
      if (i != j && uf.merge(G[j][1], G[j][2])) {
        cost2 += G[j][0];
      }
    }
    if (uf.size(0) != n || cost2 != cost) {
      ans[0]++;
      ans[1] += G[i][0];
    }
    //cout << cost2 << '\n';
  }
  cout << ans[0] << ' ' << ans[1] << '\n';

  




  
  return 0;
}


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

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n, cnt = 0;
	cin >> n;
	while (n--) {
		string s; cin >> s;
		if (s == "E869120") ++cnt;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
int graph[10][10];
int main()
{
	int n, m;
	cin >> n >> m;
	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a][b] = 1;
		graph[b][a] = 1;
	}
	vector<int> v(n);
	rep(i,n){
		v[i] = i;
	}
	int ans = 0;
	do
	{
		if (v[0] != 0)
			continue;
		bool find = true;
		rep(i, n - 1)
		{
			if(!graph[v[i]][v[i+1]])
				find = false;
		}
		ans += find ? 1 : 0;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
	return 0;
}


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

int N , M ;
cin >> N >> M ;
if( N<=9 && M <=9) cout << N*M <<endl ;
else cout << -1 <<endl;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n")[0]
    input = input.replace(/[^ACGT]+/g, '-') // ACGT以外を置き換える
   
    const lengths = input.split('-').map(elem => elem.length) 
    console.log( Math.max(...lengths) )
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 7372
// #include <bits/stdc++.h>
#include <stdio.h>
#include <utility>
 
// using namespace std;
using std::swap;
 
typedef long long ll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)

ll a[252521];
ll tmp[252521];
 
ll solve(int l,int r){
  if(r-l <= 32){
    ll ret = (r-l)*(r-l-1)/2;
    REP(k,r-l-1)FOR(i,l,r-1-k)if(a[i]>a[i+1])swap(a[i],a[i+1]),ret--;
    return ret;
  }
  // if(r-l==1){
  //   return 0ll;
  // }
  int mid = (l+r)/2;
  ll ret = solve(l,mid) + solve(mid,r);
  int hl = l, hr = mid;
  FOR(i,l,r){
    if(hl<mid && (hr==r || a[hl]<=a[hr])){
      tmp[i] = a[hl++];
    }else{
      ret += hl-l;
      tmp[i] = a[hr++];
    }
  }
  FOR(i,l,r)a[i]=tmp[i];
  return ret;
}
 
int main(){
  int n;
  ll k;
  scanf("%d%lld",&n,&k);
  REP(i,n){
    scanf("%lld",a+i+1);
    a[i+1] += a[i] - k;
  }
  ll ans = solve(0,n+1);
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N, M;
    array<ll, 64> A, B, C, D;
    array<ll, 64> ans;
    
    cin >> N >> M;
    
    for(ll i = 0; i < N; ++i){
        cin >> A[i] >> B[i];
    }
    
    for(ll i = 0; i < M; ++i){
        cin >> C[i] >> D[i];
    }
    
    for(ll i = 0; i < N; ++i){
        ll mj = 0;
        ll md = 100000000000;
        for(ll j = 0; j < M; ++j){
            ll d = abs(A[i] - C[j]) + abs(B[i] - D[j]);
            if(d < md){
                mj = j;
                md = d;
            }
        }
        ans[i] = mj + 1;
    }
    
    for(ll i = 0; i < N; ++i){
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define modp 998244353
#define Maxn 300007
using namespace std;
int n,a,b;
long long k;
int pre[Maxn],inv[Maxn];
int power(int a,int b)
{
	int res=1,now=a,left=b;
	while (left>0)
	{
		if (left%2==1) res=(1LL*res*now)%modp;
		left/=2;
		now=(1LL*now*now)%modp;
	}
	return res;
}
int calc(int a,int b)
{
	if (b<0||b>a) return 0;
	int res=(1LL*pre[a]*inv[b])%modp;
	return (1LL*res*inv[a-b])%modp;
}
int main()
{
	scanf("%d%d%d%lld",&n,&a,&b,&k);
	pre[0]=1;
	for (int i=1;i<=n;i++)
		pre[i]=(1LL*i*pre[i-1])%modp;
	inv[n]=power(pre[n],modp-2);
	for (int i=n;i;i--)
		inv[i-1]=(1LL*i*inv[i])%modp;
	int ans=0;
	for (int i=0;i<=n;i++)
	{
		long long t=k-1LL*i*a;
		if (t<0||t%b!=0) continue;
		t/=b;
		if (t>n) continue;
		int del=(1LL*calc(n,i)*calc(n,t))%modp;
		ans=(ans+del)%modp;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2560
n, m = map(int, input().split())
d = {}
s_ac = set()
ac = 0
pen = 0
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if s == 'AC':
        if p not in s_ac:
            ac += 1
            s_ac.add(p)
            if p in d:
                pen += d[p]
    else:
        if p not in d:
            d[p] = 1
        else:
            d[p] += 1
print(ac, pen)


Measured memory_bytes: 55256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n,k;
int a[maxn];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(k>=n)
	{
		cout<<0<<endl;
		return 0;
	}
	k=n-k;
	sort(a,a+n);
	long long ans=0LL;
	for(int i=0;i<k;i++)
	{
		ans+=(long long)a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
    int N,K; cin>>N>>K;
    ll ans=0;
    for(int i=K+1;i<=N;i++){
        ll s=N/i;
        ll a=N%i;
        ans+=(s*(i-K));
        if(a>=K) ans+=(a+1-K);
    }
    if(K==0) ans-=N;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools
import math

N = int(input())
Cities = []
for _ in range(N):
  x, y = map(int,input().split())
  Cities.append([x, y])
seq = [i for i in range(N)]  
patterns = list(itertools.permutations(seq))
records = [0,0]

for item in patterns:
  for i in range(N-1):
    A = (Cities[item[i+1]][0] - Cities[item[i]][0])**2
    B = (Cities[item[i+1]][1] - Cities[item[i]][1])**2
    length = math.sqrt(A+B)
    records[0] += length
  records[1] += 1 
Answer = records[0]/records[1] 

print(Answer)



Measured memory_bytes: 7972
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define cerr cout
#define F first
#define S second
#define fori(i,a,b) for (i = a; i < b; ++i)
#define ford(i,a,b) for(i = a; i>=b;--i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int(x.size())
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fill(a, x) memset(a, x, sizeof(a))
#define INF 1000000000
#define SMOD 998244353
#define endl "\n"
ll MOD;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
const ll N = 100043;
ll fact[N];
ll add(ll x, ll y)
{
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}
ll mul(ll x, ll y)
{
	return (x * 1ll * y) % MOD;
}
ll mulmod(ll a, ll b)
{
    ll res = 0;
    a = a % MOD;
    while (b>0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
        a = (a * 2) % MOD;
        b /= 2;
    }
    return res % MOD; 
}
ll binpow(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = mul(z, x);
		x = mul(x, x);
		y /= 2;
	}
	return z;
}
ll inv(ll x)
{
	return binpow(x, MOD - 2);
}
ll divide(ll x, ll y)
{
	return mul(x, inv(y));
}
void precalc()
{
	fact[0] = 1;
	ll i;
	fori(i, 1, N)
		fact[i] = mul(i, fact[i - 1]);
}
ll C(ll n, ll k)
{
	if(k > n)
	    return 0;
	return divide(fact[n], mul(fact[n - k], fact[k]));
}

void solve()
{
    ll k, i;
    cin >> k;
    k *= 9;
    MOD = k;
    // ll y = inv(9);
    if(k%2==0 || k%5==0)
    {
        cout << -1 << endl;
        return;
    }
    fori(i, 1, 1e7)
    {
        if(((7LL*((binpow(10,i)-1LL+k)%k)%k)%k)==0)
        {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin >> t;
    for(int i=1; i<=t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
from bisect import bisect_left, bisect_right
def main():
    N=int(input())
    A=sorted([int(_) for _ in input().split()])
    B=sorted([int(_) for _ in input().split()])
    C=sorted([int(_) for _ in input().split()])
    ans=0
    for b in B:
        ans += bisect_left(A,b) * (N-bisect_right(C,b))
    print(ans)
main()


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

int main(){
    int a,b,k; cin >> a >> b >> k;
    vector<int> d;
    for(int i = min(a,b); i >= 1 ; i--){
        if(min(a,b)%i == 0 && max(a,b)%i == 0){
            d.push_back(i);
        }
    }
    cout << d[k-1];
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


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

vector<int> dice(vector<int> faces,char com){
  vector<int> temp(7);
  if(com == 'N'){
    temp[1] = faces[2];
    temp[2] = faces[6];
    temp[3] = faces[3];
    temp[4] = faces[4];
    temp[5] = faces[1];
    temp[6] = faces[5];
  }else if(com == 'W'){
    temp[1] = faces[3];
    temp[2] = faces[2];
    temp[3] = faces[6];
    temp[4] = faces[1];
    temp[5] = faces[5];
    temp[6] = faces[4];
  }else if(com == 'S'){
    temp[1] = faces[5];
    temp[2] = faces[1];
    temp[3] = faces[3];
    temp[4] = faces[4];
    temp[5] = faces[6];
    temp[6] = faces[2];
  }else if(com == 'E'){
    temp[1] = faces[4];
    temp[2] = faces[2];
    temp[3] = faces[1];
    temp[4] = faces[6];
    temp[5] = faces[5];
    temp[6] = faces[3];
  }else{
    temp[1] = faces[1];
    temp[2] = faces[4];
    temp[3] = faces[2];
    temp[4] = faces[5];
    temp[5] = faces[3];
    temp[6] = faces[6];
  }
  return temp;
}

bool issame(vector<int> a,vector<int> b){
  for(int i=1; i<=6; i++){
    if(a[i] != b[i]){
      return false;
    }
  }
  return true;
}

bool check(vector<int> D1,vector<int> D2){
  bool same = false;
  for(int i=0; i<4; i++){
    D1 = dice(D1,'R');
    for(int j=0; j<4;j++){
      D1 = dice(D1, 'N');
      if(issame(D1,D2)){
        same = true;
      }
    }
  }
  D1 = dice(D1,'E');
  for(int j=0; j<4; j++){
    D1 = dice(D1,'N');
    if(issame(D1,D2)){
      same = true;
    }
  }
  D1 = dice(D1,'W');
  D1 = dice(D1,'W');
  for(int i=0; i<4; i++){
    D1 = dice(D1,'N');
    if(issame(D1,D2)){
      same = true;
    }
  }
  if(same){
    return true;
  }else{
    return false;
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> D(n,vector<int> (7));
  for(int i=0; i<n; i++){
    for(int j=1; j<=6; j++){
      cin >> D[i][j];
    }
  }
  bool all = true;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(check(D[i],D[j])){
        all = false;
      }
    }
  }
  if(all){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 3176
#include<stdio.h>
#include<string.h>
int A[100010],B[100010];
int n,q,i,j;
int Find(int a)
{    
	if(B[a]==1)
	return a;
	else return Find(A[a]);
}
int main(){
	while(scanf("%d%d",&n,&q)&&(n!=0||q!=0))
	{
		memset(B,0,sizeof(B));
		long long int sum=0;
		B[1]=1;
		for(i=2;i<=n;i++)
		{
			int a;
			scanf("%d",&a);
			A[i]=a;
		}	
		char ss[5];
		while(q--)
		{
			scanf("%s",ss);
			if(ss[0]=='Q')
			{
				int b;
				scanf("%d",&b);
				sum+=(long long)Find(b);
			}
			else if(ss[0]=='M')
			{
				int b;
				scanf("%d",&b);
				B[b]=1;
			}
		}
		printf("%lld\n",sum);
	}
	
}



Measured memory_bytes: 2480
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	int a[n],b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		{
			b[a[i]]=i+1;
		}
	for(i=1;i<n+1;i++)
		cout<<b[i]<<" ";
}

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

int main() {

	int K;
	std::string S;

	std::cin >> K >> S;

	if (size(S) <= K) {
		std::cout << S << std::endl;
	}
	else if (size(S) > K) {
		for (int i = 0; i < K; i++) {
			std::cout << S[i];
		}
		std::cout << "..." << std::endl;
	}
}

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

template<typename T> struct Dijkstra {
  struct Edge { int to; T cost; };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

int main() {
  int n;
  cin >> n;
  Dijkstra<ll> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    u--, v--;
    g.addEdge(u, v, w);
  }

  auto d = g.build(0);
  for (int i = 0; i < n; i++) {
    cout << d[i] % 2 << endl;
  }

}


Measured memory_bytes: 9088
#include<iostream>

#include <cmath>
#include <cstring>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <stdio.h>
#include <map>
typedef long long ll;
using namespace std;
const int maxn = 2e5+5;

int main()
{
	int max = 0;
	map<string,int> s;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string name;
		cin>>name;
		if(s.count(name))
		{
			s[name]++;
		}
		else
		{
			s[name] = 1;
			
		}
		if(s[name]>max)
		{
			max = s[name];
		}
	}
	for(auto it = s.begin();it!=s.end();it++)
	{
		if(it->second==max)
		cout<<it->first<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

// overflow: x < -10^4 || 10^4 < x

using namespace std;

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

P factor();
P term();
P exp();

bool f;
lli pos;
string data;

P factor(){
  if(f) return P(0, 0);
  P res;
  if(data[pos] == '('){
    pos++;
    res = exp();
    //cout << "factor(): (" << res.first << ", " << res.second << ") " << pos << endl;
    pos++;
  }else{
    bool comp = false;
    lli i;
    for(i=pos;i<data.size();i++){
      if(data[i] == 'i'){
        comp = true;
        break;
      }
      if(data[i] == '+' || data[i] == '-' || data[i] == '*' || data[i] == ')') break;
    }
    if(comp){
      res.first = 0;
      //res.second = atoi(data.substr(pos, i-pos-1).c_str());
      res.second = 1;
      i++;
      //if(res.second == 0) res.second = 1;
    }else{
      res.first = atoi(data.substr(pos, i-pos).c_str());
      res.second = 0;
    }
    pos = i;
  }
  //cout << "factor: (" << res.first << ", " << res.second << ") " << pos << endl;
  if(res.first < -10000 || 10000 < res.first) f = true;
  if(res.second < -10000 || 10000 < res.second) f = true;
  return res;
}

P term(){
  if(f) return P(0, 0);
  P res = factor();
  while(data[pos] == '*'){
    char op = data[pos++];
    if(op == '*'){
      //cout << "* (" << res.first << ", " << res.second << ")" << endl;
      P tmp = factor();
      lli a = res.first * tmp.first - res.second * tmp.second;
      lli b = res.first * tmp.second + res.second * tmp.first;
      res.first = a;
      res.second = b;
      //cout << "* (" << res.first << ", " << res.second << ")" << endl;
      //cout << "* (" << a << ", " << b << ")" << endl;
    }
    if(res.first < -10000 || 10000 < res.first) f = true;
    if(res.second < -10000 || 10000 < res.second) f = true;
    if(f) return res;
  }
  //cout << "term: (" << res.first << ", " << res.second << ") " << pos << endl;
  return res;
}

P exp(){
  if(f) return P(0, 0);
  P res = term();
  while(data[pos] == '+' || data[pos] == '-'){
    char op = data[pos++];
    if(op == '+'){
      //cout << "+ (" << res.first << ", " << res.second << ")" << endl;
      P tmp = term();
      res.first += tmp.first;
      res.second += tmp.second;
      //cout << "++ (" << tmp.first << ", " << tmp.second << ")" << endl;
    }
    if(op == '-'){
      P tmp = term();
      res.first -= tmp.first;
      res.second -= tmp.second;
    }
    if(res.first < -10000 || 10000 < res.first) f = true;
    if(res.second < -10000 || 10000 < res.second) f = true;
    if(f) return res;
  }
  //cout << "exp: (" << res.first << ", " << res.second << ") " << pos << endl;
  return res;
}

main(){
  while(cin >> data){
    pos = 0;
    f = false;
    P ans = exp();
    if(f) cout << "overflow" << endl;
    else{
      if(ans.first == 0 && ans.second == 0) cout << 0 << endl;
      else{
        if(ans.first != 0) cout << ans.first;
        if(ans.second == 0) cout << endl;
        else if(ans.second > 0 && ans.first != 0) cout << "+" << ans.second << "i" << endl;
        else cout << ans.second << "i" << endl;
      }
    }
  }
}

Measured memory_bytes: 0
require 'set'
loop do
    n = gets.to_i
    break if n == 0
    weight, capacity = (1..n).map { gets.split.map(&:to_i) }.transpose
    ans = false
    queue = [[0, 0]]
    reached = Set[0]
    until queue.empty?
        x, w = queue.pop
        news = []
        (0..n-1).each do |i|
            if x[i] == 0
                if w + weight[i] > capacity[i]
                    news = []
                    break
                else
                    y = x + (1 << i)
                    if y == 2 ** n - 1
                        ans = true
                        break
                    elsif reached.include?(y)
                        next
                    else
                        reached << y
                        news << [y, w + weight[i]]
                    end
                end
            end
        end
        break if ans
        queue += news
    end
    puts ans ? 'Yes' : 'No'
end



Measured memory_bytes: 84884
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);String x,r;for(int t=s.nextInt(),c,i,p;t-->0;System.out.println(r))for(x=s.next(),r="",i=c=0;i<x.length()-1;)if((p=x.charAt(i++))==x.charAt(i))c++;else{r+=p<49?"":p<50?new String[]{".",",","!","?"," "}[c%5]:(char)(97+(new int[]{0,3,6,9,12,15,19,22}[p-=50]+c%new int[]{3,3,3,3,3,4,3,4}[p]));c=0;}}}

Measured memory_bytes: 12000