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

using namespace std;

int cnt = 2;
int bit[maxn];
int a[maxn], b[maxn];

int main(){
	//freopen("out.txt", "w", stdout);
	puts("6597");
	printf("+ %d %d %d\n", 0, 1, 3);
	printf("+ %d %d %d\n", 3, 3, 3);
	printf("< %d %d %d\n", 0, 3, 3);
	bit[0] = ++cnt;
	for(int i = 1;i < 64;i++) printf("+ %d %d %d\n", bit[i - 1], bit[i - 1], bit[i] = ++cnt);
	int cur = ++cnt, tmp = ++cnt;
	
	printf("+ %d %d %d\n", 0, bit[0], 0);
	for(int i = 31;~i;i--){
		printf("+ %d %d %d\n", cur, bit[i], tmp);
		printf("< %d %d %d\n", tmp, 0, a[i] = ++cnt);
		printf("< %d %d %d\n", tmp, tmp, tmp);
		printf("+ %d %d %d\n", tmp, a[i], tmp);
		for(int j = 1;j <= i;j++) printf("+ %d %d %d\n", tmp, tmp, tmp);
		printf("+ %d %d %d\n", cur, tmp, cur);
	}
	
	printf("+ %d %d %d\n", 1, bit[0], 1);
	printf("< %d %d %d\n", cur, cur, cur);
	for(int i = 31;~i;i--){
		printf("+ %d %d %d\n", cur, bit[i], tmp);
		printf("< %d %d %d\n", tmp, 1, b[i] = ++cnt);
		printf("< %d %d %d\n", tmp, tmp, tmp);
		printf("+ %d %d %d\n", tmp, b[i], tmp);
		for(int j = 1;j <= i;j++) printf("+ %d %d %d\n", tmp, tmp, tmp);
		printf("+ %d %d %d\n", cur, tmp, cur);
	}
	
	
	for(int i = 0;i < 64;i++){
		printf("< %d %d %d\n", cur, cur, cur);
		for(int j = 0;j <= i;j++){
			if(j >= 0 && j <= 31 && i - j >= 0 && i - j <= 31){//debug:忘记判越界 
				printf("+ %d %d %d\n", a[j], b[i - j], tmp);
				printf("< %d %d %d\n", bit[0], tmp, tmp);
				printf("+ %d %d %d\n", cur, tmp, cur);
			}
		}
		for(int j = 1;j <= i;j++) printf("+ %d %d %d\n", cur, cur, cur);
		printf("+ %d %d %d\n", 2, cur, 2);
	}
}

Measured memory_bytes: 3680
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
# 0 ~ (p-1) は問題に選ばれる可能性が既にある（数が同じならそれ以降も）
# その他で逆転できるのはどれか
ans = [0] * n
for i in range(p):
    ans[i] = 1

index = p # まだ定まっていないもの
for i in range(p, n):
    if a[i] == a[p-1]:
        ans[i] = 1
        index += 1
    else:
        break

if index == n:
    print(sum(ans))
    exit()

# 選ばれていない中で最大: a[index]
# 選ばれている中で最小: a[index-1] => a[p-1] と考えることに修正
mn = a[p-1]

# 0 ~ (index-2)の index-1個 は必ず選ぶ。index-1は選ばない
# 残り、v - (index-1 + 1) 個をどう選ぶか

# 簡単な場合を先に処理
if v - p <= 0:
    for i in range(p, n):
        if a[i] + m >= mn:
            ans[i] = 1
        else:
            break
    print(sum(ans))
    exit()

# 小さいものにもvoteする必要がある場合（v - (index-1 + 1))個

# それより大きいものが何個あるかを求めておく
# それ以下のものも把握しておく（それ以下のものには何個配っても良い）:

large = [0] * n
small = [0] * n
for i in range(p, n):
    if i == p:
        large[p] = 0
        small[p] = n - 1 - p
    else:
        if a[i] == a[i-1]:
            large[i] = large[i-1]
            small[i] = small[i-1]
        else:
            large[i] = i - p
            small[i] = n - 1 - i


acum = [0] * (n+1)
for i in range(p-1, n):
    acum[i+1] = acum[i] + a[i]

