akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arrll(t,n);
  int m;
  cin >> m;
  vecll p(m), x(m);
  rep(i,m){
    cin >> p[i] >> x[i];
  }

  ll total = f_sum(t);

  rep(i,m){
    prt(total-t[p[i]-1]+x[i]);
  }
}


Measured memory_bytes: 256
#??±???????????¢?´¢
import collections

V, E = map(int, input().split())
Adj_list = [[] for _ in range(V)]
isVisited = [False] * V

for i in range(E):
    u, v = map(int, input().split())
    Adj_list[u].append(v)

Out = collections.deque()


def DFS(u):
    isVisited[u] = True
    for v in Adj_list[u]:
        if isVisited[v] != True:
            DFS(v)
    Out.appendleft(u)

for i in range(V):
    if isVisited[i] != True:
        DFS(i)
        
print(*Out, sep = '\n')

Measured memory_bytes: 11500
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int N;  cin >> N;
vector<int> d(N);
for (int i = 0; i < N; i++) {
    cin >> d[i];
}
sort(d.begin(), d.end());

cout << d[N/2] - d[N/2 - 1] << endl;

}

Measured memory_bytes: 640
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

using namespace std;
typedef long long ll;

int main()
{
    // Input
    int in;
    cin >> in;

    if (in % 1000 == 0) {
        cout << 0;
    } else {
        cout << 1000 - (in % 1000);
    }

    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int n,m,x;
    cin >> n >> m >> x;
    vi cost(n);
    vector<vi> a(n,vi(m));
    rp(i,n){
        cin >> cost.at(i);
        rp(j,m) cin >> a.at(i).at(j);
    }
    int ans=1<<30;
    rp(i,1<<n){
        int mon=0;
        vi us(m,0);
        rp(j,n){
            if(i&(1<<j)){
                mon+=cost.at(j);
                rp(k,m){
                    us[k]+=a.at(j).at(k);
                }
            }
        }
        bool ok=true;
        rp(j,m){
            if(us[j]<x){
                ok=false;
                break;
            }
        }
        if(ok){
            chmin(ans,mon);
        }
    }
    if(ans>1<<29) print(-1);
    else print(ans);
    return 0;
}

Measured memory_bytes: 3660
ss = [*'A'..'Z']
sss = [*'a'..'z']

s = gets.chomp.split(" ")[1]
if s.length < 1 || s.length > 100
  exit
end

if !ss.include?(s[0])
  exit
end

if s.length>1 && !sss.include?(s[1])
  exit
end

x = s[0]

puts("A#{x}C")

Measured memory_bytes: 1788
import itertools

d, g = map(int, input().split())
p, c = [None] * d, [None] * d
for i in range(d):
    p[i], c[i] = map(int, input().split())


ans = float('inf')
for r in range(0, d + 1):
    for choice in itertools.combinations(range(d), r):
        total = sum(100 * (i + 1) * p[i] + c[i] for i in choice)
        count = sum(p[i] for i in choice)

        for i in reversed(range(d)):
            if i in choice:
                continue
            
            finished = True
            for _ in range(p[i]):
                if g <= total:
                    finished = False
                    break
                total += (i + 1) * 100
                count += 1
            
            if finished:
                total += c[i]
            
            if g <= total:
                ans = min(ans, count)

print(ans)

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

int const MAXN = 1 << 13;
int f[MAXN];

int main() {
  int n,m;
  cin >> n >> m;
  memset(f, 0x7f, sizeof(f));
  f[0] = 0;
  int all = 1 << n;
  for (int i = 1; i <= m; ++i) {
    int cost, cnt; cin >> cost >> cnt;
    int s = 0;
    for (int j = 1, x; j <= cnt; ++j)
      cin >> x, s |= (1 << (x - 1));
    for (int j = 0; j < all; ++j)
      f[j | s] = min(f[j | s], f[j] + cost);
  }
  if (f[all - 1] == 0x7f7f7f7f) puts("-1");
  else printf("%d\n", f[all - 1]);
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}


int n,h,d;
ll fact[1000005];
ll factsum[1000005];
ll dp[2000005];
ll sum[2000005];


