akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n,m;
    cin >> n >> m;
    vi a(n);
    rep(i,n) cin >> a[i];
    vector<pii> in(m),sec;
    rep(i,m){
        cin >> in[i].first >> in[i].second;
        in[i].first--;
        in[i].second--;
        in[i].second *= -1;
    }
    sort(all(in));
    int ma = -1;
    rep(i,m){
        in[i].second *= -1;
        if(in[i].second <= ma)continue;
        sec.push_back(in[i]);
        ma = in[i].second;
    }
    vi ne(n);
    m = sec.size();
    /*
    cout << "sec" << endl;
    rep(i,m)cout << sec[i].first << " " << sec[i].second << endl;
    */
    j = 0;
    rep(i,n){
        if(i)ne[i] = max(ne[i-1], i+1);
        if(j < m-1 && sec[j+1].first <= i)j++;
        if(j == m || i < sec[j].first) ne[i] = i+1;
        else ne[i] = sec[j].second + 1;
        if(j < m && i >= sec[j].second) j++;
        //cout << " " << i << " " << ne[i] << endl;
    }
    vi dp(n+1,0);
    rep(i,n){
        dp[i+1] = max(dp[i+1], dp[i]);
        dp[ne[i]] = max(dp[ne[i]], dp[i] + a[i]);
    }

    cout << dp[n] << endl;

}



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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

int main()
{
    int a, b;
    ci >> a >> b;

    co << max(a + b, max(a + a - 1, b + b - 1)) << en;
    
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    stack<int> s;
    for (int i = 0; i < n; i++)
        s.push(gi());
    ll l = 2, r = 2;
    for (int i = 0; i < n; i++) {
        ll x = s.top(); s.pop();
        ll mn = (l/x)*x; if (mn < l) mn += x;
        ll mx = (r/x)*x;
        l = mn; r = mx+x-1;
        if (l > r) {
            printf("-1\n");
            return 0;
        }
    }

    cout << l << " " << r << endl;

    return 0;
}


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

int main()
{
    int c[3][3], a[3], b[3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }
    a[0] = 0;
    for (int i = 0; i < 3; i++) b[i] = c[0][i] - a[0];
    for (int i = 1; i < 3; i++) a[i] = c[i][0] - b[0];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (c[i][j] != a[i] + b[j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())

n = 2 * 10 ** 5
k = 2 * 10 ** 5
mod = 10**9 + 7

modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
    modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def prepare_binomial_coefficients(n, k):
    for i in range(1,n+1):
        bc_num[i] = i * bc_num[i-1] % mod
    bc_num[0] = 0
    for i in range(1,k+1):
        bc_den[i] = modinv_table[i] * bc_den[i-1] % mod
    return

def binomial_coefficients(n, k):
    if n == 0 and k == 0:
        return 1
    return bc_num[n] * bc_den[k] * bc_den[n-k] % mod

bc_num = [1]*(n+1)
bc_den = [1]*(n+1)
prepare_binomial_coefficients(n, n)

mids = [0]*(w-b)
dis_mid = h - a - 1
for i in range(w-b):
    mids[i] = binomial_coefficients(dis_mid+i+b,i+b)

#print(mids)

mids_down = [0]*(w-b)
dis_mid = a
for i in range(w-b):
    mids_down[i] = binomial_coefficients(dis_mid+w-b-i-1,w-b-i-1)

#print(mids_down)

for i in range(w-b-1):
    mids_down[i] -= mids_down[i+1]

#print(mids_down)

for i in range(w-b):
    mids[i] = (mids[i] * mids_down[i]) % mod

#print(mids)

print(sum(mids)%mod)


Measured memory_bytes: 40224
#include <stdio.h>

int main(){
	long long int n;
	scanf("%lld", &n);
	
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0 && i % 5 == 0){
			continue;
		}
		if(i % 3 == 0){
			continue;
		}
		else if(i % 5 == 0){
			continue;
		}
		else{
			sum += i;
		}
	}
	
	printf("%lld", sum);
	
	return 0;
}

