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

using namespace std;

using ll = long long;

//引数unzipには圧縮前のvectorを入れる
int compress(vector<ll>& unzip, map<ll, int>& zip) {
    sort(unzip.begin(), unzip.end());
    unzip.erase(unique(unzip.begin(), unzip.end()), unzip.end());
    for (int i = 0; i < unzip.size(); i++) {
        zip[unzip[i]] = i;
    }
    return unzip.size();
}

//1-indexであることに注意
template <typename T>
struct BIT {
    int n;
    vector<T> data;

    BIT(int n) : n(n), data(n + 1, 0) {}

    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, T x) {
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }
};

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

    vector<int> com(q);
    vector<ll> a, b;
    for (int i = 0; i < q; i++) {
        cin >> com[i];
        if (com[i] == 1) {
            ll x, y;
            cin >> x >> y;
            a.push_back(x);
            b.push_back(y);
        }
    }

    vector<ll> unzip = a;
    map<ll, int> zip;
    int sz = compress(unzip, zip);

    int cnt = 0;
    ll bsum = 0;
    int idx = 0;
    BIT<int> bt1(sz);
    BIT<ll> bt2(sz);
    for (int i = 0; i < q; i++) {
        if (com[i] == 1) {
            int ai = zip[a[idx]];
            bt1.add(ai + 1, 1);
            bt2.add(ai + 1, a[idx]);
            bsum += b[idx];
            idx++;
            cnt++;
        } else {
            int ng = 0, ok = sz;
            while (ok - ng > 1) {
                int mid = (ok + ng) / 2;
                int hoge = bt1.sum(mid);
                if (hoge >= (cnt + 1) / 2) ok = mid;
                else ng = mid;
            }

            ll x = unzip[ok - 1];
            int foo = bt1.sum(ok);
            int bar = cnt - foo;
            ll uku = bt2.sum(ok);
            ll ans = (bt2.sum(sz) - uku) - x * bar + x * foo - uku + bsum;
            cout << x << " " << ans << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 13164
#include <bits/stdc++.h>
using namespace std;
using int64 = int64_t;
#define int int64

int dp[101010][3];

signed main(){
  int n;cin>>n;
  vector< vector<int> > d(n, vector<int>(3,0));
  for(int i=0;i<n;++i) for(int j=0;j<3;++j) cin>>d[i][j];
  
  for(int i=0;i<n;++i){
    for(int j=0;j<3;++j){
      for(int k=0;k<3;++k){
      if(j==k) continue;
      dp[i+1][k] = max(dp[i+1][k], dp[i][j] + d[i][k]);
      }
    }
  }
  
  cout<<(max(max(dp[n][0], dp[n][1]), dp[n][2]))<<endl;
}


Measured memory_bytes: 8064
s = list(map(int, list(input())))
x = [i % 2 for i in range(len(s))]
y = [i % 2 for i in range(1, len(s) + 1)]
cntx = cnty = 0
for i, j, k in zip(s, x, y):
    if i != j:
        cntx += 1
    if i != k:
        cnty += 1
print(min(cntx, cnty))

Measured memory_bytes: 5404
#include<cstdio>
#include<algorithm>
using namespace std;

int p[5001];
int f1[5001][5002],f2[5001][5002];
long long f[5002];
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=0;i<=n;i++)
		for(int j=i+1;j<=n+1;j++){
			f1[i][j]=f1[i][j-1]+(i!=0&&j!=n+1&&p[j]<p[i]);
			//printf("1:%d %d %d\n",i,j,f1[i][j]);
		}
	for(int j=1;j<=n+1;j++)
		for(int i=j-1;i>=0;i--){
			f2[i][j]=f2[i+1][j]+(i!=0&&j!=n+1&&p[j]<p[i]);
			//printf("2:%d %d %d\n",i,j,f2[i][j]);
		}
	for(int i=1;i<=n+1;i++)
		f[i]=~0ull>>1;
	for(int i=0;i<=n+1;i++){
		//printf("%d %lld\n",i,f[i]);
		for(int j=i+1;j<=n+1;j++)
			if(!(i==0&&j==n+1)&&(i==0||j==n+1||p[j]>p[i])&&f1[i][j]+f2[i][j]==j-i-1){
				f[j]=min(f[j],f[i]+1ll*f1[i][j]*b+1ll*f2[i][j]*a);
				//printf("%d %d %lld\n",i,j,f[i]+1ll*f1[i][j]*b+1ll*f2[i][j]*a);
			}
	}
	printf("%lld\n",f[n+1]);
}

