akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;cin>>n;
    vvi G(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].PB(b);
        G[b].PB(a);
    }
    vi c(n);
    rep(i,n)cin>>c[i];
    sort(all(c));
    reverse(all(c));
    ll sum=0;
    rep(i,n)sum+=c[i];
    sum-=c[0];
    cout<<sum<<endl;
     // BFS のためのデータ構造
    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = c[0];
    que.push(0); // 0 を橙色頂点にする
    int cnt=0;
    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
            cnt++;
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = c[cnt];
            que.push(nv);
        }
    }
    rep(i,n){
        if(i!=n-1)cout<<dist[i]<<" ";
        else cout<<dist[i]<<endl;
    }
}

Measured memory_bytes: 1024
S = input()

foward = int(S[0 : 2])
back = int(S[2 : 4])

foward_MM = False
back_MM = False

if foward >= 1 and foward <= 12:
  foward_MM = True
if back >= 1 and back <= 12:
  back_MM = True

if foward_MM and back_MM:
  print("AMBIGUOUS")
elif foward_MM and not back_MM:
  print("MMYY")
elif not foward_MM and back_MM:
  print("YYMM")
else:
  print("NA")

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

using namespace std;

const int maxn = 1000007;

int frog[maxn];
int height[maxn];

int main()
{
    int n,k;
    cin >> n >> k;
    n--;
    for(int i = 0;i<=n;i++)
        cin >> height[i];

    frog[0] = 0;
    frog[1] = abs(height[0] - height[1]);
    for(int i = 2;i<k;i++)
    {
        int y = frog[0] + abs(height[0]-height[i]);
        for(int j = 1;j < i;j++)
        {
            int x = frog[j] + abs(height[j] - height[i]);
            if(x < y)
                y = x;
        }
        frog[i] = y;
    }

    for(int i = k;i<=n;i++)
    {
        int u = frog[i-k] + abs(height[i-k]-height[i]);
        for(int j = i-k;j<i;j++)
        {
            int v = frog[j] + abs(height[j]-height[i]);
            if(v < u)
              u = v;
        }
        frog[i] = u;
    }
    cout << frog[n];

}


Measured memory_bytes: 4736
/*
Problem:Zero-Sum Ranges (atcoder AGC023A)
Algorithm:
Status:
*/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <utility>
#include <list>
#include <ctime>
#include <memory.h>
#include <stack>
#include <stdio.h>
#include <string.h>

using namespace std;

const int INF=1e9+7;

map<long long,int> mp;
int n;

int main()
{
	scanf("%d",&n);
	mp[0]++;
	long long ans=0;
	long long sum=0;
	for(int i=0;i<n;i++){
		long long tmp;
		scanf("%lld",&tmp);
		sum+=tmp;
		ans+=mp[sum];
		mp[sum]++;
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


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

ll mypow(ll b, ll e) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t = mypow(b,e/2);
    return t*t;
  } else {
    return b*mypow(b,e-1);
  }
}

