akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("1222");
            //1+2+2+2=7
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("0290");
            //0-2+9+0=7
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3242");
            //3+2+4-2=7
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string StrABCD = InputList[0];
        int A = StrABCD[0] - '0';
        int B = StrABCD[1] - '0';
        int C = StrABCD[2] - '0';
        int D = StrABCD[3] - '0';

        for (int I = 1; I <= 2; I++) {
            for (int J = 1; J <= 2; J++) {
                for (int K = 1; K <= 2; K++) {
                    string Siki = "";
                    int SumVal = 0;

                    Siki += A.ToString();
                    SumVal += A;

                    Action<int, int> wkAct = (pSign, pVal) =>
                    {
                        if (pSign == 1) {
                            SumVal += pVal;
                            Siki += "+";
                        }
                        else {
                            SumVal -= pVal;
                            Siki += "-";
                        }
                        Siki += pVal.ToString();
                    };

                    wkAct(I, B);
                    wkAct(J, C);
                    wkAct(K, D);

                    if (SumVal == 7) {
                        Console.WriteLine("{0}=7", Siki);
                        return;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 201;
const int INF = 1e6 + 239;

int bad = 0;
int used[N];
int color[N];

int n;

int g[N][N];
int d[N][N];

void dfs(int cur, int c) {
	used[cur] = 1;
	color[cur] = c;
	for (int i = 0; i < n; i++) {
		if (g[cur][i]) {
			if (used[i]) {
				if (color[cur] == color[i]) bad = 1;
			} else {
				dfs(i, c ^ 1);
			}
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			char c;
			cin >> c;
			if (c == '1') {
				g[i][j] = 1;
				d[i][j] = 1;
			} else {
				g[i][j] = 0;
				d[i][j] = INF;
			}
		}
		d[i][i] = 0;
	}
	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]);
			} 
		}
	}
	{
		for (int i = 0; i < n; i++) {
			if (!used[i]) {
				dfs(i, 0);
			}
		}
		if (bad) {
			cout << -1 << endl;
			return 0;
		}
	}
	int all = 0;
	fill(used, used + n, -1);
	for (int i = 0; i < n; i++) {
		if (used[i] == -1) {
			vector<int> c;
			for (int j = 0; j < n; j++) {
				if (d[i][j] != INF) c.push_back(j);
			}
			for (auto j : c) {
				used[j] = i;
			}
			int ans = 2;
			for (auto first : c) {
				int ok = 1;
				int mx = 0;
				for (auto u : c) {
					mx = max(mx, d[first][u]);
					for (auto v : c) {
						if (!g[u][v]) continue;
						ok &= (abs(d[first][u] - d[first][v]) == 1);
					}
				}
				if (ok) {
					ans = max(mx + 1, ans);
				}
			}
			all += ans;
		}
	}
	cout << all << endl;
}

Measured memory_bytes: 3512
#include <iostream>
#include <map>

using namespace std;