int main(void){
	scanf("%d%d%d",&n,&h,&d);
	fact[0]=0;
	fact[1]=1;
	factsum[1]=1;
	for(ll i=2;i<=n;i++){
		fact[i]=fact[i-1]*i%MOD;
		factsum[i]=(fact[i]+factsum[i-1])%MOD;
	}
	dp[0]=sum[0]=fact[n]*mod_inverse(factsum[n],MOD)%MOD;
	for(int i=1;i<=h;i++){
		dp[i]=factsum[n]*(sum[i-1]-(i-d-1>=0?sum[i-d-1]:0)+MOD)%MOD;
		sum[i]=(sum[i-1]+dp[i])%MOD;
	}
	printf("%lld\n",dp[h]);
	return 0;
}


Measured memory_bytes: 34816
#include <stdio.h>

int main(void)
{
  int n, i, q, j;
  int S[10000];
  int T[500];
  int c = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
     scanf("%d", &S[i]);

  scanf("%d", &q);

  for(i = 0; i < q; i++)
    scanf("%d", &T[i]);

  for(i = 0; i < q; i++) {
    for(j = 0; j < n; j++) {
      if(S[j] == T[i]) {
        c++;
        break;
      }
    }
  }

  printf("%d\n", c);

  return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

constexpr auto M = 1000000007L;

void dijkstra(const vector<vector<pair<int64_t, int64_t>>>& adjs,
              vector<int64_t>& costs, vector<int64_t>& nums, int64_t s) {
    int64_t n = adjs.size();

    costs.resize(n, 1L << 50);
    nums.resize(n, 0L);

    costs[s] = 0;
    nums[s] = 1;

    priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>,
                   std::greater<>>
            q;
    q.emplace(0L, s);

    while (!q.empty()) {
        auto cost = q.top().first;
        auto v = q.top().second;

        q.pop();

        if (cost > costs[v]) {
            continue;
        }

        for (const auto& link : adjs[v]) {
            auto u = link.first;
            auto u_cost = cost + link.second;

            if (u_cost < costs[u]) {
                costs[u] = u_cost;
                q.emplace(u_cost, u);
                nums[u] = nums[v];
            } else if (u_cost == costs[u]) {
                nums[u] += nums[v];
                nums[u] %= M;
            }
        }
    }
}

int main() {
    int64_t n, m, s, t;
    cin >> n >> m >> s >> t;

    --s;
    --t;

    vector<vector<pair<int64_t, int64_t>>> adjs(n);
    for (auto _ : irange(0L, m)) {
        int64_t u, v, d;
        cin >> u >> v >> d;
        --u;
        --v;
        adjs[u].emplace_back(v, d);
        adjs[v].emplace_back(u, d);
    }

    array<vector<int64_t>, 2> costs, nums;
    dijkstra(adjs, costs[0], nums[0], s);
    dijkstra(adjs, costs[1], nums[1], t);

    auto dist = costs[0][t];
    assert(dist == costs[1][s]);

    int64_t ans = nums[0][t] * nums[1][s] % M;
    for (auto v : irange(0L, n)) {
        if (2 * costs[0][v] == dist && 2 * costs[1][v] == dist) {
            ans += M - nums[0][v] * nums[0][v] % M * nums[1][v] % M *
                               nums[1][v] % M;
            ans %= M;
        }

        if (2 * costs[0][v] < dist && costs[0][v] + costs[1][v] == dist) {
            for (const auto& link : adjs[v]) {
                auto u = link.first;
                auto cost = link.second;

                if (costs[0][v] + cost + costs[1][u] == dist &&
                    2 * costs[0][u] > dist) {
                    ans += M - nums[0][v] * nums[0][v] % M * nums[1][u] % M *
                                       nums[1][u] % M;
                    ans %= M;
                }
            }
        }
    }

    cout << ans << endl;
}

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

#define Bye return 0
#define ll long long
const int MAX = 1e5+1;
int a[MAX];
bool b[MAX];

int search(int i, int sum){
    if(b[i] == true) return -1;
    if(i == 2) return sum;
    
    b[i] = true;

    return search(a[i], sum + 1);
}

void solve(){
    int n; cin>>n;
    for (int i=1; i<=n; i++)
        cin>>a[i];
    memset(b, false, sizeof b);
    int res = search(1, 0);
    cout<<res<<endl;
}

int main(){
    solve();
    Bye;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    ll n,k,x,y; cin >> n >> k >> x >> y;
    ll res = 0;
    for(int i=1;i<=n;i++){
        if(i <= k)res+=x;
        else res+=y;
    }
    out(res);
}

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

int main(int argc, char** argv){
  int N;
  cin >> N;
  int V[N];
  int C[N];
  for(int i=0; i<N; i++) cin >> V[i];
  for(int i=0; i<N; i++) cin >> C[i];
  int ans = 0;
  for(int i=0; i<N; i++) if(V[i] - C[i] > 0) ans += (V[i] - C[i]);
  cout << ans << endl;
  return 0;
  
}


Measured memory_bytes: 256
N, M = tuple(map(int, input().split()))
A, B = [], []
for i in range(N):
    a, b = tuple(map(int, input().split()))
    A.append(a)
    B.append(b)
C, D = [], []
for i in range(M):
    c, d = tuple(map(int, input().split()))
    C.append(c)
    D.append(d)
ans = [0] * N
for i, (a, b) in enumerate(zip(A, B)):
    min_diff = float('inf')
    for idx, (c, d) in enumerate(zip(C, D), 1):
        diff = abs(a - c) + abs(b - d)
        if diff < min_diff:
            ans[i] = idx
            min_diff = diff
for x in ans:
    print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
        if(v[i] - c[i] > 0){
            sum += v[i] - c[i];
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
LL a, b, sum;
int main() {
	scanf("%lld%lld", &a, &b);
	LL x = abs(a - b);
	sum = 1;
	if(x > 1) {
		printf("0\n");
		return 0;
	}
	for(int i = 1; i <= a; i++) {
		sum = (sum * i) % MOD;
	}
	for(int i = 1; i <= b; i++)
		sum = (sum * i) % MOD;
	if(a == b) sum = (sum * 2) % MOD;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
res = s
for i in range(n):
    if i%2 == 1:
        res -= 2*a[i]
ans = []
ans.append(str(res))
tmp = res
for i in range(n-1):
    now = 2*a[i] - tmp
    ans.append(str(now))
    tmp = now
print(" ".join(ans))

Measured memory_bytes: 92704
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(200009),b(200009);
  for(int i=0;i<M;i++)cin >> a[i] >> b[i];
  string ans="IMPOSSIBLE";
  vector<int> q,w;
  for(int i=0;i<M;i++){
    if(a[i]==1){q.push_back(b[i]);}
    if(b[i]==N){w.push_back(a[i]);}
  }
  sort(q.begin(),q.end());
  sort(w.begin(),w.end());
  int k=0;
  for(int i=0;i<q.size();i++){
    for(int j=k;j<w.size();j++){
      if(q[i]==w[j]){cout << "POSSIBLE" << endl; return 0;}
      if(q[i]<w[j]){k=j; break;}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2812
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b=n1()
# from math import gcd
from fractions import gcd
m=gcd(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)

    divisors.sort()
    return divisors

gcd_list=make_divisors(m)
if len(gcd_list)==1:
    print(1)
else:
    prime=[]
    for i in gcd_list[1:]:
        for j in prime:
            if i%j==0:
                break
        else:
            prime.append(i)
    print(len(prime)+1)

Measured memory_bytes: 66156
from functools import reduce

def gcd_base(x, y):
    if x % y:
        return gcd_base(y, x%y)
    return y

def gcd(numbers):
    return reduce(gcd_base, numbers)

def lcm_base(x, y):
    res = (x * y) // gcd_base(x, y)
    return res if res <= 1000000007 else 0

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
a = [int(i) for i in input().split()]
k = [0] * n
for i in range(n):
    j = a[i]
    while(j%2==0):
        j //= 2
        k[i] += 1
if any([k[i]!=k[i+1] for i in range(n-1)]):
    print(0)
else:
    l = [i//2 for i in a]
    x = lcm(l)
    if x==0:
        print(0)
    else:
        print((m//x+1)//2)

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

using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define show(a) for(auto el:a)cout<<el<<" "
#define ff first
#define ss second
#define pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define fam(v,i) for(auto i=v.begin();i!=v.end();i++)
#define fai(v,i) for(auto i : v)
#define mo 1000000007




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ld d,s,t;
    cin>>d>>t>>s;
    ld a=d/s;
    if(a<t || a==t)
    {
        cout<<"Yes\n";
    }
    else
    cout<<"No";
    
     return 0;
}


Measured memory_bytes: 3736
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200000];
int main()
{
	int i,n,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	  scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n-1;i++)
	{
	   if(a[i]==a[i+1])
	   {
	      flag=1;
	      break;
	   }
	}
	if(flag==1)
	{
		printf("NO\n");
	}
	else
	{
		printf("YES\n");
	}
	return 0;	
 } 

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

long long factrial[2000010];
long long Repeat(long long a, long long cnt) {
    if(cnt == 0) return 1LL;
    if(cnt % 2 == 1) {
        long long x = Repeat(a, cnt / 2);
        return (((a * x) % MOD) * x) % MOD;
    } else {
        long long x = Repeat(a, cnt / 2);
        return (x * x) % MOD;
    }
}

long long fact(long long a) {
    if(a == 0)
        return 1LL;
    else if(factrial[a] != 0)
        return factrial[a];
    else
        return factrial[a] = (a * fact(a - 1)) % MOD;
}

long long comb(long long a, long long b) {
    long long fa, fb, fab;
    fa = fact(a);
    fb = fact(b);
    fab = fact(a - b);
    fb = Repeat(fb, MOD - 2);
    fab = Repeat(fab, MOD - 2);
    return (((fa * fb) % MOD) * fab) % MOD;
}

int main() {
    ll n, m, i, j, k, x, y;
    cin >> x >> y;
    ll ret = 0;
    factrial[0] = 1;
    for(i=1;i<=2000001;i++){
        factrial[i] = (factrial[i-1]*i)%MOD;
    }
    for(i=0;i<=y/2;i++){
        // i回y軸方向に+2の移動をする
        ll dy = 2*i;
        ll one = y-dy;
        if(one*2+i==x){
            //cout << one+i << " " << i << endl;
            ret += comb(one+i,i);
            ret %= MOD;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

void chemthan() {
    long long a, b, c, k; cin >> a >> b >> c >> k;
    if (!(k & 1)) {
        cout << a - b << "\n";
    }
    else {
        cout << b - a << "\n";
    }
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
} 


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, M = map(int, input().split())

    v = []
    for _ in range(N):
        A, B = map(int, input().split())
        v.append((A, B))
    v.sort()

    ans = 0
    now = 0
    for a, b in v:
        buy = min(M - now, b)
        ans += buy * a
        now += buy

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17812
from collections import Counter


class UnionFind:
    def __init__(self, n):
        # total number of nodes.
        self.n = n
        # node id -> root node id
        self._root_table = list(range(n))
        # root node id -> group size
        self._size_table = [1] * n

    def find(self, x):
        """Returns x's root node id."""
        r = self._root_table[x]
        if r != x:
            # Update the cache on query.
            r = self._root_table[x] = self.find(r)
        return r

    def union(self, x, y):
        """Merges two groups."""
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        # Ensure that x is the larger (or equal) group.
        if self._size_table[x] < self._size_table[y]:
            x, y = y, x

        self._size_table[x] += self._size_table[y]
        self._root_table[y] = x

    def size(self, x):
        return self._size_table[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self._root_table) if x == i]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

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


N, K, L = map(int, input().split())
roads = UnionFind(N)
rails = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    roads.union(p - 1, q - 1)
for i in range(L):
    r, s = map(int, input().split())
    rails.union(r - 1, s - 1)
c = Counter()
for i in range(N):
    gid = roads.find(i) * N + rails.find(i)
    c[gid] += 1

print(*[c[roads.find(i) * N + rails.find(i)] for i in range(N)])


Measured memory_bytes: 117976
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,ans=0,fr[1000010],dp[1000010];
int main(){
	scanf("%lld",&n);
	dp[0]=1;fr[0]=1;
	for(int i=1;i<=n;i++){
		dp[i]=dp[i-1];
		if(i>=3){dp[i]=(dp[i]+fr[i-3])%mod;}
		fr[i]=(fr[i-1]+dp[i])%mod;
	}
	for(int i=0;i<(n-1);i++){ans=(ans+(dp[i]*(n-1)%mod*n%mod))%mod;}
	ans=(ans+(dp[n-1]*(n-1)%mod))%mod;
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>
int main(){double w;int f;char *p[11]={"light fly","fly","bantam","feather","light","light welter","welter","light middle","middle","light heavy","heavy"};while(scanf("%lf",&w)!=EOF){if(w>91)f=10;else if(w>81)f=9;else if(w>75)f=8;else if(w>69)f=7;else if(w>64)f=6;else if(w>60)f=5;else if(w>57)f=4;else if(w>54)f=3;else if(w>51)f=2;else if(w>48)f=1;else f=0;puts(p[f]);}return 0;}

Measured memory_bytes: 0
#include<stdio.h>
 
int LinearSearch(int *,int);
int n,q;
 
int main(){
  int S[10000];
  int T[500];
  int i,a,c=0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d ",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    a = LinearSearch(&S[0],T[i]);
    c += a;
  }
 
  
  printf("%d\n",c);
 
  return 0;
}
 
int LinearSearch(int * A, int key){
  int i;
 
  for(i=0;i<n;i++){
    if(A[i]==key) return 1;
  }
    return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int n; cin >> n;
    vector<vector<int>> f(10, vector<int>(10, 0));
    repr(i, 1, n+1) {
        int a = to_string(i)[0]-'0';
        int b = i%10;
        ++f[a][b];
    }

    ll ans = 0;
    repr(i, 1, 10) repr(j, 1, 10) ans += f[i][j] * f[j][i];
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] happy = new int[N][3];
        for (int i = 0; i < N; i++) {
            for (int k = 0; k < 3; k++) {
                happy[i][k] = sc.nextInt();
            }
        }

        int[][] dp = new int[N + 1][3];

        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][j] = Math.max(dp[i + 1][j], dp[i][k] + happy[i][j]);
                }
            }
        }

        int result = 0;
        for (int i = 0; i < 3; i++) {
            result = Math.max(result, dp[N][i]);
        }

        System.out.println(result);
    }
}


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

int main(void){

  long x;
  scanf("%ld", &x);
  long a,b;
  long a_minus_b_1;
  long a_minus_b_2;
  long left;
  for (long i = 1; i <= sqrt(x); i++) {
    if (x%i == 0) {
      a_minus_b_1 = i;
      a_minus_b_2 = x/i;
      for (long j = 0; ; j++) {
        a = j;
        b = a-a_minus_b_1;
        left = pow(a,5)-pow(b,5);
        if (pow(a,5)-pow(b,5) == x) {
          printf("%ld %ld\n", a, b);
          return 0;
        }
        if (b > 0 && pow(a,5)-pow(b,5) > x) {
          break;
        }
      }
      for (long j = 0; ; j++) {
        b = j;
        a = b+a_minus_b_2;
        if (pow(a,5)-pow(b,5) == x) {
          printf("%ld %ld\n", a, b);
          return 0;
        }
        if (b > 0 && pow(a,5)-pow(b,5) > x) {
          break;
        }
      }
    }
  }

  return 0;
}

Measured memory_bytes: 2544
# -*- coding: utf-8 -*-
from fractions import Fraction
from collections import Counter, defaultdict, deque
import math

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(a, b):
    if a == 0 and b == 0:
        return (0, 0)
    if b == 0:
        return (1, 0)
    f = Fraction(a, b)
    a = f.numerator
    b = f.denominator
    return a, b


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, AB):
    adb = Counter()
    for a, b in AB:
        a, b = f(a, b)
        adb[(a, b)] += 1
    M = Mod(1000000007)
    ans = 1
    done = {(0, 0)}
    for k, v in adb.items():
        if k in done:
            continue
        a, b = k
        if a < 0:
            s = 1
            a = abs(a)
        elif a == 0:
            s = 1
        else:
            s = -1
        n = adb[(s*b, a)]
        done.add(k)
        done.add((s*b, a))
        t = M.sub(M.pow(2, v) + M.pow(2, n), 1)
        ans = M.mul(ans, t)
    ans = M.add(ans, adb[(0, 0)])
    return M.sub(ans, 1)


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 172712
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <iterator>
#include <map>