Measured memory_bytes: 135332
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

vector<vector<int>> memo;
string s;

int dfs(int pos, int even) {
  if (memo[pos][even] > -1) {
    return memo[pos][even];
  }
  if (s[pos] == 'R') {
    if (s[pos+1] == 'L') {
      int ret;
      if (even) ret = pos;
      else ret = pos+1;
      memo[pos][even] = ret;
    } else {
      int ret = dfs(pos+1, !even);
      memo[pos][even] = ret;
    }
  } else {
    if (s[pos-1] == 'R') {
      int ret;
      if (even) ret = pos;
      else ret = pos-1;
      memo[pos][even] = ret;
    } else {
      int ret = dfs(pos-1, !even);
      memo[pos][even] = ret;
    }
  }
  return memo[pos][even];
}

int main() {
  cin >> s;
  memo.resize(s.length(), vector<int>(2, -1));
  vector<int> ans(s.length());
  for (int i = 0; i < s.length(); i++) {
    ans[dfs(i, 1)]++;
  }
  for (auto a : ans) {
    cout << a << endl;
  }
  return 0;
}


Measured memory_bytes: 12672
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N;
	cin >> N;
	int S = 0;
	int n = N;
	int keta = log10(N) + 1;
	rep(i, keta) {
		S += N % 10;
		N /= 10;
	}
	if (n % S)cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 512
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    m = II()
    Digit = 0
    Sum = 0
    for _ in range(m):
        d, c = LI()
        Digit += c
        Sum += d * c
    print(Digit + (Sum - 1) // 9 - 1)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 43260
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i = 0; i < M; i++) cin >> A[i];
    ll day = 0;
    for(int i = 0; i < M; i++) day+=A[i];
    if(N >= day) cout << N - day << endl;
    else puts("-1");
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int N;
vector<string> S;

int main() {
    cin >> N;
    rep(i, 3) {
        string si;
        cin >> si;
        S.pb(si);
    }
    int sum = 0;
    rep(i, N) {
        set<char> setc;
        rep(j, 3) {
            setc.insert(S[j][i]);
        }
        sum += setc.size() - 1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	int q; cin >> q;
	vector<set<int>> v(26);
	rep(i, n)
	{
		int d = s[i] - 'a';
		v[d].insert(i + 1);
	}
	while (q--)
	{
		int t; cin >> t;
		if (t == 1)
		{
			int i; cin >> i;
			char c; cin >> c;
			rep(j, 26)
			{
				v[j].erase(i);
			}
			v[c - 'a'].insert(i);
		}
		else
		{
			int l, r; cin >> l >> r;
			int cnt = 0;
			rep(i, 26)
			{
				if (v[i].size() == 0)continue;
				auto it = v[i].lower_bound(l);
				if (it == v[i].end())continue;
				if (*it <=r) ++cnt;
			}
			cout << cnt << endl;
		}
	}
}


Measured memory_bytes: 26244
n = int(input())
A = tuple(map(int, input().split()))
cnt = 0
zero = False
for a in A:
    if a < 0:
        cnt += 1
    elif a == 0:
        zero = True

if cnt%2 == 0 or zero:
    print(sum(map(abs, A)))
else:
    A = sorted(map(abs, A))
    print(sum(A) - 2*A[0])


Measured memory_bytes: 93736
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

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

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  long long  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d", &a);
  if(a%2==0)   printf("%lf\n", (double)1/2);
  else    printf("%lf\n", (double)((a/2)+1)/a);
   

return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

import bisect
N = int(readline())
A = sorted(list(map(int,readline().rstrip().split())))
B = list(map(int,readline().rstrip().split()))
C = sorted(list(map(int,readline().rstrip().split())))
cnt = 0
for i in range(N):
    j = bisect.bisect_left(A,B[i])
    k = bisect.bisect_right(C,B[i])
    cnt += j*(N-k)
print(cnt)

Measured memory_bytes: 23348
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    VI ans(n);
    FOR(i,1,n-1){
        ans[in() - 1]++;
    }
    REP(i,n) printf("%d\n", ans[i]);
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<si> vsi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vsi> vvsi;



// void dp(sp_1, sp_2.....)
// {
// 	if()//exit statement
// 	if()//using the memoization 
// 	ll ans = //default/dummy answer
// 	//recursions
// 			//max/min
// 	return memo[][].. = ans;

// }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	cout.tie(NULL);
 	//memset(memo, -1, sizeof memo);
 	int n,j, mini = INT_MAX; cin>>n;
 	int a[n+1];
 	a[0] = 0;
 	cin>>a[1];
 	for(int i =2 ; i <=n ; i++)
 	{
 		cin>>j;
 		a[i] = j+a[i-1];
 	}
 	for(int i = 2 ; i<n;i++)
 		mini = min(mini,abs( 2*a[i] - a[n]));
 	cout<<mini<<endl;
 	return 0;
}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  ll n, a, b;
  std::cin >> n >> a >> b;
  if ((a & 1) == (b & 1))
    std::cout << (b - a) / 2 << "\n";
  else {
    ll ans = 0;
    if (n - a < b - 1) {
      ans = n - b + 1;
      a += n - b + 1;
      ans += (n - a) / 2;
    } else {
      ans = a;
      b -= a;
      ans += (b - 1) / 2;
    }
    std::cout << ans << "\n";
  }
}


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