int main() {
  int n;
  map <string, bool> T;
  string prev_str;
  cin >> n;
  cin >> prev_str;
  T[prev_str] = true;
  // cout << "--------" << endl;
  for (int i = 1; i < n; i++) {
    string current_str;
    cin >> current_str;
    // cout << "prev:" << prev_str << ", current:" << current_str << endl;
    if (prev_str[prev_str.size()-1] != current_str[0]) {
      // cout << "[no1]" << "prev:" << prev_str << "[" << prev_str[prev_str.size()-1] << "], current:" << current_str << ","<< current_str[0] << endl;
      cout << "No" << endl;
      return 0;
    }
    prev_str = current_str;
    if (T[current_str]) {
      // cout << "no2" << "prev:" << prev_str << ", current:" << current_str << endl;
      cout << "No" << endl;
      return 0;
    }
    T[current_str] = true;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
lst = []
for _ in range(N):
    A, B = map(int, input().split())
    lst.append([A, -B])
lst.sort()

ans = 0
index = 0
import heapq
hq = []
for i in range(M):
    while index < N and lst[index][0] <= i + 1:
        heapq.heappush(hq, lst[index][1])
        index += 1
    if len(hq) > 0:
        ans -= heapq.heappop(hq)
    # print ('ans, i', ans, i)
print (ans)

    


Measured memory_bytes: 21132
def main():
    h1, m1, h2, m2, k = map(int, input().split())

    t1 = h1 * 60 + m1
    t2 = h2 * 60 + m2
    ans = (t2 - t1) - k

    print(ans)

if __name__ == '__main__':
    main()


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const ll MAX = 10000;
static const ll INFTY = 1e12;

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

// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
using P = pair<ll, ll>;
// 入力
// 入力
ll h, w;
ll startX, startY, endX, endY;
vector<vector<char>> s;
vector<vector<ll>> cnts; // 魔法使った回数


int main() {

  string S, T;
  cin >> S >> T;
  ll min_ = 10000;

  REP(i, S.length()-T.length()+1){
    ll ans = 0;
    REP(j, T.length()){
      if(S[i+j]!=T[j])ans++;
    }
    min_ = min(ans, min_);
  }
  cout << min_ << endl;
   
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int md = 1e9 + 7;

int mul(int a, int b) {
  return ((ll)a * b) % md;
}

void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

int sub(int a, int b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}

int power(int a, ll b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> fac(n + 1);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
  vector <int> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    if (p[i] != -1) --p[i];
  }
  vector <int> par(n);
  vector <int> sz(n, 1);
  for (int i = 0; i < n; ++i) par[i] = i;
  function <int(int)> get = [&] (int a) {
    return (a == par[a] ? a : par[a] = get(par[a]));
  };

  auto join = [&] (int a, int b) {
    a = get(a);
    b = get(b);
    if (a != b) {
      par[a] = b;
      sz[b] += sz[a];
    }
  };

  for (int i = 0; i < n; ++i) {
    if (p[i] != -1) {
      join(i, p[i]);
    }
  }

  int cmp = 0, fr = 0;
  vector <int> szs;
  for (int i = 0; i < n; ++i) {
    if (p[i] == -1) {
      ++fr;
      szs.push_back(sz[get(i)]);
    }
    if (get(i) == i) {
      ++cmp;
    }
  }
  int ans = mul(sub(cmp, fr), power(n - 1, fr));

  vector <int> coef(fr + 1);
  coef[0] = 1;
  for (int i = 0; i < (int)szs.size(); ++i) {
    for (int j = fr; j > 0; --j) {
      add(coef[j], mul(coef[j - 1], szs[i]));
    }
  } 
  for (int k = 2; k <= fr; ++k) {
    add(ans, mul(coef[k], mul(power(n - 1, fr - k), fac[k - 1])));  
  }
  for (int s : szs) {
    add(ans, mul(s - 1, power(n - 1, fr - 1)));
  }
  ans = md - ans;
  add(ans, mul(n, power(n - 1, fr)));
  cout << ans << '\n';
}




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

using namespace std;

int n,k;
int arr[100005];

int main()
{
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> arr[i];
	sort(arr,arr+n);
	int ans=0;
	for(int i=0;i<k;i++) ans+=arr[i];
	cout << ans << endl;
	return 0;
}

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

int N;
vector<double> v;

void solve() {
  priority_queue<double, vector<double>, greater<double>> guzai;
  for (int i = 0; i < N; i++) {
    guzai.push(v[i]);
  }
  while (guzai.size() != 1) {
    double gu_1, gu_2;
    gu_1 = guzai.top();
    guzai.pop();
    gu_2 = guzai.top();
    guzai.pop();
    guzai.push((gu_1 + gu_2) * 0.5);
  }
  cout << guzai.top() << '\n';
}

int main() {
  cin >> N;
  v.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  solve();
  return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> D(N);
  for(int i=0;i<N;i++){
    cin>>D.at(i);
  }
  sort(D.begin(),D.end());
  int lastD=0,count=0;
  for(int i=0;i<N;i++){
    if(lastD!=D.at(i)){
      count++;
    }
    lastD=D.at(i);
  }
  cout<<count;
}


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

int main(){
    int N, T;  cin >> N >> T;
    int minC = 1 << 30;
    for(int i=0; i<N; i++){
        int c, t;  cin >> c >> t;
        if(t <= T) minC = min(c, minC);
    }

    if(minC == 1 << 30) cout << "TLE" << endl;
    else cout << minC << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.SQLOutput;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int N = sc.nextInt();
        int[] arr = new int[N];
        for (int i=0; i<N; i++) {
            arr[i] = sc.nextInt();
        }
        boolean flag = true;
        arr[0]--;
        int max = arr[0];
        for (int i=1; i<N; i++) {
            if (arr[i]>max) {
                arr[i]--;
                max = arr[i];
            } else if (arr[i]<max) {
                flag = false;
            }
        }
        if (flag) System.out.println("Yes");
        else System.out.println("No");
    }
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 41952
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    string N;
    cin >> N;
    int r = 0;
    for (auto &c : N) {
        r += (c - '0');
        r %= 9;
    }
    string res = "Yes";
    if (r % 9) {
        res = "No";
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3776
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a,b;
    char op;
    
    while(true){
        cin >> a >> op >> b;
        if (op == '?'){
            break;
        } 
        else if (op == '+'){
            cout <<(a+b) << endl;
        }
        else if (op == '*'){
            cout << (a*b) << endl;
        }
        else if (op == '-'){
            cout << (a-b) << endl;
        }
        else if (op =='/'){
            cout << (a/b) << endl;
        }
        
    }
}




Measured memory_bytes: 3104
#include <iostream>

using namespace std;
#define MAX 100000
typedef long long ll;

int n, k;
ll T[MAX];

int check(ll P) {
    int i = 0;
    for (int j = 0; j < k; ++j) {
        ll s = 0;
        while (s + T[i] <= P) {
            s += T[i];
            ++i;
            if (i == n) return n;
        }
    }
    return i;
}

int solve() {
    ll left = 0;
    ll right = 100000 * 10000; // 荷物の個数*１個あたりの最大重量
    ll mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) right = mid;
        else left = mid;
    }
    return right;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> T[i];
    }
    ll ans = solve();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3868