using namespace std;

#define DT int
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
typedef list<DT> lst;
typedef vector<DT> vec;

int main() {
	vector<int>vc(101);
	DT a, b, n=101,c,s=0,i;
	cin >> a >> b >> c;
	vc[a] = 1;
	vc[b] = 1;
	vc[c] = 1;

	forn(i, n){
		s += vc[i];
	}
	cout << s << endl;
	return 0;
}
		
	
	
				

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

int main()
{
    string T;
    cin >> T;
    for(int i = 0; i < T.size(); i++){
        if(T[i] == '?') T[i] = 'D';
    }
    cout << T << endl;

    return 0;
}

Measured memory_bytes: 3756
using System;
using System.Text;

namespace _057_TheNumberofArea
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			StringBuilder output = new StringBuilder (300);

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int inputNum = int.Parse (inputStr);
				int sum = inputNum * (inputNum + 1) / 2 + 1;
				output.AppendLine (sum.ToString ());
			}
			Console.Write (output);
		}
	}
}

Measured memory_bytes: 9120
#include <iostream>
#include <stdio.h>


using namespace std;

int main()
{
	int cur, last = -1;
	while ((cur = getchar()) != EOF)
	{
		if (cur == last)
		{
			cout << "Bad";
			return 0;
		}
		last = cur;
	}
	cout << "Good";
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> card_point(N);
    for(int i = 0; i < N; i++){
        int point;
        cin >> point;
        card_point.at(i) = point;
    }
    sort(card_point.begin(), card_point.end(), greater<int>());
    int pointAlice = 0, pointBob = 0;
    for(int i = 0; i < N; i++){
        if(i % 2) pointBob += card_point[i];
        else pointAlice += card_point[i];
    }
    cout << pointAlice - pointBob << endl;
}

