akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
       int n = sc.nextInt();
       String s = Integer.toString(n);
       if(s.charAt(0) == '9' || s.charAt(1) == '9'){
           out.println("Yes");
       }
       else{
           out.println("No");
       }
       out.close();
    }
}


Measured memory_bytes: 32780
#include "bits/stdc++.h"
using namespace std;

int main() {
    int r,d;
    int x[200];

    cin >> r >> d;
    cin >> x[0];

    for(int i =0; i < 10;i++){
        x[i+1] = r * x[i] - d;
    }
    for(int i = 1; i <= 10;i++){
        cout << x[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int weight = sc.nextInt();
        int[] w = new int[n];
        long[] v = new long[n];
        for(int i=0;i<n;i++)
        {
        	w[i] = sc.nextInt();
        	v[i] = sc.nextInt();
        }

        long[][] dp = new long[n+1][weight+1];
        for(int i=0;i<=n;i++)
        {
        	for(int j=0;j<=weight;j++)
        	{
                if(i==0||j==0)
                {
                	dp[i][j] = 0;
                	continue;
                }
        		dp[i][j] = Math.max(dp[i][j],dp[i-1][j]);
        		if(j-w[i-1]>=0)
        		{
        			dp[i][j] = Math.max(dp[i][j],dp[i-1][j-w[i-1]]+v[i-1]);
        		}
        	}
        }

       

        System.out.println(dp[n][weight]);
 	}
}

Measured memory_bytes: 140332
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  string S;
  int X,Y;
  cin>>S>>X>>Y;
  vector<pair<char,int>> A={make_pair('a',0)};
  for(char c:S){
    if(c==A.back().first)A.back().second++;
    else A.push_back({c,1});
  }
  A.erase(A.begin());
  set<int> B[2];
  B[0].insert(0);
  B[1].insert(0);
  int n=0;
  for(int j=0;j<A.size();j++){
    if(A[j].first=='T')n=(n+A[j].second)%2;
    else{
      set<int> s;
      for(int i:B[n]){
        if(j)s.insert(i-A[j].second);
        s.insert(i+A[j].second);
      }
      B[n]=s;
    }
  }
  cout<<(B[0].count(X) && B[1].count(Y)?"Yes":"No")<<endl;
}

Measured memory_bytes: 4176
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
M_chr = []
for i in range(1,M+1):
    M_chr.append(str(i))
As = list(itertools.combinations_with_replacement(M_chr, N))
pointA_max = 0
for i, A in enumerate(As):
    pointA = 0
    for i in range(Q):
        a = abcd[i][0]
        b = abcd[i][1]
        c = abcd[i][2]
        d = abcd[i][3]
        if int(A[b-1])-int(A[a-1]) == c:
            pointA = pointA + d
    if pointA_max < pointA:
        pointA_max = pointA
print(pointA_max)


Measured memory_bytes: 85076
// Author : Abhinav Jain
// Institution: Jaypee Institute of information Technology
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define lli long long int
#define pb push_back
#define mp make_pair
#define cases lli testcases;cin>>testcases; while(testcases--)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << x << endl;
#define trace2(x,y) cerr<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define trace3(x,y,z) cerr<< '>' << #x << ':' << x << " | " << #y << ':' << y <<  " | " << #z << ':' << z << endl;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef map<int,int> mii;
int MOD= 1000000007LL;
#define all(v) v.begin(), v.end()
 lli fastpow(lli base, lli exp) {lli res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}


template<typename T>
T mult(T x,T y,T mod){
    return(((x%mod)*(y%mod))%mod);
}

template<typename T>
T add(T x,T y,T mod){
    return(((x%mod)+(y%mod))%mod);
}

template<typename T>
T gcd(T x,T y){
    return(!y?x:gcd(y,x%y));
}

template<typename T>
T lcm(T x,T y){
    return((x*y)/gcd(x,y));
}

int32_t main()
{
    lli n; cin >> n;
    lli rem = n%1000;
    if(rem == 0) rem = 1000;
    cout << 1000 - rem;
    
    return 0;
}

Measured memory_bytes: 3604
W,H = map(int,raw_input().split(" "))
V = max(W,H)


PI = [input() for i in range(W)]
QI = [input() for i in range(H)]

   
ans = sum(PI)*(H+1)+sum(QI)*(W+1)


PI.sort(reverse=True)
QI.sort(reverse=True)

if W < V:
    for i in range(V-W):
        PI.append(0)
if H < V:
    for i in range(V-H):
        QI.append(0)
 

cnt = W*H

WW = H
HH = W



pin = 0
qin = 0


