akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    C = Counter(A)
    can = []
    seq = []
    for c in set(A):
        if C[c] >= 2:
            can.append(c)
            if C[c] >= 4:
                seq.append(c)

    if can:
        can = sorted(can)
        if seq:
            seq = sorted(seq)
            print(max(can[-1] * can[-2], seq[-1] ** 2))
        else:
            print(can[-1] * can[-2])
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25612
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

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

typedef long long ll;
typedef unsigned long long ull;

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

int main(void)
{
	ll a, b;
	scanf("%lld%lld", &a, &b);
	a = gcd(a, b);

	ll p[64] = { 0 }, n = 2;
	int pnc[64] = { 0 };
	int pcnt = 0, cnt = 0, pnclen = 0;
	ll sqrt_a = sqrt(a);
	while (a != 1)
	{
		if (!(a % n))
		{
			a /= n;
			if (pcnt && p[pcnt - 1] != n)
			{
				pnclen++;
			}
			pnc[pnclen]++;
			p[pcnt++] = n;
		}
		else
		{
			n++;
			if (n > sqrt_a)
			{
				n = a;
			}
		}
	}
	if(pcnt) pnclen++;


	printf("%lld", pnclen + 1);
}

Measured memory_bytes: 128
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
#dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])}
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

n = inp()
t = n%10
if t == 3:
    print("bon")
elif t in [0,1,6,8]:
    print("pon")
else:
    print("hon")
    

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define ALL(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }

#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}

template<class T> void sort3a(T& a,T& b,T& c) {if (a>b) swap(a,b); if (b>c) swap(b,c); if (a>b) swap(a,b);}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);
    const int MOD = 1000000007;

    int N,M; cin >> N>>M;
    vector<int> steps(N+1, INT_MAX);

    int a;
    rep(i, N) {
        cin >> a;
        steps[a] = -1;
    }
    steps[0] = 1;
    rep1(i, N+1) {
        if (steps[i] == -1)
            continue;
        int sum = 0;
        if (i - 1 >= 0 && steps[i - 1] != -1)
            sum += steps[i - 1]; 
        if (i - 2 >= 0 && steps[i - 2] != -1)
            sum += steps[i - 2];
        steps[i] = sum % MOD;
    }
    cout << steps[N] << endl;
}


Measured memory_bytes: 640
import itertools
N = int(input())
A = [int(_) for _ in input().split()]


def check(x):
    class SegmentTree():
        """
            Parameters
            ----------
            array : list
                to construct segment tree from
            f : func
                binary operation of the monoid
            e : 
                identity element of the monoid
            size : int
                limit for array size
        """

        def __init__(self, array, f, e, size):
            self.f = f
            self.e = e
            self.size = size
            self.n = n = len(array)
            self.dat = [e] * n + array + [e] * (2 * size - 2 * n)
            self.build()

        def build(self):
            dat, n, f = self.dat, self.n, self.f
            for i in range(n - 1, 0, -1):
                dat[i] = f(dat[i << 1], dat[i << 1 | 1])

        def modify(self, p, v):
            """
            set value at position p (0-indexed)
            """
            f, n, dat = self.f, self.n, self.dat
            p += n
            dat[p] = v
            while p > 1:
                dat[p >> 1] = f(dat[p], dat[p ^ 1])
                p >>= 1

        def query(self, l, r):
            """
            result on interval [l, r) (0-indexed)
            """
            f, e, n, dat = self.f, self.e, self.n, self.dat
            res = e
            l += n
            r += n
            while l < r:
                if l & 1:
                    res = f(res, dat[l])
                    l += 1
                if r & 1:
                    r -= 1
                    res = f(res, dat[r])
                l >>= 1
                r >>= 1
            return res

    cumsum = list(itertools.accumulate([0] + [1 if a <= x else -1 for a in A]))
    # sum([l:r)) = cumsum[r] - cumsum[l] >= 0
    # ⇔ cumsum[l] <= cumsum[r]
    e = 0
    size = 2 * N + 10
    ST = SegmentTree([e] * size, f=lambda x, y: x + y, e=e, size=size)
    count = 0
    for c in cumsum:
        c += N + 5
        count += ST.query(0, c + 1)
        ST.modify(c + 1, ST.query(c + 1, c + 2) + 1)
    return 2 * count > N * (N + 1) // 2


A_sorted = [0] + sorted(set(A)) + [10**10]
lb = 0
rb = len(A_sorted) - 1
# check(x) == Trueとなる最小のx
while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(A_sorted[mid]):
        rb = mid
    else:
        lb = mid
