akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue; 
import java.util.*;

public class Main {

	public static void main(String argv[]) {

        Scanner in = new Scanner(System.in);
        int numTask = in.nextInt();
        int maxTime = in.nextInt();
        int curr=0;
        in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

        Queue<String> q = new LinkedList<>();
     // accessing the numbers in the second line
        for (int i = 0; i < numTask; i++){
//        	String str = in.nextLine();
        	q.add(in.nextLine());
        }

        while(q.size() > 0){
        	  String element = q.remove();
        	  String[] oneTask = element.split(" ");
        	  int timeDiff = Integer.parseInt(oneTask[1]) - maxTime;
        	  if(timeDiff<=0)
        	  {
        		  curr = curr + Integer.parseInt(oneTask[1]);
        		  System.out.println(oneTask[0] + ' ' + curr);
        	  }
        	  else
        	  {
        		  curr = curr + maxTime;
        		  oneTask[1] = Integer.toString(timeDiff);
        		  q.add(oneTask[0] + ' ' + oneTask[1]);
        	  }
        }

        in.close();
    }
}



Measured memory_bytes: 113624
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MAX = 1000001;
const lint MOD = 1000000007;

lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

lint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
	lint N, K; cin >> N >> K;
	vector<lint> a(N);
	for(lint i = 0; i < N; i++) cin >> a[i];
	sort(a.begin(), a.end());
	lint ans = 0;
	COMinit();
	for(lint i = N - 1; i >= K - 1; i--){
		ans += a[i] * COM(i, K - 1);
		ans %= MOD;
	}
	for(lint i = 0; i + K <= N; i++){
		ans -= a[i] * COM(N - i - 1, K - 1);
		ans %= MOD;
		if(ans < 0) ans += MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
 
template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M) % M;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> graph[100010];
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    vector<int> ret(N,-1);
    ret.at(0) = -2;
    queue<int> que;
    que.push(0);
    while(!que.empty()) {
        int A = que.front();
        que.pop();
        for(int i = 0;i < graph[A].size();i++) {
            if(ret.at(graph[A].at(i)) == -1) {
                ret.at(graph[A].at(i)) = A;
                que.push(graph[A].at(i));
            }
        }
    }
    cout << "Yes" << endl;
    for(int i = 1;i < N;i++) {
        cout << ret.at(i) + 1 << endl;
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 H1, A1, H2, A2;
    cin >> H1 >> A1 >> H2 >> A2;
    for (i64 i = 0; H1 > 0 && H2 > 0; i++) {
        if (i % 2 == 0) {
            H2 -= A1;
        } else {
            H1 -= A2;
        }
    }
    cout << (H1 <= 0 ? "No" : "Yes") << endl;

    return 0;
}

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


void solve(std::string s, std::string t){
    map<char, set<int>> ma;
    long long n=s.length(), m=t.length();
    for(int i=0;i<n;++i){
        ma[s[i]].insert(i);
    }
    long long res = 0;
    long long k = 0;
    for(int i=0;i<m;++i){
        char c = t[i];
        if(ma[c].size()==0){
            cout<<-1<<endl;
            return;
        }
        set<int>::iterator it = ma[c].lower_bound(k);
        if(it==ma[c].end()){
            res++;
            k=0;
            i--;
        }
        else{
            k = *it + 1;
        }
    }
    cout<<res * n + k <<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(s, t);
    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
  
int main(){
    u_int n;    // the number of vegetable
    u_int m;    // capacity
     
    while(std::cin >> n >> m){
        if(n == 0 && m == 0){
            break;
        }
          
        std::vector<u_int> p(n);  // price
        for(int i = 0; i < n; ++i){
            std::cin >> p[i];
        }
         
        //m, 2*m, 3*m, ... = free(sort by descending)
        std::sort(p.begin(), p.end(), std::greater<u_int>());
        for(int i = m; i <= n; i += m){
            p[i-1] = 0;
        }
         
        std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
    }
      
    return 0;
}

Measured memory_bytes: 3004
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String s = scan.next();
	char[] c = new char[s.length()];
	for (int i = 0; i < s.length(); i++) {
		c[i] = s.charAt(i);
	}
	for (int i = 0; i < 3; i++) {
		if (c[i] == '1') {
			c[i] = '9';
		} else {
			c[i] = '1';
		}
	}
	for (int i = 0; i < 3; i++) {
		System.out.print(c[i]);
	}
	}
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct UnionFind{
    std::vector<int> data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y) {
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])std::swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y) {
        return root(x)==root(y);
    }
    int root(int x) {
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};