for i in range(p, n):
    unvote = v - p - small[i]
    if unvote <= 0:
        if a[i] + m >= mn:
            ans[i] = 1
    else:
        if a[i] + m < mn:
            break
        # 分配する個数 large[i] -> index ~ index + large[i] - 1
        sm = acum[p + large[i]] - acum[p-1]
        if sm + unvote * m <= (a[i] + m) * (large[i]+1):
            ans[i] = 1

print(sum(ans))


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

int b[30];

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

    int n,m,c;
    cin>>n>>m>>c;

    for(int i=0;i<m;i++)cin>>b[i];

    int cnt=0;

    for(int i=0;i<n;i++)
    {
        int sum=0;
        for(int j=0;j<m;j++)
        {
            int a;
            cin>>a;
            sum+=a*b[j];
        }

        if(sum+c>0)cnt++;
    }

    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    string S;
  cin >> S;
  if(S == "ABC") S = "ARC";
    else S = "ABC";
  cout << S << endl;
    return 0;
}


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

using namespace std;

int m[32005][4005];
vector <int> p;

bool solve(int val, int ind){
    if(ind==p.size()){
        return (val==0);
    }
    int mval=val+16002;
    //assert(!(mval<0 || mval >= 32005 || ind >= 2005));
    if(m[mval][ind]!=-1){
        return m[mval][ind];
    }
    return m[mval][ind]=(solve(val-p[ind],ind+1) || solve(val+p[ind],ind+1));
}


int main(){
    string s;
    int x,y,n;
    cin >> s >> x >> y;
    s.push_back('T');
    n=s.size();
    vector <int> a[2];
    bool fi=1;
    int dir=0,steps=0;
    for(int i=0;i<n;i++){
        if(s[i]=='T'){
            if(fi){
                x-=steps;
                fi=0;
            }
            else{
                a[dir].push_back(steps);
            }
            dir=1-dir;
            steps=0;
        }
        else{
            steps++;
        }
    }
    memset(m,-1,sizeof(m));
    p=a[0];
    if(!solve(x,0)){
        cout << "No" << endl;
        return 0;
    }
    memset(m,-1,sizeof(m));
    p=a[1];
    if(!solve(y,0)){
        cout << "No" << endl;
        return 0;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    string s; cin >> s;
    rep(i, 3){
        if(s[i] == '1') s[i] = '9';
        else s[i] = '1';
    }
    cout << s << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7752
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

#define ll long long

using namespace std;

void next(int array[], int size){
    for(int i = 1; i <= size; i++){
        if(array[i] == 0){
            array[i] = 1;
            break;
        }else{
            array[i] = 0;
        }
    }
}

int main(){

    int n,m;
    cin >> n >> m;
    vector<vector<int>> s;
    vector<int> p;

    for(int i = 0; i < m; i++){
        int k;
        cin >> k;
        vector<int> tmpv;
        for(int j = 0; j < k; j++){
            int tmps;
            cin >> tmps;
            tmpv.push_back(tmps);

        }
        s.push_back(tmpv);
    }

    for(int i = 0; i < m; i++){
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }

    int count = 1;

    for(int i = 0; i < n; i++) count = count * 2;

    int ans = 0;
    int onoff[11] = {};

    for(int i = 0; i < count; i++){
        bool b = true;

        
        for(int j = 1; j <= m; j++){
            //jは電球の番号
            int tmpc = 0;
            vector<int> tmpv = s[j - 1];

            //つながっているスイッチのonの数を数える
            for(int k = 0; k < tmpv.size(); k++){
                if(onoff[tmpv[k]] == 1) tmpc++;
            }

            if(tmpc % 2 != p[j - 1]){
                b = false;
                break;
            }
        }

        if(b) ans++;

        next(onoff, n);
    }

    cout << ans << endl;

    return 0;

}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL a,b,c;
  cin >> a >> b >> c;
  if(a+b<c){
    cout << b+a+b+1 << endl;
  }else{
    cout << b+c << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

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

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    int H,W;
    int r;
    int c;
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            string s;
            cin >> s;
            if(s == "snuke"){
                r = i+1;
                c = j+1;
            }
        }
    }
    cout << (char)(64+c) << r << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  ll N, M;
  cin >> N >> M;

  vvi graph = vvi(N, vi());
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }

  vector<int> ans(N, -1);
  ans[0] = 0;
  queue<int> que;
  que.push(0);

  while (!que.empty()) {
    int node = que.front();
    que.pop();

    for (int adj : graph[node]) {
      if (ans[adj] != -1) continue;
      ans[adj] = node;
      que.push(adj);
    }
  }

  out("Yes");
  rep(i, N - 1) {
    out(ans[i + 1] + 1);
  }
}


