akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = 998244353ll;

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n,bitree[225816],c[225816][4];
vector<int> y;
vector<P> s;

int query(int p){
	int v=0;
	while(p){
		v += bitree[p];
		p -= (p&(-p));
	}
	return v;
}

void update(int p, int v){
	while(p<=n){
		bitree[p] += v;
		p += (p&-p);
	}
}

ll rwpw(ll a, int p){
	ll ret = 1ll;
	while(p){
		if(p&1){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p >>= 1;
	}
	return ret;
}

int main(void){
	int i,xi,yi,j,k;
	ll ans=0ll,tmp;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> xi >> yi;
		s.push_back(P(xi,yi));
		y.push_back(yi);
	}
	sort(s.begin(),s.end());
	sort(y.begin(),y.end());
	for(i=0; i<n; ++i){
		yi = (int)(lower_bound(y.begin(),y.end(),s[i].second)-y.begin());
		c[i][2] = query(yi+1);
		c[i][1] = i-c[i][2];
		update(yi+1,1);
	}
	fill(bitree,bitree+225816,0);
	for(i=n; i>0; --i){
		yi = (int)(lower_bound(y.begin(),y.end(),s[i-1].second)-y.begin());
		c[i-1][3] = query(yi+1);
		c[i-1][0] = (n-i)-c[i-1][3];
		update(yi+1,1);
	}
	for(i=0; i<n; ++i){
		add_mod(ans,rwpw(2ll,n-1));
		for(j=0; j<16; ++j){
			tmp = 1ll;
			if(!((j&3) && (j&12) && (j&6) && (j&9))){
				continue;
			}
			for(k=0; k<4; ++k){
				if(j&(1<<k)){
					mul_mod(tmp,(MOD-1+rwpw(2ll,c[i][k]))%MOD);
				}	
			}
			add_mod(ans,tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int N, X, T;
    cin >> N >> X >> T;
    
    int hui = N / X;
    if(N % X != 0) hui++;

    cout << hui * T << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}

int main() {
	int n,ans = 1;
	cin >> n;
	vi d(n);
	repz(i, n)cin >> d[i];
	sort(d.begin(), d.end());
	for (int i = 1; i < n;i++) {
		if (d[i] != d[i-1]) ans++;
	}
	
	cout << ans << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> map(100100,0);

    rep(i,n){
        cin >> a[i]; a[i]++;
        map[a[i]-1]++;
        map[a[i]]++;
        map[a[i]+1]++;
    }

    int ans = 0;

    rep(i,100100){
        ans = max(ans,map[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#E 復習
N = int(input())
K = int(input())

from functools import lru_cache

@lru_cache(None)
def f(n, K):
    if n <= 10:
        if K == 0:
            return 1
        if K == 1:
            return n
        return 0
    div_n = n//10
    mod_n = n%10
    ans = 0
    if K >= 1:
        ans += f(div_n, K-1) * mod_n
        ans += f(div_n-1, K-1) * (9 - mod_n)
    ans += f(div_n, K)
    return ans

print(f(N, K))

Measured memory_bytes: 3940
# As = list(map(int, input().split()))
# print(As,sum(As))
# n = len(As)
# for i in range(n):
#     for j in range(i+1,n):
#         for k in range(j+1,n):
#             a = As[i]+As[j]+As[k]
#             print(sum(As)-a)
N = int(input())
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]
ps = getprime(55555)
l = []
for p in ps:
    if p % 5 == 1:
        l.append(p)
ans = l[:N]
print(*ans)

Measured memory_bytes: 5528
// AtCoder ABC140: C - 
// 2019.9.7 bal4u

#include <stdio.h>

#if 1
int getchar_unlocked(void);
int putchar_unlocked(int c);
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {  // 整数の入力
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 整数の表示
	int i; char b[30];

	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}


#define MIN(a, b) ((a)<=(b)?(a):(b))
int B[105]; int N;

int main()
{
	int i, ans;
	
	N = in(); for (i = 1; i < N; i++) B[i] = in();
	ans = B[1];
	for (i = 2; i < N; i++) ans += MIN(B[i-1], B[i]);
	ans += B[N-1];
	out(ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long llu;
typedef long long ll;
typedef unordered_map<llu,llu>mymap;
typedef unordered_set<llu >myset;
#define endl '\n'

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	llu n;
	cin>>n;
	llu last_digit=n%10;
	if(last_digit==2||last_digit==4||last_digit==5||last_digit==7||last_digit==9){cout<<"hon";}
	else if(last_digit==0||last_digit==1||last_digit==6||last_digit==8){cout<<"pon";}
	else{cout<<"bon";}

	 
	//cout<<max_consecutive(arr,n);
	return 0;
	}
	


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    string s,t; cin >> s >>t;
    string ans = "";
    REP(i,n) {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }

    cout << ans << '\n';

    return 0;
}

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

int main(){
    int id;
    double weight;
    double height;

    while(scanf("%d,%lf,%lf", &id, &weight, &height) != EOF){
        double bmi = weight / (height * height);
        if(bmi >= 25.0){
            cout << id << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <array>

typedef struct {
    int point1;
    int point2;
    int cost;
} way;

int main()
{
    int number_point, number_edge;
    int start_point;
    std::cin >> number_point >> number_edge >> start_point;//?????????????????°??¨?§???????????????????

    //?§????????????????????????????
    const int BIGNUMBER = 1001001001;
    int *shortest_way = new int[number_point];

    for (int i = 0; i < number_point; i++) {
        shortest_way[i] = BIGNUMBER;//??§???????????§?????????
    }
    shortest_way[start_point] = 0;//???????????´??????????§????????????????0

    //?§?????????????????´?????????????????????£???????????????????????????
    way *way_data = new way[number_edge];
    for (int i = 0; i < number_edge; i++) {
        std::cin >> (way_data[i]).point1 >> (way_data[i]).point2 >> (way_data[i]).cost;
    }
   
   //????????????????°?????????´??°??????
    while(true) {
        bool changed = false;
        for (int i = 0; i < number_edge; i++) {
            //?????????point1????????±????????????????????£??????????????±??????
            if (shortest_way[(way_data[i]).point2] > shortest_way[(way_data[i]).point1] + (way_data[i]).cost) {
                shortest_way[(way_data[i]).point2] = shortest_way[(way_data[i]).point1] + (way_data[i]).cost;
                changed = true;
            }
        }
        
        //??????for??§???????????????????????????????????????????????????????????????????????£??????,?????????????????????
        if (!changed) {
            break;
        }
    }
    
    for(int i = 0; i < number_point; i++) {
        if (shortest_way[i] == BIGNUMBER) {
            std::cout << "INF" << std::endl;
        } else {
            std::cout << shortest_way[i] << std::endl;
        }
    }
    
    delete[] shortest_way;
    delete[] way_data;
    
    return 0;
}

Measured memory_bytes: 8888
#include<stdio.h>
int main()
{
int a,x,i,start,end;
  scanf("%d %d",&a,&x);
  start=x-a+1;
  end=a+x;
if(x-a<-1000000) start=-1000000;
else if(x+a >= 1000000) end=1000001;

for(i=start;i<end;++i) {printf("%d ",i);}
  
return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int main() {
    int X;
    cin >> X;
    cout << Yes(X >= 30) << endl;
}

Measured memory_bytes: 3548
n = int(input())
data = list(map(int, input().split()))
line = list(range(1, n+1))

cnt = 0
not_matches = []
for i, j in zip(data, line):
  if i != j:
    cnt += 1
    not_matches.append(i)
    not_matches.append(j)
  if cnt >= 3:
    print('NO')
    break
else:
  if len(not_matches) == 0:
    print('YES')
  elif not_matches[0] == not_matches[3] and not_matches[1] == not_matches[2]:
    print('YES')
  else:
    print('NO')


Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<string>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<numeric>
//--------------------
#define MOD 1000000007 
using namespace std;
//--------------------
int main(){

	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	int x3, y3, x4, y4;
	
	x3 = x2 + y1 - y2;
	y3 = y2 + x2 - x1;
	x4 = x3 + y2 - y3;
	y4 = y3 + x3 - x2;

	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

}

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

int main(){
	string w,t;
	int i,count=0;
	cin >> w;
	while(1){
		cin >> t;
		if(t=="END_OF_TEXT"){
			break;
		}
		for(i=0;i<t.length();i++){
			t[i]=tolower(t[i]);
		}
		if(t==w){
			count++;
		}
	}
	cout << count << endl;
	return 0;
	
}

Measured memory_bytes: 3216
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

data = np.fromstring(read(), np.int64, sep=' ')

N, K  = data[:2]
P = data[2:] + 1

Pcum = np.zeros(N + 1, np.int64)
Pcum[1:] = P.cumsum()

x = Pcum[K:] - Pcum[0:-K]
print(x.max() / 2)

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

int N, A, x[60];

int main() {
	cin >> N >> A;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	long long dp[60][60][2510];
	memset(dp, 0, sizeof dp);
	dp[0][0][0] = 1;
	for (int j = 0; j < N; j++) {
		for (int k = 0; k < N; k++) {
			for (int s = 0; s <= 2500; s++) {
				dp[j + 1][k][s] += dp[j][k][s];
				dp[j + 1][k + 1][s + x[j]] += dp[j][k][s];
			}
		}
	}
	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += dp[N][i][i*A];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
(defun count-abc ()
  (let ((n (read))
        (s (read-line))
        (ans 0)) 
    (setf s (concatenate 'string s "  ")) 
    (dotimes (i n) 
      (if (equal "ABC" (subseq s i (+ i 3)))
          (incf ans)))
    ans)) 

(format t "~D~%" (count-abc)) 


Measured memory_bytes: 13412
//B - Thin: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int h, w;
    string s;
    cin >> h >> w;
    while(h--) {
        cin >> s;
        cout << s << "\n";
        cout << s << "\n";
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N, K;

int main() {
  cin >> N >> K;

  ll ans = 0;
  repe(b, K + 1, N) {
    ans += N / b * (b - K);
    int rem = N % b;
    if (rem >= K) {
      ans += rem - max(K - 1, 0);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
// vector<int> fac; //precompute fac array
// fac.resize(n+1);
// fac[0] = 1; 
// for (int i=1; i<=n; i++)   fac[i] = m(m(fac[i-1])*m(i));
// int modInverse(int n){ 
// return p(n, MOD-2); 
// }  
// int nCr(int n, int r){   
//     if(r == 0)  return 1; 
//     return m(m(m(fac[n])*m(modInverse(fac[r])))*m(modInverse(fac[n-r]))); 
// } 
signed main(){
    fast();
    int n;
    cin >> n;
    int ans = 0;
    n == 1? ans = 0: ans = 1;
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3604
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


class SegmentTree:
    def __init__(self, N, func, I):
        self.N = N
        self.sz = 2**(N-1).bit_length()
        self.func = func
        self.I = I
        self.seg = [I] * (self.sz * 2)

    def assign(self, k, x):
        self.seg[k + self.sz] = x

    def build(self):
        for i in reversed(range(1, self.sz)):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        if b == self.N:
            b = self.sz
        b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    N = int(readline())
    L = map(int, readline().split())
    seg = SegmentTree(N, gcd, 0)
    for i, n in enumerate(L):
        seg.assign(i, n)
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans, gcd(seg.query(0, i), seg.query(i+1, N)))
    print(ans)


main()


Measured memory_bytes: 60528
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(){
  ll n;
  cin >> n;

  vector<ll> a(n, 0);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

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

  vector<pair<ll, ll>> lists;
  ll cnt = 1;
  for(int i = 1; i < n; i++){
    if(a[i] == a[i-1]){
      cnt++;
    }else{
      lists.push_back(make_pair(a[i-1], cnt));
      cnt = 1;
    }
  }

  lists.push_back(make_pair(a[n-1], cnt));

  ll ans = 0;
  for(int i = 0; i < lists.size(); i++){
    if(lists[i].second < lists[i].first){
      ans += lists[i].second;
    }else{
      ans += lists[i].second - lists[i].first; 
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
    int n;
    cin>>n;
    int arr[n],dp[n];
    for(int i=0;i<n;++i)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;++i)
    {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <bitset>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()

bool f(int n) {
  n &= n - 1;
  return n == 0;
}

vector<int> gray(int n) {
  vector<int> res(1 << n);
  for (int i = 0; i < 1 << n; i++) {
    res[i] = i ^ (i >> 1);
  }
  auto it = find(res.begin(), res.end(), 0);
  rotate(res.begin(), it, res.end());
  return res;
}

int popcnt(int x) {
  int res = 0;
  while (x > 0) {
    res++;
    x &= x - 1;
  }
  return res;
}

int rev(int x, int n) {
  int res = 0;
  for (int i = 0; i < n; i++) {
    res ^= (x >> i & 1) << (n - 1 - i);
  }
  return res;
}

vector<int> tomato(int n) {
  if (n == 1) return {0, 1};
  vector<int> g = gray(n - 2);
  vector<int> res;
  int x = 1 << n - 2;
  int y = 1 << n - 1;
  for (int i = 0; i < g.size(); i++) res.push_back(g[i]);
  for (int i = g.size() - 1; i >= 0; i--) res.push_back(g[i] ^ x);
  res.push_back(x ^ y);
  for (int i = 0; i < g.size(); i++) res.push_back(g[i] ^ y);
  auto f = tomato(n - 2);
  for (int i = 1; i < f.size(); i++) {
    res.push_back(rev(f[i], n - 2) ^ x ^ y);
  }
  return res;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int M = 1 << N;
  vector<int> p0;
  vector<int> p1;
  for (int i = 0; i < N; i++) {
    if ((A ^ B) >> i & 1) {
      p1.push_back(i);
    } else {
      p0.push_back(i);
    }
  }
  if (p1.size() % 2 == 1) {
    auto to = tomato(p1.size());
    cout << "YES" << endl;
    auto g = gray(p0.size());
    auto F0 = [&](int l) {
      for (int i = 0; i < g.size(); i++) {
        int a = A;
        for (int j = 0; j < p0.size(); j++) {
          int x = g[i] >> j & 1;
          a ^= x << p0[j];
        }
        for (int j = 0; j < p1.size(); j++) {
          int x = to[l] >> j & 1;
          a ^= x << p1[j];
        }
        cout << a << ' ';
      }
    };
    auto F1 = [&](int l) {
      for (int i = g.size() - 1; i >= 0; i--) {
        int a = A;
        for (int j = 0; j < p0.size(); j++) {
          int x = g[i] >> j & 1;
          a ^= x << p0[j];
        }
        for (int j = 0; j < p1.size(); j++) {
          int x = to[l] >> j & 1;
          a ^= x << p1[j];
        }
        cout << a << ' ';
      }
    };
    // 000
    // 001
    // 011
    // 010
    // 110
    // 100
    // 101
    // 111
    for (int i = 0; i < to.size(); i++) {
      if (i % 2 == 0) F0(i);
      else F1(i);
    }
    cout << endl;
  } else { 
    cout << "NO" << endl;
  }
}

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

using Graph = vector<vector<int>>;

int main() {
    int N, M; cin >> N >> M;
    Graph G(N+1);
    for(int i=1; i<M+1; i++){
        int a, b;
        cin >> a >> b;
        G.at(a).push_back(b);
        G.at(b).push_back(a);
    }

    vector<int> v(N+1,0);
    for(int i=0; i<N; i++){
        v.at(i) = i+1;
    }

    int cnt = 0;
    bool nextfg = false;
    do{
        int tmp = 0;
        if(v.at(0) != 1) break;
        for(int i=0; i<N; i++){
            for(int j=0; j<G.at(v.at(i)).size(); j++){
                if(G.at(v.at(i)).at(j) == v.at(i+1)){
                    tmp++;
                    break;
                }
                else if(j == G.at(v.at(i)).size() - 1){
                    nextfg = true;
                }
            }
            if(nextfg){
                nextfg = false;
                break;
            }
        }

        if(tmp == N-1) cnt++;
    }while(next_permutation(v.begin(),v.end())); // Please sort vector.

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    ll res=0;
    
    int prev_max=-1;
    for (int i=0; i<n; i++) {
        if (a[i]<prev_max) {
            res+=prev_max-a[i];
        }
        prev_max=max(prev_max, a[i]);
    }

    cout << res << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 3992
using System;
using System.Linq;
public class Program {
  public static void Main() {
    int mountCount = 10;
    int outputCount = 3;
    int[] mountains = new int[mountCount];
    for (int i = 0; i < mountCount; i++) {
      mountains[i] = int.Parse(Console.ReadLine());
    }
    mountains = mountains.OrderByDescending(x => x).ToArray();
    for (int i = 0; i < outputCount; i++) {
      Console.WriteLine(mountains[i]);
    }
  }
}

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

#define pb push_back
#define ff first
#define ss second

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

int n, ans = 1e9;

int ted(int x) {
	int res = 0;
	while (x)
		res += x % 10, x /= 10;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i ^ n; i++)
		ans = min(ans, ted(i) + ted(n - i));
	cout << ans << endl;
	return 0;
}


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

import math
import sys
import heapq
from operator import itemgetter
import itertools
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

N = int(input().rstrip())
if N == 1:
	print("Hello World")
else:
	print(int(input().rstrip()) + int(input().rstrip()))

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

using ll = long long int;

const int MAX_N = (int)(2e5 + 5);

int n;
ll t;
ll period[MAX_N];

ll ans;

int main(void){
  scanf("%d %lld", &n, &t);

  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &(period[i]));
  }

  for (int i = 2; i <= n; ++i) {
    if (period[i - 1] + t > period[i]) ans += (period[i] - period[i - 1]);
    else ans += t;
  }

  ans += t;

  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1792
def main():
    # n行分・m列分ボタンを押すと
    # n(M - m) + m(N - n) = nM + Nm - 2mn マスが黒くなる
    N, M, K = map(int, input().split())
    for n in range(N + 1):
        for m in range(M + 1):
            black = n * (M - m) + (N - n) * m
            if black == K:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9136
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <algorithm>
#include <utility>
#define INF INT_MAX / 2
using namespace std;

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

int main(void) {
	string s1 = "qwertasdfgzxcvb";
	string s2 = "yuiophjklnm";


	string s;
	while(cin >> s,s!="#"){
	bool l = false;
	if(s1.find(s[0]) != string::npos)l=true;
	int cnt = 0;
	for(int i=0;i<s.size();i++){
		if(s1.find(s[i]) != string::npos){
			if(!l)cnt++;
			l = true;
		}else{
			if(l)cnt++;
			l = false;
		}
	}
	cout << cnt << endl;
}
}

// command shift d duplicate
// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));

Measured memory_bytes: 1192
import math
def primes(x):
    x+=1
    if x < 2:
        return []

    prime = [i for i in range(x)]
    prime[1] = 0

    for p in prime:
        if p > math.sqrt(x):
            break
        if p == 0:
            continue
        for non_prime in range(2 * p, x, p):
            prime[non_prime] = 0

    return [p for p in prime if p != 0]


x = int(input())

p = primes(10**6)

for y in p:
    if x<=y:
        print(y)
        exit()

Measured memory_bytes: 114544
#include <stdio.h>
#include <string.h>

int main (){
	char s[12];
	scanf("%s", s);
	char ans[12];
	int len = strlen(s), idxans = 0;
	
	for (int i = 0; s[i] != '\0'; i++){
		if(s[i] == '0' || s[i] == '1'){
			ans[idxans] = s[i];
			idxans++;
		}else if(idxans > 0){
			if(s[i] == 'B'){
				ans[idxans-1] = '\0';
				idxans -= 2;
			}
			idxans++;			
		}
	}
	ans[idxans] = '\0';
	printf("%s\n", ans);

	return 0;
}


Measured memory_bytes: 1592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long m = Long.parseLong(sc.next());
        long n = Long.parseLong(sc.next());
    
        System.out.println(pow(m, n, 1000000007));
    }
    
    static long pow(long x, long n, long M){
        if(n == 0) return 1;
        long res = pow(x * x % M, n/2, M);
        if(n%2 == 1) res = res * x % M;
        return res;
    }
}


Measured memory_bytes: 26216
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int n,m,q;
int dp[11][100001];
int d[100001],c[100001],v[100001];
vector<int> G[100001];

void f(int ver,int dist,int color){
  //printf("%d %d %d\n",ver,dist,color);
  if(dist<0)return ;
  if(dp[dist][ver]!=0)return ;
  
  dp[dist][ver]=color;
  
  f(ver,dist-1,color);
  for(int i=0;i<G[ver].size();i++){
    int u=G[ver][i];
    f(u,dist-1,color);
  }
}

int main(){
  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }
  for(int i=q-1;i>=0;i--){
    f(v[i],d[i],c[i]);
  }
  for(int i=0;i<n;i++)cout << dp[0][i] << endl;
  
  return 0;
}


Measured memory_bytes: 12024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            int[] v = {a, b, a + b};
            for (int x : v) {
                if (x % 3 == 0) {
                    out.println("Possible");
                    return;
                }
            }
            out.println("Impossible");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21588
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (register int i = (a); i <= (b); ++i)
#define per(i, a, b) for (register int i = (a); i >= (b); --i)
#define loop(it, v) for (auto it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (register int i = head[x]; i; i = edge[i].nex)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, cnt) memset(a, cnt, sizeof(a))
#define cop(a, b) memcpy(a, b, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define SC(t, x) static_cast <t> (x)
#define ub upper_bound
#define lb lower_bound
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fi first
#define se second
#define y1 y1_
#define Pi acos(-1.0)
#define iv inline void
#define enter putchar('\n')
#define siz(x) ((int)x.size())
#define file(x) freopen(x".in", "r", stdin),freopen(x".out", "w", stdout)
typedef double db ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int maxn = 1e6 + 100 ;
const int inf = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const ll mod = 1e9 + 7 ;
const double eps = 1e-5 ;

ll n, s;

ll x[maxn], p[maxn];

ll ans[maxn], tim;

signed main()
{
	scanf("%lld %lld", &n, &s);
	rep(i, 1, n) scanf("%lld %lld", &x[i], &p[i]);
	ll l = 1, r = n;
	rep(i, 1, n)
	{
		if(x[r] < s) ans[i] = x[l], p[r] += p[l ++];
		else if(x[l] > s) ans[i] = x[r], p[l] += p[r --];
		else
		{
			if(p[l] < p[r]) ans[i] = x[l], p[r] += p[l ++];
			else ans[i] = x[r], p[l] += p[r --];
		}
	}
	per(i, n, 1) tim += abs(s - ans[i]), s = ans[i];
	printf("%lld\n", tim);
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int64_t const inf = 1LL<<50;

template<class T> using PQ_G = priority_queue<T, vector<T>, greater<T>>;

int N, M, S, T;
vector<vector<pair<int, int64_t>>> gyen;
vector<vector<pair<int, int64_t>>> gsnk;

vector<int64_t> dijkstra(vector<vector<pair<int, int64_t>>> const& g, int st) {
  PQ_G<tuple<int64_t, int>> pq;
  pq.emplace(0, st);
  vector<int64_t> dist(N, inf);
  dist[st] = 0;
  while (!pq.empty()) {
    int64_t cost; int pos; tie(cost, pos) = pq.top(); pq.pop();
    rep(i, g[pos].size()) {
      int to = g[pos][i].first;
      int64_t ncost = cost + g[pos][i].second;
      if (dist[to] <= ncost) continue;
      dist[to] = ncost;
      pq.emplace(ncost, to);
    }
  }
  return dist;
}

int main() {
  cin >> N >> M >> S >> T; S--, T--;
  gyen.resize(N), gsnk.resize(N);
  rep(i, M) {
    int u, v, a, b; cin >> u >> v >> a >> b;
    u--, v--;
    gyen[u].emplace_back(v, a);
    gsnk[u].emplace_back(v, b);
    gyen[v].emplace_back(u, a);
    gsnk[v].emplace_back(u, b);
  }
  auto dyen = dijkstra(gyen, S);
  auto dsnk = dijkstra(gsnk, T);
  vector<int64_t> ans(N);
  ans[N - 1] = inf;
  for (int i = N - 1; i >= 0; i--) {
    minimize(ans[i], dyen[i] + dsnk[i]);
    if (i > 0) {
      ans[i - 1] = ans[i];
    }
  }
  rep(i, N) {
    cout << (int64_t)1e15 - ans[i] << "\n";
  }
}


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



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

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

    return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = 0
ans = N%10

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

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

using namespace std;

int main(){
  
  long long n;
  cin>>n;
  
  long long a[n],b[n],c[n];
  
  for(long long i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
  long long dpa[n-1],dpb[n-1],dpc[n-1];
  dpa[0]=a[0];dpb[0]=b[0];dpc[0]=c[0];
  for(long long i=0;i<n;i++) dpa[i+1]=a[i+1]+max(dpb[i],dpc[i]),dpb[i+1]=b[i+1]+max(dpa[i],dpc[i]),dpc[i+1]=c[i+1]+max(dpa[i],dpb[i]);

  cout<<max(dpa[n-1],max(dpb[n-1],dpc[n-1]))<<endl;
  
 return 0; 
}

Measured memory_bytes: 4992
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> as;
    for (ll i = 0; i < n; ++i)
    {
        ll a;
        cin >> a;
        as.push_back(a);
    }
    vector<ll> destinations;
    destinations.push_back(1);
    ll nowAt = 1;
    vector<bool> alreadies(n + 1, false);
    ll in_length;
    ll loop_length;
    while (true)
    {
        ll dest = as[nowAt - 1];
        if (alreadies[dest] == true)
        {
            auto itr = find(destinations.begin(), destinations.end(), dest);
            ll back_to_destinations_index = distance(destinations.begin(), itr);
            in_length = back_to_destinations_index;
            loop_length = destinations.size() - in_length;
            break;
        }
        else
        {
            alreadies[dest] = true;
            destinations.push_back(dest);
            nowAt = dest;
        }
    }
    if (k <= in_length)
    {
        cout << destinations[k] << endl;
    }
    else
    {
        cout << destinations[in_length + (k - in_length) % loop_length] << endl;
    }
}

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

using namespace std;

int a[105];

int main()
{
          int n;
          cin>>n;
          n+=n;
          for(int i=0;i<n;i++)
                    cin>>a[i];
          sort(a,a+n);
          int ans=0;
          for(int i=0;i<n;i+=2)
                    ans+=a[i];
          cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void){
  int i, n;
  double xa, ya, ra, xb, yb, rb;
  double l;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%lf%lf%lf%lf%lf%lf", &xa, &ya, &ra, &xb, &yb, &rb);
    l = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
    if(ra+rb < l){
      printf("0\n");
    }else if(l+rb < ra){
      printf("2\n");
    }else if(l+ra < rb){
      printf("-2\n");
    }else{
      printf("1\n");
    }
  }

  return 0;
}

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

int main(){
    int n;
    cin>>n;
    int arr[n];

    vector<pair<int, int> > v;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        v.push_back(make_pair(arr[i], i+1));
    }

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

    for(int i=0; i<n; i++){
        cout<<v[i].second<<" ";
    }
    cout<<endl;

}


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

// lib/insert_or_assign.hpp
#ifndef INSERT_OR_ASSIGN_HPP
#define INSERT_OR_ASSIGN_HPP


namespace tools {
  template<typename Map, typename T>
  std::pair<typename Map::iterator, bool> insert_or_assign(Map& map, const typename Map::key_type& key, const T& value) {
    std::pair<typename Map::iterator, bool> pair = map.insert(std::make_pair(key, value));
    if (!pair.second) pair.first->second = value;
    return pair;
  }
}

#endif

// main.cpp

int main() {
  std::int_fast64_t n, c;
  std::cin >> n >> c;

  std::vector<std::unordered_map<std::int_fast64_t, std::int_fast64_t>> s_to_t(c);
  std::vector<std::unordered_map<std::int_fast64_t, std::int_fast64_t>> t_to_s(c);
  for (std::int_fast64_t i = 0; i < n; ++i) {
    std::int_fast64_t s_i, t_i, c_i;
    std::cin >> s_i >> t_i >> c_i;
    std::unordered_map<std::int_fast64_t, std::int_fast64_t>& s2t = s_to_t[c_i - 1];
    std::unordered_map<std::int_fast64_t, std::int_fast64_t>& t2s = t_to_s[c_i - 1];
    tools::insert_or_assign(s2t, s_i, t_i);
    tools::insert_or_assign(t2s, t_i, s_i);
    {
      const auto it = t2s.find(s_i);
      if (it != t2s.end()) {
        const std::int_fast64_t center = s_i;
        s_i = it->second;
        s2t.erase(center);
        t2s.erase(center);
        tools::insert_or_assign(s2t, s_i, t_i);
        tools::insert_or_assign(t2s, t_i, s_i);
      }
    }
    {
      const auto it = s2t.find(t_i);
      if (it != s2t.end()) {
        const std::int_fast64_t center = t_i;
        t_i = it->second;
        s2t.erase(center);
        t2s.erase(center);
        tools::insert_or_assign(s2t, s_i, t_i);
        tools::insert_or_assign(t2s, t_i, s_i);
      }
    }
  }

  std::array<std::int_fast64_t, 100000> imos = {0};
  for (const std::unordered_map<std::int_fast64_t, std::int_fast64_t>& s2t : s_to_t) {
    for (const std::pair<std::int_fast64_t, std::int_fast64_t>& st_pair : s2t) {
      ++imos[st_pair.first - 1];
      --imos[st_pair.second];
    }
  }

  std::int_fast64_t answer = 0;
  std::int_fast64_t current_value = 0;
  for (const std::int_fast64_t& diff : imos) {
    current_value += diff;
    answer = std::max(answer, current_value);
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>

int main(){
  int k,s,x,y,z,result=0;
  
  scanf("%d %d",&k,&s);
  
  for(x=0;x<=k;x++){
    for(y=0;y<=k;y++){
      if(0<=s-(x+y) && s-(x+y)<=k){
        result++;
      }
    }
  }
  
  printf("%d",result);
}

Measured memory_bytes: 128
import fractions

def read():
    A, B = map(int, input().strip().split())
    return A, B

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def solve(A, B):
    gcd = fractions.gcd(A, B)
    divisors = sorted(make_divisors(gcd))
    table = [True] * len(divisors)
    for i in range(1, len(divisors)):
        for j in range(i+1, len(divisors)):
            if table[j] and divisors[j] % divisors[i] == 0:
                table[j] = False
    divisors = [divisors[i] for i in range(len(divisors)) if table[i]]
    return len(divisors)

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


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

using namespace std;

int main() {
	int d;
	while (cin >> d) {
		int sum = 0;
		for (int i = 1; i * d < 600; ++i) {
			sum += (i * d) * (i * d) * d;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,K,R,S,P;
  cin>>N>>K>>R>>S>>P;
  string T;
  cin>>T;
  VS X(K);
  rep(i,K){
    string SS;
    int tmp=i;
    rep(j,1000000){
      if(tmp>N-1) break;
      SS+=T[i+K*j];
      tmp+=K;
    }
    X[i]=SS;
  }
  ll ans=0;
  rep(i,K){
    int cnt=1;
    rep(j,X[i].size()-1){
      if(X[i][j+1]!=X[i][j]){
        int Q;
        if(T[i+j*K]=='r') Q=P;
        else if(T[i+j*K]=='s') Q=R;
        else Q=S;
        ans+=(cnt+1)/2*Q;
        cnt=1;
      }else cnt++;
    }
    int Q;
    if(T[i+(X[i].size()-1)*K]=='r') Q=P;
    else if(T[i+(X[i].size()-1)*K]=='s') Q=R;
    else Q=S;
    ans+=(cnt+1)/2*Q;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5120
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, ans;
int64 s[N];
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) s[i] = read();
    sort(s+1, s+1+n);
    for(int i = 1; i <= n; ++i) s[i] += s[i-1];
    for(int i = n; i&&s[i]*2 >= s[i+1]-s[i]; --i, ++ans);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {



    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();


        if (((a<c)&(c<b))||((c<a)&(b<c))) System.out.println("Yes");
        else System.out.println("No");
    }
}



Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define evn(x) (!((x)&1))
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
using namespace std;

int n;
bool vis[MAX];
vector<int> gp[MAX];
int dist[MAX];

void connect(int a, int b)	{
	gp[a].push_back(b);
}

void bfs(int a)	{
	//if(vis[a])	return;
	vis[a]=1;
	queue<int> q;
	q.push(a);
	while(!q.empty())	{
		q.pop();
		for(auto p:gp[a])	{
			if(vis[p])	continue;
			q.push(p);
			vis[p]=1;
			dist[p]=1+dist[a];
			//if(a==1 && p==2)	{cout << 1 << endl; exit(0);}
		}
		a=q.front();
	}
}

void solve()	{
	cin >> n;
	memset(dist,0,sizeof(dist));
	int x;
	for(int i=0; i<n; i++)	{
		cin >> x;
		connect(i+1,x);
	}
	bfs(1);

	if(vis[2])	cout << dist[2] << endl;
	else cout << -1 << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}



Measured memory_bytes: 34192
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const double INF = 100000000.0;
const double EPS = 1e-8;

class S{
public:
  int s, p;
  double cost;
  S(){}
  S(int p, double cost, int s) : p(p), cost(cost), s(s) {}
};

int n, m, p, a, b;
int t[8];
int edge[30][30];
double vis[30][1<<8];

bool equals(double a, double b){
  return fabs(b-a) < EPS;
}

void solve(){
  fill(vis[0], vis[30], INF);
  S u, v;
  queue<S> q;
  q.push(S(a, 0.0, (1<<n)-1));
  while(!q.empty()){
    u = q.front(); q.pop();
    for(int i=0;i<n;i++){
      if(1<<i & u.s){
        for(int j=0;j<m;j++){
          if(edge[u.p][j] == -1) continue;
          v.p = j;
          v.cost = u.cost + edge[u.p][v.p] / (double)t[i];
          v.s = u.s & ~(1<<i);
          if(vis[v.p][v.s] > v.cost){
            vis[v.p][v.s] = v.cost;
            q.push(v);
          }
        }
      }
    }
  }
  double res = INF;
  for(int i=0;i<(1<<n);i++) res = min(res, vis[b][i]);
  if(equals(res, INF)) printf("Impossible\n");
  else printf("%.3f\n", res);
}

main(){
  while(cin >> n >> m >> p >> a >> b && (n|m|p|a|b)){
    fill(edge[0], edge[30], -1);
    a--; b--;
    for(int i=0;i<n;i++) cin >> t[i];
    for(int i=0;i<p;i++){
      int x, y, z;
      cin >> x >> y >> z;
      edge[x-1][y-1] = edge[y-1][x-1] = z;
    }
    solve();
  }
}

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

long long p[51], b[51];

long long pate(int i) {
    if (i == 0) return 1;
    return p[i] = 2 * pate(i - 1) + 1;
}

long long burger(int i) {
    if (i == 0) return 1;
    return b[i] = 2 * burger(i - 1) + 3;
}

long long calc(int i, long long x) {
    if (x == 1) {
        if (i == 0)
            return 1;
        else
            return 0;
    } else if (b[i] == x) {
        return p[i];
    } else if (b[i] / 2 + 1 > x) {
        return calc(i - 1, x - 1);
    } else if (b[i] / 2 + 1 == x) {
        return p[i] / 2 + 1;
    } else {
        return (p[i] / 2 + 1) + calc(i - 1, x - (b[i] / 2 + 1));
    }
}

int main() {
    int N;
    long long X;
    cin >> N >> X;
    pate(N);
    burger(N);
    cout << calc(N, X) << endl;
}

Measured memory_bytes: 256