while cnt:

    if PI[pin] > QI[qin]:
        ans -= PI[pin] * WW
        HH-=1
        cnt -= WW
        pin += 1
    else:
        ans -= QI[qin] * HH

        WW-=1
        cnt -= HH
        qin+=1
print ans


Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//暗記用模写
const int INF=1001001001;
int a[12][12];
 
int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[i][j];
  }
  int kotae=INF;
  for(int s=0;s<(1<<n);s++){
    int sum=0;
    vector<int>d(m,0);
    for(int i=0;i<n;i++){
      if(s>>i &1){
        for(int j=0;j<m;j++){
          d[j]+=a[i][j];
        }
        sum+=c[i];
      }
    }
    bool hantei=true;
    for(int j=0;j<m;j++){
      if(d[j]<x)hantei=false;
    }
    if(hantei==true)kotae=min(kotae,sum);
  }
  if(kotae==INF)cout<<-1<<endl;
  else cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#define F first
#define S second
using namespace std;

int main(){

  int h,w,n;
  string s[1010];
  int z[1010][1010];
  int sx,sy;
  int ans = 0;
  int m;
  int dx[4] = {0,0,1,-1};
  int dy[4] = {1,-1,0,0};
  typedef pair < int,int > p;
  queue < p > que;

  cin >> h >> w >> n;

  for(int i=0;i<h;i++) cin >> s[i];

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j] == 'S'){
	sx = j;
	sy = i;
	break;
      }
    }
  }

  for(int l=0;l<n;l++){

    memset(z,-1,sizeof(z));
    z[sy][sx] = 0;
    que.push( p(sy,sx) );
    char c = '1'+l;

    while( !que.empty() ){

      int x = que.front().S;
      int y = que.front().F;
      que.pop();

      for(int i=0;i<4;i++){

	int nx = x + dx[i];
	int ny = y + dy[i];

	if(nx < 0 || ny < 0 || nx == w || ny == h) continue;
	if(s[ny][nx] == 'X') continue;

	if(s[ny][nx] == c && (z[ny][nx] == -1 || z[y][x]+1 < z[ny][nx])){
	  m = z[ny][nx] = z[y][x]+1;
	  sy = ny;
	  sx = nx;
	  que.push( p(ny,nx) );
	  continue;
	}

	if(z[ny][nx] == -1 || z[y][x]+1 < z[ny][nx]){
	  z[ny][nx] = z[y][x]+1;
	  que.push( p(ny,nx) );
	}

      }
    }
    ans += m;
  }

  cout << ans << endl;

}

Measured memory_bytes: 6260
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define nl cout<<"\n"
#define db(x) cout<<x<<" "
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define fk(a,b) for(int k=a;k<b;k++)
#define F first
#define S second
#define UM unordered_map<int,int>
#define MP map<int,int>
void fun(){
	ll n;
	cin>>n;
	ll ans=0;
	fi(1,n+1){
		ll k=n/i;
		ans+=i*k*(k+1)/2;
	}
	cout<<ans<<"\n";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("/ATOM/input.txt", "r", stdin);
		freopen("/ATOM/output.txt", "w", stdout);
	#endif
	int t=1;
	// cin>>t;
	while(t--){
		fun();
	}
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c,d,f,g;
  cin>>a>>b>>c;
  if(a==1)cout<<"Hello World";
  else cout<<b+c;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int Nmax = 100010;
const int Tmax = 200010;

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

    vector<int> s(Nmax), t(Nmax), c(Nmax), cnt(Tmax);
    rep(i, n) {
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
    }

    rep(i, C) {

        vector<int> v(Tmax);

        rep(j, n) {
            if(c[j] == i) {
                v[2*s[j]-1]++;
                v[2*t[j]]--;
            }
        }

        rep(j, Tmax-1) {
            v[j+1] += v[j];
        }

        rep(j, Tmax) {
            if(v[j] > 0) {
                cnt[j]++;
            }
        }
        
    }

    int ans = 0;
    rep(i, Tmax) {
        if(ans < cnt[i]) {
            ans = cnt[i];
        }
    }

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

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

int n;
const int N = 2e5;
string s;
pair <int, int> edges[N];
int main()
{
    ios::sync_with_stdio(0);
    cin >> s;
    n = s.size();
    if (s[0] == '0' || s[n - 1] == '1') {puts("-1"); return 0;}
    for (int i = 0; i < n / 2; ++ i)
        if (s[i] != s[n - 2 - i]) {puts("-1"); return 0;}
    for (int i = 1, j = 1; i < n; ++ i)
    {
        edges[i] = make_pair(i + 1, j);
        if (s[i - 1] == '1')
            j = i + 1;
    }
    for (int i = 1; i < n; ++ i)
        printf("%d %d\n", edges[i].first, edges[i].second);
}


Measured memory_bytes: 2384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  ll ans=0;
  ans = pow(2,m)*(m*1900+(n-m)*100);
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

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

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll a, b;

	cin >> a >> b;

	ll ans = a * b - a - b + 1;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

void sumup(vector<ll>& v)
{
    int n = v.size();

    for(int i = 1; i < n; ++i)
        v[i] = (v[i] + v[i - 1]) % MOD;
}

ll get_sum(const vector<ll>& pref, int from, int to)
{
    ll l = 0;
    if(from - 1 >= 0)
        l = pref[from - 1];

    ll r = pref[to];

    return ((r - l) + MOD) % MOD;
}

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

    vector<ll> v(n);

    for(int i = 0; i < n; ++i)
        cin >> v[i];

    vector<vector<ll> > dp(n, vector<ll>(k + 1));

    for(int j = 0; j < v[0] + 1; ++j)
        dp[0][j] = 1;

    for(int i = 1; i < n; ++i) {
        sumup(dp[i - 1]);

        for(int j = 0; j < k + 1; ++j) {
            int left = max(j - v[i], 0LL);
            int right = j;
            dp[i][j] = get_sum(dp[i - 1], left, right);
        }
    }

    cout << dp[n - 1][k] << endl;

    return 0;
}