int main() {
	int n = ri();
	int x[n];
	int y[n];
	for (int i = 0; i < n; i++) x[i] = ri() - 1, y[i] = ri() - 1;
	UnionFind uni1(200000);
	for (int i = 0; i < n; i++) uni1.unite(x[i], y[i] + 100000);
	std::map<int, std::set<int> > ma;
	for (int i = 0; i < 200000; i++) ma[uni1.root(i)].insert(i);
	int64_t all = 0;
	for (auto &i : ma) {
		int x = 0;
		int y = 0;
		for (auto j : i.second) if (j < 100000) x++; else y++;
		all += (int64_t) x * y;
	}
	std::cout << all - n << std::endl;
	
	
	return 0;
}


Measured memory_bytes: 29824
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    s = input().rstrip()
    t = input().rstrip()

    ans = N
    for i in range(N):
        if s[i:] == t[:N-i]:
            break
        else:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    rep(i, k){
        int d;
        cin >> d;
        rep(j, d){
            int b;
            cin >> b;
            b--;
            a[b]++;
        }
    }
    int ans = 0;
    rep(i, n)if(a[i] == 0)ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
int main(){
  int i,n;
  char s[11],t[11];
  scanf("%s %s",s,t);
  n=strlen(s);
  for(i=0;i<n;i++)
    if(s[i]!=t[i]){
      printf("No\n");
      return 0;
    }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 1660
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] items = {"01","02","03","04","05","06","07","08","09","10","11","12"};
		List<String> l = Arrays.asList(items);
		String s = sc.nextLine();
		String mae = s.substring(0, 2);
		String ushiro = s.substring(2,4);
		String ans = null;
		if(l.indexOf(mae) >=0  && l.indexOf(ushiro) >=0) {
			ans="AMBIGUOUS";
		}else if(l.indexOf(mae)>=0) {
			ans="MMYY";
		}else if(l.indexOf(ushiro)>=0) {
			ans="YYMM";
		}else {
			ans ="NA";
		}
		System.out.println(ans);
	}
}

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

using namespace std;

typedef long long ll;

int main(){
    int n;
    cin >> n;
    int digit = n % 10;
    if(digit == 3) cout << "bon" << '\n';
    else if(digit == 0 || digit == 1 || digit == 6 || digit == 8) cout << "pon" << '\n';
    else cout << "hon" <<'\n';
}

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

#define SQ(x) ((x) * (x))

int compare_int(const void *a, const void *b)
{
	int lhs, rhs;
	lhs = *(int *)a;
	rhs = *(int *)b;
	return ((lhs > rhs) - (lhs < rhs));
}

int main(void)
{
	int n;
	int a[3];
	int i, j;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			scanf("%d", &a[j]);
		}
		
		qsort(a, 3, sizeof(int), compare_int);
		
		if (SQ(a[0]) + SQ(a[1]) == SQ(a[2])){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int N, M, C, tmp, ans;
int B[25], A[25][25];

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

	cin >> N >> M >> C;

	for(int i = 0; i < M; i++){
		cin >> B[i];
	}

	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			cin >> A[i][j];
		}
	}

	for(int i = 0; i < N; i++){
		int sum = 0;
		for(int j = 0; j < M; j++){
			sum += A[i][j]*B[j];
		}

		if(sum + C > 0)
			ans ++;
	}

	cout << ans << "\n";

	return 0;		
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, l, res = 0, mn = INF;
    cin>>n>>l;
    rep(i, l, l + n){
        res += i;
        if(abs(mn) > abs(i)){
            mn = i;
        }
    }
    cout<<res - mn<<endl;
}


Measured memory_bytes: 256
n = int(input())
nlist = list(map(int, input().split()))
c= 0
for i in range(n):
    for k in range(i+1,n):
        j = n - 1 -k + i + 1
        if nlist[j] < nlist[j-1]:
            m = nlist[j]
            nlist[j] = nlist[j-1]
            nlist[j-1] = m
            c += 1
for i in range(n):
    if (i == n-1):
        print('{}'.format(nlist[i]), end = '')
    else : 
        print('{}'.format(nlist[i]), end = ' ')
print()
print(c)


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int ans = 0;
    int div, mod;
    
    for(int a = 1; a < n; ++a) {
        ans += (n - 1) / a;
    }

    printf("%d\n", ans);

    return 0;
}

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

using namespace std;

long long int count1=1e18;