Measured memory_bytes: 3216
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>

const char main_[] = {
	0x48, 0xc7, 0xc0, 0x00, 0x00, 0x00, 0x00,
	0x48, 0x89, 0xf9,
	0x48, 0x83, 0xc1, 0x03,
	0x48, 0x0f, 0xb6, 0x17,
	0x48, 0x83, 0xfa, 0x31,
	0x75, 0x03,
	0x48, 0xff, 0xc0,
	0x48, 0xff, 0xc7,
	0x48, 0x39, 0xf9,
	0x75, 0xeb,
	0xc3
};

int main(void){
	int fd = open("/dev/zero", O_RDONLY);
	int (*solve)(char[]) = mmap(NULL, sizeof main_, PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
	memcpy(solve, main_, sizeof main_);

	char str[4];
	fgets(str, sizeof str, stdin);
	printf("%d\n", solve(str));

	close(fd);
	munmap(solve, sizeof main_);
	return 0;
}

Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A + 1):
  for j in range(B + 1):
    for k in range(C + 1):
      total = int(500*i + 100*j + 50*k)
      if total == X:
        count+=1
  
print(count)

Measured memory_bytes: 3060
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def main():
    n,k=map(int,input().split())
    p=list(map(int,input().split()))
    p=sorted(p)
    count=0
    for i in range(k):
        count+=p[i]
    print(count)








if __name__ == "__main__":

    main()

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define ZERO(a) memset(a,0,sizeof(a))

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, r;
  cin >> n >> r;

  ll ans;
  if (n < 10)
      ans = r + 100 * (10 - n);
  else
      ans = r;

  cout << ans << endl;

}



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

int main() {
  int N, X, D=0, count=1;
  cin >> N >> X;
  vector<int> L(N);
  REP(i,N) cin >> L[i];
  REP(i,N) {
    D+=L[i];
    if(D<=X) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
for _ in range(N):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)

ans = 0
for i in range(N-1,-1,-1):
  ans += (B[i]-(A[i]+ans))%B[i]
print(ans)

Measured memory_bytes: 11048
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n, tmp, sz=0;
	vector<int> v, ans;

	cin>> n;
	v.resize(n+1);
	ans.resize(n+1);
	for(int i=1;i<n+1;i++) cin>> v[i];
	for(int i=1;i<n+1;i++) ans[i]=0;

	for(int i=n;i>0;i--){
		tmp=v[i];
		for(int j=i*2;j<=n;j+=i){
			if(ans[j]) tmp++;
		}
		if(tmp%2==1){
			ans[i]=1;
			sz++;
			//cout<< "eee" << i <<endl;
		}
	}

	cout<< sz <<endl;
	for(int i=1;i<=n;i++){
		if(ans[i]) cout<< i << " ";
	}
	cout<< endl;

}

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

using namespace std;

