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


int main(){
  int K;
  int i,j,k;
  int a;
  int x = 1;
  
  long sum = 0;

  cin >> K;
  for(i = 1;i <= K;++i){
    for(j = 1;j <= K;++j){
      for(k = 1;k <= K;++k){
        a = min(min(i,j),k);
        for(int l = 1;l <= a;++l){
          if(i % l == 0 && j % l == 0  && k % l == 0){
            x = l;
          }
         
        }
 sum += x;
    }
  }
}
cout << sum << endl;
}

Measured memory_bytes: 3640
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque

inf = 10 ** 15
mod = 10 ** 9 + 7

n = int(input())
s = input()
siro = [0 for i in range(n+1)]
kuro = [0 for j in range(n+1)]
for i,c in enumerate(s):
    siro[i+1] = siro[i]
    kuro[i+1] = kuro[i]
    if c == '#':
        kuro[i+1]+=1
    else:
        siro[i+1]+=1
def getSiro(l,r):
    return siro[r]-siro[l]

def getKuro(l,r):
    return kuro[r]-kuro[l]

ans = inf
for i in range(n+1):
    ans = min(ans, getKuro(0,i)+getSiro(i,n))
print(ans)


Measured memory_bytes: 56312
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    int mismatch = 0;
    REP(i, n){
        int num; cin >> num;
        if (i+1 != num){
            mismatch++;
        }
    }
    if (mismatch <= 2){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007
#define int long long

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N;

void init()
{
	cin >> N;
}

int ch(int x)
{
	int f[3] = {0, 0, 0};
	while (x) {
		if (x % 10 == 3) f[0] = 1;
		if (x % 10 == 5) f[1] = 1;
		if (x % 10 == 7) f[2] = 1;
		x /= 10;
	}
	rep(i, 3) if (f[i] == 0) return 0;
	return 1;
}

int dfs(int x)
{
	if (x > N) return 0;
	int res = ch(x);
	x *= 10;
	res += dfs(x + 3);
	res += dfs(x + 5);
	res += dfs(x + 7);
	return res;
}

void solve()
{
	cout << dfs(0) << endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define N 1000005
using namespace std;
typedef long long int lo;
const int mod=1000000007;
lo a,b,c,d,e,f,g,h[100005],arr[100005];
string s;
vector<lo>v;
char ch;

int main(){
	// freopen("in.txt","r",stdin);
 //    freopen("out.txt","w",stdout);
    cin >> a >> s;
    if(a>=3200){
    	cout << s;
    }
    else{
    	cout << "red";
    }
}

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

#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

const int N = 100005;

integer main() {
    ios_base::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    cout << (500 * k >= x ? "Yes" : "No");

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;



int main(){
    int n;
    cin >> n;
    vector<P> xy(n);
    
    rep(i, n) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(xy.begin(), xy.end());
    double sum = 0;
    int num = 1;
    rep(i, n) num*=(i+1);
    do {
        double z = 0;
        rep(i, n) {
            if (i==0) continue;
            double dx = xy[i].first - xy[i-1].first;
            double dy = xy[i].second - xy[i-1].second;
            z += sqrt(dx*dx + dy*dy);
        }
        sum += z;
    } while (next_permutation(xy.begin(), xy.end()));
    
    double ans = sum/num;
    
    
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
open System
open System.Collections.Generic;

let N =stdin.ReadLine()|>int
let A=stdin.ReadLine().Split()|>Array.map int
let B=stdin.ReadLine().Split()|>Array.map int
let C=stdin.ReadLine().Split()|>Array.map int
[<EntryPoint>]
let sf argv =
    let mutable ans = 0
    for i in [0..N-1] do
        ans <- if i>0 && A.[i]=A.[i-1]+1 then ans+C.[A.[i-1]-1]+B.[i] else ans+B.[i]
    printfn "%d" ans
    0 


Measured memory_bytes: 14044
#include<stdio.h>

int main()
{
    int n;
    int k;
    int h = 0;
    int w = 0;
    int s = 1;
    int b = 0;
    
    scanf("%d%d", &n, &k);
    
    while(1)
    {
        if(w <= k * s)
        {
            w += s;
            b += s;
            if(b <= n)
            {
                h++;
            }
            else
            {
                break;
            }
        }
        else
        {
            s++;
        }
    }
    
    printf("%d\n", h);
    
    return 0;
}


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



int main(){
  int N,M,k,ss,ans=0,ac=0,total=0,a=1;

  cin>>N>>M;
  vector<int> p(M+1);
  vector<vector<int>> s(M+1);

  for(int i=1;i<=M;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>ss;
      s.at(i).push_back(ss);
    }
  }
  for(int i=1;i<=M;i++)
    cin>>p.at(i);
  for(int i=0;i<N;i++){
    a*=2;
  }
  for (int tmp = 0; tmp < (1 << 10); tmp++) {
    bitset<10> sss(tmp);
    vector<int> c(M+1);
    ac=0;
    // (ビット列sに対する処理)
    if(a==total)
      break;
    for(int i=1;i<=M;i++){
      for(int j=0;j<N;j++){
        if(sss.test(j)==1){
          for(int m=0;m<s.at(i).size();m++){
            if(s.at(i).at(m)==j+1){
              c.at(i)++;
              break;
            }
          }
        }
      }
    }
    
    for(int l=1;l<=M;l++){
      if(c.at(l)%2!=p.at(l))
        ac=1;
    }
    
    if(ac==0)
      ans++;
    total++;
  }

  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}
func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}
func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	right, left := 0, 0
	for i := 0; i < len(a); i++ {
		a[i] = nextInt(sc)
		right = max(a[i], right)
	}
	tgt := int(1e9 + 1)
	for i := 0; i < len(a); i++ {
		d := abs(right/2 - a[i])
		if tgt > d && a[i] != right {
			tgt = d
			left = a[i]
		}
	}
	fmt.Println(right, left)
}


Measured memory_bytes: 3072
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ======================================================================
    public void solve() {
    	int N = ni();
    	int a;
    	boolean f = true;
    	for (int i = 0; i < N; i++) {
			a = ni();
			if(a % 2 == 0 && (a % 3 != 0 && a % 5 != 0))
				f = false;
		}
    	if(f)	out.println("APPROVED");
    	else	out.println("DENIED");
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 23892
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;

int main(){
    int64_t N;
    cin>>N;
    int64_t lo,up;
    lo=0;up=10000;
    while(up-lo>1){
        int64_t mid=(lo+up)/2;
        int64_t z=mid*(mid+1)/2;
        if(z>=N){
            up=mid;
        }else{
            lo=mid;
        }
    }
    int i=up;
    while(N>0){
        if(N>=i){
            cout<<i<<endl;
            N=N-i;
        }
        i--;
    }
    //cout<<up<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
int main(){
    int n;
    while(cin >> n, n != 0){
            cin.ignore();
        vector<string> str(n);
        vector<string> w;
        rep(i,n){
            getline(cin, str[i]);
        }
        rep(i,n){
            string s;
            stringstream ss(str[i]);
            while(getline(ss, s, ' ')){
                w.emplace_back(s);
            }
        }

        map<string, int> m[26];
        for(auto i : w){
            m[i[0] - 'a'][i]++;
        }

        char k;
        cin >> k;

        vector<pair<int, string>> p;
        for(auto i : m[k - 'a']){
            p.emplace_back(-i.second, i.first);
        }

        if(p.empty()){
            cout << "NA" << endl;
        }else{
            sort(p.begin(), p.end());
            rep(i,min<int>(5, p.size())){
                if(i) cout << ' ';
                cout << p[i].second;
            }
            cout << endl;
        }




    }
}



Measured memory_bytes: 3240
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

#include <bits/stdc++.h>
using namespace std;



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



    int a, b; cin >> a >> b;
    
    if (a <= b) {
        string res = "", c;
        c = to_string(a);

        while (b--) res += c;
        cout << res;
    } else {
        string res = "", c;
        c = to_string(b);

        while (a--) {
            res += c;
        }

        cout << res;
    }




    return 0;
}

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

using namespace std;


int main(){
	clock_t tim;
    tim = clock();

    {
    	long long mod=1e9+7;
		int N;
		cin>>N;
		long long TOT=1;
		for(int i=0;i<N;i++){
			TOT=(TOT*10)%mod;
		}
		long long Zero=1;
		for(int i=0;i<N;i++){
			Zero=(Zero*9)%mod;
		}
		long long Nine=1;
		for(int i=0;i<N;i++){
			Nine=(Nine*9)%mod;
		}
		long long NineZero=1;
		for(int i=0;i<N;i++){
			NineZero=(NineZero*8)%mod;
		}
		long long res;
		res=(TOT+NineZero-2*Zero)%mod;
		if(res<0){
			res+=mod;
		}
		cout<<res<<endl;
	}

    //tim = clock() - tim;
    //double time_taken = ((double)tim)/CLOCKS_PER_SEC;
    //cout<< fixed << setprecision(3) << time_taken << "seconds" <<endl;

	return 0;
}


Measured memory_bytes: 3628
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var S string
	var ans int = 0
	fmt.Scan(&S)
	strs := strings.Split(S, "")

	for i := 0; i < len(strs); i++ {
		if strs[i] == "+" {
			ans += 1
		} else {
			ans -= 1
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }

type SortBy []int

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return abs(a[i]) > abs(a[j]) }


Measured memory_bytes: 640
#include <stdio.h>
int main(){
    int A;
    int B;
    int ans;
    
    scanf("%d %d",&A,&B);
    
    if(A >= 1 && A <= 9){
        if(B >= 1 && B <= 9){
            ans = A*B;
            printf("%d",ans);
        }else{
            printf("-1");
        }
    }else{
        printf("-1");
    }
    return 0;
}


Measured memory_bytes: 128
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

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

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

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

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

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string input_str;
    string str;
    int N = input_str.size();
    cin >> input_str;

    for (int i = 0; i < input_str.size(); i++) {
        if (input_str[i] == 'A') {
            str += 'A';
        } else if (i + 1 < input_str.size() && input_str[i] == 'B' && input_str[i+1] == 'C') {
            str += 'D';
            i++;
        } else {
            str += input_str[i];
        }
    }

    int tmp = 0;
    int ret = 0;
    int M = str.size();
    for (int i = M - 1; i >= 0; i--) {
        if (str[i] == 'D') tmp++;
        else if (str[i] == 'A') ret += tmp;
        else tmp = 0;
    }

    cout << ret << endl;

    return 0;
}

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

int main(void){
	int n, l;
	cin >> n >> l;
	int ans = abs(l);
	for(int i = 1; i <= n; ++i){
		ans = min(abs(l+i-1), ans);
	}
	int sum = 0;
	for(int i = 1; i <= n; ++i){
		if(ans != abs(l+i-1)) sum += l+i-1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[1000][1000];
ll x[200000] = {};
ll y[200000] = {};
ll x2[200000] = {};
ll y2[200000] = {};

int main() {
	ll h, w; cin >> h >> w;
	ll v;

	rep(i, 0, h)rep(j, 0, w) {
		cin >> v;
		a[i][j] = v % 2;
	}

	ll cnt = 0;
	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] % 2) {
				a[i][j]--;
				a[i][j + 1]++;

				y[cnt] = i + 1;
				x[cnt] = j + 1;
				y2[cnt] = i + 1;
				x2[cnt] = j + 2;
				cnt++;
			}
		}
		if (i != h - 1) {
			if (a[i][w - 1] % 2) {
				a[i][w - 1]--;
				a[i + 1][w - 1]++;

				y[cnt] = i + 1;
				x[cnt] = w;
				y2[cnt] = i + 2;
				x2[cnt] = w;
				cnt++;
			}
		}
	}

	//rep(i, 0, h - 1) {
	//	if (a[i][w - 1] % 2) {
	//		a[i][w - 1]--;
	//		a[i + 1][w - 1]++;

	//		y[cnt] = i + 1;
	//		x[cnt] = w;
	//		y2[cnt] = i + 2;
	//		x2[cnt] = w;
	//		cnt++;
	//	}
	//}
	cout << cnt << endl;
	rep(i, 0, cnt) {
		cout << y[i] << " " << x[i] << " " << y2[i] << " " << x2[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 11776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		String[] str = br.readLine().split(" ");

		int P = Integer.parseInt(str[0]);
		int Q = Integer.parseInt(str[1]);
		int R = Integer.parseInt(str[2]);

		int a = P+Q;
		int b = Q+R;
		int c = R+P;

		if(a<=b && a<=c) {
			System.out.print(a);
		}else if(b<=a && b<=c) {
			System.out.print(b);
		}else if(c<=a && c<=b) {
			System.out.print(c);
		}



	}

}


