akhauriyash/Code-Regression huggingface dataset:
s = input()
abcd = [int(s[0]),int(s[1]),int(s[2]),int(s[3])]
mark = ['-','+']
for i in range(1 << 3):
    alla = abcd[0]
    i2 = format(i,'03b')
    for j in range(3):
        if i2[2 - j] == '0':#0 = -
            alla -= abcd[3 - j]
        else:
            alla += abcd[3 - j]
    if alla == 7:
        print(s[0] + mark[int(i2[0])] + s[1] + mark[int(i2[1])] + s[2] + mark[int(i2[2])] + s[3] + '=7')
        exit()


Measured memory_bytes: 3188
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    string str;
    cin >> N >> str;
    if (N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    string str1;
    string str2;
    for (int i = 0; i < N; i++) {
        if (i < N/2) {
            str1 += str[i];
        } else {
            str2 += str[i];
        }
    }

    if (str1 == str2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,m;
  cin>>N>>m;
 string S="";
  for(int i=0;i<N;i++){
    if(i==0)
      S+='1';
    else 
    S+='0';
  }
  map<int,char>M;
  bool ans=true;
  for(int i=0;i<m;i++){
    int s; char c;
    cin>>s>>c;
    if(!M.count(s-1))
      M[s-1]=c;
    else
    if(M.at(s-1)!=c){
     ans=false; break;
    }
   
  
  }if(!ans)
    cout<<-1<<endl;
  else{
  for(auto p:M){
  auto k=p.first;
    auto v=p.second;
    S.at(k)=M.at(k);
  }if(S.at(0)=='0'){
    if(N==1) cout<<0<<endl;
    else
    cout<<-1<<endl;
  }
    else{
      if(N==1 && !M.count(0))
        cout<<0<<endl;
      else
      cout<<S<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007

 

int main() {
	int N, T; cin >> N >> T;
	int min_cost = 1001;
	for (int i = 0; i < N; i++) {
		int c, t; cin >> c >> t;
		if (t <= T) {
			min_cost = min(min_cost, c);
		}
	}
	if (min_cost == 1001) {
		print("TLE");
	}
	else print(min_cost);




	return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;

struct node{
    vector<int> child;
    int parent;
    int depth;
};

node n[100000];

int main() {
    int v;
    cin >> v;
    REP(i, v){
        n[i].parent = -1;
        n[i].depth = 0;
    }
    REP(i, v){
        int x, children;
        cin >> x;
        cin >> children;
        REP(j, children){
            int y;
            cin >> y;
            n[x].child.push_back(y);
            n[y].parent = x;
        }
    }

    REP(i, v){
        node x = n[i];
        int count = 0;
        while(x.parent != -1){
            count++;
            x = n[x.parent];
        }
        n[i].depth = count;
    }

    REP(i, v){
        string str;
        if(n[i].depth == 0)
            str = "root";
        else if(n[i].child.empty())
            str = "leaf";
        else
            str = "internal node";
        cout << "node " << i << ": parent = " << n[i].parent << ", depth = " << n[i].depth << ", " << str << ", [";
        int j = 0;
        for(j; j+1 < n[i].child.size(); j++){
            cout << n[i].child[j] << ", ";
        }
        if(!n[i].child.empty())
            cout << n[i].child[j];
        cout << "]" << endl;
    }

    return 0;
}

Measured memory_bytes: 5128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#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 sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int N; cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  rep(i,N) cin >> A[i];
  rep(i,N) cin >> B[i];
  vector<int> C(N);
  rep(i,N) {
    C[(i+(N/2))%N]=B[i];
  }
  bool ok = true;
  rep(i,N){
    if(A[i]==C[i])ok =false;
  }
  if(ok){
    cout << "Yes" << endl;
    rep(i,N){
      if(i) cout << " ";
      cout << C[i];
    }
    cout << endl;
    return 0;
  }
  
  reverse(all(B));
  ok = true;
  rep(i,N){
    if(A[i]==B[i]) ok = false;
  }
  if(ok) {
    cout << "Yes" << endl;
    rep(i,N){
      if(i) cout << " ";
      cout << B[i];
    }
    cout << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int k;
    cin >> k;
    //if(b - a < k && c - b < k && d - c < k && e - d < k) cout << "Yay!" << endl;
    if( e - a <= k) cout  << "Yay!" << endl;
    else cout << ":(" << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  ll ans = 0;
  ll m = n/k;
  ans += m * m * m;
  if(k%2==0) {
    ll m = n/(k/2) - n/k;
    ans += m * m * m;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main(){
    int a,b;
    char op;
    while(1){
    scanf("%d %c %d",&a,&op,&b);
        if(op=='+')printf("%d\n",a+b);
        else if(op=='-')printf("%d\n",a-b);
        else if(op=='*')printf("%d\n",a*b);
        else if(op=='/')printf("%d\n",a/b);
        else if(op=='?')break;
    }
    return 0;
}


Measured memory_bytes: 2052
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,m,x;
	cin>>n>>m>>x;
	int count1=0,count2=0;
	for(int i=0;i<m;i++){
		int a;cin>>a;
		if(a<x){
			count1++;
		}
		else{
			count2++;
		}
	}
	cout<<min(count1,count2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
void solve1(int N) {
    if(400 <= N && N <= 599) cout << 8 << '\n';
    else if (600 <= N && N <= 799) cout << 7 << '\n';
    else if (800 <= N && N <= 999) cout << 6 << '\n';
    else if (1000 <= N && N <= 1199) cout << 5 << '\n';
    else if (1200 <= N && N <= 1399) cout << 4 << '\n';
    else if (1400 <= N && N <= 1599) cout << 3 << '\n';
    else if (1600 <= N && N <= 1799) cout << 2 << '\n';
    else if (1800 <= N && N <= 1999) cout << 1 << '\n';
}
void solve2(int N) {
    int ans = 10 - N / 200;
    cout << ans << '\n';
}
/* main */
int main(){
    int N;
    cin >> N;
    // solve1(N);
    solve2(N);
}

Measured memory_bytes: 3588
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstring>
using namespace std;
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}

const int MAXN=100002;
int n;
long long a[MAXN],ans=1,gc;

int main()
{
    read(n);
    for (int i=1;i<=n;++i)
    {
        read(a[i]);
        if(a[i]==0)
        {
            printf("0");
            return 0;
        }
    }
    for (int i=1;i<=n;++i)
    {
        ans*=a[i];
        if(ans>1000000000000000000ll||ans<gc) { printf("-1"); return 0; }
        gc=ans;
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 4472
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int list[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      list[i][j] = 0;
    }
  }
  int head,tail,number;
  for (int i = 1; i <= n; i++) {
    number = i;
    tail = number%10;
    while (number > 0) {
      head = number;
      number /= 10;
    }
    list[head][tail]++;
  }
  long answer = 0;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      answer += list[i][j]*list[j][i];
    }
  }
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n, a[123456], b[123456], c[123456];
int f(int a, int b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	if (a%b == 0)return b;
	else return f(b, a%b);
}
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> a[i];
	b[1] = a[1]; for (int i = 2; i <= n; i++)b[i] = f(b[i - 1], a[i]);
	c[n] = a[n]; for (int i = n - 1; i > 0; i--)c[i] = f(c[i + 1], a[i]);
	b[0] = c[2]; c[0] = b[2];
	b[n + 1] = c[n - 1]; b[n + 1] = c[n - 1];
	int ans = 1;
	for (int i = 1; i <= n; i++)ans = max(ans, f(b[i - 1], c[i + 1]));
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <algorithm>

using namespace std;

struct data {
	double value;
	double weight;
	double diff;
};

bool comp(struct data &a, struct data &b){
	return a.diff > b.diff;
}

struct data knap[100005];
int main() {
	int n, budget;
	double diff = 0;
	double a,b;
	
	scanf("%d %d", &n, &budget);
	for(int i=0; i<n; i++){
		scanf("%lf %lf", &a, &b);
		diff = a/b;
//		printf("t: %lf\n", diff);
		knap[i].value = a;
		knap[i].weight = b;
		knap[i].diff = diff;
	}
	
	sort(knap, knap + n, comp);
	
	
	int idx = 0;
	double total = 0;
	double res = 0;
	while(total <= budget && idx <= n){
		if(total + knap[idx].weight <= budget){
			total += knap[idx].weight;
			res += knap[idx].value;
			
		} else {
			res += (knap[idx].value)*((budget-total)/knap[idx].weight);
			break;
		}
		idx++;
	}
	printf("%lf\n", res);
}


Measured memory_bytes: 5048
h, w = map(int, input().split())
INF = 10**9
costs = [list(map(int, input().split())) for _ in range(10)]
for k in range(10):
    for j in range(10):
        for i in range(10):
            if costs[i][j] > costs[i][k] + costs[k][j]:
                costs[i][j] = costs[i][k] + costs[k][j]
opt_costs = [costs[i][1] for i in range(10)]
ans = 0
for _ in range(h):
    a = list(map(int, input().split()))
    for v in a:
        if v > -1:
            ans += opt_costs[v]
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int isPrime(int n){
    if(n==1){
        return 1;
    }
    for(int i=2;i<n;++i){
        if(n%i==0){
            return i;
        }
    }
    return n;
}
int fact(int n){
    int ans = 1;
    for(long long i = 1; i<= n; ++i){
        ans *= i;
    }
    return ans;
}


int main()
{
    const double pi = 3.14159265358979323846;
    long double a,b,h,m, hd, md,d,ans;
    cin>>a>>b>>h>>m;
    hd = h*30+(m/2);
    md = m*6;
    d = abs(hd-md);
    d = min(d, 360-d);
    ans  = (a*a+b*b)-(2*a*b*(cos(d*pi/180)));
    ans = sqrt(ans);
    cout.precision(20);
    cout<<ans<<endl;
}


Measured memory_bytes: 4144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long max = Long.MIN_VALUE;
		long min = Long.MAX_VALUE;
		for (int i=0;i<N;i++) {
			long temp = sc.nextLong();
			if (temp>max) {
				max = temp;
			}
			if (temp<min) {
				min = temp;
			}
		}
		System.out.println(max-min);
	}
}

Measured memory_bytes: 35860
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n; cin >> n;
    if(n >= 1000)
    {
        ll x = n / 1000;
        if(n % 1000 == 0)
        {
            cout << 0 << '\n';
        }
        else
        {
            x++;
            ll y = x * 1000;
            cout << y - n ;

        }
    }
    if(n < 1000)
    {
        cout << 1000 - n;
    }
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int r,s,p;

int winscore(char c){
  if(c == 'r') return p;
  if(c == 's') return r;
  if(c == 'p') return s;
}

int main(){
  
  int n,k;
  cin >>n>>k>>r>>s>>p;
  string T;
  cin >>T;
  
  int g;
  vector<string> sub(k);
  rep(i,n) sub[i%k].push_back(T[i]);
  
  int ans = 0;
  
  rep(i,k){
    rep(j,sub[i].size()){
      char now = sub[i][j];
      if(j == 0) ans += winscore(now);
      else if(j < sub[i].size()-1){
        if(now != sub[i][j-1]) ans += winscore(now);
        else sub[i][j] = '-';
      }
      else{
        if(now != sub[i][j-1]) ans += winscore(now);
      }
    }
  }
  cout << ans << endl;
}

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

unordered_map<int, unordered_map<int, long long>> E;
vector<int> V;

void dfs(int i){
    for(auto itr = E[i].begin(); itr != E[i].end(); ++itr){
        int k = itr->first;
        long long w = itr->second;
        if (V[k] >= 0) continue;
        if (w % 2 == 1) V[k] = 1 - V[i];
        else V[k] = V[i];
        dfs(k);
    }
}

int main(){
    int n;
    cin >> n;
    int u, v;
    long long w;
    for(int i = 0; i < n - 1; i++){
        cin >> u >> v >> w;
        E[u][v] = w;
        E[v][u] = w;
    }
    V.assign(n + 1, -1);
    V[1] = 0;
    dfs(1);
    for (int i = 1; i <= n; i++) cout << V[i] << endl;
}


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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m; b >>= 1;
    } return res;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

int h, n;
vector<pair<int, int>> arr(n);
getMat(dp, 1005, 10005, -1);

int res(int index, int curr) {
    if (curr >= h) {
        return 0;
    }
    if (index == n) {
        return INF;
    }
    if (dp[index][curr] != -1) {
        return dp[index][curr];
    }
    dp[index][curr] = min(res(index + 1, curr), res(index, curr + arr[index].first) + arr[index].second);
    return dp[index][curr];
}

int32_t main() { fastio;
    time_t start = now();

    cin >> h >> n;
    arr.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i].first >> arr[i].second;
    }
    cout << res(0, 0) << endl;

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

Measured memory_bytes: 79360
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

vector<int> ps;
// int func(int idx, int next, int mi, int ma){
//     if(idx == (int)ps.size() - 1){ return 0; }
//     if(ps[idx] < mi){
//         return func(idx + 1, next, mi, ma) + 1;
//     }
//     if(ps[idx] > ma){
//         return func(idx + 1, next, mi, ma) + 1;
//     }
//     // if(ps[idx] == next){
//     //     return func(idx + 1, next + 1, mi, ma);
//     // }
//     return min(
//                func(idx + 1, next, mi, ma) + 1
//                func(idx + 1, ps[idx] + 1, ps[idx], ma),
//                func(idx + 1, next, mi, ps[idx]) + 1
//               );
// }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ps.resize(n); cin >> ps;
    // cout << func(0, 1, -M, M) << '\n';
    vector<pair<int, int>> p2(n);
    for(int i = 0; i < n; i++){
        p2[i] = {ps[i], i};
    }
    sort(p2.begin(), p2.end());
    int ans = 1, cand = 0, prev = -1;
    prints(p2);
    for(int i = 0; i < n; i++){
        if(prev < p2[i].second){
            prev = p2[i].second;
            cand++;
        }else{
            ans = max(ans, cand);
            prev = p2[i].second;
            cand = 1;
        }
    }
    ans = max(ans, cand);
    ans = n - ans;
    // set<int> st;
    // int next = 1;
    // for(auto& p : ps){
    //     if(p != next){
    //         st.insert(p);
    //     }else{
    //         next++;
    //     }
    // }
    // int ans = M;
    // for(int i = 0; i <= n; i++){
    //     if(i >= *st.rbegin()){
    //         ans = min(ans, i);
    //         break;
    //     }
    //     prints(i, *st.upper_bound(i));
    //     ans = min(ans, i + n - *st.upper_bound(i) + 1);
    // }
    // for(int i = 0; i <= n; i++){
    //     int next = i + 1;
    //     int j = n;
    //     for(auto& p : ps){
    //         if(p > i && p != next){
    //             j = min(j, p);
    //         }else if(p == next){
    //             next++;
    //         }
    //     }
    //     ans = min(ans, i + n - j + 1);
    //     prints(i, j, ans, i + n - j + 1);
    // }
    cout << ans << '\n';
}


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

int r,w[2],h[2],x[2],y[2],l[2][500][500],temp[500][500]; vector<P> d[2];

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

void search(int n){
    for(int i=0;i<500;i++) for(int j=0;j<500;j++) temp[i][j]=0;
    priority_queue<P, vector<P>, greater<P> > q; d[n].push_back(P(0,0));
    q.push(P(l[n][y[n]][x[n]],x[n]*1000+y[n])); temp[y[n]][x[n]]=1;
    int res=0;
    while(!q.empty()){
        P z=q.top(),qq;
        while(qq=q.top(),qq.first<=z.first&&!q.empty()){
            q.pop(); int X=qq.second/1000,Y=qq.second%1000; res++;
            for(int k=0;k<4;k++){
                int i=X+dx[k],j=Y+dy[k];
                if(i<0||j<0||i>=w[n]||j>=h[n]) continue;
                if(temp[j][i]) continue;
                q.push(P(l[n][j][i],i*1000+j)); temp[j][i]=1;
            }
        }
        d[n].push_back(P(res,l[n][z.second%1000][z.second/1000]));
    }
}

P l_b(int m){
    int lb=-1,rb=d[1].size()-1;
    while(lb+1<rb){
        int mid=(lb+rb)/2;
        if(d[1][mid].first>=m) rb=mid;
        else lb=mid;
    }
    return d[1][rb];
}

int main(){
    while(scanf("%d",&r),r!=0){
        for(int i=0;i<2;i++){
            scanf("%d%d%d%d",&w[i],&h[i],&x[i],&y[i]); x[i]--; y[i]--;
            for(int j=0;j<h[i];j++) for(int k=0;k<w[i];k++) scanf("%d",&l[i][j][k]);
            search(i);
        }
        int res=INT_MAX;
        for(int i=0;i<d[0].size();i++){
            P p=l_b(r-d[0][i].first);
            if(p.first+d[0][i].first>=r) res=min(res,p.second+d[0][i].second);
        }
        printf("%d\n",res);
        d[0].erase(d[0].begin(),d[0].end());
        d[1].erase(d[1].begin(),d[1].end());
    }
}

Measured memory_bytes: 6696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define X first
#define Y second
ull mod=1e9+7;
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int	n,a[60]={0};
	ull s=0,fu=1;
	cin>>n;
	F(n){
		ull t,k=0;
		cin>>t;
		while(t>0){
			if(t&(ull)1)a[k]++;
			k++,t/=(ull)2;
		}
	}
	//F(60)cout<<a[i];
	//cout<<endl;
	F(60){
		//cout<<a[i]*(n-a[i])<<" "<<fu<<endl;
		if(a[i]!=0&&a[i]!=n)s=(s+(((ull)a[i]*(ull)(n-a[i])%mod)*(fu%mod)))%mod;
		fu=(fu*2)%mod;
	}
	cout<<s<<endl;
return 0;
}


