akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SI(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define debugV(x) for(int i=0;i<((ll)(x).size());i++)cerr << #x <<"at:"<<i<< ": " << x[i] << "\n"//手動デバッグ 
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
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 gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    int n,x,t;cin>>n>>x>>t;
    if(n%x==0){
        O(((n/x))*t);
    }else{
        O(((n/x)+1)*t);
    }
    
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	vector<long long int>v(N);
	for(auto &i:v)cin>>i;
	vector<long long int>by(N+1,1);
	for(int i=1;i<=N;i++){
		by[i]=by[i-1]*2;
		by[i]%=MOD;
	}
	long long int ans=0;
	for(int i=0;i<N;i++){
		long long int add=power(2,N-i-1,MOD);
		add*=power(v[i]+1,i,MOD);
		add%=MOD;
		add*=v[i];
		add%=MOD;
		ans+=add;
		ans%=MOD;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 18328
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

const int MOD = (int) 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    int sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a - 1;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string s;
	cin>>s;

	bool st,nd,rd;
	if(s[0]=='A')st=true;
	else st=false;

	int cnt=0;
	for (int i = 2; i < s.size()-1; i++){
		if(s[i]=='C')cnt++;
	}
	if(cnt==1)nd=true;
	else nd=false;

	cnt=0;

	for (int i = 0; i < s.size(); i++){
		if(s[i]<'a')cnt++;
	}
	if(cnt==2)rd=true;
	else rd=false;

	if(st==true&&nd==true&&rd==true)
		cout<<"AC"<<endl;
	else
		cout<<"WA"<<endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
    int m,n,x,s;
    scanf("%d", &m);
    scanf("%d %d", &n, &x);
        for (n;n<=x;n++)
        {
            if(n%m==0)
            {
            s++;
            }
        }
    if(s!=0)
    {
        printf("OK");
    }
    else
    {
        printf("NG");
    }


    return 0;
}

Measured memory_bytes: 1688
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << b/c - (a-1)/c;
    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int64_t const MOD = 998244353;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::string S; std::cin >> N >> S;
  std::vector<int> r, g, b;
  for(int i = 0; i < S.size(); ++i) {
    switch(S[i]){
    case 'R': r.push_back(i); break;
    case 'G': g.push_back(i); break;
    case 'B': b.push_back(i); break;
    }
  }
  std::vector<char> x(N*3, '_');
  for(int i = 0; i < N; ++i) {
    int mi = std::min(r[i], std::min(g[i], b[i]));
    x[mi] = '-';
    int ma = std::max(r[i], std::max(g[i], b[i]));
    x[ma] = '+';
  }
  int64_t ans = 1;
  for(int64_t i = 2; i <= N; ++i) (ans *= i) %= MOD;
  int64_t nmi = 0, np = 0;
  for(int i = 0; i < N*3; ++i) {
    switch(x[i]) {
    case '-': ++nmi; break;
    case '_': (ans *= nmi) %= MOD; --nmi; ++np; break;
    case '+': (ans *= np) %= MOD; --np;
    }
  }
  fin(ans);
  return 0;
}


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

using namespace std;