S = input()
N = len(S)

left_end = (N - 1)//2
right_start = (N + 3) //2 - 1

left_S = S[:left_end]
right_S = S[right_start:]

rev_left_S = left_S[::-1]
rev_right_S = right_S[::-1]

check_1 = False
if (left_S == rev_right_S):
  check_1 = True

check_2 = False
if (left_S == rev_left_S):
  check_2 = True

check_3 = False
if (right_S == rev_right_S):
  check_3 = True

result = 'Yes' if (check_1 and check_2 and check_3) else 'No'

print(result)


Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	s := nextLine()
	ret := ""

	for i := 0; i < len(s); i++ {
		if s[i] == '0' || s[i] == '1' {
			ret += string(s[i])
		} else if s[i] == 'B' && len(ret) > 0 {
			ret = ret[:len(ret)-1]
		}
	}

	fmt.Println(ret)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define M 1000000007
#define INF 999999999
#define EPS 1e-9
#define pb push_back
#define mp make_pair
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define MAX 1000005
#define fs first
#define sc second 
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector <ii> vii;
typedef vector <ll> vi;


int main()
{
// freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
 cin.tie(0);
 ll n,cnt=0,num,c1=0,c2=0,c3=0;
 vi v;
 cin>>n;
 for(ll i=0;i<n;i++)
 {
    cin>>num;
    if(num%4==0)
        c1++;
    else if(num%2==0)
        c2++;
    else
        c3++;
 }
 if(2*c1+1>=n)
    cout<<"Yes"<<endl;
else if(2*c1+c2>=n)
    cout<<"Yes"<<endl;
else
    cout<<"No"<<endl;


return 0;

}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll n,l;
ll a[100000];
bool fallen[100000];
bool ko[100000];
priority_queue<P,vector<P>,greater<P> > q;
ll now=0;
void jud(ll x){
	if(x<0||n<=x||fallen[x]) return;
	if((x-1>0&&!ko[x-1]&&a[x-1]<a[x])||(x+1<n&&!ko[x+1]&&a[x+1]<a[x])) return;
	q.push(P(a[x]+now,x));
	fallen[x]=1;
	return;
}
int main()
{
	cin>>n>>l;
	rep(i,n){
		cin>>a[i];
		a[i]=l-a[i];
	}
	
	if(n>1&&a[0]<a[1]){
		q.push(P(a[0],0));
		fallen[0]=1;
	}
	if(n>2&&a[n-2]>a[n-1]){
		q.push(P(a[n-1],n-1));
		fallen[n-1]=1;
	}
	rep1(i,n-2){
		if(a[i-1]>a[i]&&a[i]<a[i+1]){
			q.push(P(a[i],i));
			fallen[i]=1;
		}
	}
	while(!q.empty()){
		P next=q.top();
		q.pop();
		//cout<<now<<endl;
		now=next.fr;
		ko[next.sc]=1;
		jud(next.sc-1);
		jud(next.sc+1);
	}
	cout<<now<<endl;
}