Measured memory_bytes: 256
//itp1_2_a

#include <iostream>
using namespace std;

int main(){
 int a,b;

 cin>>a>>b;

 if(a<b) cout<<"a < b"<<endl;
 else if(a>b) cout<<"a > b"<<endl;
 else if (a==b) cout<<"a == b"<<endl;
 return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  long long k;
  cin >> n >> k;
  vector dp(60, vector<int>(n));
  for (auto&& e : dp[0]) {
    cin >> e;
    --e;
  }
  for (int d = 1; d < 60; ++d) {
    for (int i = 0; i < n; ++i) {
      dp[d][i] = dp[d - 1][dp[d - 1][i]];
    }
  }
  int res = 0;
  for (int d = 0; d < 60; ++d) {
    if (k >> d & 1) {
      res = dp[d][res];
    }
  }
  cout << res + 1 << '\n';
}


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

long long INF = 1145141919810364364;

int main() {
	int A, B, Q;
	cin >> A >> B >> Q;
	static long long S[100010] = {}, T[100010] = {};
	S[0] = T[0] = -INF;
	S[A + 1] = T[B + 1] = INF;
	for (int i = 1; i <= A; i++) cin >> S[i];
	for (int i = 1; i <= B; i++) cin >> T[i];
	for (int i = 0; i < Q; i++) {
		long long X;
		cin >> X;
		int L = 0, R = A + 1, SL, SR, TL, TR;
		while (R - L > 1) {
			int MID = (L + R) / 2;
			if (S[MID] < X) L = MID;
			else R = MID;
		}
		SL = L, SR = R;
		L = 0, R = B + 1;
		while (R - L > 1) {
			int MID = (L + R) / 2;
			if (T[MID] < X) L = MID;
			else R = MID;
		}
		TL = L, TR = R;
		long long ans1, ans2, ans3, ans4;
		ans1 = X - min(S[SL], T[TL]);
		ans2 = min(X - S[SL], T[TR] - X) + T[TR] - S[SL];
		ans3 = min(X - T[TL], S[SR] - X) + S[SR] - T[TL];
		ans4 = max(S[SR], T[TR]) - X;
		cout << min(min(ans1, ans2), min(ans3, ans4)) << endl;
	}
}

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