int main() {

	long long n, a, b;
	cin >> n >> a >> b;

	if ((b-a) % 2 == 0){
		cout << (b - a) / 2 << endl;
	}
	else {

		long long counter=0;
		if (a - 1 < n - b) {
			counter += a - 1 + 1 + (b - (a - 1) - 1-1) / 2;
			cout << counter << endl;
		}
		else {
			counter += n - b + 1 + (n - (a + (n - b) + 1)) / 2;
			cout << counter << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
int main(void)
{
    int a,b;
    scanf("%d %d", &a,&b);
    if(a==b){
        puts("a == b");
    }
    else if(a>b){
        puts("a > b");
    }
    else{
        puts("a < b");
    }
    return 0;
}


Measured memory_bytes: 2684
// ABC 055 D
#include<bits/stdc++.h>
 
using namespace std;
//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------
  str s; 
  deque<int> que;
  int ans=0;
  cin >> s;
  bool tri=true;
  EACH(i,s){
    if(que.empty()) {
      que.PB(*i);
      continue;
    }
    if(que.back()!=*i){
      que.pop_back();
      ans+=2;
    }else{
      que.PB(*i);
    }
  }
  //VI l(N);
  cout << ans << endl;
  return 0;
}


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

int main(){
    int x;
    for (int i=0;i<10000;i++){
        cin>>x;
        if(x!=0){
            cout<<"Case "<<i+1<<": "<<x<<endl;
        }
        else{
            break;
        }
    }
}


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

int main() {
  int N, M, A, L = 1;
  cin >> N >> M;
  set<int> S;
  while (cin >> A) A /= 2, L = L / __gcd(L, A) * A, S.insert(A);
  for (int s : S) if (!(L / s % 2)) goto NG;
  cout << (M / L + 1) / 2 << "\n";
  return 0;
  NG:
  cout << 0 << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
    int N;
    scanf("%d",&N);
    std::vector<int> a(N);
    int temp;
    for (size_t i = 0; i < N; i++) {
        scanf("%d",&temp);
        a[i]=temp-1;
    }
    std::vector<bool> v(N,false);
    int nowOn=0,counter=0;
    while (true) {
        if(nowOn==1){
            printf("%d\n",counter);
            return 0;
        }else if(v[nowOn]){
            printf("-1\n");
            return 0;
        }else{
            v[nowOn]=true;
        }
        counter++;
        nowOn=a[nowOn];
    }
    return 0;
}


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

#define rep(i, n) for (int i=0; i<n; i++)
#define rrep(i, n) for (int i=1; i<n; i++)
using vi = vector<int>;

int main(){
    int n;
    cin >> n;
    if (n % 1000 == 0)cout << 0 << endl; 
    else cout << 1000-n % 1000<< endl;
    
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const long long MOD = 1000003;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T>
T pow_ (T x, T n, T M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return static_cast<T>(u);
};

template<typename T>
T mod_inv(T x, T M){
    T u = 1, t = 1, v = 0, s = 0, m = M;
    while (x) { T q = m/x; swap(s -= q*u, u); swap(t -= q*v, v); swap(m -= q*x, x); }
    if(s < 0) s += M;
    return s;
}

template <class T> class Factorial {
    T mod;
    vector<uint64_t> facts, factinv;

public:
    Factorial(int n, T mod) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)), mod(mod) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*i % mod;
        factinv[n] = pow_(facts[n], static_cast<uint64_t>(mod - 2), static_cast<uint64_t>(mod));
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * (i+1) % mod;
    }

    T fact(int k) const {

        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T operator[](const int &k) const {
        if(k >= 0) return static_cast<T>(facts[k]);
        else return static_cast<T>(factinv[-k]);
    }

    T C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>(facts[p]*  factinv[q] % mod * factinv[p-q] % mod);
    }

    T P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return static_cast<T>((facts[p] * factinv[p-q]) % mod);
    }

    T H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return static_cast<T>(q == 0 ? 1 : C(p+q-1, q));
    }
};

int main() {
    int q;
    cin >> q;
    Factorial<ll> f(MOD-1, MOD);
    for (int i = 0; i < q; ++i) {
        ll x, d, n;
        scanf("%lli %lli %lli", &x, &d, &n);
        if(d == 0){
            printf("%lli\n", pow_(x, n, MOD));
        }else {
            ll y = x*mod_inv(d, MOD)%MOD;
            ll ans = pow_(d, n, MOD);
            if(n <= 10){
                for (int j = 0; j < n; ++j) {
                    ans = (ans*(y+j))%MOD;
                }
            }else {
                if(y+n-1 >= MOD){
                    ans = 0;
                }else {
                    ans = ans*f[y+n-1]%MOD;
                    if(y != 0) ans = ans*f[-(y-1)]%MOD;
                }
            }
            printf("%lli\n", ans);

        }
    }
    return 0;
}

Measured memory_bytes: 16512
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    N, M = input(int, int)
    A = input([int, M])
    ans = N - sum(A)
    print(ans if 0 <= ans else -1)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) (v.size())
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

LL MOD = 1000000007; 

using namespace std;


class UnionFind {
public:
    vector<int> parent;

    UnionFind(unsigned int size) {
        parent.resize(size + 1);
        iota(parent.begin(), parent.end(), 0);
    }

    // xとyが同じ集合に属するか
    bool isSameSet(int x, int y) {
        return findRoot(x) == findRoot(y);
    }

