akhauriyash/Code-Regression huggingface dataset:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy

# 最大公約数
def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z

# 幅優先探索(BFS)でスタート座標(x, y)からの最大距離返す
def bfs(SS, x, y, H, W):#入力(座標系(迷路), x, y, xの端, yの端)
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" #探索した場所は探索できないようにする
    for i in range(4): #このforで上下左右を調べてる
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      #print(tempx, tempy, xytuple[2])
      #print(S)
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" #探索した場所は探索できないようにする
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      #print(q)
  return mlength

#素因数分解
def prime_factorize(n):
  a = []
  while n % 2 == 0:
    a.append(2)
    n //= 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n //= f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

#重複を検出
def has_duplicates(seq):
  return len(seq) != len(set(seq))


#Christmas D問題
def Christmas(X, DP, DP2, N):
  ans = 0
  b = 0
  for i in reversed(range(0, N+1)):
    if(X-DP[i]>=0):
      b = DP[i]
      X -= b
      ans += DP2[i]
      if(X>=1):
        ans += 1
      N = i+1
      break
    X -= 1
    if(X == 0):
      break
  if not(X == 0):
    ans += Christmas(X, DP, DP2, N)

  return ans

#X = str(input()).split()
#a = [int(x) for x in input().split()]


NX = str(input()).split()
N = int(NX[0])
X = int(NX[1])
DP = [0]*51
DP2 = [0]*51
DP[0] = 1
DP2[0] = 1
ans = 0

for i in range(1, 51):
  DP[i] = DP[i-1]*2+3
  DP2[i] = DP2[i-1]*2+1

ans = Christmas(X, DP, DP2, N)

print(ans)



Measured memory_bytes: 39404
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

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

#define pb push_back
#define F first
#define S second

#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 5e5+5, LG = 17, MOD = 998244353;
const int SQ = 390;
const long double EPS = 1e-7;
string S;
int n;
int z[N<<1];
void Zalgo(string S){

  int L = 0, R = 0;
  int n = S.size();
  for (int i = 1; i < n; i++)
  {
      if (i > R)
      {
          L = R = i;
          while (R < n && S[R-L] == S[R])
          {
              R++;
          }
          z[i] = R-L;
          R--;
      }
      else
      {
          int k = i-L;
          if (z[k] < R-i+1)
          {
              z[i] = z[k];
          }
          else
          {
              L = i;
              while (R < n && S[R-L] == S[R])
              {
                  R++;
              }
              z[i] = R-L;
              R--;
          }
      }
  }
  int idx = (find(S.begin(), S.end(), '#') - S.begin()) + 1;
  f(i,idx,n)
    z[i-idx] = z[i];
}
bitset<N> solve(){
  bitset<N> ret;
  ret.set();
  Zalgo(S + "#" + S);
  f(i,1,S.size()/2+1)
    for(int j = i; z[j] >= i && j + i <= n; j += i)ret[j+i] = 0;
  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  cin >> S;
  n = S.size();

  if(S == string(n, S[0])){
    cout << n << '\n';
    cout << 1 << '\n';
    return 0;
  }
  auto prefix = solve();
  if(prefix[n]){
    cout << 1 << '\n';
    cout << 1 << '\n';
    return 0;
  }

  reverse(S.begin(),S.end());
  auto suffix = solve();
  int ans = 0;
  f(i,1,n)
    ans += (prefix[i]&suffix[n-i]);

  cout << 2 << '\n';
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 6212
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 入力
        int n = sc.nextInt();
        // 初期値
        boolean can = true;
        int t, x, y, dt, dx, dy, dif;
        t = x = y = 0;

        for (int i = 0; i < n; i++) {
            // 入力値
            dt = sc.nextInt();
            dx = sc.nextInt();
            dy = sc.nextInt();
            dif = dt - t - Math.abs(dx - x) - Math.abs(dy - y);
            can &= dif >= 0 && dif % 2 == 0;
            t = dt;
            x = dx;
            y = dy;
        }

        // 出力
        if (can) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 88172
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;


long long int INF=(long long)10000000000*100000;
long long int ans=0;
long long int w,h;
long long int x[100001],y[100001];
vector<long long int> vx;
vector<long long int> vy;
long long rx,ry;
int n;

long long int dfs(long long int sx,long long int sy){
	vector<long long int> v;
	for(int i=0;i<n;i++){
		v.push_back(abs(sx-x[i])+abs(sy-y[i]));
	}
	sort(v.begin(),v.end());
	long long res=0;
	for(int i=0;i<n;i++){
		if(i<n-1)res+=v[i]*2;
		else res+=v[i];
	}
	return res;
}

int main(void){
	cin >> w >> h;
	ans=INF;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
		vx.push_back(x[i]);
		vy.push_back(y[i]);
	}
	if(n==1){
		cout << 0 << endl;
		cout << x[0] << " " << y[0] << endl;
	}
	else{
		sort(vx.begin(),vx.end());
		sort(vy.begin(),vy.end());
		for(int j=-1;j<=1;j+=2){
			for(int i=-1;i<=1;i+=2){
				long long int res=dfs(vx[(n+j)/2],vy[(n+i)/2]);
				if(res<ans){
					rx=vx[(long long)((n+j)/2)];
					ry=vy[(long long)((n+i)/2)];
					ans=res;
				}
			}
		}
		cout << ans << endl;
		cout << rx << " " << ry << endl;
	}
    return 0;
}