Measured memory_bytes: 256
//16
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    while(n--){
      int f[2][4];
      for(int i=0;i<2;i++){
	for(int j=0;j<4;j++){
	  cin>>f[i][j];
	}
      }
      int r[4]={};
      for(int i=0;i<4;i++){
	for(int j=0;j<4;j++){
	  int t[][4]={{0,1,2,3},{1,0,3,2,},{2,3,0,1},{3,2,1,0}};
	  int s[][4]={{1,1,1,1},{1,-1,1,-1},{1,-1,-1,1},{1,1,-1,-1}};
	  r[t[i][j]]+=f[0][i]*f[1][j]*s[i][j];
	}
      }
      cout<<r[0]<<' '<<r[1]<<' '<<r[2]<<' '<<r[3]<<endl;
    }
  }
  return 0;
}
    

Measured memory_bytes: 1160
import itertools

N, M, R = map(int, input().split())
r = tuple(map(int, input().split()))

INF = 10**10

d = [[INF] * N for _ in range(N)]

for i in range(N):
    d[i][i] = 0

for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if d[a][b] > c:
        d[a][b] = c
        d[b][a] = c


def warshall(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]


# d = floyd_warshall(d)
warshall(d)


ans = INF
for p in itertools.permutations(r):
    dist = 0
    for i in range(R-1):
        dist += d[p[i]-1][p[i+1]-1]

    if ans > dist:
        ans = dist

