akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
using namespace std;

typedef long long ll;

const int MAX = 100001;
ll n, k;
ll w[MAX];

ll check(ll p) {
    ll i = 0;
    for (int j = 0; j < k; j++) {
        ll s = 0;
        while (s + w[i] <= p) {
            s += w[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

ll binSearch(ll lo, ll hi) {
    while (hi - lo > 1) {
        ll mi = (lo + hi) >> 1;
        ll v = check(mi);
        if (v >= n) hi = mi;
        else lo = mi;
    }
    return hi;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%lld %lld", &n, &k);
    for (int i = 0; i < n; i++) scanf("%lld", &w[i]);
    ll p = binSearch(0, 100000LL * 10000LL);
    printf("%lld\n", p);
    return 0;
}

Measured memory_bytes: 3984
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math,sys

n = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split()))
#n = int(input())
#a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
acc = a[0]
for i in range(n):
    acc = math.gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
def make():
    for i in range(2,LIMIT+1):
        if minPrime[i] == 0:
            minPrime[i] = i
            #print(i)
            for j in range(i+i,LIMIT+1,i):
                #print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i
make()
def factrial(N):
     ret = []
     while minPrime[N] != N:
         ret.append(minPrime[N])
         N = N//minPrime[N]
     if N != 1:
         ret.append(N)
     return ret

judge = set([])

for e in a:
    asf = set(factrial(e))
    if judge & asf != set():
        print("setwise coprime")
        exit()
    judge |= asf
    #judge = judge | asf #too slow
print("pairwise coprime")


Measured memory_bytes: 203640
#include <stdio.h>

#define lli long long int

int main() {
	lli w, h, x, y, z = 0;
	double ans;
	scanf("%lld %lld %lld %lld", &w, &h, &x, &y);
	ans = (double) (w * h) / 2.0;
	if (((2 * x) == w) && (2 * y) == h)
		z = 1;
	printf("%.12lf %lld\n", ans, z);
	return 0;
}

Measured memory_bytes: 128
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = list(LI())
    m = max(n)
    n.remove(m)
    print(m*10+sum(n))


if __name__ == "__main__":
    main()


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

int main() {
    int n, x, y; cin >> n >> x >> y;
    int d[n] = {};
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            d[min({j - i, abs(x - i) + abs(y - j) + 1,
                          abs(y - i) + abs(x - j) + 1}) - 1]++;
        }
    }
    for (int i = 0; i < n - 1; i++) {
        cout << d[i] << endl;
    }
}

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

int main() {
  
  int N; cin >> N;
  
  vector<int> vec(N); vector<int> sorted(N);
  
  for (int i = 0; i < N; i++) {
    
    cin >> vec[i]; sorted[i] = vec[i];
    
  }
  
  sort(sorted.begin(), sorted.end());
  
  if (sorted.back() == sorted[N - 2]) {
    
    for (int i = 0; i < N; i++) cout << sorted.back() << endl;
    
  }
  
  else {
    
    for (int i = 0; i < N; i++) {
      
      if (sorted.back() == vec[i]) cout << sorted[N - 2] << endl;
      
      else cout << sorted.back() << endl;
      
    }
    
  }
  
}

Measured memory_bytes: 3200
#include <cstdio>
#include <algorithm>
using namespace std;

int a[5];

