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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string N; cin >> N;
  ll d = 0; rep(i,N.size()) d += N[i] - '0';
  string result = d%9 ? "No" : "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3704
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    res = 0
    m = 0
    l_g = [0,A[0]]
    r_g = [0,A[-1]]
    ind = 2
    for i in A[1:]:
        l_g.append(gcd(l_g[ind-1],i))
        ind += 1
    ind = 2
    for i in range(n-2,-1,-1):
        r_g.append(gcd(r_g[ind-1],A[i]))
        ind += 1
    r_g = r_g[::-1]
    r_g = r_g[1:]

    for i in range(len(r_g)):
        if(r_g[i]!=0 and l_g[i]!=0):
            res = max(res, gcd(r_g[i],l_g[i]))
        else:
            res = max(r_g[i],l_g[i],res)
    print(res)

if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	vi a(n), cnt(4);
  	rep(i,n) {
      	cin >> a[i];
    	a[i] %= 4;
      	rep(j,4) if(a[i] == j) cnt[j]++;
    }
	// sort(all(a));
  	// rep(i,n) cout << a[i] << " ";
  	if(cnt[2]>1) cnt[2] = 1;
	if(cnt[0] >= cnt[1]+cnt[2]+cnt[3]-1) puts("Yes");
  	else puts("No");  
  	return;
}

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

Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
B = [i for i in range(1,N+1)]
C = zip(A, B)
C = sorted(C, reverse = True)
A, B = zip(*C)
dp = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
    for j in range(i + 2):
        if j == 0:
            dp[0][i-j+1] = dp[0][i-j] + A[i] * (N - (i - j) - B[i])
        elif j == i+1:
            dp[j][0] = dp[j-1][0] + A[i] * (B[i] - j)
        else:
            dp[j][i-j+1] = max(dp[j][i-j] + A[i] * (N - (i - j) - B[i]), dp[j-1][i-j+1] + A[i] * (B[i] - j))
ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)

Measured memory_bytes: 101368
//by OIerC
//Forca Barcelona!
#include<cstdio>
using namespace std;
const int P = 1e9 + 7;

void add(int &a, int b){a += b; a >= P ? a -= P : 0;}
void sub(int &a, int b){a -= b; a < 0 ? a += P : 0;}

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int M = 2e3 + 5, N = 2e5 + 5;
int a[N], b[N], dp[M * 2][M * 2];
int fac[M * 4 + 5], ifac[M * 4 + 5];
int ans;

int Pow(int x, int t)
{
	int res = 1;
	for (; t; t >>= 1, x = 1LL * x * x % P)
		if (t & 1) res = 1LL * res * x % P;
	return res;
}

int C(int n, int m)
{
	if (n < m) return 0;
	return 1LL * fac[n] * ifac[n - m] % P * ifac[m] % P;
}

int main()
{
	int n = read();
	for (int i = 1; i <= n; ++i) 
		a[i] = read(), b[i] = read();
	
	for (int i = 1; i <= n; ++i) ++dp[M - a[i]][M - b[i]];
	for (int i = 1; i < 2 * M; ++i)
		for (int j = 1; j < 2 * M; ++j)
			add(dp[i][j], (dp[i][j - 1] + dp[i - 1][j]) % P);
	for (int i = 1; i <= n; ++i) 
		add(ans, dp[a[i] + M][b[i] + M]);	
	
	fac[0] = 1;
	for (int i = 1; i <= 4 * M; ++i) fac[i] = 1LL * fac[i - 1] * i % P;
	ifac[4 * M] = Pow(fac[4 * M], P - 2);
	for (int i = 4 * M; i; --i) ifac[i - 1] = 1LL * ifac[i] * i % P;
	
	for (int i = 1; i <= n; ++i)
		sub(ans, C(2 * a[i] + 2 * b[i], 2 * a[i]));
	
	printf("%d\n", 1LL * ans * ifac[2] % P);
	return 0;
}


Measured memory_bytes: 64640
#include <stdio.h>
#include <string.h>
#define N 200002
typedef unsigned long long LL;

int a[N], lp[N], rp[N];
LL ans;

int main()
{	
	int n, i, tp, t;
	
	scanf("%d", &n);
	for(i = 1; i <= n; i++) scanf("%d", a + i);
	a[0] = a[n + 1] = 0;
	for(lp[1] = 0, i = 2; i <= n; i++){
		tp = i - 1, t = a[i];
		while(a[tp] > t) tp = lp[tp];
		lp[i] = tp;
	}
	
	ans = (LL)a[n] * (LL)(n - lp[n]); 
	for(rp[n] = n + 1, i = n - 1; i >= 1; i--){
		tp = i + 1, t = a[i];
		while(a[tp] > t) tp = rp[tp];
		rp[i] = tp;
		ans += (LL)t * (LL)(tp - i) * (LL)(i - lp[i]);
	}
	printf("%llu\n", ans);	
	
	return 0;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    class Program
    {

        static double best;
        static int n;
        static int a;
        static int b;
        static int a_cal;
        static int[] b_cal;
        
        
        static void BestPiza()
        {
            int m = 0;  

            for(int i = 0; i <= n; i++)
            {
                m = 0;

                for(int j = 0; j < i; j++)
                {
                    m += b_cal[j];
                }

                double v = (double)(a_cal + m) / (a + i * b);

                if(best < v)
                {
                    best = v;
                }
            }         

        }



        static void Main(string[] args)
        {

            n = int.Parse(Console.ReadLine()); 
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]); 
            b = int.Parse(str[1]);  
            a_cal = int.Parse(Console.ReadLine());  
            b_cal = new int[n]; 

            for (int i = 0; i < n; i++)
            {
                b_cal[i] = int.Parse(Console.ReadLine());
            }

            Array.Sort(b_cal);
            Array.Reverse(b_cal);            

            best = -1;

            BestPiza();

            Console.WriteLine((int)best);

        }
    }
}



