akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i=a; i<b; i++)
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define PB push_back
#define MP make_pair

#define N 55
#define M (N*2)
vpii g[N];
int *x[M], *y[M];

int *z[M];
void mul(int **a, int **b, int **c){ // x*y -> z
	REP(i, M){
		REP(j, M){
			z[i][j]=0;
			REP(k, M){
				z[i][j]|=a[i][k]&b[k][j];
			}
		}
	}
	REP(i, M) REP(j, M) c[i][j]=z[i][j];
}

int main(){
	REP(i, M) x[i]=new int[M], y[i]=new int[M], z[i]=new int[M];
	int n, m, c;
	while(scanf("%d%d%d", &n, &m, &c), n){
		REP(i, N) g[i].clear();
		REP(i, m){
			int a, b; scanf("%d%d", &a, &b);
			g[a].PB(MP(b, i*2+0));
			g[b].PB(MP(a, i*2+1));
		}
		REP(i, M) REP(j, M) x[i][j]=0;
		FOR(i, 1, n+1) for(pii &p:g[i]){
			int j=p.first, s=p.second;
			for(pii &q:g[j]){
				int t=q.second;
				if(s/2==t/2) continue;
				x[s][t]=1;
				// printf("%d->%d->%d %d %d\n", i, j, q.first, s, t);
			}
		}
		// REP(i, m*2){ REP(j, m*2) printf("%d ", x[i][j]); printf("\n"); }
		REP(i, M) REP(j, M) y[i][j]=(i==j);
		c--;
		while(c){
			if(c&1) mul(x, y, y);
			mul(x, x, x);
			c/=2;
		}
		// REP(i, M) REP(j, M) if(y[i][j]) printf("(%d, %d)", i, j); printf("\n");
		int ans=0;
		for(pii &p:g[1]){
			int s=p.second;
			FOR(j, 1, n+1) for(pii &q:g[j]) if(q.first==n) {
				int t=q.second;
				ans|=y[s][t];
			}
		}
		if(ans) printf("yes\n");
		else printf("no\n");
	}
}



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

#define int long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    int n,w;
    cin >> n >> w;
    vi wt(n),v(n);
    ffor(i,n){
        cin >> wt[i] >> v[i];
    }
    vvi dp(w + 1,vi(n + 1));
    // dp[i][j] -> max value we can get for allowed weight of i and j items allowed
    for(int i = 1;i <= w; ++i){
        // for this weight what's the max i can get
        for(int j = 1;j <= n; ++j){
            dp[i][j] = dp[i][j - 1];
            if(i - wt[j - 1] >= 0){
                dp[i][j] = max(dp[i][j],dp[i - wt[j - 1]][j - 1] + v[j - 1]);
            }
        }
    }

    cout << dp[w][n];
}

Measured memory_bytes: 82304
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    h1, m1, h2, m2, k = map(int, input().split())

    h = (h2 - h1) * 60
    m = m2 - m1
    ans = h + m - k
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
#include<iostream>
#include<math.h>

using namespace std;

int main () {
  int a, b, C;
  double rad, S, L, h;
  cin >> a >> b >> C;
  rad = C * M_PI / 180;
  S = a * b * sin(rad) / 2;
  L = a + b + sqrt(a*a+b*b-2*a*b*cos(rad));
  h = b*sin(rad);

  cout.precision(8);
  cout << fixed << S << " " << L << " " << h << endl;
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define dd(x) cout << #x << " : " << x << endl
using namespace std;
using ll = int64_t;

int main(){
    double a, b, h, m; cin >> a >> b >> h >> m;

    double time = h*3600+m*60;
    double asyu = time/3600;
    double bsyu = time/43200;
    double atheta = (asyu - int(asyu))*360;
    double btheta = (bsyu - int(bsyu))*360;
    double tmp1, tmp2;
    if(atheta > btheta){
        tmp1 = atheta - btheta;
        tmp2 = 360-atheta + btheta;
    } else {
        tmp1 = btheta - atheta;
        tmp2 = 360-btheta + atheta;
    }
    double dtheta = (tmp1 < tmp2) ? tmp1 : tmp2;
    dtheta /= 180.0;
    dtheta *= M_PI;

    double ans2 = a*a + b*b - 2*a*b*cos(dtheta);
    printf("%.10lf\n", sqrt(ans2));

    return 0;
}

Measured memory_bytes: 4160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using Edge = pair<ll,ll>;
using Graph =vector<vector<Edge>>;
vector<int> color;
Graph G;
ll N;
void dfs(ll v,ll o=-1,ll c=0){
for(auto u:G[v]){
  if(u.first==o)continue;
  if(u.second%2==0)color[u.first]=c,dfs(u.first,v,c);
  else color[u.first]=1-c,dfs(u.first,v,1-c);
  
}
}
int main() {
cin>>N;
G.resize(N);
rep(i,N-1){
  ll a,d,c;
  cin>>a>>d>>c;
  --a;
  --d;
  G[a].push_back(Edge(d,c));
  G[d].push_back(Edge(a,c));
}
color.resize(N,-1);
color[0]=0;
dfs(0);
rep(i,N)cout<<color[i]<<endl;
return 0;
}


Measured memory_bytes: 11264
// https://atcoder.jp/contests/abc173/tasks/abc173_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  if (N % 1000 == 0) drop(0);

  ll res = 1000 - N % 1000;

  cout << res << "\n";
}