print(A_sorted[rb])


Measured memory_bytes: 129864
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

LL cum[N][2];
int mask[N];

struct edge {
	LL s;
	int to;
	edge(LL _s, int _to) :s(_s), to(_to) {};
};
using graph = vector<vector<edge> >;


int main() {
	int n, m;
	cin >> n >> m;
	graph g(n);
	REP(i, m) {
		int u, v;
		LL s;
		scanf("%d%d%lld", &u, &v, &s);
		u--, v--;
		g[u].PB(edge(s, v));
		g[v].PB(edge(s, u));
	}
	deque<tuple<int, int, LL> > q;
	q.push_back(make_tuple(0, 0, 0LL));
	memset(cum, -1, sizeof(cum));
	while (!q.empty()) {
		auto tmp = q.front();
		q.pop_front();
		int par = get<0>(tmp);
		int pos = get<1>(tmp);
		LL val = get<2>(tmp);
		if (mask[pos] &	(1<<par)) {
			if (val != cum[pos][par]) {
				cout << "0" << endl;
				return 0;
			}
			continue;
		}
		mask[pos] |= (1 << par);
		cum[pos][par] = val;
		for (auto e : g[pos]) {
			q.push_back(make_tuple(1-par, e.to, e.s-val));
		}
	}
	if (mask[0] == 3) {//odd-loop
		REP(i, n) {
			if (cum[i][0] + cum[i][1] <= 0) {
				cout << 0 << endl;
				return 0;
			}
		}
		cout << 1 << endl;
		return 0;
	}
	else {
		LL m1 = 1, m2 = 2e9;
		REP(i, n) {
			if (mask[i] == 1) {
				m1 = min(m1, cum[i][0]);
			}
			else {
				m2 = min(m2, cum[i][1]);
			}
		}
		cout << max(m2 + m1-1, 0LL) << endl;
	}
	return 0;
}

Measured memory_bytes: 11904
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define Mod 1000000007;
using namespace std;
int n, m, k, f[105][10], cnt[10];
int main() {
	scanf("%d%d%d", &n, &m, &k);
	f[0][1] = 1;
	cnt[1] = 1;
	for(int i = 2; i <= m+1; ++i) cnt[i] = cnt[i-1] + cnt[i-2];
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(j != 1) f[i][j] = (f[i][j] + 1ll * f[i-1][j-1] * cnt[m-j+1] * cnt[j-1]) % Mod;
			if(j != m) f[i][j] = (f[i][j] + 1ll * f[i-1][j+1] * cnt[m-j] * cnt[j]) % Mod;
			//printf("%d ", f[i][j]);
			f[i][j] = (f[i][j] + 1ll * f[i-1][j] * cnt[m-j+1] * cnt[j]) % Mod;
			//printf("%d ", f[i][j]);
		}//puts("");
	}
	printf("%d\n", f[n][k]);
	return 0;
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,m = iim()
cand = []
check = []
for i in range(m):
    a,b = iim()
    if a == 1:
        cand.append(b)
    if b == n:
        check.append(a)

cand = set(cand)
flag=False
for i in check:
    if i in cand:
        flag = True

print('POSSIBLE' if flag else 'IMPOSSIBLE')

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

char t[4][4];

char judge(void){
	for(int i=0;i<3;i++){
		int j;
		for(j=1;j<3;j++){
			if(t[i][j-1] != t[i][j]) break;
		}
		if(j == 3 && t[i][0] != '+'){
			return t[i][0];
		}
	}
	for(int j=0;j<3;j++){
		int i;
		for(i=1;i<3;i++){
			if(t[i-1][j] != t[i][j]) break;
		}
		if(i == 3 && t[0][j] != '+'){
			return t[0][j];
		}
	}

	if(t[0][0] == t[1][1] && t[1][1] == t[2][2] && t[0][0]!='+'){
		return t[0][0];
	}
	if(t[0][2] == t[1][1] && t[1][1] == t[2][0] && t[0][2]!='+'){
		return t[0][2];
	}
	return '+';
}