Measured memory_bytes: 4952
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
  int N,sum,maxval;
  cin>>N;
  sum = maxval = 0;
  for (int i = 0; i < N; i++) {
    int value;
    cin>>value;
    sum += value;
    maxval = max(maxval,value);
  }
  int ans = sum - (maxval / 2);
  cout<<ans<<endl;
  return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int n,ans=0,count=0;
  string s;
  cin>>n>>s;
  for(int i=1;i<n;i++){
  set<char> st1,st2;
  for(int j=0;j<i;j++) st1.insert(s[j]);
  for(int j=i;j<n;j++) st2.insert(s[j]);
  for(int j : st1) for(int k : st2) if(j==k) count++;
  ans=max(ans,count);
  count=0;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
def is_prime(q):
    if q < 2 or q&1 == 0: return False
    return pow(5, q-1, q)*pow(7, q-1, q) == 1
  
def main():
  mod = 10**9+7
  n = int(input())
  ans = 1
  if n == 1:
    print(1)
    exit()
  
  b = [2]
  for i in range(2,min(n+1,998)):
    if i == 5 or i == 7:
      b.append(i)
    if i == 561:
      continue
    if is_prime(i):
      b.append(i)
      
  for i in b:
    p = i
    cnt = 1
    chk = 1
    for j in range(10):
      chk += n//p
      if p > n:
        ans *= chk
        ans %= mod
        chk = 1
        break
      p *= i
      
  print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL a[1010];
int flag[1000010];
int n,k;
vector<LL>s;
bool cmp(LL a,LL b){
    return a>b;
}
int main(){
    cin>>n>>k;
    a[0]=0;
    for(int i=1;i<=n;i++){
        LL x;
        scanf("%lld",&x);
        a[i]=x+a[i-1];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=n;j++){
            LL x=a[j]-a[i];
            s.push_back(x);
        }
    }
    sort(s.begin(),s.end(),cmp);
    LL x=s[0];
    int bit=0;
    //cout<<x<<endl;
    while(x){
        bit++;x>>=1;
    }
    //cout<<bit<<endl;
    LL ans=0;
    LL y=1LL<<bit;
    while(y){
        int cnt=0;
        for(int i=0;i<s.size();i++){
            if(flag[i])continue;
            if(y&s[i])cnt++;
            //cout<<y<<" "<<(y&s[i])<<endl;
        }
        //cout<<cnt<<endl;
        if(cnt>=k){
            ans=ans|y;
            for(int i=0;i<s.size();i++){
                if(flag[i])continue;
                if((y&s[i])==0)flag[i]=1;
                    //cout<<i<<endl;
            }        
        }
        //cout<<y<<" "<<ans<<endl;
        y>>=1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

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

	ll n;
	cin>>n;
	ll len = 1;
	ll cur = 0;
	ll p = 26;
	while(cur+p < n){
		cur += p;
		++len;
		p = p*26;
	}

	n -= (cur+1);
	vector<int> ans(len);
	for(int i=len-1;i>=0;i--){
		ll idx = n%26;
		ans[i] = idx;
		n /= 26;
	}

	for(int i=0;i<len;i++)
		cout<< (char)('a'+ans[i]);
	cout<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int n;
const int MAX = 1e5 + 1;
const int INF = 1e9;

int dp[MAX];
int rdp[MAX];

int gcd(int a, int b) {
    while (b != 0) {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int solve(vector<int> &nums) {

    // dp[i] = gcd by ith
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i] = gcd(nums[i - 1], dp[i - 1]);
    }

    // rdp[i] = gcd by
    rdp[n] = 0;
    for (int i = n - 1; i >= 0; --i) {
        rdp[i] = gcd(nums[i], rdp[i + 1]);
    }

    int ret = -INF;
    for (int i = 0; i < n; ++i) {
        ret = max(ret, gcd(dp[i], rdp[i + 1]));
    }

    return ret;
}


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;

    vector<int> nums(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }

    int ret = solve(nums);
    cout << ret << endl;

    return 0;
}


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

using namespace std;
#define int long long
#define N 666666
int arr[N];
signed main(){
	int n;cin>>n;int s1=0,s0=0,s=0;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
		s=s^arr[i];
	} 
	if(!s) cout<<"Yes";else cout<<"No";
	return 0;
} 

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    ll a,b,c; cin >> a >> b >> c;
    ll ma = max(a,max(b,c));
    ll mi = min(a,min(b,c));
    ll mid = a+b+c - ma - mi;
    if(ma == 7 && mid == 5 && mi == 5)out("YES");
    else out("NO");
}