Measured memory_bytes: 15916
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i) // i in [0,n)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // i in [b,a)

#define MAX_N 8
#define MAX_M 30
const double INF = 1<<30;

int n,m,p,a,b;
int t[MAX_N]; // ticket
int d[MAX_M][MAX_M]; // distance
double dp[1<<MAX_N][MAX_M]; // dp[S][v] = 残りチケットの集合がS,現在がvの時の最小コスト

void solve(void){
  // init
  rep(i,1<<n) fill(dp[i],dp[i]+m,INF);
  dp[(1<<n)-1][a] = 0; // 出発前はコスト0
  
  ROF(S, 1<<n, 0) rep(v,m) // 集合SについてSを小さくしながら = チケットを使いながら、都市vについてdp[S][v]の次の遷移を考える
    rep(i,n) if(S >> i & 1) // チケットiについてi in Sのとき
    rep(u,m) if(d[v][u] > 0) // 都市uに対しv->uの道があるなら
      dp[S & ~(1<<i)][u] = min(dp[S & ~(1<<i)][u], dp[S][v] + double(d[v][u])/t[i]); // そのチケットを使って移動
  
  double res = INF;
  rep(S,1<<n){
    res = min(res, dp[S][b]);
    //cout << dp[S][b] << endl;
  }
  
  if(res == INF) cout << "Impossible" << endl;
  else printf("%.10f\n",res);
}

int main(void){
  while(cin >> n >> m >> p >> a >> b, n|m|p|a|b){
    a--; b--;
    rep(i,n) cin >> t[i];

    rep(i,m) fill(d[i],d[i]+m,-1); // 辺がなければ距離-1
    int x,y,z;
    rep(i,p){
      cin >> x >> y >> z; x--; y--;
      d[x][y] = d[y][x] = z;
    }
    //rep(i,m){ rep(j,m) cout << d[i][j]; cout << endl; }

    solve();
  }

  return 0;
}


Measured memory_bytes: 3196
input()
A = [int(i) for i in input().split()]
n = 0
for i in range(0, len(A)):
    minj = i
    for j in range(i, len(A)):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
        n += 1

print(" ".join(map(str, A)))
print(n)



Measured memory_bytes: 5604
#include <string>
#include <iostream>
int main(){
	using namespace std;
	ios::sync_with_stdio (false);
	string a;
    cin>>a;
    int Len=a.size();
    bool c=false,f=false;
    for (int i=0;i<Len;i++){
        if (a[i]=='C')
			c=true;
        if (a[i]=='F'&&c)
			f=true;
    }
    cout<<(f?"Yes":"No")<<endl;
    return 0;
}

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

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  bool flg = true;

  if (n % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[i + n / 2]) {
      flg = false;
      break;
    }
  }

  cout << (flg ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	string ans = "";
	int in;
	map <string ,vector <int> > mp;
	while(cin >> s >> in){
		mp[s].push_back(in);
	}
	for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
		cout << (*itr).first << endl;
		sort((*itr).second.begin(),(*itr).second.end());
		for(int i = 0; i < (*itr).second.size() ; i++)
			cout << (*itr).second[i] << (i == (*itr).second.size() - 1 ? "" : " ");
		cout << endl;
	}
}

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

using namespace std;

