akhauriyash/Code-Regression huggingface dataset:
n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))
for i in range(n):
    a[i+1] = (a[i] + a[i+1]-1)%k
d = dict()
ans = 0
for i in range(n+1):
    if i >= k:
        d[a[i-k]] -= 1
    if a[i] in d:
        ans += d[a[i]]
        d[a[i]] += 1
    else:
        d[a[i]] = 1
print(ans)


Measured memory_bytes: 33672
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n;
    map<string, int> m;
    int max_s = -1;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        m[s]++;
        max_s = max(m[s], max_s);
    }

    vector<string> ss;
    for (auto e : m) {
        if (e.second == max_s) ss.push_back(e.first);
    }
    sort(ss.begin(), ss.end());
    for (auto e : ss)
        cout << e << '\n';
    return 0;
}



Measured memory_bytes: 25584
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int a, b, t;
	cin >> a >> b >> t;
	cout << (t / a) * b << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N,W = list(map(int,input().split()))
vw = [list(map(int,input().split())) for i in range(N)]
vw.sort(key = lambda x:x[0])
value = [i[1] for i in vw]
weight = [i[0] for i in vw]
#valueが最大の要素を事前に抽出


inf=float("inf")
dp = [[-inf for _ in range(W+1)] for _ in range(N+1)]

dp[0] = [0]*(W+1)
def nap():
    for i in range(N):
        w = 0
        while w <= W:
            if weight[i] <= w:
                dp[i+1][w]=max(dp[i][w-weight[i]]+value[i],dp[i][w])
            else:
                dp[i+1][w]=dp[i][w]
            w+=1
nap()

ret = 0
for i in range(N):
    ret = max(ret,dp[i][W-1]+value[i])
print(ret)

Measured memory_bytes: 273668
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

vector<vi> e;
int ans;
bool v[100010];
void rec(int c, int p, int g){
	v[c] = 1;
	for(int i : e[c]) if(i != p){
		if(i == g) ans++;
		else if(!v[i]) rec(i, c, g);
	}
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, m; cin >> n >> m;
	e.resize(n);
	rep(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	vi v;
	rep(i, n){
		if(e[i].size() % 2){
			cout << "No" << endl;
			return 0;
		}
	}
	rep(i, n){
		if(e[i].size() >= 6 || e[i].size() == 4 && v.size() >= 2){
			cout << "Yes" << endl;
			return 0;
		}
		if(e[i].size() == 4) v.pb(i);
	}
	if(v.size() < 2){
		cout << "No" << endl;
		return 0;
	}
	
	rec(v[0], v[0], v[1]);
	dbg(ans);
	cout << (ans == 2 ? "Yes" : "No") << endl;
	
	return 0;
}

Measured memory_bytes: 7040
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

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



















































Measured memory_bytes: 256
import Control.Monad  -- unless

balanced :: String -> Bool
balanced s = foldl pushPop [] fs == []
  where
    fs = filter (`elem` "()[]") s
    pushPop stack x
      | x `elem` "(["                  = closing x : stack
      | stack /= [] && x == head stack = tail stack
      | otherwise                      = "E"
    closing '(' = ')'
    closing '[' = ']'


main :: IO ()
main = do
  s <- getLine
  unless (s == ".") $ do
    putStrLn . yesno . balanced $ s
    main
  where
    yesno b = if b then "yes" else "no"

Measured memory_bytes: 4040
// https://atcoder.jp/contests/abc110/tasks/abc110_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

vector<pair<long long, long long>> prime_factorize(long long n) {
    vector<pair<long long, long long>> res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0)
            continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back({p, num});
    }
    if (n != 1)
        res.push_back({n, 1});
    return res;
}

ll modpow(ll a, ll n) {
    ll r = 1;
    while (n)
        r = r * ((n % 2) ? a : 1) % MOD, a = a * a % MOD, n >>= 1;
    return r;
}