Measured memory_bytes: 23124
n = int(input())
b = list(map(int, input().split()))

ans = []
l = len(b)
while l > 0:
    for i in range(l):
        ii = l - i
        if b[ii-1] == ii:
            ans.append(ii)
            del b[ii-1]
            l = l - 1
            break
    else:
        print(-1)
        exit(0)

for a in ans[::-1]:
    print(a)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    
    int x,y;
    while(1){
        scanf("%d %d", &x, &y);
        if(x==0 && y==0)break;
        if(x >= y) printf("%d %d\n", y, x);
        else if(x < y) printf("%d %d\n", x, y);
        //if(x > y) printf("%d %d\n", x, y);
    }
}



Measured memory_bytes: 1892
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

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

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
priority_queue<ll> que;
ll sum;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  sum = 0;
  REP(i, n) {
    ll b;
    cin >> b;
    que.push(b);
    sum += b;
  }

  REP(i, m) {
    ll q = que.top(); que.pop();
    if(q <= 0) break;
    ll q_half = q / 2;
    sum -= (q - q_half);
    que.push(q_half);
  }

  cout << sum << endl;
}


Measured memory_bytes: 1400
# ひっくりかえすのかとお保ったら180度反転だった
n = int(input())
d = []
for _ in range(n):
    s = list(input())
    d.append(s)

