akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;

int main(){ 
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(min(B,D) < max(A,C)){
    cout << '0' << endl;
  }else{
    cout << min(B,D)-max(A,C) << endl;
  }
}

Measured memory_bytes: 256
'''
def num_div(n):
    cnt = 0
    for i in range(1, n+1, 2):
        if n % i == 0:
            cnt += 1
    return cnt

l = []
for i in range(1, 201):
    if num_div(i) == 0:
        l.append(i)
'''
l = [105, 135, 165, 189, 195]

n = int(input())

for i in range(5):
    if n < l[i]:
        print(i)
        exit()

print(5)

Measured memory_bytes: 61552
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0;i < n;i++)
typedef long long ll;
const long long INF = 1LL<<60; // 仮想的な無限大の値

using namespace std;

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

  int n, k;
  while(cin >> n >> k) {
    if (n == 0)
      break;
    vector<int> a(n);
    rep(i, n) 
      cin >> a[i];

    vector<int> s(n+1);
    rep(i, n){
      s[i+1] = s[i] + a[i];
    }

    int ans = 0;
    rep(i, n-k) {
      ans = max(ans, s[i+k] - s[i]);
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;

struct UnionFindTree{
    vector<int> par,rank;
    UnionFindTree(int n):par(n),rank(n,0){
        for(int i=0;i<n;i++) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[rx]<rank[ry]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

ll power(ll a,ll x){
    ll res=1;
    while(x>0){
        if(x&1) res*=a;
        a*=a;
        x>>=1;
    }
    return res;
}

int popcount(int x){
    int res=0;
    while(x>0){
        if(x&1) res++;
        x>>=1;
    }
    return res;
}

int f(int x){
    if(x==0) return 1;
    return f(x%popcount(x))+1;
}

vector<int> prime_factor(int n){
    vector<int> res(n+1,0);
    for(int i=2;i<=n;i++){
        int m=i;
        for(int j=2;j*j<=m;j++){
            if(m%j==0){
                while(m%j==0){
                    res[j]++;
                    m/=j;
                }
            }
        }
        if(m!=1) res[m]++;
    }
    return res;
}

int main(){
    int n;cin>>n;
    vector<int> cp=prime_factor(n);
    int ans=0;
    sort(cp.begin(),cp.end(),greater<int>());
    int m=(int)cp.size();
    for(int i=0;i<m;i++){
        if(cp[i]>=74) ans++;
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            if(i==j) continue;
            if(cp[i]>=24&&cp[j]>=2) ans++;
            if(cp[i]>=14&&cp[j]>=4) ans++;
        }
    }
    for(int i=0;i<m;i++){
        for(int j=i+1;j<m;j++){
            for(int k=0;k<m;k++){
                if(i==j||j==k||k==i) continue;
                if(cp[i]>=4&&cp[j]>=4&&cp[k]>=2) ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

namespace ABC042A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            d = a + b + c;

            if (d == 17) Console.WriteLine("YES");
            else Console.WriteLine("NO");

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>

using namespace std;

int Ans[100000];

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

    int A;
    for(int i = 0; i < n; i++){
        cin >> A;
        Ans[A - 1] = i + 1;
    }

    for(int i = 0; i < n; i++){
        cout << Ans[i] << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 1152
n = int(input())
lis = []
for i in range(n):
    a,b =map(int,input().split())
    lis.append([a-b,a+b])
lis.sort(key = lambda x:x[1])
ans = 0
now = -10 ** 10
for a,b in lis:
    if now <= a:
        ans += 1
        now = b
print(ans)

Measured memory_bytes: 21336
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
map<string,ll>mp;
int main()
{
    ll a,b,c,i,j,k=0,x=0;
    string s;
    cin>>a;
    b=(a*(a+1))/2;
    x=b-a;
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//動画解答写し 
int main() {
  int n; cin >>n;
  vector<int>a(n);
  int kotae=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    kotae^=a[i];
  }
  for(int i=0;i<n;i++){
    a[i]^=kotae;
  }
  for(int i=0;i<n;i++){
    if(i!=n-1)cout<<a[i]<<" ";
    else cout<<a[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 4036
//naru-hodo
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<time.h>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#define ff first
#define ss second
#define ll long long 
#define ull unsigned long long
#define loop(i,x,n) for(int i=x; i<=n; i++)
#define rloop(i,x,n) for(int i=x; i>=n; i--)
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    loop(i,0,n-1) cin>>a[i]>>b[i]>>c[i];
    rloop(i,n-2,0){
        a[i] += max(b[i+1],c[i+1]);
        b[i] += max(a[i+1],c[i+1]);
        c[i] += max(a[i+1],b[i+1]);
    }
    cout<<max(a[0],max(b[0],c[0]));
    return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0 or 0 in d[1:]:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 39152
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        ao: [i64;n]
    }

    let mut a = ao;
    a.sort();
    let mut plus = n-1;
    for i in 1..n-1 {
        if a[i] >=0 {
            plus = std::cmp::min(plus, i);
        }
    }
    let mut ret = vec![];
    let mut acc = a[0];
    for i in plus+1..n {
        ret.push((acc, a[i]));
        acc = acc - a[i];
    }
    let mut acc2 = a[plus];
    for i in 1..plus {
        ret.push((acc2, a[i]));
        acc2 = acc2 - a[i];
    }
    ret.push((acc2, acc));

    println!("{}", acc2 - acc);
    for p in ret {
        println!("{} {}", p.0, p.1);
    }
}


Measured memory_bytes: 10108
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let N = Number(input[0])
	let K = Number(input[1])
	let X = Number(input[2])
	let Y = Number(input[3])
	let out = 0
	for (let i = 1 ; i <= N ; i++) {
		if(K + 1 <= i ) {
			out += Y
		} else {
			out += X
		}
	}
	console.log(out)
}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
// 2011/02/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int p1 = 0;
		int p2 = 0;
		int p3 = 0;
		int p4 = 0;
		int t1 = 60*60*4;
		int t2 = 60*60*4;
		int t3 = -1;
		int t4 = -1;

		for(int i=0; i<n; i++){
			int c1, m1, s1, m2, s2, m3, s3, m4, s4;
			cin >> c1 >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
			int t = (m1+m2+m3+m4)*60+s1+s2+s3+s4;

			if(t<t1){
				p2 = p1;
				t2 = t1;
				p1 = c1;
				t1 = t;
			}
			else if(t<t2){
				p2 = c1;
				t2 = t;
			}

			if(t>t4){
				p3 = p4;
				t3 = t4;
				p4 = c1;
				t4 = t;
			}
			else if(t>t3){
				p3 = c1;
				t3 = t;
			}
		}

		cout << p1 << endl;
		cout << p2 << endl;
		cout << p3 << endl;
	}

	return 0;
}

Measured memory_bytes: 864
import sys
def input(): return sys.stdin.readline().rstrip()
class mod_comb3:
    def __init__(self,mod=10**9+7,n_max=1):
        self.mod,self.n_max=mod,n_max
        self.fact,self.inv,self.factinv=[1,1],[0,1],[1,1]
        if 1<n_max:setup_table(n_max)
    def comb(self,n,r):
        if r<0 or n<r:return 0
        if self.n_max<n:self.setup_table(n)
        return self.fact[n]*(self.factinv[r]*self.factinv[n-r]%self.mod)%self.mod
    def setup_table(self,t):
        for i in range(self.n_max+1,t+1):
            self.fact.append(self.fact[-1]*i%self.mod)
            self.inv.append(-self.inv[self.mod%i]*(self.mod//i)%self.mod)
            self.factinv.append(self.factinv[-1]*self.inv[-1]%self.mod)
        self.n_max=t

def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    com=mod_comb3()
    A.sort()
    mod=10**9+7
    max_a,min_a=0,0
    for i in range(n):
        max_a=(max_a+A[i]*com.comb(i,k-1))%mod
        min_a=(min_a+A[i]*com.comb(n-i-1,k-1))%mod
    print((max_a-min_a)%mod)

if __name__=='__main__':
    main()

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

#define ll long long 
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()

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

	ll n, m, k;
	cin >> n >> m >> k;
	ll a[n], b[m];
	for(ll i = 0; i < n; i++)
		cin >> a[i];
	for(ll j = 0; j < m; j++) 
		cin >> b[j];
	for(ll i = 1; i < n; i++)
		a[i] += a[i - 1];
	for(ll i = 1; i < m; i++) 
		b[i] += b[i - 1];

	ll ans = 0;
	for(ll i = 0; i < n; i++) {
		if(a[i] > k) break;
		auto it = upper_bound(b, b + m, k - a[i]);
		--it;
		ans = max((ll)(it - b) + i + 2, ans);
	}
	for(ll i = 0; i < m; i++) {
		if(b[i] > k) break;
		auto it = upper_bound(a, a + n, k - b[i]);
		--it;
		ans = max((ll)(it - a) + i + 2, ans);
	}
	cout << ans << "\n";
	return 0;
}


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

int main() {
	int t; cin >> t;
	rep(i, t) {
		int MaxU = 0, MaxD = 0;
		int n; cin >> n;
		int back;
		rep(j, n) {
			int h; cin >> h;
			if (j) {
				if (h > back)MaxU = max(MaxU, h - back);
				else MaxD = max(MaxD, back - h);
			}
			back = h;
		}
		cout << MaxU << ' ' << MaxD << endl;
	}
}

Measured memory_bytes: 2992
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x) {return power(x, MOD - 2);}
const int MAXN = 1e5 + 5;
//const bool is_in = container.find(element) != container.end();
int main()
{
	zapp;
	ll x;
	cin >> x;
	ll dep = 100;
	ll years = 0;
	while (dep < x)
	{
		dep = dep + dep / 100;
		years++;
	}
	cout << years;

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll n;
	cin>>n;
	vector<ll> a(n);
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]==i+1)
		{
			ans++;
			if(i+1!=n)
			{
				if(a[i+1]==i+2)
					i++;
			}
		}
	}
	cout<<ans;
	return;
}
int main()
{
	fast;
	int q;
	q=1;
	// cin>>q;
	while(q--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3956
S = input()
P =2019
ans = 0

count = [0] * P
count[0] = 1
u = 0
for i, s in enumerate(reversed(S)):
    u = (int(s) * pow(10, i, P) + u) % P
    ans += count[u]
    count[u] += 1
print(ans)


Measured memory_bytes: 73956
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if a > b:
    oni = a + (-1*v) * t
    nige = b + (-1*w) * t
    if oni <= nige:
        print("YES")
    else:
        print("NO")
else:
    oni = a + v*t
    nige = b + w * t
    if oni >= nige:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9116
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


import math
n,k = map(int, input().split())
a = list(map(int, input().split()))
a1 = [item for item in a if item>0]
a2 = [item for item in a if item<0]
n1 = sum(item>0 for item in a)
n2 = sum(item<0 for item in a)
nz = sum(item==0 for item in a)
a1.sort(reverse=True)
a2.sort()
c1 = [math.log10(item) for item in a1]
c2 = [math.log10(-item) for item in a2]
def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l
cc1 = cumsum(c1)
cc2 = cumsum(c2)
if n1+n2<k:
    ans = 0
else:
    best = -10**12
    ind = None
    for i in range(n2//2+1):
        # マイナスを偶数個
        if 2*i>k:
            continue
        if 2*i+n1<k:
            continue
        if k-2*i<=n1:
            val = cc2[2*i] + cc1[k-2*i]
            if val>best:
                ind = i
                best = val
    M = 10**9+7
    if ind is None:
        if nz>0:
            ans = 0
        else:
            # マイナスだけ
            ans = 1
            if k<=n2:
                for i in range(k):
                    ans *= a2[-(i+1)]
                    ans %= M
            else:
                for i in range(n2):
                    ans *= a2[i]
                    ans %= M
                for i in range(n1):
                    ans *= a1[i]
                    ans %= M
    else:
        ans = 1
        for i in range(2*ind):
            ans *= a2[i]
            ans %= M
        for i in range(k-2*ind):
            ans *= a1[i]
            ans %= M
print(ans)

Measured memory_bytes: 108620
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[1000010],b[1000050];
char d[200000], c[2005][1000]={"dream","dreamer","erase","eraser","dreamerase","dreameraser"};
int main()
{
    int i,n,m,j,k=0,l;
    scanf("%s",d);
    for(i=0;i<strlen(d);i++)
    {
        if(strncmp(d+i,c[5],11)==0)
        {
            i+=10;
            k+=11;
        }else if(strncmp(d+i,c[4],10)==0)
        {
            i+=9;
            k+=10;
        }else if(strncmp(d+i,c[3],6)==0)
        {
            i+=5;
            k+=6;
        }else if(strncmp(d+i,c[2],5)==0)
        {
            i+=4;
            k+=5;
        }else if(strncmp(d+i,c[1],7)==0)
        {
            i+=6;
            k+=7;
        }else if(strncmp(d+i,c[0],5)==0)
        {
            i+=4;
            k+=5;
        }
    }
    if(strlen(d)==k)
    {
        printf("YES\n");
    }else
    {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 2432
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
A = Counter(a).most_common()
d = [0] * (10**5+10)
for i in range(len(A)):
    d[A[i][0]] = A[i][1]

B = []
C = []
for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(q):
    d[C[i]] += d[B[i]]
    cnt = d[B[i]]
    ans += (C[i]-B[i])*cnt
    print(ans)
    d[B[i]] = 0

Measured memory_bytes: 27696
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
total = 0

for k,i in enumerate(a):
  total += b[i-1]
  if k == n - 1:
    continue
  elif a[k]+1 == a[k+1]:
    total += c[i-1]
    
    
print(total)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    //final List<Integer> list = new ArrayList<>();
    //final List<Integer> list2 = new ArrayList<>();
    //final List<Long> list3 = new ArrayList<>();

    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();
    int count = 0;
    int high = 0;
    if(a >= b){
        high = a;
    }else{
        high = b;
    }

    for(int i = high; i > 0 ; i--){
        if(a % i == 0 && b % i == 0){
            count++;
        }
        if(k == count){
            System.out.println(i);
            System.exit(0);
        }
    }

    




    







}
}

Measured memory_bytes: 35776
fun main(args: Array<String>) {
    val kn = readLine()!!.split(" ")
    val K = kn[0].toInt()
    val N = kn[1].toInt()

    val AI = readLine()!!.split(" ")

    //家間の距離のリストを作成
    var arr: Array<Int> = Array(N) { 0 }
    for (i in AI.indices) {
        if (i == 0) {
            arr[i] = K - AI[N - 1].toInt() + AI[i].toInt()
        } else {
            arr[i] = AI[i].toInt() - AI[i - 1].toInt()
        }
    }

    arr.sortBy { it * -1 }
    println(K - arr[0])
}


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

using namespace std;

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if (a == b && b == c) cout << 1 << endl;
  else if (a == b) cout << 2 << endl;
  else if (b == c) cout << 2 << endl;
  else if (a == c) cout << 2 << endl;
  else cout << 3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a, b;
    cin >> a >> b;
    cout << max(a-2*b, 0ll) << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

def BFS(G, s):
    visited = {s: None}
    unvisited = collections.deque([s])
    while unvisited:
        u = unvisited.popleft()
        for v in G[u - 1]:
            if not(v in visited):
                unvisited.append(v)
                visited[v] = u
    
    return visited

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

g = [set([]) for _ in range(n)]

for abi in ab:
    g[abi[0] - 1].add(abi[1])
    g[abi[1] - 1].add(abi[0])

ans = [0] * (n - 1)

for k, v in BFS(g, 1).items():
    if k == 1:
        continue
    else:
        ans[k - 2] = v

print("Yes")
for num in ans:
    print(num)

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

int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  int i = 1;

  for (int j = 0; j<N; j++) {
    if (i <= K){
      i *= 2;
    }
    else if (i > K){
      i += K;
    }
  }
  cout << i << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> present(N);
  for (int i = 0; i < N; i++) {
    cin >> present.at(i);
  }
  sort(present.begin(), present.end());
  int count = 1;
  for (int i = 0; i < N - 1; i++) {
    if (present.at(i) != present.at(i+1)){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 9600
from collections import defaultdict


n = int(input())
div = defaultdict(int)

for i in range(2, n+1):
    num = i
    while num != 1:
        for d in range(2, num+1):
            if num % d == 0:
                num //= d
                div[d] += 1
                break
            else:
                continue

values = list(div.values())
over2 = 0
over4 = 0
over14 = 0
over24 = 0
over74 = 0
for value in values:
    if value >= 2:
        over2 += 1
    if value >= 4:
        over4 += 1
    if value >= 14:
        over14 += 1
    if value >= 24:
        over24 += 1
    if value >= 74:
        over74 += 1

ans1 = max(0, over4 * (over4-1) * (over2-2) // 2)
ans2 = max(0, over14 * (over4-1))
ans3 = max(0, over24 * (over2-1))
ans4 = over74
res = sum([ans1, ans2, ans3, ans4])
print(res)


Measured memory_bytes: 38512
#include<iostream>
using namespace std;
int main(){
  int b,s,e,tmp;
  cin >> b;
  while(b!=0){
    tmp=0;
    s=1;
    e=1;
    while(true){
      if(tmp>b){
        tmp-=s;
        s++;
      }else if(tmp<b){
        tmp += e;
        e++;
      }else{
        cout << s <<" " <<e-s<<endl;
        break;
      }
    }
    cin >> b;
  }
}



Measured memory_bytes: 3096
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var H, W, M, h, w int
  var ok bool
  NextInt(&H, &W, &M)
  X := make([]int, H)
  Y := make([]int, W)
  A := make([][]int, M)
  B := make(map[int]map[int]struct{})
  for i := range A {
    NextInt(&h, &w)
    h--; w--
    X[h]++; Y[w]++
    A[i] = []int{h, w}
    if _, ok = B[h]; !ok { B[h] = make(map[int]struct{}) }
    B[h][w] = struct{}{}
  }
  E := 0
  for _, a := range A { E = MaxInt(X[a[0]] + Y[a[1]] - 1, E) }
  mx := MaxInt(X...)
  MX := make([]int, 0)
  for i, x := range X { if x == mx { MX = append(MX, i) } }
  my := MaxInt(Y...)
  MY := make([]int, 0)
  for i, y := range Y { if y == my { MY = append(MY, i) } }
  L: 
    for _, x := range MX {
      for _, y := range MY {
        if _, ok = B[x][y]; ok { continue }
        E = mx + my
        break L
      }
    }
  Write(E)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]int, 0)
    return
  }
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  if len(L) == 1 && L[0] == "" {
    (*A) = make([]float64, 0)
    return
  }
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  fmt.Fprintln(writer, B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

Measured memory_bytes: 119456
#include<stdio.h>

int max(int a, int b){
  if(a > b) return a;
  else return b;
}

  int n,W;
  int weight[110], value[110];
  int dp[110][10010];

int main(){

  scanf("%d %d",&n,&W);
  for(int i = 0; i < n; ++i){
    scanf("%d %d",&value[i], &weight[i]);
  }

  for(int w = 0; w <= W; ++w){
    dp[0][w] = 0;
  }

  for(int i = 0; i < n; ++i){
    for(int w = 0; w <= W; ++w){
      if( w >= weight[i] ) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i] , dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }

  printf("%d\n",dp[n][W]);

  return 0;
}



Measured memory_bytes: 5724
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=200005;

struct SegTree{
  //SegTree
  vector<P> dat;
  int N;
  explicit SegTree(int n){
    N=1; while(N<n) N*=2;
    dat.resize(2*N);
    rep(i,2*N-1)  dat[i]=P(INF,-1);
  }
  void init(const vector<int> &v){
    rep(i,v.size()) dat[N-1+i]=P(v[i],i);
    for(int i=N-2;i>=0;i--) dat[i]=min(dat[2*i+1],dat[2*i+2]);
  }
  void update(int i,int x){
    i+=N-1;
    dat[i]=P(x,i-N+1);
    while(i>0){
      i=(i-1)/2;
      dat[i]=min(dat[2*i+1],dat[2*i+2]);
    }
    return;
  }
  P rmq(int a,int b){
    return rmq(a,b,0,0,N);
  }
  P rmq(int a,int b,int k,int l,int r){
    //ノードkに対応する区間[l,r)を与える
    //query(a,b,0,0,n)で[a,b)のminを与える
    if(r<=a || b<=l) return P(INF,-1);
    else if(a<=l && r<=b) return dat[k];
    else{
      P lmin=rmq(a,b,2*k+1,l,(l+r)/2);
      P rmin=rmq(a,b,2*k+2,(l+r)/2,r);
      return min(lmin,rmin);
    }
  }
};

SegTree even(MAX_N),odd(MAX_N);
int N;
using T = tuple<P,P,P,P>;

int cnt=0;

T calc(int l,int r){
  P a,b,c;
  int val1,val2,x1,x2;
  tie(val1,x1) = (l%2==0 ? even:odd).rmq(l,r);
  tie(val2,x2) = (l%2==0 ? odd:even).rmq(x1+1,r);
  return T(P(val1,val2),P(l,x1),P(x1+1,x2),P(x2+1,r));
}

void solve(){
  vector<int> ans;
  priority_queue<T,vector<T>,greater<T>> que;
  que.push(calc(0,N));
  while(!que.empty()){
    P val,a,b,c;
    tie(val,a,b,c) = que.top();
    que.pop();
    ans.pb(val.first);
    ans.pb(val.second);
    if(a.first<a.second) que.push(calc(a.first,a.second)); 
    if(b.first<b.second) que.push(calc(b.first,b.second)); 
    if(c.first<c.second) que.push(calc(c.first,c.second)); 
    
    // if(cnt++>100) exit(1);
    // else cout << "["<<a.second << "," << a.second << "), [" << b.first << "," << b.second <<
    //       "), [" << c.first << "," << c.second << ")" <<  endl;
  }
  rep(i,N) printf("%d%c",ans[i],i==N-1 ? '\n':' ');
}

int main(){
  cin >> N ;
  rep(i,N){
    int a;
    scanf("%d",&a);
    (i%2==0 ? even:odd).update(i,a);
    (i%2==0 ? odd:even).update(i,INF);
  }
  solve();
  return 0;
}

Measured memory_bytes: 12784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string a,b;
    cin>>a>>b;
    string ans="D";
    if(a==b)ans="H";
    cout << ans << endl;
    return 0;
}

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	n=int(io())
	l=list(map(int, io().split()))
	di={}
	for i in l:
		try:
			di[i] = di[i]+1
		except:
			di[i] = 1
	
	c=0
	for k in di.keys():
		c += di[k] if di[k] < k else di[k] - k
	
	return c

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 18164
#include<stdio.h>

int main(){
		int n,i,j;
		long long x,a[100];
		scanf("%d%lld",&n,&x);
		for(i=0;i<n;i++)scanf("%lld",&a[i]);
		for(i=0;i<n;i++){
				for(j=0;j<n;j++){
						if(a[i]<a[j]){
								long long tmp=a[i];
								a[i]=a[j];
								a[j]=tmp;
						}
				}
		}
		for(i=0;i<n;i++){
		//		printf("%lld\n",a[i]);
				x-=a[i];
				if(x<0)break;
		}
		if(i==n&&x>0)i--;
		printf("%d\n",i);
		return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    long double a; long double b;
    cin >> a >> b;
    cout << (ll)(a*b + 0.001) << endl;
    return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,r;
    cin >> n >> r;
    if(n < 10){
        cout << r+100*(10-n) << endl;
    }
    else 
        cout << r << 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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  bool flag = true;
  REP(x,100000){
    int pr = double(x) * 1.08;
    if(pr==n){
      cout << x << endl;
      flag = false;
      break;
    }
  }
  if(flag) cout << ":(\n";
  return 0;
}


Measured memory_bytes: 3564
N = gets.to_i
A, B, C = 3.times.map { gets.chomp.chars }

a = A.zip(B.zip(C)).map do |a, (b, c)|
  if a == b && b == c
    0
  elsif a == b || b == c || c == a
    1
  else
    2
  end
end

p a.inject(:+)


Measured memory_bytes: 1788
h,w = map(int,input().split())
n = int(input())
ls = list(map(int,input().split()))
di = []
def split_list(l, n):
    for idx in range(0, len(l), n):
        yield l[idx:idx + n]
for i in range(n):
    for j in range(ls[i]): 
        di.append(i+1)
new = list(split_list(di, w))
for j in range(len(new)):
    if j % 2 == 0:
        new[j].sort(reverse=True)
for k in range(len(new)):
    print(*new[k])


Measured memory_bytes: 3956
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (auto& x : A) cin >> x;

  map<int, int> m;
  for (int a : A) {
    ++m[a];
  }

  LL sum = 0;
  for (auto p : m) {
    LL n = p.second;
    if (n < 2) continue;
    sum += n*(n-1)/2;
  }

  for (int a : A) {
    LL n = m[a];
    cout << sum - (n-1) << endl;
  }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll k, a, b;
    ll n = 1;
    ll tmp;
    cin >> k >> a >> b;
    tmp = k;
    if (n < a) {
        tmp -= a - n;
        n = a;
    }
    if (tmp > 0) {
        n += (b - a) * (tmp / 2);
    }
    if (tmp % 2) n++;
    ll ans = max(n, k + 1);
    cout << ans << endl;
    
    return 0;
}



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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=2e5+10;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

i32 N,Ans;
ar A,B;

inline double mid(i32 arr[]){
    if(N&1) return arr[N+1>>1];
    return (arr[N>>1]+arr[(N>>1)+1])/2.0;
}

int main(){
    N=read();
    f(i,1,I,N) A[i]=read(),B[i]=read();
    sort(A+1,A+1+N);
    sort(B+1,B+1+N);
    if(N&1)
        Ans=mid(B)-mid(A)+1;
    else
        Ans=2*(mid(B)-mid(A))+1;
    print(Ans);
    output();
    return 0;
}

Measured memory_bytes: 5160
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import System.IO.Unsafe

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = unsafePerformIO $ VUM.read v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = unsafePerformIO $ VUM.write v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = unsafePerformIO $ VUM.swap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = unsafePerformIO $ VU.freeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = unsafePerformIO $ VU.thaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> foldl' (\acc p -> uwrite p n acc) elems path `seq` n
    n          -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF (UnionFind (_, sizes)) i = uread i sizes

unionUF :: UnionFind -> Int -> Int -> (UnionFind, Int)
unionUF uf@(UnionFind (elems, sizes)) i j =
  let pi = findUF uf i
      pj = findUF uf j
      si = sizeUF uf pi
      sj = sizeUF uf pj
  in  if pi == pj
        then (uf, 0)
        else
          let sij = si + sj
          in  ( UnionFind
                ( if si < sj then uwrite pi pj elems else uwrite pj pi elems
                , if si < sj
                  then uwrite pi 0 (uwrite pj sij sizes)
                  else uwrite pj 0 (uwrite pi sij sizes)
                )
              , si * sj
              )

comb2 k = k * (k - 1) `div` 2

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = unsafePerformIO $ VU.freeze $ (\(_, _, acc) -> acc) $ VU.foldr
  go
  (group, 0, unsafePerformIO $ VUM.replicate m 0)
  abs
 where
  go (a, b) (uf, k, acc) =
    let (uf'@(UnionFind (!elems, !sizes)), d) = unionUF uf a b
    in  let prev = if k == 0 then 0 else uread (k - 1) acc
        in  (uf', k + 1, uwrite k (prev + d) acc)

  nC2 = comb2 n

  group :: UnionFind
  group =
    UnionFind (uthaw $ VU.enumFromN 0 n, unsafePerformIO $ VUM.replicate n 1)

main = do
  let readInt     = fmap (second B.tail) . B.readInt
  let readJustInt = fst . (\(Just x) -> x) . B.readInt

  nm  <- VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    (nm VU.! 1)
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  let solutions = solve (nm VU.! 0) (nm VU.! 1) abs
  let nC2       = comb2 $ nm VU.! 0

  mapM_ (print . (nC2 -) . (solutions VU.!)) [nm VU.! 1 - 2, nm VU.! 1 - 3 .. 0]
  print nC2


Measured memory_bytes: 43388
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    n = int(input())
    if n >= 400 and n <= 599:
        print(8)
    if n >= 600 and n <= 799:
        print(7)
    if n >= 800 and n <= 999:
        print(6)
    if n >= 1000 and n <= 1199:
        print(5)
    if n >= 1200 and n <= 1399:
        print(4)
    if n >= 1400 and n <= 1599:
        print(3)
    if n >= 1600 and n <= 1799:
        print(2)
    if n >= 1800 and n <= 1999:
        print(1)


if __name__ == '__main__':
    main()


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

int main(void){
  int N;
  cin>>N;
  int sum=0;
  int j=1;
  for(int i=1;i<=N;i++){
    sum+=800;
    if(i==(j*15)){
      sum-=200;
      j++;
    }
  }
  cout<<sum<<endl;
}

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

bool vector_include(vector<int> arr, int a, int b) {
  return find(arr.begin(), arr.end(), a) != arr.end() && find(arr.begin(), arr.end(), b) != arr.end();
}

int main() {
  vector<int> a{1, 3, 5, 7, 8, 10, 12};
  vector<int> b{4, 6, 9, 11};
  vector<int> c{2};
  int x, y ;
  cin >> x >> y;

  if (vector_include(a, x, y) || vector_include(b, x, y) || vector_include(c, x, y)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a[3][3], b[3][3] = {};
  int n, x;
 
  for(int i = 0; i < 3; i++)
  {
    for(int j = 0; j < 3; j++)
	{
      scanf("%d",&a[i][j]);
    }
  }
  
  scanf("%d",&n);
  for(int k = 0; k < n; k++)
  {
    scanf("%d",&x);
    for(int i = 0; i < 3; i++)
	{
      for(int j = 0; j < 3; j++)
	  {
        if(a[i][j] == x)
        {
        	b[i][j] = 1;
		}
      }
    }
  }
 
  if(b[0][0]+b[1][1]+b[2][2] == 3 || b[0][2]+b[1][1]+b[2][0] == 3)
  {
      puts("Yes");
      return 0;
    }
 
  for(int i = 0; i < 3; i++)
  {
      if(b[i][0]+b[i][1]+b[i][2] == 3 || b[0][i]+b[1][i]+b[2][i] == 3)
	  {
        puts("Yes");
        return 0;
      }
    }
 
    puts("No");
 
    return 0;
}

Measured memory_bytes: 1644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

long com[100][100];

long comb(int n,int r){
    if(com[n][r]!=0){
        return com[n][r];
    }
    if(n==0||r==0||n<=r){
        com[n][r]=1;
        return 1;
    }
    com[n][r]=comb(n-1,r-1)+comb(n-1,r);
    return com[n][r];
}

int main(){
    int N;
    int a,b;
    cin >> N;
    cin >> a;
    cin >> b;
    vector<long> v(N);
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());

    long sum=0;
    for(int i=N-1;i>=N-a;i--){
        sum+=v[i];
    }

    cout << std::fixed << std::setprecision(10);
    cout << (1.0*sum/a) << endl;

    auto low=std::lower_bound(v.begin(),v.end(),v[N-a]);
    auto upp=std::upper_bound(low,v.end(),v[N-a]);
    int eq_size=upp-low;
    a-=v.end()-upp;
    b-=v.end()-upp;

    long ans=0;
    if(v[N-1]==v[N-a-1]){
        for(int i=0;a+i<=b&&v[N-1]==v[N-a-i];i++){
            ans+=comb(eq_size,a+i);
        }
    }
    else{
        ans=comb(eq_size,a);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#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;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s,t;
    cin>>s>>t;
    t=t.substr(0,t.length()-1);
    if(s==t)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>

using namespace std;
int main()
{
  int k, a, b;
  cin >> k >> a >> b;

  for (int i = k; i <= b; i += k)
  {
    if (a <= i && i <= b)
    {
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n, W;
	cin >> n >> W;
	map <int, vector<int>> mp;
	for (int i = 0; i < n; i++) {
		int w, v;
		cin >> w >> v;
		mp[w].push_back(v);
	}
	vector <int> v[5];
	vector <ll> wei(5);
	int x = 0;
	for (auto g : mp) {
		x++;
		wei[x] = g.ff;
		v[x] = g.ss;
	}
	for (int i = 1; i <= 4; i++) {
		v[i].push_back(0);
		sort(all(v[i]));
		reverse(v[i].begin() + 1, v[i].end());
		for (int j = 1; j < (int) v[i].size(); j++) {
			v[i][j] += v[i][j - 1];
		}
	}
	int ans = 0;
	for (int i = 0; i < (int) v[1].size(); i++) {
		for (int j = 0; j < (int) v[2].size(); j++) {
			for (int k = 0; k < (int) v[3].size(); k++) {
				int val = v[1][i] + v[2][j] + v[3][k];
				ll curW = i * wei[1] + j * wei[2] + k * wei[3];
				if (curW > W)
					continue;
				if (wei[4] == 0) {
					ans = max(ans, val);
					continue;
				}
				int ex = (W - curW) / wei[4];
				val = val + v[4][min(ex, (int) v[4].size() - 1)];
				ans = max(ans, val);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	if(s == "Sunny") cout << "Cloudy" << endl;
	else if(s == "Cloudy") cout << "Rainy" <<endl;
	else cout << "Sunny" << endl;
}

Measured memory_bytes: 256
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    FAST;
    ll n,t,i,d,d2;
    cin>>t;
    d=0;
    d2=0;
    for(i=0; i<t; i++)
    {
        cin>>n;
        if(n%4==0)
        {
            d++;
        }
        if(n%4==2)
        {
            d2++;
        }
    }
    ll s=t/2;
    if(d>=s)
    {
        cout<<"Yes"<<endl;
    }
    else if((d2/2+d)>=s)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256