int main(void){
	while(1){
		for(int i=0;i<3;i++){
			cin>>t[i];
			if(t[0][0] == '0') return 0;
		}
		char tmp = judge();
		if(tmp == '+')
			cout<<"NA\n";
		else
			cout<<tmp<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cstdlib>

using namespace std;

int main() {
    int k = 0;
    int a, b, c, d;
    long int cnt = 0;
    cin >> k;
    for (int a = 1; a <= k ; a++){
        for (int b = 1; b <= k; b++){
            for (int c = 1; c <= k; c++){
                d = gcd(a,b);
                cnt = cnt + gcd(d,c);
            }
        }
    }
    cout << cnt;
}

int gcd(int aa, int bb)
{
   if (aa%bb == 0)
   {
       return(bb);
   }
   else
   {
       return(gcd(bb, aa%bb));
   }
}


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

int main(){
    int n,d,x;
    cin >> n;
  	cin >> d >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int sum = x;
    rep(j,n){
        rep(i,d+2){
            if(d < a[j]*i+1){
                sum += i;
                break;
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,x;
int a[100010],b[100010],QwQ,QAQ;
int main(){
	cin>>s;
	x=s;
	int len=s.size();
	for(int i=0;i<len/2;i++)swap(x[i],x[len-i-1]);
	for(int i=0;i<len;i++){
		if(x[i]=='b')x[i]='d';
		else if(x[i]=='d')x[i]='b';
		else if(x[i]=='p')x[i]='q';
		else if(x[i]=='q')x[i]='p';
	}
	if(x==s)
		cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,a[N],s0,s1,s2;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int t=0;
		scanf("%d",&a[i]);
		while(a[i]%2==0&&t<2) a[i]>>=1,t++;
		if(!t) s0++;
		else  if(t==1) s1++;
		else s2++;
	}
	if(s2>=s0||s2>=n/2) puts("Yes");
	else puts("No");
	return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	string s[3];
	rep(i,3)cin>>s[i];
	rep(i,3)cout<<s[i][i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long
#define mod 998244353

using namespace std;

llint h, w;
string l, r, u, d;
llint udsum[100005];

const int FACT_MAX = 400005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint get(llint h, llint w)
{
	if(h == 0) return 0;
	h--;
	return comb(h+w, w);
}

llint calc()
{
	llint lsum = 0, rsum = 0;
	for(int i = 1; i <= h; i++) lsum += l[i]-'0', rsum += r[i]-'0';
	if(lsum == 0 && rsum == 0){
		llint ret = 1;
		for(int i = 1; i <= w; i++){
			llint cnt = (u[i]-'0') + (d[i]-'0');
			if(cnt) ret *= cnt, ret %= mod;
		}
		return ret;
	}
	for(int i = 1; i <= w; i++){
		udsum[i] = udsum[i-1];
		udsum[i] += (u[i]-'0') + (d[i]-'0');
	}
	
	llint ret = 0, sum = 0, num = 0, mul = 1;
	for(int i = w; i >= 1; i--){
		llint cnt = (u[i]-'0') + (d[i]-'0');
		if(cnt == 0) continue;
		sum += get(rsum, num), sum %= mod;
		sum *= cnt, sum %= mod;
		mul *= cnt, mul %= mod;
		if(rsum == 0) sum = mul;
		ret += get(lsum, udsum[i-1]) * sum % mod, ret %= mod;
		num += cnt;
	}
	if(lsum == 0) ret = sum;
	return ret;
}

int main(void)
{
	cin >> h >> w;
	cin >> l >> r >> u >> d;
	l = "#" + l, r = "#" + r, u = "#" + u, d = "#" + d;
	
	make_fact();
	
	bool wflag = false;
	for(int i = 1; i <= w; i++){
		if(u[i] == '1' || d[i] == '1') wflag = true;
	}
	bool hflag = false;
	for(int i = 1; i <= h; i++){
		if(l[i] == '1' || r[i] == '1') hflag = true;
	}
	if(!wflag && !hflag){
		cout << 1 << endl;
		return 0;
	}
	
	llint ans = 0;
	if(wflag) ans += calc();
	swap(l, u), swap(r, d), swap(h, w);
	if(hflag) ans += calc(), ans %= mod;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(){
  int i,j,q,point = 0,ue,ue_D,yoko,yoko_D;
  int dice[6][4]=            
    {{1,2,4,3},{0,3,5,2},{0,1,5,4},{0,4,5,1},{0,2,5,3},{1,3,4,2}};
  int num[6];
  scanf("%d %d %d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4],&num[5],&q);
  for(i=0;i<q;i++){
    scanf("%d %d",&ue,&yoko);
    for(j=0;j<6;j++){
      if(ue == num[j]){
	ue_D = j;
      }
      if(yoko == num[j]){
	yoko_D = j;
      }
    }
    for(j=0;j<4;j++){
      if(yoko_D == dice[ue_D][j]){
	if(j==3){
	  printf("%d\n",num[dice[ue_D][0]]);
	  break;
      }
	else{
	  printf("%d\n",num[dice[ue_D][j+1]]);
	  break;
	}
      }
    }
  }
  
  return 0;
}

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

using namespace std;

int DiceInfo[2][7];
vector<string> DicePosition;
const string WEDirection = "364136";
const string NSDirection = "265126";
const string LRDirection = "453245";

void swap(string &ans, int pos, const string &direction) {
	char tmp;

	tmp = ans[direction[pos] - '0'];
	ans[direction[pos + 0] - '0'] = ans[direction[pos + 1] - '0'];
	ans[direction[pos + 1] - '0'] = ans[direction[pos + 2] - '0'];
	ans[direction[pos + 2] - '0'] = ans[direction[pos + 3] - '0'];
	ans[direction[pos + 3] - '0'] = tmp;
	//cout << "=" << ans << endl;
}

void solve() {
	int len;
	string ans;

	ans = "0123456";
	DicePosition.push_back(ans);
	for (int i = 0; i < 3; ++i) {
		swap(ans, i, WEDirection);
		DicePosition.push_back(ans);
	}

	len = DicePosition.size();
	for (int i = 0; i < len; ++i) {
		ans = DicePosition[i];
		for (int k = 0; k < 3; ++k) {
			swap(ans, k, NSDirection);
			DicePosition.push_back(ans);
		}
	}

	len = DicePosition.size();
	for (int i = 0; i < len; ++i) {
		ans = DicePosition[i];
		for (int k = 0; k < 3; ++k) {
			swap(ans, k, LRDirection);
			DicePosition.push_back(ans);
		}
	}
}

bool judge() {
	int len, j;

	len = DicePosition.size();
	for (int i = 0; i < len; ++i) {
		for (j = 1; j < 7; ++j) {
			if (DiceInfo[0][DicePosition[i][j] - '0'] != DiceInfo[1][j]) {
				break;
			}
		}
		if (j == 7) {
			return true;
		}
	}

	return false;
}

int main() {

	for (int i = 0; i < 2; ++i) {
		for (int j = 1; j < 7; ++j) {
			cin >> DiceInfo[i][j];
		}
	}
	solve();
	if (judge()) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
int i,j,k,n,sum=0;
cin>>n;
int a[n];
int b[n];
int c[n];
for(i=0;i<n;i++)
{
    cin>>a[i];
}
for(i=0;i<n;i++)
    cin>>b[i];
for(i=0;i<n-1;i++)
    cin>>c[i];
    
sum=b[a[0]-1];
for(i=1;i<n;i++)
{
    if(a[i]==a[i-1]+1)
    {
        sum+=b[a[i]-1]+c[a[i]-2];
    }
    else
    {
        sum+=b[a[i]-1];
    }
}

cout<<sum;


	return 0;
}

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

int main() {
    long long s, ss, div, ans = 0;
    cin >> s;
    int num = log10(s), ii;
    for (int bit = 0; bit < (1 << num + 1); bit += 2) {
//        cout << "bit " << bit << endl;
        ss = s;
        ii = 0;
        for (int i = 1; i <= num; i++) {
            if (bit & (1 << i)) {
//                cout << "i " << i << endl;
                div = pow(10, i - ii);
                ans += ss % div;
                ss /= div;
                ii = i;
//                cout << "ss " << ss << endl;
            }
        }
        ans += ss;
//        cout << "ans " << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4036
#include <stdio.h>

int main(){
   int a[3];
  int temp,i,j;
  
  for(i=0;i<3;i++){
     scanf("%d",&a[i]);
  }
while(j<10){
  for(i=0;i<2;i++){
     if(a[i] > a[i+1]){
       temp = a[i];
       a[i] = a[i+1];
       a[i+1] = temp;
     } 
     else;
  }
  j++;
}
  for(i=0;i<3;i++){
  	printf("%d",a[i]);
    if(i != 2){
    	printf(" ");
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

vl find_divisors(ll n){
    vl out;
    for(ll i=2; i*i<=n; ++i){
        if(n%i==0){
            out.pb(i);
            if(n/i != i) out.pb(n/i);
        }
    }
    out.pb(n);
    return out;
}

bool gives1(ll k, ll n){
    
        ll md = n%k;
        if(md==0){
            while(md==0){
                n = n/k;
                md = n%k;
            }
        }
        n = md;
    
    
    return n==1;
}

int main(){
    ll n;
    while(cin>>n){
        if(n==2){
            cout<<1<<endl; continue;
        }else if(n==3){
            cout<<2<<endl; continue;
        }
        ll out = 0;
        vl div = find_divisors(n-1);
        out+=(ll)div.size();

        div = find_divisors(n);
        for(ll x: div){
            if(gives1(x,n)) ++out;
        }
        
        // deb2(n,out);
        cout<<out<<endl;
    }
    return 0;
}

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

int main(void) {
    int N; cin >> N;
    int x;
    if(N>=10) x=N%10;
    else x=N;
    if(x==3) cout << "bon" << endl;
    else if(x==0 || x==1 || x==6 || x==8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3584
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N)cin >> A[i];

  vector<int> wa(N+10,0);
  vector<int> sa(N+10,0);
  for(int i = 1;i <= N;i++){
    if(i + A[i-1] < 300000 && i + A[i-1] >= 0)wa[i] = i + A[i-1];
    if(i - A[i-1] >= 0 && i - A[i-1] < 300000)sa[i] = i - A[i-1];
  }



  vector<int> cnt1(300000,0);
  for(int i = 1;i <= N;i++){
    cnt1[wa[i]]++;
  }
  vector<int> cnt2(300000,0);
  for(int i = 1;i <= N;i++){
    cnt2[sa[i]]++;
  }
  ll ans = 0;
  rep(i,300000){
    if(i==0)continue;
    ll plus = 1ll*cnt1[i]*cnt2[i];
    ans += plus;
  }
  cout << ans << endl;

 }

Measured memory_bytes: 8020
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt(), q = scanner.nextInt();
        String s = scanner.next();
        List<Integer> ac = new ArrayList<>();
        for (int i = 1; i < n; i++)
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C')
                ac.add(i);
        for (int i = 0; i < q; i++) {
            int l = scanner.nextInt(), r = scanner.nextInt();
            int l1 = search(ac, l);
            int r1 = search(ac, r);
            System.out.println(r1 - l1);
        }
    }

    private static int search(List<Integer> list, int key) {
        int r = Collections.binarySearch(list, key);
        return r < 0 ? ~r : r;
    }
}

Measured memory_bytes: 98940
from collections import deque
H, W = list(map(int, input().split()))
S = [input().strip() for _ in range(H)]

M = [[-1] * W for _ in range(H)]


q = deque()
q.append((0, 0))
M[0][0] = 1

while q:
    p = q.popleft()

    directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
    for d in directions:
        x = p[0] + d[0]
        y = p[1] + d[1]

        if 0 <= x and x < W and 0 <= y and y < H:
            if M[y][x] == -1 and S[y][x] == ".":
                M[y][x] = M[p[1]][p[0]] + 1
                q.append((x, y))

minD = M[H-1][W-1]
count = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            count += 1

if minD == -1:
    print(-1)
else:
    print(count-minD)


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

#define endl '\n'
#define PI acos(-1.0)

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	priority_queue<size_t> p;
	while(true) {
		string cmd;
		cin >> cmd;
		
		if(cmd == "end") break;
		
		if(cmd == "insert") {
			int x;
			cin >> x;
			p.push(x);
		} else {
			cout << p.top() << endl;
			p.pop();
		}
	}
	
	return 0;
}



Measured memory_bytes: 11152
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), list(n + 10, 0);
  int i;
  for (i = 1; i < n; i++) {
    cin >> a[i];
    list[a[i]]++;
  }
    for (i = 1; i <= n; i++) {
      cout << list[i] << endl;
  }
  return 0;
}


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

int main(){
    int data[100000];
    for(int i=0; i<100000; i++) data[i]=0;
    
    int n;
    cin >> n;

    int maxA = 0;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        data[tmp]++;
        maxA = (maxA < tmp) ? tmp : maxA;
    }
    int maxCnt = 0;
    for (int i = 2; i < 100000; i++)
    {
        int sum = data[i-2]+data[i-1]+data[i];
        maxCnt = (maxCnt < sum) ? sum : maxCnt;
    }

    cout << maxCnt;
    
    
}

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

int main() {
    int n;
    cin >> n;
    for (int t = 0; t < n; t++) {
        int a[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                cin >> a[i][j];
            }
        }
        bool flag[9][9];
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                flag[i][j] = false;
            }
        }
        for (int i = 1; i < 10; i++) {
            for (int j = 0; j < 9; j++) {
                int count = 0;
                for (int k = 0; k < 9; k++) {
                    if (a[j][k] == i) count++;
                }
                if (count <= 1) continue;
                for (int k = 0; k < 9; k++) {
                    if (a[j][k] == i) flag[j][k] = true;
                }
            }


            for (int j = 0; j < 9; j++) {
                int count = 0;
                for (int k = 0; k < 9; k++) {
                    if (a[k][j] == i) count++;
                }
                if (count <= 1) continue;
                for (int k = 0; k < 9; k++) {
                    if (a[k][j] == i) flag[k][j] = true;
                }
            }

            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    int count = 0;
                    for (int l = 0; l < 3; l++) {
                        for (int o = 0; o < 3; o++) {
                            if (a[j * 3 + l][k * 3 + o] == i) count++;
                        }
                    }
                    if (count <= 1) continue;
                    for (int l = 0; l < 3; l++) {
                        for (int o = 0; o < 3; o++) {
                            if (a[j * 3 + l][k * 3 + o] == i) {
                                flag[j * 3 + l][k * 3 + o] = true;
                            }
                        }
                    }
                }
            }
        }

        if (t) cout << endl;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                if (flag[i][j]) cout << "*";
                else cout << " ";
                cout << a[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

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

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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


void solve(){
  ll N, M;
  cin >> N >> M;

  ll sum = 0;
  rep(i, M){
    ll a;
    cin >> a;
    sum += a;
  }

  int ans = N - sum;
  if(ans < 0) ans = -1;
  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int dp[1010][10010];

int main(){
    int h,n;
    cin>>h>>n;
    vector<int> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];

    rep(i,1010) rep(j,10010) dp[i][j]=INF;
    dp[0][0]=0;

    rep(i,n){
        for(int w=0;w<=h;w++){
            dp[i+1][w]=min(dp[i+1][w],dp[i][w]);
            dp[i+1][min(h,w+a[i])]=min(dp[i+1][min(h,w+a[i])],dp[i+1][w]+b[i]);
        }
    }

    cout<<dp[n][h]<<endl;

}


Measured memory_bytes: 43060
n,x=map(int, input().split())
x_list=list(map(int, input().split()))
x_list.sort()

from fractions import gcd

ans=abs(x-x_list[0])
for i in range(1, n):
    x_diff=x_list[i]-x_list[i-1]
    ans=gcd(ans, x_diff)

print(ans)

Measured memory_bytes: 14224
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt");
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        int n = int.Parse(input.ReadLine());
        
        int[] backet = new int[n];

        var s = input.ReadLine();
        var spl = s.Split(' ');

        for (int i=0; i<n; i++) {
            int no = int.Parse(spl[i]);
            backet[no - 1] = i + 1;
        }

        var buil = new StringBuilder(200);
        foreach(int no in backet) {
            buil.Append(no);
            buil.Append(" ");
        }

        return buil.ToString();
    }
}


Measured memory_bytes: 30044
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll X, A, B;
	cin >> X >> A >> B;

	if (B<=A) { cout << "delicious"; }
	else if (B <= A + X) { cout << "safe"; }
	else { cout << "dangerous"; }

	system("PAUSE");
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n,m;cin>>n>>m;
    string s;cin>>s;

    int checked = n;
    int num = 0;
    VI seq;

    while(checked != 0){
        bool f = false;
        for(int i=checked-m, j=m;i<checked;i++,j--){
            
            if(i<0){
                continue;
            }
            if(s[i] == '0'){
                checked = i;
                seq.PB(j);
                f = true;
                num++;
                //dump(i)
                //dump(j)
                break;
            }
        }
        if(!f){
            cout << -1 << endl;
            return;
        }

        //checked -= m;
    }

    PER(i,SIZE(seq)){
        cout << seq[i];
        if(i!=0){
            cout << " " ;
        }
    }
    cout << endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 1096
#Small and Large Integers

#入力
A,B,K = map(int,input().split())

#パターン足りない
if 2*K > B-A:
	for i in range(B-A+1):
		print(A+i)

#パターン足りる
else:
	for j in range(K):
		print(A+j)
	for k in range(K):
		print(B-K+1+k)

Measured memory_bytes: 3060
from collections import defaultdict
from collections import deque
N = int(input())
dict = defaultdict(int)
for a in [int(x) for x in input().split()]:
  dict[a] += 1

ab = deque([])
for a, cnt in dict.items():
  if cnt > 1:
    ab.append((a, cnt))

ab = sorted(list(ab), reverse=True)
i = 4
ret = 1
for abc in ab:
  if i == 2:
    ret *= abc[0]
    i = 0
    break
  elif abc[1] >= 4:
    ret = abc[0] ** 2
    i = 0
    break
  else:
    ret *= abc[0]
    i -= 2
if i:
  ret = 0
print(ret)

Measured memory_bytes: 18592
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;
int main() {
    int n;
    cin >> n;
    if(n % 2) {
        cout << (n - 1) * (n - 2) / 2 + n / 2 << endl;
        for(int i = 1; i < n; i++) {
            for(int j = i + 1; j <= n; j++) {
                if(i + j != n) {
                    cout << i << " " << j << endl;
                }
            }
        }
    } else {
        cout << (n - 1) * (n - 2) / 2 + (n / 2 - 1) << endl;
        for(int i = 1; i < n; i++) {
            for(int j = i + 1; j <= n; j++) {
                if(i + j != n + 1) {
                    cout << i << " " << j << endl;
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
void swapa(int x, int y){
    int c;
    c = x; x = y; y = c;
    return;
}
int main(){
    int x,y;
    cin >>x >> y;
    if(x<y) swapa(x,y);
    while(x>0 && y>0){
       x = x%y;
       swap(x,y);
    }
    cout << x <<  endl;
    return 0;
}


Measured memory_bytes: 3104
n, m = list(map(int, input().split()))
# 生徒の場所
ab = [list(map(int, input().split())) for i in range(n)]
# チェックポイント
cd = [list(map(int, input().split())) for i in range(m)]

for val in ab:
  tmp = []
  for point in cd:
    tmp.append(abs(val[0]-point[0])+abs(val[1]-point[1]))
  print(tmp.index(min(tmp))+1)

Measured memory_bytes: 3064
def lscan; gets.split.map(&:to_i); end

a,b,h,m = lscan

am = Rational(m,60)
ah = Rational(h,12) + am/12

radm=am.to_f*2*Math::PI
radh=ah.to_f*2*Math::PI

xm = Math::cos(radm)*b
ym = Math::sin(radm)*b
xh = Math::cos(radh)*a
yh = Math::sin(radh)*a

p Math::hypot((xm-xh), (ym-yh))

Measured memory_bytes: 14740
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

void Merge(int *,int,int,int);
void MergeSort(int *,int,int);
int cnt=0;

int main(){
  int i,n,left,right;
  int *a;

  scanf("%d",&n);
  a=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  right=n;
  left=0;

  MergeSort(a,left,right);

  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n%d\n",cnt);

  free(a);


  return 0;

}


void Merge(int *A,int left,int mid,int right){
  int *L,*R,i,k,j,n1,n2;
  // for(i=0;i<10;i++) printf("%d \n",A[i]);

  n1 = mid - left;
  n2 = right - mid;

  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));


  for( i = 0 ; i <= n1-1; i++){
    L[i] = A[left + i];
  }
  for( i = 0 ; i <= n2-1; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i = 0;
  j = 0;

  for(k = left ; k<=right-1; k++){
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
      cnt++;
    }
    else {
      A[k] = R[j];
      j = j + 1;
      cnt++;
    }
  }
  free(L);
  free(R);
}

void MergeSort(int *A,int left,int right){
  int i,mid;

  if (left+1 < right){
    mid = (left + right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }

}

Measured memory_bytes: 4484
N, M = map(int, input().split())
graph = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)


def dfs(now, visited):
    visited.append(now)
    if len(visited) == N:
        return 1

    ret = 0
    for edge in graph[now]:
        if edge in visited:
            continue
        ret += dfs(edge, visited[:])

    return ret


print(dfs(0, []))


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

using namespace std;

using ll = long long int;
using pii = pair<int, int>;

int main()
{
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    map<int, vector<int>> mp_a_and_i;
    for (int i = 0; i < N; i++)
    {
        mp_a_and_i[A[i]].push_back(i);
    }

    vector<pii> ni_and_isadd(N);
    for (const auto a_and_i : mp_a_and_i)
    {
        vector<int> v = a_and_i.second;
        for (int j = 0; j < v.size(); j++)
        {
            int i = v[j];
            int ni = (v[(j + 1) % v.size()] + 1) % N;
            int isadd = ((((j + 1) == v.size())) ? 1 : 0);
            ni_and_isadd[i] = pii(ni, isadd);
        }
    }

    int ni = 0;
    int T = 0;
    T += ni_and_isadd[ni].second;
    ni = ni_and_isadd[ni].first;
    while (ni != 0)
    {
        T += ni_and_isadd[ni].second;
        ni = ni_and_isadd[ni].first;
    }
    T++;

    int r = K % T;
    int ni2 = 0;
    int T2 = 0;
    int i_start = ni2;
    while (T2 < r)
    {
        i_start = ni2;
        T2 += ni_and_isadd[ni2].second;
        ni2 = ni_and_isadd[ni2].first;
    }

    vector<int> ans;
    map<int, int> a_to_i;
    for (int i = i_start; i < N; i++)
    {
        int test = a_to_i.size();
        if (a_to_i.find(A[i]) == a_to_i.end())
        {
            ans.push_back(A[i]);
            a_to_i[A[i]] = ans.size() - 1;
        }
        else
        {
            const int ii_start = a_to_i[A[i]];
            for (int ii = ii_start; ii < ans.size(); ii++)
            {
                a_to_i.erase(ans[ii]);
            }
            ans.erase(ans.begin() + ii_start, ans.end());
        }
    }

    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 35828
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
//#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
vector<ll> ed[100005];
map<ll,ll> mp,ans;
void depth(vector<ll> n,ll d)
{
    vector<ll> v;
    rep(i,n.size()) mp[n[i]]=d;
    //cout<<"e\n";
    rep(i,n.size())
    {
        rep(j,ed[n[i]].size())
        {
            if(mp[ed[n[i]][j]]==0)
            {
                v.pb(ed[n[i]][j]);
                mp[ed[n[i]][j]]=-1;
            }
        }
    }
    if(v.size()==0) return;
    depth(v,d+1);
}
int main()
{
    ll n,m;
    cin>>n>>m;
    rep(i,m)
    {
        ll u,v;
        cin>>u>>v;
        ed[u].pb(v);
        ed[v].pb(u);
    }
    mp[1]=1;
    depth(ed[1],2);
    for(int i=2;i<=n;i++)
    {
        rep(j,ed[i].size())
        {
            if(mp[ed[i][j]]+1==mp[i])
            {
                ans[i]=ed[i][j];
                break;
            }
        }
    }
    cout<<"Yes\n";
    for(int i=2;i<=n;i++) cout<<ans[i]<<"\n";
}


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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H.at(i);
  vector<int> DP(N, 1e9);
  DP.at(0) = 0;
  for (int i = 0; i < N; i++) {
    if (i + 1 >= N) continue; 
    DP.at(i + 1) = min(DP.at(i + 1), DP.at(i) + abs(H.at(i + 1) - H.at(i)));
    if (i + 2 >= N) continue;
    DP.at(i + 2) = min(DP.at(i + 2), DP.at(i) + abs(H.at(i + 2) - H.at(i)));
  }
  cout << DP.at(N - 1) << "\n";
}

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

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

N, A, B, C = inpl()
L = [0]*N
for i in range(N):
    L[i] = int(input())

ans = 10**9
for k in range(4**N):
    ABC = [0]*3
    CNT = [0]*3
    j = k*1
    for i in range(N):
        d, m = divmod(j, 4)
        if m <= 2:
            ABC[m] += L[i]
            CNT[m] += 1
        j = d
    if min(CNT) == 0:
        continue
    tmp = abs(ABC[0] - A) + abs(ABC[1] - B) + abs(ABC[2] - C) + sum([10*(cnt-1) for cnt in CNT])
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 48092
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		sc.close();
		
		int tutotal = x - a;
		System.out.println(tutotal%b);
			
		
		

	}

}


Measured memory_bytes: 23124
<?php
$in = explode(" ", trim(fgets(STDIN)));
$a = $in[0];
$b = $in[1];

$d = $a / $b;
$r = $a % $b;
$f = $a / $b;

echo floor($d) . " " . $r . " " . sprintf("%.5f",$f) . "\n";

Measured memory_bytes: 15204
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S, T;
    cin >> S >> T;


    for(int i = 0; i < S.size(); i++) {
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }

        S = S.back() + S.substr(0, S.size()-1);
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
// Good Sequence

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a) vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    map<int,int>m{};
    int ma=0;
    rep(i,0,n){
        int a;cin>>a;
        m[a]++;
        ma=max(a,ma);
    }
    int ans = 0;
    irep(i,m){
        if(i->second>=i->first)ans+=abs(i->second-i->first);
        if(i->second<i->first)ans+=i->second;
    }
    cout<<ans<<nnn;
    return 0;
}

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

int main(){
	
	string s;
	cin>>s;
	
	stack<char> st;
	for(int i=0;i<(int)s.size();i++){
		if(s[i]!='B'){
			st.push(s[i]);
		} else if(!st.empty()){
			st.pop();
		}
	}
	
	string res;
	while(!st.empty()){
		res+=st.top();
		st.pop();
	}
	for(int i=res.length()-1;i>=0;i--) cout<<res[i];
}

Measured memory_bytes: 256