ll comb(int P_, int Q_) {
    if (P_ < 0 || Q_ < 0 || Q_ > P_)
        return 0;
    ll p = 1, q = 1;
    Q_ = min(Q_, P_ - Q_);
    for (int i = 1; i <= Q_; i++)
        p = p * P_ % MOD, q = q * i % MOD, P_--;

    return p * modpow(q, MOD - 2) % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<PLL> v = prime_factorize(m);

    ll ans = 1;
    for (auto x : v) {
        ans = (ans * comb(x.second + n - 1, n - 1)) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 1e6 + 10;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
   ll n,m;cin >> n >> m;
   vector< pair<ll,ll> >p;
   for(int i = 0;i<n;i++){
    ll a,b;
    cin >> a >> b;
    p.push_back({a,b});
   }
   sort(p.begin(),p.end());
   int cnt = 0;ll ans = 0;
   for(int i = 0;i<n;i++){
    if(p[i].second+cnt<=m) {
        cnt += p[i].second;
        ans += (p[i].second*p[i].first);
    }
    else{
        ans += (m-cnt)*p[i].first;
        break;
    }
   }
   cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 5272
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int N = 200010;

int main()
{
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n;
    string S;
    cin >> n >> S;
    int Q;
    cin >> Q;
    vector<set<int>>a(26);
    for(int i=0;i<26;++i)a[i].insert(INT_MAX);
    for(int i=0;i<(int)S.size();i++)
        a[S[i]-'a'].insert(i);
    while(Q--)
    {
        int t, x, y;
        char c;
        cin >> t;
        if(t==1){
            cin >> x >> c;
             x--;
            a[S[x]-'a'].erase(x);
            a[c-'a'].insert(x);
            S[x] = c;
        } else if(t == 2)
        {
            cin >> x >> y;
            x--, y--;
            int ans = 0;
            for(int i=0;i<26;i++)
            {
                int k = *a[i].lower_bound(x);
               // cout << k << ' ' << k << endl;
                if(y >= k)ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 27216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ABC168D
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int N = int.Parse(target[0]);
            int M = int.Parse(target[1]);
            List<List<int>> route = new List<List<int>>();
            for(int i=0;i<N;i++) route.Add(new List<int>());
            int[] dir = new int[N];
            Queue<int> queue = new Queue<int>();
            for(int i=1;i<N;i++) dir[i] = -1;
            for(int i=0;i<M;i++){
                target = Console.ReadLine().Split(' ');
                int P = int.Parse(target[0])-1;
                int Q = int.Parse(target[1])-1;
                route[P].Add(Q); route[Q].Add(P); 
            }
            queue.Enqueue(0);
            while(queue.Count > 0){
                int tmp = queue.Dequeue();
                foreach(int k in route[tmp]){
                    if(dir[k] == -1){
                        dir[k] = tmp;
                        queue.Enqueue(k);
                    }
                }
            }
            Console.WriteLine("Yes");
            for(int i=1;i<N;i++) Console.WriteLine(dir[i]+1);

        }
    }
}


Measured memory_bytes: 51668
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;
const long INF = 2000000000;

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

  int cnt1 = 0;;
  for(int i = 0; i < s.size(); i++) {
    if(i % 2 == 0 & s[i] == '0') cnt1++;
    if(i % 2 == 1 & s[i] == '1') cnt1++;
  }

  int cnt2 = 0;
  for(int i = 0; i < s.size(); i++) {
    if(i % 2 == 0 & s[i] == '1') cnt2++;
    if(i % 2 == 1 & s[i] == '0') cnt2++;
  }
  
  cout << min(cnt1,cnt2) << endl;
}

Measured memory_bytes: 3760
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int n,a,cnt=0,ans=0;
cin >> n;
for(int i=0;i<n;i++){
cin >> a;
if(a==1){
cnt++;
ans=max(ans,cnt);
}
else if(a==0){
cnt=0;
}
}
cout << ans+1 << endl;
return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vector<vector<tuple<ll, ll, ll>>> path;
//***********//
int main() {
	ll C;
	cin >> N >> K >> C;
	string S;
	cin >> S;
	vl L(K), R(K);
	ll num = 0;
	for (i = 0; i < N; i++) {
		if (S[i] == 'o') {
			L[num] = i;
			i += C;
			num++;
		}
		if (num >= K) break;
	}
	num = K-1;
	for (i = N-1; i >=0; i--) {
		if (S[i] == 'o') {
			R[num] = i;
			i -= C;
			num--;
		}
		if (num < 0) break;
	}
	//debug(R, L);
	vl Ans;
	for (i = 0; i < K; i++) {
		if (L[i] == R[i]) Ans.push_back(L[i]+1);
	}
	if (Ans.size() == 0) cout << endl;
	else {
		for (i = 0; i < Ans.size(); i++) {
			cout << Ans[i] << endl;
		}
	}
}


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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}
const ll INF = 1e18;

multiset<ll> ss1;
multiset<ll> ss2;

int x, y, z;
vector<pair<ll, ll> > vv;
ll s2;
ll sm;

int main() {
    scanf("%d%d%d", &x, &y, &z);
    int n = x + y + z;
    for (int i = 0; i < n; ++i) {
        ll a, b, c;
        scanf("%lld%lld%lld", &a, &b, &c);
        sm += a;
        vv.push_back(make_pair(b - a, c - a));
    }
    sort(vv.begin(), vv.end());
    reverse(vv.begin(), vv.end());
    ll ans = -INF;
    ll cur = 0;
    for (int i = 0; i < y; ++i) {
        ss1.insert(vv[i].first - vv[i].second);
        cur += vv[i].first;
    }
    for (int i = y; i < vv.size(); ++i) {
        ss2.insert(vv[i].second);
        s2 += vv[i].second;
    }
    while (ss2.size() > z) {
        s2 -= *ss2.begin();
        ss2.erase(ss2.begin());
    }
    ans = max(ans, cur + s2);
    for (int i = y; i < y + z; ++i) {
        if (ss2.find(vv[i].second) != ss2.end()) {
            ss2.erase(ss2.find(vv[i].second));
            s2 -= vv[i].second;
        }
        while (ss2.size() > z - (i + 1 - y)) {
            s2 -= *ss2.begin();
            ss2.erase(ss2.begin());
        }
        cur += vv[i].first;
        ss1.insert(vv[i].first - vv[i].second);
        cur -= *ss1.begin();
        ss1.erase(ss1.begin());
        ans = max(ans, cur + s2);
    }
    cout << ans + sm << "\n";
    return 0;
}




Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e4+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
//#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    cout<<(n-1)/(k-1)+((n-1)%(k-1)!=0);
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
// typedef
using ll  = long long;
using str = string;
using PL  = pair<ll, ll>;
using P   = pair<int, int>;
using VL  = vector<ll>;
using VI  = vector<int>;
using VS  = vector<str>;
using VP  = vector<P>;
using VPL = vector<PL>;
using VVL = vector<VL>;
using VVI = vector<VI>;

// const num
const ll INF         = 1e18 + 18;
const ll MAX         = 100005;
const ll MOD         = 1000000007;
const long double PI = acosl(-1.0);

// loop
#define REP(i, a, b) for(ll(i) = (a); (i) < (b); (i)++)
#define RREP(i, a, b) for(ll(i) = (a); (i) >= (b); (i)--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)

// YesNo
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
// All
#define ALL(v) v.begin(), v.end()
#define deduplicate(v) (v).erase(unique(ALL(d)), (v).end())

int main(void) {
	int l, r;
	int d;
	int cnt = 0;
	cin >> l >> r >> d;
	for(int i = l; i <= r; i++) {
		if(i % d == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vi A(N), B(N), C;
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i] - (i + 1);
    }
    sort(all(B));
    C = B;
    C.erase(unique(all(C)), C.end());
    
    ll sm = 0;
    rep(i, N)sm += B[i] - C[0];
    ll re = sm;

    ll p = 0;
    FOR(i, 1, sz(C)) {
        while (p < N && B[p] < C[i])++p;
        ll q = N - p;
        sm += (p - q) * (C[i] - C[i - 1]);
        smin(re, sm);
    }

    cout << re << endl;
}

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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if( (a*100+b*10+c)%4==0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    long long re;
    int r,d,x; cin>>r>>d>>x;
    for(int i=0;i<10;i++)
    {
       re=(r*x)-d;
       x=re;
       cout<<re<<endl;

    }

    return 0;
}


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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2 * 1000;

int n, dp[MAXN], ans, res[MAXN], ted[MAXN];
string s;
vector<int> adj[MAXN];

void dfs1(int v, int par = 0) {
	if (s[v] == '1')
		ted[v]++;
	for (auto i : adj[v])
		if (i != par)
			dfs1(i, v), ted[v] += ted[i], res[v] += res[i] + ted[i];
}
void dfs2(int v, int par = 0) {
	dp[v] = res[v] & 1;
	for (auto i : adj[v])
		if (i != par)
			dfs2(i, v), dp[v] = max(dp[v], dp[i] + 2 * ted[i] + res[i] - res[v]);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> s;
	s = '0' + s;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		adj[v].pb(u);
		adj[u].pb(v);
	}
	ans = 1e9 + 17;
	for (int i = 1; i <= n; i++) {
		memset(dp, 0, sizeof dp);
		memset(res, 0, sizeof res);
		memset(ted, 0, sizeof ted);
		dfs1(i);
		dfs2(i);
		if (!dp[i])
			ans = min(ans, res[i] >> 1);
	}
	cout << (ans == 1e9 + 17? -1: ans) << endl;
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int M=20;
const int N=1e5+10;
int n,l,a[N],p,to[M][N],q;
//
int main(){
	n=getint();
	rep(i,n)a[i]=getint();
	l=getint();
	p=n;a[n]=INF*2+10;
	for(int i=n-1;i>=0;i--){
		while(p>i+1&&a[p]-a[i]>l)p--;
		to[0][i]=(p>=n)?-1:p;
	}
	for(int i=1;i<M;i++)rep(j,n){
		if(to[i-1][j]!=-1)to[i][j]=to[i-1][to[i-1][j]];
		else to[i][j]=-1;
	}
	q=getint();
	rep(qqq,q){
		int x=getint()-1,y=getint()-1;
		if(x>y)swap(x,y);
		if(x==y)printf("%d\n",0);
		else{
			int res=0;
			for(int i=M-1;i>=0;i--)if(to[i][x]!=-1&&to[i][x]<y){
				x=to[i][x];
				res+=(1<<i);
			}
			printf("%d\n",res+1);
		}
	}
	return 0;
}

Measured memory_bytes: 9088
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main()
{
    string x,y;
    cin >> x >> y;
	for (int i = 0; i < x.size(); i++) {
		for (int j = i + 1; j <  x.size(); j++) {

			if (x[i] > x[j]) {
				int q = x[i];
				x[i] = x[j];
				x[j] = q;
			}
		}
	}
	for (int i = 0; i < y.size(); i++) {
		for (int j = i + 1; j < y.size(); j++) {

			if (y[i]<y[j]) {
				int q = y[i];
				y[i] = y[j];
				y[j] = q;
			}
		}
	}
	int e = max(x.size(), y.size());
	for (int i = 0; i < e; i++) {
		if (x[i] < y[i]) {
			cout << "Yes";
			break;
		}
		else if (x[i] > y[i]) {
			cout << "No";
			break;
		}
		else if (x[i] == y[i]&&i==e-1) {
			cout << "No";
			break;
		}
		else
			continue;
	}

	

    return 0;
}

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	std::string s;

	std::cin >> s;

	std::array<std::string, 7> w {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

	auto sun = w.begin();
	auto day = std::find(w.begin(), w.end(), s);

	std::cout << (7-std::distance(sun, day)) << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll X, A, B;
    cin >> X >> A >> B;
    if (A - B >= 0)
        cout << "delicious" << endl;
    else if (B - A <= X)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 3648
H = int(input())
heap = list(map(int, input().split()))
heap.insert(0, 0)
for i in range(1, len(heap)):
    p = i // 2
    l = i * 2
    r = i * 2 + 1
    s = 'node ' + str(i) + ': key = ' + str(heap[i]) + ', '
    if 1 <= p <= H:
        s += 'parent key = ' + str(heap[p]) + ', '
    if l <= H:
        s += 'left key = ' + str(heap[l]) + ', '
    if r <= H:
        s += 'right key = ' + str(heap[r]) + ', '

    print(s)

Measured memory_bytes: 7608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}
	Scanner cin;
	const int MOD = 1000000007;
	const int INF = int.MaxValue - 10;
	const long INFL = long.MaxValue - 10;
	const double EPS = 1e-7;
	const double PI = 3.1415926536;

	int N;
	void prog()
	{
		cin = new Scanner();
		int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int[] p = new int[N];
		long[] pa = new long[N];
		long[] pb = new long[N];
		long[] A = new long[N];
		long[] B = new long[N];
		long amin = INFL, bmin = INFL;
		for (int i = 0; i < N; i++)
		{
			p[i] = cin.nextInt() - 1;
			A[i] = i + 1;
			B[i] = N - i;
		}
		for (int i = 0; i < N; i++)
		{
			pa[p[i]] = pb[p[i]] = i;
		}
		for (int i = 1; i < N; i++)
		{
			pa[i] += pa[i - 1];
			pb[N - 1 - i] += pb[N - i];
		}
		for (int i = 0; i < N; i++)
		{
			A[i] += pa[i];
			B[i] += pb[i];
			amin = Math.Min(amin, A[i]);
			bmin = Math.Min(bmin, B[i]);
		}
		for (int i = 0; i < N; i++)
		{
			if (i < N - 1)
			{
				Console.Write("{0} ", A[i] - amin + 1);
			}
			else
			{
				Console.WriteLine(A[i] - amin + 1);
			}
		}
		for (int i = 0; i < N; i++)
		{
			if (i < N - 1)
			{
				Console.Write("{0} ", B[i] - bmin + 1);
			}
			else
			{
				Console.WriteLine(B[i] - bmin + 1);
			}
		}
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

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

int main(){
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    long long min_A, max_A;
    long long sum_A;
    min_A = *std::min_element(A.begin(), A.end());
    max_A = *std::max_element(A.begin(), A.end());
    sum_A = accumulate(A.begin(), A.end(), 0LL);
    printf("%lld %lld %lld\n", min_A, max_A, sum_A);
    return 0;
}


Measured memory_bytes: 3296
n = int(input())
a = []
for i in [6,9]:
    j = 1
    while i**j<1000000:
        a.append(i**j)
        j += 1
a.sort()
dp = [i for i in range(n+1)]
dp[0]= 0
for c in a:
    for i in range(c,n+1):
        dp[i] = min(dp[i-c]+1, dp[i])
print(dp[n])


Measured memory_bytes: 7064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
using Point = pair<lld, lld>;
const lld EPS = 1e-9;

random_device rnd;
mt19937 mt(rnd());

lld dist(Point &a, Point &b)
{
    return sqrtl((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

void update(Point &a, Point &center)
{
    Point differ = {a.first - center.first,
                    a.second - center.second};
    lld d = dist(center, a);
    differ.first /= d;
    differ.second /= d;
    center.first += differ.first * (d - 1.0);
    center.second += differ.second * (d - 1.0);
}

pair<Point, Point> get_center_of_cirlce(Point &a, Point &b)
{
    Point center = {0, 0};
    while (abs((lld)1.0 - dist(center, a)) > EPS || abs((lld)1.0 - dist(center, b)) > EPS)
    {
        update(a, center);
        update(b, center);
    }
    //cerr << fixed << setprecision(18) << center.first << " " << center.second << endl;
    //cerr << fixed << setprecision(18) << dist(center, a) << endl;
    //cerr << fixed << setprecision(18) << dist(center, b) << endl;
    Point differ1 = {a.first - center.first,
                     a.second - center.second};
    Point differ2 = {b.first - center.first,
                     b.second - center.second};
    Point other = {
        -a.first - b.first + center.first,
        -a.second - b.second + center.second};
    return {center, other};
}

int calc(vector<Point> &v, Point &center)
{
    int ret = 0;
    for (auto &&p : v)
    {
        //cerr << fixed << setprecision(18) << dist(p, center) << endl;
        if (dist(p, center) <= 1.0 + 1e-6)
        {
            ret++;
        }
        else
        {
            //cerr << "*" << fixed << setprecision(18) << abs(1.0 - dist(p, center)) << endl;
        }
    }
    return ret;
}

void solve()
{
    int n;
    cin >> n;
    if (n == 0)
        exit(0);
    vector<Point> v(n);
    int ans = 1;
    rep(i, n) cin >> v[i].first >> v[i].second;
    rep(i, n)
    {
        rep(j, i + 1, n)
        {
            if (dist(v[i], v[j]) > 2.0 + EPS)
            {
                continue;
            }
            auto ret = get_center_of_cirlce(v[i], v[j]);
            //cerr << fixed << setprecision(18) << abs(1.0 - dist(v[i], ret.first)) << endl;
            chmax(ans, calc(v, ret.first));
            chmax(ans, calc(v, ret.second));
        }
    }
    cout << ans << endl;
    return;
}

int main()
{
    while (true)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3256
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[2][n];

		for (int i = 0; i < n; i++) {
			a[0][i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			a[1][i] = sc.nextInt();
		}

		int max = 0;
		int first = 0;
		for (int i = 0; i < n; i++) {
			first += a[0][i];
			int second = 0;
			for (int j = i; j < n; j++) {
				second += a[1][j];
			}
			max = Math.max(max, first + second);
		}

		System.out.println(max);

		sc.close();

	}

}

Measured memory_bytes: 36128
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>

using namespace std;

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

#define fs first
#define sc second


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

    int x = (N + A - 1)/ A;
    if(x > B){
        cout << -1 << endl;
        return 0;
    }
    if(A + B > N+1){
        cout << -1 << endl;
        return 0;
    }

    vector<int> res;
    for(int i = 0; i <= N; i++){
        int z = ((N - i) + (A - 1)) / A;
        if(B == z + i){
            int start = N - A + 1;
            for(int j = 0; j < z; j++){
                for(int k = 0; k < A; k++){
                    if(start + k > i){
                        res.push_back(start + k);
                    }
                }
                start -= A;
            }
            for(int j = i; j > 0; j--){
                res.push_back(j);
            }
            break;
        }
    }

    for(auto r: res){
        cout << r << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3440
def A():
    s = input()
    days = ['SAT', 'FRI', 'THU', 'WED', 'TUE','MON', 'SUN']
    print(days.index(s)+1)

def B():
    d = {chr(65+i): i for i in range(0, 26)}
    N = int(input())
    S = input()
    ans = ""
    def helper(n):
        if n>25:
            return n-26
        return n
    for c in S:
        ans+=chr(65+helper(N+d[c]))
    print(ans)
B()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int N;
	cin >> N;
	vector<int> a(N), b(N);
	for(int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	for(int i = 0; i < N; ++i){
		cin >> b[i];
	}
	int res = 0;
	for(int k = 1; k <= 30; ++k) {
		long long M = 1LL << k;
		vector<int> bb(N);
		for(int i = 0; i < N; ++i) {
			bb[i] = b[i] % M;
		}
		sort(ALL(bb));
		int cnt = 0;
		for(int i = 0; i < N; ++i) {
			int aa = a[i] % M;
			cnt += (lower_bound(ALL(bb), M - aa) - lower_bound(ALL(bb), M / 2 - aa))
				+ (lower_bound(ALL(bb), 2 * M - aa) - lower_bound(ALL(bb), 3 * M / 2 - aa));
		}
		res |= (cnt % 2) << (k-1);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4992
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mod=1e9+7;
ll N;
ll memo[2100000];
bool vis[2100000];
bool k[22][22];
ll sol(int pos,int mask){
  if(pos==N)return 1;
  if(vis[mask])return memo[mask];
  vis[mask]=1;
  ll t=0;
  for(int i=0;i<N;i++){
    if(k[pos][i] && (mask&(1<<i))==0){
      t+=sol(pos+1,mask+(1<<i));
    }
  }
  return memo[mask]=t%mod;
}
signed main(){
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
		cin>>N;
		for(ll i=0;i<N;i++){
      for(int j=0;j<N;j++)cin>>k[i][j];
		}
		cout<<sol(0,0);
    return 0;
}

Measured memory_bytes: 18688
package main

import (
	"fmt"
)

func main() {
	var n, l, ans int
	fmt.Scan(&n, &l)

	first := l
	last := l + n - 1

	if first >= 0 {
		for i := first + 1; i <= last; i++ {
			ans += i
		}
	} else if first < 0 && 0 <= last {
		for i := first; i <= last; i++ {
			ans += i
		}
	} else {
		for i := first; i < last; i++ {
			ans += i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
vector<int> vis, to;
int dfs(int i, int c) {
    vis[i] = 1;
    if (!vis[to[i]]) {
        return dfs(to[i], c + 1);
    }
    return c;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, r;
    cin >> n >> r;
    vis.resize(n);
    to.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> to[i];
        --to[i];
    }
    vector<int> co(n + 1);
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            int t = dfs(i, 1);
            co[t]++;
            // cout << t << endl;
        }
    }
    vector<int> a, b;
    for (int i = 0; i <= n; i++) {
        if (co[i]) {
            a.push_back(i);     // val
            b.push_back(co[i]); // limit
        }
    }
    int m = a.size();
    //  cout << m << endl;
    auto dp = make_v<int>(n + 1);
    fill_v(dp, -1);
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j <= n; j++) {
            if (dp[j] != -1) {
                dp[j] = b[i];
            }
            if (j >= a[i] && dp[j - a[i]] > 0) {
                chmax(dp[j], dp[j - a[i]] - 1);
            }
        }
        //  cout << dp[i + 1];
    }
    if (dp[r] != -1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 7624
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <map>
#include <set>

using namespace std;

uint64_t N;
  vector<uint64_t> Ss;


int main() {

  cin >> N;

  map<uint64_t, uint64_t> mods;
  mods[0] = 0;

  for (uint i = 0; i < N; ++i) {
    uint64_t s;
    cin >> s;
    Ss.push_back(s);

    auto res = mods.emplace(s % 10, s);
    if (!res.second) {
      auto it = res.first;
      if (s < it->second)
        it->second = s;
    }
  }

  vector<uint64_t> bads = {0};
  for (auto p : mods) {
    auto s = bads.size();
    for (size_t i = 0; i < s; ++i)
      bads.push_back(p.second + bads[i]);
  }

  sort(bads.begin(), bads.end());

  uint64_t sum = accumulate(Ss.cbegin(), Ss.cend(), static_cast<uint64_t>(0));

  for (auto b : bads) {
    if ((sum - b) % 10) {
      cout << sum - b << endl;
      return 0;
    }
  }

  cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
class Map(dict):
    def __missing__(self, key):
        self[key] = 0
        return 0


def main():
    int(input())

    d = Map()
    ans = 0
    for i, height in enumerate(input().split()):
        height = int(height)
        # 引き算のほうの i は足し算のよりも大きい。
        # 従って，このように順番に見ていく必要がある。
        d[i + height] += 1
        ans += d[i - height]

    return ans


if __name__ == '__main__':
    print(main())

# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030


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

public class Main {

	public static int solve (String str) {
		int[] nums = new int[str.length()];
		int sum = 0;
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'M')
				nums[i] = 1000;
			else if (str.charAt(i) == 'D')
				nums[i] = 500;
			else if (str.charAt(i) == 'C')
				nums[i] = 100;
			else if (str.charAt(i) == 'L')
				nums[i] = 50;
			else if (str.charAt(i) == 'X')
				nums[i] = 10;
			else if (str.charAt(i) == 'V')
				nums[i] = 5;
			else if (str.charAt(i) == 'I')
				nums[i] = 1;
		}
//		System.out.println(Arrays.toString(nums));
		sum = nums[0];
		for (int i = 1; i < nums.length; i++) {
			if (nums[i - 1] < nums[i]) {
				sum -= nums[i - 1];
				sum += nums[i] - nums[i - 1];
			} else
				sum += nums[i];
//			System.out.println(sum);
		}
		return sum;
	}

	public static void main(String[] args) throws IOException {

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {
			System.out.println(solve(line));
			line = null;
		}

	}

}

Measured memory_bytes: 16876
#include <bits/stdc++.h>
 
int gcd(int x,int y){
    if (y==0) return x;
    else gcd(y,x%y);
}

int main (){
    int a,b,c;

    scanf("%d%d",&a,&b);

    if(a<b){
        std::swap(a,b);
    }
    c=gcd(a,b);
    printf("%d\n",c);

}

Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

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

int main()
{
  int x[5];
  for (int i = 0; i < 5; i++)
  {
    cin >> x[i];
    if (x[i] == 0)
    {
      cout << i + 1;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  vector<char>a;
  int i;
  for( i=0;i<n;i++)
  {
    a.push_back(s[i]);
    a.push_back(t[i]);
  }
  for(i=0;i<a.size();i++)
  {
    cout<<a[i];
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 100000000
//#define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

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

    long long int ans = 1;
    long long int MOD = 1000000007;
    for(long long int i = 1; i <= n; i++){
        ans = ans * i % MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ 1369: Distribution Center
// 2017.11.3 bal4u@uu
// 2018.1.5

#include <stdio.h>
#include <string.h>

int y[100002];
int l[200002], r[200002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, m, i, x, xmin, xmax;

	n = in(), m = in();
	x = in(), y[x] = in();
	xmin = xmax = x;
	i = m-1; while (i--) {
		x = in(), y[x] = in();
		if (x < xmin) xmin = x;
		else if (x > xmax) xmax = x;
	}

	for (i = 1; i <= n; i++) l[i] = i;
	memcpy(r, l, sizeof(int)*(n+1));

	for (x = xmin; x <= xmax; x++) {
		if (y[x]) i = y[x], l[i+1] = l[i], r[i] = r[i+1];
	}
	printf("%d", r[1]-l[1]+1);
	for (i = 2; i <= n; i++) printf(" %d", r[i]-l[i]+1);
	putchar('\n');
	return 0;
}



Measured memory_bytes: 3788
import sys

def solve(lis):
    for e in lis[1:3]:
        if not e%2:
            return "NG"
    for e in lis[3:10]:
        if e%2:
            return "NG"
    return "OK"

li = [0]*102
for s in sys.stdin:
    a,b = map(int,s.split())
    if a == b == 0:
        print solve(li)
        li = [0]*102
        continue
    li[a] += 1
    li[b] += 1

Measured memory_bytes: 4216
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define INF 1e15

typedef struct edge{
    long long int from;
    long long int to;
    long long int cost;
} edge;

int main(){
    long long int n, m;
    cin >> n >> m;
    
    vector<edge> v;
    long long int d[1001];
    long long int a, b, c;
    
    bool negative[1001];
    
    fill(negative+1, negative+n+1, false);
    
    fill(d+1, d+n+1, INF);
    
    d[1] = 0;
    
    long long int i, j;
    for(i = 0; i < m; i++){
        cin >> a >> b >> c;
        edge e;
        e.from = a;
        e.to = b;
        e.cost = -c;
        v.push_back(e);
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            edge e = v[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            edge e = v[j];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                negative[e.to] = true;
            }
            
            if(negative[e.from] == true){
                negative[e.to] = true;
            }
        }
    }
    
    if(!negative[n]){
        cout << (-1)*d[n] << endl;
    }else{
        cout << "inf" << endl;
    }
    
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int n,a,b,x,cnt=0;
	scanf("%d%d%d",&n,&a,&b);
	while (n--) {
		scanf("%d",&x);
		if (x<a||x>=b) {
			++cnt;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 505

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

    int r;
    cin >> r;
    cout << fixed << setprecision(5) << 3.14159*2*r << "\n";    

    return 0;
}


Measured memory_bytes: 3820
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input! {
        n: usize,
        a: i64,
        b: i64,
        c: i64,
        mut l: [i64; n],
    }

    l.sort();

    let abc = [a, b, c];
    let ans = rec(&l, &abc, &mut BTreeMap::new());

    println!("{}", ans);
}

fn rec(l: &Vec<i64>, abc: &[i64], tbl: &mut BTreeMap<Vec<i64>, i64>) -> i64 {
    if let Some(ret) = tbl.get(l) {
        return *ret;
    }

    let mut ret = 1000000;

    for i in 0..l.len() {
        for j in 0..l.len() {
            if i == j {
                continue;
            }
            for k in 0..l.len() {
                if i == k || j == k {
                    continue;
                }

                let cur = (l[i] - abc[0]).abs() + (l[j] - abc[1]).abs() + (l[k] - abc[2]).abs();
                ret = std::cmp::min(ret, cur);
            }
        }
    }

    for i in 0..l.len() {
        for j in i + 1..l.len() {
            let mut nl = vec![l[i] + l[j]];

            for k in 0..l.len() {
                if k != i && k != j {
                    nl.push(l[k]);
                }
            }
            nl.sort();

            ret = std::cmp::min(ret, rec(&nl, abc, tbl) + 10);
        }
    }

    tbl.insert(l.clone(), ret);
    ret
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-
 
# Input
s = [input() for i in range(2)]
 
N = int(s[0].split()[0])
A = int(s[0].split()[1])
B = int(s[0].split()[2])
X = s[1].split()
 
F = 0
 
# 疲労度の少ない方法を逐次選択する
for i in range(0, N-1):
    if A*(int(X[i+1]) - int(X[i])) >= B:
        F = F + B
    else:
        F = F + A*(int(X[i+1]) - int(X[i]))
 
# Output
print(F)

Measured memory_bytes: 11096
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	int m=2*d+1;
	int cnt=1;
	int a=m;
	while(1){
		if(m>=n){
			break;
		}
		m+=a;
		cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256