Measured memory_bytes: 79360
/*input
84 97 66
79 89 11
61 59 7
7
89
7
87
79
24
84
30
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

signed main() {
	IOS;
	int a[3][3];
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		int x;
		cin >> x;
		for(int j = 0 ; j < 3 ; j++){
			for(int k = 0 ; k < 3 ; k++){
				if(a[j][k] == x){
					a[j][k] = -1;
				}
			}
		}
	}
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			if(a[i][j] == -1){
				a[i][j] = 1;
			}
			else{
				a[i][j] = 0;
			}
		}
	}
	bool ans = 0;
	for(int i = 0 ; i < 3 ; i++){
		bool res = 1;
		for(int j = 0 ; j < 3 ; j++){
			res &= a[i][j];
		}
		ans |= res;
	}
	for(int i = 0 ; i < 3 ; i++){
		bool res = 1;
		for(int j = 0 ; j < 3 ; j++){
			res &= a[j][i];
		}
		ans |= res;
	}
	ans |= (a[0][0] & a[1][1] & a[2][2]);
	ans |= (a[2][0]&a[1][1]&a[0][2]);
	if(ans){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

std::vector<int64_t> calc_seq(std::vector<int64_t> & xs) {
    auto seq = std::vector<int64_t>{};
    auto count = 1;
    for (size_t i = 0; i < xs.size() - 1; i++) {
        if (xs[i] == xs[i+1]) {
            count++;
        } else {
            seq.push_back(count);
            count = 1;
        }
    }
    seq.push_back(count);
    return seq;
}

std::vector<int64_t> form_seq(std::vector<int64_t> & xs) {
    auto seq = calc_seq(xs);
    if (xs[0] == 0) {
        seq.insert(begin(seq), 0);
    }
    if (seq.size() % 2 == 0) {
        seq.push_back(0);
    }
    return seq;
}

int64_t sum(std::vector<int64_t> xs, int64_t i0, int64_t i1) {
    auto val = 0LL;
    for (auto i = i0; i <= i1; i++) {
        val += xs[i];
    }
    return val;
}

void calc(int64_t n, int64_t k, std::vector<int64_t> & xs) {
    auto seq = form_seq(xs);
    auto m = seq.size();
    auto i = 1LL;
    if (i + 2*k > m) {
        std::cout << n;
        return;
    }
    auto val = sum(seq, i-1, i-1 + 2*k);
    auto biggest = val;
    i += 2;
    while (i + 2*k <= m) {
        val += seq[i-1+2*k-1] + seq[i-1+2*k] - seq[i-1-2] - seq[i-1-1];
        if (biggest < val) {
            biggest = val;
        }
        i += 2;
    }
    std::cout << biggest;
}

int main() {
    std::string s1, s2;
    std::cin >> s1 >> s2;
    auto n = stoi(s1);
    auto k = stoi(s2);

    std::string s3;
    std::cin >> s3;
    std::vector<int64_t> xs(n);
    for (size_t i = 0; i < n; i++) {
        xs[i] = stoi(s3.substr(i, 1));
    }
    calc(n, k, xs);
}

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

int main(){
	int n, l;
	cin >> n >> l;
	string S[n];
	for (int i = 0; i < n; i++) cin >> S[i];
	sort(S, S+n);
	for (int i = 0; i < n; i++) cout << S[i];
	cout << "\n";
}


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

namespace OddString
{
    class OddString
    {
        static void Main(string[] args)
        {
            string strInpString = Console.ReadLine();
            string strOut = "";
            for (int i = 0; i < strInpString.Length; i+=2) {
                strOut += strInpString.Substring(i, 1);

            }
            Console.WriteLine(strOut);

            // for debug
            return;
        }
    }
}


Measured memory_bytes: 34772
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    int x = 0;
    
    for(int i=1; i<=N; i++){
      x = x + L + i -1;
    }
    
    int y = 0;
    for(int i=1; i<=N; i++){
      if(L - 1 + i == 0){
        y = i;
      }
    }
    if(y == 0){
      if(L * L > (L + N - 1) * (L + N - 1)){
        y = N;
      }else {
        y = 1;
      }
    }
    System.out.println(x - L + 1 - y);
  }
}
         

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

const int MAX = 1 << 17;

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	vector<int> v(MAX << 1, INT_MAX);
	while (q--) {
		int com, x, y;
		scanf("%d%d%d", &com, &x, &y);
		if (com == 0) {
			for (v[x += MAX] = y; x > 1; x >>= 1) {
				v[x >> 1] = min(v[x], v[x ^ 1]);
			}
		}
		else {
			int res = INT_MAX;
			for (x += MAX, y += MAX + 1; x < y; x >>= 1, y >>= 1) {
				if (x & 1) res = min(res, v[x++]);
				if (y & 1) res = min(res, v[--y]);
			}
			printf("%d\n", res);
		}
	}
	return 0;
}



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

int main()
{
  int n, m; cin>>n>>m;
  vector<int> c(m, 0);
  rep(i, m) cin>>c[i];
  vector<int> dp(n+1, 1001001001);
  dp[0] = 0;
  rep(i, m) {
    for (int j=1; j<=n; j++) {
      if (j>=c[i]) dp[j] = min(dp[j], dp[j-c[i]]+1);
    }
  }
  cout << dp[n] << endl;

  return 0;
}



Measured memory_bytes: 3180
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ll t;
        cin >> t;
        if (t < A || B <= t) {
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main(){
char s[1000000];
  int i,j,k;
  
  scanf("%s",s);
  for(i=0;i<strlen(s);i++){
    if(i%2 == 0)
      printf("%c",s[i]);
  }
  puts("");
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
n = int(input())
taro = hanako = 0
for i in range(n):
    a, b = input().split()
    if a == b:
        taro += 1
        hanako += 1
    elif a > b:
        taro += 3
    else:
        hanako += 3
print(taro, hanako)

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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

int main() {
  int1(n);
  lint a[n];
  lint ans[n];
  lint sum = 0;
  repi(n){
    cin>>a[i];
    if(i % 2==0){
      sum+=a[i];
    }else{
      sum-=a[i];
    }
  }
  ans[0]=sum/2;
  cout<<ans[0]*2;
  repi(n-1){
    ans[i+1]=a[i]-ans[i];
    cout<<" "<<ans[i+1]*2;
  }
  cout<<endl;
  
}


Measured memory_bytes: 2816
from collections import deque
N, D, A = map(int, input().split())
XH = []
for _ in range(N):
    x, h = map(int, input().split())
    XH.append((x, h))
XH.sort(key=lambda x: x[0])
D = 2 * D
tot = 0
q = deque()
ans = 0
for i in range(N):
    x, h = XH[i]
    while 0 < len(q) and q[0][0] < x:
        tot -= q[0][1]
        q.popleft()
    h -= tot
    if h > 0:
        num = (h + A - 1) // A
        ans += num
        damage = num * A
        tot += damage
        q.append((x + D, damage))
print(ans)


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

int main()
{
	int n, b[4] = {};
	string str;
	char d;

	while (cin >> n >> d >> str){
		if(str == "A")	b[0]++;
		if(str == "B")	b[1]++;
		if(str == "AB")	b[2]++;
		if(str == "O")	b[3]++;

	}
	
	for (int i = 0; i < 4; ++i)
		cout << b[i] << endl;

	return 0;
}

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

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  string ans;
  
  for (int i = 0; i < n; i++) {
   char a = s.at(i);
    char b = t.at(i);
    ans += a;
    ans += b;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
	Behind every successful man 
	there's a lot of unsuccessful years
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n,k;
		cin >> n >> k;
		cout << (n+k-1)/k <<endl;
	
	
	}
	
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
s = gets.chomp

ary = []
pre = "1"
c = 0
n.times do |i|
    if pre != s[i]
        ary << c
        c = 0
        pre = s[i]
    end
    c += 1
end
ary << c
ary << 0 if s[-1] == "0"
x = ary.size

k = 2 * k + 1
if x <= k
    puts ary[0..-1].inject(:+)
else
    ans = ary[0, k].inject(:+)
    sum = ans
    (k + 1).step(x, 2) do |i|
        sum += ary[i] + ary[i - 1]
        sum -= ary[i - k] + ary[i - k - 1]
        ans = sum if ans < sum
    end
    puts ans
end


Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define MAX_T 1260

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int main(void) {
    while (1) {
        int n; // pc
        int m; // person
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }

        VI pc(m + 1, 0);
        VI start(m + 1, 0);

        VVI time(m + 1, VI(MAX_T + 1, 0));

        int r;
        cin >> r;
        for (int i = 0; i < r; i++) {
            int t;
            int n2; // pc
            int m2; // person
            int s;
            cin >> t >> n2 >> m2 >> s;
            if (s == 1) {
                if (pc[m2] == 0) {
                    start[m2] = t;
                }
                pc[m2]++;
            } else {
                pc[m2]--;
                if (pc[m2] == 0) {
                    int end = t;
                    for (int loop = start[m2]; loop < end; loop++) {
                        time[m2][loop] = 1;
                    }
                }
            }
        }
        /*
           for (int i = 1; i <= m; i++) {
           int count = 0;
           for (int j = 0; j < MAX_T + 1; j++) {
           count += time[i][j];
           }
           cout << i << " " << count << endl;
           }
         */
        int q;
        cin >> q;
        for (int i = 0; i < q; i++) {
            int s;
            int e;
            int m2;
            cin >> s >> e >> m2;
            int count = 0;
            for (int j = s; j < e; j++) {
                count += time[m2][j];
            }
            cout << count << endl;
        }

    }
    return 0;
}