print(int(ans))


Measured memory_bytes: 48088
#include<stdio.h>
long long p=1,t=1000000000000000000,n,a,i;
int main(void)
{
	double m=1;
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    p*=a;
    m*=a;
  }
  if(p>t||m>t){
    printf("-1\n");
  }
  else{
    printf("%lld\n",p);
  }
  return 0;
}


Measured memory_bytes: 1732
import Control.Applicative ((<$>))
import Control.Arrow ((&&&))
import Data.List (sortBy,group)
import Text.Printf (printf)


comb n r = iterate (scanl1 (+)) [1,1..] !! fromIntegral(n-r) !! fromIntegral r

average :: [(Integer,Integer)] -> Double
average s = fromIntegral(sum(map (uncurry(*)) s))/fromIntegral(sum(map snd s))

solve :: Integer -> Integer -> [(Integer,Integer)] -> [(Integer,Integer)] -> (Double,Integer)
solve a b (h@(e,l):svs) stack
  | ls == 0 && a <= l = (fromIntegral e,sum [comb l r|r<-[a..min l b]])
  | ls > 0 && a <= l  = (average ((e,a):stack),comb l a)
  | l < a = solve (a-l) (b-l) svs (h:stack)
  where ls = length stack

main = do
  [n,a,b] <- map read.words <$> getLine :: IO [Integer]
  vs <- map read.words <$> getLine :: IO [Integer]
  let svs = map (head&&&fromIntegral.length).group.sortBy (flip compare) $ vs :: [(Integer,Integer)]
      (avg,pat) = solve a b svs []
  printf "%.7f\n%d\n" avg pat


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