Measured memory_bytes: 6000
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    
    int P[100000], Y[100000];

    pair<pair<int,int> , int> city[100000];
    for(int i=0; i<M; i++){
        cin >> P[i] >> Y[i];
        city[i].first.first = P[i];
        city[i].first.second = Y[i];
        city[i].second = i;
    }
    
    sort(city, city+M);

    int x[100000];
    
    for(int i=0; i<M; i++){
        if(i==0 || city[i].first.first != city[i-1].first.first){
            x[ city[i].second ] = 1;
        }else{
            x[ city[i].second ] = x[city[i-1].second]+1;
        }
    }
    
    for(int i=0; i<M; i++){
        cout << setw(6) << setfill('0') << P[i];
        cout << setw(6) << setfill('0') << x[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
int main(){
	int N,W,H;
	scanf("%d %d %d",&W,&H,&N);

	int x[101],y[101],a[101];
	int Rx=W,Lx=0,Oy=H,Uy=0;
	int i;
	for(i=1;i<=N;i++){
		scanf("%d %d %d",&x[i],&y[i],&a[i]);
		switch(a[i]){
			case 1:
				if(Lx<=x[i])Lx=x[i];
				break;
			case 2:
				if(Rx>=x[i])Rx=x[i];
				break;
			case 3:
				if(Uy<=y[i])Uy=y[i];
				break;
			case 4:
				if(Oy>=y[i])Oy=y[i];
				break;
		}
	}

	if(Lx>=Rx || Oy<=Uy){
		printf("0");
		return 0;
	}
	printf("%d",(Rx-Lx)*(Oy-Uy));

}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
int t[N];
int lowbit(int x){return x&(-x);}
void add(int x){
    while(x<N){
        t[x]++;
        x+=lowbit(x);
    }
}
long long sum(int x){
    long long ans=0;
    while(x){
        ans+=t[x];
        x-=lowbit(x);
    }
    return ans;
}
struct node{int id;long long val;};
node arr[N];
bool comp(node p1,node p2){
    return p1.val<p2.val;
}
int num[N];
int main(){
    std::ios::sync_with_stdio(false);
    int n,k;
    while(cin>>n>>k){
        memset(t,0,sizeof(t));
        long long a;
        arr[0].id = 0;
        arr[0].val = 0;
        for(int i=1;i<=n;i++){
            arr[i].id = i;
            cin>>a;
            arr[i].val = a-k;
        }
        for(int i=1;i<=n;i++){
            arr[i].val += arr[i-1].val;
        }
        sort(arr,arr+n+1,comp);
        for(int i=0;i<=n;i++){
            if(i>0&&arr[i].val==arr[i-1].val)num[arr[i].id] = num[arr[i-1].id];
            else num[arr[i].id] = i+1;
        }
        long long ans = 0;
        for(int i=0;i<=n;i++){
            int x = num[i];
            ans += sum(x);
            add(x);
        }
        cout<<ans<<endl;
    }
}


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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DLOG(...)
#endif

void debug(auto f) {
#if DEBUG
  f();
#endif
}

ll mPrime = 998244353;

ll mAdd(ll x, ll y) {
  ll z = x + y;
  if (z < mPrime)  return z;
  else             return (z - mPrime);
}

ll mSub(ll x, ll y) {
  ll z = x - y;
  if (z >= 0)  return z;
  else         return (z + mPrime);
}

ll mMul(ll x, ll y) {
  return (x * y) % mPrime;
}



ll N;
vector<ll> A;
vector<ll> dp;
vector<ll> dp2;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  A.resize(N);
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  ll half = (sum + 1) / 2;
  dp.resize(half+1);
  dp.at(0) = 1;
  for (ll i = 0; i < N; i++) {
    dp.at(half) = mMul(3, dp.at(half));
    for (ll k = half - 1; k >= 0; k--) {
      ll j = min(k + A.at(i), half);
      dp.at(j) = mAdd(dp.at(j), dp.at(k));
      dp.at(k) = mMul(2, dp.at(k));
    }
  }
  ll bad1 = dp.at(half);
  dp2.resize(half+1);
  dp2.at(0) = 1;
  for (ll i = 0; i < N; i++) {
    for (ll k = half - 1; k >= 0; k--) {
      ll j = k + A.at(i);
      if (j > half)  continue;
      dp2.at(j) = mAdd(dp2.at(j), dp2.at(k));
    }
  }
  ll bad2;
  if (sum % 2 == 0) {
    bad2 = dp2.at(half);
  }else {
    bad2 = 0;
  }
  ll bad = mSub(mMul(3, bad1), mMul(3, bad2));
  ll all = 1;
  for (ll i = 0; i < N; i++)  all = mMul(3, all);
  ll good = mSub(all, bad);
  DLOG("bad1 = %lld, bad2 = %lld, all = %lld, good = %lld\n", bad1, bad2, all, good);
  cout << good << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

void swap(int* a, int* b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

int q[100005];
int q_size = 0;
void push(int value)
{
    q_size++;
    q[q_size] = value;
    int i2 = q_size;
    while (i2 > 1) {
        int i1 = i2 / 2;
        if (q[i1] >= q[i2]) {
            break;
        }
        swap(&q[i1], &q[i2]);
        i2 = i1;
    }
}
int pop()
{
    if (q_size == 0) {
        return -1;
    }
    int ret = q[1];
    q[1] = q[q_size];
    q_size--;
    int i1 = 1;
    int i2 = i1 * 2;
    while (i2 <= q_size) {
        if (i2 < q_size && q[i2] < q[i2 + 1]) {
            i2++;
        }
        if (q[i1] > q[i2]) {
            break;
        }
        swap(&q[i1], &q[i2]);
        i1 = i2;
        i2 = i1 * 2;
    }
    return ret;
}

int main(void)
{
    int n, m;
    int a;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a);
        push(a);
    }
    for (int i = 0; i < m; ++i) {
        a = pop();
        a /= 2;
        push(a);
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        a = pop();
        ans += (long long)a;
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
//const int MOD=1e9+7;
 
const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<int> a(n), b(n);
    
    for(int&i:a)cin>>i;
    for(int&i:b)cin>>i;
    
    
    vector<pair<int,int>> va(n), vb(n);
    
    for(int i=0; i<n ;i++){
        va[i]={a[i],i};
        vb[i]={b[i],i};
    }
    
    
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    
    
    
    for(int i=0; i<n; i++){
        if(a[i]>b[i]){
            cout<<"No";
            return 0;
        }
    }
    for(int i=1; i<n; i++){
        if(a[i]<=b[i-1]){
            cout<<"Yes";
            return 0;
        }
    }
    
    sort(va.begin(),va.end());
    sort(vb.begin(),vb.end());
    
    vector<int> perm(n);
    for(int i=0; i<n; i++){
        perm[va[i].second]=vb[i].second;
    }
    vector<bool> vis(n);
    int ct=0;
    int pos=0;
    while(!vis[pos]){
        ct++;
        vis[pos]=1;
        pos=perm[pos];
        
    }
    

    cout<<(ct<n?"Yes":"No");
    
    
    
    
    
    return 0;
}

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

using namespace std;

#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

int dp[2010][2010];
int tr[2010][2010];

signed main()
{
  string s;
  while(cin >> s) {
    string t = s; reverse(all(s));    
    memset(dp, 0, sizeof(dp));
    memset(tr, 0, sizeof(dp));
    for(int i = 0; i < s.size(); i++) {
      for(int j = 0; j < t.size(); j++) {
	if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1, tr[i+1][j+1] = 1;
	else {
	  if(dp[i+1][j] > dp[i][j+1]) dp[i+1][j+1] = dp[i+1][j], tr[i+1][j+1] = 2;
	  else dp[i+1][j+1] = dp[i][j+1], tr[i+1][j+1] = 3;
	}
      }
    }
    string x;
    for(int i = s.size(), j = t.size(); i > 0 && j > 0; ) {
      switch(tr[i][j]) {
      case 1: x += s[i-1], i--, j--; break;
      case 2: j--; break;
      case 3: i--; break;
      }
    }
    cout << x << endl;
  }
  return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif

typedef pair<ll, ll> pt;

const int MAXN = 100;
//#define int long long
const int INF = 1e9;

void solve(){
  int n;
  cin >> n;
  vector<pt> a(n);
  for (int i =0; i < n; i++) cin >> a[i].ff >> a[i].ss;

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

  ll ans = 0;
  for (auto i : a){
    ll cur = i.ff + ans;
    cur %= i.ss;
    if (cur) ans += i.ss - cur;
  }
  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


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

using namespace std;

int main() {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
        int n, m;
        scanf("%d%d", &n, &m);
        vector<int> a(n + 10, 0);
        for (int i = 0; i < m; i++) {
                int l, r;
                scanf("%d%d", &l, &r);
                a[l]++;
                a[r + 1]--;
        }
        int sum = 0, ans = 0;
        for (int i = 1; i <= n; i++) {
                int cur = sum + a[i];
                if (cur == m) {
                        ans++;
                }
                sum += a[i];
        }
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

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

    vector<long> x(N), y(N), h(N);
    for (int i = 0; i < N; ++i)
        cin >> x[i] >> y[i] >> h[i];

    vector<long> i1, i2;
    for (int i = 0; i < N; ++i)
        ((h[i] > 0) ? i1 : i2).push_back(i);

    
    for (int cx = 0; cx <= 100; ++cx)
    {
        for (int cy = 0; cy <= 100; ++cy)
        {
            auto get = [&](long i) { return h[i] + abs(x[i] - cx) + abs(y[i] - cy); };
            int ch = -1;
            for (auto i : i1)
            {
                int ch2 = get(i);
                if (ch >= 0 and ch != ch2)
                {
                    ch = -1;
                    break;
                }
                else
                    ch = ch2;
            }
            if (ch >= 0)
            {
                for (auto i : i2)
                {
                    int h2 = ch - abs(x[i] - cx) - abs(y[i] - cy);
                    if (h2 <= 0) continue;

                    ch = -1;
                    break;
                }
            }
            if (ch > 0)
                cout << cx << " " << cy << " " << ch << endl;
        }
    }
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    H1, M1, H2, M2, K = map(int, input().split())

    if H1 == H2:
        time = M2 - M1
    else:
        time = (60 - M1) + (H2 - H1 - 1) * 60 + M2

    ans = time - K
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
S = input()
message = "No"
if S == S[::-1]:
	index = (len(S)-1)//2
	test = S[:index]
	if test == test[::-1]:
		index2 = (len(S)+3)//2
		otest = S[index2-1:]
		if otest == otest[::-1]:
			message = "Yes"
print(message)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)

int main (){
  int F[100][14];
  int P[100][15];
  int n;
  cin>>n;

  r(i,n){
      for(int j=0; j<10; j++)cin>>F[i][j];
    }
    for(int i=0; i<n;i++)for(int j=0;j<11;j++)cin>>P[i][j];

    int res=-(1<<30);

    for(int b=1;b<(1<<10);b ++){
      int cc =0;
      for(int i=0; i<n;i++){
        int c=0;
        for (int j=0; j<10; j++) if(( b>>j &1)&& F[i][j])c++;
        cc += P[i][c];
      }
      if(res<cc) res = cc ;
    }
    cout<<res<<endl;

    return 0;
  }


Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += bisect_left(L,L[i]+L[j])-(j+1)
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    string S;
    cin>>N>>S;
    int l=0,r=0;
    int lm=0,rm=0;
    rep(i,N){
        if(S[i]=='(') l++;
        else l--;
        lm=min(lm,l);
    }
    rep(i,N){
        if(S[N-1-i]==')') r++;
        else r--;
        rm=min(rm,r);
    }
    int lx=abs(lm);
    int rx=abs(rm);
    //if(lx+l>rx+r) rx+=lx+l-r;
    //else if(lx+l<rx+r)lx+=rx+r-l;
    rep(i,lx) cout<<'(';
    cout<<S;
    rep(i,rx) cout <<')';
    cout<<endl;




}

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

typedef long long ll;

ll mod = 1e9+7;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x%mod;
        x = x*x%mod;
        n = n>>1;
    }
    return ans;
}

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

    vector<ll> a(K-1+1), comb_a(K-1+1), b(N-K+1+1), comb_b(N-K+1+1);
    comb_a[0] = 1;
    comb_b[0] = 1;
    for (ll j=1;j<=K-1;j++){
        a[j] = mpow(j, mod-2);
        comb_a[j] = (comb_a[j-1]*(K-1-j+1)%mod)*a[j]%mod;
    }
    for (ll j=1;j<=N-K+1;j++){
        b[j] = mpow(j, mod-2);
        comb_b[j] = (comb_b[j-1]*(N-K+1-j+1)%mod)*b[j]%mod;
    }

    for (ll i=1;i<=K;i++){
        ll ans = comb_a[i-1];
        if (i <= N-K+1){
            ans *= comb_b[i];
            ans %= mod;
        }else ans = 0;
        cout << ans << endl;
    }

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, mx_l, mx_r;
    scanf("%d", &n);
    vector<int> md(n);
    vector<pair<int, int>> x(n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &x[i].first);
        x[i].second = i;
    }
    sort(x.begin(), x.end());
    mx_l = x[n / 2 - 1].first;
    mx_r = x[n / 2].first;
    for (int i = 0; i < n / 2; ++i)
    {
        md[x[i].second] = mx_r;
    }
    for (int i = n / 2; i < n; ++i)
    {
        md[x[i].second] = mx_l;
    }
    for (int i = 0; i < n; ++i)
    {
        printf("%d\n", md[i]);
    }
}



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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define minit(a,b) memset(a,b,sizeof(a))