    // xとyの属する集合を併合
    void unionSet(int x, int y) {
        x = findRoot(x);
        y = findRoot(y);
        if (x == y) { return; }

        parent[x] = y;
    }

    // 集合の数を取得
    int getNumberOfSet() {
        int n = 0;
        for (int i = 0; i < parent.size(); ++i) {
            if (parent[i] == i) { n++; }
        }
        return n;
    }

    // 木の根を求める
    int findRoot(int x) {
        if (parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = findRoot(parent[x]);
        }
    }
};

int main(int argc, char *argv[]) {
    int N, K, L, A, B;
    cin >> N >> K >> L;
    
    UnionFind uf1(N);
    UnionFind uf2(N);
    
    FOR(i, 0, K) {
        cin >> A >> B;
        A--; B--;
        uf1.unionSet(A, B);
    }
    FOR(i, 0, L) {
        cin >> A >> B;
        A--; B--;
        uf2.unionSet(A, B);
    }
    
    std::map<std::pair<int, int>, int> m;
    FOR(i, 0, N) {
        int a = uf1.findRoot(i);
        int b = uf2.findRoot(i);
        m[{a, b}]++;
    }
    
    FOR(i, 0, N) {
        int a = uf1.findRoot(i);
        int b = uf2.findRoot(i);
        int ans = m[{a, b}];
        if (i == 0) {
            std::cout << ans;
        }
        else {
            std::cout << " " << ans;
        }
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 13568
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        SetOut(new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split().Select(int.Parse).ToArray();
        var st = new DisjointSparseTable<int>(A, GCD);
        var ans = 0;
        for (int i = 0; i < N; i++)
        {
            ans = Max(ans, GCD(st.Query(0, i), st.Query(i + 1, N)));
        }
        WriteLine(ans);
        Out.Flush();
    }

    static int GCD(int a, int b)
    {
        while (b != 0)
        {
            var c = a;
            a = b;
            b = c % b;
        }
        return a;
    }
}

public class DisjointSparseTable<T> // 半群
{
    T[,] buffer;
    Func<T, T, T> F;
    int[] log2;

    public DisjointSparseTable(T[] init, Func<T, T, T> f)
    {
        F = f;

        var n = init.Length;

        var log = 0;
        while ((1 << log) <= n - 1) log++;
        //Query[l, r) で log2[l ^ (r - 1)]を計算するため 1 << log2(r - 1) + 1 = 1 << log2(n - 1) + 1
        log2 = new int[1 << log + 1];
        log2[0] = -1;
        for (int i = 2; i < log2.Length; i++)
        {
            log2[i] = log2[i >> 1] + 1;
        }

        var h = log2[n - 1] + 1;//ceil(log2(n))
        buffer = new T[h, n];

        for (int j = 0; j < n; j++) buffer[0, j] = init[j];
        for (int i = 1; i < h; i++)
        {
            int s = 1 << i;
            for (int j = 0; j < n; j += s << 1)
            {
                int t = Math.Min(j + s, n);
                buffer[i, t - 1] = init[t - 1];
                for (int k = t - 2; k >= j; k--) buffer[i, k] = f(init[k], buffer[i, k + 1]);//非可換

                if (n <= t) break;

                buffer[i, t] = init[t];
                int r = Math.Min(t + s, n);
                for (int k = t + 1; k < r; k++) buffer[i, k] = f(buffer[i, k - 1], init[k]);//非可換
            }
        }
    }

    public T Query(int l, int r)
    {
        if (l == r) return default(T);
        if (r - l == 1) return buffer[0, l];
        r--;//閉区間
        var h = log2[l ^ r];
        return F(buffer[h, l], buffer[h, r]);
    }
}


Measured memory_bytes: 29408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)
int main()
{
	int H, W, N, cnt, tm = 0;
	cin >> H >> W >> N;

	if (H > W)
	{
		while (N > cnt)
		{
			cnt += H;
			tm++;
		}
	}
	else
	{
		while (N > cnt)
		{
			cnt += W;
			tm++;
		}
	}
	cout << tm << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
#define to first
#define cost second
int main(){
  int v,e,r,a,b,c;
  vector<PA> vec[2000];
  scanf("%d %d %d",&v,&e,&r);
  for(int i=0;i<e;i++){
    scanf("%d %d %d",&a,&b,&c);
    vec[a].push_back(PA(b,c));
  }
  int min_cost[1000];
  fill(min_cost,min_cost+1000,INT_MAX);
  min_cost[r] = 0;
  for(int i=0;i<e;i++){
    for(int j=0;j<e;j++){
      for(int k=0;k<vec[j].size();k++){
	PA d = vec[j][k];
	if(min_cost[j] == INT_MAX || min_cost[d.to] <= min_cost[j]+d.cost) continue;
	min_cost[d.to] = min_cost[j]+d.cost;
	if(i == e-1){
	  puts("NEGATIVE CYCLE");
	  return (0);
	}
      }
    }
  }
  for(int i=0;i<v;i++){
    if(min_cost[i] == INT_MAX) puts("INF");
    else printf("%d\n",min_cost[i]);
  }
  return (0);
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % 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; }

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

int k, q;
ll d[5010];

ll solve(ll n, ll x, ll m){

  ll mx = x % m;

  vector<ll> sum_md_block(k+1);

  sum_md_block[0] = 0;

  rep(i, k){

    ll md = d[i] % m;
    if(md == 0) md = m;
    sum_md_block[i+1] = sum_md_block[i] + md;
  }

  ll sum_md = 0;
  sum_md = mx + sum_md_block[k] * ((n-1) / k) + sum_md_block[(n-1) % k];

  ll num_cross = sum_md / m;

  ll ret = (n-1) - num_cross;

  return ret;

}


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

  cin >> k >> q;
  rep(i, k) cin >> d[i];

  vector<ll> ans(q);

  ll n, x, m;
  rep(i, q){
    cin >> n >> x >> m;
    ans[i] = solve(n, x, m);
  }

  rep(i, q){
    cout << ans[i] << endl;
  }

  

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

/*int main() {
    ll A[6];
    rep(i,4){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << << endl;
}*/

int main(){
    ll t=0;
    char A[6],B[6];
    cin >> A >> B;
    rep(i,3){
        if(A[i]==B[i]){
            t++;
        }
    }
    cout <<  t << endl;
}


Measured memory_bytes: 888
import java.util.*;
//セグメント木
public class Main{
	public static boolean check(int n){
		if(n == 1)
			return true;
		else if(n % 2 != 0)
			return false;
		else
			return check(n / 2);
	}
	public static void add(long rsq[], int i, int x, int n){
		i += (n - 1);
		rsq[i] += x;
		if(i == 0)
			return;
		i = (i-1) / 2;
		while(i >= 0){
			rsq[i] += x;
			i = (i-1)/2;
                        if(i == 0)
				break;
		}
	}
	public static long getSum(long rsq[], int s, int t, int left, int right, int i){
		if(right <= s || left > t)
			return 0;
		else if(left >= s && right <= t+1)
			return rsq[i];
		else
			return getSum(rsq,s,t,left,(left+right)/2,2*i+1) + getSum(rsq,s,t,(left+right)/2,right,2*i+2);
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int n_ = n;
		while(!check(n_))
			n_++;
		int q = sc.nextInt();
		long rsq[] = new long[2*n_ - 1];
		for(int i = 0 ; i < 2*n_ - 1 ; i++)
			rsq[i] = 0L;
		for(int i = 0 ;i < q ; i++){
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			switch(com){
				case 0: add(rsq,x-1,y,n_); break;
				case 1: System.out.println(getSum(rsq,x-1,y-1,0,n_,0)); break;
			}
		}
	}
}


Measured memory_bytes: 118908
# include <bits/stdc++.h>
 
using namespace std;
 
# define REP(i, a, b) for(int i = a; i <= b; ++ i)
# define CLR(i, a) memset(i, a, sizeof(i))
# define REPD(i, a, b) for(int i = a; i >= b; -- i) 
 
const int N = 2e3 + 5, MOD = 1e9 + 7;
 
int n, k, f[N][N], inv[N * N], fac[N * N];
 
inline void inc(int &a, int b) { a = (a + b) % MOD; }
 
inline int binom(int x, int y) { return (y < 0 || y < x) ? 0 : 1ll * fac[y] * inv[x] % MOD * inv[y - x] % MOD; }
int pow_(int x, int k) {
	int ret = 1;
	while(k) {
		if(k & 1) ret = 1ll * ret * x % MOD;
		x = 1ll * x * x % MOD;
		k >>= 1;
	}
	return ret;
}
 
int main() {
	scanf("%d%d", &n ,&k);
    if(k == 1) puts("1"), exit(0);
	fac[0] = 1;
	REP(i, 1, n * k + 1) fac[i] = 1ll * fac[i - 1] * i % MOD;
	inv[n * k + 1] = pow_(fac[n * k + 1], MOD - 2);
	REPD(i, n * k, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
	f[0][0] = 1;
	REP(i, 0, n) {
		REPD(j, i, 0) {
			inc(f[i + 1][j + 1], 1ll * f[i][j] * binom(k - 2, i * k - j + k - 2) % MOD);
			if(j) inc(f[i][j - 1], f[i][j]);
		}
	}
	printf("%d\n", 1ll * f[n][0] * fac[n] % MOD);
	return 0;
}

Measured memory_bytes: 47360
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#pragma endregion

//#define __DEBUG__
#ifdef  __DEBUG__
#define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// pair出力
template<typename T, typename U>
ostream& operator << (ostream& os, pair<T, U>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template<typename T, typename U>
ostream& operator << (ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template<typename T>
ostream& operator << (ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#endif

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, W; cin >> N >> W;
    vector<vector<ll>> dp(N+1, vector<ll>(W+1,0));
    REP(i, N) {
        int w, v; cin >> w >> v;
        REP(j, W+1) {
            if (j - w >= 0) dp[i + 1][j] = max(dp[i][j],dp[i][j - w] + v);
            else dp[i + 1][j] = dp[i][j];
        }
    }
    cout << dp[N][W] << endl;
    getchar(); getchar();
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    long long int n,i,j,k;
    cin>>n>>k;
    long long int a[n],b[n];
    b[0]=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
        {
            b[i]=1000000000;
        }
    }
    for(i=1;i<n;i++)
    {
        for(j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
               b[i]=min(b[i],b[i-j]+abs(a[i-j]-a[i]));
            }
        }
    }
    /*for(i=0;i<n;i++)
    {
        cout<<b[i]<<" ";
    }*/
    cout<<b[n-1];
    return 0;
}




Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    String moji = scanner.nextLine();
		    
		    if( moji.indexOf("S") != -1 ) 
		    {
		    	if(moji.indexOf("N") != -1 ) 
		    	{
		    		if( moji.indexOf("W") != -1 ) 
				    {
				    	if(moji.indexOf("E") != -1 ) 
				    	{
				    		System.out.println("Yes");
				    	}
				    	else 
				    	{
				    		System.out.println("No");
				    	}
				    }
		    		else 
		    		{
		    			if(moji.indexOf("E") != -1 ) 
				    	{
				    		System.out.println("No");
				    	}
				    	else 
				    	{
				    		System.out.println("Yes");
				    	}
		    		}
		    	}
		    	else 
		    	{
		    		System.out.println("No");
		    	}
		    }
		    else 
		    {

		    	if(moji.indexOf("N") == -1 ) 
		    	{
		    		if( moji.indexOf("W") != -1 ) 
				    {
				    	if(moji.indexOf("E") != -1 ) 
				    	{
				    		System.out.println("Yes");
				    	}
				    	else 
				    	{
				    		System.out.println("No");
				    	}
				    }
		    		else 
		    		{
		    			if(moji.indexOf("E") != -1 ) 
				    	{
				    		System.out.println("No");
				    	}
				    	else 
				    	{
				    		System.out.println("Yes");
				    	}
		    		}
		    	}
		    	else 
		    	{
		    		System.out.println("No");
		    	}
		    }
		    
		    scanner.close(); }
		  }

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