Measured memory_bytes: 10008
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
 
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;
  //cin >> tc;
  while(tc--)
  {
    long double pi = 3.14159265358979323846;

    int r;
    cin >> r;
    long double ans = 2.0 * pi * r;
    cout << fixed << setprecision(20) << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

void solve(long long N, std::vector<long long> a){
    vector<ll> cumsum(N+1, 0);
    for(ll i = 0; i < N; ++i) cumsum[i+1] = cumsum[i] + a[i];
    ll ans = INF;
    //for(auto a : cumsum) cout << a << " ";
    //cout << endl;
    for(ll i = 1; i < N; ++i){
        //cout << cumsum[i] << " " << (cumsum[N] - cumsum[i]) << endl;
        ans = min(ans, abs(cumsum[i] - (cumsum[N] - cumsum[i])));
    }
    cout << ans << endl;
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 6428
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
using namespace std;
const int mod=1e9+7;
LL fac[mxn],ifc[mxn];
int n,m,sl,fh;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int _pow(int k,int i)
{
	int t=1;
	while(i)
	{
		if(i&1) t=1ll*t*k%mod;
		k=1ll*k*k%mod;i>>=1;
	}
	return t;
}
LL C(int x,int y)
{
	if(x<y)  return 0;
	return fac[x]*ifc[y]%mod*ifc[x-y]%mod;
}
int main()
{
	n=rd();m=rd();fac[0]=1;
	for(int i=1;i<=n;++i) fac[i]=i*fac[i-1]%mod;
	ifc[n]=_pow(fac[n],mod-2);
	for(int i=n;i;--i) ifc[i-1]=i*ifc[i]%mod;
	for(int i=1;i<=m;++i) printf("%lld\n",C(n-m+1,i)*C(m-1,i-1)%mod);
	return 0;
}

Measured memory_bytes: 2304
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <list>

int n, f;

std::vector<std::pair<int, int>> vec;

void func(std::vector<std::pair<int, int>>::iterator vec_begin, std::vector<std::pair<int, int>>::iterator vec_end, int& counter) {
    auto dis = std::distance(vec_begin, vec_end);
    auto e = std::min_element(vec_begin, vec_end);
    auto min_times = (*e).first;
    auto begin_index1 = e;
    auto end_index1 = std::next(e);
    for (auto it = vec_begin; it != begin_index1; it++) {
        (*it).second = min_times;
    }
    for (auto it = end_index1; it != vec_end; it++) {
        (*it).second = min_times;
    }
    counter += ((*e).first - (*e).second);
    if (begin_index1 != vec_begin) {
        func(vec_begin, begin_index1, counter);
    }
    if (end_index1 != vec_end) {
        func(end_index1, vec_end, counter);
    }
}

int main() {
    int counter = 0;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> f;
        vec.push_back(std::make_pair(f, 0));
    }
    func(vec.begin(), vec.end(), counter);
    std::cout << counter << std::endl;

}



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

int main() {
  int N,Q;
  long K;

  cin >> N >> K >> Q;
  vector<int> vec(N);
  for(int i=0;i<Q;++i){
    int A; cin >> A;
    vec.at(A-1) += 1;
  }

  for(int i=0;i<N;++i){
    if(K-Q+vec.at(i) > 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3780
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++){
            a[i]= sc.nextInt();
        }
        for(int j = 0; j < n; j++){
            System.out.print(a[n - 1 - j]);
            if(j != n - 1){
                System.out.print(" ");
            }
        }
        System.out.print("\n");
        sc.close();
    }
}


Measured memory_bytes: 26164
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[101010];

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

char c[2010][2010];
ll ans = 0;

void solve(ll x) {
	ll res = 0;
	if (x % 4 == 0) {
		res = x;
	}
	else if (x % 4 == 1) {
		res = 1;
	}
	else if (x % 4 == 2) {
		res = 1 ^ x;
	}
	ans ^= res;
}

//long longしか使わない
//素数は1より大きい
int main() {
	ll a, b;
	cin >> a >> b;
	solve(a - 1);
	solve(b);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int N, D, X, ans = 0;
    scanf("%d", &N);
    scanf("%d %d", &D, &X);
    int A[N];
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        A[i] = tmp;
    }
    for (int i = 0; i < N; i++) {
        if (D % A[i] == 0) {
            ans += D / A[i];
        } else {
            ans += D / A[i] + 1;
        }
    }
    printf("%d\n", ans + X);
    return 0;
}