int main() {
  ll d,n; cin >> d >> n;
  if(n==100) {
    cout << mypow(100,d)*(n+1) << endl;
  } else {
    cout << mypow(100,d)*n << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,int> P;

struct point{
  ll x,y;  
  point operator + (const point &p)const{
    return (point){x+p.x,y+p.y};
  }
  point operator - (const point &p)const{
    return (point){x-p.x,y-p.y};
  }
  point operator * (const ll r)const{
    return (point){x*r,y*r};
  }
  bool operator < (const point &p)const{
    return (x==p.x?y<p.y:x<p.x);
  }
};

ll dot(point a,point b){
  return a.x*b.x+a.y*b.y;
}
ll norm(point a){
  return dot(a,a);
}
ll cross(point a,point b){
  return a.x*b.y-b.x*a.y;
}

int ccw(point a,point b,point c){
  if(cross(b-a,c-a)>0)return 1;//ccw
  if(cross(b-a,c-a)<0)return -1;//cw
  if(dot(b-a,c-a)<0)return 2;//back
  if(norm(b-a)<norm(c-a))return -2;//front
  return 0;//on
}

bool isIntersect(point a,point b,point c,point d){
  return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}

double solve(vector<point> &t,int n,point sp,point tp){
  vector<double> d(n,1e20);
  d[0]=0;
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push(P(0,0));
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int pos=p.second;
    double cost=p.first;
    if(d[pos]<cost)continue;
    for(int to=0;to<n;to++){
      if(to==pos || isIntersect(t[pos],t[to],sp,tp))continue;
      double ncost = cost + sqrt(norm(t[pos]-t[to]));
      if(ncost<d[to]){
        d[to]=ncost;
        Q.push(P(ncost,to));
      }
    }
  }  
  return d[1]+sqrt(norm(sp-tp));
  
}

int a,b;
vector<point> A,B;

int main(){
  cin>>a>>b;
  A.resize(a);
  B.resize(b);
  for(int i=0;i<a;i++)cin>>A[i].x>>A[i].y;
  for(int i=0;i<b;i++)cin>>B[i].x>>B[i].y;
  double ans;  
  if( isIntersect( A[0],A[1],B[0],B[1] ) ){
    ans=min(solve(A,a,B[0],B[1]),solve(B,b,A[0],A[1]));    
  }else{
    ans=sqrt(norm(A[0]-A[1]))+sqrt(norm(B[0]-B[1]));
  }
  if(ans>=1e19){
    printf("-1\n");
  }else{
    printf("%.10f\n",ans);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

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

	int n;
	cin >> n;

	vi vec(n);
	rep(i, 0, n)
		cin >> vec[i];

	int mn = vec.back();
	vi hoba(n, -1);

	for(int i = n - 2; i >= 0; i--)
	{
		hoba[i] = mn;
		mn = min(mn, vec[i]);
	}

	rep(i, 0, n - 1)
	{
		if (hoba[i] - vec[i] >= -1)
			continue;
		return cout << "No", 0;
	}
	cout << "Yes\n";

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#define N 200000 

int main(void){
int Rt[N], RMAX = 0, RANS = 0, R;
int n, s;
int i, j, k = -1;

scanf("%d",&n);
for(i = 0; i < n; i++){
scanf("%d", &s);
Rt[i] = s;
}	
	RANS = Rt[1] - Rt[0];
for( i = 0; i < n-1; i++){
	RMAX = Rt[i + 1];
		if (k < i){
for( j = i + 1; j < n; j++){
	if( Rt[j] > RMAX) {
		RMAX = Rt[j];
		k = j;
}
		}
		}
			else RMAX = Rt[k];
	R = RMAX - Rt[i] ;
	if(RANS < R)RANS = R;
}
printf("%d\n", RANS);



return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N;
  int a[100100];

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    --a[i];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (a[a[i]] == i) ++ans;
  }

  cout << ans/2 << endl;

  return 0;
}



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

int dist[2001][2001];

int main() {
	int n,x,y;
	map<int,int> mp;
	
	cin>>n>>x>>y;
	
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			dist[i][j] = dist[j][i] = abs(j-i);
		}
	}
	
	for(int i=1;i<=n;i++){
		dist[i][x] = dist[x][i] = min(dist[i][x],1+dist[i][y]);
	}
	
	for(int i=1;i<=n;i++){
		dist[i][y] = dist[y][i] = min(dist[i][y],1+dist[i][x]);
	}
	
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=n;j++){
	        dist[i][j] = dist[j][i] = min(dist[i][j],min(dist[i][x]+dist[x][j],dist[i][y]+dist[y][j]));
	    }
	}
	
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			int d = dist[i][j];
			
			if(mp.find(d)==mp.end()) mp[d] = 1;
			else mp[d]+=1;
		}
	}
	
	for(int i=1;i<n;i++){
		if(mp.find(i)==mp.end()) cout<<0<<endl;
		else cout<<mp[i]<<endl;
	}
	
	return 0;
	
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
template<class T>bool CHMAX(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool CHMIN(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll prime_fac(ll n, vector<pair<ll, ll>>&l){
  ll r, s = floor(sqrt(n));
  pair<ll,ll> x;
  for (ll i=2; i<=s; i++) {
    if(n%i == 0){
      r = 0;
      do {
        r++;
        n /= i;
      } while(n%i == 0);
      x = make_pair(i, r);
      l.push_back(x);
    }
  }
  if(n > s){
    x = make_pair(n, 1);
    l.push_back(x);
  }
  return l.size();
}

ll counter(ll n){
  ll ans = 0;
  for(ll i=1; i<=n; i++) { n-=i; ans++; }
  return ans;
}

int main(){
  IOS;

  ll n; cin >> n;
  vector<pair<ll,ll>> l;
  prime_fac(n, l);

  ll ans = 0;
  for (pair<ll,ll>x: l) ans += counter(x.second);
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    ll N, M;
    cin >> N >> M;
    vector<vector<string>> p(N + 1);
    for (int i = 1; i <= M; i++){
        ll question;
        string result;
        cin >> question >> result;
        p[question].pb(result);
    }

    ll ac = 0, wa = 0;
    for (int i = 1; i <= N; i++){
        if(!p[i].empty()){
            vector<string> res = p[i];
            ll w = 0;
            bool a = false;
            for(string result : res){
                if(result == "WA"){
                    w++;
                }else if(result == "AC"){
                    a = true;
                    break;
                }
            }
            if(a){
                wa += w;
                ac++;
            }
        }
    }

    cout << ac << " " << wa << endl;

    return 0;
}


Measured memory_bytes: 10368
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;

int gcd( int m, int n ){
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;
  // ユークリッドの方法
  while( m != n ){
    if ( m > n ) m = m % n;
    else         n = n % m;
  }
  return m;
}//gcd


int main()
{
  long x,y; //かっている数//最大100
  cin >> x >> y;

  if (x==y){
      cout << "-1";
      return 0;
  }

  for (int i = 1; i < y; ++i){
    if (x * i %y !=0){
      cout << x*i;
      return 0;
    }
  }

  cout << "-1";

  return 0;
}



























Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b=list(set(a))
m=len(b)

p=[0]*(10**6+1)
for i in b:
    if p[i]==0:
        j=2
        while i*j<=10**6:
            p[i*j]=1
            j+=1
a.append(-1)
a.insert(0,-1)
ans=0
for i in range(1,n+1):
    if a[i]!=a[i+1] and a[i]!=a[i-1] and p[a[i]]==0:
        ans+=1
print(ans)


Measured memory_bytes: 32572
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 101;

short f[MAX][MAX][MAX][MAX];
short prefR[MAX][MAX];
short prefC[MAX][MAX];

int main(void) {
  ios_base::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;

  vector<string> a(H);
  REP(i, H) cin >> a[i];

  REP(i, H) {
    prefR[i][0] = 0;
    REP(j, W) prefR[i][j + 1] = prefR[i][j] + (a[i][j] == 'o');
  }

  REP(i, W) {
    prefC[i][0] = 0;
    REP(j, H) prefC[i][j + 1] = prefC[i][j] + (a[j][i] == 'o');
  }

  int xe = -1, ye = -1;
  REP(i, H) REP(j, W) if (a[i][j] == 'E') xe = i, ye = j;

  for (int x1 = H - 1; x1 >= 0; --x1) {
    for (int x2 = x1; x2 < H; ++x2) {
      for (int y1 = W - 1; y1 >= 0; --y1) {
        for (int y2 = y1; y2 < W; ++y2) {
          if (x1 == x2 && y1 == y2) {
            f[x1][x2][y1][y2] = a[x1][y1] == 'o';
          }

          int h = x2 - x1 + 1;
          int w = y2 - y1 + 1;

          int r1 = x1 + max(0, h - 1 - (H - 1 - xe));
          int c1 = y1 + max(0, w - 1 - (W - 1 - ye));
          int r2 = x1 + min(h - 1, xe);
          int c2 = y1 + min(w - 1, ye);
          if (h > 1) {
            {
              short score = f[x1 + 1][x2][y1][y2];
              if (r1 <= r2 && r1 == x1 && c1 <= c2) {
                score += prefR[x1][c2 + 1] - prefR[x1][c1];
              }
              f[x1][x2][y1][y2] = max(f[x1][x2][y1][y2], score);
            }
            {
              short score = f[x1][x2 - 1][y1][y2];
              if (r1 <= r2 && r2 == x2 && c1 <= c2) {
                score += prefR[x2][c2 + 1] - prefR[x2][c1];
              }
              f[x1][x2][y1][y2] = max(f[x1][x2][y1][y2], score);
            }
          }

          if (w > 1) {
            {
              short score = f[x1][x2][y1 + 1][y2];
              if (r1 <= r2 && c1 == y1 && c1 <= c2) {
                score += prefC[y1][r2 + 1] - prefC[y1][r1];
              }
              f[x1][x2][y1][y2] = max(f[x1][x2][y1][y2], score);
            }
            {
              short score = f[x1][x2][y1][y2 - 1];
              if (r1 <= r2 && c2 == y2 && c1 <= c2) {
                score += prefC[y2][r2 + 1] - prefC[y2][r1];
              }
              f[x1][x2][y1][y2] = max(f[x1][x2][y1][y2], score);
            }
          }
        }
      }
    }
  }

  cout << f[0][H - 1][0][W - 1] << "\n";
  return 0;
}


Measured memory_bytes: 203008
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll

int n,m;
string s[1000];
int r,t;

signed main(){
  cin>>n>>m;
  rep(i,n){
    cin>>s[i];
  }

  rep(i,n){
    rep(j,m){
      if(s[i][j]=='.') r++;
      else t++;
    }
  }

  queue<P> q;
  q.push(P(0,0));
  int c[1000][1000];
  rep(i,1000){
    rep(j,1000){
      c[i][j]=inf;
    }
  }
  c[0][0]=0;
  while(q.size()){
    int a=q.front().F;
    int b=q.front().S;
    q.pop();
    rep(i,4){
      int x=a+vx[i];
      int y=b+vy[i];
      if(!(0<=x&&x<m&&0<=y&&y<n))continue;
      if(s[y][x]=='#') continue;
      if(c[y][x]>c[b][a]+1){
        c[y][x] = c[b][a]+1;
        q.push(P(x,y));
      }
    }
  }

  if(c[n-1][m-1]==inf){
    cout<<-1<<endl;
    return 0;
  }

  cout<<r-1-c[n-1][m-1]<<endl;
}

Measured memory_bytes: 8064
from collections import deque

N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
for a in range(K + 1):
    for b in range(K + 1 - a):
        if a + b > N:
            continue

        q = deque(X)
        tmp = []
        for _ in range(a):
            tmp.append(q.popleft())

        for _ in range(b):
            tmp.append(q.pop())

        tmp.sort(reverse=True)
        cnt = 0
        for _ in range(K - a - b):
            if tmp and tmp[-1] < 0:
                tmp.pop()

        ans = max(ans, sum(tmp))

print(ans)


Measured memory_bytes: 74720
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

def spin(l):
    '''
    return right sppined list

    l : string list
    '''

    i = -1
    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]

    return res
def has_same_faces(a, b):
    '''
    check if all elements of a are equel to those of b.
    a : string list
    b : string list
    '''
    return set(a) == set(b)

def is_identical_lists(a, b):
    for x, y in zip(a, b):
        if x != y:
            return False

    return True

def check_two_dice(a, b):
    if not has_same_faces(a, b):
        return False
    
    orig_a = a[:]

    #roll and spin to check
    for i in range(6):
        if 1 <= i <= 3:
            a = roll(a, "N")
        elif i == 4:
            pass
            a = orig_a[:]
            a = roll(a, "W")
        elif i == 5:
            a = orig_a[:]
            a = roll(a, "E")

        # spin 4 times
        for _ in range(4): #spin 3 times
            a = spin(a)
            if is_identical_lists(a, b):
                return True
        
    return False

def check_all_different(dice):
    '''
    if all dice are different, return True

    dice : string list

    '''
    for i in range(len(dice)):
        if i == 0:
            continue
        for j in range(i):
            res = check_two_dice(dice[i], dice[j])

            if res:
                return False
    
    return True


if __name__ == "__main__":
    res = False
    n = int(input())
    dice = []
    for _ in range(n): 
        dice.append(input().split())

    res = check_all_different(dice)

    print("Yes") if res else print("No")





Measured memory_bytes: 5632
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func unset(s []int, i int) []int {
	if i >= len(s) {
		return s
	}
	return append(s[:i], s[i+1:]...)
}

func nearZero(s []int) int {
	min := math.Abs(float64(s[0]))
	minIdx := 0
	for i := 0; i < len(s); i++ {
		if math.Abs(float64(s[i])) > min {
			break
		}
		if math.Abs(float64(s[i])) < min {
			min = math.Abs(float64(s[i]))
			minIdx = i
		}
	}
	return minIdx
}

func main() {
	nl := strings.Fields(nextLine())
	n, _ := strconv.Atoi(nl[0])
	l, _ := strconv.Atoi(nl[1])
	apples := make([]int, n)
	for i := 1; i <= n; i++ {
		apples[i-1] = l + i - 1
	}
	sort.Ints(apples)
	if apples[0] >= 0 && apples[n-1] >= 0 {
		apples = unset(apples, 0)
	} else if apples[0] < 0 && apples[n-1] >= 0 {
		apples = unset(apples, nearZero(apples))
	} else {
		apples = unset(apples, n-1)
	}
	answer := 0
	for i := range apples {
		answer += apples[i]
	}
	fmt.Println(answer)
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a,b;
    a=sc.nextInt();
    b=sc.nextInt();
    int n=0;
    if(a<b){
      for(int i=0;i<b;i++){
        if(i-a==b-i){
          n=i;
          break;
        }
      }
    }else{
      for(int i=0;i<a;i++){
        if(a-i==i-b){
          n=i;
          break;
        }
      }
    }
    if(n!=0){
      System.out.println(n);
    }else{
      System.out.println("IMPOSSIBLE");
    }
  }
}