Measured memory_bytes: 3656
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


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

    count = Counter(A)
    count = sorted(count.items(), key=lambda x: (-x[0], x[1]))
    count = [(k, v) for k, v in count if v >= 2]
    if len(count) < 2:
        print(0)
    elif count[0][1] >= 4:
        print(count[0][0] ** 2)
    else:
        print(count[0][0] * count[1][0])


if __name__ == "__main__":
    main()


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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

"""
S,T
"""

n = I()
c = LI()
c.sort(reverse=True)
dp = [0]*n
dp[0] = c[0]
p = 1
for i in range(n-1):
    dp[i+1] = (2*dp[i] + p*(2+i+1)*c[i+1]) % mod
    p *= 2
    p %= mod
p *= 2
p %= mod
print(dp[-1]*p % mod)

Measured memory_bytes: 96304
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const ll inf = 4e18;
int main() {
    int t;
    cin >> t;
    while (t--) {
        ll n, a, b, c, d;
        cin >> n >> a >> b >> c >> d;
        vector<pair<int, ll>> ops = { { 2, a }, { 3, b }, { 5, c } };
        unordered_map<ll, ll> mp;
        mp[0] = 0;
        mp[1] = d;
        function<ll(ll)> dfs = [&](ll x) {
            if (mp.find(x) != mp.end()) {
                return mp[x];
            }
            ll ret = inf;
            if ((long double)d * (long double)x < ret) {
                ret = d * x;
            }
            for (auto& p : ops) {
                int n = p.first;
                ll c = p.second;
                ret = min(ret, dfs(x / n) + c + d * (x % n));
                if (x % n != 0)
                    ret = min(ret, dfs(x / n + 1) + c + d * (n - x % n));
            }
            return mp[x] = ret;
        };
        cout << dfs(n) << '\n';
    }
}

Measured memory_bytes: 4168
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Node {
    int id;
    Node left;
    Node right;
}

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

        for (int i = 0; i < n; i++) {
            String command = sc.next();
            if (command.charAt(0) == 'i') {
                int id = sc.nextInt();
                insert(id);
            } else if (command.charAt(0) == 'p') {
                System.out.println(inParse(root));
                System.out.println(preParse(root));
            } else if (command.charAt(0) == 'f') {
                int id = sc.nextInt();
                System.out.println(find(id));
            }
        }
    }

    public static void insert(int id) {
        Node insertedNode = new Node();
        insertedNode.id = id;

        if (root == null) {
            root = insertedNode;
            return;
        }

        Node node = root;
        while(true) {
            if (id < node.id) {
                if (node.left == null) {
                    node.left = insertedNode;
                    return;
                }
                node = node.left;
            } else {
                if (node.right == null) {
                    node.right = insertedNode;
                    return;
                }
                node = node.right;
            }
        }
    }

    public static String find(int id) {
        Node node = root;
        while(true) {
            if (node == null) {
                return "no";
            } else if (id == node.id) {
                return "yes";
            }

            if (id < node.id) {
                node = node.left;
            } else {
                node = node.right;
            }
        }
    }

    public static String preParse(Node node) {
        if (node == null) {
            return "";
        }
        return " " + node.id + preParse(node.left) + preParse(node.right);
    }

    public static String inParse(Node node) {
        if (node == null) {
            return "";
        }
        return inParse(node.left) + " " + node.id + inParse(node.right);
    }
}



