akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int A[3];
	cin >> A[0] >> A[1] >> A[2];
	sort(A, A + 3);
	if (A[0] == 5 && A[1] ==5 && A[2] == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s, t;
    cin >> s >> t;
    s += s;
    rep(i, s.size())
    {
        if (s.size() < i + t.size())
            break;
        if (s.compare(i, t.size(), t) == 0)
        {
            OP("Yes");
            return 0;
        }
    }
    OP("No");
    return 0;
}

Measured memory_bytes: 256
# import sys
# import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import permutations #順列生成
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    ans = 0
    for i in range(n+1):
        if i%3!=0 and i%5!=0:
            ans += i
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 67204
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
#define MOD 1000000007
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ll n,cnt = 1;
	cin >> n;
	ll a[n],b[n];
	
	rep(i,0,n){
		cin >> a[i];
		b[i] = abs(n-2*i-1);
	}
	
	sort(a,a+n);
	sort(b,b+n);
	
	rep(i,0,n){
		if(a[i] != b[i]){
			cout << 0 << endl;
			return 0;
		}
	}
	
	rep(i,0,n/2){
		cnt *= 2;
		cnt %= MOD;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1792
from itertools import permutations

N = int(input())
P = input().replace(' ', '')
Q = input().replace(' ', '')

index = {}
i = 0
for l in permutations(list(map(str, range(1, N + 1)))):
    i += 1
    index[''.join(l)] = i
print(abs(index[P] - index[Q]))


Measured memory_bytes: 8552
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const ll LINF = 1e18;
// clang-format on

void solve(long long N, long long L, std::vector<std::string> S) {
  sort(all(S));
  string ans;
  rep(i, N) { ans += S[i]; }
  cout << ans << endl;
}

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


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n; cin >> n;
    vector<int> b(n-1);
    rep(i, n-1) cin >> b[i];
    ll ans = b[0]+b[n-2];
    rep(i, n-2) ans += min(b[i], b[i+1]);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a, b, c = mi()
    print(min(c, b // a))


if __name__ == "__main__":
    main()


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> binary_search(ll l, ll r, ll num1, ll num2, ll t, ll a){
    // tx >= num1, ax >= num2 となる最小のxを見つける
    vector<ll> ans;
    map<ll, bool> tried;
    tried[l] = false;
    tried[r] = true;

    while (true){
        ll mid = (r + l) / 2;

        // 後半２つは t*midやa*midがoverflowしないための例外処理
        bool cond = (t * mid >= num1 && a * mid >= num2 || INF / mid <= t || INF / mid <= a);
        if (cond){
            r = mid;
            tried[mid] = true;
        } else {
            l = mid;
            tried[mid] = false;
        }

        // 一つ前ではだめで，ここではokという変曲点があるはず
        if (tried.find(mid+1) != tried.end() && tried[mid + 1] && !tried[mid]){
            ans.push_back(t * (mid + 1)); ans.push_back(a * (mid + 1));
            return ans;
        }
        if (tried.find(mid-1) != tried.end() && !tried[mid - 1] && tried[mid]){
            ans.push_back(t * mid); ans.push_back(a * mid);
            return ans;
        }
    }
}


void Main() {
    ll t, a, N; cin >> N;
    ll num1 = 1, num2 = 1;
    rep(i, N){
        cin >> t >> a;
        vector<ll> ans = binary_search(0, 1000000000000000000, num1, num2, t, a);
        num1 = ans.at(0); num2 = ans.at(1);
    }
    cout << num1 + num2 << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
S = list(input())
K = int(input())
N = len(S)

import sys

if N==1:
    print(K*N//2)
    sys.exit()

if S[0] == S[-1]:
    
    cnt = 1
    m = 0
    flag = True
    tmpcnt1 = 0
    for i in range(N-1):
        if S[i+1] == S[i]:
            cnt += 1
        else:
            if flag:
                tmpcnt1 = cnt
                flag = False
                cnt = 1
            else:
                m += cnt//2
                cnt = 1
    ans = 0
    ans += m*K
    ans += (tmpcnt1 + cnt)//2 *(K-1)
    ans += tmpcnt1//2
    ans += cnt//2
    
    if cnt == N:
        print(K*N//2)    
    else:
        print(ans)
        
else:
    cnt = 1
    m = 0
    for i in range(N-1):
        if S[i+1] == S[i]:
            cnt += 1
        else:
            m += cnt//2
            cnt = 1
    m += cnt//2
    print(m*K)
    

Measured memory_bytes: 3064
toInt :: String -> [Int]
toInt x = map read $ words x :: [Int]

product' :: ([Int], [Int]) -> (Int, Int)
product' (a, b) = (product a, product b)

cmp :: (Int, Int) -> Int
cmp (a, b) 
    | a >= b = a
    | a < b = b

main = do
    x <- getLine
    putStrLn $ show $ cmp $ product' $ splitAt 2 $ toInt x
    

Measured memory_bytes: 508
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder();
  o.o(o.ceil(o.n()/2))
}
m();

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n;i++) cin >> c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());


    vector<ll> matchbc(n);
    for(int i=0;i<n;i++){
        ll ubb = c.end() - upper_bound(c.begin(),c.end(),b[i]);
        matchbc[i] = ubb;
    }

    vector<ll> csum(n+1);
    csum[0] = 0;
    for(int i=0;i<n;i++) csum[i+1] = csum[i] + matchbc[n-1-i];


    ll ans = 0;
    for(int i=0;i<n;i++){
        ll ub = b.end() - upper_bound(b.begin(),b.end(),a[i]);
        ans += csum[ub];
    }

    cout << ans << endl;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

const int INF = 2e5;
const int N = 1e5 + 4;
vi adj[N];
int da[N], dt[N];

void dfs(int u, int p) {
	int d = da[u] + 1;
	for (int v : adj[u]) if (v != p) {
		da[v] = d;
		dfs(v, u);
	}
}

void dfs2(int u, int p) {
	int d = dt[u] + 1;
	for (int v : adj[u]) if (v != p) {
		if (d < da[v]) {
			dt[v] = d;
			dfs2(v, u);
		}
	}
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, u, v;
	scanf("%d%d%d", &n, &u, &v);
	for (int i = 0; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	for (int i = 1; i <= n; i++) da[i] = dt[i] = INF;
	da[v] = 0;
	dfs(v, 0);
	//for (int i = 1; i <= n; i++) printf("%d ", da[i]); puts("");

	dt[u] = 0;
	dfs2(u, 0);
	//for (int i = 1; i <= n; i++) printf("%d ", dt[i]); puts("");

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (dt[i] < INF) ans = max(ans, da[i] - 1);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 10368
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
ll power(ll x, ll p){
  ll curr = x;
  ll res = 1;
  ll tmp = p;
  while(tmp){
    if(tmp % 2 == 1)res = res * curr % mod;
    curr = curr * curr % mod;
    tmp /= 2;
  }
  return res;
}

ll inv[100001];
ll fac[100001];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n)cin >> a[i];
  fac[0] = 1;
  FOR(i, 1, n+1)fac[i] = fac[i-1] * i % mod;
  FOR(i, 1, n+1){
    inv[i] = power(i, mod - 2);
  }
  FOR(i, 1, n+1){
    inv[i] = (inv[i] + inv[i-1]) % mod;
  }
  ll res = 0;
  rep(j, n){
    ll tmp = (inv[j+1] + inv[n-j] - 1) % mod;
    if(j == 0)tmp = inv[n];
    else if(j == n - 1)tmp = inv[n];
    if(tmp < 0)tmp += mod;
    res = (res + tmp * a[j] % mod) % mod;
  }
  cout << res * fac[n] % mod << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,M=1e9,count=0;
  cin>>N;
  vector<int> A(N,0);
  for(int i=0;i<N;i++)
  {
    cin>>A.at(i);
    if(A.at(i)<=M){M=A.at(i);count++;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define l first
#define r second

int main(){
	int n,w,h,p;
	while(cin>>n>>w>>h){
		p=w*2+h*2;
		deque<pii> rng(n);
		rep(i,n){
			int x,y,v; char c;
			cin>>x>>y>>c;
			rng[i].l=[=]{return (int[]){x-h+y,x+h-y,w*2+h+y-x,w*2+h-y-x}["NEWS"s.find(c)];}();
			rng[i].r=[=]{return (int[]){x+h-y,w*2+h-y-x,w*2+h+y+x,w*2+h+y-x}["NEWS"s.find(c)];}();
		}
		sort(all(rng),[](pii a,pii b){return a.r<b.r;});
		//for(auto i:rng)cout<<i.l<<","<<i.r<<endl;
		
		int ans=1e8;
		rep(i,n) {
			//for(auto&j:rng) if(j.r<rng[0].r) j.l+=p, j.r+=p;
			sort(all(rng),[](pii a,pii b){return a.r<b.r;});
			int a=1,b=rng[0].r;
			//cout<<i<<":"<<b<<"====="<<endl;
			range(j,1,n){
				if(rng[j].l>b){
					a++;
					b=rng[j].r;
					//cout<<j<<":"<<b<<endl;
				}
			}
			ans=min(ans,a);
			rng[0].l+=p, rng[0].r+=p;
			//rng.push_back(rng[0]);
			//rng.pop_front();
		}
		cout<<ans<<endl;
	}
	return 0;
}



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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

constexpr static int MOD = 1000000000 + 7;
constexpr static int inf = INT_MAX / 2;
constexpr static llong INF = 1LL<<31;
constexpr static int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<string> S(n);
    rep(i, n) cin >> S[i];

    llong cnt = 0, cntA = 0, cntB = 0, cntBA = 0;
    rep(i, n) {
        if (S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A') {
            ++cntBA;
        } else {
            if (S[i][0] == 'B') ++cntB;
            if (S[i][S[i].size() - 1] == 'A') ++cntA;
        } 
        rep(j, S[i].size() - 1) {
            if (S[i][j] == 'A' && S[i][j + 1] == 'B') ++cnt;
        }
    }

    int ans = cnt;
    if (! cntBA) {
        ans += min(cntA, cntB);
    } else {
        if (cntA || cntB) ans += cntBA + min(cntA, cntB);
        else ans += cntBA - 1;
    }

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

Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }
 
typedef complex<double> P;

double triangleArea(P a, P b, P c)
{
    b -= a;
    c -= a;
    
    return (0.5 * abs(b.imag() * c.real() - c.imag() * b.real()));
}

// _ªOp`ÌÉ é©
bool isInTriangle(P p[3], P x)
{
    int i;
    double S = triangleArea(p[0], p[1], p[2]);
    
    rep(i, 3) S -= triangleArea(x, p[i], p[(i + 1) % 3]);
    
    return abs(S) < EPS;
}
 
int main()
{
    int n;
        cin >> n;
        
        
        while(n--)
        {
                P p[3];
                P k, s;
                
                rep(i, 3) cin >> p[i].real() >> p[i].imag();
                cin >> k.real() >> k.imag() >> s.real() >> s.imag();
        
                if(isInTriangle(p, k) ^ isInTriangle(p, s))
                {
                        cout << "OK" << endl;
                }
                else
                {
                        cout << "NG" << endl;
                }
        }
}
 

Measured memory_bytes: 948
import collections
from itertools import combinations
N = int(input())
ab = [tuple(map(int, input().split())) for i in range(N-1)]
M = int(input())
uv = [tuple(map(int, input().split())) for i in range(M)]


def popcount(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


G = [[-1]*N for i in range(N)]
for i in range(N-1):
    a, b = ab[i]
    a -= 1
    b -= 1
    G[a][b] = i
    G[b][a] = i

q = collections.deque()

G2 = [[0 for j in range(N)] for i in range(N)]

for i in range(N):
    q.append((i, 0))
    reached = [False]*N
    reached[i] = True
    while(q):
        x, s = q.popleft()
        for y in range(N):
            if G[x][y] == -1 or reached[y]:
                continue
            else:
                G2[i][y] = s | (1 << G[x][y])
                q.append((y, s | 1 << G[x][y]))
                reached[y] = True


ans = 2**(N-1)
ans2 = 0
for i in range(1, 2**M):
    tmp = 2**(N-1) - 1
    for j in range(M):
        if (i >> j) % 2 == 1:
            u, v = uv[j]
            u -= 1
            v -= 1
            tmp &= ~G2[u][v]
    ans2 += ((-1)**(popcount(i)-1)) * (1 << popcount(tmp))
    # print(ans2, i)
print(ans-ans2)


Measured memory_bytes: 44892
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//MessageBox(GetForegroundWindow(),"标题","内容",MB_YESNO);
	int n;
	cin>>n;
	int sum=0;
	while(n--){
		int a,b;
		cin>>a>>b;
		if(a==b){
			sum++;
		}else{
			sum=0;
		}
		if(sum==3){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3616
from collections import defaultdict
import sys
input = sys.stdin.readline

# エラトステネスの篩
#############################################################
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
#############################################################

# 素因数分解、リストで返す
#############################################################
def prime_factorize(n, prime_list):
    a = []
    for p in prime_list:
        if p * p > n:
            break
        while True:
            if n % p == 0:
                a.append(p)
                n //= p
            else:
                break
    if n != 1:
        a.append(n)
    a.sort()
    return a
#############################################################


N = int(input())
A = list(map(int, input().split()))

data = set(get_sieve_of_eratosthenes(10**6))

primes = defaultdict(int)

for i in range(N):
    p = prime_factorize(A[i], data)
    p_set = set(p)
    for pi in p_set:
        primes[pi] += 1

# print(primes)

if len(primes) == 0:
    print("pairwise coprime")
    exit()

max_cnt = max(primes.values())
min_cnt = min(primes.values())

if max_cnt == 1:
    print("pairwise coprime")
elif max_cnt != N:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 252092
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e9;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

string s;
ll n;
bool valid(ll i) { return i <= n - 2 && s[i] == 'B' && s[i + 1] == 'C'; }

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

  cin >> s;

  n = s.length();
  ll i = 0;

  ll cnt = 0;
  ll res = 0;
  for (ll i = 0; i < n; i++) {
    if (valid(i)) {
      res += cnt;
      i += 1;
      continue;
    }
    if (s[i] == 'A')
      cnt++;
    else
      cnt = 0;
  }

  cout << res << en;

  return 0;
}

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

int main() {
	int i;
	int n, t, a;
	double num, min = 100000, idx;
	
	std::cin >> n >> t >> a;

	for (i = 0; i < n; i++) {
		std::cin >> num;
		num = abs(a - (t - num * 0.006));
		if (min > num) {
			min = num;
			idx = i;
		}
	}
	std::cout << idx+1 << std::endl;

	return 0;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 110, M = 10, mod = 1e9 + 7;

int n, m;
int d[N][N];
PII q[N * N];
char g[N][N];

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

void bfs(int x, int y)
{
	memset(d, -1, sizeof d);
	int hh = 0, tt = -1;
	d[x][y] = 0;
	q[ ++ tt] = {x, y};
	
	while (hh <= tt)
	{
		auto t = q[hh ++ ];
		
		for (int i = 0; i < 4; i ++ )
		{
			int tx = t.F + dx[i];
			int ty = t.S + dy[i];
			
			if (tx < 1 || tx > n || ty < 1 || ty > m) continue;
			if (g[tx][ty] == '#' || d[tx][ty] != -1) continue;
			
			q[ ++ tt] = {tx, ty};
			d[tx][ty] = d[t.F][t.S] + 1;
		}
	}
}

int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i ++ ) cin >> (g[i] + 1);
	
	bfs(1, 1);
	if (d[n][m] == -1)
	{
		puts("-1");
		return 0;
	}
	
	int sum = 0;
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= m; j ++ )
			if (g[i][j] == '.')
				sum ++ ;
	
	cout << sum - d[n][m] - 1 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll M;
ll A[MAX_N];

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

void no() {
	cout << "0\n";
	exit(0);
}

void solve() {
	cin >> N >> M;
	rep(i, 0, N) {
		cin >> A[i];
		if(A[i] % 2) no();
		A[i] /= 2;
	}
	int cnt = 0;
	ll res = 1;
	while(A[0] % 2 == 0) {
		cnt++; A[0] /= 2;
		res *= 2;
	}
	rep(i, 1, N) {
		int tmp = 0;
		while(A[i] % 2 == 0) {
			tmp++; A[i] /= 2;
		}
		if(tmp != cnt) no();
	}
	rep(i, 0, N) {
		res = lcm(res, A[i]);
		if(res > M) no();
	}
	cout << (M - res) / (2 * res) + 1 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 1024
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if N == 1:
  print(abs(A[0]-W))
  exit()
  
if abs(A[-1]-A[-2]) >= abs(A[-1]-W):
  print(abs(A[-1]-A[-2]))
else:
  print(abs(A[-1]-W))


Measured memory_bytes: 3188
n=int(input())
cards = [[s+" "+str(n) for n in range(1,14)] for s in ["S","H","C","D"]]
for _ in range(n):
    suit,num =input().split()
    if suit=="S":
        cards[0][int(num)-1]=0
    elif suit=="H":
        cards[1][int(num)-1]=0
    elif suit=="C":
        cards[2][int(num)-1]=0
    elif suit=="D":
        cards[3][int(num)-1]=0
for s in cards:
    for n in s:
        if n!=0:
            print(n)

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

long gcm(long a, long b){
	if (a<b) swap(a, b);

	if (a%b == 0)
		return b;
	else
		return gcm(b, a % b);
}

int main(void){

	while (true){
		long a, b, x, y;
		cin>>a>>b;
		if (cin.eof()) break;

		x = gcm(a, b);
		y = a / x * b;
		cout<<x<<" "<<y<<endl;
	}
	return 0;
} 

Measured memory_bytes: 1160
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

s = input()
if s in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
    print('A')
else:
    print('a')

Measured memory_bytes: 83304
from itertools import permutations 
n, m = map(int, input().split())

M = [[0]*n for _ in range(n)]
for _ in range(m):
    a,b = map(int, input().split())
    M[a-1][b-1] = 1
    M[b-1][a-1] = 1

cnt = 0
for per in permutations(range(n)):
    Pth = True
    for i in range(n-1):
        if M[per[i]][per[i+1]] != 1 or per[0]!=0:
            Pth = False
            break
    if Pth:
        cnt += 1
print(cnt)

Measured memory_bytes: 3188
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int height = sc.nextInt();
		int width = sc.nextInt();
		boolean oddCoin[][] = new boolean[height][width];
		for(int i = 0; i < height; i ++) {
			for(int j = 0; j < width; j ++) {
				oddCoin[i][j] = sc.nextInt() % 2 == 1;
			}
		}
		int count = 0;
		ArrayList<String> output = new ArrayList<String>();
		for(int i = 0; i < height - 1; i ++) {
			for(int j = 0; j < width; j ++) {
				if(oddCoin[i][j]) {
					count ++;
					oddCoin[i][j] = !oddCoin[i][j];
					oddCoin[i + 1][j] = !oddCoin[i + 1][j];
					output.add((i + 1)+" "+(j + 1)+" "+(i + 1 + 1)+" "+(j + 1));
				}
			}
		}
		for(int j = 0; j < width - 1; j ++) {
			if(oddCoin[height - 1][j]) {
				count ++;
				oddCoin[height - 1][j] = !oddCoin[height - 1][j];
				oddCoin[height - 1][j + 1] = !oddCoin[height - 1][j + 1];
				output.add(height+" "+(j + 1)+" "+height+" "+(j + 2));
			}
		}
		System.out.println(count);
		for(int i = 0; i < output.size(); i ++) {
			System.out.println(output.get(i));
		}
	}
}

Measured memory_bytes: 101196
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iostream>
#define maxn 100009
using namespace std;
string s1="dream",s2="dreamer",s3="erase",s4="eraser";
bool dp[maxn];
char s[maxn];
string st(int L,int R){
	string ans="";
	if(L<1)
		return ans;
	for(int i=L;i<=R;i++)
		ans.push_back(s[i]);
	return ans;

}
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	dp[0]=1;
	for(int i=1;i<=n;i++){
		if(s1==st(i-4,i))
			dp[i]|=dp[i-5];
		if(s2==st(i-6,i))
			dp[i]|=dp[i-7];
		if(s3==st(i-4,i))
			dp[i]|=dp[i-5];
		if(s4==st(i-5,i))
			dp[i]|=dp[i-6];
	}
	if(dp[n])
		puts("YES");
	else
		puts("NO");
	//system("pause");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>


using namespace std;


struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) 
{
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;

	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}

}

Node* findNode(int key)
{
	Node *x = root;

	while (x != NIL && x->key != key) {

		if (key < x->key) {
			x = x->left;
		}
		else if(key > x->key){
			x = x->right;
		}
	}

	return x;
}

Node* treeMinimum(Node *x)
{
	while (x->left != NIL) {
		x = x->left;
	}

	return x;

}

Node* treeSuccessor(Node *x)
{
	if (x->right != NIL) {
		return treeMinimum(x->right);
	}

	Node *y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}

	return y;

}

void deleteNode(Node *z) {

	Node *y;
	Node *x;

	if (z->left == NIL || z->right == NIL) {
		y = z;
	}
	else {
		y = treeSuccessor(z);
	}

	if (y->left != NIL) {
		x = y->left;
	}
	else {
		x = y->right;
	}

	if (x != NIL) {
		x->parent = y->parent;
	}

	if (y->parent == NIL) {
		root = x;
	}
	else {
		if (y == y->parent->left) {
			y->parent->left = x;
		}
		else {
			y->parent->right = x;
		}
	}

	if (y != z) {
		z->key = y->key;
	}

	delete y;
}


void inorder(Node *u) {
	if (u == NIL) {
		return;
	}

	inorder(u->left);
	cout << " " <<u->key;
	inorder(u->right);
}


void preorder(Node *u) {
	if (u == NIL) {
		return;
	}

	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}


int main(void)
{
	int n;
	string command;
	int key;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> command;

		if (command == "insert") {
			cin >> key;
			insert(key);
		}
		else if (command == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;

		}
		else if (command == "find") {
			cin >> key;
			if (findNode(key) != NIL) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
		else if (command == "delete") {
			cin >> key;
			deleteNode(findNode(key));
		}

	}

	return 0;

}

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

int main(){
  int N;
  cin>>N;
  vector<tuple<string,int,int>> res;
  for(int i=1;i<=N;i++){
    string S;
    int P;
    cin>>S>>P;
    res.push_back(make_tuple(S,100-P,i));
  }
  sort(res.begin(),res.end());

  for(int i=0;i<N;i++){
    cout<<get<2>(res.at(i))<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int x, y, s;
    while(cin >> x >> y >> s && x) {
        int ans = 0;
        for(int i=1; i<s; ++i) {
            for(int j=1; ; ++j) {
                int p = i*(100+x)/100 + j*(100+x)/100;
                if(p > s) break;
                if(p == s) {
                    ans = max(ans, i*(100+y)/100 + j*(100+y)/100);
                }
            }
        }
        cout << ans << endl;
    }
}
// 発想を変えて、税抜き前で探索して、税を足してsに一致した時の比較で処理する。



Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  cin >> n;
  set<string > se;
  REP(i,n) {
    string s;
    cin >> s;
    se.insert(s);
  }
  int m;
  cin >> m;
  bool f = 1;
  REP(i,m) {
    string s;
    cin >> s;
    if (se.count(s)) {
      if (f) cout << "Opened by ";
      else cout << "Closed by ";
      f ^= 1;
    } else {
      cout << "Unknown ";
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1232
#include <iostream>
#include <cstdio>
#define mod 998244353
#define MN 301000

int n, cnt[8];
char s[MN];

int main()
{
	scanf("%d", &n); scanf("%s", s + 1);
	int ans = 1;
	for(int i = 1; i <= n; i++) ans = 1ll * ans * i % mod;
	
	for(int i = 1; i <= 3 * n; i++)
	{
		int x;
		if(s[i] == 'R') x = 1;
		if(s[i] == 'G') x = 2;
		if(s[i] == 'B') x = 4;
		if(cnt[x ^ 7]) ans = 1ll * ans * cnt[x ^ 7] % mod, cnt[x ^ 7]--;
		else if(x != 1 && cnt[1]) ans = 1ll * ans * cnt[1] % mod, cnt[1]--, cnt[x ^ 1]++;
		else if(x != 2 && cnt[2]) ans = 1ll * ans * cnt[2] % mod, cnt[2]--, cnt[x ^ 2]++;
		else if(x != 4 && cnt[4]) ans = 1ll * ans * cnt[4] % mod, cnt[4]--, cnt[x ^ 4]++;
		else cnt[x]++;
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC135C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = RInt;
            var A = RLongs;
            var B = RLongs;

            long ans = 0;
            for (int i = 0; i < N; i++)
            {
                long atk = Math.Min(B[i], A[i]);
                ans += atk;
                A[i] -= atk;
                B[i] -= atk;

                atk = Math.Min(B[i], A[i + 1]);
                ans += atk;
                A[i + 1] -= atk;

            }

            Console.WriteLine(ans);
        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D<T>(T[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            string[,] map2 = new string[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0.ToString();
                    else if (i == 0) map2[i, j] = (j - 1).ToString();
                    else if (j == 0) map2[i, j] = (i - 1).ToString();
                    else map2[i, j] = map[i - 1, j - 1].ToString();
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j].Last());
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D<T>(T[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 33756
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define lli long long int
#define pii pair<lli,lli>
#define f first
#define sE second
lli n,x,y,t,mod=1e9+7,ans=0;
int main() { 
    fast
    lli k;
    cin>>n>>k;
    vector<lli>a(n+1),dp(n+1,mod);
    dp[1]=0;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=1){
                dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
            }
        }
    } 
    cout<<dp[n]<<endl;
} 

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

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    int v[n], c[n];
    for(int i=0; i<n; i++) cin>>v[i];
    for(int i=0; i<n; i++) cin>>c[i];
    
    int ans = 0;
    for(int i=0; i<n; i++) {
        int s = v[i]-c[i];
        if(s>0) {
            ans += s;
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> v;
  for(ll i=1; i*i<=m; i++) {
    if(m%i==0) {
      v.pb(i);
      if(i*i!=m) v.pb(m/i);
    }
  }
  ll ans=0;
  rep(i,v.size()) {
    if(m/v[i]>=n) ans=max(ans,v[i]);
  }
  pr(ans);
}

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


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
  input! {
    mut a: isize,
    b: isize,
    mut c: isize,
    d: isize,
  }
  
  let mut turn: isize = 0;
  while (a > 0) & (c > 0) {
    if turn % 2 == 0 {
      c -= b;
    }
    else {
      a -= d;
    }
    turn += 1;
  }
  
  let ans = if c <= 0 {"Yes"} else {"No"};
  println!("{}", ans);
}


Measured memory_bytes: 2184
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main{
	public static void main(String[] args){
	int x =0;
	Scanner scan = new Scanner(System.in);
	ArrayList<Integer> list = new ArrayList<Integer>();
	int ii = 0;
		while(scan.hasNextInt()){
			x = scan.nextInt();			
			if(x == 0){
				break;
			}
			else{
				list.add(x);
			}
		}
		for(int i=0;i<list.size();i++){
			System.out.println("Case "+(i+1)+": "+list.get(i));
		}
	}
}

Measured memory_bytes: 44572
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
const int N=2e5+100;
using namespace std;
int main()
{
	string s;
	while(cin>>s)
	{
		int arr[110],flag=0;
		memset(arr,0,sizeof(arr));
		for(int i=0;i<s.size();i++)
		{
			arr[s[i]-'a']++;
		}
		sort(arr,arr+30,greater<int>());
		for(int i=0;arr[i]!=0;i++)
		{
			if(arr[i]%2!=0)
			{
				flag=1;
				cout<<"No"<<"\n";
				break;
			}
		}
		if(!flag)
		cout<<"Yes"<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int s[]={a,b,c};
    int x=0,y=0;
    for(int i=0;i<3;i++){
        if(s[i]==5)
            x++;
        else if(s[i]==7)
            y++;
    }

    if(x==2&&y==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}


Measured memory_bytes: 3528
s = input()

if s.startswith('k') and s.endswith('eyence'):
  print('YES')
elif s.startswith('ke') and s.endswith('yence'):
  print('YES')
elif s.startswith('key') and s.endswith('ence'):
  print('YES')
elif s.startswith('keye') and s.endswith('nce'):
  print('YES')
elif s.startswith('keyen') and s.endswith('ce'):
  print('YES')
elif s.startswith('keyenc') and s.endswith('e'):
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3060
import sys

[n, y] = map(int, raw_input().split())
a = 0
b = 0
c = y // 1000
d = c - n
if n > c:
    print -1, -1, -1
    sys.exit(0)
if d >= 4:
    k = d // 4
    k = min(k, c // 5)
    b += k
    c -= k * 5
    d -= k * 4
if d * 2 > b:
    print -1, -1, -1
    sys.exit(0)
b -= 2 * d
a += d
print a, b, c

Measured memory_bytes: 2820