int n;
vector<int> g[100001];
char c[100001];
int visit[100001];
int finish[100001];
int group[100001];
int m;
int main() {

    cin >> n >> m;
    for (int i1 = 1; i1 <=m; ++i1) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

   stack<int> s;
    for (int l = 0; l < n; ++l) {
        c[l] = 'w';

    }
    int time = 0;
    int start = -1;
    int v;
    int nowg = 0;
    while(true) {
        nowg++;
        start++;
        if(start == n) break;
        if(c[start] == 'w') {
            time++;
            s.push(start);
            c[start] = 'g';
            group[start] = nowg;
            visit[start] = time;
            while (s.size() != 0) {
                time++;
                v = s.top();
                int next = -1;
                for (int i = 0; i < g[v].size() ; ++i) {
                    if(c[g[v].at(i)] == 'w') {
                        next = g[v].at(i);
                        break;
                    }
                }
                if(next == -1) {
                    c[v] = 'b';
                    finish[v] = time;
                    s.pop();
                } else {
                    c[next] = 'g';
                    group[next] = nowg;
                    visit[next] = time;
                    s.push(next);
                }
            }
        }
    }

    int q;
    cin >> q;
    for (int m = 0; m < q; ++m) {
        int a, b;
        cin >> a >> b;
        if(group[a] == group[b]) cout << "yes";
        else cout << "no";
        cout << endl; 


    }



    return 0;
}



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