Measured memory_bytes: 128
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    x = ii()
    for i in range(1,400):
        if (x*i) % 360 == 0:
            print(i)
            exit()




main()




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

long gcd(long a,long b)
 {
     if(b==0)
      return a;
      return gcd(b,a%b);
 }
int main()
{
  long  a,b;
    cin>>a>>b;
  int g=gcd(a,b);
  long long int lcm=(a/g)*b;
  cout<<lcm;
return 0;    
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;

typedef long long LL ;
const int N = 200010 , mod = 1000000007;
int a[N];


signed main()
{
    int n , k ;
    scanf("%lld%lld",&n,&k);
    for(int i = 0 ; i < n ; i ++) scanf("%lld",&a[i]);

    sort(a,a + n);

    LL res = 1 ;
    int l = 0 , r = n - 1 ;
    int sign = 1 ;
    if(k % 2 )
    {
        res =  a[r]; 
        r -- ;
        k -- ;

        if(res < 0) sign = -1;
    }
    while(k)
    {
        LL x = (LL)a[l] * a[l + 1] , y = (LL)a[r] * a[r - 1];
        if(x * sign > y * sign)
        {
            res = x % mod * res % mod; 
            l += 2;                                
        }
        else 
        {
            res = y % mod * res % mod; 
            r -= 2; 
        }
        k -= 2; 
    }
    printf("%lld",(res%mod+mod)%mod);
    return 0;
}

Measured memory_bytes: 5320
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int a[1100000];
int b[1100000];
int c[1100000];
int main()
{
    int n;
    cin>>n;
    int t;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&c[i]);
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    sort(c+1,c+1+n);
    long long  add1=1;
    long long  add2=1;
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        while(a[add1]<b[i]&&add1<n)
            add1++;
        while(c[add2]<=b[i]&&add2<n)
            add2++;
        if(a[1]>=b[i]||c[n]<=b[i])
            continue;
        if(a[add1]<b[i])
            sum+=add1*(n-add2+1);
        else
            sum+=(add1-1)*(n-add2+1);
        //cout<<add1<<"_"<<add2<<endl;
        //cout<<sum<<endl;
    }
    cout<<sum<<endl;
    return 0;
}

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