Measured memory_bytes: 559372
def Main(N, M, S, C):
    dig = [set([]),set([]),set([])]
    for i in range(M):
        dig[S[i]-1].add(C[i])
    for s in dig:
        if len(s) == 2:
            return -1
    if N == 3:
        if len(dig[0]) > 0 and list(dig[0])[0] == 0:
            return -1
        if len(dig[0]) == 0:
            dig[0].add(1)
        if len(dig[1]) == 0:
            dig[1].add(0)
        if len(dig[2]) == 0:
            dig[2].add(0)
        return list(dig[0])[0]*100+list(dig[1])[0]*10+list(dig[2])[0]
    elif N == 2:
        if len(dig[0]) > 0 and list(dig[0])[0] == 0:
            return -1
        if len(dig[0]) == 0:
            dig[0].add(1)
        if len(dig[1]) == 0:
            dig[1].add(0)
        return list(dig[0])[0]*10+list(dig[1])[0]
    else:
        return list(dig[0])[0]       
        
                

def main():
    N, M = map(int, input().split())
    if M == 0:
        if(N == 3):
            print(100)
        elif(N == 2):
            print(10)
        else:
            print(0)
        exit()
    S = [1]*M
    C = [0]*M
    for i in range(M):
        S[i], C[i] = map(int, input().split())
    print(Main(N, M, S, C))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int M=200001,P=998244353;