using namespace std;

typedef long long ll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define mp make_pair
#define pb push_back
#define all(name) (name.begin(), name.end())
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) power(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;

class Dsu {
	vector<int> drr;
	vector<int> size_arr;
	public :
	Dsu (int n) {
		rep(i, 0, n+1){
			drr.pb(i);
			size_arr.pb(1);
		}
	}

	int f_p (int a) {
		return drr[a] == a ? a : f_p(drr[a]);
	}

	ll size (int a) {
		return (ll)size_arr[f_p(a)];
	}

	void uni(int a, int b) {
		int ap = f_p(a);
		int bp = f_p(b);
		if(ap == bp)return;
		if(!(size_arr[ap] > size_arr[bp]))swap(ap,bp);
		drr[bp] = ap;
		size_arr[ap] += size_arr[bp];
	}
};



vector<ll> ft(1, 1LL);
vector<bool> is_prime(1000000, 1);

void sieve();
ll power(ll x, ll y);
int ch(string s, int a){
    int f = 1;
    for(int i = 0; i < a/2; i++){
        if(s[i] != s[a-i-1])return 0;
    }
    return 1;

}
int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	sieve();
	int t = 1;
	// cin >> t;
	while(t--)
	{
		string s;
        cin >> s;
        int n = s.size();
        if(ch(s, (n-1)/2) and ch(s, n))cout << "Yes\n";
        else cout << "No\n";
	}
}
//
//
//
//
//
//important funct
ll power(ll x, ll y) {
    ll res = 1;x %= mod;
    while (y > 0) {
        if (y & 1)res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
void sieve(){
	is_prime[0] = is_prime[1] = 0;
	for(int i = 2; i*i <= 1000000; i++)
		if(is_prime[i])
			repc(j, i*i, 1000000, i)is_prime[j] = 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2642>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 <reference : http://okuraofvegetable.hatenablog.com/entry/2017/09/17/000945>
 
 ================================================================
 */

ll solve(){
    ll res = -LINF;
    ll N,P,Q; cin >> N >> P >> Q;
    vector<ll> C(N); for(auto& in:C) cin >> in;
    ll S = accumulate(C.begin(),C.end(),0LL);
    vector<ll> F(N);
    for(ll a = 0; a < N;a++){
        F[a] = P*a + C[a];
    }
    sort(F.begin(),F.end());
    for(int i = 0; i < N-1;i++) F[i+1] += F[i];
    res = S;
    for(ll k = 1; k <= N;k++){
        res = max(res,S+k*P*Q+P*k*(k-1)-F[k-1]);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 10756
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int N,K;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> N >> K;
    vector<int> memo(K+1),sum(K+1);
    REP(i,N){
        int l,r;
        cin >> l >> r;
        ++memo[l];--memo[r];
    }

    REP(i,K) sum[i+1] = sum[i] + memo[i];
    cout << *max_element(sum.begin(),sum.end()) << '\n';
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define MAXN 105
using namespace std;
int n,x;
int sum[MAXN];
map<string,int> mp;
string s;
int main()
{
	while(~scanf("%d",&n))
	{
		mp.clear();
		sum[0] = 0;
		for(int i = 1;i <= n;++i)
		{
			cin >> s;
			scanf("%d",&x);
			mp[s] = i;
			sum[i] = sum[i-1] + x;
		}
		string ss;
		cin >> ss;
		int tt = mp[ss];
		printf("%d\n",sum[n]-sum[tt]);
	}
	return 0;
}

Measured memory_bytes: 256
function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.trim().split(" ");
	input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var N = parseInt(input[0].split(" ")[0]);
  var list = input[1].split(" ").map((a)=>Number(a));
  var output = new Array(N - 1);
  for(var i = 0; i < N; i++){
    var tmp = list[i];
    output[tmp - 1] = i + 1;
  }
  myout(output.join(" "));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

using namespace std;

const int max_n = 18, inf = 1000111222;
const int max_mask = (1 << max_n) + 5;

int n, a[max_n][2], dp[max_mask][max_n][2];

bool get_bit(int mask, int pos) {
    return (mask >> pos) & 1;
}

void upd(int mask, int last, int tp, int val) {
    dp[mask][last][tp] = min(dp[mask][last][tp], val);
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i][0];
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i][1];
    }
    for (int mask = 0; mask < max_mask; ++mask) {
        for (int last = 0; last < n; ++last) {
            for (int tp = 0; tp < 2; ++tp) {
                dp[mask][last][tp] = inf;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        dp[1 << i][i][i % 2] = i;
    }
    for (int mask = 0; mask < max_mask; ++mask) {
        int tot = __builtin_popcount(mask);
        for (int last = 0; last < n; ++last) {
            for (int tp = 0; tp < 2; ++tp) {
                if (dp[mask][last][tp] == inf) {
                    continue;
                }
                //cout << mask << " " << last << " " << tp << ": " << dp[mask][last][tp] << endl;
                int to_right = tot, to_left = 0;
                for (int nxt = 0; nxt < n; ++nxt) {
                    to_right -= get_bit(mask, nxt);
                    int cnt = nxt - to_left;
                    if (!get_bit(mask, nxt) && a[last][tp] <= a[nxt][(cnt + to_right) % 2]) {
                        upd(mask | (1 << nxt), nxt, (cnt + to_right) % 2, dp[mask][last][tp] + cnt);
                    }
                    to_left += get_bit(mask, nxt);
                }
            }
        }
    }
    int ans = inf;
    for (int last = 0; last < n; ++last) {
        for (int tp = 0; tp < 2; ++tp) {
            ans = min(ans, dp[(1 << n) - 1][last][tp]);
        }
    }
    if (ans == inf) {
        ans = -1;
    }
    cout << ans << "\n";
    return 0;
}


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

int main(){
    int n, t, a;
    cin >> n >> t >> a;
    vector<uint32_t> height(n);
    float abs_temp = FLT_MAX;
    int index = 0;
    for (auto i = 0; i < n; i++) {
        cin >> height[i];
        float temp = abs(a - (t - height[i] * 0.006));
        if (abs_temp > temp) {
            abs_temp = temp;
            index = i + 1;
        }
    }

    cout << index << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String args[]){
		
	Scanner sc = new Scanner(System.in);
		
	//数列の長さを最初に、そのあとに数を受け取っていく
	String s1 = sc.next();
        int n = Integer.parseInt(s1);
        int a[] = new int[n];
        for(int i = 0;i < a.length; i++){
            String s2 = sc.next();
            a[i] = Integer.parseInt(s2);
        }
        
        //受け取った順番と逆の順番で出力する
        for(int i = (a.length - 1); i >= 0; i--){
            if(i != 0){
        	System.out.print(a[i] + " ");
            }
            else{
        	System.out.println(a[i]);
            }
        }
    }
}

Measured memory_bytes: 17292
#include <stdio.h>
int main(){
int a,b,c,d;
scanf ("%d%d%d%d",&a,&b,&c,&d);
  if(a+b>c+d){
printf ("Left");
  }
  else if(a+b==c+d){
printf ("Balanced");
  }
  else{
printf ("Right");
  }
  return 0;
}


Measured memory_bytes: 128
import math

def count(N,K,mid,a):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(a[i]/mid-1)
    if cnt > K:
        return False
    else:
        return True

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    low = 1
    high = 10**9+1
    mid = (low+high)//2

    while high > low+1:
        if count(N,K,mid,a):
            high = mid
        else:
            low = mid
        mid = (low+high)//2
    
    if count(N,K,low,a):
        print(low)
    else:
        print(high)

main()

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    int n,a,b;
    cin>>n;
    bool ok=true,check=false;
    cin>>a;
    rep(i,n-1){
        cin>>b;
        if(a-b>1) ok=false;
        else if(a-b==1){
            if(check) ok=false;
            check=true;
        }
        else if(a<b){
            check=false;
        }
        a=b;
    }
    cout<<(ok?"Yes": "No")<<endl;
    return 0;
}

Measured memory_bytes: 256
n, k = gets.chomp.split(' ').map{|s| s.to_i}
sunuke = Array.new(n, 0)
k.times do |i|
  d = gets
  gets.chomp.split(' ').map{|s| s.to_i - 1}.each do |a|
    sunuke[a] = 1
  end
end

puts sunuke.count{|s| s == 0}

Measured memory_bytes: 14308