vector<vector<unsigned long long>> num_all_plus (vector<int> &vec, vector<vector<unsigned long long>> data, int n ){

  if ( n < 0) {
    return data;
  }
  
  int p = vec.at(n);
  vector<vector<unsigned long long>> data_c = data;
  
  for (int i=0; i<data.size(); i++){
    data_c.at(i).push_back(p);
  }
  
  for (int i=0; i < data.size(); i++){
    int x = data.at(i).size() - 1;
    data.at(i).at(x) = data.at(i).at(x) * 10 + p;
  }
  data.insert(data.end(), data_c.begin(), data_c.end()); 
  return num_all_plus ( vec, data, n - 1);

}  


int main() {
  unsigned long long S;
  cin >> S;
      
  vector<int> num;
  
  for (unsigned long long i = S; i > 0; i/=10) {
      num.push_back( i%10 );
  }

  int num_s = num.size() - 1;
  
  if( num_s == 0 ) cout << S << endl;
  else {
    
  vector<vector<unsigned long long>> num_all(1, vector<unsigned long long>(1, num.at(num_s)));
  
  num_all = num_all_plus (num, num_all, num_s - 1 );
  
  unsigned long long A = 0;
  for (int i=0; i < num_all.size(); i++){
    for (int j=0; j < num_all.at(i).size(); j++){
      A += num_all.at(i).at(j);
    }
  }
  cout << A << endl;
  }
}