using namespace std;

int main() {
    long n;
    cin >> n;
    long a[n], sum=0;
    for (auto &ai:a) {
        cin >> ai;
        sum += ai;
    }
    long stare = n * (n+1) / 2;
    if (sum % stare) {
        cout << "NO" << '\n';
        return 0;
    }
    long layer = sum / stare,
         prev  = a[n-1];
    for (auto ai:a) {
        long step = prev - ai + layer;
        if (step < 0 || step % n) {
            cout << "NO" << '\n';
            return 0;
        }
        prev = ai;
    }
    cout << "YES" << '\n';
    return 0;
}

Measured memory_bytes: 1024
//
//  main.cpp
//  ABC159D2
//
#include <iostream>
#include<vector>
using namespace std;
int main()
{
    long long N; // ボールの数
    cin >> N;
    vector<long long>A(N+1); // ボールに書かれている整数
    vector<long long>d(200001); // d(0)~d(200000)まで
    for (int i = 1; i <= N; i++)
    {
        cin >> A.at(i);
        d.at(A.at(i))++; // 各数値のボールが何個あるか
    }
    long long all = 0;
    for (int j = 1; j <= 200000; j++)
    {
        if (d.at(j)>1) // ボールが２個以上
        {
            long long cmb = d.at(j)*(d.at(j)-1)/2; // 同じ数値から２個取る組合せの数
            all += cmb;
        }
    }
    //  k番目のボールを除いたとき、減る組合せの数
    long long before=0;
    long long after=0;
    for (int k = 1; k <= N; k++)
    {
        if (d.at(A.at(k))>1) // ボールが２個以上ある　組合せの数が変化する
        {
            before=d.at(A.at(k))*(d.at(A.at(k))-1)/2;
            after=(d.at(A.at(k))-1)*(d.at(A.at(k))-2)/2;
            cout << all - before + after << endl;
        }else{
            cout << all<<endl; // ボールが１個しかなく、結果に影響がない
        }

    }
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int a;
    int arr[4];
    cin>>arr[1]>>arr[2]>>arr[3];
    cin>>a;
    sort(arr+1,arr+4,cmp);
    int att=0;
    att=att+arr[2]+arr[3];
    int y=1;
    for(int i=1;i<=a;i++)
    {
        arr[1]*=2;
    }
    att+=arr[1];
    cout<<att<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (W-r>=x&&H-r>=y&&r<=x&&r<=y){
		cout << "Yes" << endl;
	}

	else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main(){
    //全ての操作をO(1)で出来ればforを回すだけで良いだろう.
    string S;cin>>S;
    int Q;cin>>Q;
    vector<char> lst_1;
    vector<char> lst_2;
    //revの回数が偶数か奇数かのみ見ればよい.
    int flg = 0;//flgが偶数.
    rep(i,Q){
        int T;cin>>T;
        if(T == 1){
            flg += 1;
        }else{
            int F;char C;cin>>F>>C;
            if(F==1){
                if(flg % 2 == 0){
                    lst_1.push_back(C);
                }else{
                    lst_2.push_back(C);
                }
            }else{
                if(flg % 2 == 0){
                    lst_2.push_back(C);
                }else{
                    lst_1.push_back(C);
                }
            }
        }
    }
    //最後にまとめてくっつける
    if(flg % 2 == 0){
        reverse(lst_1.begin(),lst_1.end());
        for(char x:lst_1){
            cout<<x;
        }
        cout<<S;
        for(char y:lst_2){
            cout<<y;
        }
        cout<<endl;
    }else{
        reverse(lst_2.begin(),lst_2.end());
        reverse(S.begin(),S.end());
        for(char x:lst_2){
            cout<<x;
        }
        cout<<S;
        for(char y:lst_1){
            cout<<y;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; ++i) if (s[i] == '?') s[i] = 'D';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3740
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fifirst
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_penext_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int n,fir;
ll k;
ll a[200010],b[200010];
inline int finda(int i,ll ans){
    int l=1,r=n,mid,ret=0;
    while(l<=r){
        mid=(l+r)>>1;
        if(a[mid]*a[i]<ans) ret=mid,l=mid+1;
        else r=mid-1;
    }
    return ret>=i?(ret-1):ret;
}
inline int findb(int i,ll ans){
    int l=1,r=n,mid,ret=0;
    while(l<=r){
        mid=(l+r)>>1;
        if(b[mid]*a[i]<ans) ret=mid,l=mid+1;
        else r=mid-1;
    }
    return (ret+i>n)?(ret-1):ret;
}
inline int check(ll ans){
    ll nowk=0;
    for(int i=1;i<fir;i++)
        nowk+=findb(i,ans);
    for(int i=fir;i<=n;i++)
        nowk+=finda(i,ans);
    nowk/=2;
    return nowk>=k;
}
inline int cmp(int x,int y){
    return x<y;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n,cmp);
    fir=n+1;
    for(int i=1;i<=n;i++)
        if(a[i]>=0){fir=i;break;}
    for(int i=1;i<=n;i++) b[n-i+1]=a[i];
    ll l=-1e18,r=1e18,mid,ans;
    while(l<=r){
        mid=(l+r)/2;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans-1;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(){
    int a;
    cin >> a;
    int num[a];
    for(int i=0;i<a;i++){
        cin >> num[i];
    }
    for(int j=a-1;j>=0;j--){
    cout << num[j];
    if(j==0){
        cout << "\n";
        break;
    }
    cout << " ";
    }
    return 0;
}


Measured memory_bytes: 3044
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	a, _ := strconv.Atoi(stringLineScan())
	b, _ := strconv.Atoi(stringLineScan())
	ans := -1
	for i := 1; i <= 100000; i++ {
		x := i * 8 / 100
		y := i * 10 / 100
		if x == a && y == b {
			ans = i
			break
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
# ABC171 D 

import itertools

n = int(input())
a_l = [int(x) for x in input().split()]
q = int(input())

a_l.sort()
gr = itertools.groupby(a_l)
a_d = dict()
a_sum = sum(a_l)
for key, group in gr:
    a_d[key] = len(list(group))
for i in range(q):
    _b, _c = map(int, input().split())
    try:
        _b_num = a_d.pop(_b)
        a_sum = a_sum + (_c - _b) * _b_num
        try:
            _c_num = a_d[_c]
            a_d[_c] = _b_num + _c_num
        except:
            a_d[_c] = _b_num
    except:
        pass
    print(a_sum)

Measured memory_bytes: 85872
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        private static long mod = 1000000007;
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var k = int.Parse(ReadLine());
            var a = line[0];
            var b = line[1];
            var c = line[2];

            for(var i = 0; i < k; i++)
            {
                if(a >= b)
                {
                    b *= 2;
                }
                else if(b >= c)
                {
                    c *= 2;
                }
            }

            WriteLine(a < b && b < c ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 28160
#include <stdio.h>
#define maxN 300000
#define repeat(i, N, M) for(int i = N; i < M; i++)

int
main(int argc, char *argv[])
{
  int n;char s[maxN + 1]; int w[maxN] = {}, e[maxN] = {};
  scanf("%d", &n);
  scanf("%s", s);
  int k = 0;
  
  repeat(i, 1, n){
    w[i] = w[i - 1] + (s[i - 1] == 'W' ? 1 : 0);
    e[n - 1 - i] = e[n - i] + (s[n - i] == 'E' ? 1 : 0);
  }

  int ans = maxN;
  repeat(i, 0, n){
    if(w[i] + e[i] < ans){
      ans =  w[i] + e[i];
      k = i;
    }
  }
  printf("%d\n", ans);

  return 0;
}
  

Measured memory_bytes: 2816
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		int[][] h=new int[4][2];
		double[] ts={1.1, 0.6, 0.2, 0};
		for(; sc.hasNext();){
			for(int j=0; j<2; j++){
				double s=sc.nextDouble();
				for(int i=0; i<4; i++){
					if(s+EPS>ts[i]){
						h[i][j]++;
						break;
					}
				}
			}
		}
		for(int i=0; i<4; i++){
			println(h[i][0]+" "+h[i][1]);
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a,b,c,d,tmp[ohara],tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    rep(i,3)cin>>tmp[i];
    cin>>k;
    sort(tmp,tmp+3);
    ans=tmp[0]+tmp[1];
    rep(i,k)tmp[2]*=2;
    Cout(ans+tmp[2]);
    return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

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

 return 0;
}

Measured memory_bytes: 256
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;

void kohho(int n, pair<double, double> p1, pair<double, double> p2){
	if(n==0) return;
	else{
		pair<double, double> s = make_pair(((2*p1.first)+(p2.first))/3, (((2*p1.second)+(p2.second))/3));
		pair<double, double> t = make_pair(((p1.first)+(2*p2.first))/3, (((p1.second)+(2*p2.second))/3));
		pair<double, double> u = make_pair(((t.first-s.first)*cos(M_PI/3))-((t.second-s.second)*sin(M_PI/3))+s.first, ((t.first-s.first)*sin(M_PI/3))+((t.second-s.second)*cos(M_PI/3))+s.second); 
		kohho(n-1, p1, s);
		printf("%.9f %.9f\n", s.first, s.second);
		kohho(n-1, s, u);
		printf("%.9f %.9f\n", u.first, u.second);
		kohho(n-1, u, t);
		printf("%.9f %.9f\n", t.first, t.second);
		kohho(n-1, t, p2);
	}
}

int main(){
	int n;
	pair<double, double> p1, p2;
	scanf("%d", &n);
	p1 = make_pair(0, 0);
	p2 = make_pair(100, 0);
	printf("%.9f %.9f\n", p1.first, p1.second);
	kohho(n, p1, p2);
	printf("%.9f %.9f\n", p2.first, p2.second); 
}



Measured memory_bytes: 3228
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    //Airplane
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[3];
        for (int i = 0; i < 3; i++) A[i] = sc.nextInt();
        Arrays.sort(A);
        sc.close();
        System.out.println(A[0] + A[1]);
    }
}


Measured memory_bytes: 21716
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int a[MAXN];

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]); sort(a,a+n);
	int eat=0;
	for(int at=0,to=at;at<n;at=to) {
		while(to<n&&a[at]==a[to]) ++to;
		int cnt=to-at;
		//printf("%d: %d\n",a[at],cnt);
		eat+=cnt-1;
	}
	if(eat%2==1) ++eat;
	printf("%d\n",n-eat);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    int n; cin >> n;
    vector<ll> a;
    REP(i,n){
        ll t; cin >> t; a.push_back(t);
    }
    sort(a.begin(), a.end());
    auto be = a.begin();
    auto en = a.end()-1;
    ll f = *be;
    ll e = *en;
    ll ans = e - f;
    be++;
    en--;
    REP(i,n-2){
        ll fdel = max(abs(e-*be), abs(f-*be));
        ll edel = max(abs(e-*en), abs(f-*en));
        ans += max(fdel, edel);
        if(fdel>edel){
            if(abs(e-*be)>abs(f-*be)){
                e = *be;
            }else{
                f = *be;
            }
            be++;
        }else{
            if(abs(e-*en)<abs(f-*en)){
                f = *en;
            }else{
                e = *en;
            }
            en--;
        }
    }
    cout << ans << endl;


}

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

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*(w+1) for _ in range(n)]

for i in range(wv[0][0], w+1):
    dp[0][i] = wv[0][1]

for i in range(1, n):
    for j in range(w+1):
        if j-wv[i][0] < 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-wv[i][0]]+wv[i][1])
