akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),cnt(2e5,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    cnt[a[i]]++;
  }
  int ans=cnt[0]+cnt[1]+cnt[2];
  for(int i=1;i<1e5;i++){
    int tmp=cnt[i-1]+cnt[i]+cnt[i+1];
    if(ans<tmp) ans=tmp;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,a[220000];
bool cmp(long long a,long long b) {
	return a>b;
}
int main() {
	scanf("%lld",&n);
	for (int i=1;i<=n;++i) scanf("%lld",&a[i]);
	sort(a+1,a+1+n,cmp);
	long long ans=a[1];
	int pos=2;
	for (int i=2;i<n;++i) 
		if (i%2) ans+=a[pos++]; else ans+=a[pos];
	printf("%lld",ans);
	return 0;
} 

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
  	if (n%2!=0)
      cout<<(n/2);
  	else
      cout<<(n/2-1);

    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};
int main(){
int N;
	cin >> N;
	vector<int> A(N);
	vector<long long> B(N + 1, 0); //累積和テーブル
	int mod = 1000000007;
 
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		B[i + 1] = B[i] + A[i];
	}
 
	long ans = 0;
 
	//i について全探索する
	for (int i = 0; i < N; i++)
	{
		//累積和を使ってA[i+1] + ... + A[N] を求める
		long long sum = (B[N] - B[i + 1]) % mod;
 
		ans += A[i] * sum;
		ans %= mod;
	}
 
	cout << ans << endl;
}




Measured memory_bytes: 5580
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{

static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);//グラフの頂点数
static long m = long.Parse(input[1]);
static long[] parents = new long[n];//親
  
	static void Main()
	{
    long[,] maxDistance = new long[n,n];
  
    for(long i = 1; i < n; i++)
    {
      parents[i] = i;//unionFindの初期化
    }

    long[,] edges = new long[m,3];
    for(int i = 0; i < m; i++)//全ての辺
    {
      long[] edgesGet = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      edges[i,0] = edgesGet[0];
      edges[i,1] = edgesGet[1];
      edges[i,2] = edgesGet[2];
    }
    long[,] edgesSub = MinimumAllTree(edges);//最小全域木の作成
    long answer = 0;
    for(int i = 0; i < n-1; i++) answer += edgesSub[i,2];
    
    Console.WriteLine(answer);
	}

  static long[,] MinimumAllTree(long[,] edgesSub)
  {//unionfindでまだ繋がっていない全ての頂点を繋ぎ辺の和が最小の最小全域木で新たに繋いだ辺を返す。
  //辺数をeとして、辺の長さ順にソートするのでO(eloge)。
  //辺は0-indexの無向で[始点、終点、長さ]
    List<long> listStart = new List<long>();
    List<long> listGoal = new List<long>();
    List<long> listLength = new List<long>();
    int e = edgesSub.GetLength(0);
    long[][] edges = new long[e][];
    for(int i = 0; i < e; i++)
    {
      edges[i] = new long[3];
      for(int j = 0; j < 3; j++) edges[i][j] = edgesSub[i,j];
    }
    Array.Sort(edges, (a, b) => a[2].CompareTo(b[2]));//辺の長さでソート

    for(int i = 0; i < e; i++)
    {
      if(whatParent(edges[i][0]) != whatParent(edges[i][1]))
      {
        listStart.Add(edges[i][0]);
        listGoal.Add(edges[i][1]);
        listLength.Add(edges[i][2]);
        parents[whatParent(edges[i][0])] = whatParent(edges[i][1]);//親を結合して統一。親が2人できることはない。
      }
    }
    
    int answerCount = listStart.Count();
    long[,] answer = new long[answerCount,3];
    for(int i = 0; i < answerCount; i++)
    {
      answer[i,0] = listStart[i];
      answer[i,1] = listGoal[i];
      answer[i,2] = listLength[i];
    }

    return answer;
  }

  static long whatParent(long child)
  {
    if(parents[child] == child) return child;
    else return parents[child] = whatParent(parents[child]);
  }
  
}


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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec)
        is >> x;
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N, K;
    cin >> N >> K;

    string s;
    cin >> s;

    vector<pair<char, int>> v;

    pair<char, int> temp = make_pair(s[0], 1);
    FOR(i, 1, N) {
        if(temp.first != s[i]) {
            v.push_back(temp);
            temp.first = s[i];
            temp.second = 1;
        } else {
            temp.second++;
        }
    }
    v.push_back(temp);

    int ans = 0;
    int aans = 0;
    int cnt = 0;
    REP(i, v.size()) {

        // cout << v[i].first << " " << v[i].second << endl;

        if(v[i].first == '0') {
            if(cnt < K) {
                cnt++;
            } else {
                if(i - K * 2 >= 0) {
                    ans -= v[i - K * 2].second;
                }
                if(i - K * 2 - 1 >= 0) {
                    ans -= v[i - K * 2 - 1].second;
                }
            }
        }
        ans += v[i].second;

        aans = max(aans, ans);
    }

    cout << aans << endl;

    return 0;
}