Measured memory_bytes: 50976
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = list(input())
nya = list("keyence")
slen = len(s)
for i in range(slen):
    #rint(s[:i],nya[:i],s[-7+i:],nya[-7+i:])
    if s[:i] == nya[:i] and s[-7 + i:] == nya[-7 + i:]:
        print('YES')
        exit()
print('NO')


Measured memory_bytes: 3316
# Problem: https://atcoder.jp/contests/abc080/tasks/abc080_b
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())
#   def MI1(): return map(int1, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


yes = "Yes"


no = "No"


def solver(checkNum):
    result = no
    checkNumStr = str(checkNum)
    harshedNum = 0
    for j in range(0, len(checkNumStr)):
        harshedNum = harshedNum + int(checkNumStr[j])
    if checkNum % harshedNum == 0:
        result = yes
    return result


if __name__ == "__main__":
    print("{}".format(solver(II())))


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int A, B, C;
        cin >> A >> B >> C;

        if (A+B>=C)
        {
                cout << "Yes" << endl;
        } else{
                cout << "No" << endl;
        }

        

        return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]){
		double[] r = new double[4];
		
		Scanner scn = new Scanner(System.in);
		String inl = scn.nextLine();
		String[] part = inl.split(" ");
		for(int i = 0 ; i < 4 ; i++){
			r[i] = Double.parseDouble(part[i]);
		}
		System.out.println(Math.sqrt(Math.pow( (r[0] - r[2]) , 2) + Math.pow( (r[1] - r[3]) , 2)));
	}
}