Measured memory_bytes: 3624
#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()
{
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define P pair
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl

bool check(str s)
{
    if(s.size()%2){
        return false;
    }else{
        string p=s.substr(0,s.size()/2),q=s.substr(s.size()/2,s.size()/2);
        if(p==q){
            return true;
        }else{
            return false;
        }
    }
}

int main(){
    sts(s);
    repr(i,s.size()){
        s.erase(i);
        if(check(s)){
            print(s.size());
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  
 ll N;cin>>N;
  ll ans=0;
  for(ll i=1;i<=N;i++) {
if(i%3!=0&&i%5!=0) {
ans+=i;
}
  }
  cout<<ans<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define ZERO(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int n;
vint a(110);
const int INF = 114514810;

int solve() {
    int ret = INF;
    for(int i=-100; i<=100; i++) {
        int cost = 0;
        rep(j,n) cost += (a[j] - i) * (a[j] - i);
        ret = min(ret, cost);
    }
    return ret;
}

int main() {
    while(cin>>n) {
        a.clear();
        rep(i,n) scanf("%d",&a[i]);
        int ans = solve();
        cout << ans << "\n";
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
class UnionFind{
private:
    std::vector<int> par;
    std::vector<int> rank;
public:
    void init(int N){
        par.resize(N);
        rank.resize(N);
        for(int a = 0;a < N;a++)
        {
            par[a]=-1;
            rank[a]=0;
        }
    }
    int root(int a)
    {
        if(par[a] < 0)return a;
        else return par[a] = root(par[a]);
    }
    void connect(int a,int b)
    {
        a = root(a);
        b = root(b);
        if(a==b)return;

        if(rank[a] < rank[b]){
            par[a] = b;
        }else{
            par[b] = a;
            if(rank[a] == rank[b])rank[a]++;
        }
    }
    bool check(int a,int b){
        a = root(a);
        b = root(b);
        if(a == b)return true;
        else return false;
    }
};
int main(){
    UnionFind Uni;
    CIN(N);CIN(Q);
    Uni.init(N);
    REP(a,Q){
        CIN(x);CIN(y);CIN(z);
        if(x == 0){
            Uni.connect(y, z);
        }else{
            if(Uni.check(y,z)){
                COUT(1);
            }else{
                COUT(0);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int r;
    cin>>r;
    string s;
    cin>>s;
    if(r%2) cout<<"No";
    else{
        int n=r/2;
        int flag=0;
        for(int i=0,j=n;i<n,j<r;i++,j++){
            if(s[i]==s[j]){
                flag=1;
             continue;
            }
            else{
                flag=0;
                cout<<"No";
                break;
            }
        }
        if(flag) cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
LL x[maxn], v[maxn];
multiset<LL> MS;
multiset<LL> :: iterator it;

int main(){
    int N;
    LL C;
    scanf("%d %lld", &N, &C);
    LL tmp = 0, tmp2 = 0, M = 0;
    for(int i = 1; i <= N; ++i) scanf("%lld %lld", x + i, v + i);
    for(int i = 1; i <= N; ++i){
        tmp += v[i];
        M = max(M, tmp - x[i]);
        MS.insert(tmp - x[i]);
    }
    for(int i = N; i >= 1; --i){
        it = MS.find(tmp - x[i]);
        MS.erase(it);
        if(MS.empty()) break;
        tmp -= v[i];
        tmp2 += v[i];
        LL MM = *MS.rbegin();
        M = max(M, MM + tmp2 - 2 * (C - x[i]));
    }

    for(int i = 1; i <= N / 2; ++i) swap(x[i], x[N-i+1]), swap(v[i], v[N-i+1]);
    for(int i = 1; i <= N; ++i) x[i] = C - x[i];

    MS.clear();
    tmp = 0, tmp2 = 0;
    for(int i = 1; i <= N; ++i){
        tmp += v[i];
        M = max(M, tmp - x[i]);
        MS.insert(tmp - x[i]);
    }
    for(int i = N; i >= 1; --i){
        it = MS.find(tmp - x[i]);
        MS.erase(it);
        if(MS.empty()) break;
        tmp -= v[i];
        tmp2 += v[i];
        LL MM = *MS.rbegin();
        M = max(M, MM + tmp2 - 2 * (C - x[i]));
    }
    printf("%lld\n", M);
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void){
    int n; cin >> n;
    int p[200005]={0};
    rep(i,n) cin >> p[i];
    int M[200005]={0};
    M[0] = p[0];
    rep(i,n-1){
        M[i+1] = min(M[i],p[i+1]);
    }
    int ans = 0;
    rep(i,n){
        if(p[i]<=M[i]) ans++;
    }
    cout << ans;
}







Measured memory_bytes: 1792
// Your code here!

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let nums: Vec<i32> = read_vec();
    let mut temp : i32 = nums[2];
    for i in 0..10{
        temp=nums[0]*temp-nums[1];
        println!("{:?}",temp);
    }
    
}




Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  string s ;
  cin>>s;
  int tot=0;
    for(int i = 0; i<n-2 ; i++){
      if (s[i]=='A'&& s[i+1]=='B'&& s[i+2]=='C')
        tot++;
          }
  cout << tot << endl;
}

Measured memory_bytes: 256
/*
TASK: Together
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define EPS 1e-9
#define ALL(x) (x).begin(),(x).end()
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define FOR(i,st,ed) for(int (i)=(st);(i)<(ed);(i)++)
typedef pair<int,int> PII;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long LL;

int N,M,T;
int tb[100005];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	int i,j,k;
	cin >> N;
	for(i=0;i<N;i++) {
        cin >> k;
        tb[k+1]++;
	}
	int Mc=1;
	for(i=1;i<=100001;i++)
        Mc=max(Mc,tb[i-1]+tb[i]+tb[i+1]);
    cout << Mc << '\n';
	return 0;
}


Measured memory_bytes: 640
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
T meguru_search(T ok, T ng, function<bool(T)> check){
    while(max(ok, ng) - min(ok, ng) > T(1)){
        T mid = (ok + ng) / T(2);
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

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

    lint n, k;
    cin >> n >> k;

    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }

    vector<lint> f(n);
    rep(i, n){
        cin >> f[i];
    }

    SORT(a);
    SORT_INV(f);

    auto check = [&](lint mid){
        lint cnt = 0;
        rep(i, n){
            if(a[i] * f[i] > mid){
                cnt += a[i] - mid / f[i];
                if(cnt > k){
                    return false;
                }
            }
        }
        return cnt <= k;
    };

    lint ans = meguru_search<lint>(LLINF, -1LL, check);

    cout << ans << endl;

    cout << flush;

    return 0;
}

Measured memory_bytes: 3456
#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 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] odd = sc.next().split("");
        String[] even = sc.next().split("");
        StringJoiner sj = new StringJoiner("");

        for (int i = 1; i <= odd.length + even.length; i++) {
            if (i % 2 == 0) {
                sj.add(even[i / 2 - 1]);
                continue;
            }
            sj.add(odd[i / 2]);
        }
        System.out.println(sj.toString());
    }

}


Measured memory_bytes: 21460
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(n, m, d):
    t = (n-d)
    if d != 0:
        t *= 2
    return t/(n**2) * (m-1)


def main():
    n, m, d = read_int_n()

    
    print(slv(n, m, d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6476
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,q,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n;
        ll a[n],ans=1000;
        FOR(i,0,n)  cin>>a[i];
        FOR(i,0,n-1)
        {
            k = 0;
            if(a[i+1]>a[i]){
                k = ans/a[i];
                ans -= a[i]*k;
            }
            ans += a[i+1]*k;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(){
  string a,b;
  int n,c,d,ans=0;
  cin>>a>>n;
  c=a.size();
  for(int i=0;i<n;i++){
    cin>>b;
    d=b.size();
    b=b+b;
    for(int i=0;i<d;i++){
      if(b.substr(i,c)!=a)continue;
      ans++;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1212
s = int(input())
a = [0 for i in range(10**6+1)]
cnt = [0 for i in range(10**6+1)]

def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1

for i in range(1, 10**6):
    if i == 1:
        a[i] = s
    else:
        a[i] = f(a[i-1])

    if cnt[a[i]] == 0:
        cnt[a[i]] += 1
    else:
        print(i)
        break


Measured memory_bytes: 115532
a=[]
m1,m2=0,0
ct=0
t=input()
for i in range(t):
    n=input()
    a.append(n)
    if n>m1:
        m2=m1
        m1=n
        ct=i
    elif n>m2:
        m2=n
for i in range(t):
    if i==ct:
        print m2
    else:
        print m1


Measured memory_bytes: 16744
#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() {
  int n;
  string s;
  cin >> n >> s;
  int a = 0, b = 0;
  rep(i,n) if (s[i] == 'R') a++;
  int ans = max(a,b);
  rep(i,n) {
    if (s[i] == 'R') a--;
    else b++;
    int now = max(a,b);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3760
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

T = [0, 1, 2, 3]
E = [0]*N
def dfs(i):
    if i == N:
        return solve()
    r = 10**18
    for k in T:
        E[i] = k
        r = min(r, dfs(i+1))
    return r
def solve():
    a = b = c = 0
    p = q = r = 0
    for i in range(N):
        if E[i] == 1:
            a += L[i]
            p += 1
        elif E[i] == 2:
            b += L[i]
            q += 1
        elif E[i] == 3:
            c += L[i]
            r += 1
    if not p or not q or not r:
        return 10**18
    return (p+q+r-3)*10 + abs(A - a) + abs(B - b) + abs(C - c)
print(dfs(0))

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }

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

    string S;
    std::cin >> S;

    string S2 = "";
    REP(i, S.size()) {
        if(i != S.size() - 1 && S.substr(i, 2) == "BC") {
            S2 += "D";
            i++;
        }
        else {
            S2 += S[i];
        }
    }

    ll ans   = 0;
    ll a_cnt = 0;
    REP(i, S2.size()) {
        switch(S2[i]) {
            case 'A': {
                a_cnt++;
                break;
            }
            case 'D': {
                ans += a_cnt;
                break;
            }
            default: {
                a_cnt = 0;
                break;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 916
from operator import itemgetter

N = int(input())
ins = [list(input().split()) for _ in range(N)]

res = []
for i, row in enumerate(ins):
    row = [i+1] + [row[0]] + [int(row[1])]
    res.append(row)

# 点数でソート
res.sort(key=itemgetter(2), reverse=True)

# 市名で辞書式ソート
res.sort(key=itemgetter(1))

for i in res:
    print(i[0])


Measured memory_bytes: 3060
/**
 *    author:  lets
 *    created: 2020-06-07 14:18:59 JST
 **/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  unsigned long long ans = (n * (n + 1)) / 2 - n;
  cout << ans << '\n';
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;

  return 0;
}


Measured memory_bytes: 3624
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string ring = Console.ReadLine();
            string target = Console.ReadLine();

            ring += ring;
            while (ring.Length < target.Length * 2)
                ring += ring;

            Console.WriteLine(ring.Contains(target) ? "Yes" : "No");
        }
    }
}

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


using namespace std;

const int maxi=1e6+2;
const long long mo=1e9+7;
int n;
long long dp[20][20][500];
string s1,s2,s11,s22;
int main()
{

   cin>>n;

   cin>>s1;
   cin>>s2;



   for (int i=0;i<n;i++)
    for (int j=0;j<3;j++)
        for (int k=0;k<3;k++)
            if (s1[i]==s2[i] && k==j)
    {
            if (i==0) dp[j][k][i]=1; else
             {
                 for (int j1=0;j1<3;j1++)
                    for (int k1=0;k1<3;k1++)
                    if (j1!=j && k1!=j) dp[j][k][i]=(dp[j][k][i]+dp[j1][k1][i-1])%mo;
             }
    } else
    if (s1[i]!=s2[i] && k!=j)
    {
        if (i==0) dp[j][k][i]=1; else
            if (s1[i-1]==s1[i]) dp[j][k][i]=dp[j][k][i-1]; else
        {
            for (int j1=0;j1<3;j1++)
                    for (int k1=0;k1<3;k1++)
                    if (j1!=j && k1!=k) dp[j][k][i]=(dp[j][k][i]+dp[j1][k1][i-1])%mo;
        }
    }

  long long ans=0;

  for (int i=0;i<3;i++)
  for (int j=0;j<3;j++)
   ans=(ans+dp[i][j][n-1]) %mo;

   cout<<ans<<"\n";///////////
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	var n int
	fmt.Scan(&n)
	w := make([]int, n)
	for i := range w {
		fmt.Scan(&w[i])
	}
	min := 10001
	for i := 1; i < n; i++ {
		var f, l int
		for _, v := range w[:i] {
			f += v
		}
		for _, v := range w[i:] {
			l += v
		}
		if abs(f-l) < min {
			min = abs(f - l)
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200005];
ll b[200005];
ll c[200005];
int main(void){
	int n,k; cin>>n>>k;
	string S; cin>>S;
	int t=0;
	int s=0;
	a[t]++;
	if(S[0]=='0'){
		c[s]=t;
		s++;
	}
	for(int i=1;i<S.size();i++){
		if(S[i]==S[i-1]){
			a[t]++;
		}else{
			t++;
			a[t]++;
			if(S[i]=='0'){
				c[s]=t;
				s++;
			}
		}
	}
	for(int i=1;i<=t+1;i++){
		b[i]=b[i-1]+a[i-1];
	}
	b[t+2]=b[t+1];
	ll ans=0;
	int K=2*k;
	if(s<=k){
		cout<<S.size()<<endl;
		return 0;
	}
	for(int i=0;i<s;i++){
		if(c[i]==0){
			ans=max(ans,b[K]);
		}
		ans=max(ans,b[c[i]+K]-b[c[i]-1]);
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	for(char s[80001];scanf("%s",s),s[0]!='0';){
		int n=strlen(s);

		static int dp[80001][11];
		rep(i,n){
			int a=s[i]-'0';
			rep(j,11) dp[i+1][(10*j+a)%11]=dp[i][j];
			if(a!=0) dp[i+1][a]++;
		}

		int ans=0;
		rep(i,n) ans+=dp[i+1][0];
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 4276
/*
* ID: juryc
* PROG: Fennec vs Monster
* LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n; int k; cin>>k;
vector<int> h(n);
for(int& i: h) cin>>i;
sort(h.begin(),h.end()); 
if(k>=n) cout<<0<<endl;
else{
long long ans=0;
for(int i=0;i<n-k;i++)  ans+=h[i]; 
cout<<ans<<"\n";
}
return 0;
}

Measured memory_bytes: 4032
N=int(input())
# 1011: -9
# 101  1 + 4 =5
# 10: -2
# 1

def calc(x):
    ans=""
    
    while True:

        if x%2==0:
            ans="0"+ans
        else:
            ans="1"+ans
            x-=1
        if x==0:
            break

        x = x//(-2)
    return ans

a=calc(N)

print(a)        

Measured memory_bytes: 9144