int main(void) {
    string s, w;
    while (cin >> s) {
        int JOI = 0, IOI = 0;
        for (int i = 0; i < s.size(); i++) {
            w = s.substr(i, 3);
            if (w == "JOI") JOI++;
            else if (w == "IOI") IOI++;
        }
        cout << JOI << endl;
        cout << IOI << endl;
    }

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
int h,w,a,r,P,Q,i,p,M[26];main(){std::cin>>h>>w;for(i=0;i<h;i++){std::string s;std::cin>>s;for(auto c:s)M[c-'a']++;}for(p:M){if(p%2)P++;if((p-p%2)%4==2)Q++;}a=h*w%2,r=h%2*(w/2)+w%2*(h/2);puts((P!=a||Q>r||(r-Q)%2)?"No":"Yes");}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#define MAXA 100000
#define MAX 20000000000
#define s(i) scanf("%d", &(i))
#define p(i) printf("%d", (i))
#define ps() printf(" ") 
#define rer(i,j,k) for((i)=(j);(i)<(k);++(i))
#define ret(i,j,k) for((i)=(j);(i)>(k);--(i))
using namespace std;
int main(){
	double a,b;
	cin >> a >> b;
	cout << max(max((a+b),(a-b)),(a*b)) << endl;
	return 0;
}

Measured memory_bytes: 256
s = int(input())
a = []
ans = 0
i = 0
while ans == 0:
    if i == 0:
        a.append(s)
        i += 1
    else:
        if a[i - 1] % 2 == 0:
            a.append(a[i - 1] // 2)
        else:
            a.append(a[i - 1] * 3 + 1)
        if len(a) != len(set(a)):
            ans = i + 1
        i += 1
print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int A[100];
void print(int A[], int n)
{
	for (int i = 0; i < n-1; ++i)
	{
		cout<<A[i]<<" ";
	}
	cout<<A[n-1]<<endl;
}

int main(int argc, char const *argv[])
 {
 	int n;
 	cin>>n;
 	for (int i = 0; i < n; ++i)
 	{
 		cin>>A[i];
 	}

 	int flag = 1;
 	int cnt = 0;
 	while(flag)
 	{
 		flag = 0;
 		for (int i = n-1; i >= 1; --i)
 		{
 			if(A[i] < A[i-1])
 			{
 				int tmp = A[i];
 				A[i] = A[i-1];
 				A[i-1] = tmp;
 				cnt++;
 				flag = 1;
 			}
 		}
 	}
 	print(A,n);
 	cout<<cnt<<endl;
 	return 0;
 }

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

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

   vector<vector<ll>> dp(n+1, vector<ll>(k+1, 0));
   vector<ll> pref(k+1, 0);

   dp[0][0] = 1;

   for(int i=1; i<=n; i++)
   {
        int a;
        cin >> a;

        pref[0] = dp[i-1][0];
        for(int h=1; h<=k; h++)
            pref[h] = pref[h-1]+dp[i-1][h];

        for(int j=0; j<=k; j++)
        {
            ll l = pref[j];
            ll r = (j>a)? pref[j-a-1]: 0;
            dp[i][j] = (dp[i][j]+(l-r))%INTF;
        }
   }  

   cout<<dp[n][k];
    
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
const int N = 1010101;
int main() {
	int n;
	cin >> n;
	// エラトスネテスの篩は天才すぎんか？
	V a(n);
	V cnt(N);
	VE<bool> sieve(N, false);
	rep(i, n) {
		cin >> a[i];
		sieve[a[i]] = true;
		cnt[a[i]]++;
	}
	rep(i, N) {
		if (sieve[i]) {
			for (int j = i + i; j < N; j += i) sieve[j] = false;
		}
	}
	int ans = 0;
	rep(i, N) {
		ans += sieve[i] && cnt[i] == 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7908
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

vt permutation(vt n, vt k) { //modなし順列
	if (k == 1) return n;
	return permutation(n, k - 1) * (n - k + 1);
}

vt comb(vt n, vt k) { //modなし二項係数
	if (n < k) return 0;
	if (k == 0) return 1;
	return permutation(n, k) / permutation(k, k);
}

int main() {
	ll n;
	cin >> n;
	vector<string> v;
	rep(i, n) {
		string s;
		cin >> s;
		sort(all(s));
		v.push_back(s);
	}
	sort(all(v));
	ll ans = 0;
	ll i = 0;
	for (vt i = 0; i < n; ) {
		string value = v.at(i);
		vt cnt = 1;
		for (i = i + 1; i < n; i++) {
			if (value == v.at(i)) cnt++;
			else break;
		}
		ans += comb(cnt, 2);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5748
#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: 3076
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
using namespace std;
#define ll long long

int main () {
  ll n, x;
  cin >> n >> x;
  ll num[n + 1];
  num[0] = 1;
  num[1] = 5;
  ll p[n + 1];
  p[0] = 1;
  p[1] = 3;
  for (ll i = 2; i <= n; i++) {
    num[i] = 3 + num[i - 1] * 2;  
    p[i] = 1 + p[i - 1] * 2;
  }
  ll ans = 0;
  ll itr = n;
  while (1) {
    if (x == num[itr]) {
      ans = ans + p[itr];
      break;
    }
    if (x == 1 || x == 0) {
      break;
    }
    if (x >= 2 + num[itr - 1]) {
      ans = ans + p[itr - 1] + 1;
      x = x - (2 + num[itr - 1]);
      itr--;  
    }
    else {
      x--;
      itr--;  
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 888
chr_list = input().split()
number_list = list(map(int, input().split()))
chr = input()

ch_dict = {}
for each_ch, number in zip(chr_list, number_list):
    ch_dict[each_ch] = number

ch_dict[chr] = ch_dict[chr] - 1

for each_ch in chr_list:
    print(ch_dict[each_ch], end="")
    print(" ", end="")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)


int main(){
    ll K,A,B,bisket=1,rate = 0,nokori=0,hiritu=0;
    cin >> K >> A >> B;


    ll i = 0;

    hiritu = (A - 1) + 2;

    rate = hiritu + 1;

    while(i < K){
        if(A < B and rate < B){
            if(bisket < A and (i + A - bisket + 2 ) <= K){
                i += A - bisket;
                bisket = 0; //Aのビスケット変換
                i++;
                bisket += B;
                i++;
            }else if(bisket >= A and i < K - 1){
                nokori = (K - i) / 2;
                bisket += (B - A) * nokori;
                i += 2 * nokori;
            }else{
                bisket++;
                i++;
            }
            
        }else{
            bisket += K;
            break;
        }

    }

    rate = K + 1;

    if(rate <= bisket)
        cout << bisket << endl;
    else
        cout << rate << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
#define PI 3.141592653589793
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};


using namespace std;
using Graph = vector< vector<int> > ;


int main(){
    int n;
    cin >> n;
    int last;
    if (n <10){
        last = n;
    }else if (n < 100){
        last = n%10;
    }else{
        n %= 10;
        last = n %= 10;
    }
    if (last == 2 || last == 4 || last == 5 || last == 7 || last == 9){
        cout << "hon" << endl;
    }else if (last == 3){
        cout << "bon" << endl;
    }else{
        cout << "pon" << endl;
    }
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
const int ms = 1e5+9;
typedef long long ll;

ll vet[ms], n, soma[ms], m;

int main(){
  cin >> n >> m;
  for(int i = 1;i<=n;i++)cin >> vet[i];
	for(int i = 1;i<=n;i++)
    	soma[i] = (soma[i-1]+vet[i])%m;
  //for(int i = 0;i<=n;i++) cout<<soma[i];
  //cout<<endl;
  
  map<ll,ll> mapa;
  ll ans = 0;
  for(int i = 0;i<=n;i++)
    	mapa[soma[i]]++;
  for(auto it: mapa){
  	ans += (it.second*(it.second-1))/2;
  }
  cout<<ans;

}

Measured memory_bytes: 5760
import java.util.*;
public class Main {
	int i,runner;
	String time;
	Runner timeArray[] = new Runner[24];
	int flag[] = new int[timeArray.length];
	Runner subArray[] = new Runner[timeArray.length];
	void doIt(){
		Scanner sc = new Scanner(System.in);
		for(i = 0; i < timeArray.length; i ++ ){
			runner = sc.nextInt();
			time = sc.next();
			timeArray[i] = new Runner(runner,time);
		}
		for(i = 0; i < 3; i ++ ){
			Arrays.sort(timeArray,i * 8,i * 8 + 8);
			System.out.println(timeArray[i * 8].runner+" "+timeArray[i * 8].time);
			System.out.println(timeArray[i * 8 + 1].runner+" "+timeArray[i * 8 + 1].time);
			flag[i * 8] = 1;
			flag[i * 8 + 1] = 1;
		}
		subArray = timeArray.clone();
		for(i = 0; i < subArray.length; i ++ ){
			if(flag[i] == 1)subArray[i].time = "hoge";
		}
		Arrays.sort(subArray);
		System.out.println(subArray[0].runner+" "+subArray[0].time);
		System.out.println(subArray[1].runner+" "+subArray[1].time);
	}
	class Runner implements Comparable<Runner>{
		int runner;
		String time;
		Runner(int runner,String time){
			this.runner = runner;
			this.time = time;
		}
		@Override
		public int compareTo(Runner r){
			return time.compareTo(r.time);
		}
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}

Measured memory_bytes: 25864
#include <bits/stdc++.h>
 
#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
 
using namespace std;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const i64 MOD = 1000000007;
const int INF = 2000000000;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
    int n, l;
    cin >> n >> l;

    vi a(n+1, 0);
    int fl = 0;

    REP(i, 1, n) {
    	a[i] = i + l - 1;
    	fl += a[i];
    }

    int ch = a[1];

    REP(i, 2, n) {
		if (abs(ch) > abs(a[i])) {
			ch = a[i];
		}
    }

    cout << fl - ch << endl;

	return 0;
}

Measured memory_bytes: 256
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
res=[]


for i in range(1,y[0]+1):
    for j in range(z[i-1]):
        res=res+[i]

sw=0
for j in range(0,x[0]):
    if sw==0:  
        for i in range(j*x[1],(j+1)*x[1]):
            print(res[i],end=' ')
        sw=1
        print('')
        continue
    if sw==1:
        for i in range((j+1)*x[1]-1,j*x[1]-1,-1):
            print(res[i],end=' ')
        sw=0
        print('')
        continue
    

quit()

Measured memory_bytes: 3952
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int k;
	string s;
	cin >> k >> s;
	if(s.size() > k) cout << s.substr(0,k) << "..." << endl;
	else cout << s << endl;
	//cout << ans << endl;
}

Measured memory_bytes: 3632
N,Ma,Mb = map(int,input().split())

lis = [[float("inf")] * 401 for i in range(401)]
lis[0][0] = 0

for x in range(N):

    a,b,c = map(int,input().split())

    olis = []
    for i in lis:
        new = []
        for j in i:
            new.append(j)
        olis.append(new)

    for i in range(401):

        for j in range(401):

            if olis[i][j] != float("inf"):

                if i + a < 400 and j + b < 400:

                    lis[i+a][j+b] = min( olis[i][j] + c , lis[i+a][j+b] )

ans = float("inf")

for i in range(400):

    i += 1

    for j in range(400):

        j += 1

        if i * Mb == j * Ma:

            ans = min(ans , lis[i][j])

if ans == float("inf"):
    print (-1)
else:
    print (ans)


Measured memory_bytes: 110428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, A, B;
int h[100010];

int check(int m) {
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    ll tmp = h[i] - (ll)m * B;
    if (tmp < 0) continue;
    sum += (tmp + (A - B) - 1) / (A - B);
  }
  return sum <= m;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> A >> B;
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }  
  int ok = 1 << 30, ng = 0;
  while (ok - ng > 1) {
    int m = (ok + ng) / 2;
    if (check(m)) ok = m;
    else ng = m;
  }
  cout << ok << endl;

  return 0;
}

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

int main(){
    int n,ans=0;
    string s;
    cin>>n;
    rep(i,n){
        cin>>s;
        if(s=="E869120")ans++;
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 3192
def solve(a, b, k):
    if a % k == 0:
        return a % k == 0
    return a / k < b / k

assert solve(12, 14, 4)
assert solve(11, 11, 1)
assert solve(11, 12, 1)
assert solve(11, 12, 3)
assert solve(11, 12, 5) == False
assert solve(3, 3, 3)
assert solve(1, 2, 3) == False
assert solve(5, 7, 4) == False
assert solve(7, 7, 7)
assert solve(3, 7, 4)
assert solve(5, 8, 4)
assert solve(5, 9, 4)
assert solve(500, 600, 7)

k = int(raw_input())
a, b = map(int, raw_input().split())

print 'OK' if solve(a, b, k) else 'NG'



Measured memory_bytes: 64372
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
    LL x,y;
    cin >> x >> y;
    if (x < y) swap(x,y);
    if (x - y > 1) cout << "Alice" << endl;
    else cout << "Brown" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
  Node *cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  Node *cur = nil->next;
  int isf = 0;
  while(1){
    if(cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d",&n);
  init();
  for(i = 0; i < n; i++){
    scanf("%s%d",com, &key);
    if(com[0] == 'i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
	if(com[6] == 'F') deleteFirst();
	else if(com[6] == 'L') deleteLast();
      }
      else{
	deleteKey(key);
	nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}

Measured memory_bytes: 33812
//Kaori Miyazono, did I reach you ?
//"I can't die because... I have to protect you." -Asuna Yuuki

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

const int N = 100100;

int nums[N];
int cnt[N];
int ant[N];
int novo[N];
int n;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	vector< pair<int, int> > b;
	for(int i = 0; i < n; i++) {
		cin >> nums[i];
		b.push_back(make_pair(nums[i], i));
	}
	int on = 0;
	sort(b.begin(), b.end());
	for(int i = 0; i < n; i++){
		if (i == 0) {
			ant[on] = nums[b[i].second];
			novo[b[i].second] = on;
		} else {
			if (b[i].first > b[i - 1].first) {
				on++;
			}
			ant[on] = nums[b[i].second];
			novo[b[i].second] = on;
		}
	}
	/*for(int i = 0; i < n; i++) {
		cout << novo[i] << ' ';
	}
	cout << endl;*/
	for(int i = 0; i < n; i++) {
		cnt[novo[i]]++;
	}
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if (cnt[i] > ant[i]) {
			ans += cnt[i] - ant[i];
		} else if (cnt[i] < ant[i]) {
			ans += cnt[i];
		}
	}
	cout << ans;
	return 0;
}	






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


void solve(vector<int> Narray){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string N;
    cin >> N ;
    vector<int> Narray(N.size(),0);
    for (int i =0 ;i<N.size();i++){
        Narray[i] = stoi(N.substr(i,1));
    }
    vector<int> dp(N.size(),0);
    vector<int> dp_plus(N.size(),0);
    dp[0] = min(Narray[0],10-Narray[0]+1);
    dp_plus[0] = min(Narray[0]+1,10-Narray[0]);
    for (int i=1;i<N.size();i++){
        int digit = Narray[i];
        dp[i] = min(digit + dp[i-1],10-digit + dp_plus[i-1]);        
        dp_plus[i] = min(digit + 1 + dp[i-1],9-digit+ dp_plus[i-1]);        
    }
    printf("%d\n",dp[N.size()-1]);
    
    return 0;
}


Measured memory_bytes: 13060
$labels = <STDIN>; $labels =~ s/\s+$//;
$nums = <STDIN>; $nums =~ s/\s+$//;
$dec = <STDIN>; $dec =~ s/\s+$//;

($l1, $l2) = split (/ /, $labels);
($n1, $n2) = split (/ /, $nums);
if ($dec eq $l1) { 
  $n1 --;
} else {
  $n2 --;
}
print "$n1 $n2\n";


Measured memory_bytes: 512
import kotlin.math.max

fun main() {
    var m = 0
    var count = 0
    repeat(nextInt()) {
        val (x, y) = nextIntList()
        if (x == y) {
            count++
        } else {
            m = max(m, count)
            count = 0
        }
    }
    m = max(m, count)
    println(if (m >= 3) "Yes" else "No")
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 37940
class Tree:
    def __init__(self, N):
        self.N = N
        self.nodes = [ Node(i) for i in range(N) ]

    def get_root(self, node):
        if node.parent is None:
            return node
        root = self.get_root(node.parent)
        node.parent = root
        return root

    def merge(self, node1, node2):
        root1 = self.get_root(node1)
        root2 = self.get_root(node2)

        if root1.ID == root2.ID:
            return

        root1.parent = root2

    def get_root_count(self):
        count = 0
        for n in self.nodes:
            if n.parent is None:
                count += 1
        return count

class Node:
    def __init__(self, ID):
        self.ID = ID
        self.parent = None

def main():
    N, M = map(int, input().split())
    tree = Tree(N)
    for i in range(M):
        A, B = map(int, input().split())
        A, B = A-1, B-1
        tree.merge(tree.nodes[A], tree.nodes[B])
    print(tree.get_root_count() - 1)


main()


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

int main()
{
	int n;
	cin >> n;
	long long fib[50];
	fib[0] = fib[1] = 1;
	for (int i = 2; i <= n; i++) {
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	cout << fib[n] << endl;
	return 0;
}


Measured memory_bytes: 3100
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		
		
		int count = 0;
		for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(count);
		
	}
}


Measured memory_bytes: 26420
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...U>void _(const char*s,T h,U...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}//break continue pop_back
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=2e5+1;
int a[N],b[N];
int32_t main(){

    int n;
    cin>>n;
    forn(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n,std::greater<int>());
    forn(i,n){
        if(a[i]==b[0]){
            cout<<b[1]<<'\n';
        }else cout<<b[0]<<'\n';
    }
    return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int MAX=510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        //???
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
    COMinit();
    ll n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    //全2点間マンハッタン
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ll t=((n-i)*((m-j)*(i+j))%mod)%mod;
            if(i!=0&&j!=0) t*=2;
            //ななめは二通りあるから2倍
            ans=(ans+t)%mod;
        }
    }

    ans=(ans*COM(n*m-2,k-2))%mod;

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


Measured memory_bytes: 12160
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
	
def main():
	N = int(input())
	
	ans = 0
	for i in range(1, N+1, 2):
		tmp = make_divisors(i)
		if len(tmp) == 8:
			ans += 1
	
	print(ans)
	
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
	
if __name__ == "__main__":
	main()


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

int main()
{
    int n; cin >> n;
    string s, t1, t2; cin >> s;
    if(n % 2 == 0) {
        t1 = s.substr(0, n/2);
        t2 = s.substr(n/2, n/2);
        if(t1 == t2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#define N 200000000
#define INF 2000000000

int size;
int h[N];

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


void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= size && h[l] > h[i]) valM = l;
  else valM = i;
  if(r <= size && h[r] > h[valM]) valM = r;
  if(valM != i){
    swap(&h[i], &h[valM]);
    maxHeapify(valM);
  }
}

void hIncreaseKey(int i, int key){
  if(key < h[i]) return;
  h[i] = key;
  while(i>1 && h[i/2]<h[i]){
    swap(&h[i], &h[i/2]);
    i = i/2;
  }
}

void maxHeapInsert(int key){
  size++;
  h[size] = -INF;
  hIncreaseKey(size, key);
}

int heapExtractMax(){
  int valM;
  if(size < 1) return 0;
  valM = h[1];
  h[1] = h[size--];
  maxHeapify(1);
  return valM;
}


int main(){
  char input[20];
  size = 0;
  while(scanf("%s", input)){
    if(!strcmp(input, "end"))break;
    if(!strcmp(input, "extract")) printf("%d\n", heapExtractMax());
    else{
      char val[20];
      scanf("%s", val);
      maxHeapInsert(atoi(val));
    }
  }
  return 0;
}



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

static const int MOD = 1000000007;

const int N = 2020;
int C[N][N];

void init() {
        for (int i = 0; i < N; i ++) C[i][0] = C[i][i] = 1;
        for (int i = 1; i < N; i ++) {
                for (int j = 1; j < i; j ++) {
                        C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
                }
        }
}

int main() {
        init();
        int X, Y;
        cin >> X >> Y;
        int ans = X + 1;
        for (int s = 1; s <= X; s ++) {
                for (int t = 0; s + t <= X; t ++) {
                        if (s > Y - 1 || t > s - 1) continue;
                        int res = 1;
                        res = (long long) res * C[Y - 1][s] % MOD;
                        res = (long long) res * C[s - 1][t] % MOD;
                        res = (long long) res * C[X - s - t + 2][2] % MOD; //ways to place s and t
                        ans = (ans + res) % MOD;
                }
        }
        cout << ans << endl;
        return 0;
}


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

int main(){
  char c; cin >> c;
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,m,x=map(int,input().split())
book=[[]]
for i in range(n):
    book.append(list(map(int,input().split())))

ans=10**8
for mask in range(1,1<<n):
    mem=[0]*m
    c=0
    for i in range(n):
        if (mask & (1<<i)):
            c+=book[i+1][0]
            for j in range(m):
                mem[j]+=book[i+1][j+1]
    for j in range(m):
        if mem[j]<x:
            break
    else:
        ans=min(ans,c)
if ans==10**8:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9228
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n;

  cin >> n;

  for(int i=0;i*4<=n;i++){
    if((n - i*4) % 7 == 0) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	unsigned long long int n, fac;
	
	scanf("%llu", &n);
	
	if(n>=1 && n<=20){
		fac = n;
		fac = fac * (n-1);
		n = n-2;
		
		while(n>1){
			fac = fac * n;
			n = n-1;
		}
	
		printf("%llu\n", fac);
	}
	
	return 0;
	
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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;}

int main(){
  ll s;
  int n,k;cin>>n>>k>>s;
  if(s<1000000000){
    rep(i,k)cout<<s<<' ';
    rep(i,n-k)cout<<s+1<<' ';
  }else{
    rep(i,k)cout<<s<<' ';
    rep(i,n-k)cout<<1<<' ';
  }
}


Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstdio>
#include <random>
#include <chrono>
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define int long long
using namespace std;

const int INF = 2e17;
const int MOD = 1e9 + 7;

void solve() {
	int n, w;
	cin >> n >> w;
	vector<pair<int, int>> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	vector<vector<int>> dp(n + 1, vector<int>(1e5 + 1, INF));
	dp[0][0] = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < dp[i].size(); j++) {
			dp[i][j] = min(dp[i - 1][j],j - a[i].second >= 0 && a[i].first + dp[i - 1][j - a[i].second] <= w ? dp[i - 1][j - a[i].second] + a[i].first : INF);
		}
	}

	for (int i = dp[n].size() - 1; i >= 0; i--) {
		if (dp[n][i] != INF) {
			cout << i;
			return;
		}
	}
}



signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;

class State{
public:
  string name;
  int value;
  State(){}
  State(string n, int v):name(n), value(v){}

  bool operator < ( const State &s) const{
    //    if ( value == s.value ){
      if ( name.size() == s.name.size() ){
	return name < s.name;
      } else {
	return name.size() < s.name.size();
      }
      //    } else return value > s.value;
  }
  
};

main(){
  int n;
  map<string, int> mp;
  cin >> n;
  for ( int i = 0; i < n; i++ ){
    string name;
    int value;
    cin >> name >> value;
    mp[name] += value;
  }

  vector<State> S;
  for ( map<string, int>::iterator it = mp.begin(); it != mp.end(); it++ ){
    S.push_back(State((*it).first, (*it).second));
  }
  sort(S.begin(), S.end());

  for ( int i = 0; i < S.size(); i++ ){
    cout << S[i].name << " " << S[i].value << endl;
  }

}

Measured memory_bytes: 1236