int n,len,B[M<<1],tot,ans;
int Pow[M];
struct node{
	int x,y;
}A[M];
bool comp1(node a,node b){
	return a.x<b.x;
}
bool comp2(node a,node b){
	return a.y<b.y;
}
bool comp(node a,node b){
	return a.x<b.x;
}
int C1[M<<1],C2[M<<1];
int query_litte(int x){
	int res=0;
	while(x){
		res+=C1[x];
		if(res>=P)res-=P;
		x-=x&-x;
	}
	return res;
}
int query_large(int x){
	int res=0;
	while(x<=tot){
		res+=C2[x];
		if(res>=P)res-=P;
		x+=x&-x;
	}
	return res;
}
void add_litte(int x){
	while(x<=tot){
		C1[x]++;
		x+=x&-x;
	}
}
void add_large(int x){
	while(x){
		C2[x]++;
		x-=x&-x;
	}
}
int main(){
	scanf("%d",&n);
	Pow[0]=1;
	for(int i=1;i<=n;i++)Pow[i]=Pow[i-1]*2%P;
	for(int i=1;i<=n;i++){
		scanf("%d%d",&A[i].x,&A[i].y);
		B[++tot]=A[i].x,B[++tot]=A[i].y;
	}
	sort(B+1,B+tot+1);
	len=unique(B+1,B+tot+1)-B-1;
	for(int i=1;i<=n;i++){
		A[i].x=lower_bound(B+1,B+len+1,A[i].x)-B;
		A[i].y=lower_bound(B+1,B+len+1,A[i].y)-B;
	}
	ans=n*1ll*(Pow[n]-1)%P;
	for(int i=1;i<=n;i++){
		ans=(ans-(Pow[i-1]-1)+P)%P;
		ans=(ans-(Pow[i-1]-1)+P)%P;
		ans=(ans-(Pow[n-i]-1)+P)%P;
		ans=(ans-(Pow[n-i]-1)+P)%P;
	}
	sort(A+1,A+n+1,comp);
	for(int i=1;i<=n;i++){
		ans=(ans+Pow[query_litte(A[i].y)]-1)%P;
		add_litte(A[i].y);
		ans=(ans+Pow[query_large(A[i].y)]-1)%P;
		add_large(A[i].y);
	}
	memset(C1,0,sizeof(C1));
	memset(C2,0,sizeof(C2));
	for(int i=n;i>=1;i--){
		ans=(ans+Pow[query_litte(A[i].y)]-1)%P;
		add_litte(A[i].y);
		ans=(ans+Pow[query_large(A[i].y)]-1)%P;
		add_large(A[i].y);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 7296
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(str(input())))

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            count = 0
            for i_ in range(-1, 2):
                if i + i_ < 0 or i + i_ >= h:
                    continue
                for j_ in range(-1, 2):
                    if j + j_ < 0 or j + j_ >= w:
                        continue
                    if i_ == 0 and j_ == 0:
                        continue
                    if s[i+i_][j+j_] == "#":
                        count += 1
            s[i][j] = str(count)
for i in range(h):
    print("".join(s[i]))


Measured memory_bytes: 41072
fn main() {
    let mut x = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_end().to_owned().parse::<i32>().unwrap()
    };

    let mut result = 0;

    result += (x / 500) * 1000;
    x = x % 500;

    result += (x / 5) * 5;

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


Measured memory_bytes: 2140
#include<cstdio>
using namespace std;
int d2b(int n,int b,char c[])
{
    int i=0,k;                                                                                                                                                   
    while(n!=0)
    {
        k=n%b;
        n/=b;
        if(k<0){k-=b;n+=1;}
        if(k>9)c[i]=char(k-10+'A');
        else c[i]=char(k+'0');
        i++;
    }
    return i-1;
}
int main()
{
    int a,n,i;
    char b[4000];
    scanf("%d",&a);
	n=-2;    
    if(a==0)printf("0");
    for(i=d2b(a,n,b);i>=0;i--)printf("%c",b[i]);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
string itoch(int cnt)
{
	string str,ptr; char ch; int m=0;
	while(cnt)
	{
		int n=cnt%10; ch='0'+n; cnt/=10;
		if(m==0) str=ch; else str+=ch;
		m++;
	}
	ptr=str;
	int len=str.size(); for(int i=0;i<len;i++) ptr[i]=str[len-1-i];
	return (ptr);
}
int main()
{
	while(1)
	{
		int n ; cin >> n ;
		if(!n) break;
		string str,ptr; cin >> str ;
		while(n--)
		{
			int len=str.size();
			for(int i=0;i<len; )
			{
				int cnt=1; char ch; ch=str[i];
				while(i+cnt<len && str[i]==str[i+cnt]) cnt++;
				string tmp; tmp=itoch(cnt); tmp+=ch;
				if(i==0) ptr=tmp;
				else ptr+=tmp;
				i+=cnt;
			}
			str=ptr;
		}
		cout << str << endl ;
	}
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

int n, k;
vector<vector<int> > G;
vector<int> d;

void dfs(int v, int p) {
  int c = 0;
  for (int nv : G[v]) {
    if (nv == p) continue;
    d[nv] = max(0, k - 1 - (p != -1) - c++);
    dfs(nv, v);
  }
}

void solve() {
  cin >> n >> k;
  if (n == 1) { cout << k << '\n'; return; }
  G.resize(n);
  d.resize(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].eb(b);
    G[b].eb(a);
  }
  rep(i, n) {
    if (sz(G[i]) == 1) {
      d[i] = k;
      dfs(i, -1);
      // cout << d << '\n';
      ll ans = 1;
      rep(i, n) (ans *= d[i]) %= mod;
      cout << ans << '\n';
      return;
    }
  }
}


Measured memory_bytes: 12416
n = gets.to_i
a = gets.split.map(&:to_i)
puts a * ' '
(1..n-1).each do |i|
  j = i
  while j>=1 && a[j]<a[j-1]
    a[j-1], a[j] = a[j], a[j-1]
    j -= 1
  end
  puts a * ' '
end


Measured memory_bytes: 6896
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int ans = 0;
	for(int i=0;i<3;i++)
		if(s[i] == 'R') {
			int j=i;
			while(j + 1 < 3 && s[j + 1] == 'R')	j++;
			ans = max(ans,j - i + 1);
			i = j;
		}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t=1;
  while(t--){
   	int n,k;
   	cin>>n>>k;
   	vector<double> v(n);
   	for(int i=0;i<n;i++){
   	    cin>>v[i];
   	}
    double ans=0;
    for(int i=0;i<k;i++){
        ans=ans+log(v[i]);
    }
    double prev=ans;
    int j=0;
    int i=k;
    while(i<n){
        ans-=log(v[i-k]);
        ans+=log(v[i]);
        if(ans>prev){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
        prev=ans;
        i++;
        j++;
    }
  }
   return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define maxn 2086

using namespace std;

const int p = 1e9 + 7;

int n, k;
int f[maxn][maxn], sum[maxn][maxn];

int main(){
	scanf("%d%d", &n, &k);
	f[0][n + 1] = 1;
	for(int i = 1;i <= k;i++){
		for(int j = n + 2 - i;j;j--){
			f[i][j] = sum[i - 1][j] = (sum[i - 1][j + 1] + f[i - 1][j]) % p;
			//printf("%d %d %d--\n", i, j, f[i][j]);
		}
	}
	int ans = (f[k][1] + p - f[k - 1][1]) % p;
	for(int i = 1;i <= n - k - 1;i++) ans = ans * 2 % p;
	printf("%d", ans); 
}

Measured memory_bytes: 32000
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CNumbersOnACircle {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    int calc(vector<int>& A) {
        priority_queue<pair<int, int>> pq;
        int sz = A.size();
        REP(i, sz) {
            pq.push({A[i], i});
        }
        int res = 0;
        while (!pq.empty()) {
            int val, idx;
            tie(val, idx) = pq.top();
            pq.pop();

            int l = idx > 0 ? idx - 1 : sz - 1;
            int r = idx < sz - 1 ? idx + 1 : 0;

            int bc = A[l] + A[r];
            if (A[idx] <= bc) continue;

            res += (A[idx] - 1) / bc;
            A[idx] %= bc;
            if (A[idx] == 0) A[idx] = bc;

            pq.push({A[idx], idx});
        }
        return res;
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N;
        cin >> N;
        vector<int> A(N), B(N);
        REP(i, N) cin >> A[i];
        REP(i, N) cin >> B[i];

        int a = calc(A);
        int b = calc(B);
        if (A == B && b >= a) {
            cout << b - a << endl;
        } else {
            cout << -1 << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CNumbersOnACircle solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 11444
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char ** argv){
  int A,B,K;
  scanf("%d",&K);
  scanf("%d %d",&A,&B);
  if(K<1 || K >1000 || A <1 || B <1 || A >1000 || B > 1000)
  exit(1);

  if(K > B)printf("NG");
  if(K <= B && K >=A)printf("OK");
  if(K > B/2 && K < A)printf("NG");
  if(K <= B/2 && K >= 1)printf("OK");

  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int h,w;
  cin >> h >> w;
  vector< vector<char> > arr;
  vector< vector<int> > paint;
  arr.resize(h);
  paint.resize(h);
  for (int i = 0; i < h; i++) {
    arr[i].resize(w);
    paint[i].resize(w);
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> arr[i][j];
      paint[i][j] = 0;
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == '#') {
        if (j != w-1 && arr[i][j+1] == '#') {
          paint[i][j] = 1;
          paint[i][j+1] = 1;
        }
        if (i != h-1 && arr[i+1][j] == '#') {
          paint[i][j] = 1;
          paint[i+1][j] = 1;
        }
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == '#') {
        if (paint[i][j] == 0) {
          cout << "No" <<endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" <<endl;

	return 0;
}


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

int main() {
  int x;
  cin >> x;
  if(x >= 30) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn dfs(G: &Vec<Vec<(usize, u64)>>, memo: &mut Vec<Option<u64>>, x: usize, pos: u64) -> bool {
    if let Some(p) = memo[x] {
        return p == pos;
    }
    memo[x] = Some(pos);
    for &(y, d) in G[x].iter() {
        if !dfs(G, memo, y, pos + d) {
            return false;
        }
    }
    true
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let m = line[1];

    let mut G = vec![Vec::new(); n];
    let mut root = vec![true; n];

    for _ in 0..m {
        let line: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let l = (line[0] - 1) as usize;
        let r = (line[1] - 1) as usize;
        let d = line[2];
        G[l].push((r, d));
        root[r] = false;
    }

    let mut memo = vec![None; n];
    let mut ans = true;
    for i in 0..n {
        if root[i] {
            ans &= dfs(&G, &mut memo, i, 0);
        }
    }
    for i in 0..n {
        if memo[i].is_none() {
            ans &= dfs(&G, &mut memo, i, 0);
        }
    }

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(void){
   int H,W,K;
   cin>>H>>W>>K;
   vector<vector<char>> c(H,vector<char>(W));
   for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
         cin>>c[i][j];
      }
   }
   int ans=0;
   for(int bit1=0;bit1<(1<<H);bit1++){
      for(int bit2=0;bit2<(1<<W);bit2++){
         vector<vector<char>> temp(H,vector<char>(W));
         for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
               temp[i][j]=c[i][j];
            }
         }
         for(int i=0;i<H;i++){
            if(bit1&(1<<i)){
               for(int j=0;j<W;j++){
                  temp[i][j]='?';
               }
            }
         }
         for(int j=0;j<W;j++){
            if(bit2&(1<<j)){
               for(int i=0;i<H;i++){
                  temp[i][j]='?';
               }
            }
         }
         int sum=0;
         for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
               if(temp[i][j]=='#'){
                  sum++;
               }
            }
         }
         if(sum==K) ans++;
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
	// your code goes here
	ll n;
	cin>>n;
	
	ll h[n];
	for(ll i=0;i<n;i++)
	cin>>h[i];
	
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(ll i=2;i<n;i++)
	{
		dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]));
		
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 5108
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadLong();
        var M = sc.ReadLong();
        var max = (double)M / N;
        for (int i = (int)max; i >= 0; i--)
        {
            if (M % i != 0) continue;
            Console.WriteLine(i);
            return;
        }
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<pair<int,int>> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i).first>>a.at(i).second;
  sort(a.begin(),a.end());
  
  cout<<a.at(N-1).first+a.at(N-1).second<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,p;cin>>n>>m>>p;
  struct edge{
    ll from,to ,coin;
  };
  vector<edge>eds(m);
  vector<vector<ll>>ed(n),red(n);
  rep(i,m){
    cin>>eds[i].from>>eds[i].to>>eds[i].coin;
    eds[i].coin-=p;
    eds[i].coin=-eds[i].coin;

    eds[i].from--;
    eds[i].to--;
    ed[eds[i].from].push_back(eds[i].to);
    red[eds[i].to].push_back(eds[i].from);
  }
  vector<ll>memo(n),mask(n,0),mask1(n),mask2(n);
  function<void(ll)>dfs=[&](ll v){
    memo[v]=1;
    mask1[v]=1;
    for(auto nn:ed[v]){
      if(memo[nn])continue;
      dfs(nn);
    }
  };

  function<void(ll)>dfs2=[&](ll v){
    //cout<<"dfs2 "<<v<<endl;
    memo[v]=1;
    mask2[v]=1;
    for(auto nn: red[v]){
      if(memo[nn])continue;
      dfs2(nn);
    }
  };
  dfs(0);
  rep(i,n)memo[i]=0;

  dfs2(n-1);
  rep(i,n)mask[i]=mask1[i]&mask2[i];
  vector<ll>dist(n,1e17);
  dist[0]=0;
  rep(i,n)rep(j,m){
    if(dist[eds[j].from]==1e17)continue;
    if(mask[eds[j].from]&&mask[eds[j].to])chmin(dist[eds[j].to],dist[eds[j].from]+eds[j].coin);
  }
  ll res=dist[n-1];
  ll f=0;
  if(res==1e17)f=1;
  rep(i,n)rep(j,m){
    if(dist[eds[j].from]==1e17)continue;
    if(mask[eds[j].from]&&mask[eds[j].to])f|=chmin(dist[eds[j].to],dist[eds[j].from]+eds[j].coin);
  }
  //rep(i,n)cout<<mask2[i]<<endl;
  if(f){
    cout<<-1<<endl;
  }
  else{
    cout<<max(0LL,-res)<<endl;
  }
  return 0;

}


Measured memory_bytes: 896
#include <iostream>
#include <cmath>

typedef long long ll;

using namespace std;

int main()
{
  ll n, t[1100], a[1100], score_t[1100], score_a[1100], nn, na, nt;

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

  score_t[0] = score_a[0] = 1;
  for (int i = 0; i < n; i++)
  {
    if ((nt = score_t[i] / t[i] + (score_t[i] % t[i] == 0 ? 0 : 1)) > (na = score_a[i] / a[i] + (score_a[i] % a[i] == 0 ? 0 : 1)))
    {
      nn = nt;
    }
    else
    {
      nn = na;
    }
    score_a[i + 1] = a[i] * nn;
    score_t[i + 1] = t[i] * nn;
  }

  cout << score_a[n] + score_t[n] << endl;
}


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

using namespace std;
int A[1000001];
void solve()
{
    int n,m,g,h;
    cin>>n>>m>>g>>h;
    cout<<(n-g)*(m-h);
}

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

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

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

int main(void) {
  int i,j;
  int n,q;
  while(1){
    cin>>n>>q;
    if(n+q==0)break;
    vector<pair<pii,string> > p(n);
    rep(i,n){
      int a,b;
      cin>>p[i].second>>a>>b;
      p[i].first.first=b-a+1;
      p[i].first.second=b;
    }
    sort(all(p));
    rep(i,q){
      int y;
      cin>>y;
      rep(j,n)
	if(p[j].first.first<=y && y<=p[j].first.second){
	  cout<<p[j].second<<" "<<y-p[j].first.first+1<<endl;
	  break;
	}
      if(j==n)cout<<"Unknown"<<endl;
    }
  }
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  string s, t;
  cin >> s >> t;

  if (s.size() == t.size() - 1) {
    rep(i, 0, s.size()) {
      if (s[i] != t[i]) {
        cout << "No\n";
        return 0;
      }
    }
  } else {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
}

Measured memory_bytes: 3612
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int maxlog(int n){
	int res = 0;
	while(n != 0){
		n >>= 1;
		res++;
	}
	if((res<<1) < n) res++;
	return res;
}

int main()
{
	ios_init();
	int n;
	cin >> n;
	vector<LL> x(n);
	REP(i,n) cin >> x[i];
	LL l;
	cin >> l;

	int m = maxlog(n);
	vector<vector<int>> nex(m,vector<int>(n,-1));
	REP(i,n){
		auto tmp = upper_bound(x.begin()+i,x.end(),x[i]+l);
		if(tmp == x.end()){
			nex[0][i] = n-1;
		}else if(tmp == x.begin()+i){
			nex[0][i] = -1;
		}else{
			tmp--;
			nex[0][i] = tmp-x.begin();
		}
	}
	REP(i,m-1){
		REP(j,n){
			if(nex[i][j] == -1) nex[i+1][j] = -1;
			nex[i+1][j] = nex[i][nex[i][j]];
		}
	}
	REP(i,m) dpite(ALL(nex[i]));
	int q;
	cin >> q;
	REP(i,q){
		int a,b;
		cin >> a >> b;
		if(a > b) swap(a,b);
		a--; b--;
		int ans = 0;
		RREP(k,m){
			// DEBUG(a);
			if(nex[k][a] == -1) continue;
			if(nex[k][a] < b){
				a = nex[k][a];
				ans += (1<<k);
			}
		}
		if(a < b) ans++;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 8312
if __name__ == '__main__':
    N = int(input())

    sum_digit = 0
    tmp_N = N
    while tmp_N > 0:
        sum_digit += tmp_N % 10
        tmp_N = tmp_N//10

    if N % sum_digit == 0:
        print("Yes")
    else:
        print("No")

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

int main()
{
  int n,i;cin>>n;
  static double x[100],a[100],y,p1,p2,p3,p4;

  for(i=0;i<n;i++)cin>>x[i];
  for(i=0;i<n;i++)cin>>y,a[i]=abs(x[i]-y),p1+=a[i],p2+=a[i]*a[i],p3+=a[i]*a[i]*a[i],p4=p4<a[i]?a[i]:p4;
  cout<<fixed<<p1<<endl<<sqrt(p2)<<endl<<cbrt(p3)<<endl<<p4<<endl;
  return 0;
}

Measured memory_bytes: 3464
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)
#define RALL(x) (x).rbegin(), (x).rend()


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, K;

  std::cin >> N >> K;

  long long a[1111], acc[1111];

  acc[0] = 0;

  for (int i = 0; i < N; i ++) {
    std::cin >> a[i];

    acc[i + 1] = a[i] + acc[i];
  }

  std::map<long long, int> map;

  for (int i = 0; i < N; i ++)
    for (int j = i + 1; j <= N; j ++)
      map[acc[j] - acc[i]] ++;

  for (long long x = 1LL << 60; x > 0; x >>= 1) {
    int k = 0;

    for (const auto& kv : map)
      if (kv.first & x)
        k += kv.second;

    if (k >= K)
      for (auto it = std::begin(map); it != std::end(map); ) {
        if (it->first & x) {
          ++ it;
        }
        else {
          it = map.erase(it);
        }
      }
  }

  long long x = -1;

  int k = 0;

  for (auto it = map.rbegin(); it != map.rend(); ++ it) {
    x &= it->first;

    if ((k += it->second) >= K)
      break;
  }

  std::cout << x << std::endl;

  return 0;
}


Measured memory_bytes: 33712
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

int fun(int n) {
    int res = 0;
    for(int i = 1; i < 45; i++) {
        if(i * (i + 1) / 2 <= n)
            res = i;
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1; 
    // cin >> t; 
    while (t--) {
        int n;
        cin >> n;

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

        int ans = 0;    
        for(auto p: mp) {
            ans += fun(p.second);
        }

        cout << ans << '\n';
        
    }
    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 3828
readInt :: String -> Int
readInt = read
x ? (a,b) = if x then a else b

main = do
    s <- readInt<$>getLine
    putStrLn $ solve s

solve :: Int -> String
solve s = abnm?(cdnm?("NA","YYMM"), cdnm?("MMYY","AMBIGUOUS")) where
  abnm = nm ab
  cdnm = nm cd
  nm n = n == 0 || n > 12
  ab = div s 100
  cd = mod s 100


Measured memory_bytes: 508
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
ll gcd(ll a, ll b) {
    if(a < b)
        gcd(b, a);
    ll r = 1;
    while(r != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] /= 2;
    }
    ll G = a[0];
    for(int i = 1; i < n; i++) {
        G = G * a[i] / gcd(G, a[i]);
        if(G > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < n; i++) {
        b[i] = (G / a[i]) % 2;
    }
    ll ans = 0;
    ll s = -1;
    if(count(all(b), 0) == n) {
        s = 1;
    }
    if(count(all(b), 1) == n) {
        s = 0;
    }
    if(s == -1) {
        cout << 0 << endl;
      	return 0;
    }
    if(s % 2 == 0) {
        ans += (m / G + 1) / 2;
    } else {
        ans += (m / G) / 2;
    }
    cout << ans << endl;
    // ll l = m / G;
    // cout << (l + 1) / 2 << endl;
}


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

int main() {
    int h, w, a, b;  cin >> h >> w >> a >> b;
    cout << (h-a)*(w-b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <algorithm>
using namespace std;

#define ll long long

int main(){

    ll int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int64_t GCD(int64_t a,int64_t b){
    return b == 0 ? a : GCD(b, a % b);
   
}
int main(){
    int n,x;
    cin>>n>>x;
    vector<int> a(n+1);
    rep(i,n){
        cin>>a[i];
    }
    a[n]=x;
    sort(a.begin(),a.end());
    vector<int> b(n);
    rep(i,n){
        b[i]=a[i+1]-a[i];
       // cout << b[i] <<" ";
    }
    //cout<<endl;
    int gcd=b[0];
    for(int i=1;i<n;i++){
        gcd = GCD(gcd,b[i]);
    }
    cout << gcd<<endl;

}

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

long long solve() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    using P = pair<int, int>;
    priority_queue<P> pq;
    long long ans = 0;
    rep(i, 0, N) if(A[i] != B[i]) pq.push(P(B[i], i));
    while(!pq.empty()) {
        P t = pq.top(); pq.pop();
        int i = t.second;
        int v = B[(i + N - 1) % N] + B[(i + 1) % N];
        if((B[i] - A[i]) % v == 0) {
            ans += (B[i] - A[i]) / v;
            B[i] = A[i];
        } else if(B[i] <= v) return -1;
        else {
            ans += (B[i] / v);
            B[i] %= v;
        }
        if(A[i] < B[i]) pq.push(P(B[i], i));
        else if(A[i] > B[i]) return -1;
    }
    return ans;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
//int myfunc(int, vvec);

//グローバル変数
//int N, M;
//vvec data(N, vec(M));
vvec tb(10, vec(10));

//関数：

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

	int N; cin >> N;
	bool frag = false;
	for(int i=1; i<10; i++)for(int j=1; j<10; j++) {
	tb[i][j] = i*j;
	}

	for(int i=1; i<10; i++)for(int j=1; j<10; j++) {
	if(tb[i][j] == N) frag = true;
	}
	if(frag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void)
{
    int a[3];
    int maxnum = 0;
    int sum = 0;
    cin >> a[0] >> a[1] >> a[2];
    for (int i = 0; i < 3; i++)
    {
        sum += a[i];
        maxnum = max(maxnum, a[i]);
    }

    cout << maxnum * 10 + sum - maxnum << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;


class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		String S  = sc.next();
		//S は"2017/01/dd"
		
		String S2 = "2018" + S.substring(4);
		System.out.println(S2);
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
   
int main(){
    int dice[6],q,i;
    char c;
       
    for(i=0;i<6;i++){
        scanf("%d",&dice[i]);
    }
       
    scanf("%d",&q);
    for(i=0;i<q;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if((x==dice[5] && y==dice[4])||(x==dice[4] && y==dice[0])||(x==dice[0] && y==dice[1])||(x==dice[1] && y==dice[5])){
            printf("%d\n",dice[2]);
        }else if((x==dice[0] && y==dice[2])||(x==dice[2] && y==dice[5])||(x==dice[5] && y==dice[3])||(x==dice[3] && y==dice[0])){
            printf("%d\n",dice[4]);
        }else if((x==dice[5] && y==dice[1])||(x==dice[1] && y==dice[0])||(x==dice[0] && y==dice[4])||(x==dice[4] && y==dice[5])){
            printf("%d\n",dice[3]);
        }else if((x==dice[0] && y==dice[3])||(x==dice[3] && y==dice[5])||(x==dice[5] && y==dice[2])||(x==dice[2] && y==dice[0])){
            printf("%d\n",dice[1]);
        }else if((x==dice[2] && y==dice[1])||(x==dice[1] && y==dice[3])||(x==dice[3] && y==dice[4])||(x==dice[4] && y==dice[2])){
            printf("%d\n",dice[5]);
        }else{
            printf("%d\n",dice[0]);
        }
    }
    return 0;
}



Measured memory_bytes: 2132
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<deque>
#include<cstdio>
#include<queue>
using namespace std;
string s;
long long a[15],ans;
void dfs(int x)
{
	if (x==s.size())
	{
		long long m=0,now=0;
		for (int i=1;i<s.size();i++)
		if (a[i])
		{
			long long k=0;
			for (int j=m;j<i;j++)
			k=k*10+s[j]-'0';
			now+=k;
			m=i;
		}
		long long k=0;
		for (int i=m;i<s.size();i++)
		k=k*10+s[i]-'0';
		ans=ans+now+k;
		return ;
	}
	a[x]=1;
	dfs(x+1);
	a[x]=0;
	dfs(x+1);
}
int main()
{
	cin>>s;
	//cout<<s.size()<<endl;
	dfs(1);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256