d = sorted(d, key=lambda dd: len(dd), reverse=True)
base = {}
for c in d[0]:
    if c not in base:
        base[c] = 1
    else:
        base[c] += 1

for s in d[1:]:
    tmp = {}
    for c in s:
        if c not in tmp:
            tmp[c] = 1
        else:
            tmp[c] += 1
    for k, v in base.items():
        if k in tmp and base[k] >= 1:
            base[k] = min(base[k], tmp[k])
        else:
            base[k] = -1
ans = []
for k, v in base.items():
    if v > 0:
        ans.append(k * v)
ans = sorted(ans)
ans = "".join(ans)
print(ans)

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

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

const int inf = 1'000'000'000;

bool is_palindrome(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  if (s == t) return true;
  else return false;
}

int main() {
  string s,s2,s3;
  cin >> s;
  int n = s.size();
  s2 = s.substr(0, (n-1)/2);
  s3 = s.substr((n+3)/2-1, n);
  if (is_palindrome(s) && is_palindrome(s2) && is_palindrome(s3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
    int n, m, t;
    cin >> n >> m >> t;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    int ans=0;
    bool s=1;
    int idx=0;

    rep(i, t) {

        if (idx >= n) {
            if (!s) { i += m - 1; s = 1; }
            else ans++;
            continue;
        }

        if (s and i + m >= a[idx]) {
            i += m - 1;
            idx++;
            s = 0;
            continue;
        }

        if (!s and i + m*2 < a[idx]) {
            i += m - 1;
            s = 1;
            continue;
        }
        else if (!s and i + m*2 >= a[idx]){
            i = a[idx] - 1;
            idx++;
            continue;
        }

        ans++;

    }

    cout << ans << endl;

}

Measured memory_bytes: 3092
import java.util.Scanner;
public class Main{
    public static void main(String[] args){  
        Scanner sc = new Scanner(System.in);
        while(true){
            int x = sc.nextInt();
            String cal = sc.next();
            int y = sc.nextInt();
        
            if(cal.equals("+")){
                System.out.printf("%d\n",x+y);
            }else if(cal.equals("-")){
                System.out.printf("%d\n",x-y);
            }else if(cal.equals("*")){
                System.out.printf("%d\n",x*y);
            }else if(cal.equals("/")){
                System.out.printf("%d\n",x/y);
            }else{
                break;
            }
        }
    }
}


Measured memory_bytes: 26632
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

signed main(){
	int N, M, K, i, j;
	scanf("%lld%lld%lld", &N, &M, &K);
	int L = (N + M - 1) / (K - 1);
	vector<vector<int>> dp(L + 1, vector<int>(M + 1, 0)), sum(L + 1, vector<int>(M + 1, 0));
	dp[0][0] = 1;
	for(j = 0; j <= M; j++){
		sum[0][j] = 1;
	}
	for(i = 1; i <= L; i++){
		for(j = 0; j <= M; j++){
			if(j < K){
				dp[i][j] = sum[i - 1][j];
			}
			else{
				dp[i][j] = MOD(sum[i - 1][j] - sum[i - 1][j - K]);
			}
		}
		sum[i][0] = dp[i][0];
		for(j = 1; j <= M; j++){
			sum[i][j] = MOD(sum[i][j - 1] + dp[i][j]);
		}
	}
/*	printf("dp\n");
	for(i = 0; i <= L; i++){
		for(j = 0; j <= M; j++){
			printf("%lld ", dp[i][j]);
		}
		printf("\n");
	}
	printf("sum\n");
	for(i = 0; i <= L; i++){
		for(j = 0; j <= M; j++){
			printf("%lld ", dp[i][j]);
		}
		printf("\n");
	}
*/	int ans = 0;
	for(i = 0; M - i * (K - 1) > 0; i++){
		ans = MOD(ans + dp[L - i][M - i * (K - 1)]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 125568
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

class SegTree_Delay {
public:
    int f;
    int INIT = 0;
    vector<int> dat, lazy;

    SegTree_Delay(int n) {
        f = 1;
        while (f < n) f *= 2;
        dat.assign(2 * f, INIT);
        lazy.assign(2 * f, INIT);
    }

    void eval(int k) {
        if (lazy[k] == INIT) return;
        if (k < f - 1) {
            lazy[2 * k + 1] += lazy[k];
            lazy[2 * k + 2] += lazy[k];
        }
        dat[k] += lazy[k];
        lazy[k] = INIT;
    }

    void update(int a, int b, int x, int k, int l, int r) {
        eval(k);
        if (a <= l && r <= b) {
            lazy[k] += x;
            eval(k);
        }
        else if (a < r && l < b) {
            update(a, b, x, k * 2 + 1, l, (l + r) / 2);
            update(a, b, x, k * 2 + 2, (l + r) / 2, r);
            dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
        }
    }

    void update(int a, int b, int x) {
        update(a, b, x, 0, 0, f);
    }

    int query(int a, int b) {
        return query(a, b, 0, 0, f);
    }

    int query(int a, int b, int k, int l, int r) {
        eval(k);
        if (r <= a || b <= l) return INIT;
        if (a <= l && r <= b) return dat[k];
        else {
            int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return vl + vr;
        }
    }
};


int main() {
    int n, q;
    cin >> n >> q;
    SegTree_Delay st = SegTree_Delay(n);
    while (q--) {
        int m;
        cin >> m;
        if (m) {
            int i;  cin >> i;
            cout << st.query(i - 1, i) << endl;
        }
        else {
            int s, t, x;
            cin >> s >> t >> x;
            st.update(s - 1, t, x);
        }
    }
}



Measured memory_bytes: 4964
#include<iostream>
using namespace std;
int main(){
	int n; cin>>n;
	while(n--){
		int x=0,y=0,dx,dy,d,mx=0,my,md=0;
		while(cin>>dx>>dy,dx||dy){
			x+=dx,y+=dy,d=x*x+y*y;
			if(d>md||d==md&&mx<x)md=d,mx=x,my=y;
		}
		cout<<mx<<" "<<my<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll rk(ll k){
	ll s=1;
	for(ll i=1;i<=k;i++) s*=10;
	return s;
}
bool pan(ll k, ll fir, ll las, ll per){
	ll r=k, s=0, s1=0;
	while(r) s+=r%10, r/=10;
	for(ll i=fir;i<=las;i+=per){
		r=i, s1=0;
		while(r) s1+=r%10, r/=10;
		if(i>k&&s1*k>s*i) return 0;
	}
	return 1;
}
int main(){
	ll k;
	cin>>k;
	/*for(ll i=1;i<=min(9LL, k);i++) cout<<i<<endl;
	k-=9;
	for(ll i=1;i<=min(9LL, k);i++) cout<<i<<9<<endl;
	k-=9;
	if(k<=0) return 0;*/
	ll f=0;
	for(ll i=1;i<=15;i++){
		ll fir=rk(i-1)+f;
		if(i>2) f=f*10+9;
		ll per=max(1LL,rk(i-3)), las=rk(i);
		for(ll j=fir;j<las;j+=per){
			if(k&&pan(j, fir, las+1, per)) {
				printf("%lld\n", j);
				k--;
			}
		}
		if(!k) return 0;
	}
	//cout<<maxn<<" "<<k;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
x=list(list(map(int,input().split())) for _ in range(n))

from itertools import chain

y=[]

for i in range(n):
	y.append(x[i][1:])

z=list(chain.from_iterable(y))
v=list(set(z))

cnt=0
for i in range(len(v)):
	if z.count(v[i])==n:
		cnt+=1

print(cnt)


Measured memory_bytes: 3064
a, b, c = map(int, input().split())
count = 0
for i in range(1100):
    if (a%2 + b%2 + c%2):
        break
    d,e,f = (b+c)//2, (c+a)//2, (a+b)//2
    a,b,c = d,e,f
    count += 1
if(count>1000):
    count = -1
print(count)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
vector<int> G[MAX_N];

void solve() {
	cin >> N >> M;
	rep(i, 0, N) {
		int a, b; cin >> a >> b;
		if(M - a >= 0) {
			G[M - a].pb(b);
		}
	}
	priority_queue<int> que;

	ll res = 0;
	rer(i, M, 0) {
		rep(j, 0, sz(G[i])) que.push(G[i][j]);
		if(!que.empty()) {
			res += que.top(); que.pop();
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 15104
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

signed main()
{
	int N, i;
	cin >> N >> i;
	cout << (N - i + 1) << endl;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=char(n%10+48);n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

ll gcd(ll gcd_a, ll gcd_b){return gcd_b == 0 ? gcd_a : gcd(gcd_b, gcd_a % gcd_b);}
ll fpow(ll fpow_b, ll fpow_exp, ll fpow_mod){if(fpow_exp == 0) return 1;ll t = fpow(fpow_b,fpow_exp/2,fpow_mod);if(fpow_exp&1) return t*t%fpow_mod*fpow_b%fpow_mod;return t*t%fpow_mod;}
ll divmod(ll divmod_i, ll divmod_j, ll divmod_mod){divmod_i%=divmod_mod,divmod_j%=divmod_mod;return divmod_i*fpow(divmod_j,divmod_mod-2,divmod_mod)%divmod_mod;}


int main(){
	int n;
	scan(n);
	ll ans = fpow(10, n, mod) - fpow(9, n, mod)*2 + fpow(8, n, mod);
	ans %= mod;
	ans = (ans+mod)%mod;
	print(ans);
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  vector<vector<char>> s(N, vector<char>(10));
  REP(i, N) {
    REP(j, 10) { cin >> s[i][j]; }
    sort(ALL(s[i]));
  }
  sort(ALL(s));
  ll ans = 0;
  ll count = 0;
  REP(i, N - 1) {
    if (s[i] == s[i + 1]) {
      count++;
    } else {
      count = 0;
    }
    ans += count;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 5760
#include  <stdio.h>
#include <math.h>

int main(void){
  double  a,b,c;
  double  S,L2, L, h;

  scanf("%lf %lf %lf",&a,&b,&c);

  S = 0.5*a*b*sin(c*3.14159265359/180);
  L2 = a*a+b*b-2*a*b*cos(c*3.1415926359/180);
  L = sqrt(L2)+a+b;
  h = 2*S/a;

  
  printf("%.11lf\n%.11lf\n%.11lf\n",S ,L,h); 

  return 0;
}



Measured memory_bytes: 2044
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        sc.close();

        int result = 0;

        if(A >= 13){
            result = B;
        }else if(A >= 6){
            result = B/2;
        }

        System.out.print(result);


    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define all(c) (c).begin(), (c).end()
#define endl '\n'
// auto start = high_resolution_clock::now(); 
// auto stop = high_resolution_clock::now(); 
// auto duration = duration_cast<microseconds>(stop - start); 
 
// cout << duration.count() << endl; 





int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
     // auto start = high_resolution_clock::now(); 
    //  int t;
    //  cin >> t;
 
    //  // for(auto a : prime)cout << a <<  ' ';
    //  //    cout << endl;

    // while(t--) {

    // }
    int x,k,d;
    cin >> x >> k >> d;

    x = abs(x);
    int ba = x/d;
    if(k <= ba)cout << x-d*k << endl;
    else{
        x -= ba*d;
        int p = k-ba;
        if(p&1)x -= d;
        cout << abs(x) << endl;
    }
    



return 0;
}



Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            Console.WriteLine((a - c) * (c - b) > 0 ? "Yes" : "No");
        }
    }
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int C[202020];

int L,R;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	int ma=0;
	FOR(i,N) {
		cin>>x;
		C[x]=C[x-1]+1;
		ma=max(ma,C[x]);
	}
	cout<<N-ma<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int n; cin >> n;
    int p[n]; repp(i,0,n) cin >> p[i];
    int res = 0;
    repp(i,1,n-1) {
        if ((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1])) ++res;
    }
    cout << res << endl;
}


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

int main(){
    double W,H,x,y;
    cin >> W >> H >> x >> y;
    double ans = (W * H) / 2;
    int flag = 0;
    if (W/2 == x && H/2 == y) flag = 1;
    cout << setprecision(12) << ans << " " << flag << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
int main(void){
    int n; cin >> n;
    vector<int> t(n);
    int cnt = 0;
    rep(i, n) {
        cin >> t[i];
        cnt += t[i];
    }
    int m; cin >> m;
    rep(i, m) {
        int p, x; cin >> p >> x;
        int ans = cnt + x - t[p - 1];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
int contain(int *a, int n, int x)
{
    int i;
    for(i=0;i<n;++i) if (a[i]==x) return i;
    return -1;
}
int main(void)
{
    int a[30], L, k=0, i;
    while (scanf("%d%d", a, &L), L) {
        for(k=0;k<30;++k) {
            int c[10]={0}, t=a[k], min, max, j;
            for(i=0;i<L;++i) { ++c[t%10]; t/=10; }
            for(max=0,i=9;i>=0;--i) for(j=0;j<c[i];++j) max=max*10+i;
            for(min=0,i=0;i<=9;++i) for(j=0;j<c[i];++j) min=min*10+i;
            a[k+1]=max-min;
            if ((j=contain(a, k+1, a[k+1]))>=0) {
                printf("%d %d %d\n", j, a[j], k+1-j);
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
public class AtCoder
{

    public static void Main()
    {
        //入力を保持する
        var N = int.Parse(Console.ReadLine());
        var As = Console.ReadLine().Split().Select(e => BigInteger.Parse(e)).ToArray();
        //Array.Sort(As);
        foreach (var a in As)
        {
            if (a == 0)
            {
                Console.WriteLine(0);
                return;
            }
        }
        BigInteger ans = 1;
        for (int i = 0; i < N; i++)
        {
            BigInteger work = ans * As[i];
            if (work > 1000000000000000000)
            {
                ans = -1;
                break;
            }
            ans = ans * As[i];
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 64948
b=[0]*t=2**19;n,*a=`dd`.split.map &:to_i;a.pop(n).zip(a){|a,h|r=0;i=h;(r=[r,b[i]].max;i-=i&-i)while i>0;(b[h]=[b[h],a+r].max;h+=h&-h)while h<t};p b[t/2]

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

using namespace std;

int main()
{
    int N, M;
    
    scanf("%d", &N);
    scanf("%d", &M);
    
    vector<long long> P(M);
    
    vector<long long> Q(N - 1);
    vector<long long> A(N - 1);
    vector<long long> B(N - 1);
    vector<long long> C(N - 1);
    
    for(int i = 0; i < M; i++)
    {
        scanf("%lld", &P[i]); P[i]--;
    }
    
    for(int i = 0; i < M - 1; i++)
    {
        for(int j = min(P[i], P[i + 1]); j < max(P[i], P[i + 1]); j++)
        {
            Q[j]++;
        }
    }
    
    for(int i = 0; i < N - 1; i++)
    {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
        scanf("%lld", &C[i]);
    }
    
    long long ret = 0;
    
    for(int i = 0; i < N - 1; i++)
    {
        long long s = A[i] * Q[i];
        long long t = B[i] * Q[i] + C[i];
        
        ret += min(s, t);
    }
    
    printf("%lld\n", ret);
    
    return 0;
}

Measured memory_bytes: 6796
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, X;
lint dp_a[51], dp_p[51];

lint rec(lint n, lint x) {
	if (n == 0) return 1;
	if (x == 1) return 0;
	if (x < 2 + dp_a[n - 1]) return rec(n - 1, x - 1);
	if (x == 2 + dp_a[n - 1]) return dp_p[n - 1] + 1;
	if (x < 3 + 2 * dp_a[n - 1]) return dp_p[n - 1] + 1 + rec(n - 1, x - 2 - dp_a[n - 1]);
	else return 2 * dp_p[n - 1] + 1;
}


int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> X;
	dp_a[0] = 1;
	dp_p[0] = 1;
	REP(i, 50) {
		dp_a[i + 1] = 2 * dp_a[i] + 3;
		dp_p[i + 1] = 2 * dp_p[i] + 1;
	}
	cout << rec(N, X);
}


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

int main(){
	int N, P;
	int pp[50];
	while(cin >> N >> P, N && P){
		int c = P;
		for(int i = 0; i < N; i++){
			pp[i] = 0;
		}
		
		int idx = 0;
		while(1){
			if(c > 0){
				pp[idx] += 1;
				c -= 1;
				if(pp[idx] == P){
					cout << idx << endl;
					break;
				}
			}else{
				c = pp[idx];
				pp[idx] = 0;
			}
			idx = (idx + 1) % N;
		}
	}
}

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

int main() {
  int N, A, i, j, min = 10^9;
  cin >> N;
  for (i = 1; i <= N; i++) {
    cin >> A;
    j = 0;
    while (A % 2 == 0) {
      A /= 2;
      if (j >= min && i > 1) {
        break;
      }
      j++;
    }
    min = j;
    //cout << j << endl;
  }
  cout << min;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	string a, b;
	cin >> a >> b;

	FOR(i,0,n) cout << a[i] << b[i];
	cout << endl;

}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    long long N,K;
    cin >> N >> K;
    
    for(int i=0; i<K; i++){
        int a,b;
        cin >> a >> b;
        if(a > N/2) a = N+1-a;
        if(b > N/2) b = N+1-b;
        int ans;
        if(a>b) ans = b%3;
        else ans = a%3;
        if(ans == 0) ans = 3;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
import java.math.*;
import java.io.*;
import java.util.*;
 
class Main{
    static ArrayList<Integer>[] lists;
    static long mod = 1000000007;
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] l1 = br.readLine().split(" ");
        int M = Integer.parseInt(l1[0]);
        int N = Integer.parseInt(l1[1]);

        long[][] dp = new long[M][N];
        char[][] in = new char[M][N];

        dp[0][0] = (long)1;
        
        for(int i = 0; i < M; i++){
            String l2 = br.readLine();
            for(int j = 0; j < l2.length(); j++){
                in[i][j] = l2.charAt(j);
            }
        }

        // System.out.println(Arrays.deepToString(in));

        for(int i = 0; i < M; i++){
            for(int j = 0; j < N; j++){
                if(in[i][j] == '#') continue;
                if(i - 1 >= 0) dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod;
                if(j - 1 >= 0) dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod;
            }
        }
        System.out.println(dp[M - 1][N - 1]);
    }
}

Measured memory_bytes: 35844