template<typename T> struct Graph {
  struct Edge { int to; T cost; };
  vector<int> prev;
  vector<vector<Edge>> g;
  Graph(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  vector<T> dijkstra(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

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

  int n; cin >> n;
  Graph<int> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int s, t, w; cin >> s >> t >> w;
    g.addEdge(s, t, w);
  }
  vector<int> d0 = g.dijkstra(0);
  int maxId0 = distance(begin(d0), max_element(begin(d0), end(d0)));
  vector<int> d1 = g.dijkstra(maxId0);
  int maxId1 = distance(begin(d1), max_element(begin(d1), end(d1)));
  vector<int> d2 = g.dijkstra(maxId1);
  for (int i = 0; i < n; ++i) {
    cout << max(d1[i], d2[i]) << endl;
  }
  return 0;
}



Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

map<int, int> prime_factor(int n) {
    map<int, int> ret;
    for (int i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    rep (i, n, 1000000) {
        auto K = prime_factor(i);
        if (K.size() == 1) {
            for (auto j : K) {
                if (j.second == 1) {
                    cout << i << "\n";
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
l = []
for i in range(5):
    l.append(int(input()))

last = min(l,key = lambda x:(x+9)%10)
l.remove(last)

sum = 0
for i in l:
    if i%10==0:
        sum+=i
    else:
        sum+=i-i%10+10
        
print(sum+last)



Measured memory_bytes: 3060
#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;
int main() {
	string s;
	cin >> s;
	if (s[s.size() - 1] == 's') {
		cout << s << "es" << endl;
	}
	else {
		cout << s << "s" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    // double asum = 0;
    rep(i, N) {
        A[i] -= i;
    }
    sort(A.begin(), A.end());
    if (N % 2 == 0) {
        int med_1 = A[N/2], med_2 = A[N/2-1];
        ll ans_1 = 0, ans_2 = 0;
        rep(i, N) {
            ans_1 += abs(med_1 - A[i]);
            ans_2 += abs(med_2 - A[i]);
        }
        cout << min(ans_1, ans_2) << endl;
    } else {
        int med = A[N/2];
        ll ans = 0;
        rep(i, N) {
            ans += abs(med - A[i]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();

		while(x != 0 || y != 0){
			if(x > y){
				System.out.println(y + " " + x);
			}else{
				System.out.println(x + " " + y);
			}
			x = scan.nextInt();
			y = scan.nextInt();
		}
	}
}

Measured memory_bytes: 34752
#include<iostream>
#include<map>
#include<vector>

using namespace std;
using ll = long long;

int main() {
    while(1) {
        int n, m;
        cin >> n >> m;
        if (n == 0) break;
        map<int, int> mp;
        vector<int> h;

        for (int i = 0; i < n; ++i) {
            int hi;
            cin >> hi;
            if (mp.find(hi) != mp.end()) {
                mp[hi]++;
            } else {
                mp[hi] = 1;
            }

            int hij = hi;
            for (int j = h.size() - 1; j >= 0; j--) {
                hij += h[j];
                if (mp.find(hij) != mp.end()) {
                    mp[hij]++;
                } else {
                    mp[hij] = 1;
                }
            }

            h.push_back(hi);
        }

        vector<int> w;
        ll ans = 0;
        for (int i = 0; i < m; ++i) {
            int wi;
            cin >> wi;

            if (mp.find(wi) != mp.end()) {
                ans += mp[wi];
            }

            int wij = wi;
            for (int j = w.size() - 1; j >= 0; j--) {
                wij += w[j];
                if (mp.find(wij) != mp.end()) {
                    ans += mp[wij];
                }
            }

            w.push_back(wi);
        }

        cout << ans << endl;
    }

    
}

Measured memory_bytes: 16448
#include<stdio.h>
int main()
{
    int A,C,B,D,E;
    scanf("%d %d %d %d %d", &A, &B, &C, &D, &E);
    if(A==0)
    {
    	printf("1");
    }
 	 if(B==0)
    {
    	printf("2");
     }if(C==0)
    {
    	printf("3");
    }if(D==0)
    {
    	printf("4");
    }if(E==0)
    {
    	printf("5");
    }
}

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

int main(){
    int A, B, K;
    std::cin >> A >> B >> K;

    int min = A < B ? A : B;
    std::vector<int> ans;

    for(auto i = 1; i <= min; i++){
        if(A % i == 0 && B % i == 0){
            ans.push_back(i);
        }
    }

    auto iter = ans.size() - K;
    std::cout << ans.at(iter) << std::endl;

    return 0;
}


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

int main(){
    string S;
    cin >> S;
    int N;
    N = S.size();
    bool correct = true;
    if (S.at(0) != 'A'){
        correct = false;
    }
    int count = 0;
    for (int i = 2; i < N - 1; i++){
        if (S.at(i) == 'C'){
            count++;
        }
    }
    if (count != 1){
        correct = false;
    }
    int count_large;
    for (int i = 0; i < N; i++){
        if ('A' <= S.at(i) && S.at(i) <= 'Z'){
            count_large++;
        }
    }
    if (count_large != 2){
        correct = false;
    }
    if (correct){
        cout << "AC" << endl;
    }
    else{
        cout << "WA" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    ll n,a,cnt=0;cin>>n;
    lol(i,n){
	cin>>a;
	cnt+=(a%2==0);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define MOD 998244353
#define INF 10000000000000000
int n, M;
pair<int, pair<int, int>> P[100000];
vector<long long int> value; // ノードの値を持つ配列
int N;             // 葉の数

void update(int i, long long int x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}
long long int query(int a, int b, int k, int l, int r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        long long int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        long long int c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}

int main(){
  cin >> n >> M;
  N = 1;
  while (N < n) N *= 2; // 葉の数を計算（n以上の最小の2冪数）
  value = vector<long long int>(2 * N - 1, INF);
  update(0, 0);
  rep(i, M){
    cin >>P[i].first >> P[i].second.first >> P[i].second.second;
  }
  sort(P, P + M);
  rep(i, M){
    int L = P[i].first - 1;
    int R = P[i].second.first - 1;
    long long int C = P[i].second.second;
    update(R, min(value[R + N - 1],query(L, R , 0, 0, N) + C));
  }
  if(value[n + N - 2]  == INF)
           value[n + N - 2]  = -1;
  cout << value[n + N - 2] << endl;
}

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

int main(){
	string s;
	cin >> s;
	for (int i = 0; i < 4; ++i){
		cout << s[i];
	}
	cout << " ";
	for (int i = 4; i < 12; i++){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
n = stdin.readline().rstrip()
a = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 1
ok = 1
for i in a:
    if i == 0:
        print(0)
        sys.exit(0)
    if ok == 1:
        tmp *= i
        if tmp > 1000000000000000000:
            ok = 0
if ok == 0:
    print(-1)
else :
    print(tmp)

Measured memory_bytes: 21700
#include <iostream>
using namespace std;
int main(){
  int n, i;
  cin >> n;
  char a[n], b[n];
  for(i=0; i<n; i++)
  cin >> a[i];
  for(i=0; i<n; i++)
   cin >> b[i];
  for(i=0; i<n; i++)
    cout << a[i] << b[i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
bool cmp(char x,char y)
{
    return x>y;
}
int main()
{
    char a[200],b[200];
    cin>>a>>b;
    sort(a,a+strlen(a));
    sort(b,b+strlen(b),cmp);
    int judge=0;
    //cout<<a<<endl<<b<<endl;
    for(int i=0;i<strlen(a)&&i<strlen(b);i++)
    {
        if(b[i]>a[i])
        {
            judge=2;
            break;
        }
        if(b[i]<a[i])
        {
            judge=1;
            break;
        }
    }
    if(judge==2)
    {
        printf("Yes");
    }
    else if(judge==1)
        printf("No");
    else if(judge==0&&strlen(a)<strlen(b))
        printf("Yes");
    else printf("No");
    return 0;
}


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

typedef vector<int> vi; 

#define sz(x) (int)(x.size())

void rev(vi& perm, int f, int t) { 
  while(f < t) { 
    swap(perm[f], perm[t-1]); 
    f++; 
    t--; 
    } 
  } 

class LadderPermutation { 
  public: 
  vector <int> createLadder(int n, int m, int k) { 
    // !FDI 
    vi error; 
    vi res; 
    for(int t=0; t<n; t++) res.push_back(t+1); 
    rev(res, n-k, n); 
    int currm = n - k + 1; 
    if(currm < m) return error; 
    int nat = n - k; 
    while(currm > m) { 
      if(nat == 0) return error; 
      int eat = k; 
      if(eat > nat) eat = nat; 
      /* currm - (eat-1) == m => eat = currm - m + 1 */ 
      if(eat > currm-m+1) eat = currm-m+1; 
      rev(res, nat-eat, nat); 
      currm -= (eat-1); 
      nat -= eat; 
      } 
    return res; 
    } 
  }; 


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

	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	LadderPermutation A;
	vi ans = A.createLadder(n, a, b);
	if (sz(ans) == 0) {
		printf("-1\n");
	}	else {
		for(int z : ans) {
			printf("%d ", z);
		}
	}

	return 0;
}

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

using namespace std;
#define ll long long int
#define X first
#define Y second
const int MAXN = 1e5 + 5;
ll n, dp[MAXN], arr[MAXN], k;

ll solve(int idx = 1)
{
	if (idx > n) return 0;

	ll &ret = dp[idx];
	if (~ret) return ret;
	ret = 0;

	if (idx < n) ret = solve(idx + 1) + abs(arr[idx] - arr[idx + 1]);
	for (int i = idx + 2; i <= min(idx + k, n); i++)
		ret = min(ret, solve(i) + abs(arr[idx] - arr[i]));

	return ret;
}

int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	memset(dp, -1, sizeof dp);
	cout << solve() << endl;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;


template<class T>
T op(T &a, T &b) {
    return a + b;
}

template<class T>
T e() {
    return 0;
}

template<class T>
struct SegmentTree {

    int n;
    int size;
    vector<T> val;

    SegmentTree(int _n) {
        n = 1;
        size = _n;
        while(n < _n) n *= 2;
        val.assign(n*2, e<T>());
    }

    void update(int k, T a) { // val[k] = a;
        k += n-1;
        val[k] = a;
        while(k > 0) {
            k = (k-1) / 2;
            val[k] = op(val[k*2+1], val[k*2+2]);
        }
    }

    T query(int l, int r) { // 閉区間[l,r]
        return _query(l, r+1, 0, 0, n);
    }
    T _query(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return e<T>();
        if(a <= l && r <= b) return val[k];
        else {
            T vl = _query(a, b, k*2+1, l, (l+r)/2);
            T vr = _query(a, b, k*2+2, (l+r)/2, r);
            return op(vl, vr);
        }
    }
};

const ll mod = 998244353;

int main(){

    int n, k;
    cin >> n >> k;
    V<int> ls(k), rs(k);
    rep(i,k) cin >> ls[i] >> rs[i];

    SegmentTree<ll> sums(n);
    sums.update(0,1);

    Rep(i,n-1) {
        ll tmp = 0;
        rep(j,k) {
            if(i - ls[j] >= 0) {
                tmp += sums.query(max(0,i-rs[j]), i-ls[j]);
                tmp %= mod;
            }
        }
        sums.update(i,tmp);
    }

    int ans = sums.query(n-1, n-1);
    cout << ans << endl;
}

Measured memory_bytes: 7452
#include<iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
using namespace std;
using ll=long long;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  int N;
  int V[30], C[30];
  cin>>N;
  REP(i,N) cin>>V[i];
  REP(i,N) cin>>C[i];

  int ans=0;
  REP(i,N){
    int dif = V[i]-C[i];
    if(dif>0) ans+=dif;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
def resolve():
    N, H = map(int, input().split())
    b = []
    max_a = -1
    for _ in range(N):
        ai, bi = map(int, input().split())
        max_a = max(max_a, ai)
        b.append(bi)
    max_b = sorted([_ for _ in b if _ > max_a], reverse=True)
    rest = H
    cnt = 0
    ans = -1
    for b in max_b:
        rest -= b
        cnt += 1
        if rest <= 0:
            ans = cnt
            break

    if ans == -1:
        div, mod = divmod(rest, max_a)
        ans = cnt + div
        if mod != 0:
            ans += 1
    print(ans)
resolve()

Measured memory_bytes: 59352
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

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

const int INF = 1000000009;
const int MAX_M = 11;
int m,n,t;
int ct;
stack<P> park[MAX_M];
queue<P> wait;
vector<int> out;

bool parking() {
	if(wait.empty()) return false;

	P car = wait.front();
	// park
	rep(i,m) {
		if(park[i].empty()) {
			// printf("car %d parks at %d\n", car.second, i);
			park[i].push(P(car.first+ct, car.second));
			wait.pop();
			return true;
		}
	}

	// situation 1
	int p = -1;
	int minval = INF;
	rep(i,m) {
		if(park[i].size() == 1 && park[i].top().first >= ct + car.first) {
			if(minval > park[i].top().first - (ct + car.first)) {
				minval = park[i].top().first - (ct + car.first);
				p = i;
			}
		}
	}
	if(p >= 0) {
		// printf("car %d parks at %d\n", car.second, p);
		park[p].push(P(ct+car.first, car.second));
		wait.pop();
		return true;
	}

	// situation 2
	rep(i,m) {
		if(park[i].size() == 1 && park[i].top().first <= ct + car.first) {
			if(minval > ct + car.first - park[i].top().first) {
				minval = ct + car.first - park[i].top().first;
				p = i;
			}
		}
	}
	if(p >= 0) {
		// printf("car %d parks at %d\n", car.second, p);
		park[p].push(P(ct+car.first, car.second));
		wait.pop();
		return true;
	}
	return false;
}

bool leave() {
	int minval = INF;
	rep(i,m) {
		if(!park[i].empty() && minval > park[i].top().first) {
			minval = park[i].top().first;
		}
	}

	if(minval > ct) return false;
	
	bool update = false;
	rep(i,m) {
		if(!park[i].empty() && park[i].top().first == minval) {
			// printf("car %d leaves from %d\n", park[i].top().second, i);
			out.push_back(park[i].top().second);
			park[i].pop();
			update = true;
		}

		if(!park[i].empty() && park[i].top().first <= minval) {
			// printf("car %d leaves from %d\n", park[i].top().second, i);
			out.push_back(park[i].top().second);
			park[i].pop();
		}
	}
	return update;
}

int main() {
	while(scanf("%d%d", &m, &n), m|n) {
		ct = 0;
		out.clear();
		while(out.size() != n) {
			if(ct < 10 * n && ct % 10 == 0) {
				scanf("%d", &t);
				wait.push(P(t, ct/10+1));
			}
			while(leave()) {}
			while(parking()) {}
			ct++;
		}

		rep(i,n) {
			printf("%d%c", out[i], i==n-1 ? '\n' : ' ');
		}
	}
}

Measured memory_bytes: 1208
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[310][90010] = {};
ll dp2[310][90010] = {};
ll power(ll x, ll n){
    if(n == 0) return 1LL;
    ll res = power(x * x % MOD, n/2);
    if(n % 2 == 1) res = res * x % MOD;
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[310];
    rep(i,0,N) cin >> a[i];
    dp[0][0] = 1;
    ll sum = 0;
    rep(i,0,N) sum += a[i];
    rep(i,0,N){
        rep(j,0,300 * N + 1){
            if(j - a[i] >= 0) (dp[i+1][j] += dp[i][j - a[i]]) %= MOD;
            (dp[i+1][j] += 2 * dp[i][j]) %= MOD;
        }
    }

    dp2[0][0] = 1;
    rep(i,0,N){
        rep(j,0,300*N+1){
            if(j - a[i] >= 0) (dp2[i+1][j] += dp2[i][j - a[i]]) %= MOD;
            (dp2[i+1][j] += dp2[i][j]) %= MOD;
        }
    }

    ll ans = 0;
    rep(i,(sum+1)/2, sum+1){
        (ans += dp[N][i]) %= MOD;
    }
    if(sum % 2 == 0){
        ans -= dp2[N][sum/2];
        ans = (ans + MOD) % MOD;
    }
    ans *= 3;
    ans %= MOD;
    // if(sum % 2 == 0) ans += dp2[N][sum/2] * 6;
    ans = (power(3,N) - ans + MOD) % MOD;
    print(ans);

}

Measured memory_bytes: 425600
n,k=list(int(i) for i in input().split())
A=list(int(i) for i in input().split())
dp=[[0 for i in range(k+1)] for j in range(2)]
for i in range(k+1):
    for j in range(n):
        if i>=A[j]:
            if dp[1][i-A[j]] is "First":
                dp[0][i]="First"
            if dp[0][i-A[j]] is "Second":
                dp[1][i]="Second"
    if dp[0][i]==0:
        dp[0][i]="Second"
    if dp[1][i]==0:
        dp[1][i]="First"
print(dp[0][-1])


Measured memory_bytes: 56048
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define ll long long
#define pb push_back
#define pf push_front			
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pi 3.14159265358
#define xmod 1000000007
using namespace std;

ll a,b,n1,n2;
int main(){
	scanf("%lld%lld",&a,&b);
	if ((a-1)%4 == 0)
	n1=a-1;
	else
	if ((a-1)%4 == 1)
	n1=1;
	else
	if ((a-1)%4 == 2)
	n1=a;
	else
	n1=0;
	
	if (b%4 == 0)
	n2=b;
	else
	if (b%4 == 1)
	n2=1;
	else
	if (b%4 ==2)
	n2=b+1;
	else
	n2=0;
	printf("%lld\n",n2^n1);
	return 0;
}

Measured memory_bytes: 128