int main()
{
	int n,i,flag=0;
	cin>>n;
	long long int *arr = new long long int[n];
	for(i=0;i<n;i++) 
	{
		cin>>arr[i];
		if(arr[i]==0) flag=1;
	}
	if(flag==1)
	{
		cout<<0<<endl;
		return 0;
	}
	long long int prod=1,left=1;
	for(i=0;i<n-1;i++)
	{
		prod*=arr[i];
		left=count1/prod;
		//cout<<left<<" ";
		if(left<arr[i+1]&&left)
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	prod*=arr[n-1];
	cout<<prod<<endl;
	return 0;
}


Measured memory_bytes: 4376
#include <iostream>

using namespace std;

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

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

	int count = 0;
	for(int i=0;i<n;i++){
		if(a[i] >= total/(4*m)){
			count++;
		}
	}

	if(count >= m){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
import sys
import fractions
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H, N = IL()
ab = [IL() for i in range(N)]

dp = [MAX_INT for i in range(H+1)]
dp[H] = 0
for hp in range(H+1)[::-1]:
  if dp[hp] == MAX_INT:
    continue
  for at,mp in ab:
    dp[max(0,hp - at)] = min(dp[max(0,hp - at)], dp[hp] + mp)
print(dp[0])

Measured memory_bytes: 68056
N = int(input())
a = list(map(int,input().split()))
Alice = 0
Bob = 0

for i in range(N):
    for j in range(N-1,i,-1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]

if N % 2 == 0:
    for k in range(N//2):
        Alice += a[(2*k)+1]
        Bob += a[2*k]
        

else:
    for k in range(N//2):
        Alice += a[2*k]
        Bob += a[2*k+1]
    Alice += a[N-1]

print(Alice-Bob)


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

using namespace std;

typedef long long ll;
typedef pair<bool , bool> pii;
typedef pair<ll, ll> pll;

#define $ system("pause")
#define MOD ll(1e9 + 7)
#define MAXN 300010
#define inf (ll)1e18

template<typename T> inline T smin(T &a, const T &b) { return a > b ? a = b : a; }
template<typename T> inline T smax(T &a, const T &b) { return a < b ? a = b : a; }
inline void add(ll &l, const ll &r) { l = (l + r) % MOD; }
ll gcd(ll v, ll u) { return u ? gcd(u, v % u) : v; }
ll po(ll v, ll u) { return u ? (po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD) : 1; }

/*
int n, arr[MAXN];
int have[MAXN][20];
int pl[MAXN][20], pr[MAXN][20];
vector<int> p[MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	for (int i = 2; i < MAXN; i++)
		if (p[i].empty()) {
			for (int j = i; j < MAXN; j += i)
				p[j].push_back(i);
		}

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		int local = arr[i];
		for (auto e : p[arr[i]]) {
			int cnt = 0;
			while ((local % e) == 0) {
				cnt++;
				local /= e;
			}
			have[e][cnt]++;
		}
	}
	for (int i = 1; i < MAXN; i++) {
		pr[i][19] = have[i][19];
		for (int j = 18; j; j--) 
			pr[i][j] = pr[i][j + 1] + have[i][j];
		have[i][0] = n - pr[i][1];
		pr[i][0] = n;
		pl[i][0] = have[i][0];
		for (int j = 1; j < 20; j++)
			pl[i][j] = pl[i][j - 1] + have[i][j];

	}
	return 0;
}

*/

int n, arr[MAXN];
vector<int> adj[MAXN];

bool dfs(int v, int p = 0) {
	bool res = false;
	for (auto e : adj[v]) {
		if (e ^ p && arr[e] < arr[v]) {
			res |= !dfs(e, v);
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> arr[i];
	for (int i = 1; i < n; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		if (dfs(i))
			cout << i << ' ';
	}
	//$;
	return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

void Impossible(){
	cout<<-1<<endl;
	exit(0);
}
void PrintEdge(int u,int v){
	print(u+1,2);
	print(v+1);
}

signed main(){
	string s=readString();
	int n=s.size();
	if(s.back()=='1')
		Impossible();
	if(s[0]=='0')
		Impossible();
	s.pop_back();
	FOR(i,1,n){
		if(s[i-1]!=s[n-i-1]){
			Impossible();
		}
	}
	int cur=0;
	vi waf;
	FOR(i,1,n)if(s[i-1]=='1'){
		waf.PB(i-cur);
		cur=i;
	}
	cerr<<waf<<endl;
	assert(cur==n-1);
	waf.PB(1);
	int last=-1,head=0;
	for(auto w:waf){
		int root=head;
		if(last!=-1)
			PrintEdge(last,root);
		FOR(i,1,w)
			PrintEdge(root,root+i);
		head+=w;
		last=root;
	}
}


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
inline int read(int &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
inline void write(int x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}
int x,y;
signed main(){
	read(x);read(y);
	write(max(0,x-y*2));
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC164
//
//  Created by 安藤光希 on 2020/04/26.
//  Copyright © 2020 安藤光希. All rights reserved.
//

#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#define rep(i, n) for (int i = 0; i<n; i++)
using namespace std;
// https://atcoder.jp/contests/abc163/tasks/abc163_c
typedef long long ll;


int main() {
    ll N;
    cin >> N;
    
    vector<string> s(N);
    
    rep(i, N) cin >> s[i];
    
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end() ), s.end() );
    
    cout << s.size() << endl;

}

Measured memory_bytes: 9544
#include <bits/stdc++.h> 
using namespace std;
typedef vector<int> int_vector;
typedef vector<long> long_vector;
typedef vector< vector<int> > int_matrix;
typedef vector<string> string_vector;
typedef vector< vector<string> > string_matrix;
int cmp(const void* a, const void* b)
{
	const int* x = (int*) a;
	const int* y = (int*) b;
	if (*x > *y)
		return 1;
	else if (*x < *y)
		return -1;
	return 0;
}

int main(){
    int n, k;
    long sum=0;
    cin >> n >> k;
    long_vector Hs;
    for (int i=0; i<n; i++){
        long h;
        cin >> h;
        Hs.push_back(h);
    }
	qsort(&Hs[0], n, sizeof(long), cmp);
    for (int i=0; i<n-k; i++){
        sum+=Hs[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3564
def resolve():
    import heapq
    from collections import deque
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p = sorted(p, reverse=True)[:x]
    q = sorted(q, reverse=True)[:y]
    heapq.heapify(p)
    heapq.heapify(q)
    r = deque(sorted(r, reverse=True))
    while r:
        testp = heapq.heappop(p)
        testq = heapq.heappop(q)
        testr = r.pop()
        if testp <= testq:
            heapq.heappush(q, testq)
            if testp <= testr:
                heapq.heappush(p, testr)
            else:
                heapq.heappush(p, testp)

        if testp > testq:
            heapq.heappush(p, testp)
            if testq <= testr:
                heapq.heappush(q, testr)
            else:
                heapq.heappush(q, testq)
    print(sum(p+q))
resolve()

Measured memory_bytes: 23472
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int M;
priority_queue<LL> que;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  cin >> N >> M;
  rep(i, N) {
    LL a;
    cin >> a;
    que.push(a);
  }

  rep(i, M) {
    LL t = que.top(); que.pop();
    que.push(t/2);
  }

  LL tot = 0;
  while (!que.empty()) {
    LL t = que.top(); que.pop();
    tot += t;
  }
  cout << tot << endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

int n;
vi data;

signed main()
{
    cin >> n;
    data.assign(n, 0);
    rep(i, n) {
        cin >> data[i];
    }

    int ans = 0, state = 0, num = data[0];
    Rep(i, n) {
        if (state == 1) {
            if (num > data[i]) {
                state = 0;
                ans++;
            }
        } else if (state == -1) {
            if (num < data[i]) {
                state = 0;
                ans++;
            }
        } else {
            if (num < data[i]) {
                state = 1; // inc
            } else if (num > data[i]) {
                state = -1;
            }
        }
        num = data[i];
    }
    cout << ans +1 << endl;


    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
int l[10];
int main() {
    int n;
    cin >> n;
    rep(i,n){
        cin >> l[i];
    }
    sort(l, l+n);
    int mx = l[n-1];
    int ot = 0;
    rep(i, n - 1){
        ot += l[i];
    }
    if(ot > mx){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;

    }
}



Measured memory_bytes: 256
<?php
$input_line = trim(fgets(STDIN));
  $s = trim(fgets(STDIN));
  $s = str_replace(array("\r\n","\r","\n"), '', $s);
  $s = explode(" ", $s);
  
  $find = 0;
  
  $output = array_count_values($s);
 
  
for ($i = 1; $i < $input_line; $i++) {
// 	for ($j = 0; $j < $input_line -1; $j++) {
// 	   // var_dump((int)$s[$j]);
//         if ((int)$s[$j] == $i) {
//             $find++;
//         }
//     }
//     echo $find . "\n";
//     $find = 0;
    if (isset($output[$i])) {
        echo $output[$i] . "\n";
    } else {
        echo 0 . "\n";
    }
    
}

// echo $output;
echo 0 . "\n";


?>

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

using namespace std;

#define LL long long
#define N 3000
#define INF 0x3f3f3f3f3f3f3f3fLL

LL n,tot,ans,head[N],iter[N],level[N],q[N],a[N];
struct edge{LL v,cap,nxt;}e[N];

void add(LL x,LL y,LL z){
	e[++tot].v=y; e[tot].cap=z; e[tot].nxt=head[x]; head[x]=tot;
	e[++tot].v=x; e[tot].cap=0; e[tot].nxt=head[y]; head[y]=tot;
}

void bfs(LL s){
	memset(level,-1,sizeof level);
	LL tt=0,ww=1; q[1]=s; level[s]=0;
	while (tt<ww){
		LL u=q[++tt];
		for (LL i=head[u],v;i;i=e[i].nxt)
			if (e[i].cap>0&&level[v=e[i].v]<0){
				level[v]=level[u]+1;
				q[++ww]=v;
			}
	}
}
			
LL dfs(LL u,LL t,LL f){
	if (u==t) return f;
	for (LL &i=iter[u],v;i;i=e[i].nxt){
		if (e[i].cap>0&&level[v=e[i].v]>level[u]){
			LL d=dfs(v,t,min(f,e[i].cap));
			if (d>0){e[i].cap-=d; e[i^1].cap+=d; return d;}
		}
	}
	return 0;
}

LL dinic(LL s,LL t){
	LL flow=0;
	while (1){
		bfs(s); if (level[t]<0) break;
		for (LL i=0;i<=n+1;i++) iter[i]=head[i];
		for (LL f=dfs(s,t,INF);f>0;f=dfs(s,t,INF)) flow+=f;
	}
	return flow;
}

int main(){
	scanf("%lld",&n); tot=1;
	for (LL i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		if (a[i]>=0){add(0,i,a[i]); add(i,n+1,0); ans+=a[i];}
		if (a[i]<0){add(0,i,0); add(i,n+1,-a[i]);}
		for (LL j=2;j*i<=n;j++) add(j*i,i,INF);
	}
	ans-=dinic(0,n+1);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 256
#include<stdio.h>

#define N 500000

void merge(int *A,int right,int left,int mid);
void MS(int *A,int left,int right);

int cnt=0;

int main(){
int n,A[N],i,j,k,left,right,mid;

scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
MS(A,0,n);
for(i=0;i<n;i++){
    if(i == 0)printf("%d",A[i]);
    else printf(" %d",A[i]);
}
printf("\n%d\n",cnt);
    return 0;
}

void merge(int *A,int right,int left,int mid){

int n1,n2,i,j,k;

n1 = mid - left;
n2 = right - mid;

int L[n1],R[n2];

for(i=0;i<n1;i++)L[i] = A[left + i];
for(i=0;i<n2;i++)R[i] = A[mid + i];

L[n1] = R[n2] = 999999999;

i = j = 0;

for(k = left; k < right ; k++){
    if(L[i] <= R[j]){
        A[k] = L[i];
        i = i + 1;
        cnt++;
    }
    else {
        A[k] = R[j];
        j = j + 1;
        cnt++;
    }
}
}

void MS(int *A,int left,int right){
    int mid;
    if(left+1 < right){
        mid = (left + right)/2;
        MS(A,left,mid);
        MS(A,mid,right);
        merge(A,right,left,mid);
    }
}


Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=20+10,mod=1e9+7;
inline void add(int &x,int y){
	x+=y;
	if(x>=mod) x-=mod;
}
int dp[2][21][1<<20],l[maxn][maxn],r[maxn][maxn];
int main(){
	int m=read()-1,n=read(),K=read();
	REP(i,1,n) REP(j,1,m) r[i][j]=1;
	while(K--){
		int x=read(),y=read(),z=read();
		l[x][y]=r[x][y]=z;
	}
	dp[0][m][0]=1;
	REP(i,1,n) REP(j,1,m){
		REP(k,0,(1<<m)-1) dp[i&1][j][k]=0;
		REP(k,0,(1<<m)-1){
			int x=i,y=j-1;
			if(!y) y=m,--x;
			x=(x&1);
			REP(u,l[i][j],r[i][j]){
				if(k&(1<<(j-1))){
					if(!u) continue;
					add(dp[i&1][j][k],dp[x][y][k]);
				}
				else{
					if(!u) add(dp[i&1][j][k],dp[x][y][k]);
					else{
						int z=(k^(k&((1<<j)-1)));
						if(z) z=(k^(1<<(__builtin_ctz(z))));
						else z=k;
						z|=(1<<(j-1));
						add(dp[i&1][j][z],dp[x][y][k]);
					}
				}
			}
		}
	}
	int ans=0;
	REP(i,0,(1<<m)-1) add(ans,dp[n&1][m][i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 156032
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n;
    vl X,Y;
    rep(i,n){
        cin>>a>>b;
        X.push_back(a);
        Y.push_back(b);
    } 

    double A=0;

    rep(i,n){
        rep(j,i){
            A+=hypot(X[i]-X[j],Y[i]-Y[j]);
        }
    }

    cout<<setprecision(10)<<A*2/n<<endl;
}

Measured memory_bytes: 256
let solve list =
  let already = Hashtbl.create (List.length list) in
  let rec inner last rest = match rest with
    | [] -> true
    | x::xs ->
       if (String.length last > 0) && (String.get x 0) <> (String.get last (String.length last - 1)) then false
       else
         begin
           if Hashtbl.mem already x then false
           else
             begin
               Hashtbl.add already x 1;
               inner x xs
             end
         end
  in
  inner "" list

let read_list_of_string () =
  let rec read_list_of_string_inner lst =
    try let ans = (Scanf.scanf "%s\n" (fun x->x)) in
        read_list_of_string_inner (ans::lst)
    with End_of_file ->
      List.rev lst
  in
  read_list_of_string_inner []

let () =
  let _ = read_int() in
  let list = read_list_of_string () in
  let ans = solve list in
  Printf.printf "%s\n" (if ans then "Yes" else "No")
;;


Measured memory_bytes: 384
/* Be your own light */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())

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

    ll n,m,i;
    cin>>n>>m;
    vector<ll> a(m);
    ll s = 0;
    for(i=0;i<m;i++) cin>>a[i],s+=a[i];
    // cout<<s<<"  ";
    if(s>n) cout<<-1;
    else cout<<n-s;
}

Measured memory_bytes: 3744
#include<iostream>
using namespace std;
string k[]={"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan",
	    "Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"};
int main(){
  int m,n;
  while(cin>>m>>n&&m){
    int s[18]={};
    s[0]=m;
    for(int i=0;i<n-1;i++){
      for(int j=17;j>=0;j--){
	s[j]*=m;
	int t=j;
	while(s[t]>9999)s[t+1]+=s[t]/10000,s[t]%=10000,t++;
      }
    }
    for(int i=17;i>=0;i--)if(s[i])cout<<s[i]<<k[i];
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
a,b,c,d = map(int,input().split())

def gcd(x,y):
    a = max(x,y)
    b = min(x,y)
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b

if a % c == 0:
    l = a
    if b % c == 0:
        r = b
    else:
        r = b - (b%c)
    if l > r:
        x = 0
    else:
        x = (r-l) // c + 1
else:
    l = a+(c-(a%c))
    if b % c == 0:
        r = b
    else:
        r = b - (b%c)
    if l > r:
        x = 0
    else:
        x = (r-l) // c + 1
if a % d == 0:
    l = a
    if b % d == 0:
        r = b
    else:
        r = b - (b%d)
    if l > r:
        y = 0
    else:
        y = (r-l) // d + 1
else:
    l = a+(d-(a%d))
    if b % d == 0:
        r = b
    else:
        r = b - (b%d)
    if l > r:
        y = 0
    else:
        y = (r-l) // d + 1
g = c*d//gcd(c,d)
if a % g == 0:
    l = a
    if b % g == 0:
        r = b
    else:
        r = b - (b%g)
    if l > r:
        z = 0
    else:
        z = (r-l) // g + 1
else:
    l = a+(g-(a%g))
    if b % g == 0:
        r = b
    else:
        r = b - (b%g)
    if l > r:
        z = 0
    else:
        z = (r-l) // g + 1
ans = b-a+1-x-y+z
print(ans)


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class1
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            int M;
            string ans;
            for(int i = 9; i>1; i--)
            {
                M = N % i;
                if (M == 0)
                {
                    N /= i;
                    break;
                }
            }
            if (N <10)
                ans = "Yes";
            else
                ans = "No";
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;

int SURP = 1000000007;

int main(){
	int N,K;
	cin >> N >> K;
	long long int ret = 0;

	FOR(i,1,N+1){
		int p = N/i;
		int r = N%i;
		ret += p * max(0,i-K);
		if (K==0){
			ret += max(0,r-K);
		}else{
			ret += max(0,r-K+1);
		}
	}

	cout << ret << endl;
	return 0;


}


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


def solve(N: int, K: int, R: int, S: int, P: int, T: str):

    winToR = P
    winToS = R
    winToP = S
    # init
    dp = []
    for i in range(K):
        dp.append([])
        for _ in range(N // K + 1):
            m = [0] * 3
            dp[i].append(m)

    for k in range(K):
        if T[k] == "r":
            dp[k][0][0] = winToR
        elif T[k] == "s":
            dp[k][0][1] = winToS
        else:
            dp[k][0][2] = winToP

    for n in range(K, N):
        if T[n] == "r":

            dp[n % K][n // K][0] = winToR + max(dp[n % K][n // K - 1][1], dp[n % K][n // K - 1][2])
            dp[n % K][n // K][1] = max(dp[n % K][n // K - 1][0], dp[n % K][n // K - 1][2])
            dp[n % K][n // K][2] = max(dp[n % K][n // K - 1][0], dp[n % K][n // K - 1][1])
        elif T[n] == "s":
            dp[n % K][n // K][0] = max(dp[n % K][n // K - 1][1], dp[n % K][n // K - 1][2])
            dp[n % K][n // K][1] = winToS + max(dp[n % K][n // K - 1][0], dp[n % K][n // K - 1][2])
            dp[n % K][n // K][2] = max(dp[n % K][n // K - 1][0], dp[n % K][n // K - 1][1])
        else:
            dp[n % K][n // K][0] = max(dp[n % K][n // K - 1][1], dp[n % K][n // K - 1][2])
            dp[n % K][n // K][1] = max(dp[n % K][n // K - 1][0], dp[n % K][n // K - 1][2])
            dp[n % K][n // K][2] = winToP + max(dp[n % K][n // K - 1][0], dp[n % K][n // K - 1][1])

    sum = 0
    for k in range(N - K, N):
        imax = 0
        for i in range(3):
            imax = max(imax, dp[k % K][k // K][i])
        sum += imax

    print(sum)




    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    T = next(tokens)  # type: str
    solve(N, K, R, S, P, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30680
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    long long int n,sum=0;
    cin >> n;

   for(int i=1;i<=n;i++){
        if(i%3==0||i%5==0) continue;
        sum+=i;
   }
   cout<<sum;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n;
    cin>>n;
    ll ans=1;
    while(n%2){
        n/=2;ans*=2;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

using ll = long long int;

int main() {
    // Input
    int N, K;
    vector<short> D;

    cin >> N >> K;
    D = vector<short>(K);
    rep(i, K) cin >> D[i];

    // Process
    vector<bool> allow(10, true);
    rep(i, K) allow[D[i]] = false;

    int ans;
    for (ans = N;; ans++) {
        int n;
        for (n = ans; n > 0 && allow[n % 10]; n /= 10)
            ;

        if (n == 0) break;
    }

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
char a[MN+5],b[MN+5];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
	int n,m,i,g;long long ans;
	scanf("%d%d%s%s",&n,&m,a,b);
	g=gcd(n,m);ans=1LL*n*m/g;
	for(i=0;i<g;++i)if(a[i*n/g]!=b[i*m/g])break;
	printf("%lld",i<g?-1:ans);
}

Measured memory_bytes: 384
import collections
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
b = collections.Counter(a)
c = list(b.items())
now = 0
tnp = 1
l = 0
l += c[0][1]*2-1
if (l>=n-1):
    print(c[0][0]*(n-1))
    exit()
now = l*c[0][0]
while True:
    if (l+c[tnp][1]*2>=n-1):
        print(now + (n-l-1)*c[tnp][0])
        break
    else:
        l += c[tnp][1]*2
        now += c[tnp][0]*c[tnp][1]*2
        tnp += 1

Measured memory_bytes: 42804
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int a,b;
	cin >> a >> b;
	for(int i = 1; i <= max(a,b); ++i)
	{
		cout << min(a,b);
	}


    return 0;
}

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

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

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define SET(arr) memset(arr, -1, sizeof(arr))
#define CLR(arr) memset(arr, 0, sizeof(arr))

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

#define $ vector< int > :: iterator
#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(int i=0; i<(n); i++)
#define forn(i, n) for (int i = 1; i <=(int)(n); ++i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forba(i, b, a) for (int i = (int)(b); i >= (int)(a); --i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<
#define CS(i) cout<<"Case "<<(int)(i)<<": "

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);
const ld E=2.71828182845904523536;

int main() {
Boost;
//READ("in.txt");
//WRITE("out.txt");
    int n,m;
    cin>>n>>m;
    cout<<n-m+1<<endl;


return 0;
}




Measured memory_bytes: 256
#include<iostream>

int main(void){
	using namespace std;
	int m, n;
	cin >> m >> n;
	int v[m][n];
	int b[n];
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			cin >> v[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	for(int i = 0; i < m; i++){
		int sum = 0;
		for(int j = 0; j < n; j++){
			sum += v[i][j]*b[j];
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3140
#ifdef LOCAL
#  define _GLIBCXX_DEBUG
#  define _GLIBCXX_DEBUG_PEDANTIC
#endif

#include "bits/stdc++.h"
#define ff first
#define ss second
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }

const ll MAXV = 1000000000000000;

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

void solve() {
	int prime_cnt = 2;
	map<pii, int> primes;
	auto get_prime = [&](pii p) {
		if (primes.count(p)) {
			return primes[p];
		}
		/*if (p.ff == 0 && p.ss % 4 == 1) {
			return primes[p] = 1;
		}*/
		while (true) {
			bool fl = true;
			for (int j = 2; j * j <= prime_cnt; ++j) {
				if (prime_cnt % j == 0) {
					fl = false;
					break;
				}
			}
			if (fl) {
				break;
			}
			++prime_cnt;
		}
		return primes[p] = prime_cnt++;
	};
	int n;
	cin >> n;
	vector<vector<ll>> ans(n, vector<ll>(n));
	// int cnt = 2;
	set<ll> have;
	vector<pii> order;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if ((i + j) & 1) {
				order.push_back({i, j});
			}
		}
	}

	for (auto p : order) {
		int i, j;
		tie(i, j) = p;
		ans[i][j] = get_prime({0, i + j});
		// have.insert(ans[i][j]);
	}

	for (auto p : order) {
		int i, j;
		tie(i, j) = p;
		ans[i][j] *= get_prime({1, i - j});
		have.insert(ans[i][j]);
	}	

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (!((i + j) & 1)) {
				ll res = 1;
				for (int d = 0; d < 4; ++d) {
					int nx = i + dx[d];
					int ny = j + dy[d];
					if (0 <= nx && nx < n && 0 <= ny && ny < n) {
						ll tmp = __gcd(res, ans[nx][ny]);
						assert((double) res * ans[nx][ny] / tmp < 1e18);
						res = res / tmp * ans[nx][ny];
						if (res > MAXV) {
							cerr << i << " " << j << endl;
						}
						assert(res <= MAXV);
					}
				}
				int mult = 1;
				while (have.count(res * mult + 1)) {
					++mult;
					assert(res * mult + 1 <= MAXV);
				}
				ans[i][j] = res * mult + 1;
				have.insert(ans[i][j]);
			}
		}
	}

	// cerr << MAXV << endl;
	set<ll> check;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			assert(!check.count(ans[i][j]));
			check.insert(ans[i][j]);
			assert(1 <= ans[i][j] && ans[i][j] <= MAXV);
			for (int d = 0; d < 4; ++d) {
				int nx = i + dx[d];
				int ny = j + dy[d];
				if (0 <= nx && nx < n && 0 <= ny && ny < n) {
					assert(max(ans[nx][ny], ans[i][j]) % min(ans[nx][ny], ans[i][j]) == 1);
				}
			}
		}
	}

	for (auto& v : ans) {
		for (auto num : v) {
			cout << num << " ";
		}
		cout << "\n";
	}
}


int main() {
	//freopen(TASK_NAME ".in", "r", stdin);
	//freopen(TASK_NAME ".out", "w", stdout);
	cerr << fixed << setprecision(15);
	cout << fixed << setprecision(15);
	ios::sync_with_stdio(false);

	int tests = 1;
	// cin >> tests;
	for (int it = 1; it <= tests; ++it) {
		solve();
	}
	
	#ifdef LOCAL
		cerr << "time: " << clock() << " ms\n";
	#endif
	return 0;
}

Measured memory_bytes: 29556
public class Main {
  public static void main(String[] args) {
	java.util.Scanner scanner = new java.util.Scanner(System.in);
	int n = scanner.nextInt();
	int[] a = new int[n];
	for (int i = 0; i < n; i++) {
		a[i] = scanner.nextInt();
	}
	
	int count = 0; // 2で割った回数
	while(true) {
		boolean hasOdd = false;
		for (int i = 0; i < n; i++) {
			if (a[i] % 2 != 0) {
				hasOdd = true;
				break;
			}
		}
		if (hasOdd) {
			break;
		}
		for (int i = 0; i < n; i++) {
			a[i] = a[i] / 2;
		}
		count++;
	}
	System.out.println(count);
  }
}


Measured memory_bytes: 22740