Measured memory_bytes: 22356
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

void makePrimes( int limit, vector<int> & primes ) {

  vector<bool> isPrime( limit + 1 );
  fill( isPrime.begin(), isPrime.end(), true );
  isPrime[ 0 ] = isPrime[ 1 ] = false;
  const int loopMax = (int)sqrt( limit );
  for ( int i = 2; i <= loopMax; i++ ) {
	if ( isPrime[ i ] ) {
	  for ( int j = i * i; j <= limit; j += i ) {
		isPrime[ j ] = false;
	  }
	}
  }
  for ( int i = 2; i <= limit; i++ ) {
	if ( isPrime[ i ] ) {
	  primes.push_back( i );
	}
  }
}

int main() {
  vector<int> primes;
  makePrimes( 10000, primes );
  const int size = primes.size();
  
  vector<int> cum( size );
  vector<int> count( 10001 );

  int sum = 0;
  for ( int i = 0; i <= size; i++ ) {
	cum[ i ] = sum;
	sum += primes[ i ];
  }
  
  fill( count.begin(), count.end(), 0 );
  for ( int i = 0; i <= size; i++ ) {
	for ( int j = i + 1; j <= size; j++ ) {
	  const int n = cum[ j ] - cum[ i ];
	  if ( n <= 10000 ) {
		count[ n ]++;
	  }
	}
  }
  
  while ( true ) {
	int n;
	cin >> n;
	if ( n == 0 ) break;
	cout << count[ n ] << endl;
  }  
}