typedef long long lint;

struct UnionFind {
private:
	vector< int > data;
	
public:
	UnionFind(int _size) : data(_size, -1) {}
	
	bool unite(int _x, int _y) {
		_x = root(_x); _y = root(_y);
		if (_x != _y) data[_x] += data[_y]; data[_y] = _x;
		return _x != _y;
	}
	
	bool same(int _x, int _y) { return root(_x) == root(_y); }
	
	int root(int _x) { return data[_x] < 0 ? _x : data[_x] = root(data[_x]); }
	
	int size(int _x) { return -data[root(_x)]; }
};

int N, Q, p[100010];
char q[100010];
int mark[100010], v[100010];

void solve() {
	UnionFind uf(N+1);
	
	for_(i,1,N+1) if (!mark[i]) uf.unite(p[i], i);
	
	lint ans = 0;
	
	for_rev(i,Q-1,0) {
		if (q[i] == 'M') {
			--mark[ v[i] ];
			if (!mark[ v[i] ]) uf.unite(p[ v[i] ], v[i]);
		} else {
			ans += uf.root(v[i]);
		}
	}
	
	cout << ans << endl;
}

int main() {
	while (scanf("%d %d", &N, &Q), N) {
		for_(i,2,N+1) {
			scanf("%d", &p[i]);
		}
		
		minit(mark, 0);
		mark[1] = 1;
		
		for_(i,0,Q) {
			scanf("%s %d", &q[i], &v[i]);
			if (q[i] == 'M') ++mark[ v[i] ];
		}
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 2884
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read() {
	LL x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
int a, b, c;
int main() {
	a = read(); b = read(); c = read();
	cout << (((a == b && b != c) + (b == c && a != c) + (a == c && a != b) == 1) ? "Yes\n" : "No\n");
	return 0;
}

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

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  int n,m,ans=0;
  cin>>n>>m;
  vector<ll> a[100010];
  rep(i,n){
    ll x,y;cin>>x>>y;
    a[x].push_back(y);
  }
  priority_queue<ll> p;
  for(ll i=1;i<=m;i++){
    for(auto tmp:a[i]) p.push(tmp);
    if(!p.empty()){
      ans+=p.top();
      p.pop();
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5632
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int cnt = 0;
    
    for(int i = 0; i < 3; i++){
      if(s.charAt(i) == t.charAt(i)){
       cnt++; 
      }
    }
    
    System.out.println(cnt);
  }
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

signed main(){
    int N;cin>>N;
    vint A(N);rep(i,N)cin>>A[i];
    vint B(N);rep(i,N)cin>>B[i];

    priority_queue<pint>que;
    rep(i,N){
        if(A[i]!=B[i])que.emplace(B[i],i);
    }

    int ans=0;
    while(que.size()){
        int val;
        int i;
        tie(val,i)=que.top();
        que.pop();
        int d=B[(i+1)%N]+B[(i+N-1)%N];
        if(B[i]<=d){
            cout<<-1<<endl;
            return 0;
        }

        int r=B[i]%d;
        if(r>A[i]){
            ans+=B[i]/d;
            B[i]=r;
            que.emplace(B[i],i);
            continue;
        }
        if(B[i]>=A[i]&&(B[i]-A[i])%d==0){
            ans+=(B[i]-A[i])/d;
            B[i]=A[i];
            continue;
        }
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9456
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int sums =0;
    String S = String.valueOf(N);
    for(int i=0;i<S.length();i++){
      sums = sums+Integer.parseInt(S.substring(i,i+1));
    }
    if(N%sums==0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  

  
}

Measured memory_bytes: 21844
import sys
from bisect import bisect_left, bisect_right
N=int(sys.stdin.readline().strip())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

F=factorization(N)

L=[1]
for i in range(2,51):
    L.append(L[-1]+i)

ans=0
for x,y in F:
    if x==1: continue
    ans+=bisect_right(L,y)
print ans

Measured memory_bytes: 66272
// #line 2 "weighted_union_find.hpp"
#ifndef Weighted_union_find_hpp
#define Weighted_union_find_hpp
#include <cassert>
#include <cstddef>
#include <vector>

template <class Abel>
class weighted_union_find
{
    size_t n;
    std::vector<int> link;
    std::vector<Abel> diff_weight;

public:
    explicit weighted_union_find(size_t _n) : n(_n), link(n, -1), diff_weight(n) {}

    size_t find(const size_t x)
    {
        assert(x < n);
        if(link[x] < 0) return x;
        const size_t root = find(link[x]);
        diff_weight[x] += diff_weight[link[x]];
        return link[x] = root;
    }

    size_t size() const { return n; }
    size_t size(const size_t x) { return -link[find(x)]; }

    Abel weight(size_t x) { return find(x), diff_weight[x]; }

    Abel diff(size_t x, size_t y) { return weight(y) - weight(x); }

    bool same(const size_t x, const size_t y) { return find(x) == find(y); }

    bool unite(size_t x, size_t y, Abel w)
    {
        w += weight(x) - weight(y);
        x = find(x), y = find(y);
        if(x == y) return false;
        if(link[x] > link[y]) std::swap(x, y), w = -w;
        link[x] += link[y], link[y] = x;
        diff_weight[y] = w;
        return true;
    }
}; // class weighted_union_find

#endif

#include <iostream>

main()
{
    using namespace std;
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n,m; cin>>n>>m;
    weighted_union_find<long long> uf(n);
    while(m--)
    {
        int l,r,d; cin>>l>>r>>d;
        --l,--r;
        if(uf.same(l,r))
        {
            if(uf.diff(l,r)!=d)
            {
                cout << "No" << "\n";
                return 0;
            }
        }
        else
        {
            uf.unite(l,r,d);
        }
    }
    cout << "Yes" << "\n";
}

Measured memory_bytes: 1408
#include <stdio.h>
int main(void){
    // Your code here!
    int h, m, H, M, k;
    scanf("%d %d %d %d %d", &h, &m, &H, &M, &k);
    printf("%d", 60 * (H - h) + M - m - k);
    return (0);
}


Measured memory_bytes: 1732
yen = int(input())
'''
happy= 0
while yen > 499:
  yen -= 500
  happy += 1000

while yen > 4:
  yen -=5
  happy += 5
'''
happy = 1000 * int(yen//500) + 5 * int((yen - (500 * int(yen//500)))//5)

print(happy)


Measured memory_bytes: 9084
K, N = map(int, input().split()) 
A = list(map(int, input().split()))
res = [0 for _ in range (N)]
for i in range(N-1):
  res[i] = K - max(A[i+1]-A[i], A[i]-A[i-1])
res[N-1] = K - max(A[N-1]-A[N-2], A[0]+K-A[N-1])
print(min(res))

Measured memory_bytes: 26420
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {

  string S;
  int K;
  cin >> S >> K;

  for(int i = 0;i < S.size();i++) {
    int n = (26 - (S.at(i) - 'a')) % 26;
    if(K >= n) {
      S.at(i) = 'a';
      K -= n;
    }
    if(K <= 0) break; 
  }

  int N = S.size();
  S.at(N-1) = (S.at(N-1) - 'a' + K) % 26 + 'a';

  cout << S << endl;

}


Measured memory_bytes: 512
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #

*/

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

typedef long long int LLi;
typedef long long LL;
typedef vector<LLi> VLL;
typedef vector<string> VS;
typedef vector<pair<LLi, LLi> > VP;


#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;

LLi max_3(LLi a, LLi b, LLi c)
{
    return max(a,max(b,c));
}
LLi min_3(LLi a, LLi b, LLi c)
{
    return min(a,min(b,c));
}

main()
{
    LLi q,t;
  //  cin>>t;
  //  while(t--)
  //  {
        LLi a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
        LLi aa[1000];
        LLi flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
        LLi ma=0, mi=100000000;
        LLi mid=0, temp=0, stop=0, start=0;
        double pi= 3.141592653589793;
        double d1=0.0, d2, d3, d4;
        VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
        VS vs, vs1, vs2, vs3, vs4;
        VP vp, vp1,vp2;
        char ch, ch1, ch2;
        string str, str1, str2, str3, str4, str5;
        pair<LLi, LLi> pa;
        list<LLi> li, li1;
        map<LLi, LLi> mp, mp1;
        set<LLi> st;
        map<LLi ,LLi> :: iterator imll;
        VLL :: iterator ivll;
        set<LLi> :: iterator isll;
        VP :: iterator ivp;

        cin>>a>>b>>c>>d>>f;
        if(a==0)cout<<1<<endl;
        else if(b==0)cout<<2<<endl;
        else if(c==0)cout<<3<<endl;
        else if(d==0)cout<<4<<endl;
        else cout<<5<<endl;

  //   }
    exit()

}


Measured memory_bytes: 3588
import math

N = int(input())
T = []
A = []
for _ in range(N):
    t, a = [int(x) for x in input().split()]
    T.append(t)
    A.append(a)

t = T[0]
a = A[0]
for i in range(1, N):
    r1 = -(-t // T[i])
    r2 = -(-a // A[i])
    minR = min(r1, r2)
    maxR = max(r1, r2)
    if minR * T[i] >= t and minR * A[i] >= a:
        t = minR * T[i]
        a = minR * A[i]
    else:
        t = maxR * T[i]
        a = maxR * A[i]

    # print("r1:{},r2:{}".format(r1, r2))
    # print("t:{},a:{}".format(t, a))
    # print("---")

print(t + a)


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

int power_10(int x) {
  int ans = 1;
  for(int i = 0; i < x; i++) {
    ans *= 10;
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  
  int N_1, N_2;
  N_1 = N;
  N_2 = N;
  
  //Nの桁数をxとする
  int x = 1;
  for(int i = 0; i < 10; i++) {
    if(N / 10 > 0) {
      x++;
      N /= 10;
    }
    else
      break;
  }
  
  //Nの各位の数の和をSとする
  int S = 0;
  for(int i = 0; i < x; i++) {
    S += N_1 / power_10(x - 1);
    N_1 %= power_10(x - 1);
    N_1 *= 10;
  }
  
  if(N_2 % S == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

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

int main()
{
  int h1,h2,k1,k2;
  int a,b,c,d;
  int name1 = 0 ,name2 = 0;

  cin >> h1 >> h2 ;
  cin >> k1 >> k2 ;
  cin >> a >> b >> c >> d;

  name1 = h1*a + h2*b;
  name2 = k1*a + k2*b;

  if(h1 >= 10 || k1 >= 10)
    {
      name1 += (h1/10)*c;
      name2 += (k1/10)*c;
    }
  if(h2 >= 20 || k2 >= 20)
    {
      name1 += (h1/20)*d;
      name2 += (k2/20)*d;
    }
  if(name1 > name2)
    {
      cout << "hiroshi" << endl;
    }
  else if(name1 == name2)
    {
      cout << "even" << endl;
    }
  else
    {
      cout << "kenjiro" << endl;
    }
}



Measured memory_bytes: 3096
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    double x[n+1];
    double y[n+1];
    int i;
    for(i=0; i<n; i++){
        scanf("%lf %lf",&x[i],&y[i]);
    }
    x[n]=x[0];
    y[n]=y[0];
    double v_x[n+1];
    double v_y[n+1];
    for(i=0; i<n; i++){
        v_x[i]=x[i+1]-x[i];
        v_y[i]=y[i+1]-y[i];
    }
    v_x[n]=v_x[0];
    v_y[n]=v_y[0];
    int S=1;
    int T;
    for(i=0; i<n; i++){
        if(v_x[i]*v_y[i+1]-v_x[i+1]*v_y[i] >= 0){
            T=1;
        } else {
            T=0;
        }
        S = S*T;
    }
    if(S != 0){
        printf("1\n");
    } else {
        printf("0\n");
    }
    
    return 0;
}


Measured memory_bytes: 2756
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,mod=1e9+7,f[1000005],fac[1000005],fi[1000005],inv[1000005],ans;
long long c(long long x,long long y)
{
	return fac[x]*fi[y]%mod*fi[x-y]%mod;
}
int main()
{
	cin>>n;
	fac[0]=fac[1]=inv[0]=inv[1]=fi[0]=fi[1]=1;
    for (i=2;i<=1000000;i++)  
    {  
        fac[i]=fac[i-1]*i%mod;
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        fi[i]=fi[i-1]*inv[i]%mod;
    }
    for (i=(n+1)/2;i<n;i++)
    {
		f[i]=c(i-1,n-i-1)*fac[i]%mod*fac[n-i-1]%mod;
	}
    for (i=(n+1)/2;i<n;i++)
	{
		(ans+=(f[i]-f[i-1])*i)%=mod;
	}
    cout<<(ans%mod+mod)%mod;
    return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		string s;
		cin >> s;
		if(s == "Sunny")cout << "Cloudy" << endl;
		else if(s == "Cloudy")cout << "Rainy" << endl;
		else if(s == "Rainy")cout << "Sunny" << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N;
ll A[200000];

ll err(int k) {
	ll result = 0;

	for (int i=0; i<N; i++) {
		result += abs(A[i] - (k + i + 1));
	}

	return result;
}

bool is_ok(int b) {
	return (err(b-1) >= err(b));
}

ll find_max_ok(ll lower, ll upper) {
	if (!is_ok(lower)) return -1; // 存在しない

	ll ok = lower;
	ll ng = upper;

	while(ng - ok > 1) {
		ll trying = (ng + ok) / 2;

		if (is_ok(trying)) {
			ok = trying;
		} else {
			ng = trying;
		}
	}

	return ok;
}

int main() {
	cin >> N;

	for (int i=0; i<N; i++) {
		cin >> A[i];
	}

	ll b = find_max_ok(-1000000000, 1000000000);

	ll ans = err(b);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5108
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        ArrayList<Integer> A = new ArrayList<>();

        for(int i = 0; i < n; i++) {
        	int query = sc.nextInt();

        	if(query == 0) {
        		int x = sc.nextInt();
        		A.add(x);
        	}
        	if(query == 1) {
        		int p = sc.nextInt();
        		System.out.println(A.get(p));
        	}
        	if(query == 2) {
        		A.remove(A.size() - 1);
        	}
        }
	}

}



Measured memory_bytes: 140364
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7


def main():
    N = INT()
    A = LIST()

    # 上昇列に分割する
    s = 0
    curr = A[0]
    money = 1000
    for i in range(1, N):
        # print(i, A[i], money)
        if curr <= A[i]:
            # print("A")
            curr = A[i]
        else:
            # print("B")
            n = money // A[s]   # 個買う
            money -= n*A[s]
            money += curr * n
            s = i
            curr = A[s]
    if curr == A[N-1] and s != N-1:
        n = money // A[s]   # 個買う
        money -= n*A[s]
        money += curr * n
    print(money)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9244
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int a[200005];
int sum[200005];
int main()
{
	ll K,N;
	cin>>K>>N;
	int ans = K;
	for( int i=0; i<N; i++ )
	{
		cin>>a[i];
	}
	for( int i=0; i<N; i++ )
	{
		int st = a[i];
		int ed = i==0?a[N-1]:a[i-1];
		int dis = ed>st?ed-st:ed+K-st;
		ans = min(ans,dis);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
	char c[9][9];
	int i , j , flag , n[10][10] = {0};
	while(scanf("%s" , &c[0][0])!=EOF){
		for(i=1;i<8;i++){
			scanf("%s" , &c[i][0]);
		}
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				n[i+1][j+1] = c[i][j] - '0';
			}
		}
		flag = 0;
		for(i=1;i<9;i++){
			for(j=1;j<9;j++){
				if(n[i][j] == 1){
					flag = 1;
					break;
				}
			}
			if(flag) break;
		}
		//C or E
		if(n[i+1][j]==0){
			if(n[i][j+2]==1) printf("C");
			else printf("E");
		//A , B , D , F or G
		}else{
			//D or G
			if(n[i+1][j-1]==1){
				if(n[i][j+1]==0) printf("D");
				else printf("G");
			//A , B or F
			}else{
				if(n[i][j+1]==1) printf("A");
				else if(n[i+2][j]==1) printf("B");
				else printf("F");				
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
using System;

class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int H, W, A, B;
            H = int.Parse(input[0]);
            W = int.Parse(input[1]);
            A = int.Parse(input[2]);
            B = int.Parse(input[3]);
            Console.WriteLine(Solve(H, W, A, B));
        }

        static int Solve(int H, int W, int A, int B)
        {
            int modulo = 1000000007;
            Modulo md = new Modulo(H + W - 2, modulo);
            int ans = 0;
            var y = H - A - 1;
            for (int i = 0; i < W - B; i++)
            {
                ans += md.Multiply(md.Combination(y + B + i, y), md.Combination(A - 1 + W - B - i - 1, A - 1));
                ans %= modulo;
            }
            return ans;
        }
    }

    class Modulo
    {
        private readonly int M = 1000000007;
        private readonly int[] m_facs;

        public Modulo(int n, int m)
        {
            m_facs = new int[n + 1];
            m_facs[0] = 1;
            for (int i = 1; i <= n; ++i)
            {
                m_facs[i] = Multiply(m_facs[i - 1], i);
            }
            M = m;
        }

        public int Multiply(int a, int b)
        {
            return (int)(Math.BigMul(a, b) % M);
        }

        public int Factorial(int n)
        {
            return m_facs[n];
        }

        public int Pow(int a, int m)
        {
            switch (m)
            {
                case 0:
                    return 1;
                case 1:
                    return a;
                default:
                    int p1 = Pow(a, m / 2);
                    int p2 = Multiply(p1, p1);
                    return ((m % 2) == 0) ? p2 : Multiply(p2, a);
            }
        }

        public int Divide(int a, int b)
        {
            return Multiply(a, Pow(b, M - 2));
        }

        public int Combination(int n, int r)
        {
            if (n < r) { return 0; }
            if (n == r) { return 1; }
            int res = Factorial(n);
            res = Divide(res, Factorial(r));
            res = Divide(res, Factorial(n - r));
            return res;
        }

        public int Permutation(int n, int r)
        {
            if (n < r) { return 0; }
            if (n == r) { return 1; }
            int res = Factorial(n);
            res = Divide(res, Factorial(n - r));
            return res;
        }
    }

Measured memory_bytes: 13192
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
const int mod = 1000000007;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
using namespace std;
int n;
vector<int>a, b, c;
int main() {
	cin >> n;
	a.resize(n, 0); b.resize(n, 0); c.resize(n, 0);
	rep(i, n) cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n)cin >> c[i];
	sort(ALL(a)); sort(ALL(b)); sort(ALL(c));
	ll ct = 0;
	rep(i, n) {
		ll an = lower_bound(ALL(a), b[i]) - a.begin();
		ll cn = n-(upper_bound(ALL(c), b[i]) - c.begin());
		ct += an * cn;
	}
	cout << ct << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

double abs(double a){
  return a >= 0 ? a : -a;
}

int main(void) {
 int n, t, a, i, ans = -10000000, h, ansn;
  scanf("%d%d%d", &n, &t, &a);
  for(i = 0; i < n; ++i) {
    scanf("%d", &h);
    if(abs(t - (double)h * 0.006 - a) < abs(t - (double)ans * 0.006 - a)) ans = h, ansn = i + 1;
  }
  printf("%d", ansn);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());

        int ans;
        if (N % 2 == 0)
        {
            ans = N;
        }
        else
        {
            ans = N * 2;
        }

        Console.WriteLine(ans);
    }
    
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
long long rlim[4005],blim[4005],dp[4005][4005],mod=998244353,f1,f2,g1,g2,h1,h2,n,m,i,j;
string st;
int main()
{
	cin>>st;n=st.length();
	st=" "+st;
	memset(rlim,0,sizeof(rlim));
	memset(blim,0,sizeof(blim));
	fz1(i,n)
	{
		g1+=2-(st[i]-'0');
		g2+=st[i]-'0';
		rlim[max(0ll,f1)]=max(rlim[max(0ll,f1)],g2);
		blim[max(0ll,f2)]=max(blim[max(0ll,f2)],g1);
		if (st[i]=='0') {if (h1) h1--; else f1++;h2++;}
		if (st[i]=='2') {h1++;if (h2) h2--; else f2++;}
	}
	fz1(i,g1) rlim[i]=max(rlim[i-1],rlim[i]);
	fz1(i,g2) blim[i]=max(blim[i-1],blim[i]);
	dp[0][0]=1;
	fz0g(i,g1)
	{
		fz0g(j,g2)
		{
			if (rlim[i]<j||blim[j]<i) continue;
			(dp[i+1][j]+=dp[i][j])%=mod;
			(dp[i][j+1]+=dp[i][j])%=mod;
		}
	}
	cout<<dp[g1][g2]<<endl;
	return 0;
}

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

int main() {
  char b;
  cin >> b;
  if(b == 'A'){
    cout << "T" << endl;
  }
  if(b == 'T'){
    cout << "A" << endl;
  }
  if(b == 'C'){
    cout << "G" << endl;
  }
  if(b == 'G'){
    cout << "C" << endl;
  }

  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll llabs(ll a){return a<0?-a:a;}
ll N,Z,W,a,b;
int main(){
    cin>>N>>Z>>W;
    if(N==1){
        cin>>a;
        cout<<llabs(a-W)<<endl;
        return 0;
    }
    while(--N)cin>>a;
    cin>>b;
    cout<<max(llabs(a-b),llabs(b-W))<<endl;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;

	int maxValue = 1000000;

	for (int ii = 1; ii < maxValue; ++ii){
		int aho = ii * 0.08;
		int hoge = ii * 0.1;
		if ((aho == A) && (hoge == B)){
			cout << ii << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256