print(dp[n-1][w])


Measured memory_bytes: 120428
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
mini = float('inf')
f=0

for i in range(2**n):
    v = [0]*m
    total = 0
    flag=0
    for j in range(n):  
        if ((i >> j) & 1):
            for k in range(m):
                v[k]+=a[j][k+1]
            total += a[j][0]
    for k in range(m):
        if v[k] < x:
            flag=1
    if flag == 0 and mini > total:
        mini = total
        f=1
        
if f == 0:
    print("-1")
else :
    print(int(mini))

Measured memory_bytes: 68520
#解説参照
#「下の桁と」mod4「のみで決まる」
# 正負考慮しなくてもこれで
ans = []
n = int(input())
if n==0:
    print(0)
    exit()
while n:
    m = n%4
    if m == 0:
        ans.extend(["0","0"])
    elif m==1:
        ans.extend(["1","0"])
    elif m==2:
        ans.extend(["0","1"])
        n+=4
    else:
        ans.extend(["1","1"])
        n+=4
    n//=4
ans.reverse()
if ans[0]=="1":
    print(''.join(ans))
else:
    print(''.join(ans[1:]))



Measured memory_bytes: 38408
A, B, M = [int(_) for _ in input().split()]
a = [int(__) for __ in input().split()]
b = [int(__) for __ in input().split()]
# 一番安い金額を足しておく。
MIN = min(a) + min(b)
sum = 0
for _ in range(M):
    x, y ,c = [int(__) for __ in input().split()]
    tmp = a[x-1] + b[y-1] - c
    if tmp < MIN:
        MIN = tmp