string toBinary(long long n)
{
    string s;
    while (n != 0)
    {
        int r = abs(n % 2);
        s += to_string(r);
        n -= r;
        n /= -2;
    }
    reverse(s.begin(), s.end());

    return s;
}

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

    if (N == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << toBinary(N) << endl;

    return 0;
}

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

int main()
{
    ll r, d, x;
    cin >> r >> d >> x;
    rep(i, 10)
    {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
N, C = map(int, input().split())
xv = [[int(i) for i in input().split()] for _ in range(N)]

l1 = [xv[i][1] for i in range(N)]
l2 = l1[::]
r1 = l1[::-1]
r2 = r1[::]

for i in range(1, N) :
    l1[i] += l1[i-1]
    l2[i] += l2[i-1]
    r1[i] += r1[i-1]
    r2[i] += r2[i-1]
    
for i in range(N) :
    x = xv[i][0]
    l1[i] -= x
    l2[i] -= 2 * x
    r1[N-1-i] -= C - x
    r2[N-1-i] -= 2 * (C - x)

for i in range(1, N) :
    l1[i] = max(l1[i], l1[i-1])
    r1[i] = max(r1[i], r1[i-1])

ret = max(l1[-1], r1[-1])
for i in range(N-1) :
    ret = max(ret, l2[i] + r1[N-2-i])
    ret = max(ret, r2[i] + l1[N-2-i])
    
print(max(ret, 0))

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

int main(){
    int m, h;
    char cards[256], temp[256], result[256];
    int i, j=0, len;

    while(1){
        scanf("%s", cards);
        len=strlen(cards);
        if(strcmp(cards, "-")==0&&len==1)break;
        scanf("%d", &m);
        for(;m>0;m--){
            scanf("%d", &h);
            strcpy(temp, cards);
            for(i=0;i<h;i++){
                cards[len-h+i]=temp[i];
            }
            for(i=0;i<len-h;i++){
                cards[i]=temp[i+h];
            }
        }
        for(i=0;i<len;i++){
            result[j++]=cards[i];
        }
        result[j++]='\n';
    }
    result[j]='\0';
    printf("%s", result);

    return 0;
}


Measured memory_bytes: 2076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt()*2;
		int X = sc.nextInt();
		int Y = sc.nextInt();
		
		if(A+B>=C) {
			if(A!=0&&B!=0) {
				int minxy = min(X,Y);
				int numc = C*minxy;
				int sum = numc + A*(X-minxy) + B*(Y-minxy);
				
				int sum2 = C*max(X,Y);
				
				System.out.println(min(sum,sum2));
			}
			if(A==0||B==0) {
				System.out.println(A*X + B*Y);
			}
		}else {
			System.out.println(A*X + B*Y);
		}
		
	}

	public static int min(int a,int b) {
		return a<b?a:b;
	}
	
	public static int max(int a,int b) {
		return a>b?a:b;
	}
	
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;

int main(){
    int a,b,t;
    cin >> a>>b>>t;
    cout << b*(t/a)<<endl;

}


Measured memory_bytes: 764
import math

N = int(input())

x = list(map(float,input().split()))
y = list(map(float,input().split()))

for p in range(1,4):
    Dxy = float(0)
    for i in range(N):
        Dxy += abs(x[i]-y[i])**p
    Dxy = Dxy**(1/p)
    print("%.6f"%(Dxy))

Dxy = float(0)

for i in range(N):
    if Dxy<abs(x[i]-y[i]):Dxy=abs(x[i]-y[i])
print(f'{Dxy:.6f}')


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

int main(){
    int n; cin >> n;
    map<int, int> p;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        if(p.count(a)) p[a]++;
        else p[a]=1;
    }
    ll ans = 0;
    for(auto q:p){
        int x=q.first, y=q.second;
        if(x>y) ans += y;
        else ans += y-x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8100
#include <stdio.h>

int main(){
  long long int a,b,c,d;
  scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
  long long int ans=a*c;
  if(ans<a*c) ans=a*c;
  if(ans<b*c) ans=b*c;
  if(ans<a*d) ans=a*d;
  if(ans<b*d) ans=b*d;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1736
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

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

#define DEBUG
#undef DEBUG

using ll = long long;

int N;
int A[300005];

ll maxsum(int k)
{
    vector<ll> v(A, A+k);
    sort(begin(v), end(v), greater<ll>());
    return accumulate(begin(v), begin(v)+N, 0LL);
}

ll minsum(int k)
{
    vector<ll> v(A+k, A+3*N);
    sort(begin(v), end(v));
    return accumulate(begin(v), begin(v)+N, 0LL);
}

/**
 * 区切り位置 k (N <= k <= 2*N) で総当たり
 * 全てのkについて
 *   前半の中からN個選ぶ和の最大値
 *   後半の中からN個選ぶ和の最小値
 * をあらかじめ求めておく。
 */
void solve()
{
    ll lmax_table[300005]; // 前半の中からN個選ぶ和の最大値テーブル
    ll rmin_table[300005]; // 後半の中からN個選ぶ和の最小値テーブル

    /**
     * 優先度付きキューを用いてテーブルを構築
     */
    ll lmax = 0; // 前半の中からN個選ぶ和の最大値
    ll rmin = 0; // 後半の中からN個選ぶ和の最小値
    priority_queue<int, vector<int>, greater<int>> ql; // 前半中最大のN個
    priority_queue<int>                            qr; // 後半中最小のN個

    // 前半初期化
    // 最初のN個をキューに追加し、総和を記録
    FOR(i, 0, N) {
        int a = A[i];
        lmax += a;
        ql.push(a);
    }
    // k == N の場合
    lmax_table[N] = lmax;
    // N+1 <= k <= 2*N の場合
    FOR(k, N+1, 2*N+1) {
        // 新しく得た値をキューに加える
        // その値を総和に加え、キューから取り出した最小値を引く
        int a = A[k-1];
        ql.push(a);
        lmax += a;
        lmax -= ql.top(); ql.pop();
        lmax_table[k] = lmax;
    }

    // 後半初期化
    // 最後のN個をキューに追加し、総和を記録
    for(int i = 3*N-1; i >= 2*N; --i) {
        int a = A[i];
        rmin += a;
        qr.push(a);
    }
    // k == 2*N の場合
    rmin_table[2*N] = rmin;
    // N <= k <= 2*N-1 の場合
    for(int k = 2*N-1; k >= N; --k) {
        // 新しく得た値をキューに加える
        // その値を総和に、キューから取り出した最大値を引く
        int a = A[k];
        qr.push(a);
        rmin += a;
        rmin -= qr.top(); qr.pop();
        rmin_table[k] = rmin;
    }

    ll score_max = numeric_limits<ll>::min();
    FOR(k, N, 2*N+1) {
        score_max = max(score_max, lmax_table[k] - rmin_table[k]);
    }

    cout << score_max << "\n";
}

int main()
{
    cin >> N;
    REP(i, 3*N) {
        cin >> A[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N;
string s;
void dfs(ll index, char M)
{
  if (index == N) {
    cout << s << endl;
    return;
  }
  for (ll i = 0; i <= M - 'a' + 1; ++i) {
    s[index] = (char)('a' + i);
    dfs(index + 1, max(M, (char)('a' + i)));
  }
}

int main()
{
  cin >> N;
  s = "";
  for (ll i = 0; i < N; ++i) {
    s += 'a';
  }
  dfs(1, 'a');
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  double a, b, n;
  cin >> a >> b >> n;
  if(n<b){
    cout << floor(n*a/b) << endl;
  }else{
    cout << floor((b-1)*a/b) << endl;
  }
  return 0;
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  int sum = 0;
  rep(i,N){
    sum += A[i];
  }
  if(sum >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
 }

Measured memory_bytes: 640
#include <cstdio>
int n;
int main() {
	while(scanf("%d", &n), n) {
		int ret = 0;
		for(int l = 1; l <= n; l++) {
			int sum = l;
			for(int r = l + 1; r <= n; r++) {
				sum += r;
				if(sum == n) ret++;
			}
		}
		printf("%d\n", ret);
	}
}

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

bool solve(vector<int>& nums, int target)
{
    vector<vector<bool>> dp(nums.size(), vector<bool>(target + 1, false));

    for (int i = 0; i < nums.size(); i++) {
        dp[i][0] = true;
    }
    dp[0][nums[0]] = true;

    for (int i = 1; i < nums.size(); i++) {
        for (int j = 1; j <= target; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - nums[i] >= 0) {
                dp[i][j] = dp[i][j] || dp[i - 1][j - nums[i]];
            }
        }
    }
    return dp[nums.size() - 1][target];
}

bool solve_optimized(vector<int>& nums, int target)
{
    vector<bool> dp(target + 1, false);

    dp[0] = true;
    dp[nums[0]] = true;

    for (int i = 1; i < nums.size(); i++) {
        for (int j = target; j >= 1; j--) {
            if (j - nums[i] >= 0) {
                dp[j] = dp[j] || dp[j - nums[i]];
            }
        }
    }
    return dp[target];
}

int main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int m;
        cin >> m;
        if (solve_optimized(A, m)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main() {
  int a,b;
  cin>>a>>b;
  int yaju=1;
  int ans=0;
  for(int i=1;;i++){
    if(yaju>=b){
      cout<<ans<<endl;
      break;
    }
    else{
      yaju--;
      yaju+=a;
      ans++;
    }
  }
}


Measured memory_bytes: 256
def chk_a():
    global a
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]=a[i]//2
        else:
            return False
    return True

n = int(input())
a = list(map(int,input().split()))

for i in range(10**9):
    if chk_a()==False:
        break
print(i)

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

const int MAX = 510000;
const int MOD = 1000000007;

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

//逆元ライブラリ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
  COMinit();
  long long B,W,ans;
  cin>>B>>W;
  long long p,q,bunshi,bunbo;
  bunshi=1;
  bunbo=1;
  p=0;
  q=0;
  for(int i=0;i<B+W;++i){
    bunbo*=inv[2];
    bunbo%=MOD;
    bunshi*=2;
    bunshi%=MOD;
    if(i>=B){
      p*=2;
      p+=COM(i-1,B-1);
      p%=MOD;
    }
    if(i>=W){
      q*=2;
      q+=COM(i-1,W-1);
      q%=MOD;
    }
    //cout<<p<<" "<<q<<" "<<bunbo<<" "<<bunshi<<"\n";
    ans=(((bunshi)*inv[2]%MOD-p-q)+2*q+MOD)*bunbo%MOD;
    cout<<ans<<"\n";
  }

return 0;
}

Measured memory_bytes: 14208
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		String o = scanner.nextLine();
		String e = scanner.nextLine();

		if (o.length() == e.length()) {
			for (int i = 0; i < o.length(); i++) {
				System.out.print(o.charAt(i) + "" + e.charAt(i));
			}
		}else {
			for (int i = 0; i < o.length()-1; i++) {
				System.out.print(o.charAt(i) + "" + e.charAt(i));
			}
			System.out.print(o.charAt(o.length()-1));
		}
		System.out.println();
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

vector<int> par;
vector<int> rnk;

void init(int n) {
  par = vector<int>(n);
  rnk = vector<int>(n);

  REP(i, n) {
    par[i] = i;
    rnk[i] = 0;
  }
}

int root(int x) {
  if (x == par[x]) return x;
  return root(par[x]);
}

int same(int x, int y) {
  return root(x) == root(y);
}

void unite(int a, int b) {
  int x = root(a);
  int y = root(b);

  if (rnk[x] > rnk[y]) {
    par[y] = x;
  } else {
    par[x] = y;
    rnk[x]++;
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  init(n);

  REP(i, q) {
    int com, x, y;
    scanf("%d %d %d", &com, &x, &y);
    if (com == 0) {
      unite(x, y);
    } else {
      printf("%d\n", same(x, y));
    }
  }

  return 0;
}

Measured memory_bytes: 3348
N = int(input())
N -= 1

alpha = "abcdefghijklmnopqrstuvwxyz"

a = 1
for i in range(1,10000):
    a *= 26
    if N < a:
        NN = N
        o = [0]*i
        for j in range(i):
            o[j] = NN % 26
            NN //= 26
        print(''.join([alpha[x] for x in o[::-1]]))
        exit()
    else:
        N -= a



Measured memory_bytes: 61872
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
#define INF (1<<26)
 
int N,M,a,b,si,ti;
vector<int> G[MAX_N];
int sd[MAX_N],td[MAX_N];
int sc[MAX_N],tc[MAX_N];
 
void calc(int si,int d[MAX_N],int c[MAX_N]){
  for(int i=0;i<MAX_N;i++)d[i]=INF,c[i]=0;
 
  queue<int> Q;
  d[si]=0;
  c[0]++;
  Q.push(si);
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    for(int i=0;i<(int)G[pos].size();i++){
      int to=G[pos][i];
      if(d[pos]+1<d[to]){
    d[to]=d[pos]+1;
    c[d[to]]++;
    Q.push(to);
      }
    }
  }
}
 
int main(){
  scanf("%d %d %d %d",&N,&M,&si,&ti);
  for(int i=0;i<M;i++){
    scanf("%d %d",&a,&b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  calc(si,sd,sc);
  calc(ti,td,tc);
  
  int total=sd[ti];
  long long ans=0,A,B;
  for(int i=0;i<=N;i++){
    if(total-2-i<0)continue;
    A=sc[i];
    B=tc[total-2-i];
    ans+=A*B;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9152
N=int(input())
A=sorted(list(map(int,input().split())))[::-1]
B=[A[i] for i in range(len(A)) if i %2 == 0 ] #Alice
C=[A[i] for i in range(len(A)) if i %2 != 0 ] #Bob

print(sum(B)-sum(C))


Measured memory_bytes: 2940
from itertools import product
N,M=map(int,input().split())
A=[]
for _ in range(M):
    A.append(list(map(int,input().split()))[1:])
P=list(map(int,input().split()))

ans=0

for st in product([0,1],repeat=N):
    f=True
    for i in range(M):
        k=0
        for j in A[i]:
            k+=st[j-1]
        f= k%2==P[i]
        if not f:
            break
    if f:
        ans+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
 
#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)
 
inline ll ii(){ ll x; cin >> x; return x; }
inline string is(){ string x; cin >> x; return x; }
inline ld id(){ ld x; cin >> x; return x; }
inline void oi(ll x){ cout << x; }
inline void od(ld x){ cout << fixed << setprecision(10) << x; }
inline void os(string x){ cout << x; }
inline void oe(){ cout << endl; }
inline void oie(ll x){ oi(x); oe(); }
inline void ode(ld x){ od(x); oe(); }
inline void ose(string x){ os(x); oe(); }
inline void maxin(ll &a, ll b){ a=max(a,b); }
inline void minin(ll &a, ll b){ a=min(a,b); }


int main(){
    ll N=ii();
    ll ret=0;
    ll a=1;
    for(ll i=N-1;i>=2;i--){
        while(i*(a+1)<N){
            a++;
        }
        ret+=a;
    }
    ret+=N-1;
    oie(ret);
    return 0;
}


Measured memory_bytes: 3640
H, N = map(int, input().split())
a, b = zip(*(list(map(int, input().split())) for _ in range(N)))
maxA = max(a)

inf = float("inf")
dp = [inf for _ in range(H+maxA+1)]
dp[0] = 0

for j in range(N):
    for i in range(a[j], H+maxA+1):
        dp[i] = min(dp[i], dp[i-a[j]]+b[j])

print(min(dp[H:]))

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

long long d[205][205];
long long N, M, R;
vector<long long> r;
long long A[40000];
long long B[40000];
long long C[40000];

int main(){
	cin >> N >> M >> R;
	for(long long i = 0; i < R; i++){
		long long tmp;
		cin >>  tmp;tmp--;
		r.push_back(tmp);
	}

	for(long long i = 0; i < M; i++){
		cin >> A[i] >> B[i] >> C[i];
		A[i]--;B[i]--;
	}

	for(long long i = 0; i < 205; i++){
		for(long long j = 0; j < 205; j++){
			d[i][j] = INT_MAX;
		}
		d[i][i] = 0;
	}

	for(long long i = 0; i < M; i++){
		d[A[i]][B[i]] = min(d[A[i]][B[i]], C[i]);
		d[B[i]][A[i]] = min(d[B[i]][A[i]], C[i]);
	}

	for(int k = 0; k < N; ++k){
		for(int i = 0; i < N; ++i){
			for(int j = 0; j < N; ++j){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	sort(r.begin(), r.end());

	long long mini = INT_MAX;

	do {
		long long tmp = 0;
		for(long long i = 0; i < r.size() - 1; i++){
			tmp += d[r[i]][r[i+1]];
		}
		mini = min(tmp, mini);
	} while( next_permutation(r.begin(), r.end()) );     // 次の順列を生成
	cout << mini << endl;
}

Measured memory_bytes: 1024
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    dists = set([])
    for idx in range(len(A) - 1):
        dists.add(A[idx + 1] - A[idx])
    dists.add(A[0] + K - A[-1])
    print(K - max(list(dists)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 99916