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

using namespace std;


int main() {
    int N,M; cin >> N >> M;
    priority_queue<int> Q;
    for(int i=0;i<N;i++) {
        int a; cin >> a;
        Q.push(a);
    }

    while(M>0) {
        int q = Q.top();
        Q.pop();
        q = q >> 1;
        Q.push(q);
        M--;
    }

    long long int ans = 0ll;
    while(!Q.empty()) {
        ans += (long long int) Q.top();
        Q.pop();
    }
    cout << ans << endl;

    return 0;
}


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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int n, m, q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
int ans = -1;

void dfs(int _now_num, vector<int> a_array) {
    if (_now_num == n) {
        int num = 0;
        rep(i, q) {
            if (a_array[b[i] - 1] - a_array[a[i] - 1] == c[i])
                num += d[i];
        }
        ans = max(num, ans);
        return;
    }

    int num = 1;
    if (a_array.size() != 0)
        num = a_array[a_array.size() - 1];

    for (int i = num; i <= m; i++) {
        a_array.emplace_back(i);
        dfs(_now_num + 1, a_array);
        a_array.erase(a_array.begin() + a_array.size() - 1);
    }
}

int main() {
    cin >> n >> m >> q;
    rep(i, q) {
        int ai, bi, ci, di;
        cin >> ai >> bi >> ci >> di;
        a.emplace_back(ai);
        b.emplace_back(bi);
        c.emplace_back(ci);
        d.emplace_back(di);
    }

    vector<int> a_array(0, 0);

    dfs(0, a_array);

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 3600
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

# 解説AC
N = int(sys.stdin.buffer.readline())

if N % 2 == 0:
    groups = [set() for _ in range(N // 2)]
    for i in range(N // 2):
        groups[i].add(i + 1)
        groups[i].add(N - i)
else:
    groups = [set() for _ in range(N // 2 + 1)]
    for i in range(N // 2):
        groups[i].add(i + 1)
        groups[i].add(N - i - 1)
    groups[-1].add(N)

ans = set()
for group in groups:
    for v in set(range(1, N + 1)) - group:
        for u in group:
            ans.add((min(v, u), max(v, u)))

print(len(ans))
for r in ans:
    print(*r)


Measured memory_bytes: 4028
N = int(input())
a = list(map(int, input().split()))
import fractions
import functools
import math

def func(a, b):
    return a * b //fractions.gcd(a, b)

#print(functools.reduce(func, a))
x = functools.reduce(func, a)
print(sum([(x-1) % val for val in a]))


Measured memory_bytes: 5616
function main(input) {
	const args = input.split('\n');
  	const N = args[0];
    let arr = args[1].split(' ').map((n) => parseInt(n, 10));
  			
  	let aSum = 0;
    let bSum = 0;
    
    arr.sort((a, b) => b - a);
  
  	arr.forEach((v, i) => {
      i % 2 === 0 ? aSum += v : bSum += v
    });
  
  	console.log(aSum - bSum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29588
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }


int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i, M){
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    vector<int> d(N, 1<<30);
    d[0] = 0;
    pq.push(make_pair(0, 0));
    while(!pq.empty()){
        auto tp = pq.top(); pq.pop();
        int s = tp.second;
        for(int t : G[s]){
            if(d[s] + 1 < d[t]){
                d[t] = d[s] + 1;
                pq.push(make_pair(d[t], t));
            }
        }
    }
    cout << "Yes" << endl;
    for(int s=1; s<N; s++){
        for(int t : G[s]){
            if(d[s] - d[t] == 1){
                cout << t+1 << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 10732
#include <bits/stdc++.h>
using namespace std;
int main(){
  	string s,t,a[]={"Yes","No"};
  	int c=0;
  	cin >> s >> t;
  	for(int i=0;i<s.size();i++){
      	if(s[i]!=t[i]){
        	c++; break;
        }
    }
  	cout << a[c] << endl;
  	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> times(n);
    vector<vector<int>> c_sum(n + 1, vector<int>(7));
    for (int i = 0; i < n; i++) {
        int a;
        cin >> times[i] >> a;

        c_sum[i + 1] = c_sum[i];
        if (a > 0)c_sum[i + 1][a - 1]++;
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        int start = lower_bound(times.begin(), times.end(), l) - times.begin();
        int end = lower_bound(times.begin(), times.end(), r) - times.begin();

        vector<int> now(7);
        for (int j = 0; j < 7; j++) now[j] = c_sum[end][j] - c_sum[start][j];

        long double ret = 1000000000;
        for (int j = 0; j < 7; j++) ret *= pow(((9.0 - j) / 10), now[j]);
        cout << fixed << setprecision(15) << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 10276
a, b = map(int, input().split())
while True:
    uru = [str(i) for i in range(a, b+1) if i % 400 == 0 or (i % 4 == 0 and i % 100 != 0)]
    result = '\n'.join(uru)

    if not result:
        result = 'NA'
    print(result)

    a, b = map(int, input().split())
    if a + b == 0: break
    print()

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

namespace AOJ2
{
    class Program
    {
        static bool[] rui;

        static void Main(string[] args)
        {
            List<int> resultList = new List<int>();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                rui = new bool[3];
                int run = 0;
                int outCount = 0;
                while (outCount != 3)
                {
                    switch (Console.ReadLine())
                    {
                        case "HIT":
                            run += Advance();
                            break;
                        case "HOMERUN":
                            run += rui.Where(s => s).Count() + 1;
                            rui = new bool[3];
                            break;
                        case "OUT":
                            outCount++;
                            break;
                    }
                }

                resultList.Add(run);
            }

            foreach (int r in resultList)
            {
                Console.WriteLine(r);
            }


        }

        static int Advance()
        {
            int run = 0;
            if (rui[2])
            {
                run++;
                rui[2] = false;
            }
            if (rui[1])
            {
                rui[2] = true;
                rui[1] = false;
            }
            if (rui[0])
            {
                rui[1] = true;
            }
            rui[0] = true;

            return run;
        }

    }
}

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

bool drop(int pos, char* s, char* t, char* d, int N, int Q, bool left_check) {
  for (int i = 0; i < Q; i++) {
    if (t[i] == s[pos]) {
      pos += (d[i] == 'L') ? -1 : 1;
    }
    if (pos < 0 && left_check) {
      return true;
    } else if  (pos > N-1 && !left_check) {
      return true;
    }
  }
  return false;
}

int main() {
  int N, Q;
  cin >> N >> Q;
  char s[N];
  cin >> s;
  char t[Q], d[Q];
  int g_pos[N];
  vector<int> con_pos;
  for (int i = 0; i < N; i++) {
    g_pos[i] = i;
  }
  for (int i = 0; i < Q; i++) {
    cin >> t[i] >> d[i];
  }

  int ml, mr;
  int left = 0;
  int right = N;
  while (left < right) {
    int mid = (left + right) / 2;
    if (drop(mid, s, t, d, N, Q, true)) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  ml = left;
  left = 0;
  right = N;
  while (left < right) {
    int mid = (left + right) / 2;
    if (drop(mid, s, t, d, N, Q, false)) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  mr = left;
  cout << mr - ml << endl;
  return 0;
}


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

using ll = long long;

struct frac {
	ll p = 0, q = 1;
	frac() {}
	explicit frac(ll a, ll b = 1) {
		assert(b > 0);
		ll g = __gcd(a,b);
		p = a/g, q = b/g;
	}
	friend bool operator < (const frac& a, const frac& b) {
		return a.p * b.q < b.p * a.q;
	}
};

const int MAXN = 1.1e5;
int N;
pair<ll, ll> pts[MAXN]; // first is max, second is difference
ll pref[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		ll a, b; cin >> a >> b;
		pts[i] = {max(a, b), b-a};
	}
	sort(pts, pts + N);

	ll sum_better = 0;
	pref[0] = 0;
	for (int i = 0; i < N; i++) {
		sum_better += max(0ll, pts[i].second);
		pref[i+1] = pref[i] + pts[i].first;
	}

	pair<int, frac> ans;
	for (int i = 0; i < N; i++) {
		auto M = pts[i];
		ll cutoff = (sum_better - max(0ll, M.second) + M.second);
		int mi = -1;
		int ma = N+1;
		while (ma - mi > 1) {
			int md = (mi + ma) / 2;
			ll lhs = pref[md] - (i < md ? M.first : 0);
			if (lhs <= cutoff) {
				mi = md;
			} else {
				ma = md;
			}
		}
		if (mi == -1) continue;
		ll lhs = pref[mi] - (i < mi ? M.first : 0);
		assert(cutoff >= lhs);
		ll B = M.second >= 0 ? M.first : M.first + M.second;
		ans = max(ans, pair<int, frac>(mi - (i < mi), frac{cutoff - lhs, B}));
	}
	frac res{ans.first * ans.second.q + ans.second.p, ans.second.q * N};
	cout << res.p << ' ' << res.q << '\n';

	return 0;
}

// say that you can beat ringo from fraction {t} into of beam M
// M.A + sum_pref A_i <= (1-{t}) * M.B + sum_non_pref (B_i - A_i)
// M.A + sum_pref_worse A_i + sum_pref_better A_i <= (1-{t}) * M.B + sum_suff_better (B_i - A_i)
// M.A + sum_pref_worse A_i + sum_pref_better B_i <= (1-{t}) * M.B + sum_better(B_i - A_i)
// we want to cram as many as possible into pref, so we should take as many until we hit M.B - M.A + sum_better


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

typedef long long ll;
typedef long long LL;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#ifdef DEBUG
    #define cek(x) cout<<x
#else
    #define cek(x) if(false){}
#endif // DEBUG

#define fi first
#define se second
#define INF 1000000000
#define INFLL 1000000000000000000LL
#define EPS 1e-9
#define PI acos(-1.0)
#define pb push_back
#define TC() while(tc--)
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORN(i,n) for(int i=0;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define REPN(i,a,b) for(int i=a;i<=b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define sc(x) scanf("%d",&x)

int main(void){
    #ifdef ccsnoopy
        freopen("D:/Code/in.txt","r",stdin);
    #endif

    int n;
    sc(n);
    int x;
    int sisa = 0;
    ll tot = 0;
    FOR(i,n){
        sc(x);
        if(!x){
            sisa = 0;
            continue;
        }
        if(sisa){
            sisa--;
            tot++;
            x--;
        }
        tot+=x/2;
        sisa = x%2;
    }

    cout << tot;


    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int h, w;
    vector<string> s;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    
    for(int i = 0; i < h; i++){
        cout << s[i] << endl;
        cout << s[i] << endl;
    }
    return 0;
}










Measured memory_bytes: 384
#include <stdio.h>

int main()
{
  int d, n;

  scanf("%d %d", &d, &n);

  if(d==0) {
    if (n != 100)printf("%d\n", n);
    else printf("101\n");
  }
  else if (d==1) {
    if(n != 100)printf("%d\n",n*100);
    else printf("10100\n");
  }
  else {
    if(n!=100)printf("%d\n", n*10000);
    else printf("1010000");
  }
  
  return 0;
}


Measured memory_bytes: 128
def main():
  import sys
  b=sys.stdin.buffer
  h,w=map(int,b.readline().split())
  x=w+1
  s=[c>>3for c in b.read()]
  dp=[10000]*h*x
  a=p=s[0]
  dp[0]=b=q=5-a
  r=range(1,w)
  for i in r:
    t=s[i]
    b+=a^t
    dp[i]=b
    a=t
  for i in range(x,h*x,x):
    t=s[i]
    q+=p^t
    dp[i]=b=q
    a=p=t
    for _ in r:
      i+=1
      si=s[i]
      b+=a^si
      j=i-x
      t=dp[j]+(s[j]^si)
      if b>t:b=t
      dp[i]=b
      a=si
  print(b+1>>1)
main()

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int n,x,m,ma=-1;
int in[6];
int out[6];
int tmp[10][3];
void f(int a){
	if(a==n){
		rep(i,m){
			int sum=0;
			loop(j,tmp[i][0]-1,tmp[i][1])sum+=in[j];
			if(sum!=tmp[i][2])return ;
		}
		int sum=0;
		rep(i,n)sum+=in[i];
		if(sum>ma){
			ma=sum;
			rep(i,n)out[i]=in[i];
		}
	}else{
		rep(i,x+1){
			in[a]=i;
			f(a+1);
		}
	}
}
int main(){
	cin>>n>>x>>m;
	rep(i,m)cin>>tmp[i][0]>>tmp[i][1]>>tmp[i][2];
	f(0);
	if(ma==-1)cout<<-1<<endl;
	else {
		cout<<out[0];
		rep(i,n-1)cout<<" "<<out[i+1];
		cout<<endl;
	}
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <map>
#include <numeric>
#include <vector>
#include <utility>

using namespace std;

typedef pair<int, pair<int, int>> State;

map<State, int> memo;

int findBest(const vector<int>& a, int index, int turn, int opp) {
  State state = make_pair(index, make_pair(turn, opp));
  auto found = memo.find(state);
  if (found != memo.end())
    return found->second;

  int best = abs(a.back() - opp);
  for (int ni = index + 1; ni < a.size(); ni++) {
    int score = findBest(a, ni, 1 - turn, a[ni-1]);
    if (turn == 0) {
      if (best < score)
        best = score;
    } else {
      if (best > score)
        best = score;
    }
  }

  return memo[state] = best;
}

int main() {
  int N, Z, W;
  scanf("%d%d%d", &N, &Z, &W);
  vector<int> a;
  for (int i = 0; i < N; i++) {
    int v;
    scanf("%d", &v);
    a.push_back(v);
  }

  printf("%d\n", findBest(a, 0, 0, W));
}


Measured memory_bytes: 888
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    x = 0
    y = sum(a)
    m = 10**100
    for i in range(N-1):
        x += a[i]
        y -= a[i]
        m = min(m, abs(x-y))
    print(m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 101020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10, mod = 1e9 + 7;
int n, ans, t, s;
int c[maxn];
ll fpm(ll a, ll b) {
	ll ret = 1ll;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)ret = ret * a % mod;
	return ret;
}
void solve() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> c[i];
	sort(c + 1, c + n + 1, greater<int>());
	t = fpm(2, 2 * n - 2);
	for (int i = 1; i <= n; ++i)
		(ans += 1ll * (i + 1) * c[i] % mod) %= mod;
	ans = 1ll * ans * t % mod;
	cout << ans << endl;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 1024
/*
https://atcoder.jp/contests/abc176/tasks/abc176_c
*/

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

bool db = false;
typedef long long LL;
typedef long double LD;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<LL, pll> pl_ll;
typedef pair<pll, LL> pll_l;

const LL INF = 1e18+1;

const LL maxn = 2*1e6+1;

LL t, n, m;
LL a[maxn+1];

int main() {

#ifdef MY_FILE_INPUT
    db = false;
    db = true;
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    LL ans = 0;
    for(int i = 1; i < n; i++) {
        if(a[i] < a[i-1]) {
            ans += (a[i-1] - a[i]);
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5132
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}
ll n,m,T;
int a[maxn];

int main(){
//	cin>>n;
	ll x,y;
	cin>>n>>x>>y;
	ll temp=abs(x-y)-1;
	if(x==y){
		cout<<"0\n";
		return 0; 
	} 
	if(temp&1){
		cout<<(temp+1)/2<<endl;
	}else{
		if(x>y)swap(x,y);
		ll ans=(x-1)+1+(temp)/2;
		ans=min(ans,(n-y)+1+(temp)/2);
		cout<<ans<<endl;
	}
	
	return 0;
}
/*
10
9 4

*/



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
using namespace std;
signed main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (a <= b) {
		if (a + w >= b)cout << 0 << endl;
		else cout << b - (a + w) << endl;
	}
	else {
		if (b + w >= a)cout << 0 << endl;
		else cout << a - (b + w) << endl;
	}
}

Measured memory_bytes: 256
n = gets.to_i
s = []
for i in 0...n do
  s[i] = gets.chomp
end

m = gets.to_i
t = []
for i in 0...m do
  t[i] = gets.chomp
end

s = s.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h
t = t.group_by(&:itself).map{ |key, value| [key, value.count] }.to_h

s_key = s.keys
s_value = s.values
t_key = t.keys
t_value = t.values

common_word = s_key & t_key
#p common_word

if common_word.length == 0
  puts s_value.max
else
  ans = -1
  for i in 0...common_word.length do
    s_point = s[common_word[i]]
    t_point = t[common_word[i]]
    if ans < s_point - t_point
      ans = s_point - t_point
    end
  end

  cnt = 0
  other_word = []
  for i in 0...s_key.length do
    flg = false
    for j in 0...common_word.length do
      if s_key[i] == common_word[j]
        flg = true
        break
      end
    end
    if flg == false
      other_word[cnt] = s_key[i]
      cnt += 1
    end
  end
  max = -10
  for i in 0...cnt do
    if s[other_word[i]] > max
      max = s[other_word[i]]
    end
  end

#  puts "max: #{max}"

  if ans < max
    puts max
  elsif ans < 0
    puts 0
  else
    puts ans
  end
end



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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , xr , p[MAXN];
vector<ll> vec;
set<ll> st;
map<ll , ll> cnt;

int main() {
    fast_io;

    cin >> n;
    for(ll i = 0 ; i < n ; i++){
        cin >> p[i];
        st.insert(p[i]);
        cnt[p[i]]++;
    }

    if(n % 3 != 0){
        if(cnt[0] < n)  return cout << "No" << endl , 0;
        return cout << "Yes" << endl , 0;
    }

    for(auto &i : st){
        if(cnt[i] % (n / 3) != 0) return cout << "No" << endl , 0;
        for(ll j = 0 ; j < cnt[i] / (n / 3) ; j++)  xr ^= i;
    }

    if(xr == 0) return cout << "Yes" << endl , 0;
    cout << "No" << endl;


    return 0;
}
/*

*/


Measured memory_bytes: 9344
/*まずうちさあ屋上あんだけど、焼いてかない？*/
	#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	ll pas[51][52];
	const ll INF = 1e18;
	const ll mod = 1e9 + 7;

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

	int main(){
		IOS;
		int n,C;
		cin >> n >> C;
		vec<vec<P>> ch(C + 1); //各チャネルの放送時間
		REP(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			ch[c].push_back(P(a, b));
		}
		vec<P> use;
		REP(i,C + 1){
			sort(ALL(ch[i]));
			int j = 0;
			while(j < ch[i].size()){
				int stat = ch[i][j].first;
				int goal = ch[i][j].second;
				while(j + 1 < ch[i].size() && ch[i][j + 1].first == ch[i][j].second){
					j++;
					goal = ch[i][j].second;
				}
				use.push_back(P(stat,goal));
				j++;
			}
		}
		vec<ll> s(114514,0);
		REP(i,use.size()){
			s[use[i].first - 1]++;
			s[use[i].second]--;
		}
		ll tmp = 0;
		ll ans = 0;
		REP(i,114514){
			tmp += s[i];
			ans = max(ans,tmp);
		}
		dump(ans);
	}

Measured memory_bytes: 5236
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int in()
{
  int x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
int a[20][20] , c[20] , d[20] ;
int main()
{
  int n = in() , m = in() , x = in() ;
  for(int i = 1; i <= n ;i ++ )
   {
     c[i] = in() ;
     for(int j = 1; j <= m ;j ++ )
      a[i][j] = in() ;
   }
  int ans = INF ;
  for(int i = 1;i < (1 << n) ;i ++ )
   {
     memset(d,  0 , sizeof d) ;
     int res = 0 ;
     for(int j = 0 ; j < n ;j ++ )
      {
        if((i & (1 << j)))
         {
           res += c[j + 1] ;
           for(int k = 1 ; k <= m ;k ++ )
            d[k] += a[j + 1][k] ;
         }
      }
      int flag = 1 ;
      for(int j = 1 ; j <= m ;j ++ )
       if(d[j] < x) flag = 0 ;
      if(flag) ans = min(ans , res) ;
   }
  if(ans == INF) ans = -1 ;
  cout << ans << endl ;
  return 0 ;
}
/*
*/


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int hi[100001];

int main(void){
  int n, m;
  int a;
  int ans = 0;
  cin >> n >> m;
  vector<int> q[100001];
  rep(i,n){
    cin >> a;
    q[a%m].push_back(a);
    hi[a]++;
  }
  rep(i,m){
    sort(all(q[i]));
  }

  ans += q[0].sz/2;
  
  if(m%2==0){
    //偶数
    for(int i = 1; i < m/2; i++){
      int use = min(q[i].sz, q[m-i].sz);

      if(q[i].sz>use){
        int res = q[i].sz - use;
        if(res > 1){
          rep(j,q[i].sz){
            while(res>1&&hi[q[i][j]]>1){
              hi[q[i][j]]-=2;
              ans++;res-=2;
            }
          }
        }
      }
      if(q[m-i].sz>use){
        int res = q[m-i].sz - use;
        if(res > 1){
          rep(j,q[m-i].sz){
            while(res>1&&hi[q[m-i][j]]>1){
              hi[q[m-i][j]]-=2;
              ans++;res-=2;
            }
          }
        }
      }
      ans+= use;
    }
    ans += q[m/2].sz/2;
  }else{
    for(int i = 1; i <= m/2; i++){
      int use = min(q[i].sz, q[m-i].sz);
      if(q[i].sz>use){
        int res = q[i].sz - use;
        if(res > 1){
          rep(j,q[i].sz){
            while(res>1&&hi[q[i][j]]>1){
              hi[q[i][j]]-=2;
              ans++;res-=2;
            }
          }
        }
      }
      if(q[m-i].sz>use){
        int res = q[m-i].sz - use;
        if(res > 1){
          rep(j,q[m-i].sz){
            while(res>1&&hi[q[m-i][j]]>1){
              hi[q[m-i][j]]-=2;
              ans++;res-=2;
            }
          }
        }
      }
      ans+= use;
    }
  }

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


Measured memory_bytes: 6144
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
namespace SOLVE {
	
	void main() {
		ll n, v;
		cin >> n >> v;
		map<ll, ll> freq;
		vector<VLL> og(4, VLL(n));

		REP(i, 0, 4) {
			REP(j, 0, n) {
				cin >> og[i][j];
			}
		}
		REP(i, 0, n) {
			REP(j, 0, n) {
				freq[og[0][i] + og[1][j]]++;
			}
		}
		ll ans = 0;
		REP(i, 0, n) {
			REP(j, 0, n) {
				ans += freq[v - og[2][i] - og[3][j]];
			}
		}

		cout << ans << endl;
	}
}


signed main() {

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



Measured memory_bytes: 128076
#include <cstdio>
#include <algorithm>

typedef long long LL;

const int MAXN = 1e5;
int n, a[MAXN + 5], ord[MAXN + 5];

struct BinaryIndexTree {
	int siz, val[MAXN * 2 + 5];
	inline int lowbit ( const int x ) { return x & -x; }
	inline void init ( const int s ) {
		siz = s;
		for ( int i = 0; i <= siz; ++ i ) val[i] = 0;
	}
	inline void update ( const int x, const int k ) {
		for ( int i = x; i <= siz; i += lowbit ( i ) ) {
			val[i] += k;
		}
	}
	inline int presum ( const int x ) {
		int ret = 0;
		for ( int i = x; i; i -= lowbit ( i ) ) {
			ret += val[i];
		}
		return ret;
	}
} bit;

inline bool check ( const int x ) {
	static int tmp[MAXN + 5], s[MAXN + 5]; s[0] = 0;
	static const LL lim = n * ( n + 1ll ) >> 2;
	for ( int i = 1; i <= n; ++ i ) tmp[i] = a[i] >= x ? -1 : 1;
	for ( int i = 1; i <= n; ++ i ) s[i] = s[i - 1] + tmp[i];
	LL sum = 0;
	bit.init ( n << 1 | 1 ), bit.update ( n + 1, 1 );
	for ( int i = 1; i <= n; ++ i ) {
		sum += bit.presum ( s[i] + n );
		bit.update ( s[i] + n + 1, 1 );
	}
	return sum <= lim;
}

int main () {
	scanf ( "%d", &n );
	for ( int i = 1; i <= n; ++ i ) scanf ( "%d", &a[i] ), ord[i] = a[i];
	std :: sort ( ord + 1, ord + n + 1 );
	int l = 1, r = n, mid;
	while ( l < r ) {
		mid = l + r + 1 >> 1;
		if ( check ( ord[mid] ) ) l = mid;
		else r = mid - 1;
	}
	printf ( "%d\n", ord[l] );
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int c[10][10];
  memset(c, 0, sizeof(c));
// 値をセット
  for (int i = 1; i <= n; i++) {
    string numStr;
    numStr = to_string(i);
    c[numStr[0] - '0'][numStr[numStr.size() - 1] - '0']++;
  }

  long long int ans = 0;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      ans += c[i][j] * c[j][i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

int main() {

	string s;
	int k;
	cin >> s >> k;

	vector<string> ans;

	for (int i = 0; i < s.size(); ++i) {
		for (int j = 1; j <= k; ++j) {
			ans.push_back( s.substr(i, j) );
		}
	}

	sort(ans.begin(), ans.end());
	//重複の削除
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	
	cout << ans.at(k-1) << endl;

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	int fx = 0;
	int tmp = n;
	while (tmp) {
		fx += tmp % 10;
		tmp /= 10;
	}
	if (n % fx == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int sum(int n) {
    int res = 0;
    string s = to_string(n);
    rep(i, s.size()) res += (s[i]-'0');
    return res;
}

int main() {
    int n, a, b, ans = 0;
    cin >> n >> a >> b;
    for (int i=1; i<=n; ++i) {
        int tmp = sum(i);
        if (a <= tmp and tmp <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func selectionSort(a []int) (count int) {
	if len(a) <= 1 {
		return
	}

	minI := minIndex(a)
	if minI != 0 {
		a[0], a[minI] = a[minI], a[0]
		count++
	}
	count += selectionSort(a[1:])
	return
}

// Returns the index of the minimum value in a.
func minIndex(a []int) (index int) {
	min := a[0]
	for i, e := range a {
		if min > e {
			min = e
			index = i
		}
	}
	return
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}

	count := selectionSort(a)
	for i, e := range a {
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(e)
	}
	fmt.Println()
	fmt.Println(count)
}



Measured memory_bytes: 1164
#include<algorithm>
#include<iostream>
#include<cstring>

int n;
char field[1000][1000];
int dp[1000][1000];

int main()
{
	while( std::cin >> n, n )
	{
		for( int i = 0; i != n; ++i )
			for( int j = 0; j != n; ++j )
				std::cin >> field[i][j];
	
		int ans = 0;
		memset( dp, 0, sizeof( dp ) );
		for( int i = 0; i != n; ++i )
		{
			for( int j = 0; j != n; ++j )
			{
				if( i && j && field[i][j] == '.' )
				{
					dp[i][j] = std::min( dp[i-1][j-1], std::min( dp[i][j-1], dp[i-1][j] ) ) + 1;
					ans = std::max( ans, dp[i][j] );
				}
				else
					dp[i][j] = field[i][j] == '.';
			}
		}

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

	return 0;
}

Measured memory_bytes: 6052
#include <bits/stdc++.h>
using namespace std;
void solve(int n){
    int ans=INT_MAX;
    int j,tmp;
    for(int i=0;i*i*i<=n;i++){
        tmp=n-i*i*i;
        for(j=0;j*j<=tmp;j++){}
        j--;
        ans=min(ans,i+j+tmp-j*j);
    }
    cout<<ans<<endl;
}

int main(void){
    int n;
    while(cin>>n,n){
        solve(n);
    }
    
}



Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

INF = 10**6

A.sort()
check = [False] + [True]*(INF)

setA = list(set(A))
length = len(setA)
for i in range(length):
    x = setA[i]
    for j in range(2, int(INF/x)+1):
        check[x*j] = False

prev = 0
count = 0
flag = False #重複チェック
for i in range(N):
    x = A[i]
    if check[x]:
        if x != prev:
            count += 1
            flag = True
        elif flag:
            count -= 1
            flag = False
        prev = x
print(count)

Measured memory_bytes: 41808
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const rule = lines.shift().split(" ").map(Number);
  const bookNum = rule[0];
  const algorithmNum = rule[1];
  const target = rule[2];

  let res = Infinity;

  const bookArrays: any = lines.map((line) => {
    return line.split(" ").map((int) => parseInt(int));
  });

  for (let bit = 0; bit < 1 << bookNum; bit++) {
    let row: any[] = [];
    let num = "";
    let resArray = [];
    resArray = Array(bookNum + 1).fill(0);

    for (let i = 0; i < bookNum; i++) {
      num += bookArrays[i];
      if (bit & (1 << i)) {
        //理解度と値段をプラスする
        for (let j = 1; j < bookNum + 1; j++) {
          resArray[j] += bookArrays[i][j];
        }
        resArray[0] += bookArrays[i][0];
        row.push(i);
      }
    }

    let flag = true;
    for (let k = 1; k < resArray.length; k++) {
      if (resArray[k] < target) {
        flag = false;
        break;
      }
    }

    if (flag && resArray[0] < res) {
      res = resArray[0];
    }
  }
  res === Infinity ? (res = -1) : res;
  console.log(res);
});


Measured memory_bytes: 36776
#include <iostream>
#include <iomanip> 
#include <algorithm>

using namespace std;
const int MAX = 3001;
double dp[MAX][MAX];
double c[MAX];
double re;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> c[i];
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0;j<=i;j++)
		{
			dp[i][j] = dp[i - 1][j] * (1 - c[i]);
			if (j > 0)
				dp[i][j] += (dp[i - 1][j - 1] * c[i]);
		}
	}
	for (int i = n / 2 + 1; i <= n; i++)
		re += (dp[n][i]);
	
	cout <<setprecision(10) << re;
	
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

const int MAX = 2000000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    ll x, y;
    cin >> x >> y;
    ll s, t;
    if((2*y-x) % 3 || (2*x-y) % 3){
        cout << 0 << endl;
        return 0;
    }
    s = (2*y - x) / 3;
    t = (2*x - y) / 3;

    com_init();
    cout << com(s+t, s) << endl;
}

Measured memory_bytes: 47104
#include <iostream>
using namespace std;
int n,s[200000],t[200000],p,tmp,ans;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=n;i>0;i--){
        p=2;
        tmp=0;
        while(i*p<=n){
            tmp+=t[i*p-1];
            p+=1;
        }
        t[i-1]=abs(s[i-1]-tmp%2);
        ans+=abs(s[i-1]-tmp%2);
    }
    cout<<ans<<endl;
    for(int i=0;i<n;i++){
        if(t[i])cout<<i+1<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
typedef pair<int,int>ii;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n;
    while(sf("%d",&n)==1)
    {
        int ini[n+5];
        for(int i=0;i<n;i++)sf("%d",&ini[i]);
        ii ara[n+5];
        for(int i=0;i<n;i++)
        {
            ara[i].first=ini[i];
            ara[i].second=i;
        }

        sort(ara,ara+n);
        int mx1=ara[n-1].second;
        int val1=ara[n-1].first;
        int mx2=ara[n-2].second;
        int val2=ara[n-2].first;

        for(int i=0;i<n;i++)
        {
            if(i==mx1)pf("%d\n",val2);
            else pf("%d\n",val1);
        }
    }
    return 0;
}







































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

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

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/


int main(){
  ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> v(n+1),w(n+1);
  rep(i,n){
    cin >> v[i+1] >> w[i+1];
  }
  vector<vector<P>> data((1<<10)+5); //d9 made hanbun-zenrekkyo
  REP(i,1,min(n+1,1<<10)){
    vector<int> ls;
    if(i==1){
      data[i].emplace_back(w[i],v[i]);
      data[i].emplace_back(0,0);
    } else {
      for(auto it:data[i/2]){
        data[i].emplace_back(it.F,it.S);
        data[i].emplace_back(it.F+w[i],it.S+v[i]);
      }
    }

    sort(data[i].begin(),data[i].end());
    REP(j,1,data[i].size()){
      data[i][j].S = max(data[i][j].S, data[i][j-1].S);
    }
  }

  int q;
  cin >> q;
  while(q--){
    int x,L; cin >> x >> L;
    if(x<min(n+1,1<<10)){
      int pos = lower_bound(data[x].begin(),data[x].end(),P(L+1,0)) - data[x].begin();
      int ans = data[x][pos-1].S;
      cout << ans << ln;
    } else {
      vector<int> ls;
      int tmp = x;
      while(tmp>=(1<<10)){ ls.emplace_back(tmp); tmp/=2; }
//      sort(ls.rbegin(),ls.rend());
      int sz = ls.size();
      int ans = 0;
      vector<int> d;
      for(auto it:data[tmp]){ d.emplace_back(it.F); }
      rep(b,1<<sz){
        int vsum = 0, wsum = 0;
        rep(j,sz)if(bit(b,j)){
          vsum += v[ls[j]];
          wsum += w[ls[j]];
        }
        if(wsum>L) continue;
        int pos = lower_bound(d.begin(),d.end(),L-wsum+1) - d.begin();
        //int pos = lower_bound(data[tmp].begin(),data[tmp].end(),P(L-wsum+1,0)) - data[tmp].begin();
        ans = max(ans, vsum+data[tmp][pos-1].S);
      }
      cout << ans << ln;
    }
  }

  return 0;
}

Measured memory_bytes: 10856
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, M;

  std::cin >> N >> M;

  long long c = 0;

  if (N == M) {
    c = 2;
  }
  else if (std::abs(N - M) == 1) {
    c = 1;
  }

  for (int i = 1; i <= N; i ++)
    (c *= i) %= MOD;

  for (int i = 1; i <= M; i ++)
    (c *= i) %= MOD;

  std::cout << c << std::endl;

  return 0;
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
    // assert(freopen("output.txt", "w", stdout));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

li ans;
li n;
li a[2][3];

void go(int z, li n) {
    if (z == 2) {
        ans = max(ans, n);
        return;
    }
    vector <int> g;
    for (int j = 0; j < 3; ++j) {
        if (a[z][j] < a[!z][j])
            g.push_back(j);
    }
    if (g.size() == 0)
        go(z + 1, n);
    else if (g.size() == 1) {
        int j = g[0];
        li k = n / a[z][j];
        go(z + 1, n - k * a[z][j] + k * a[!z][j]);
    } else if (g.size() == 2) {
        for (li c0 = 0; c0 * a[z][g[0]] <= n; ++c0) {
            li n1 = n - c0 * a[z][g[0]];
            li c1 = n1 / a[z][g[1]];
            go(z + 1, n1 + c0 * a[!z][g[0]] - c1 * a[z][g[1]] + c1 * a[!z][g[1]]);
        }
    } else {
        for (li c0 = 0; c0 * a[z][g[0]] <= n; ++c0) {
            for (li c1 = 0; c0 * a[z][g[0]] + c1 * a[z][g[1]] <= n; ++c1) {
                li n1 = n - c0 * a[z][g[0]] - c1 * a[z][g[1]];
                li c2 = n1 / a[z][g[2]];
                go(z + 1, n1 + c0 * a[!z][g[0]] + c1 * a[!z][g[1]] - c2 * a[z][g[2]] + c2 * a[!z][g[2]]);
            }
        }
    }
}

void solve(bool __attribute__((unused)) read) {
    cin >> n;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }
    ans = n;
    go(0, n);
    cout << ans << "\n";
}

Measured memory_bytes: 256
import sys
line = sys.stdin.read().lower()
al_dict = {}

for al in [chr(i) for i in range(ord('a'), ord('z')+1)]:
    al_dict[al] = 0
    
for al in line:
    if al_dict.get(al) != None:
        al_dict[al] += 1

for al in al_dict:
    print('{} : {}'.format(al, al_dict[al]))


Measured memory_bytes: 5568
from collections import deque


def main():
    S = deque(list(input()))
    Q = int(input())
    count = 0
    for _ in range(Q):
        query = list(input().split())
        if query[0] == "1":
            count += 1
        if query[0] == "2":
            if count % 2 == 0:
                if query[1] == "1":
                    S.appendleft(query[2])
                elif query[1] == "2":
                    S.append(query[2])
            else:
                if query[1] == "1":
                    S.append(query[2])
                elif query[1] == "2":
                    S.appendleft(query[2])
    if count % 2 == 0:
        ans = "".join(S)
        print(ans)
    else:
        S.reverse()
        ans = "".join(S)
        print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin >> N;
  string s="Three";
  
  vector<char>vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
    if(vec.at(i)=='Y'){
      s="Four";
      break;
    }
  }
  cout << s <<endl;
  
}
  

Measured memory_bytes: 3492
n = int(input())
def fizzbuzz_sum(n):
    result = 0
    for i in range(1, n+1):
        if i % 5 == 0 or i % 3 == 0:
            result += 0
        else:
            result += i
    return result

# result = fizzbuzz_sum(15) * fizzbuzz_sum(n // 15) + fizzbuzz_sum(n % 15)

result = fizzbuzz_sum(n)
print("{}".format(result))


Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

using namespace std;

typedef long long ll;

const ll mod = 1000000007LL;
ll K,dp[10010][110][2]; // dp[桁][余り][Nとぴったりか] := 総数
string N;

void compute() {
  reverse(N.begin(),N.end());
  dp[(int)N.size()][0][1] = 1LL;
  for(int i=(int)N.size();i>=1;i--) {
    for(ll remain=0;remain<K+1;remain++) {
        rep(sameN,2) {
          rep(digit, 10) {
            int new_remain = remain + (digit != 0);//(N[i-1] - '0' != 0);
            if( sameN && digit > (N[i-1] - '0')) continue;
            int new_sameN = sameN;
            if( sameN && digit < ( N[i-1] - '0' ) ) new_sameN = 0;
            ( dp[i-1][new_remain][new_sameN] += dp[i][remain][sameN] ) %= mod;
          }
      }
    }
  }
  cout << ( dp[0][K][0] + dp[0][K][1] + mod ) % mod << endl;
}

int main() {
  cin >> N >> K;
  compute();
  return 0;
}

Measured memory_bytes: 384