Measured memory_bytes: 1276
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		char[] A = sc.next().toCharArray();
		int N = A.length;
		int[] cnt = new int[26];
		for(int i=0; i<N; i++)
			cnt[A[i]-'a']++;
		
		long ans = (long)N*(N+1)/2+1;
		for(int i=0; i<26; i++)
			if(cnt[i]>0)
				ans -= (long)cnt[i]*(cnt[i]+1)/2;
		
		System.out.println(ans);
		
		sc.close();
	}
}


Measured memory_bytes: 26576
n, m = map(int, input().split())
a = list(map(lambda x: x % m, map(int, input().split())))

b = [0]
s = 0
for i in range(n):
  s = (s + a[i]) % m
  b.append(s)

mods = {}

ans = 0
for i in range(n+1):
  if b[i] in mods.keys():
    ans += mods[b[i]]
    mods[b[i]] += 1
  else:
    mods[b[i]] = 1
  
print(ans)

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

int main() {
    int a,b;
    char op;
    std::cin >> a >> op >> b;
    if(op=='+'){
        std::cout << a+b << std::endl;
    }
    else{
        std::cout << a-b << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t

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

    vector<int> Ai;
    double sum = 0.0;
    rep(i,N){
       int ai;
       cin >> ai;
       Ai.push_back(ai);
       sum += ai;
    }

    double ave = sum / N;
    int ans = 0;
    double min = abs(Ai.at(0) - ave);

    rep(i,N){
       double diff = abs(Ai.at(i) - ave);
       if(min > diff){
         ans = i;
         min = diff;
       }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#bitDP(再帰使用)
#forの組合せでやろうとすると男性の集合/女性の集合を分けるのが難しい

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    N = int(input())
    a = [list(map(int, input().split())) for _ in range(N)]

    #dp[s]：sは既に使った女性をbitで表していて、
    #          dp[s]は残りの男女の組合せの場合の数
    dp = [-1]*(1<<N)
    #全員相手が見つかった状態
    dp[-1] = 1

    #numは今見ている男性
    def dfs(s, num):
        #既にその状態を調べ終わっているなら返す
        if dp[s] != -1:
            return dp[s]

        #resは状態(s, num)において考えられる場合の数で
        #for文で全ての女性について考えて足している
        res = 0

        #状態sにおいて, 男性numと全ての女性とのマッチングを考える
        for i in range(N):
            #i番目の女性がまだ使っていなくて, 今見ている男性と相性が良い時
            if(s >> i) & 1 == 0 and a[num][i] == 1:
                #sを更新して, 次の男性について調べる
                #次の状態が既に調べ終わっていたらその場合の数が足される
                res += dfs(s+(1<<i), num+1)
        dp[s] = res % mod
        return dp[s]

    print(dfs(0, 0))

if __name__ == '__main__':
    main()

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

using namespace std;

typedef unsigned long long ull;

const int N = 128;

int data[N], cnt, sum;
ull f[21];
string str;

main(){
  cin >> str;
  fill(data, data+N, 0);
  for(int i=0;i<str.size();i++) data[str[i]]++;
  cnt = sum = 0;
  for(int i=0;i<N;i++){
    if(data[i] % 2) cnt++;
    data[i] /= 2;
    sum += data[i];
  }
  ull ans;
  if(cnt > 1) ans = 0;
  else{
    f[0] = 1;
    for(int i=1;i<21;i++) f[i] = f[i-1] * i;
    ans = f[sum];
    for(int i=0;i<N;i++) ans /= f[data[i]];
  }
  cout << ans << endl;
}

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

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

typedef unsigned int uint;

int main() {
	int n, m, a, ans;
	vector<int> p, p2;
	while(1) {
		cin >> n >> m;
		if(!n&&!m) break;
		p.clear(); p2.clear(); ans = 0;
		for(int i=0; i<n; ++i) {
			cin >> a;
			p.push_back(a); p2.push_back(a);
		}
		for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) {
				if(p2[i]+p2[j]<=m) p.push_back(p2[i]+p2[j]);
		}
		p.push_back(0);
		sort(p.begin(), p.end());
		for(uint i=0; i<p.size(); ++i) {
			vector<int>::iterator it = --lower_bound(p.begin(), p.end(), m-p[i]);
			ans = max(ans, *it+p[i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 7312
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
sum_a = sum(a)
ret = "No"
cnt = 0
for i in a:
    if i >= (sum_a/(4*m)):
        cnt+=1

if cnt >= m:
    ret ="Yes"
print(ret)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define itn int
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}
ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}
int n,k;
int main(){	
	//freopen("in.txt","r",stdin);
	cin>>n>>k;
	int N=(n-1)*(n-2)/2;
	if(k>N)return o(-1);
	o(N-k+n-1);
	int cnt=N-k;
	for(int i=1;i<n;i++)cout<<i<<" "<<n<<endl;
	for(int i=1;i<n;i++)
	for(int j=i+1;j<n;j++){
		if(cnt>0){
			cout<<i<<" "<<j<<endl;
			cnt--;
		}
	}
}


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

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> vec(6);
    rep(i, H){
        
            cin >> vec.at(i);
      
    }
    auto vec_sec=vec;
    int count=0;
    int answer=0;
    rep(tmp, (1<<7)){
        bitset<7> xs(tmp);
        if(xs.test(H)){
            break;
        }
        rep(tm,(1<<7)){
            bitset<7> ys(tm);
            if(ys.test(W)){
                break;
            }
            vec_sec=vec;
            count =0;
            rep(i,H){
                if(xs.test(i)){
                    rep(j,W){
                        vec_sec.at(i).at(j)='0';
                    }
                
                }
            }

            rep(i,W){
                if(ys.test(i)){
                    rep(j,H){
                        vec_sec.at(j).at(i)='0';
                    }
                }
            }

            rep(i,H){
                rep(j,W){
                    if(vec_sec.at(i).at(j)=='#'){
                        count++;
                    }
                }
            }
            
            if(count==K){
                answer++;
            }
        }
        
    }
SKIP:
cout << answer << endl;


}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize("O3") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
#define __USE_MINGW_ANSI_STDIO 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include<stdio.h>
#include<iomanip>
#include<set>
#include<string>
#include<map>
#include <math.h>
#include<queue>
#include<complex>
#include<ctime>
#include<list>
#include<stack>
#define ll  long long
#define lll __int128
#define fi first
#define ld long double
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<vector<int>>
using namespace std;
ll n;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
    cin >> n;
    ll q = n;
    ll ans =0 ;
    for(ll i = 2 ;i *i <= n;i++)
        if(q % i == 0){
            int cnt =0 ;
            while(q % i ==0){
                cnt++;
                q/=i;
            }
      //      cout << i <<" "<< cnt <<" "<< ans <<"\n";
            for(int i =1 ;i <= cnt;cnt-=i,i++)
                ans++;
        }
    if(q != 1)
        ans++;
    cout << ans;
  return  0;    
}

Measured memory_bytes: 3184
from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

Measured memory_bytes: 27048
package main

import (
        "fmt"
)

func main() {
        ret := "No"
        A := make([][]int, 3, 3)
        P := make([][]bool, 3, 3)
        for i := range A {
                A[i] = make([]int, 3, 3)
                P[i] = make([]bool, 3, 3)
                fmt.Scanf("%d %d %d\n", &(A[i][0]), &(A[i][1]), &(A[i][2]))
        }
        var N int
        fmt.Scanf("%d\n", &N)
        for i := 0; i < N; i++ {
                var x int
                fmt.Scanf("%d\n", &x)
                for i := range A {
                        for j := range A[i] {
                                if A[i][j] == x {
                                        P[i][j] = true
                                }
                        }
                }
        }
        for i := range P {
                if P[i][0] && P[i][1] && P[i][2] {
                        ret = "Yes"
                        break
                }
                if P[0][i] && P[1][i] && P[2][i] {
                        ret = "Yes"
                        break
                }
        }
        if P[0][0] && P[1][1] && P[2][2] {
                ret = "Yes"
        }
        if P[0][2] && P[1][1] && P[2][0] {
                ret = "Yes"
        }
        fmt.Println(ret)

}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define pb push_back
#define int long long
#define mod (int)(1e9 + 7)
using namespace std;
typedef pair<int,int> pii;

signed main(){
  int n,k;

  cin>>n>>k;

  int t;
  vector<int> a;
  for(int i=0;i<n;i++){
    cin>>t;
    a.pb(t);
  }

  int res=0;
  for(int i=0;i<a.size();i++){
    t=a[i];
    int l,r;
    l=r=0;
    for(int j=0;j<i;j++){
      if(a[j]<t) l++;
    }
    for(int j=i+1;j<a.size();j++){
      if(a[j]<t) r++;
    }

    //printf("%d :%d %d\n",i,l,r);

    if(k%2==0) res+=(((r*(k/2LL))%mod)*(k+1LL))%mod;
    else res+=(((r*((k+1LL)/2LL))%mod)*(k))%mod;
    res%=mod;
    k--;
    if(k%2==0) res+=(((l*(k/2LL))%mod)*(k+1LL))%mod;
    else res+=(((l*((k+1LL)/2LL))%mod)*(k))%mod;
    k++;
    res%=mod;
  }
  cout<<res<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

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

	int a[4][3][10] = {};
	for (int i = 0; i < n; i++) {
		int b, f, r, v;
		cin >> b >> f >> r >> v;
		a[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << " " << a[i][j][k];
			}
			cout << endl;
		}
		if (i < 3) cout << "####################" << endl;
	}

	return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N; cin >> N;
	int _N = N;
	vector<ll> a(N), b(N);
	rep(i, N) cin >> a[i] >> b[i];
	if (N % 2 == 0) {
		N++;
		a.pb(0);
		b.pb(0);
	}
	vector<pair<ll, ll_ll> > p(N);
	rep(i, N) p[i] = make_pair(a[i] + b[i], i_i(a[i], b[i]));
	sort(p.begin(), p.end());
	rep(i, N) a[i] = p[i].second.first, b[i] = p[i].second.second;
	int n = N / 2;
	if (_N % 2 == 0 || _N <= 10) {
		ll ans = n * (a[0] + b[0]);
		vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
		dp[0][0] = ans;
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= n; j++) {
				ll l = a[i + j + 1], r = b[i + j + 1];
				if (i < n) {
					ll x = dp[i][j] + r + (n - i - 1) * (l + r);
					dp[i + 1][j] = min(dp[i + 1][j], x);
				}
				if (j < n) {
					ll x = dp[i][j] + l + (n - j - 1) * (l + r);
					dp[i][j + 1] = min(dp[i][j + 1], x);
				}
			}
		cout << dp[n][n] << endl;
		return 0;
	}
	ll unko = LLONG_MAX;
	rep(t, 10) {
		ll ans = n * (a[0] + b[0]);
		vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
		dp[0][0] = ans;
		for (int i = 0; i <= n; i++)
			for (int j = 0; j <= n; j++) {
				ll l = a[i + j + 1], r = b[i + j + 1];
				if (i < n) {
					ll x = dp[i][j] + r + (n - i - 1) * (l + r);
					dp[i + 1][j] = min(dp[i + 1][j], x);
				}
				if (j < n) {
					ll x = dp[i][j] + l + (n - j - 1) * (l + r);
					dp[i][j + 1] = min(dp[i][j + 1], x);
				}
			}
		unko = min(unko, dp[n][n]);
		vector<pair<ll, ll_ll> > _p = p;
		swap(_p[0], _p[t + 1]);
		sort(_p.begin() + 1, _p.end());
		rep(i, N) a[i] = _p[i].second.first, b[i] = _p[i].second.second;
	}
	cout << unko << endl;
}


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

int main() {
  int64_t n;
  cin >> n;
  int p=1;
  for(int i=2;i<int(sqrt(n))+1;i++){
    if(n%i==0){
      p=i;
    }
  }
  cout<<p+n/p-2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb(x) push_back(x)
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
const int MAXN = 1024;

//OPERATORS


//GLOBALS


//FUNCTIONS


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b; cin >> a >> b ;
	
	for(double i = 0; i <= 2000; i++){
		if(floor(i * 0.08) == a and floor(i*0.1) == b){
			
			cout << i << endl;
			return 0;		
		}
	}
	cout << -1 << endl;



	return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, K, Q, i, j, k, l, tmp, ans;

int main(){
    string s;
    cin >> N;
    while(N > 0){
        N -= 1;
        s.push_back((char)('a' + N % 26));
        N /= 26;
    }
    reverse(ALL(s));
    cout << s;
    return 0;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline

N=int(input())
C=[]
for i in range(N):
    A=int(input())
    B=[tuple(map(int,input().split())) for i in range(A)]
    C.append(B)

ANS=0

for i in range(1<<N):
    HONEST=[j for j in range(N) if 1<<j & i !=0]

    #print(i,HONEST)

    flag=1

    for h in HONEST:
        for p,k in C[h]:
            if k==1:
                if p-1 in HONEST:
                    continue
                else:
                    flag=0
                    break

            else:
                if p-1 in HONEST:
                    flag=0
                    break
        if flag==0:
            break

    if flag==1:
        #print(i,HONEST)
        ANS=max(ANS,len(HONEST))

print(ANS)
                    
                
            


Measured memory_bytes: 47980
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	int R, G;
	cin >> R >> G;

	cout << 2 * G - R << endl;

}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
int find(int a){
     if(par[a]==a)return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);if(a==b)return ;
     parent[b]=a;
}*/
 
 
 
 
 
 
 












int main(){
     ll n,W;
     cin>>n>>W;
     vector<ll> val[4];
     vector<ll> pre[4];
     ll w[n],v[n];
     ll s; 
     ll mx=0LL;
     for(int i=0;i<n;i++){
          ll x,y;cin>>x>>y;
          if(i==0){
               val[0].pb(y);s=x;
          }
          else{
               val[x-s].pb(y);
          }
     }
     for(int i=0;i<4;i++){
          sort(val[i].rbegin(),val[i].rend());
     }
     for(int i=0;i<4;i++){
          pre[i].resize(val[i].size()+1,0);
          for(int j=0;j<val[i].size();j++){
               pre[i][j+1]=pre[i][j]+val[i][j];
          }
     }
     //cout<<s<<"\n";
     for(int i=0;i<=val[0].size();i++){
          for(int j=0;j<=val[1].size();j++){
               for(int k=0;k<=val[2].size();k++){
                    for(int z=0;z<=val[3].size();z++){
                         ll total=i*s+j*(s+1)+k*(s+2)+z*(s+3);
                         //cout<<i<<" "<<j<<" "<<k<<" "<<z<<" "<<total<<"\n";
                         if(total<=W){
                              ll totval=pre[0][i]+pre[1][j]+pre[2][k]+pre[3][z];
                              mx=max(mx,totval);
                         }
                    }
               }
          }
     }
     cout<<mx;
     

     
}


























Measured memory_bytes: 3596
import java.util.*;
public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			int a[]=new int [n];
			int b[]=new int [n];
			int count=0;
			if(n==0)break;
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
				b[i]=a[i];

			}
			Arrays.sort(b);
			while(!judge(a,b)){
				for(int i=1;i<a.length;i++){
					//System.err.println(count);
					int temp=0;
					if(a[i-1]>a[i]){
						temp=a[i];
						a[i]=a[i-1];
						a[i-1]=temp;
						count++;
					}
				}
			}
			 System.out.println(count);
		}

	}

	static boolean judge(int a[],int b[]){
		boolean judge=true;
		for(int i=0;i<a.length;i++){
			if(a[i]!=b[i]){
				judge=false;
			}
		}
		if(judge){
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 21764
#include <stdio.h>
#include <string.h>

int route[128][128];
int ng[128][128];

int countWay(int nx, int ny)
{
	if (ng[ny][nx] || nx <= 0 || ny <= 0){
		return (0);
	}
	
	if (nx == 1 && ny == 1){
		return (1);
	}
	if (route[ny][nx] >= 0){
		return (route[ny][nx]);
	}
	
	return (route[ny][nx] = countWay(nx, ny - 1) + countWay(nx - 1, ny));
}

int main(void)
{
	int x, y;
	int i;
	int n;
	
	while (1){
		
		scanf("%d %d", &x, &y);
		
		if (x == 0 && y == 0){
			break;
		}
		
		scanf("%d", &n);
		
		memset(ng, 0, sizeof(ng));
		
		for (i = 0; i < n; i++){
			int nx, ny;
			scanf("%d %d", &nx, &ny);
			ng[ny][nx] = 1;
		}
		
		memset(route, -1, sizeof(route));
		
		printf("%d\n", countWay(x, y));
	}
	
	return (0);
}

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

int main(){
    int vec[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> vec[i][j];
        }
        }

int a[3];
int b[3];

a[0]=0;
b[0]=vec[0][0];
b[1]=vec[0][1];
b[2]=vec[0][2];
a[1]=vec[1][0]-vec[0][0];
a[2]=vec[2][0]-vec[0][0];

for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
        if(vec[i][j]!=a[i]+b[j]){
            cout << "No" << endl;
            return 0;
        }
    }
}