Measured memory_bytes: 1528
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	double r,g; cin >> r >> g;
	cout << 2*g - r << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int mod = 998244353;
inline void reduce(int &x) { x += x >> 31 & mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
//ruogu_alter
const int N = 2e5 + 5;
int n, m, fac[N], inv[N];
//
int c(int x, int y) {
  return mul(fac[x], mul(inv[y], inv[x - y]));
}
int modpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1) ans = mul(ans, x);
    x = mul(x, x);
    y >>= 1;
  }
  return ans;
}
int modinv(int x) { return modpow(x, mod - 2); }
int main() {
  int k;
  fac[0] = 1; for (int i = 1; i < N; i++) fac[i] = mul(fac[i - 1], i);
  inv[N - 1] = modinv(fac[N - 1]);
  for (int i = N - 2; i >= 0; i--) inv[i] = mul(inv[i + 1], i + 1);
  n = getint(); m = getint(); k = getint();
  int res = 0;
  rep(i, k + 1) {
    int ans = mul(c(n - 1, i), mul(m, modpow(m - 1, n - i - 1)));
    reduce(res += ans - mod);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 5196
class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

class DirectedSegment:
    def __init__(self, s, e):
        self.start = s
        self.end = e

LEFT = -1
ONLINE = 0
RIGHT = 1

def datasets():
    import sys
    while True:
        s = sys.stdin.readline()
        if len(s) < 2:
            break
        x1, y1, x2, y2, x3, y3, xp, yp = [float(d) for d in s.split()]
        p1 = Point(x1, y1)
        p2 = Point(x2, y2)
        p3 = Point(x3, y3)
        x = Point(xp,yp)
        yield p1, p2, p3, x

def side(ds, p):
    return cmp(p.x * (ds.start.y - ds.end.y) + ds.start.x * (ds.end.y - p.y) + ds.end.x * (p.y - ds.start.y), 0)

for p1, p2, p3, x in datasets():
    r = [
            side(DirectedSegment(p1, p2), x),
            side(DirectedSegment(p2, p3), x),
            side(DirectedSegment(p3, p1), x)
        ]
    if all(0 < n for n in r) or all(0 > n for n in r):
        print "YES"
    else:
        print "NO"

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


int a[200050];
int b[200050];
int one[200050];
int zer[200050];
int ok,zk;
int cal(int x,int y)
{
    int c1=lower_bound(one,one+ok,y)-one;
    int c2=lower_bound(zer,zer+zk,y)-zer;
    if(x)
    {
        int f1=ok-c1;
        int f2=c2;
        return f1+f2;
    }
    else
    {
        int f1=c1;
        int f2=zk-c2;
        return f1+f2;
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",a+i);
    for(int i=0;i<n;i++)
        scanf("%d",b+i);
    int ans;
    for(int i=0;i<30;i++)
    {
        int f=1<<i;
        ok=zk=0;
        for(int j=0;j<n;j++)
        {
            int z=b[j]%f;
            if(b[j]&f)
                one[ok++]=z;
            else
                zer[zk++]=z;
        }
        sort(one,one+ok);
        sort(zer,zer+zk);
        int cnt=0;
        for(int j=0;j<n;j++)
        {
            int temp=cal((a[j]>>i)&1,f-a[j]%f);
//            printf("%d\n",temp);
            cnt^=temp%2;
        }
        if(cnt)
            ans|=f;
    }
    printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 3072
n = gets.chomp.to_i
a=[]
a.push(gets.chomp.to_i)
a.push(gets.chomp.to_i)
a.push(gets.chomp.to_i)
a.push(gets.chomp.to_i)
a.push(gets.chomp.to_i)

min = a.min
#puts min

if n%min==0
    puts n/min+4
else
    puts n/min+5
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0]==5 && a[1]==5 && a[2]==7) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> d(n, vector<int>(2));

    for(int i=0; i<n; i++) {
        for(int j=0; j<2; j++) {
            cin >> d[i][j];
        }
    }
    int zorome = 0;
    for(int i=0; i<n; i++) {
        if(d[i][0] == d[i][1]) {
            zorome++;
            if(zorome == 3) break;
        } else {
            zorome = 0;
        }
    }
    string ans = zorome >= 3 ? "Yes" : "No";
    cout << ans << endl;
}

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

string s;

int main(void){
	cin >> s;
	vector<int> c(30);
	for(auto i : s) c.at(i-'a')++;
	for(int i = 0; i < 26; i++){
		if(c.at(i) >= 2){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;

	return 0;
}


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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,ans; string str;

int solve(){
    cin>>n;
    rep(i,1,n){
        int t=i*1.08;
        if(t==n){
            cout<<i;
            return 0;
        }
    }
    cout<<":(";
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
s = input()
q = int(input())
flip = 1
right_edge = list(s)
left_edge = []
for i in range(q):
    query = input()
    if query[0] == '1':
        flip *= -1
    else:
        if query[2] == '1':
            if flip == 1:
                left_edge.append(query[-1])
            else:
                right_edge.append(query[-1])
        else:
            if flip == 1:
                right_edge.append(query[-1])
            else:
                left_edge.append(query[-1])
left_edge = left_edge[::-1]
if flip == 1:
    print(''.join(left_edge + right_edge))
else:
    print(''.join(right_edge[::-1] + left_edge[::-1]))
        



Measured memory_bytes: 103964
#! /usr/bin/env perl

my $input = <STDIN>;
chomp $input;
my ($n,$a,$b) = split / /, $input;

my $train = $a*$n;
my $tac = $b;

if($train == $tac)
{
    print $tac;
}
elsif($train < $tac)
{
    print $train;
}
elsif($train > $tac)
{
    print $tac;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  int ans = n;
  for (int i = 0; i < n; ++i) {
    if (s1.substr(i, n - i) == s2.substr(0, n - i)) {
      break;
    }
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)

n=int(input())
a=list(map(int,input().split()))

tree=[[] for _ in range(n)]
for _ in range(n-1):
    aa,bb=map(int,input().split())
    tree[aa-1].append(bb-1)
    tree[bb-1].append(aa-1)

ans=[0]*n
import bisect

#bisect.bisect_left(a, 4) #被ったら左側のindexを返す
#bisect.bisect_right(a, 4)#被ったら右側のindexを返す

def lisOnTree(x,lis):
    global ans,tree,a,n
    i=bisect.bisect_left(lis, a[x])
    if i==len(lis):
        lis.append(a[x])
        flag="append"
    else:
        flag=(i,lis[i])
        lis[i]=a[x]
    #print(x,lis)
    ans[x]=len(lis)
    for item in tree[x]:
        if ans[item]==0:
            lisOnTree(item,lis)
    if flag=="append":
        lis.pop()
    else:
        lis[flag[0]]=flag[1]

lisOnTree(0,[])

for item in ans:
    print(item)


    




Measured memory_bytes: 234788
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

typedef long long ll;
ll mod=1000000007;
ll gyaku(ll n){
  ll mo=mod-2;
  ll now=n;
  ll ret=1;
  while(mo>0){
    if(mo&1)ret*=now;
    ret%=mod;
    now*=now;
    now%=mod;
    mo/=2;
  }
  return ret;
}
ll nck(ll n,ll k){
  if(2*k>n)k=n-k;
  ll ret=1;
  for(ll i=0;i<k;i++){
    ret*=n-i;
    ret%=mod;
    ret*=gyaku(i+1);
    ret%=mod;
  }
  return ret;
}

int main(void){

  int n,m;
  cin >> n;
  cin >> m;
  /*
  vector<int> p(100001,1);
  p[0]=0;
  p[1]=0;

  for(int i=2;i<100000;i++){
    if(p[i]){
      for(int j=2;i*j<100000;j++){
        p[i*j]=0;
      }
    }
  }

  vector<int> pp(0);

  for(int i=2;i*i<=1000000000;i++){
    if(p[i]){
      //cout << i << " ";
      pp.push_back(i);
    }
  }
  /*
  for(int x:pp){
    cout << x << " ";
  }
  cout << endl;
  */
  /*
  int m_tmp=m;
  vector<int> pf(pp.size(),0);
  for(int i=0;i<pp.size();i++){
    while(m_tmp % pp[i] == 0){
      pf[i]++;
      m_tmp /= pp[i];
    }
  }
  */
  vector<int> pf(0);

  for(int i=2;m>1;i++){
    int sum=0;
    while(m % i == 0){
      sum++;
      m /= i;
    }
    if(sum) pf.push_back(sum);
  }


  long long int ans=1;
  for(int i=0;i<pf.size();i++){
    if(pf[i]){
      //cout << pp[i] << ":" << pf[i] << endl;
      //cout << ncr( pf[i] + n - 1 , n-1 ) << endl;
      ans *= nck( pf[i] + n - 1 , pf[i] );
      ans %= mod;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(){long N;
cin >> N;
vector<long> c(N + 1); vector<long> s(N + 1); vector<long> f(N + 1);
for(int i = 1; i <= N - 1; i++) cin >> c.at(i) >> s.at(i) >> f.at(i);
vector<long> dp(N + 1);
dp.at(1) = 0;

for(int x = 0; x < N; x++){
    for(int i = 1; i <= N - 1 - x; i++){
        if(dp.at(i) >= s.at(i + x)){
            for(int k = 0; k < 100; k++){
                if((dp.at(i) + k) % f.at(i + x) == 0){
                    dp.at(i + 1) = dp.at(i) + k + c.at(i + x);
                    break;
                }
            }
        }
        else{
            dp.at(i + 1) = s.at(i + x) + c.at(i + x);
        }
    }
    cout << dp.at(N - x) << endl;
}

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

Measured memory_bytes: 256
n=int(input())
v=list()

for i in range (n):
    a,b=input().split()
    b=int(b)
    if a=='S':
        v.append(b+0)
    elif a=='H':
        v.append(b+13)
    elif a=='C':
        v.append(b+26)
    elif a=='D':
        v.append(b+39)
for i in range(1,53):
    if not (i in v):
        if i<14:
            print(f"S {i-0}")
        elif i<27:
            print(f"H {i-13}")
        elif i<40:
            print(f"C {i-26}")
        else:
            print(f"D {i-39}")
        


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i=0;i<N;i++) cin >> p.at(i);
    int count=0;
    for(int i=1;i<=N;i++){
        if(p.at(i-1)!=i) count++;
    }
    if(count==0||count==2)cout<< "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        
        boolean isWin = false;

        for (int j = 0; j < N; j++) {

            if ((H - A[j]) <= 0) {
                isWin = true;
                break;
            } else {
                H -= A[j];
                
            }
        }
        if (isWin) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 50836
#include <iostream>

using namespace std;

bool maybeRed[100'000];
int balls[100'000];

int main()
{
    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++)
    {
        balls[i] = 1;
        maybeRed[i] = (i == 0);
    }

    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;

        maybeRed[y] = maybeRed[y] || maybeRed[x];
        balls[x]--;
        balls[y]++;

        if (balls[x] == 0)
        {
            maybeRed[x] = false;
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (maybeRed[i])
        {
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#define MAX 1000

int main() {
  int i, j, n, Y[MAX], M[MAX], D[MAX], sum[MAX];
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    sum[i]=0;
    scanf("%d %d %d", &Y[i], &M[i], &D[i]);
    for(j=Y[i]+1; j<1000; j++) {
      if(j%3 == 0) sum[i] += 200;
      else sum[i] += 195;
    }
    if(Y[i]%3 == 0) {
      sum[i] += 21-D[i];
      sum[i] += (10-M[i])*20;
    } else {
      if(M[i]%2 != 0) sum[i] += 21-D[i];
      else sum[i] += 20-D[i];
      for(j=M[i]+1; j<11; j++) {
	if(j%2 != 0) sum[i] += 20;
	else sum[i] += 19;
      }
    }
  }
  for(i=0; i<n; i++) {
    printf("%d\n",sum[i]);
  }
  return 0;
}


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

static const int NMAX = 1000;
static const long long MOD = 1000000007;

ll N;
int fact[NMAX+1];

void factoring(int num){
  int x = 2;

  while(num >= x*x){
    if(num%x == 0){
      fact[x]++;
      num /= x;
    }else{
      x++;
    }
  }
  fact[num]++;
}

int main(){
  cin >> N;
  for(int i=0;i<=NMAX;i++) fact[NMAX] = 0;

  ll ans = 1;

  if(N==1){
    cout << ans << endl;
    return 0;
  }

  for(int i=2;i<=N;i++) factoring(i);

  for(int i=2;i<=N;i++){
    if(fact[i]==0) continue;
    ans = (ans * (fact[i]+1)) % MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;

ll kaikai[11000]={};
ll KAI(ll m)
{
  if(kaikai[m])return kaikai[m];
  if(m<0) return 0;
  if(m==0) return 1;
  kaikai[m]=m*KAI(m-1)%MOD;
  return kaikai[m];
}

ll extGCD(ll a, ll b, ll *x, ll *y) {
    if (b == 0) {
        *x = 1;
        *y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    *y -= a / b * *x;
    return d;
}

 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, &x, &y);
    return (x % MOD + MOD) % MOD;
}

ll n,a,ans=0,co[5100]={},dp[5005][5005][3]={};

int main()
{
 
  scanf("%lld%lld",&n,&a);
  co[0]=1;
  rep(i,5050)co[i+1]=co[i]*(n-a-1-i)%MOD*modinv(i+1)%MOD;
  dp[a][0][0]=1;
  ROF(i,1,a+1){
    rep(j,a+2){
      rep(k,3){
        if(k==0){
          dp[i-1][j][1]+=dp[i][j][k]*(i-1)%MOD;
          dp[i-1][j][1]%=MOD;
          dp[i][j+1][2]+=dp[i][j][k];
          dp[i][j+1][2]%=MOD;
        }
        else if(k==1){
          dp[i-1][j][0]+=dp[i][j][k]%MOD;
          dp[i-1][j][0]%=MOD;
          dp[i-1][j][1]+=dp[i][j][k]*(i-1)%MOD;
          dp[i-1][j][1]%=MOD;
          dp[i][j+1][2]+=dp[i][j][k]%MOD;
          dp[i][j+1][2]%=MOD;
        }
        else{
          dp[i-1][j][0]+=dp[i][j][k]%MOD;
          dp[i-1][j][0]%=MOD;
          dp[i-1][j][1]+=dp[i][j][k]*(i-1)%MOD;
          dp[i-1][j][1]%=MOD;
        }
      }
    }
  }
  rep(i,a+1){
    FOR(j,1,a+2){
      if(j>n-a)continue;
      ans+=dp[i][j][2]*KAI(i)%MOD*co[j-1]%MOD;
      ans%=MOD;
    }
  }
  rep(i,n-a){
    ans*=(i+1);
    ans%=MOD;
  }
  printf("%lld",ans);
}


Measured memory_bytes: 588424
import java.util.Scanner;
 
class Main{
    public static void main(String[] args) {
        
    	Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        Node[] heap = new Node[n + 1];
        heap[0] = new Node();
        
        for (int i = 1; i < n + 1; i++) {
            heap[i] = new Node();
            heap[i].id = i;
            heap[i].key = sc.nextInt();
        }
 
        buildMaxHeap(heap, n);
        
        
        for(int i = 1;i < n+1;i++){
            System.out.print(" "+heap[i].key);
        }
        
        System.out.println();
    }
 
    static void maxHeapify(Node A[], int i, int n) {
        int l = 2 * i;
        int r = 2 * i + 1;
        int max = i;
        //System.out.println(l+" "+r);
        if (l <= n && A[l].key > A[max].key)max = l;
        if (r <= n && A[r].key > A[max].key)max = r;
        if (max != i) {
            int temp = A[i].key;
            A[i].key = A[max].key;
            A[max].key = temp;
            maxHeapify(A, max, n);
        }
 
    }
 
    static void buildMaxHeap(Node A[], int n){
        for(int i = n/2;i > 0;i--){
            maxHeapify(A, i, n);
        }
    }
}
 
class Node {
    int id;
    int key;
    int p;
    int l;
    int r;
 
    Node() {
        id = Integer.MIN_VALUE;
        key = Integer.MIN_VALUE;
        p = Integer.MIN_VALUE;
        l = Integer.MIN_VALUE;
        r = Integer.MIN_VALUE;
    }
}



Measured memory_bytes: 184980
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int r;
   cin >> r;
   cout << r * r << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int S, W;
	cin >> S >> W;

	if (W >= S)
	{
		cout << "unsafe";
	}
	else
	{
		cout << "safe";
	}

	return 0;
}


Measured memory_bytes: 3608
def main():
	a, b , c = map(int , input().split())
	if a==b and b==c:
		print(0)
	else:
		tot=0
		tot = tot+(a+b+c)
		mx = max(a, max(b, c))
		i = 0
		f=0
		while f==0:
			if((tot+2*i)%3==0):
				p = ((tot+2*i))//3
				if p>=mx:
					f=1
			i = i+1
		print(i-1)
if __name__=="__main__":
	main()

Measured memory_bytes: 61836
#include <stdio.h>

int n, A[50];

// ??\?????????M???????????????????´????????????????????????°??¢??°
int solve(int i, int m) {
  if(m==0) return 1;
  if(i>=n) return 0;
  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

int main(void) {
  int q, M, i;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for (int i=0; i<q; i++) {
    scanf("%d",&M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int query (const string &s) {
  cout << "? " << s << endl;

  int ans;
  cin >> ans;

  return ans;
}

const int MAX_L = 128;
int get_cnt (char c) {
  return MAX_L - query(string(MAX_L, c));
}

string build (const string &s, const string &t, const vector<int> &blocks) {
  string ans = "";

  int tptr = 0;
  for (int k = 0; k < (int) s.size(); k++) {
    for (int i = 0; i < blocks[k]; i++) {
      ans += t[tptr];
      tptr++;
    }
    ans += s[k];
  }
  for (int i = 0; i < blocks.back(); i++) {
    ans += t[tptr];
    tptr++;
  }

  return ans;
}

int n;
string merge (const string &s, const string &t) {
  vector<int> blocks ((int) s.size() + 1, 0);

  int len = s.size();
  for (int i = 0; i <= (int) s.size(); i++) {
    while (true) {
      blocks[i]++;
      len++;
      if (len > (int) t.size() + (int) s.size()) {
        blocks[i]--;
        len--;
        break;
      }
      int cur = query(build(s, t, blocks));
      if (cur != n - len) {
        blocks[i]--;
        len--;
        break;
      }
    }
  }
  return build(s, t, blocks);
}

const int MAX_M = 200;

string at [MAX_M];

int main () {
  priority_queue<pair<int, char>, vector<pair<int, char>>, greater<pair<int, char>>> PQ;
  for (char c = 'a'; c <= 'z'; c++) {
    int cnt = get_cnt(c);
    n += cnt;
    if (cnt > 0) {
      at[c] = string(cnt, c);
      PQ.push(make_pair(cnt, c));
    }
  }
  for (char c = 'A'; c <= 'Z'; c++) {
    int cnt = get_cnt(c);
    n += cnt;
    if (cnt > 0) {
      at[c] = string(cnt, c);
      PQ.push(make_pair(cnt, c));
    }
  }
  for (char c = '0'; c <= '9'; c++) {
    int cnt = get_cnt(c);
    n += cnt;
    if (cnt > 0) {
      at[c] = string(cnt, c);
      PQ.push(make_pair(cnt, c));
    }
  }

  while ((int) PQ.size() >= 2) {
    auto p0 = PQ.top();
    PQ.pop();
    auto p1 = PQ.top();
    PQ.pop();

    string s = merge(at[p0.second], at[p1.second]);
    at[p0.second] = s;
    PQ.push(make_pair((int) s.size(), p0.second));
  }

  auto p0 = PQ.top();
  PQ.pop();
  cout << "! " << at[p0.second] << endl;
}


Measured memory_bytes: 3800
import sys

K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

# うまい方法がない気がするため、二分探索で攻める
l = 0
r = 2 * 10**15
ans1 = -1
while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res >= 2:
        r = n
        if res == 2:
            ans1 = n
    else:
        l = n + 1

l = 0
r = 2 * 10**15
ans2 = -1
while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res <= 2:
        l = n + 1
        if res == 2:
            ans2 = n
    else:
        r = n

if ans1 != -1:
    print(ans1, ans2)
    # print(n - n % A[0], A[0] * ((n - 1) // A[0] + 1) - 1)
else:
    print(-1)

Measured memory_bytes: 20612
import java.util.Scanner;

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

		for (int i = 0; i < c.length(); i++) {
			char t = c.charAt(i);
			if ('A' <= t && t <= 'Z') {
				t += 32;
			} else if ('a' <= t && t <= 'z') {
				t -= 32;
			}
			System.out.print(t);
		}
		System.out.println();
	}
}


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


using namespace std;
int l,m,n;
float f,g,h;
long long a,b,c,k;


int main(int argc, char const *argv[])
{

  cin >> a >> b >> c >> k;

  if(a >= b && a >= c){
    cout << (a<<k) + b + c <<endl;
  }else
  if(c >= b && c >= a){
    cout << (c<<k)  + a + b<<endl;
  }else
  if(b >= a && b >= c){
    cout << (b<<k) + c + a <<endl;
  }
  // cut << l * m  * n  << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}


int a[10];

void output(int a){
    if (a){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    exit(0);
}

int main(){
    cin.tie(0);
    
    string ss = "AKIHABARA";
    string s; cin >> s;

    int j = 0;
    for (int i = 0; i < s.length(); i++){
        if (j == ss.length()) output(0);
        while (j < ss.length()){
            if (s[i] == ss[j]){
                a[j] = 1;
                j++;
                break;
            }
            j++;
        }
    }
    for (int i = 0; i < ss.length(); i++){
        if (!a[i] && ss[i] != 'A') output(0);
    }
    output(1);
    return 0;
} 


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> piccel(H+2,vector<char>(W+2,'#'));
  for(int i=1;i<H+1;++i){
    for(int j=1;j<W+1;++j){
      cin >> piccel.at(i).at(j);
    }
  }
  
  for(int i=0;i<H+2;++i){
    for(int j=0;j<W+2;++j){
      cout << piccel.at(i).at(j);
      if(j==W+1)
        cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b,c,d;
  cin>>a>>b;
  for(int i=0;i<999;i++){
    int tmp=i*(i+1)/2;
    if(tmp>=a){
      c=tmp;
      d=tmp+(i+1);
      if(c-a==d-b){
        cout<<c-a<<endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int ball = in.nextInt();
        int man = in.nextInt();
        in.close();
        int ans = man > 1 ? ball - man : 0;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
char str[1000005];
int n,m;
int main()
{
while(1){
  vector<int>vec;
  scanf("%d %d",&n,&m); if(!n) break;
  scanf("%s",&str);
  int i=0;
  for(;;)
    {
      if(str[i]=='I')
	{
	  int now=0;
	  while(i+2<m)
	    {
	      if(str[i+1]=='O' && str[i+2]=='I')
		{
		  i+=2;
		  now++;
		}else
		{
		  break;
		}
	    }
	  vec.push_back(now);
	}
      i++;
      if(i>=m) break;
    }
  int ans=0;
  for(int i=0;i<vec.size();i++)
    {
      ans+=max(vec[i]-n+1,0);
    }
  printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 2064
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<deque>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
//#define ll __int64
#define ll long long
#define P pair<ll,ll>

int n,a,b;
ll t[1100000];
ll tt[110000];

bool che(ll x){
	rep(i,n)tt[i]=t[i];

	ll cnt=0;//Aで殴る必要のある回数
	rep(i,n){
		tt[i]-=b*x;
		
		if(tt[i]>0){
			cnt+=tt[i]/(a-b);
			if(tt[i]%(a-b))cnt++;
		}
	}
	if(cnt>x)return 0;
	else return 1;
}

int main(){
	cin>>n>>a>>b;
	rep(i,n)cin>>t[i];
	ll l=0,r=10000000001;
	ll mid=(l+r)/2;

	rep(i,100){
		if(che(mid))r=mid;
		else l=mid;
		mid=(r+l)/2;
	}
	
	cout<<mid+1<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int N; cin >> N;
    for(int i = 0;i <= 50000;i++) {
        if(floor(i * 1.08) == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  long N,M;
  scanf("%ld %ld",&N,&M);
  long A[M];
  long i,sum=0;
  for(i=0;i<M;i++){
    scanf("%ld",&A[i]);
  }
  for(i=0;i<M;i++){
    sum=sum+A[i];
  }
  N=N-sum;
  if(N<0){
    printf("-1");
  }
  else{
    printf("%ld",N);
  }
  return 0;
}

Measured memory_bytes: 1760
#include<iostream>
#include<math.h>
#include<stdio.h>

using namespace std;

int main(void)
{
	double q;
	while(1){
		cin>>q;
		if(q==-1) break;
		double x=q/2;
		while(1){
			x=x-((x*x*x-q)/(3*x*x));
			if(fabs(x*x*x-q)<0.00001*q) break;
		}
		printf("%.6lf\n",x);
	}
	return 0;
}

Measured memory_bytes: 1228
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
int n, a[N], b[N], c[2], d[N];
char s[N];
int Abs(int x){return x > 0 ? x : -x;}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &a[i], &b[i]);
		++c[(a[i] + b[i]) & 1];
    }
    if (c[0] != n && c[1] != n)
    {
    	puts("-1");
		return 0;
    }
    printf("%d\n", 31 + (c[0] != 0));
	for (int i = 0; i <= 30; i++)
		printf("%d ", 1 << i);
	if (c[0])
		printf("1 ");
	putchar(10);
	for (int i = 1; i <= n; i++)
	{
		int x = a[i], y = b[i];
		if (c[0])
			--x, s[31] = 'R';
		int f = 0;
        for (int i = 30; i >= 0; i--)
        {
            if (Abs(x) < Abs(y))
            	swap(x, y), f ^= 1;
			if (x > 0)
				x -= 1 << i, s[i] = "RU"[f];
			else
				x += 1 << i, s[i] = "LD"[f];
		}
		puts(s);
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int a = s[0] - '0';
		int b = s[1] - '0';
		int c = s[2] - '0';
		int d = s[3] - '0';

		if(a+b+c+d ==7) {
			System.out.printf("%d+%d+%d+%d=7",a,b,c,d);
		}else if(a+b+c-d ==7) {
			System.out.printf("%d+%d+%d-%d=7",a,b,c,d);
		}else if(a+b-c+d ==7) {
			System.out.printf("%d+%d-%d+%d=7",a,b,c,d);
		}else if(a+b-c-d ==7) {
			System.out.printf("%d+%d-%d-%d=7",a,b,c,d);
		}else if(a-b+c+d ==7) {
			System.out.printf("%d-%d+%d+%d=7",a,b,c,d);
		}else if(a-b+c-d ==7) {
			System.out.printf("%d-%d+%d-%d=7",a,b,c,d);
		}else if(a-b-c+d ==7) {
			System.out.printf("%d-%d-%d+%d=7",a,b,c,d);
		}else if(a-b-c-d ==7) {
			System.out.printf("%d-%d-%d-%d=7",a,b,c,d);
		}

		sc.close();
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>

using namespace std;


int main() {
  int N;
  scanf("%d",&N);
  if (N==1) printf("Hello World");
  else {
    int A,B;
    scanf("%d%d",&A,&B);
    printf("%d",A+B);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    vec A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];
    vector<Pii> a(N), b(N);
    REP(i, N){
        a[i] = Pii(A[i], i);
        b[i] = Pii(B[i], i);
    }
    SORT(a); SORT(b);

    vec Bm(N);
    REP(i, N) Bm[i] = B[a[i].second];
    //REP(i, N) cout << Bm[i] << endl;
    IREP(i, N - 1) Bm[i] = max(Bm[i], Bm[i + 1]);
    //REP(i, N) cout << Bm[i] << endl;
    SORT(A); SORT(B);

    int ans = INF;
    int tmp = 0;
    REP(i, N) tmp += B[i];
    ans = min(ans, tmp);
    tmp = 0;
    REP(i, N) tmp += A[i];
    ans = min(ans, tmp);

    
    REP(i, N - 1){
        tmp += B[i] - A[N - 1 - i];
        int tmp2 = tmp;
        int tmp3 = tmp;
        if(B[i] == Bm[N - 1 - i]){
            tmp2 += B[i + 1] - B[i];
            tmp3 -= A[N - 1 - i - 1] - A[N - 1 - i];
        }
        ans = min(ans, tmp2);
        ans = min(ans, tmp3);
    }
    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 5760
import math
x=int(input())

serach_number = 100004

def sieve_of_eratosthenes(target, x):
    dest = int(math.sqrt(target))
    target_list = list(range(2, target + 1))
    prime_list = []

    while True:
        num_min = min(target_list)
        if num_min >= dest:
            prime_list.extend(target_list)
            break
        prime_list.append(num_min)


        i = 0

        while True:
            if i >= len(target_list):
                break
            elif target_list[i] % num_min == 0:
                target_list.pop(i)
            i += 1
    while True:
        if (x in prime_list) == True:
            print(x)
            break
        else:
            x +=1


sieve_of_eratosthenes(serach_number, x)


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

int main() {
    int n, x, v_min, v_max;
    long long sum;
    // int sum;
    cin >> n;
    cin >> x;
    v_min = x;
    v_max = x;
    sum = x;
    for (int i=1;i<n;i++) {
        cin >> x;
        v_min = min(v_min, x);
        v_max = max(v_max, x);
        sum += x;
    }
    cout << v_min << " " << v_max << " " << sum << endl;
    return 0;
}




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

def dbg(s):
    # print(s)
    pass


X, K, D = map(int, input().split())
absX = abs(X)

k_steps = abs(X)//D
x = absX - K*D
mod = abs(X) % D
if k_steps >= K:
    print(x)
    exit()

remain_steps = K - k_steps

if remain_steps % 2 == 0:
    x = mod
else:
    x = D - mod
print(x)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define P pair<int,int>
#define prique priority_queue
signed main(){
	int n,a[400000];
	vector<int>ans;
	cin>>n;
	rep(i,n)cin>>a[i];
	for(int i=n-1;i>0;i-=2)ans.push_back(a[i]);
	ans.push_back(a[0]);
	if(n%2){
		for(int i=1;i<n;i+=2)ans.push_back(a[i]);
	}
	else{
		for(int i=2;i<n;i+=2)ans.push_back(a[i]);
	}
	rep(i,n){
		cout<<ans[i];
		if(i==n-1)cout<<endl;
		else cout<<" ";
	}
	return 0;
}


Measured memory_bytes: 6896
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;
using pii = pair<int,int>;

void print(int a[], int n)
{
    rep(i, n) {
        printf("%d%c", a[i], i+1 < n ? ' ' : '\n');
    }
}

signed main()
{
    int N, a[101];
    scanf("%d", &N);

    rep(i, N) scanf("%d", a+i);
    print(a, N);

    for (int i=1; i<N; ++i) {
        int j = i-1;
        int tmp = a[i];
        while (j >= 0 && a[j] > tmp) {
            a[j+1] = a[j];
            --j;
        }
        a[j+1] = tmp;
        print(a, N);
    }
}




Measured memory_bytes: 3156
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<int> cntR(n);
    int tmp=0;
    for(int i=0;i<n;i++){
        if(s[i]=='L'){
            cntR[i-1]=tmp;
            tmp=0;
        }
        else tmp++;
    }
    vector<int> cntL(n);
    tmp=0;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='R'){
            cntL[i+1]=tmp;
            tmp=0;
        }
        else tmp++;
    }

    vector<int> res(n);
    for(int i=0;i<n;i++){
        int v=(cntR[i]+1)/2+(cntL[i]+1)/2;
        res[i]+=v;
        if(i-1>=0){
            res[i]+=cntR[i-1]/2;
        }
        if(i+1<n){
            res[i]+=cntL[i+1]/2;
        }
    }
    for(int i=0;i+1<n;i++){
        cout<<res[i]<<" ";
    }
    cout<<res.back()<<endl;
    return 0;
}


Measured memory_bytes: 1792
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys

hw = []
h,w = map(int, input().split())
while h+w > 0:
  hw.append([h,w])
  h,w = map(int, input().split())

for i in range(len(hw)):
  for _ in range(hw[i][0]):
    for _ in range(hw[i][1]):
      print("#", end="")
    print()
  print()



Measured memory_bytes: 7016
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int col[8] = {0};
  int red = 0;
  rep(i, n){
    int a;
    cin >> a;
    if(a/400 >= 8) red++;
    else col[a/400] = 1;
  }
  int ans = 0;
  rep(i, 8) ans += col[i];
  cout << max(ans,1) << " " << ans+red << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
a = s[len(s)-1]

if a == "2" or a == "4" or a == "5" or a == "7" or a == "9":
    print("hon")
elif a == "0" or a == "1" or a == "6" or a == "8":
    print("pon")
else:
    print("bon")

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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

ll dp[101][101];
priority_queue<ll> minusa[101][101];

ll n, k;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    cin >> n >> k;
    vll v(n);
    REP(i, n) cin >> v[i];

    REP(l, n) REP(r, n) {

        if(l + r >= k or l + r >= n)
            continue;

        dp[l + 1][r] = dp[l][r] + v[l];
        minusa[l + 1][r] = minusa[l][r];
        if(v[l] < 0)
            minusa[l + 1][r].push(-v[l]);

        dp[l][r + 1] = dp[l][r] + v[n - 1 - r];
        minusa[l][r + 1] = minusa[l][r];
        if(v[n - 1 - r] < 0)
            minusa[l][r + 1].push(-v[n - 1 - r]);

        // cout << "dp " << l << " " << r << " " << dp[l][r] << endl;
    }

    ll ans = 0;
    REP(l, n + 1) REP(r, n + 1) {

        if(l + r > k or l + r > n)
            continue;

        for(int i = l + r; i < k; i++) {
            if(!minusa[l][r].empty()) {
                dp[l][r] += minusa[l][r].top();
                // cout << l << " " << r << " "
                //      << " " << i - l - r << " " << minusa[l][r].top() << " "
                //      << dp[l][r] << endl;
                minusa[l][r].pop();
            }
        }
        ans = max(ans, dp[l][r]);
    }

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


Measured memory_bytes: 1280