print(MIN)

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

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

/* 採点コード
	vector<int> t(D);
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}
	vector<int> last(26, 0);

	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i+1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
		cout << v << endl;
	}
	*/

int main(void) {
	srand(time(NULL));
	int D; cin >> D;
	vector<int> c(26, 0);
	rep(i, 26)cin >> c[i];
	vector<vector<int>> s(D, vector<int>(26, 0));
	rep(i, D)rep(j, 26)cin >> s[i][j];

	vector<int> t(D, 0);
	rep(i, D) {
		rep(j, 26) {
			if (s[i][t[i]] <= s[i][j])t[i] = j;
		}
	}
	vector<int> ans = t;
	ll best = 0;

	auto start = clock();
	while (clock() - start < 1700000) {
      	rep(hoge, 5){
		    int idx = rand() % D;
		    t[idx] = rand() % 26;
        }

		//採点
		vector<int> last(26, 0);
		ll v = 0;
		rep(i, D) {
			v += s[i][t[i]];
			last[t[i]] = i + 1;
			rep(j, 26) {
				v -= c[j] * (i + 1 - last[j]);
			}
		}
		//採点

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

	for (auto x : ans) {
		cout << x + 1 << endl;
	}

	//テスト時得点確認用
	if(false){
		vector<int> last(26, 0);

		t = ans;

		int v = 0;
		rep(i, D) {
			v += s[i][t[i]];
			last[t[i]] = i + 1;
			rep(j, 26) {
				v -= c[j] * (i + 1 - last[j]);
			}
		}

		cout << v << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3708
// AOL 1580 Barter
// 2018.2.18 bal4u

#include <stdio.h>
#include <string.h>

#define BASE 300
#define DBASE 600
int dp[101][BASE+2][DBASE+2];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, x, y, a, b, c, d, i, j, k, ans;

	n = in();
	x = in(), y = in();
	memset(dp, -1, sizeof(dp));
    dp[0][0][BASE] = 0;

	for (i = 0; i < n; i++) {
		a = in(), b = in(), c = in(), d = in();
		for (j = 0; j <= BASE; j++) for (k = 0; k <= DBASE; k++) {
			if (dp[i][j][k] < 0) continue;
			if (dp[i+1][j][k] < dp[i][j][k]) dp[i+1][j][k] = dp[i][j][k];
			if (x >= j + a && dp[i+1][j+a][k-b] < dp[i][j][k]) dp[i+1][j+a][k-b] = dp[i][j][k]; 
            if (dp[i+1][j][k+c] < dp[i][j][k]+d) dp[i+1][j][k+c] = dp[i][j][k]+d;
        }
    }

    ans = 0;
	for (j = 0; j <= x; j++) for (k = 0; k <= 600; k++) {
		if (ans < dp[n][j][k] && y+BASE >= k) ans = dp[n][j][k];
	}
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 73564
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    rep(i, n) cin >> a[i];
    int cnt = 0;
    rep(i, n) {
        while(a[i] % 2 == 0) {cnt++; a[i] /= 2;}
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec l(n),r(n);
  for(ll i=0;i<n;i++) cin >> l[i] >> r[i];
  sort(l.rbegin(),l.rend());
  sort(r.begin(),r.end());
  ll ans=0;
  ll sum=0;
  for(ll i=0;i<=n/2;i++) {
    if(i) {
      sum+=2*l[i-1]+-2*r[i-1];
    }
    ans=max(ans,sum);
    if(i*2<n) {
      ans=max(ans,(sum+max(2*l[i],-2*r[i])));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4844
#include<iostream>
using namespace std;
int a[1002];
int main()
{
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=i+1;j<=n;j++)
                sum+=a[i]*a[j];
        }
        cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

bool can(int y,int x) {
	if(0 <= y && y < h && 0 <= x && x < w) return true;
	return false;
}

int cnt = 0, sy = 0, sx = 0;
bool used[10][10];
vector< vector<int> > v;

void rec(int y, int x) {
	used[y][x] = true;
	cnt++;

	rep(i, 4) {
		int ny = y + dy[i];
		int nx = x + dx[i];

		if(can(ny, nx) && !used[ny][nx] && v[ny][nx] == c) {
			rec(ny, nx);
		}
	}
}

int target, change;

void dfs(int y, int x) {
	v[y][x] = change;
	rep(i, 4) {
		int ny = y + dy[i];
		int nx = x + dx[i];

		if(can(ny, nx) && v[ny][nx] == target) {
			dfs(ny, nx);
		}
	}
}

int ans = 0;
void func(vector< vector<int> > t, int id) {
	// cout << " ------ func ---- :" << id << endl;
	// rep(i, h) {
	// 	rep(j, w) cout << t[i][j] << " ";
	// 	cout << endl;
	// }
	if(id == 4) {
		v = t;
		target = t[sy][sx];

		if(target == c) return;
		change = c;
		dfs(sy, sx);

		cnt = 0;
		memset(used, 0, sizeof(used));
		rec(sy, sx);
		ans = max(ans, cnt);
		return;
	}

	REP(i, 1, 7) {
		if(i == t[sy][sx]) continue;
		v = t;
		target = t[sy][sx]; change = i;
		dfs(sy, sx);
		func(v, id + 1);
	}
}

int main() {
	while(cin >> h >> w >> c) {
		if(h == 0 && w == 0 && c == 0) break;

		v.resize(h);
		rep(i, h) {
			v[i].resize(w);
			rep(j, w) cin >> v[i][j];
		}

		ans = 0;
		func(v, 0);

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

Measured memory_bytes: 1228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                List<string> s = new List<string>();
                string num = "";

                for (int i = 0; i < input.Length; i++)
                {
                    if (input[i] >= '0' && input[i] <= '9')
                    {
                        num += input[i];
                    }
                    else if (input[i] == 'X')
                    {
                        num += input[i];
                    }
                    else if (input[i] == '+' || input[i] == '=')
                    {
                        s.Add(num);
                        num = "";
                    }
                }

                string res = "";

                for (int i = 0; i <= 9; i++)
                {
                    string s1 = s[0].Replace("X", i.ToString());
                    string s2 = s[1].Replace("X", i.ToString());
                    string ans = num.Replace("X", i.ToString());

                    string sum = SumString(s1, s2);

                    if (sum == ans)
                    {
                        res = i.ToString();
                        break;
                    }
                }

                if (res == "") sb.AppendLine("NA");
                else sb.AppendLine(res);
            }
            Console.Write(sb);
        }

        static string SumString(string s1, string s2)
        {
            int len = Math.Max(s1.Length, s2.Length);

            int[] nums1 = MakeArray(s1, len);
            int[] nums2 = MakeArray(s2, len);
            int[] sum = new int[len + 1];

            for (int i = 0; i < len; i++)
            {
                int temp = nums1[i] + nums2[i] + sum[i];

                if (temp >= 10)
                {
                    sum[i + 1] = 1;
                    sum[i] = temp % 10;
                }
                else
                {
                    sum[i] = temp;
                }
            }

            string ret = "";
            if (sum[len] != 0) ret += sum[len];

            for (int i = len - 1; i >= 0; i--)
            {
                ret += sum[i];
            }
            return ret;
        }

        static int[] MakeArray(string s, int len)
        {
            int[] ret = new int[len];

            for (int i = s.Length - 1, j = 0; i >= 0; i--, j++)
            {
                ret[j] = int.Parse(s[i].ToString());
            }
            return ret;
        }
    }
}

Measured memory_bytes: 9296
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    string m = "01235789";
    for(int n;cin>>n,n;){
        string res = "";
        while(n){
            res.append(1, m[n%8]);
            n/=8;
        }
        reverse(res.begin(), res.end());
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
// abc163_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

#define _USE_MATH_DEFINES

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    double R;
    cin >> R;
    double ans = 2 * M_PI * R;
    print(ans);

    return 0;
}


Measured memory_bytes: 3776
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;
int main(){
  string s; cin>>s;
  int n=s.length();
  long long k; cin>>k;
  int i=0;
    while(s[i]=='1' && i<n){

     if(i==k-1) {cout<<1<<endl; return 0;}
     i++;
    }
    cout<<s[i]<<endl;


}


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

int main() {
	double l;
	cin >> l;
	std::cout<<std::fixed<<std::setprecision(10)<<(l * l * l) / 27 << endl;
	return 0;
}


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

int dp[100005], vet[100005];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++) scanf("%d", &vet[i]);
	memset(dp, 0x3f3f3f3f, sizeof dp);
	dp[(n-1)] = 0;
	for (int i=n-2; i>=0; i--){
		dp[i] = min(dp[i], dp[i+1] + abs(vet[i]-vet[i+1]));
		if(i+2 < n) dp[i] = min(dp[i], dp[i+2] + abs(vet[i]-vet[i+2]));
		//cout << i << ' ' << dp[i] << endl;
	}
	printf("%d\n", dp[0]);
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)

    n := nextInt()

    total := 0

    for i := 1; i <= n; i++ {
        if !(i%3==0 || i%5==0) {
            total += i
        }
    }

    fmt.Println(total)
}

// Library

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 1760
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(N);
    if (N%2==0)
    {
        ll ans1=N/2;
        N=N/2;
        ll x=N;
        while (x>0)
        {
            ans1+=x/2;
            x=x/2;
        }
        x=N;
        ll ans2=0;
        while (x>0)
        {
            ans2+=x/5;
            x=x/5;
        }
        cout<<min(ans1,ans2)<<endl;
        
    }
    else
    {
        cout<<0<<endl;
    }
    
    

    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Right Triangle
            var line = ReadLine();

            var edges = line.OrderBy(x => x).ToList();
            int edge1 = edges[0];
            int edge2 = edges[1];

            Console.WriteLine(edge1 * edge2 / 2);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');
            var numbers = new List<int>();

            foreach (var s in array)
            {
                int num = int.Parse(s);
                numbers.Add(num);
            }

            return numbers;
        }
    }
}

Measured memory_bytes: 13396