cout << "Yes" << endl;
    }

Measured memory_bytes: 3624
#include<iostream>
#include<vector>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      vector<int> key;
      for(int i=0; i<n; i++){
         int k;
         cin>> k;
         key.push_back(k);
      }
      string s;
      cin>> s;
      while(key.size()<s.size()){
         for(int i=0; i<n; i++) key.push_back(key[i]);
      }

      vector<char> alp;
      for(char c='a'; c<='z'; c++) alp.push_back(c);
      for(char C='A'; C<='Z'; C++) alp.push_back(C);

      string answer;
      for(int i=0; i<s.size(); i++){
         char c=s[i];
         for(int j=0; j<alp.size(); j++){
            if(alp[j]==c){
               answer+=(alp[(j-key[i]+52)%52]);
            }
         }
      }
      
      cout<< answer<< endl;
   }

   return 0;
}

Measured memory_bytes: 3244
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define ll long long

int main(void){
  vector<int> a;
  for(int i = 0; i < 3; i++){
    a.push_back(0);
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if(a[0] + a[1] == a[2]) cout << "Yes\r\n";
  else cout << "No\r\n"; 

}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make([]int, n*3)
	var ans int64
	for i := 0; i < n*3; i++ {
		aa[i] = getNextInt(scanner)
	}
	sort.Ints(aa)
	for i := 0; i < n*2; i++ {
		if i%2 == 1 {
			ans += int64(aa[n*3-1-i])
		}

	}
	fmt.Println(ans)

	writer.Flush()
}


Measured memory_bytes: 6272