int main(void){
	for(int i=1;i<=3;i++)
	scanf("%d",&a[i]);
	sort(a+1,a+1+3);
	if(a[1]==a[2]&&a[1]!=a[3]){
		printf("Yes\n");
		return 0;
	}
	if(a[2]==a[3]&&a[1]!=a[3]){
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int n,mi=10000000,ma=-10000000;
    long long sum=0;
    cin >> n;
    int i,b;
    for(i=0;i<n;i++){
        cin >> b;
        mi=min(mi,b);
        ma=max(ma,b);
        sum+=b;
    }
    cout << mi <<  " " << ma << " " << sum << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,a=0; scanf("%lld\n",&n);
    if(n==1000000000000000000){
        cout << 124999999999999995 << endl;
        return 0;
    }
    if(n%2) return puts("0"),0;
    a += n / 10;
    a += n / 50;
    a += n / 250;
    a += n / 1250;
    a += n / 6250;
    a += n / 31250;
    a += n / 156250;
    a += n / 781250;
    a += n / 3906250;
    a += n / 19531250;
    a += n / 97656250;
    a += n / 488281250;
    a += n / 2441406250;
    a += n / 12207031250;
    a += n / 61035156250;
    a += n / 305175781250;
    a += n / 1525878906250;
    a += n / 7629394531250;
    a += n / 38146972656250;
    a += n / 190734863281250;
    a += n / 953674316406250;
    a += n / 4768371582031250;
    a += n / 23841857910156250;
    a += n / 119209289550781250;
    a += n / 596046447753906250;
    printf("%lld\n",a);
}

Measured memory_bytes: 3712
from itertools import combinations

h, w, k = map(int, input().split())

c = [list(input()) for i in range(h)]

def make(a):
    new = []
    for i in a:
        new.append(c[i])
    return new

def counter(lines, b):
    cnt = 0

    for i in b:
        for j in lines:
            if j[i] == '#':
                cnt += 1
    if cnt == k:
        return 1
    else:
        return 0
            


count = 0
for r in range(1,h+1):
    for i in combinations(range(h), r):
        new = make(i)
        for l in range(1, w+1):
            for j in combinations(range(w), l):
                num =counter(new, j)
                count += num
print(count)

Measured memory_bytes: 9096
#include <stdio.h>
#define N 10
#define M 200

void minCost(int w[][N], int m[][N]){
	int i, j, k, D;
	int pre[N][N];
	for (i = 0; i < N; i++){
		for (j = 0; j < N; j++){
			m[i][j] = w[i][j];
			pre[i][j] = i;
		}
	}

	for (k = 0; k < N; k++){
		for (i = 0; i < N; i++){
			for (j = 0; j < N; j++){
				D = m[i][k] +m[k][j];
				if (D < m[i][j]){
					m[i][j] = D; 
					pre[i][j] = pre[k][j];
				}
			}
		}
	}
}
int main(void){
	int H, W;
	scanf("%d%d", &H, &W);
	int c[N][N], A[M][M];
	int i, j;
	//printf("cij>>\n");
	for (i = 0; i < N; i++){
		//printf("%d: ", i);
		for (j = 0; j < N; j++){
			 scanf("%d", &c[i][j]);
		}
	}
	//printf("Aij>>\n");
	for (i = 0; i < H; i++){
		//printf("%d: ", i);
		for (j = 0; j < W; j++){
			 scanf("%d", &A[i][j]);
		}
	}
	int minM[N][N];
	minCost(c, minM);
	int res = 0;
	for (i = 0; i < H; i++){
		for (j = 0; j < W; j++){
			if (A[i][j] == -1) res += 0;
			else res += minM[A[i][j]][1];
		}
	}
	printf("%d\n", res);
	return 0;
}

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

string aiueo = "aiueo";

bool f(char x){
    return count(aiueo.begin(), aiueo.end(), x);
}

int main(){
    int n;
    while(cin >> n, n){
        vector<string> codes;
        string s;
        int ma = 0;

        for(int i = 0; i < n; i++){
            cin >> s;
            string code = "";
            code += s[0];
            for(int i = 0; i < s.length()-1; i++)   if(f(s[i])) code += s[i+1];
            codes.push_back(code);
            ma = max(ma, (int)code.length());
        }

        int k, i;
        for(k = 1; k <= ma; k++){
            set<string> se;
            for(i = 0; i < n; i++){
                string tmp;
                if(codes[i].length() >= k){
                    tmp = codes[i].substr(0,k);
                }else{
                    tmp = codes[i];
                }
                if(se.count(tmp))   break;
                se.insert(tmp);
            }
            if(i == n)  break;
        }

        cout << (k == ma+1 ? -1 : k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
def chess(h,w):
  if (h+w) % 2 == 0:
    return '#'
  return '.'

while True:
  H,W = map(int, input().split())
  if H == 0 and W ==0:
    break
  for i in range(H):
    for j in range(W):
      print(chess(i,j), end='')
    print()
  print()


Measured memory_bytes: 7004
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
#define X first
#define Y second
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
const int maxn=1e4+10;
int a[maxn];

int main(){
	int sum=0;
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	int cnt;
	bool flag=false;
	if(sum%(4*m)==0){
		cnt=sum/(4*m);
	}else{
		sum-=(sum%(4*m));
		cnt=sum/(4*m);
		flag=true;
	}
	int res=0;
	bool tag=false;
	for(int i=0;i<n;i++){
		if(a[i]>=cnt&&!flag){
			res++;
		}else if(a[i]>=cnt+1&&flag){
			res++;
		}
		if(res>=m){
			tag=true;
			break;
		}
	}
	if(tag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    switch(n%10) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon";
            break;
        case 3:
            cout << "bon";
            break;
        default:
            cout << "pon";
            break;
    }

    return 0;
}


Measured memory_bytes: 3672
typedef long long ll;

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

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  const int k = getInt();

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

  REP(i,n){
    a[i] = getInt();
    b[i] = getInt();
  }

  ll ans = 0;
  for(int i = 0; i <= 30; i++){
    if((k & (1 << i)) == 0) continue;

    int mask = 0;
    int mask2 = 0;
    for(int j = i + 1; j <= 30; j++){
      mask2 |= 1 << j;
      if(k & (1 << j)) mask |= 1 << j;
    }

    ll cur = 0;
    REP(j,n){
      if(a[j] & (1 << i)) continue;
      if(((a[j] & mask2) | mask) != mask) continue;
      cur += b[j];
    }

    ans = max(ans, cur);
  }

  ll cur = 0;
  REP(i,n){
    if((a[i] | k) == k) cur += b[i];
  }
  ans = max(ans, cur);

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

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, n) {
        cin >> a[i+1];
    }
    vector<int> ans(n+1);

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

    int sum = 0;
    rep(i, n) {
        sum += ans[i+1];
    }
    cout << sum << endl;
    rep(i, n) {
        if (ans[i+1]==1) cout << i+1 << " ";
    }
    cout << endl;
    
    

    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
using namespace std;
int main() {
	int w, n;
	int l[30];
	int tmp;
	int a, b;
	char c;
	cin >> w >> n;
	for (int i = 0; i < w; i++){
		l[i] = i + 1;
	}
	for (int i = 0; i < n; i++){
		cin >> a >> c >> b;
		a -= 1;
		b -= 1;
		tmp = l[a];
		l[a] = l[b];
		l[b] = tmp;
	}
	for (int i = 0; i < w; i++){
		cout << l[i] << endl;
	}
	cin >> c;
}

Measured memory_bytes: 3076
// 解き直し.
// https://img.atcoder.jp/nomura2020/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
const int MAX = 101010;
LL A[MAX], B[MAX], ACUM[MAX];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N + 1) scanf("%lld", &A[i]);
    
    // 解説通り.
    // 2. 累積和.
    rep(i, 101010) ACUM[i + 1] = ACUM[i] + A[i];
    
    // 3. 葉でない頂点数を更新.
    // 33.txt で WA版.
    // 0
    // 2
    // -> -1 が 正解だが, 1 が 出力されたので, ロジック修正.
    // 3-1. 条件(1) を 設定.
    bool ok = true;
    B[0] = 1 - A[0];
    if(B[0] < 0) ok = false; // 33.txt 対策.
    repx(i, 1, N + 1){
        // 3-2. 条件(2), (3) から, B[i] の 候補 を 計算.
        B[i] = min(2 * B[i - 1] - A[i], ACUM[N + 1] - ACUM[i + 1]);
        
        // 3-3. 条件(2) を チェック.
        if(A[i] + B[i] < B[i - 1] || A[i] + B[i] > 2 * B[i - 1] || B[i] < 0){
            ok = false;
            break;
        }
    }
    
    // 4. 頂点数を保存.
    LL ans = 0;
    rep(i, N + 1) ans += (A[i] + B[i]);
    
    // 5. 出力.
    printf("%lld\n", ok ? ans : -1);
    return 0;
    
}

Measured memory_bytes: 6040
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)

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

    int n; cin >> n;
    int a[n];
    int count_4 = 0;
    int count_2 = 0;
    int count_odd = 0;
    REP(i, n) {
        cin >> a[i];
        if (!(a[i] % 4)) count_4++;
        else if (!(a[i] % 2)) count_2++;
        else count_odd++;
    }

    if (count_4 >= n / 2) cout << "Yes" << '\n';
    else if (count_4 >= count_odd) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] = abs(a[i] - x);
	}
	int ans = a[0];
	for (int i = 0; i < n; i++) {
		ans = __gcd(ans, a[i]);
		if (ans == 1)
			return cout << 1, 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3752
/// Be Kind :)
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")

/*				Who knew evil girls had the prettiest face					*/

/*				We pop out at your party, I'm with the gang
				And it's gon' be a robbery, so tuck ya chain
				I'm a killer girl, I'm sorry, but I cannot change
				We ain't aiming for your body, shots hit you brain
				We come from poverty, man, we ain't have a thing
				It's a lot of animosity, but they won't say my name
				Them killers rock with me, lil' nigga, don't get banged
				'Cause they'll do that job for me while I hop on a plane	*/

/*				I take you to the candy shop								*/

/*				Baby, let me put your panties to the side
				I'ma make you feel alright
				'Cause I'ma give you what you need, yeah					*/

/*				Ooooh ooh, it's me, myself and I
				Solo ride until I die, 'cause I got me for life				*/

/*				So I ball So hard, muh'fuckas wanna find me					*/

/*				Bitch, where you when I was walkin'?
				Now I run the game, got the whole world talkin'				*/
 
/*				Niggas been counting me out
				I'm counting my bullets, I'm loading my clips
				I'm writing down names, I'm making a list					*/

/*				Fuck your friendship, I meant it							*/

/*				The Chanel or Balenciaga, Louis and Vuitton
				She know I got Fendi, Prada when I hit Milan				*/

/*				I ran away, I don't think I'm coming back home				*/
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
 
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn=1e5+10, maxm=1e5+10, lg=21, mod=1e9+7, inf=1e18;

#define kill() cout<<"First", exit(0)

vector<ll> g[maxn];
bool bal[maxn];
void dfs(ll v=1,ll p=0){
	bal[v]=1;
	for(auto u:g[v])if(u!=p){
		dfs(u,v);
		if(bal[u]){
			if(bal[v]) bal[v]=0;
			else kill();
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	ll n; cin>>n;
	if(n%2) kill();
	for(int i=1;i<n;i++){
		ll v,u; cin>>v>>u;
		g[v].pb(u), g[u].pb(v);
	}
	dfs();
	cout<<"Second";
	
	return 0;
}



 


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j

const int mod = 2019;

int main() {
  ll L, R;
  cin >> L >> R;
  if (R - L >=2018) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> modnums(R - L + 1);
  rep(i, 0, R - L + 1) {
    int num = (L + i) % mod;
    modnums[i] = num;
  }
  vector<int> ans;
  rep(i, 0, modnums.size() - 1) {
    rep(j, i+1,  modnums.size()) {
      int num = (modnums[i] * modnums[j]) % mod;
      ans.pb(num);
    }
  }
  sort(All(ans));
  cout << ans[0] << endl;
};


Measured memory_bytes: 9840
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

	int N;
	cin >> N;

	VI fs( N ), as( N ), ts( N ), xs( N ), ys( N );
	REP( i, N )
	{
		cin >> fs[i] >> as[i] >> ts[i] >> xs[i] >> ys[i];
	}

	VT( double ) dists( 2, -1 ), times( 2, 1e9 );
	REP( i, 1, N )
	{
		const int t = ts[i];
		if ( !( ts[ i - 1 ] == t && as[i] != as[ i - 1 ] ) )
		{
			continue;
		}

		const double dist = sqrt( pow( xs[i] - xs[ i - 1 ], 2. ) + pow( ys[i] - ys[ i - 1 ], 2. ) );
		const double time = ( fs[i] - fs[ i - 1 ] ) * ( 1 / 60. );

		if ( dists[t] < dist || abs( dists[t] - dist ) <= 1e-5 && time < times[t] )
		{
			dists[t] = dist;
			times[t] = time;
		}
	}

	cout << setprecision( 8 ) << fixed;
	REP( i, 2 )
	{
		if ( dists[i] == -1 )
		{
			cout << "-1 -1" << endl;
		}
		else
		{
			cout << dists[i] << ' ' << times[i] << endl;
		}
	}

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (ll i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  ll h, n, a;
  cin >> h >> n;
  ll sum = 0;
  re(i, n) {
    cin >> a;
    sum += a;
  }

  if(h <= sum) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
char b[ 2000];
int main()
{
    char a[4]={'y','a','k','i'};
    while(cin>>b)
    {
        int flag=0;
        int  len=strlen( b);
            if(b[0]=='Y'&&b[1]=='A'&&b[2]=='K'&&b[3]=='I')
                flag=1;
        if(flag)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
signed main(){
    int n,m,l,a[100][100],b[100][100];
    cin>>n>>m>>l;
    rep(i,n)rep(j,m)cin>>a[i][j];
    rep(i,m)rep(j,l)cin>>b[i][j];
    rep(i,n){
        rep(j,l){
            int sum=0;
            rep(k,m){
                sum+=a[i][k]*b[k][j];
            }
            cout<<sum;
            if(j!=l-1)cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1e18;
void solve(){

}
int main(){
    ll A,B,C;
    cin >> A >> B >> C;
    ll total = A * B * C;
    ll ans = LINF;
    if (A % 2 == 1 && B % 2 == 1 && C % 2 == 1) {
        ans = min(ans, min(B*C,min(C*A,A*B)));
    } else {
        ans = 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, ll> P;

const ll MOD=1000000007;
int N;
ll a[1000];
bool used[1000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>a[i];
    int res=max_element(a, a+N)-a;
    if(0>=a[res]){
        cout <<a[res]<<"\n";
        cout <<N-1<<"\n";
        rep(i,0,res){
            cout <<1<<"\n";
        }
        rep(i,res+1,N){
            cout <<N-i+1<<"\n";
        }
        return 0;
    }
    ll e=0,o=0;
    rep(i,0,N){
        if(a[i]>0){
            if(i%2) o+=a[i];
            else e+=a[i];
        }
    }
    int k;
    if(o>e) k=1;
    else k=0;
    int cnt=0;
    rep(i,0,N){
        if(a[i]<=0||(a[i]>0&&i%2!=k)){
            used[i]=1;
        }
    }
    cout <<max(e,o)<<"\n";
    bool t=true;
    int siz=N;
    vector<int> ans;
    while(t&&siz){
        t=false;
        if(used[0]){
            cnt++;
            t=true;
            ans.pb(1);
            siz--;
            rep(i,0,siz){
                used[i]=used[i+1];
            }
            continue;
        }
        if(used[siz-1]){
            cnt++;
            t=true;
            ans.pb(siz);
            siz--;
            continue;
        }
        else{
            rep(i,1,siz-1){
                if(used[i]&&used[i-1]==used[i+1]){
                    cnt++;
                    t=true;
                    ans.pb(i+1);
                    siz-=2;
                    rep(k,i,siz){
                        used[k]=used[k+2];
                    }
                    break;
                }
            }
        }
    }
    cout <<cnt<<"\n";
    rep(i,0,cnt){
        cout <<ans[i]<<"\n";
    }
}

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

const int MAX = 2000000;
int A[MAX + 1];
int H = 0;

void maxHeapify(int i) {
  int largest;
  int l = i * 2;
  int r = i * 2 + 1;

  if (l <= H && A[l] > A[i]) {
    largest = l;
  } else {
    largest = i;
  }
  if (r <= H && A[r] > A[largest]) largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

void insert(int k) {
  H++;
  A[H] = k;
  int i = H;
  while (i > 1 && A[i / 2] < A[i]) {
    swap(A[i / 2], A[i]);
    i = i / 2;
  }
}

int extract() {
  int r = A[1];
  swap(A[1], A[H]);
  H--;
  maxHeapify(1);
  return r;
}

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

  string command;
  int k;
  while (1) {
    cin >> command;
    if (command[0] == 'i') {
      // insert
      cin >> k;
      insert(k);
    } else if (command[1] == 'x') {
      // extract
      cout << extract() << endl;
    } else if (command[1] == 'n') {
      // end
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 7084
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>
#include<set>
#include<stack>
#include<map>

using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> prime;
    const int MAXP=55556;
    bool IsPrime[MAXP];
    fill(IsPrime,IsPrime+MAXP,true);
    for(int i=2;i<MAXP;i++){
        if(IsPrime[i]){
            prime.push_back(i);
            int j=2*i;
            while(j<MAXP){
                IsPrime[j]=false;
                j+=i;
            }
        }
    }
    /*
    int tmp[5]={};
    for(int i=0;i<prime.size();i++){
        int x=prime[i]%5;
        tmp[x]++;
    }
    for(int j=0;j<5;j++){
        cout<<tmp[j]<<endl;
    }
     */
    int count=0;
    int i=0;
    while(count<N){
        int x=prime[i];
        if(x%5==1){
            cout<<x<<' ';
            count++;
        }
        i++;
    }
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main()
{
  int a[100][100]; //0オリジン
  int n,i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=0;  //a[0][0]=0,a[1][1]=0, ...
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u=u-1; //0オリジンへ変換
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v=v-1; //0オリジンへ変換
      a[u][v] = 1; // 辺作成
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0) printf(" ");
      printf("%d",a[i][j]);
    }
    printf("\n");
  }
  return 0;
}
  



Measured memory_bytes: 2104
using System.Linq;
using System;
using System.IO;
using System.Collections.Generic;

class Program
{
  static void Main(string[] args) =>
    new Program().solve();

  private void solve()
  {
    var seq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var a = seq[0];
    var b = seq[1];
    var k = seq[2];

    var ans = intStm(1).Take(Math.Max(a, b))
      .Where(i => (a % i == 0) && (b % i == 0))
      .Reverse().Skip(k-1).First();
    Console.WriteLine(ans);
  }

  private IEnumerable<int> intStm(int n)
  {
    while(true) { yield return n++; }
  }
}

Measured memory_bytes: 13396
n, a, b = map(int, raw_input().split())

def doit(aa, bb, mask):
    bits   = filter(lambda b: mask & (1 << b) == 0, range(n))
    differ = filter(lambda b: (aa ^ bb) & (1 << b), bits)[-1]
    change = filter(lambda b: differ != b, bits)
    if not change:
        return [aa, bb]
    ab = aa ^ (1 << change[0])
    ba = ab ^ (1 << differ)
    return doit(aa, ab, mask | (1 << differ)) + doit(ba, bb, mask | (1 << differ))

if bin(a ^ b).count('1') % 2 != 1:
    print "NO"
else:
    print "YES"
    ret = doit(a, b, 0)
    print " ".join(map(str, ret))

Measured memory_bytes: 15612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin>>n;
    
    string s[] = {"AC","WA","TLE","RE"};
    
    vector<int> a(4,0);
    
    for(int i=0; i<n; i++){
        
        string s1;
        cin>>s1;
        
        if(s1[0]=='A') a[0]++;
        if(s1[0]=='W') a[1]++;
        if(s1[0]=='T') a[2]++;
        if(s1[0]=='R') a[3]++;
    }
    
    
    for(int i=0; i<4; i++){
        
        cout<<s[i]<<" x "<<a[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






/*
考察
a[i]=0,1は使わない
a[i]=2は全て使う
a[i]=-2はペアで使っていく
もし、a[i]=-2が奇数個でa[i]=-1があるなら、そこでペアにして使う
*/














int N, A[101];
int use[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    map<int, int> cnt;
    rep(i, 0, N) cnt[A[i]]++;

    // 2
    rep(i, 0, N) if (A[i] == 2) use[i] = 1;

    // -2
    int m2 = cnt[-2];
    if (m2 % 2 == 1) {
        if (0 < cnt[-1]) {
            rep(i, 0, N) if (A[i] == -1) {
                use[i] = 1;
                break;
            }
        } else m2--;
    }
    rep(i, 0, N) if (A[i] == -2 and m2) {
        use[i] = 1;
        m2--;
    }

    vector<int> ans;
    rep(i, 0, N) if (use[i]) ans.push_back(i + 1);
    
    int n = ans.size();
    printf("%d\n", n);
    rep(i, 0, n) printf("%d\n", ans[i]);
}


Measured memory_bytes: 3308
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    A = LI()
    B = LI()

    cnt = 0
    for i in range(n):
        left = min(A[i], B[i])
        B[i] -= left
        cnt += left

        # if B[i] > 0:
        right = min(A[i+1], B[i])
        A[i+1] -= right
        cnt += right
    print(cnt)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 19284
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func main() {
	var N, M int
	fmt.Scanf("%d %d\n", &N, &M)
	nf := FactoredPrimeNumber(GCD(N, M))

	fmt.Println(len(nf) + 1)

}


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

int main()
{
  int n;
  string str;
  cin>>n;
  cin>>str;
  int ans = 1;
  for(int i = 1;i<n;i++)
  {
    if(str[i]==str[i-1])
      continue;
    ans++;
  }
  cout<<ans<<"\n";
  return 0;
}
  	

Measured memory_bytes: 512
typedef long long ll;

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

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

const int mod = 1000000007;

int main(){
  const int n = getInt();
  vector<vector<ll> > now(n + 1, vector<ll>(n + 1));
  vector<char> ss(n);

  now[0][0] = 1;

  REP(k,n){
    char c[2]; scanf("%s", c);
    ss[k] = c[0];
  }

  REP(k,n){
    vector<vector<ll> > next(n + 1, vector<ll>(n + 1));
    const char c = ss[k];

    REP(i,n + 1) REP(j,n + 1) if(now[i][j]){
      if(c == 'U'){
        if(j > 0){
          // ue
          next[i][j] += now[i][j] * j;
          next[i][j] %= mod;
        }
        // sita
        next[i + 1][j + 1] += now[i][j];
        next[i + 1][j + 1] %= mod;
      }else if(c == 'D'){
        if(i > 0){
          if(j > 0){
            // ue
            next[i - 1][j - 1] += now[i][j] * j * i;
            next[i - 1][j - 1] %= mod;
          }
          // sita
          next[i][j] += now[i][j] * i;
          next[i][j] %= mod;
        }
      }else{
        next[i][j] += now[i][j];
        next[i][j] %= mod;
      }
    }

    now.swap(next);
  }

  printf("%d\n", (int)now[0][0]);

  return 0;
}

Measured memory_bytes: 1532
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	FORI(i,1,10)
	{
		if(N%i==0 && N/i<10)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string SS, T;
  cin >> SS;
  cin >> T;

  ll N = SS.length();
  ll M = T.length();

  set<string> ans;

  REP(i, N - M + 1) {
    bool ok = true;
    REP(j, M) if (SS[i + j] != '?' && SS[i + j] != T[j]) ok = false;

    if (ok) {
      string S;
      REP(j, N) S += SS[j];
      REP(j, M) S[i + j] = T[j];
      REP(j, N) if (S[j] == '?') S[j] = 'a';
      ans.insert(S);
    }
  }
  if (ans.size() == 0) {
    cout << "UNRESTORABLE";
  } else {
    cout << *(ans.begin());
  }

  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, a: i64, b: i64, c: i64, d: i64);
    let x = a * c;
    let y = b * d;
    let z = a * d;
    let w = b * c;
    let mut ret = max(x, y);
    ret.chmax(z);
    ret.chmax(w);
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2172
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <map>
using namespace std;
using Int = long long;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    int result = 0;
    for (int i = 0; i < 29; i++) {
        vector<int> C(N), D(N);
        int T = 1 << i;
        for (int j = 0; j < N; j++) C[j] = A[j] % (T<<1), D[j] = B[j] % (T<<1);
        sort(C.begin(), C.end());
        sort(D.begin(), D.end());
        Int count = 0;
        for (int c : C) {
            count += lower_bound(D.begin(), D.end(), 2 * T - c) - lower_bound(D.begin(), D.end(), T - c);
            count += D.end() - lower_bound(D.begin(), D.end(), 3 * T - c);
        }
        result |= (count % 2) << i;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3432
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
    int n;
    int d;
    cin>>n>>d;
    int cnt=0;
    while (n--) {
        int  x, y;
        cin>>x>>y;
        double ans = (sqrt(x*x + y*y));
        if (ceil(ans)<=d) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3608
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define INF 100000000000000000

int main(){
  long long n;
  cin >> n;
  long long a,b;
  long long ans = INF;
  long long count = 0;
  for(int i=1;i<n;i++){
    count = 0;
    a = i;
    b = n-i;
    while(a != 0){
      count += a%10;
      a -= a%10;
      a /= 10;
    }
    while(b != 0){
      count += b%10;
      b -= b%10;
      b /= 10;
    }
    ans = min(ans,count);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))

A = [0] * N
for i in range(M):
    a, b = map(int, input().split())
    A[a-1] = max(A[a-1], H[b-1])
    A[b-1] = max(A[b-1], H[a-1])

res = sum([H[i] > A[i] for i in range(N)])
print(res)

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(k > a){
        ans += a;
        k -= a;
    }
    else{
        ans += k;
        k = 0;
    }
    if(k > 0) k -= b;
    while(k > 0){
        ans--;
        k--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
n=int(input())
h=list(map(int,input().split()))
ans=[]
forward=0
count2=0
for i in range(n):
    if h[i]>forward:
        ans.append(0)
        count=0
    else:
        ans.append(count+1)
        count+=1
    forward=h[i]
    #print(ans)
print(max(ans))


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  if(a+b==15){
     cout <<"+"<<endl; 
    }else if(a*b==15){
      cout <<"*"<<endl;
    }else{
      cout<<"x"<<endl;
    }
  
    return 0;
  }

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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int nmax = 40, abmax = 10, inf = 1000000;

int a[nmax], b[nmax], c[nmax];
int dp[nmax + 1][nmax * abmax + 1][nmax * abmax + 1];

int main(int argc, const char * argv[]) {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  
  for (int i = 0; i <= n; i++) {
    for (int ca = 0; ca <= nmax * abmax; ca++) {
      for (int cb = 0; cb <= nmax * abmax; cb++) {
        dp[i][ca][cb] = inf;
      }
    }
  }
  
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int ca = 0; ca <= nmax * abmax; ca++) {
      for (int cb = 0; cb <= nmax * abmax; cb++) {
        if (dp[i][ca][cb] == inf) {
          continue;
        }
        dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
        dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
      }
    }
  }
  
  int ans = inf;
  for (int ca = 1; ca <= nmax * abmax; ca++) {
    for (int cb = 1; cb <= nmax * abmax; cb++) {
      if (ca * mb == cb * ma) {
        ans = min(ans, dp[n][ca][cb]);
      }
    }
  }
  
  if (ans == inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 25984
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int[] hiniti = {0,31,29,31,30,31,30,31,31,30,31,30,31};
			int month = sc.nextInt() ;
			int day = sc.nextInt();
			if(month == 0 && day == 0) break;
			for(int i = 0;i < month;i++){
				day += hiniti[i];
			}
			int date = day % 7;
			switch(date){
			case 1:System.out.println("Thursday");break;
			case 2:System.out.println("Friday");break;
			case 3:System.out.println("Saturday");break;
			case 4:System.out.println("Sunday");break;
			case 5:System.out.println("Monday");break;
			case 6:System.out.println("Tuesday");break;
			case 0:System.out.println("Wednesday");break;
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 17412
def check(x)
  i = 2
  max = 1
  while (i ** 2) <= x
    j = 2
    while true
      test = i ** j
      if test < x
        if test > max
          max = test
        end
      end
      if test == x
        return x
      end
      if test > x
        break
      end
      j += 1
    end
    i += 1
  end
  return max
end

x = gets.chomp.to_i
if x == 1
  puts 1
else
  puts check(x)
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(ll i=a;i<=(ll)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int n,k,t=M;cin>>n>>k;
    vector<int> v(n+1);v[0]=0;
    repp(i,1,n) cin>>v[i];
    sort(v.begin(),v.end());
    repp(i,1,n-k+1) {
        t=min(t,v[i+k-1]-v[i]);
    }
    cout<<t;
}

Measured memory_bytes: 640