Measured memory_bytes: 384
from collections import deque
from sys import stdin

def bfs():
    readline=stdin.readline
    h,w=map(int,readline().split())
    sy,sx=map(int,readline().split())
    gy,gx=map(int,readline().split())
    sy-=1;sx-=1;gy-=1;gx-=1
    s=[list(readline()) for _ in range(h)]
    dict={".":10000000,"#":-1}
    s=[[dict[s[y][x]] for x in range(w)]for y in range(h)]
    s[sy][sx]=0
    que=deque([[sy,sx]])
    temp=[i for i in range(-2,3)]
    while que:
        y,x=que.popleft()
        s1=s[y][x]
        for i in temp:
            nexty=y+i
            if 0<=nexty<h:
                s2=s[nexty]
                for j in temp:
                    nextx=x+j
                    if 0<=nextx<w and s2[nextx]>=0:
                        dist=s2[nextx]
                        if i*i+j*j<=1 and dist>s1:
                            s[nexty][nextx]=s1
                            que.appendleft([nexty,nextx])
                        elif dist>s1+1:
                            s[nexty][nextx]=s1+1
                            que.append([nexty,nextx])

    if s[gy][gx]==10000000:
        print(-1)
    else:
        print(s[gy][gx])
bfs()


Measured memory_bytes: 157796
import sys
 