Measured memory_bytes: 17344
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		StringBuilder sb = new StringBuilder();
		int length = S.length();
		
		for (int i=0; i<length; i++) {
			sb.append("x");
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(true) {
			int H = scan.nextInt();
			int W = scan.nextInt();

			if(H == 0 && W == 0) {
				break;
			}

			for(int i = 0; i < H; i++) {
				for(int j = 1; j < W; j++) {
					System.out.print("#");
				}
				System.out.println("#");
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 36896
n=int(input())

x=[]
tot=0

for i in range(100):
	if n==0:
		x.append(0)
		break
	if (n-tot)%((-2)**(i+1))!=0:
		x.append(1)
		tot+=(-2)**i
		if tot==n:
			break
	else:
		x.append(0)

res=''

for i in x[::-1]:
	res=res+str(i)
        
print(res)

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	int cnt0=0, cnt1=0;
	for(int i=0;i<s.size();i++){
		if(s[i] == '0') cnt0++;
		if(s[i] == '1') cnt1++;
	}
	cout << min(cnt0,cnt1)*2 << "\n";
	return 0;
}

Measured memory_bytes: 512
a = gets.chomp
b = gets.chomp
c = gets.chomp
players = {
  'a' => a.chars,
  'b' => b.chars,
  'c' => c.chars,
}

next_player = 'a'
result = nil
while result == nil
  cards = players[next_player]
  if cards.empty?
    result = next_player.upcase()
    break
  end
  next_player = cards.shift()
end

puts result


Measured memory_bytes: 1788
import math

a, b, h, m = map(int, input().split())
i = (60 * h + m) / 2
j = 6 * m
t = i - j
if t > 180:
    t = (360 - i) + j
c = math.sqrt(math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(math.radians(t)))
print(c)

Measured memory_bytes: 62316
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=20050;
const ll inf=0x3f3f3f3f3f;
struct point{
	long double x,y,r;
}a[MAX];

long double dis[MAX];
int vis[MAX];
ll n,m,point;// 点数 边数  起始点
vector<pair<ll,long double> >v[MAX];
struct node
{
    ll id;
    long double d;
    node(){};
    node(int id,long double d):id(id),d(d){};
    bool operator <(const node&a)const{
         return d>a.d;
    }
};
void dijkstra(int point)
{
    for(int i=1;i<=n+2;i++){
        vis[i]=0;dis[i]=1.00*inf;
    }
    dis[point]=0;
    priority_queue<node>q;  //大根堆，优先队列在logn内可以从大到小排序
    q.push(node(point,0));
    node temp;
    while(!q.empty())
    {
        temp=q.top();q.pop();
        if(vis[temp.id]==1)continue;
        vis[temp.id]=1;
        for(int i=0;i<v[temp.id].size();i++)
        {
            int j=v[temp.id][i].first;
            long double k=v[temp.id][i].second;
            if(temp.d+k<dis[j]&&vis[j]==0)
            {
                dis[j]=temp.d+k;
                q.push(node(j,dis[j]));
            }
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	ll xs,ys,xt,yt;cin>>xs>>ys>>xt>>yt;
	cin>>n;
	a[1].x=xs;a[1].y=ys,a[1].r=0;
	for(int i=2;i<=n+1;i++)
		cin>>a[i].x>>a[i].y>>a[i].r;
	a[n+2].x=xt;a[n+2].y=yt,a[n+2].r=0;
	for(int i=1;i<=n+2;i++){
		for(int j=i+1;j<=n+2;j++){
			long double s=(long double)sqrt(1.00*(a[i].x-a[j].x)*(a[i].x-a[j].x)+1.00*(a[i].y-a[j].y)*(a[i].y-a[j].y))-1.00*a[i].r-1.00*a[j].r;
			if(s<0)s=0;
			v[i].push_back(make_pair(j,s));
			v[j].push_back(make_pair(i,s));
		}
	}	
	point=1;
	dijkstra(point);
	cout<<fixed<<setprecision(9)<<dis[n+2]<<endl;
   return 0;
} 

Measured memory_bytes: 44724
#include <iostream>
#include <cstdio>
#include <string>
#include <bits/stdc++.h>
#include <set>
#include <list> //list<???> a; a.push_back ,insert(追加したい要素),a.sort(),参照できない
#include <vector> //vector<???> a; a.push_back,sort(a.begin(),a.end());a[i]
//配列 int a[N];a[i]=追加したい要素;sort(a,a+N);a[i]
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)


//using namespace std;
//


int main(){
  string moji;cin>>moji;

  int j;
  int cnt;
  for(int i=1;i<moji.size();i++){
    if (moji[i]!=moji[i-1]){
      cnt+=1;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import numpy as np
mod = 1000000000+7
n = int(input())
A = [int(a) for a in input().strip().split()]
s = sum(A)%mod
S = 0

for a in A:
    s = s-a
    S += (s*a)%mod
S = S%mod
print(S)


Measured memory_bytes: 50000
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

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

	long long min = 10000000;
	
	long long i = 1, j = N / i;
	while(i <= j){
		if(N % i != 0){
			i++;
			j = N / i;
			continue;
		}
		int tmp_A = to_string(i).length();
		int tmp_B = to_string(j).length();
		int tmp_min = MAX(tmp_A, tmp_B);
		min = MIN(min, tmp_min);

		i++;
		j = N / i;
	}
	
	cout << min << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long a, b, c, d;
    long long count = 0;
    bool pushed[101] = {};
    
    cin >> a >> b >> c >> d;
    for(int i = a; i < b; i++)
        pushed[i] = true;
    for(int i = c; i < d; i++)
        if(pushed[i])
            count++;
    
    cout << count << endl;
    
    return 0;
}

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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_debug(...) do { printf("DEBUG: line %d: %s: ", __LINE__, __PRETTY_FUNCTION__); printf(__VA_ARGS__); } while(0)
  #define pr_vars(...) do { pr_debug(" "); pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_debug(...) do { } while(0)
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;

template<typename X, typename Y> ostream &operator<< (ostream &fout, const pair<X, Y> &p)
{ fout << '{' << p.first << ", " << p.second << "} "; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (const auto &el : vec) fout << el << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cout << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cout << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-9;
constexpr double INF = 2e18;

using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

constexpr ll MAX = 1e3 + 5;

int main()
{
    ll res = 0;
    ll n; cin >> n;
    res = n / 3;

    cout << res << endl;
    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    
    if (a > b){
        cout << "a > b" << endl;
        
    }
    
    else if (a < b){
        cout << "a < b" << endl;
        
    }
    
    else{
        cout << "a == b" << endl;
        
    }
}



Measured memory_bytes: 3100
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int tmp;

        tmp = a;
        a = b;
        b = tmp;

        tmp = a;
        a = c;
        c = tmp;
        
        System.out.println(a + " " + b + " " + c);
    }
}

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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	ll n, k;
	cin >> n >> k;

	vector<int> p(n);
	rep(i, n){
		cin >> p[i];
		p[i]--;
	}

	vector<ll> c(n);
	rep(i, n) cin >> c[i];

	ll ans = -1e12;

	rep(i, n){
		ll t = k;
		ll sco = 0;
		ll cnt = 0;
		int x = i;
		while(t > 0){
			x = p[x];
			sco += c[x];
			t--;
			cnt++;
			chmax(ans, sco);
			if(x == i) break;
		}

		ll q = (t / cnt == 0 ? 0 : t / cnt - 1);
		ll r = (t / cnt == 0 ? t % cnt : t % cnt + cnt);

		ll t2 = sco + sco * q;
		chmax(ans, t2);
		int y = p[i];
		rep(j, r){
			t2 += c[y];
			chmax(ans, t2);
			y = p[y];			
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

const int dx[] = { 0,1 };
const int dy[] = { 1,0 };
char mp[10][10];
bool used[10][10];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<int>> cnt(10, vector<int>(10));
	for (int i = 1; i <= n; ++i) {
		int a = i % 10;
		int b = i;
		while (b >= 10) b /= 10;
		cnt[a][b]++;
	}
	int ans = 0;
	rep(i, 10)rep(j, 10) ans += cnt[i][j] * cnt[j][i];
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int A, B, x;
  int flag = 0;

  unused = scanf("%d %d", &A, &B); //8%のときA円，10％のときB円 1000

  x = 1;
  while(x<1010 && flag==0){
    if((int)(x*0.08) == A && (int)(x*0.1) == B){
      printf("%d", x);
      flag = 1;
    }
    x++;
  }
  if(flag == 0) printf("%d", -1);
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
// import java.util.Arrays;
// import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));


        StringTokenizer st = new StringTokenizer(f.readLine());
        int N = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(f.readLine());

        double[] p = new double[N];
        for (int i = 0; i < N; i++) {
            p[i] = Double.parseDouble(st.nextToken());
        }
        // note that the probabilities of tails are 1 - p[i]


        double[][] dp = new double[N+1][N+1];

        dp[0][0] = 1;
        for (int _i = 1; _i < N+1; _i++) {
            int i = _i - 1;
            // populate the entire first row
            dp[0][_i] = dp[0][_i-1] * (1 - p[i]);
        }

        // last item in the 1st row is 0 Heads in N Rounds

        for (int _i = 1; _i < N+1; _i++) {
            // int i = _i - 1;

            for (int _j = 1; _j < N+1; _j++) {
                int j = _j - 1;
                dp[_i][_j] = dp[_i-1][_j-1] * p[j] + dp[_i][_j-1] * (1 - p[j]);
            }
        }

        // sum up all with more than N/2 heads
        double res = 0;
        for (int i = N/2 + 1; i < N + 1; i++) {
            res += dp[i][N]; // the last column
        }

        /*for (double[] i : dp) {
            for (double j : i) {
                System.out.print(String.valueOf(j) + " ");
            }
            System.out.println();
        } */

        System.out.println(res);


    }
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

bool used[10];
int N;
set<string> se;

void dfs(int i, string s) {
    if (i == N) {
        se.insert(s);
        return;
    }

    for (int j = 1; j <= N; j++) {
        if (used[j]) continue;
        used[j] = true;
        dfs(i + 1, s + to_string(j));
        used[j] = false;
    }
}

int main() {
    cin >> N;

    dfs(0, "");

    string P = "";
    string Q = "";
    rep(i, N) {
        string p;
        cin >> p;
        P += p;
    }

    rep(i, N) {
        string q;
        cin >> q;
        Q += q;
    }

    int a = distance(se.begin(), se.find(P));
    int b = distance(se.begin(), se.find(Q));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 3968
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    if(x == 1 || x == 2*n-1){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    vector<int> ans(2*n-1, -1);
    ans[n-1] = x;
    ans[n-2] = x - 1;
    ans[n] = x + 1;
    int cnt = 1;
    rep(i,2*n-1){
        if(ans[i] != -1) continue;
        while(x-1 <= cnt && cnt <= x+1) ++cnt;
        ans[i] = cnt++;
    }
    rep(i,2*n-1) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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 n;
  cin >> n;
  ll ans = 0;
  rep(i,n) ans += ll(i+1)*(n-i);
  rep(i,n-1){
    ll u,v;
    cin >> u >> v;
    if(u>v)swap(u,v);
    ans -= u*(n-v+1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3660
N, Y = map(int, input().split())

ans = []
for i in range(N+1):
    for j in range(N-i+1):
        k = N-i-j
        if 10000*i + 5000*j + 1000*k == Y:
            ans.append([i,j,k])

if len(ans) == 0:
    print("-1 -1 -1")
else:
    print(ans[0][0], ans[0][1], ans[0][2])

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

int main(void){
    int n,l,x;
    cin>>n;
    list<int> list;
    char com[20];
    for(l=0;l<n;l++){
        scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&x);
            list.push_front(x);
        }
        else if(com[6]=='F'){
            //cerr<<vec[0]<<endl;
            list.pop_front();
        }
        else if(com[6]=='L'){
            //cerr<<vec.size()<<endl;
            list.pop_back();
        }
        else{
            scanf("%d",&x);
            for(auto i=list.begin();i!=list.end();i++){
                if(*i==x){
                    list.erase(i);
                    break;
                }
            }
        }
    }
    for(auto i=list.begin();i!=list.end();i++){
        if(i!=list.begin())cout<<" ";
        cout<<*i;
    }
    cout<<endl;
}


Measured memory_bytes: 34496
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class BRowToColumn {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<string> a(n);
        for(auto&i:a) in>>i;
        bool f=true;
        vector<int> v(n);
        vector<bool> c(n),h(n,true);
        fr(i,n) fr(j,n){
            if(a[i][j]=='#') c[j]=true,++v[i],f=false;
            else h[j]=false;
        }
        if(f){
            out<<-1<<endl;
            return;
        }
        int b=0;
        fr(i,n) if(h[i]) ++b;
        int ans=2*n,tmp;
        fr(j,n){
            if(c[j])tmp=0;
            else tmp=1;
            tmp+=n-v[j];
            ans=min(ans,tmp);
        }
        out<<ans+n-b<<endl;
    }
};

int main() {
    BRowToColumn solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for(i, m, n) for(int i = m;i < n;i++)
#define forr(i, m, n) for(int i = m;i >= n;i--)
#define sort(v, n) sort(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

bool a[1001] = {0};

int main(){
    for(i, 1, 1000){
        for(j, 2, 1000){
            int n = pow(i, j);
            if(n <= 1000) a[n] = 1;
            else if(n > 1000) break;
        }
    }
    int x, m;
    cin >> x;
    for(i, 1, x+1) if(a[i] == 1) m = i;
    cout << m << endl;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  cout << ((a * 1 + b * 5 + c * 10 + d * 50 + e * 100 + f * 500) >= 1000 ? 1 : 0) << endl;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> B;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
        B.emplace_back(A[i],1);
    }
    rep(i,M){
        ll b,c;
        cin >> b >> c;
        B.emplace_back(c,b);
    }
    sort(ALL(B));
    ll ans = 0,cnt = 0;;
    rrep(i,B.size()){
        if(cnt + B[i].second <= N){
            ans += B[i].first * B[i].second;
            cnt += B[i].second;
        }else{
            ans += B[i].first * (N - cnt);
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7152
#include<iostream>
#include<string>
#include <cmath>
#include <ctype.h>
#include<vector>
#include<algorithm>
using namespace std;
int N;
string s;
vector<int> v;
int main() {
    cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
k=0
for i in range(n-1):
	if h[i]>h[i+1]+1:
		print("No")
		break
	elif h[i]==h[i+1]+1:
		h[i+1]+=1
		k+=1
	else:
		k+=1
if k==n-1:
	print("Yes")


Measured memory_bytes: 14224