int main() {
  int n, k, ans = 0;
  cin >> n >> k;
  int x[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    ans += min(x[i] * 2, abs(k - x[i]) * 2);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, L = map(int, readline().split())
    S = [readline().strip() for _ in range(N)]

    S.sort()
    ans = ''.join(S)
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61880
#include <stdio.h>

#define _CRT_SECURE_NO_WARNINGS

int main(void) {
	int a, b,c,d;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if (a > b) {
		d = a;
		a = b;
		b = d;
	}
	if (b > c) {
		d = b;
		b = c;
		c = d;
	}
	if (a > b) {
		d = a;
		a = b;
		b = d;
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    char a[n][n];
    char b[m][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            cin >> b[i][j];
        }
    }    
    bool match = true;
    int count;
    for (int ax = 0; ax < n-m+1; ax++) {
        for (int ay = 0; ay < n-m+1; ay++) {
            count = 0;
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < m; j++) {
                    if (a[i+ax][j+ay] != b[i][j]) {
                        i = m;
                        j = m;
                    } else {
                        count++;
                    }
                }
            }
            if (count == m*m) {
                cout << "Yes\n";
                ax = n-m+1;
                ay = n-m+1;
            }
        }
    }
    if (count != m*m) cout << "No\n";
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    vvll a(3, vll(3));
    rep(i,3)rep(j,3)cin >> a[i][j];

    ll n;
    cin >> n;
    rep(i,n){
        ll b;
        cin >> b;
        rep(x,3)rep(y,3)if(a[x][y] == b)a[x][y] = 0;
    }

    vector<bool> check(8,true);
    rep(i,3)rep(j,3){
        if(a[i][j] != 0)check[i] = false;
        if(a[j][i] != 0)check[i+3] = false;
        if(a[i][i] != 0)check[6] = false;
        if(a[2-i][i] != 0)check[7] = false;
    }

    rep(i,8)if(check[i] == true){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;


    return 0;
}

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

void compareValue(int a, int b, int c)
{
    cout << ((a < b && b < c) ? "Yes" : "No") << endl;
}

int main()
{
    int a = 0, b = 0, c = 0;
    cin >> a >> b >> c;
    compareValue(a, b, c);
    
    return 0;
}

Measured memory_bytes: 1152
class UnionFind:
    __slots__ = ["N", "root", "rank"]

    def __init__(self, N):
        """
        N:要素数
        root:各要素の親要素の番号を格納するリスト.
             ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
        rank:ランク
        """
        self.N = N
        self.root = [-1] * N
        self.rank = [0] * N

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def find(self, x):
        """頂点xの根を見つける"""
        while self.root[x] >= 0:
            x = self.root[x]
        return x

    def union(self, x, y):
        """x,yが属する木をunion"""
        # 根を比較する
        # すでに同じ木に属していた場合は何もしない.
        # 違う木に属していた場合はrankを見てくっつける方を決める.
        # rankが同じ時はrankを1増やす
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x, y):
        """xとyが同じグループに属するかどうか"""
        return self.find(x) == self.find(y)

    def count(self, x):
        """頂点xが属する木のサイズを返す"""
        return - self.root[self.find(x)]

    def members(self, x):
        """xが属する木の要素を列挙"""
        _root = self.find(x)
        return [i for i in range(self.N) if self.find == _root]

    def roots(self):
        """森の根を列挙"""
        return [i for i, x in enumerate(self.root) if x < 0]

    def group_count(self):
        """連結成分の数"""
        return len(self.roots())

    def all_group_members(self):
        """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
        return {r: self.members(r) for r in self.roots()}


import sys
input = sys.stdin.readline
n, q = map(int, input().split())
uf = UnionFind(n)
res = []
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        res.append(int(uf.same(u, v)))
    else:
        uf.union(u, v)
print(*res,sep="\n")


Measured memory_bytes: 80884
//include
//------------------------------------------
#include <bits/stdc++.h>
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//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)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<pair<ll, ll>> get_surround(ll x, ll y, ll H, ll W){
    vector<pair<ll, ll>> res;
    res.emplace_back(x,y);

    if(x-1 >= 0){
        res.emplace_back(x-1,y);
        if(y-1 >= 0) res.emplace_back(x-1,y-1);
        if(y+1 < W) res.emplace_back(x-1,y+1);
    }

    if(y-1 >= 0) res.emplace_back(x,y-1);
    if(y+1 < W) res.emplace_back(x,y+1);

    if(x+1 < H){
        res.emplace_back(x+1,y);
        if(y-1 >= 0) res.emplace_back(x+1,y-1);
        if(y+1 < W) res.emplace_back(x+1,y+1);
    }

    return res;
}

int main(void){

    ll H, W, N;
    cin >> H >> W >> N;
    ll a[N], b[N];
    REP(i,N) cin >> a[i] >> b[i];

    map<pair<ll,ll>, ll> m;
    ll ans[10];
    REP(i,10) ans[i] = 0;

    REP(i,N){
        vector<pair<ll, ll>> v = get_surround(a[i]-1, b[i]-1, H, W);
        for(pair<ll, ll> p : v){
            if(m.find(p) != m.end()) m[p]++;
            else m[p] = 1;
        }
    }

    ans[0] = (H-2)*(W-2);
    for(auto itr=m.begin(); itr!=m.end(); itr++){
        if(itr->first.first==0 || itr->first.second==0 || itr->first.first==H-1 || itr->first.second==W-1)
            continue;
        ans[itr->second]++;
        ans[0]--;
    }

    REP(i,10) cout << ans[i] << endl;

    return 0;
}

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



public class Main{
	public static void main(String[] args){

		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		int a, b, C;
		double S, L, h, c, R;//S:??¢??????L:??¨????????????h:a???????????¨????????¨????????????
		String str;
		String[] array_str;

		try{
			str=reader.readLine();
			array_str=str.split(" ");
			a=Integer.parseInt(array_str[0]);
			b=Integer.parseInt(array_str[1]);
			C=Integer.parseInt(array_str[2]);

			S=Math.sin(Math.toRadians(C))*a*b/2;
			c=Math.sqrt(b*b+a*a-2*a*b*Math.cos(Math.toRadians(C)));
			R=c/Math.sin(Math.toRadians(C));
			L=a+b+c;
			h=b*Math.sin(Math.toRadians(C));

			System.out.printf("%.8f", S);
            System.out.println();
            System.out.printf("%.8f", L);
            System.out.println();
            System.out.printf("%.8f", h);
            System.out.println();

		}catch(IOException e){
			System.out.print(e);
		}
	}

}

Measured memory_bytes: 24744
A, B, N = map(int,input().split())
mmax=0
N_max = N if B > N else B
for n in reversed(range(N_max - A, N_max + 1)):
    _max = int(A*n/B)-(A*int(n/B))
    if mmax < _max:
        mmax=_max

print(mmax)

Measured memory_bytes: 9176
#include <stdio.h>
#include <limits.h>

#define MAX 500000

long cnt = 0;
long L[MAX / 2 + 1], R[MAX / 2 + 1];
//分割
void merge(long A[], long left, long mid, long right) {
  long i, j, k;
  long n1 = mid - left;
  long n2 = right - mid;
  for (i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  L[n1] = LONG_MAX;
  for (i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  R[n2] = LONG_MAX;

  i = 0;  j = 0;

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

//統合
void mergeSort(long A[], long left, long right) {
  int mid;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void) {
  long A[MAX];
  long i, n;

  scanf("%ld", &n);

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

  mergeSort(A, 0, n);

  printf("%ld", A[0]);
  for(i = 1; i < n; i++)
    printf(" %ld", A[i]);
  printf("\n%ld\n", cnt);

  return 0;
}

Measured memory_bytes: 8836
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s = collections.Counter([str(readline().rstrip().decode('utf-8')) for _ in range(n)]).most_common()
    s.sort(key=lambda x: x[0])
    s.sort(key=lambda x: x[1], reverse=True)
    for k, v in s:
        if v == s[0][1]:
            print(k)
        else:
            break


if __name__ == '__main__':
    solve()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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; }
const ll MOD = 1e9+7;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    REP(q, Q){
        int k;
        cin >> k;

        int d = 0;
        int m = 0;
        ll num = 0;
        ll ans = 0;
        REP(i,N){
            char c = S[i];
            if(c == 'D'){
                d++;    
            }
            else if(c == 'M'){
                m++;
                num += d; 
            }
            else if(c == 'C'){
                ans += num;
            }

            if(i >= k-1){
                char pc = S[i - k + 1];
                if(pc == 'D'){
                    d--;    
                    num -= m;
                }
                else if(pc == 'M'){
                    m--;
                    //num -= d; 
                }
                else if(pc == 'C'){
                    //ans += num;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int n;cin>>n;
    double ret=0;
    FOR(i,n){
        int x;cin>>x;
        ret += (double)1/x;
    }
    cout << setprecision(8) << fixed << (double)1/ret;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int t,n;
    
    for(int i = 0; i < 4; i++){
        cin >> t >> n;
        
        if(t == 1){
            cout << 6000 * n;
        }
        else if(t == 2){
            cout << 4000 * n;
        }
        else if(t == 3){
            cout << 3000 * n;
        }
        else{
            cout << 2000 * n;
        }
        cout << endl;
    }
}


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

int main()
{
    int l, flg;
    unsigned int ans;
    string s,ss;

    cin >> s;
    l = s.size();
    ans = 0;
    rep(i,l) {
        for (int j = 1;j <= l - i;++j) {
            ss = s.substr(i, j);
            flg = 0;
            rep(k, ss.size()) {
                if (ss.at(k) != 'A' && ss.at(k) != 'C' && ss.at(k) != 'G' && ss.at(k) != 'T') {
                    ++flg;
                    break;
                }
            }
            if (flg == 0)
                if (ans < ss.size())
                    ans=ss.size();
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define ll long long
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if((a*b)%2==1){cout << "Odd" << endl;}
    else cout << "Even" << endl;

    return 0;
}

Measured memory_bytes: 256
X, N = map(int, input().split())
if N > 0:
    p = list(map(int, input().split()))

    move = 0
    while True:
        minus_check = X - move
        if minus_check not in p:
            print(minus_check)
            break

        pulus_check = X + move
        if pulus_check not in p:
            print(pulus_check)
            break

        move += 1
else:
    print(X)


Measured memory_bytes: 61664
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
A = LIST()

sm = sum(A)
ans = N - sm
if ans < 0:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 10172
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
char n, m,k, a[1000000] = {}, sum, ans = 0, dp[100000][10000] = {};
bitset<10000>bi[10] = {};
struct edge { LL to, cost; };
vector<edge>vec[100000];
string st[2],str;
int main(){
	cin >> n >> m;
	cout << (n > m ? ">" :(n<m? "<":"=")) << endl;
	return 0;
}

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

const int N=105;
int n,a[N],b[N];
bool del[N];
vector<int> v;

int main()
{
    cin>>n;
	for(int i=1;i<=n;i++)
	{
        scanf("%d",&a[i]);b[i]=i;
		if(a[i]>i) return puts("-1"),0;
	}
	while(v.size()<n)
	{
        bool flag=0;
		for(int i=n;i>=1;i--)
		if(!del[i]&&a[i]==b[i])
		{
            del[i]=1;flag=1;
            v.emplace_back(a[i]);
			for(int j=i+1;j<=n;j++) b[j]--;
			break;
		}
		if(!flag) return puts("-1"),0;
	}
	reverse(v.begin(),v.end());
	for(auto x : v) printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 256
n = int( input() )
abc = []
for _ in range(n): abc.append( list( map( int, input().split() ) ) )

dp = [[0]*3 for _ in range(n)]
dp[0] = abc[0]
for i in range(1,n):
    dp[i][0] = max(dp[i-1][1]+abc[i][0],dp[i-1][2]+abc[i][0])
    dp[i][1] = max(dp[i-1][0]+abc[i][1],dp[i-1][2]+abc[i][1])
    dp[i][2] = max(dp[i-1][0]+abc[i][2],dp[i-1][1]+abc[i][2])

print(max(dp[n-1]))

Measured memory_bytes: 74756
#include<iostream>
using namespace std;
int n,a[100010],b,ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>b;
		if(b>100000)
		  ans++;
		else a[b]++;
	}
	for(int i=0;i<100001;i++)
	{
		if(a[i]>=i)
		  ans+=a[i]-i;
		else ans+=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])
    Q = int(input())
    reverse = False
    before = []
    after = []
    for _ in range(Q):
        q = list(map(str, input().split()))
        t = q[0]
        if t == '1':
            reverse = not (reverse)
        else:
            if reverse ^ (q[1] == '1'):
                before.append(q[2])
            else:
                after.append(q[2])
    if reverse:
        after.reverse()
        s.reverse()
        print(''.join(after + s + before))
    else:
        before.reverse()
        print(''.join(before + s + after))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 10080
<?php
$n = intval(trim(fgets(STDIN)));
$s = trim(fgets(STDIN));
$kigu = 0;
for($i = 0; $i < $n; ++$i){
    $dp[$i] = ((int)$s[$i])-1;
    $kigu ^= ($dp[$i]%2) * ((($n-1) & $i) == $i);
}
if($kigu){
    echo 1;
}else{
    if(array_search(1, $dp)!==false){
        echo 0;
    }else{
        $kigu = 0;
        for($i = 0; $i < $n; ++$i){
            $kigu ^= ($dp[$i]/2) * ((($n-1) & $i) == $i);
        }
        if($kigu){
            echo 2;
        }else{
            echo 0;
        }
    }
}


Measured memory_bytes: 41584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

char BUF[3500000];
inline void I(int &a){scanf("%d",&a);}
inline void VI(vector<int> &v,int n){int t;rep(i,n){I(t);v.pb(t);}}
inline void L(ll &a){scanf("%I64d",&a);}
inline void VL(vector<ll> &v,int n){ll t;rep(i,n){L(t);v.pb(t);}}
inline void S(string &str){scanf("%s",&BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int> &v){scanf("%s",&BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

int main(){
    string str;
    S(str);
    rep(i,str.size()){
        if(str[i]==',') str[i] = ' ';
    }
    cout << str << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		Map<String, Long> points = new HashMap<String, Long>();
		for (int i = 0; i < N; i++) {
			String key = sc.next();
			long tmp = (points.get(key) == null) ? 0L : points.get(key);
			points.put(key, ++tmp);
		}
		
		long M = sc.nextLong();
		for (int i = 0; i < M; i++) {
			String key = sc.next();
			long tmp = (points.get(key) == null) ? 0L : points.get(key);
			points.put(key, --tmp);
		}

		Long maxP = 0L;
		for (Entry<String, Long> ent : points.entrySet()) {
			if (maxP < ent.getValue()) {
				maxP = ent.getValue();
			}
		}
		
		System.out.println(maxP);
	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;


bool cmp(const P &a, const P &b){
    return a.second > b.second;
} 

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}
    vector<P> bc;
    rep(i, m){ int tmpb, tmpc; cin >> tmpb >> tmpc; bc.push_back(P(tmpb, tmpc));}

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

    sort(bc.begin(), bc.end(), cmp);

    vector<int> cmp;
    for (auto itr: bc)
    {
        rep(i, itr.first){
            cmp.push_back(itr.second);
        }
        if (cmp.size() >= n) break;    
    }

    ll ans = 0;    
    rep(i, n){
        if (i < cmp.size()){
            ans += max(a[i], cmp[i]);
        } else {
            ans += a[i];
        }
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 2932
from math import factorial
 
M = 10**9 + 7
n, a, b = map(int, input().split())
r = pow(2, n, M) - 1
c = 1
for i in range(b):
  c = c * (n - i) % M
  if i + 1 == a:
    r -= c * pow(factorial(a) % M, M - 2, M)
    a = b
print(r % M)


Measured memory_bytes: 5468
#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
#include<cstdlib>
using namespace std;

bool isso(long long int a) {
	if (a == 1||a==0)return false;
	for (long long int i = 2; i*i <= a; ++i) {
		if ((a%i)) {
		}
		else {
			return false;
		}
	}
	return true;
}



long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

struct edge {
	int from;
	int to;
	int cost;
};

struct aa {
	int now;
	int fuel;
	int cost;
};

class Compare {
public:
	//keiroが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.cost> r.cost;
	}
};

vector<vector<int>>involve;


vector<int> dfs2(const int now, vector<bool>&used) {
	if (used[now])return vector<int>(0);
	else {
		used[now] = true;
	}
	vector<int>ans;
	for (auto i : involve[now]) {
		if (involve[i].size()) {
			vector<int>a(dfs2(i,used));
			ans.insert(ans.end(), a.begin(), a.end());
		}
		else {
			ans.push_back(i);
		}
	}
	return ans;
}


int main() {
	while (1) {
		int num = 0;
		map<string,int>mp;
		set<int>ed;
		int N; cin >> N;
		if (!N)break;
		involve.clear();
		involve.resize(100000);
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			string groupname;
			vector<string> membername;
			int pre;
			for (int j = 0; j < st.size(); ++j) {
				if (st[j] == ':') {
					groupname = st.substr(0, j);
					pre = j;
				}
				else if (st[j] == ','||st[j]=='.') {
					membername.push_back(st.substr(pre + 1, j - pre - 1));
					pre = j;
				}
			}
			if (!mp.count(groupname)) {
				mp[groupname] = num++;
			}
			for (int i = 0; i < membername.size(); ++i) {
				if (!(mp.count(membername[i]))) {
					mp[membername[i]] = num++;
				}
			}
			for (int i = 0; i < membername.size(); ++i) {
				involve[mp[groupname]].push_back(mp[membername[i]]);
				ed.emplace(mp[membername[i]]);
			}
		}
		vector<bool>used(100001, false);
		vector<int>allnames(dfs2(0,used));
		sort(allnames.begin(), allnames.end());
		const int ans(unique(allnames.begin(), allnames.end()) - allnames.begin());
		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 5476
N = list(input())
ans = 0
temp = [0] + [int(n) for n in N]
for i in reversed(range(1, len(N)+1)):
    if temp[i] < 5 or (temp[i] == 5 and temp[i-1] < 5):
        ans += temp[i]
    else:
        temp[i-1] += 1
        ans += (10 - temp[i])
        temp[i] = 0
ans += temp[0]
print(ans)

Measured memory_bytes: 29292
N,M,X = [int(i) for i in input().split()]
A = []
for _ in range(N):
    A.append([int(i) for i in input().split()])
ans = float("inf")

for i in range(1,2**N):
    a = 0
    e = [0]*M
    bi = "0"*N + bin(i)[2:]
    bi = list(bi[len(bi)-N:])
    for j in range(N):
        if bi[j] == "1":
            a += A[j][0]
            for k in range(M):
                e[k] += A[j][k+1]
    c = True
    for i in range(M):
        c &= e[i] >= X
    if c:
        ans = min(ans,a)
if ans > 10**7:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9236
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int l,r;
}a[200005];
bool cmp(node a,node b)
{
	if(a.l==b.l) return a.r<b.r;
	return a.l<b.l;
}
int main()
{
	vector<int> v[505];
	int n,m,Q,p,q,i,j;
	scanf("%d%d%d",&n,&m,&Q);
	for(i=0;i<m;i++) scanf("%d%d",&a[i].l,&a[i].r);
	sort(a,a+m,cmp);
	for(i=0;i<m;i++) v[a[i].l].push_back(a[i].r);
	while(Q--)
	{
		int ans=0;
		scanf("%d%d",&p,&q);
		for(j=p;j<=q;j++)
		{
			int len=v[j].size();
			for(i=len-1;i>=0;i--) if(v[j][i]<=q) break;
			ans+=i+1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3584
A, B, K = map(int, input().split())
a = []
b = []

for x in range(1, A + 1):
    if A % x == 0:
        a.append(x)

for y in range(1, B + 1):
    if B % y == 0 and y in a:
        b.append(y)

b = sorted(b,reverse = True)

print(b[K - 1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep_a(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

int main(){

 long long n;
 cin>>n;

 vector<int>p(n),q(n);

 rep(i,n) cin>>p[i];
 rep(i,n) cin>>q[i];

    vector<int> v(n);
    iota(v.begin(), v.end(), 1);

    int i = 1;
    int a,b;
    do {
        if(p == v) a = i;
        if(q == v) b = i;
        i++;
    } while( next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;


return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

void f(ll n, char c) { rep(i, n) cout << c; }

int main() {
  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  f(ty - sy, 'U');
  f(tx - sx, 'R');
  f(ty - sy, 'D');
  f(tx - sx + 1, 'L');
  f(ty - sy + 1, 'U');
  f(tx - sx + 1, 'R');
  f(1, 'D');
  f(1, 'R');
  f(ty - sy + 1, 'D');
  f(tx - sx + 1, 'L');
  cout << 'U' << endl;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(a) (a).begin(),(a).end()

int p[10];
int h[10];
const int base[] = {4, 1, 4, 1, 2, 1, 2, 1};

string f() {
  int num = 0;
  rep(i,8) {
    num *= 10;
    num += h[i];
  }
  stringstream ss;
  ss << num;
  return ss.str();
}

void solve() {
  rep(i,8) h[i] = base[i];

  int mnCnt = 1 << 28;
  string mnH;
  
  rep(i,8) {
    rotate(h, h+1, h+8);
    int cnt = 0;
    rep(j,8) cnt += max(0, p[j] - h[j]);
    // printf("cnt=%d\n", cnt);
    string temp = f();
    if (mnCnt > cnt) {
      mnCnt = cnt;
      mnH = temp;
    }
    else if (mnCnt == cnt) {
      if (mnH > temp) {
        mnH = temp;
      }
    }

  }

  rep(i,8) {
    if (i) cout << ' ';
    cout << mnH[i];
    // printf("%c", mnH[i]);
  }
  cout << endl;
}

int main() {
  while (cin >> p[0]) {
    for (int i = 1; i <= 7; i++)
      cin >> p[i];
    solve();
  }
  return 0;
}

Measured memory_bytes: 1232
a = list(map(int, input()))
for i in range(8):
    bit = bin(i)[2:len(bin(i))]
    diflen = 3 - len(bit)
    if diflen != 0:
        bit = '0'*diflen + bit
    exp = str(a[0])
    ans = int(a[0])
    for i in range(3):
        if bit[i] == '0':
            exp = exp + '+' + str(a[i+1])
            ans += a[i+1]
        elif bit[i] == '1':
            exp = exp + '-' + str(a[i+1])
            ans -= a[i+1]
    if ans == 7:
        print(exp, '=7', sep='')
        break


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#define FOR(i,l,r) for(int i = l; i <= r; i++)
using namespace std;

const int MAXN = 100100;
const long long p = 1000000000 + 7;

int n;
long long A,B,s[MAXN],x[MAXN],y[MAXN],sx[MAXN],sy[MAXN];
int lastX[MAXN],lastY[MAXN],conx,cony;

long long sum(long long x, long long y){
  return (x + y) % p;
}

int main(){
  cin >> n >> A >> B;
  s[0] = -A-1;
  if(B>A) s[0] = -B-1;
  FOR(i,1,n) scanf("%lld",&s[i]);
  lastX[1] = 0; lastY[1] = 0;
  FOR(i,2,n){
    int lx = lastX[i-1], ly = lastY[i-1];
    while(s[i] - s[lx+1] >= A) lx++;
    while(s[i] - s[ly+1] >= B) ly++;
    lastX[i] = lx;
    lastY[i] = ly;
  }
  // FOR(i,1,n) cout << lastX[i] << ' ';
  // cout << endl;
  // FOR(i,1,n) cout << lastY[i] << ' ';
  // cout << endl;
  conx = 1; cony = 1;
  x[1] = 1; y[1] = 1;
  FOR(i,2,n){
    x[i] = 0; y[i] = 0;
    if(lastX[i] + 1 >= cony){
      if(lastX[i] + 1 < i) x[i] = sum(x[i],y[lastX[i]+1]);
      else x[i] = sum(x[i-1],y[i-1]);
    }
    if(lastY[i] + 1 >= conx){
      if(lastY[i] + 1 < i) y[i] = sum(y[i],x[lastY[i]+1]);
      else y[i] = sum(y[i-1],x[i-1]);
    }
    if(lastX[i] != i-1) conx = i;
    if(lastY[i] != i-1) cony = i;
    // cout << x[i] << ' ' << y[i] << endl;
  }
  cout << sum(x[n],y[n]);
  return 0;
}

// f[i] = ansX + ansY
//   ansX =


Measured memory_bytes: 3328
#include <iostream>
#include <string>

using namespace std;

int main() { 
    string s;
    cin >> s;
    int n = s.size();
    int ret = n;
    for (int i = 0; i < n - 1; i++) {
        if(s[i]!=s[i+1]){
            ret = min(ret, max(i + 1, n - i - 1));
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mk make_pair
#define pb push_back
#define pp pop_back
using namespace std ;
const ll N = 5e5 + 100 ;
int n , a , b , c , wrong = 1e6 , dp[N] , ar[N] ; 
//map<int,int>mp; 
vector<int>v,v1;
string s; 
int cal (int pos)
{
          if ( pos >= n ) 
          {
                    return wrong ; 
          }
          if ( pos == n - 1 ) 
          {
                    return 0 ; 
          }
          if ( dp[pos] != -1 ) 
          {
                    return dp[pos] ; 
          }
          int val1 = cal(pos+1) + abs(ar[pos] - ar[pos+1] ) ; 
          int val2 = cal(pos+2) + abs(ar[pos] - ar[pos+2] ) ;
          return dp[pos] = min(val1,val2) ; 
}

int main () 
{
    // cout << "Hello wolrd" ;
    cin >> n ; 
    for ( int i = 0 ; i < n ; ++i ) 
    {
              cin >> ar[i] ; 
    }
    memset(dp,-1,sizeof dp) ; 
   cout << cal(0);
}

Measured memory_bytes: 5760
#include<stdio.h>
  
 int main()
{
  int n, w, i, j, y=0, f, g, h;
  scanf("%d", &n);
  int data[n];
  char c[12];
 
  for(i = 0; i < n; i++){
    scanf("%s %d", c, &w);
 
    if(c[0] == 'i'){
      data[i]=w;
    }
 
    else if(c[6] == 'F'){
      i -= 2;
      n -= 2;
    }
 
    else if(c[6] == 'L'){
      i--;
      n--;
      y++;
    }
 
    else{
      i--;
      n--;
      f=0;
      for(j = i; j >= 0; j--){
 
    if(f > 0) break;
 
    if(w == data[j]){
      h = 0;
      g = i-j;
      f++;
      while(g!=h++)
	data[j + h - 1]=data[j + 1 + h - 1];
      i--;n--;
    }
      }
    }
  }
  for(i = 0; i < n-y; i++){
    if(i == n-y-1)
      printf("%d\n",data[n-1-i]);
    else
      printf("%d ",data[n-1-i]);
  }
  return 0;
}
    

Measured memory_bytes: 5624
#include <stdio.h>

int prime(int x) {
    int i;
    
    if( x == 2)
        return 1;
    if(x < 2 || x % 2 == 0)
        return -1;
        
    i = 3;
    while(i * i <= x) {
        if(x % i == 0)
            return -1;
        
        i = i  + 2;
    }
    return 1;
}

int main(void)
{
    int n , m , i;
    int Num[10005];
    int count = 0;
    
    scanf("%d" , &n);
    
    for (i = 0 ; i < n ; i++){
            scanf("%d¥n" , &Num[i]);
    }
    
    for (m = 0 ; m < n ; m++){
        if(prime(Num[m]) == 1)
            count++;
    }
    
    printf("%d\n" , count);
    
    return 0;
}



Measured memory_bytes: 2136
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        double sum = 0;
        int cnt = 0;
        Integer[] items = new Integer[N];
        for (int i = 0; i < N; i++) {
            int itemVote = sc.nextInt();
            sum += itemVote;
            items[i] = itemVote;
        }
        Arrays.sort(items, Collections.reverseOrder());
        double baseNum = sum / ((double) 4 * (double) M);
        for (int l = 0; l < M; l++) {
            double val = (double) items[l];
            if (val < baseNum) {
                continue;
            }
            cnt++;
        }
        if (cnt >= M) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int a[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    int b[m];
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }

    int ans[n];
    for(int i = 0; i < n; i++){
        ans[i] = 0;
        for(int j = 0; j < m; j++){
            ans[i] += a[i][j] * b[j];
        }
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3132
//C++の難しさ
#include <iostream>
#include <stdio.h>
#define N_MAX 500000
using namespace std;
//thik&solve easy 
//オブジェクトは変数でありその変数に記録されたデータそのもののことだ

int n;//num of input

class node{//将来を見据えて動的にしています
public:
	int *key;
	node *parent;
	node *l_chld;
	node *r_chld;

	node(int n){
		key =new int(n);
		parent = NULL;
		l_chld = NULL;
		r_chld = NULL;
	}

	~node(){
		delete key;
		delete parent;
		delete l_chld;
		delete r_chld;
	}
};

void insert(node **root,node *z){
	node *y;
	node *x;
	y = NULL;
	x = *root;
	while(x != NULL){
		y = x;
		if(*(z->key) < *(x->key))
			x = x->l_chld;
		else
			x = x->r_chld;
		z->parent = y;
	}

	if(y == NULL)
		*root = z;
	else if(*(z->key) < *(y->key))
		y->l_chld = z;
	else
		y->r_chld = z;
	
}

void preorder(node* u){
	node* pos;
	cout <<" " <<*(u->key);

	if(u->l_chld != NULL){
		pos = u->l_chld;
		preorder(pos);
	}

	if(u->r_chld != NULL){
		pos = u->r_chld;
		preorder(pos);
	}
}

void inorder(node* u){
	node* pos;
	
	if(u->l_chld != NULL){
		pos = u->l_chld;
		inorder(pos);
	}
	cout <<" " <<*(u->key);

	if(u->r_chld != NULL){
		pos = u->r_chld;
		inorder(pos);
	}
}

void print(node *u){
	inorder(u);
	cout <<endl;

	preorder(u);
	cout <<endl;

}

int main(){
	//はじめはrootがNULL

	char type[100];
	int z;
	node* root;
	root = NULL;
	node** rtroot = &root;

	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%s",&type);
		if(type[0] == 'i'){
			scanf("%d",&z);

			//挿入するわけだから新しくオブジェクトを作成
			node *nd;
			nd = new node(z);

			insert(rtroot,nd);
		}else
			print(root);
	}

	return 0;
}

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

using namespace std;
using ll = long long;

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

vector<int> g[N];

ll dp[N][2]; 

void dfs(int u, int par = -1) {
    dp[u][0] = 1; // u is colored white
    dp[u][1] = 1; // u is colored black
    for (int v : g[u]) {
        if (v == par) continue;
        dfs(v, u);

        // if this node is colored black
        (dp[u][1] *= dp[v][0]) %= MOD;
        
        // if this node is colored white
        (dp[u][0] *= (dp[v][0] + dp[v][1])) %= MOD;
    }
}

int main() { 
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    cout << (dp[1][0] + dp[1][1]) % MOD << '\n';
}


Measured memory_bytes: 14208