for line in sys.stdin:
    card = line.split(" ")
    alice = int(card[0])
    bob = int(card[1])
    if alice == 1:
        alice += 13
    if bob == 1:
        bob += 13
        
    if alice > bob:
        print("Alice")
    elif alice < bob:
        print("Bob")
    else:
        print("Draw")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(n + 1);
    for(auto &i : a) cin >> i;
    ll cur = 1;
    ll ans = 0;
    ll tot = 0;
    for(auto &i : a) tot += i;
    for(int i = 0 ; i <= n ; i++){
        ans += cur;
        tot -= a[i];
        cur -= a[i];
        if(cur < 0) finish(-1);
        cur *= 2;
        cur = min(cur, tot);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3784
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_A
  * ?????????
  * ???????????´??° a ??¨ b ?????????????????§?????\?????????????¨??????????????????°?????????????????????????????????
  * a ?? b ??? d (??´??°)
  * a ?? b ????????? ??? r (??´??°)
  * a ?? b ??? f (???????°???°?????°)
  */
object Main {
  def main(args: Array[String]): Unit = {
    val array = io.StdIn.readLine().split(" +").map(_.toInt)
    val (a, b) = array match {
      case Array(x, y) => (x, y)
    }
    val d = a / b
    val r = a % b
    val f = a.toDouble / b.toDouble
    println(f"$d $r $f%.5f")
  }
}

Measured memory_bytes: 44132
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
#define INF (1<<28)
#define FDBST int hogehogehoge;cin>>hogehogehoge;

int main(){
	int n;
	cin>>n;
	int a[100000];
	lp(i,n) cin>>a[i];
	sort(a,a+n);
	int q;
	cin>>q;
	int b;
	int count=0;
	lp(i,q){
		cin>>b;
		int low=0,high=n-1,it=n/2;
		if(a[high]==b||a[low]==b){
			count++;
			continue;
		}
		lp(j,20){
			if(a[it]==b){
				count++;
				break;
			}
			if(a[it]>b){
				high=it;
			}
			else low=it;
			it=(high+low)/2;
		}
	}
	cout<<count<<endl;
	return 0;
}




Measured memory_bytes: 3540
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-19 07:29:19
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n; cin >> n;
  vector<int> a(n); cin >> a;

  vector<int> ans(n, 0);

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

  int m = accumulate(all(ans), int());
  cout << m << '\n';
  for (int i = 0; i < n; ++i) {
    if (ans[i] == 1) {
      cout << i + 1 << " ";
    }
  }

  cout << '\n';

  return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

ll a[10010];

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

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] == 0) continue;
		while (a[i] % 2 == 0) {
			if (a[i] == 0)break;
			ans++;
			a[i] /= 2;
		}
	}

	cout << ans << endl;

	return 0;
}

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

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

    const vector<char> V = {'M', 'A', 'R', 'C', 'H'};

    int N;
    cin >> N;
    vector<ll> cnt(5, 0);
    for (int i = 0; i < N; ++i) {
        string S;
        cin >> S;
        char &c = S.front();
        for (int j = 0; j < 5; ++j) {
            if (c == V.at(j)) {
                cnt.at(j)++;
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; ++i) {
        for (int j = i + 1; j < 5; ++j) {
            for (int k = j + 1; k < 5; ++k) {
                ans += cnt.at(i) * cnt.at(j) * cnt.at(k);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int cnt[] = new int[26];
        String str;
        char c = 0;
        char c2 = 'a';

        while (null != (str = br.readLine())) {
            for (int i = 0; i < str.length(); i++) {
                str = str.toLowerCase();
                c = str.charAt(i);
                if (Character.isLowerCase(c)) {
                    for (int j = 0; j < cnt.length; j++) {
                        if (c == c2) {
                            cnt[j]++;
                            c2 = 'a';
                            break;
                        } else {
                            c2++;
                        }
                    }
                }
            }
        }
        
        for (int i = 0; i < cnt.length; i++) {
            System.out.println(c2 + " : " + cnt[i]);
            c2++;
        }
    }
}

Measured memory_bytes: 25932
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    string S;
    cin >> S;

    int w;
    cin >> w;

    REP(i,S.size()) {
        if (i%w == 0) cout << S[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#define INF 1000000000;

int max(int a,int b);
int main(void){
	long n;
	scanf("%ld",&n);
	long i,j;
	long a,b;
	int min=INF;
	for(i=1;i<=sqrt(n)+1;i++){
		if(n%i==0){
			a=n/i;
			b=i;
			int cnta=1,cntb=1,cnt;
			while(a/10!=0){
				a=a/10;
				cnta++;
			}
			while(b/10!=0){
				b=b/10;
				cntb++;
			}
			cnt=max(cnta,cntb);
			if(min>cnt){
				min=cnt;
			}
		}
	}
	printf("%d\n",min);
	return 0;
}

int max(int a,int b){
	if(a<b){
		return b;
	}else{
		return a;
	}
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, AS):
    ret = 0
    prevStep = 0
    for i in range(1, N):
        if prevStep + AS[i - 1] > AS[i]:
            prevStep = prevStep + AS[i - 1] - AS[i]
            ret += prevStep
        else:
            prevStep = 0
    return ret


def main():
    N = int(input())
    AS = list(map(int, input().split()))
    print(solve(N, AS))


# tests
T1 = """
5
2 1 5 4 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
4
"""

T2 = """
5
3 3 3 3 3
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
0
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


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

int main() {
  char b;
  cin >> b;

  if(b=='A')  cout << 'T';
  else if(b=='T') cout << 'A';
  else if(b=='C') cout << 'G';
  else if(b=='G') cout << 'C';
 
return 0;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl enjoy_codeforces
void debug_impl(){std::cerr<<'\n';}
template<class Head,class...Tail>void debug_impl(Head head, Tail... tail){std::cerr << " " << head;debug_impl(tail...);}
    template<class Container,class Value=typename Container::value_type,std::enable_if_t<!std::is_same<Container,std::string>::value,std::nullptr_t> = nullptr>
std::ostream&operator<<(std::ostream&os,Container const&v)
{os<<"{";for(auto it=v.begin();it!=v.end();it++){os<<(it!=v.begin()?",":"")<<*it;}return os<<"}";}
    template<template<class...>class Tuple,class...Args,std::size_t...Inds,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&tuple_output_impl(std::ostream&os,const Tuple<Args...>&tuple,std::integer_sequence<std::size_t,Inds...>)
{os<<"(";(void)std::initializer_list<int>{((void)(os<<(Inds>0?",":"")<<std::get<Inds>(tuple)),0)...};return os<<")";}
    template<template<class...>class Tuple,class...Args,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&operator<<(std::ostream&os,const Tuple<Args...>&tuple)
{return tuple_output_impl(os,tuple,std::index_sequence_for<Args...>());}
#define DEBUG 0
#if DEBUG
#define debug(...)do{std::cerr<<std::boolalpha<<"["<<#__VA_ARGS__<<"]:";debug_impl(__VA_ARGS__);std::cerr<<std::noboolalpha;}while(false)
#else
#define debug(...) {}
#endif
int main(){
    int n;std::cin>>n;
    long long N=1<<n;
    std::vector<std::vector<std::pair<int,int>>>g(n);
    for(int i=0;i<n-1;i++){
        int u,v;std::cin>>u>>v;u--,v--;
        debug(u,v);
        g.at(u).emplace_back(v,i);
        g.at(v).emplace_back(u,i);
    }
    debug(g);
    int q;std::cin>>q;
    std::vector<std::pair<int,int>>uv(q);
    for(int i=0;i<q;i++){
        int u,v;std::cin>>u>>v;u--,v--;
        uv.at(i)={u,v};
    }
    debug(uv);
    int Q=1<<q;
    std::vector<long long>b(Q);
    b.at(0)=1ll<<n-1;
    std::vector<int>mul(n-1);
    for(int bs=0,i=1;i<Q;i++){
        bs^=1<<__builtin_ctz(i);
        debug(std::bitset<8>(bs));
        int d=bs>>__builtin_ctz(i)&1?1:-1;
        int u,v;std::tie(u,v)=uv.at(__builtin_ctz(i));
        auto dfs=[&](auto&&dfs,int x,int p)->bool{
            if(x==v)return true;
            for(auto&&pair:g.at(x)){
                int y,id;std::tie(y,id)=pair;
                if(y==p)continue;
                if(dfs(dfs,y,x)){
                    mul.at(id)+=d;
                    return true;
                }
            }
            return false;
        };
        dfs(dfs,u,u);
        int counter=0;
        for(int j=0;j<n-1;j++){
            counter+=!!mul.at(j);
        }
        b.at(bs)=1ll<<n-1-counter;
        debug(u,v);
        debug(mul);
    }
    debug(b);
    long long ans=0;
    for(int i=0;i<Q;i++){
        ans+=(__builtin_popcount(i)&1?-1:1)*b.at(i);
    }
    std::cout<<ans<<'\n';
}



Measured memory_bytes: 8448
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(all(A), greater<int>());
    int a = 0, b = 0;
    for(int i = 0; i < N; i++){
        if(i % 2) b+=A[i];
        else a+=A[i];
    }
    cout << a - b << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    while (1) {
        int a, b; cin >> a >> b;
        if (a + b == 0) {
            break;
        }
        if (a > b) swap(a, b);
        cout << a << ' ' << b << '\n';
    }

}



Measured memory_bytes: 3012
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll last(200001,-1) ;
	vll dp(n+1,0) ;
	dp.at(0) = 1 ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		dp.at(i+1) = dp.at(i) ;
		if(last.at(a)!=-1&&last.at(a)+1!=i) dp.at(i+1) += dp.at(last.at(a)+1) ;
		dp.at(i+1) %= mod ;
		last.at(a) = i ;
	}
	cout << dp.at(n) << endl ;
}


Measured memory_bytes: 6420
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();

    long min = Math.min(b / c, b / d) + 1;

    long m = lcm(c ,d);

    long x = b - a + 1;
    long y = (b / c) - (a - 1) / c;
    long z = (b / d) - (a - 1) / d;
    long w = (b / m) - (a - 1) / m;
    long ans = x - y - z + w;
    System.out.println(ans);
  }
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
  }

  private static long lcm(long m, long n) {
      return m * n / gcd(m, n);
  }

}


Measured memory_bytes: 23124