akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m,s,t = LI()
    s -= 1
    t -= 1
    v = [[] for i in range(n)]
    v2 = [[] for i in range(n)]
    for i in range(m):
        a,b,c,d = LI()
        a -= 1
        b -= 1
        v[a].append((b,c))
        v[b].append((a,c))
        v2[a].append((b,d))
        v2[b].append((a,d))
    d = [float("inf")]*n
    d[s] = 0
    q = [(0,s)]
    while q:
        dx,x = heappop(q)
        for y,c in v[x]:
            nd = dx+c
            if nd < d[y]:
                d[y] = nd
                heappush(q,(nd,y))
    d2 = [float("inf")]*n
    d2[t] = 0
    q = [(0,t)]
    while q:
        dx,x = heappop(q)
        for y,c in v2[x]:
            nd = dx+c
            if nd < d2[y]:
                d2[y] = nd
                heappush(q,(nd,y))
    ans = [10**15-(d[i]+d2[i]) for i in range(n)]
    for i in range(n-1)[::-1]:
        if ans[i+1] > ans[i]:
            ans[i] = ans[i+1]
    for i in ans:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 117308
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;
ll a , b  , cnt , n , m , ans , sum;
int main(){
    cin >> n;
    ans = n / 500;
    n -= ans * 500;
    ans *= 1000;
    cout << ans + n / 5 * 5;
}
/// ab#c ad#c
/// ab## c#d#


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,j,k) for(int i=j;i<k;i++)
#define rep(i,j) reps(i,0,j)
char chenge[] = {'m','c','x','i'};
char _chenge[] = {'i','x','c','m'};
int c[] = {1000,100,10,1};
	
int getNUM(string s){
	int len = s.size();
	char prev = '$';
	int ret = 0;
	rep(i,len){
		bool f = false;
		rep(j,4){
			if(s[i] == chenge[j]){
				if(prev == '$'){
					ret += c[j];
					prev = '$';
					f = true;
				}
				else{
					ret += (prev-'0')*c[j];
					prev = '$';
					f = true;
				}
			}
		}
		if(!f){
			prev = s[i];
		}
	}
	return ret;
}
string decode(int a){
	string res = "";
	int index = 0;
	while(a){
		int t = a%10;
		if(t == 0){
			;
		}
		else if(t == 1){
			res += _chenge[index];
		}
		else{
			res += _chenge[index];
			res += (t+'0');
		}
		a/=10;
		index++;
	}
	reverse(res.begin(),res.end());
	return res;
}
int main(){
	int N;
	cin >> N;
	rep(i,N){
		string a,b;
		int _a = 0;
		int _b = 0;
		cin >> a >> b;
		_a = getNUM(a);
		_b = getNUM(b);
		//cout << _a << " " << _b << "\n";
		int res = _a+_b;
		cout << decode(res) << "\n";
	}
	return 0;
}

Measured memory_bytes: 1192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {

	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens()) {
				String cad = br.readLine();
				if (cad == null)
					return null;
				tk=new StringTokenizer(cad);
			}
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public long nextLong() throws NumberFormatException, IOException{
			return Long.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}
	
	public static void main(String args[]) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		int N = sc.nextInt();
		int c_t = 0;
		int old_x = 0;
		int old_y = 0;
		for(int i = 0; i < N; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();
			int diff = Math.abs(x - old_x) + Math.abs(y - old_y);
			int time_diff = t - c_t;
			if (time_diff < diff) {
				System.out.println("No");
				return;
			}
			else {
				int offset = time_diff - diff;
				if (offset % 2 != 0) {
					System.out.println("No");
					return;
				}
			}
			old_x = x;
			old_y = y;
			c_t = t;
		}
		System.out.println("Yes");
	}

}


Measured memory_bytes: 42240
#include<stdio.h>

#define MAX 1000

int top;
int S[MAX];

int initialize(){
       return top=0;
       }

int isempty(){
       return top==0;
       }

int isfull(){
       return top>=MAX-1;
       }

void push(int n){
       if (isfull()){return;}

       top++;
       S[top]=n;
       }

int pop(){
       if (isempty()){return;}

       top--;
       return S[top+1];
       }

int main(){
       int i,j,x,y;
       char op[MAX];
       initialize();
       while(scanf("%s",&op) != EOF){
                   if(op[0]=='+'){
                               x=pop();
                               y=pop();
                               push(y+x);
                               }
                   else if(op[0]=='-'){
                               x=pop();
                               y=pop();
                               push(y-x);
                               }
                   else if(op[0]=='*'){
                               x=pop();
                               y=pop();
                               push(y*x);
                               }
                   else {push(atoi(op));}
                   }
          printf("%d\n",pop());
          return 0;
          }




Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num[10005];

int main(){
    ll n,k;scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++) scanf("%lld",&num[i]);
    ll sum=0;
    sort(num,num+n);
    for(ll i=0;i<k;i++) sum+=num[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3668
from bisect import bisect_right
n = int(input())
a = [int(x) for x in input().split()]

cum = [0]
for x in a:
  cum.append(cum[-1]+x)

ans = 10**30
for z in range(4):
  for i in range(2,n-1):
    b = cum[bisect_right(cum, cum[i]//2)-1+(z&1)]
    c = cum[i]-b
    d = cum[bisect_right(cum, (cum[n]-cum[i])//2+cum[i])-1+(z>>1&1)] - cum[i]
    e = cum[n] - (b+c+d)
    ans = min(ans, max(b,c,d,e) - min(b,c,d,e))
  
print(ans)
  
  

Measured memory_bytes: 112304
class Node:
    elm = None
    nxt = None

    def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt


class MyQueue:
    head = tail = None
    size = 0

    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

    def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

    def is_empty(self):
        return self.size == 0

n, q = map(int, input().split())

s = MyQueue()
result = list()
process = 0

for i in range(n):
    name, time = map(str, input().split())
    s.enqueue([name, int(time)])

while not s.is_empty():

    e = s.dequeue()
    diff = e[1] - q
    if diff <= 0:
        process += e[1]
        result.append([e[0], process])
    else:
        process += q
        s.enqueue([e[0], diff])
for i in result:
    print(i[0], i[1])

Measured memory_bytes: 25832
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  string s;
  cin >> s;

  std::vector<string> weekday = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  REP(i,7){
    if(weekday[i] == s){
      cout << 7-i << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 764
N = int(input())
L = list(map(int, input().split()))

counter = 0

for i in range(1,N-1):
	if L[i] > L[i-1] and L[i] < L[i+1]:
		counter += 1
	elif L[i] < L[i-1] and L[i] > L[i+1]:
		counter += 1

print(counter)

Measured memory_bytes: 3064
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int i, j, n, flag=0;
	scanf("%d", &n);
	int d[n];
	loop(i, 1, 10){
		loop(j, i, 10){
			if(n == i*j) flag =1;
		}
	}
	if(flag == 1) puts("Yes");
	else puts("No");
	return 0;
}

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

int main(){
	int a,b;
	cin >> a >> b;
	cout << 6-a-b << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const ll INF = (ll)(1e18);

int main(void){
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  REP(i, H) cin >> S[i];
  ll ans = INF;
  REP(div, 1<<(H-1)){
    ll g = 0;
    vector<ll> id(H);
    REP(i, H){
      id[i] = g;
      if(div>>i&1) g++;
    }
    g++;
    vector<vector<ll>> c(g, vector<ll>(W, 0));
    REP(i, H) REP(j, W) c[id[i]][j] += S[i][j]-'0';
    ll cnt = __builtin_popcount(div);
    vector<ll> now(g, 0);
    auto add = [&](ll j){
      REP(i, g) now[i] += c[i][j];
      REP(i, g) if(now[i] > K) return false;
      return true;
    };
    REP(j, W){
      if(!add(j)){
        cnt++;
        now = vector<ll>(g, 0);
        if(!add(j)){
          cnt = INF;
          break;
        }
      }
    }
    chmin(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

const MOD:usize = 1000000007;

fn main() {
    scan!(n, k; usize);

    let mut min = ((k-1) * k) / 2;
    let mut max:usize = (0..k).map(|i| n - i).sum();

    let mut res = 1;
    for i in k..=n {
        res = (res + max - min + 1) % MOD;
        min += i;
        max += n - i;
    }

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


Measured memory_bytes: 2168
code = input()
read_code = list(code)
count = 0
count_end = 0

for i in range(0, len(read_code)):
    code_count = False
    if read_code[i] == "A" or read_code[i] == "C" or read_code[i] == "G" or read_code[i] == "T":
        count += 1
        if(count >= count_end):
            count_end = count
    else:
        count = 0

print(count_end)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int n;
double mp[8][2];
double tot = 0;

void ave_len(int _now_num, vector<int> mati, vector<int> nokori) {
	if (_now_num == n) {
		for (int i = 1; i < n; i++) {
			tot += sqrt((mp[mati[i]][0] - mp[mati[i - 1]][0]) * (mp[mati[i]][0] - mp[mati[i - 1]][0]) + (mp[mati[i]][1] - mp[mati[i - 1]][1]) * (mp[mati[i]][1] - mp[mati[i - 1]][1]));
		}
		return;
	}

	for (int i = 0; i < n - _now_num; i++) {
		mati[_now_num] = nokori[i];
		vector<int> zan(n - _now_num);
		for (int j = 0; j < n - _now_num; j++) {
			zan[j] = nokori[j];
		}
		zan.erase(zan.begin() + i);
		ave_len(_now_num + 1, mati, zan);
	}
}

double kaijou(int j) {
	int num = 1;
	for (int i = 1; i <= j; i++) {
		num *= i;
	}

	return num;
}

int main() {
	cin >> n;

	vector<int> map(n);
	vector<int> number(n);

	for (int i = 0; i < n; i++) {
		number[i] = i;
	}

	for (int i = 0; i < n; i++)
		cin >> mp[i][0] >> mp[i][1];

	ave_len(0, map, number);

	double ans;
	double kai;
	kai = kaijou(n);
	ans = tot / kai;
	printf("%f", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};

 
 

int main(){
    int n;cin >> n;
    map<string,int> ma;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        string s;cin >> s;
        cin >> x[i];
        ma[s] = i;
    }
    string s;cin >> s;
    int ans = 0;
    for (int i = ma[s] + 1; i < n; i++) {
        ans += x[i];
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

const ll MOD = 1e9 + 7;
ll N;
vector<ll> Dp, DpSum;
int main() {
  cin >> N;
  Dp.resize(N);
  DpSum.resize(N);
  Dp[N - 1] = DpSum[N - 1] = N;
  for (ll i = N - 2; i >= 0; --i) {
    // 1
    (Dp[i] += Dp[i + 1]) %= MOD;
    // xyyy... (x,y non-one)
    (Dp[i] += (N - 1) * (N - 1)) %= MOD;
    // n1...1
    if (i <= N - 4) {
      (Dp[i] += DpSum[i + 3]) %= MOD;
      (Dp[i] += i + 2) %= MOD;
    } else {
      (Dp[i] += N - 1) %= MOD;
    }
    DpSum[i] = (DpSum[i + 1] + Dp[i]) % MOD;
  }
  cout << Dp[0] << endl;
  return 0;
}


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

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

  // ここにプログラムを追記
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    if(s=="Y"){
      cout<<"Four";
      break;
    }
    else if (i==N-1){
      cout<<"Three";
    }
  }
}

Measured memory_bytes: 256
import math

N, D = map(int, input().split())

X = []
Y = []

for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)


count = 0
for i in range(N):
    d = math.sqrt(X[i] ** 2 + Y[i] ** 2)
    if D >= d:
        count += 1
print(count)


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

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

    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> L(M), R(M);
    for(int i = 0; i < M; i++){
        cin >> L[i] >> R[i];
    }
    vector<int> p(Q), q(Q);
    for(int i = 0; i < Q; i++){
        cin >> p[i] >> q[i];
    }

    vector<vector<int>> S(N + 1, vector<int>(N + 1, 0));
    for(int i = 0; i < M; i++){
        S[L[i]][R[i]]++;
    }

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            S[i][j] += S[i][j - 1];
        }
    }
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            S[i][j] += S[i - 1][j];
        }
    }

    for(int i = 0; i < Q; i++){
        int ans = S[q[i]][q[i]];
        ans -= S[p[i] - 1][q[i]];
        ans -= S[q[i]][p[i] - 1];
        ans += S[p[i] - 1][p[i] - 1];

        cout << ans << endl;
    }



    return 0;
}

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

int n;
string s[200055];

typedef unsigned long long ull;
const ull B = 1e9 + 9;

int cnt[26];

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

    cin >> n;

    for (int i = 0; i < n; i++) cin >> s[i];

    sort(s, s + n, [&] (string v, string u) {
        return v.size() < u.size();
    });

    long long res = 0;
    map<ull, int> c;

    for (int i = 0; i < n; i++) {
        ull h = 0;

        for (auto ch: s[i]) cnt[ch - 'a']++;

        for (int j = 0; j < 26; j++) if (cnt[j] > 0) {
            if (c.count(j + 1)) {
                res += c[j + 1];
            }
        }

        ull x = 1;

        for (int j = (int)s[i].size() - 1; j >= 0; j--) {
            h = x * (s[i][j] - 'a' + 1) + h;
            cnt[s[i][j] - 'a']--;

            if (j != s[i].size() - 1 && c.count(h)) {
                res += c[h];
            }

            x *= B;

            for (int k = 0; k < 26; k++) if (cnt[k] > 0) {
                if (j - 1 >= 0 && k == (s[i][j - 1] - 'a')) continue;
                if (c.count(h + x * (k + 1))) {
                    res += c[h + x * (k + 1)];
                }
            }
        }

        c[h]++;
    }

    cout << res << endl;

    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int C[10001] = {0};
    int n = 0;
    cin >> n;
    int a = 0;
    int mina = 10000;
    for (int i = 0; i != n; ++i){
        cin >> a;
        ++C[a];
        if (a < mina) mina = a;
    }
    cout << mina;
    --C[mina];
    for (int i = mina; i != 10001; ++i){
        for (int j = 0; j != C[i]; ++j){
            cout << ' ' << i;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;

const int maxn = 100005;

int n, m;

int a[maxn], b[maxn];

struct Edge {
    int id, to;
};

vector<Edge> E[maxn];

bool ans[maxn * 2];
bool vis[maxn];
int fa[maxn];
int fid[maxn];
void dfs(int x, bool isRoot) {
    vis[x] = true;
    for (auto &e: E[x]) if(!vis[e.to]) {
        dfs(e.to, false);
        fa[e.to] = x;
        fid[e.to] = e.id;
        if (b[e.to]) {
            ans[e.id] = true;
            b[e.to] = 0;
            b[x] ^= 1;
        }
    }
}

vector<pair<int, int> > vec;

int main() {
#ifdef __APPLE__
    freopen("main.in", "r", stdin);
#endif
    scanf(" %d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        int a, b; scanf(" %d%d", &a, &b);
        vec.push_back(make_pair(a, b));
    }
    sort(vec.begin(), vec.end());
    for (int i = 0; i < n; ++i) {
        a[i + 1] = vec[i].first;
        b[i + 1] = vec[i].second;
    }
    for (int i = n; i >= 1; --i) b[i] ^= b[i - 1];
    /*
    for (int i = 1; i <= n; ++i) {
        cout << a[i] << " " << b[i] << endl;
        }*/
    //cout << endl;
    for (int i = 1; i <= m; ++i) {
        int l, r; scanf(" %d%d", &l ,&r);
        int nl = lower_bound(a + 1, a + n + 1, l) - a;
        int nr = upper_bound(a + 1, a + n + 1, r) - a - 1;
        //cerr << nl << " " << nr << endl;
        if (nl > nr) continue;
        l = nl, r = nr + 1;
        E[l].push_back({i, r});
        E[r].push_back({i, l});
        //cerr << l << " " << r << endl;
    }
    //cout << endl;
    for (int i = 1; i <= n; ++i) if (!vis[i]) {
        // cerr << i << endl;
        vis[n + 1] = false;
        dfs(i, true);
        if (b[i] && !vis[n + 1]) {
            puts("-1"); return 0;
        } else if (b[i] && vis[n + 1]) {
            int cur = n + 1;
            while (cur != 0) {
                ans[fid[cur]] ^= 1;
                cur = fa[cur];
            }
        }
    }
    int sum = 0;
    for (int i = 1; i <= m; ++i) sum += ans[i];
    printf("%d\n", sum);
    for (int i = 1; i <= m; ++i) if (ans[i]) {
        printf("%d ", i);
    } puts("");
    return 0;
}


Measured memory_bytes: 15220
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

template<int N, int MOD>
struct Comb {
	ll fact[N + 1], inv[N + 1];
	Comb() {
		fact[0] = inv[0] = inv[1] = 1;
		for (int i = 2; i <= N; i++) inv[i] = (MOD + ((ll)-inv[MOD%i] * (MOD / i)) % MOD) % MOD;
		REPS(i, N) {
			fact[i] = fact[i - 1] * i%MOD;
			inv[i] = inv[i] * inv[i - 1] % MOD;
		}
	}
	ll operator()(int n, int r) {
		if (n < 0 || r < 0 || r > n) return 0;
		ll res = inv[r] * inv[n - r];
		if (res >= MOD) res %= MOD;
		res *= fact[n];
		if (res >= MOD) res %= MOD;
		return res;
	}
};
Comb<300000, MOD> C;

int T, n, m, h, w, a, b;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> h >> w >> a >> b;
	ll ans = 0;
	REP(i, h - a) {
		ans += C(i + b - 1, i) * C(w - b + h - i - 2, h - i - 1) % MOD;
	}
	cout << ans % MOD << endl;
	return 0;
}


Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	P := make([]int, N)
	for i := 0; i < N; i++ {
		P[i] = nextInt(sc)
	}
	// fmt.Println("N", N, "P", P)
	minp, maxp, ans := int(1e6), 0, 0
	for i := 0; i < N; i++ {
		minp = min(minp, P[i])
		maxp = max(maxp, P[i])
		if minp >= P[i] {
			ans++
		}
	}
	fmt.Println(ans)
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

int main() {
  intmax_t r, D, x;
  std::cin >> r >> D >> x;

  for (int i = 0; i < 10; i++) {
    x = r * x - D;
    std::cout << x << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
char s[15];
map<string, int> mp;
map<string, int>::iterator it;
int n, m;
int main()
{	
	while (~scanf("%d", &n))
	{
		//string mxstr = "axiba";
		int mx = 0;
		mp.clear();
		for (int i = 0; i < n; i++)
		{
			scanf("%s", s);
			mp[s]++;
		}
		scanf("%d", &m);
		for (int i = 0; i < m; i++)
		{
			scanf("%s", s);
			mp[s]--;
		}
		for (it = mp.begin(); it != mp.end(); it++)
		{
			if (it->second >= mx)
				mx = it->second;
				//mxstr = it->first;
		}
		printf("%d\n", mx);
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	double len;
	double wid;
	double hei;
	double s[3];
	int n;
	int ent;
	int entd;
	int min;
	int i, j;
	
	while (1){
		scanf("%lf %lf %lf", &len, &wid, &hei);
		if (len == 0 && wid == 0 && hei == 0){
			break;
		}
		scanf("%d", &n);
		for (i = 0; i < n; i++){
			scanf("%d", &ent);
			entd = ent * 2;
			s[0] = sqrt(len * len + wid * wid);
			s[1] = sqrt(wid * wid + hei * hei);
			s[2] = sqrt(len * len + hei * hei);
			
			min = s[0];
			for (j = 1; j < 3; j++){
				if (min > s[j]){
					min = s[j];
				}
			}
			if (entd > min) printf("OK\n");
			else printf("NA\n");
		}
	}
	return (0);
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
/*ll ncr(ll n,ll r)
{
	if(n==1 || r==0)
	return 1;
	if(r>n/2)
	r=n-r;
	ll ans=1;
	for(ll i=1;i<=r;i++)
	{
		ans=((ans * n )/i);
		n--;
	}
	return ans;
}*/
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow(ll a,ll b,ll m)
{
	ll ans=1;
	while(b>0)
	{
		if(b&1)
			ans=(ans*a)%m;
		b=b/2;
		a=(a*a)%m;
	}
	return ans;
}
 
ll modinv(ll k)
{
	return pow(k,MOD-2,MOD);
}

ll ncr(ll n,ll c)
{
    ll t=1;
    c=min(c,n-c);
    for(ll i=1;i<=c;i++)
    {
     	t=(t*(n-i+1))%MOD;
        t=(t*modinv(i))%MOD;
	}
    return t;
}
int main()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	ll k=0;
	for(ll i=0;i<n;i++)
	{
		if(a[i]%2==0)
		{
			if(a[i]%3!=0 && a[i]%5!=0)
			{
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    int a[n+1];
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    int mi = a[0];
    int res = -0x3f3f3f3f;
    for(int i = 1; i < n; i++){
        res = max(a[i]-mi, res);
        mi = min(mi, a[i]);
    }
    printf("%d\n", res);
    return 0;
}


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

int z[100001], w[100001];
 
void merge_sort(long long x[], int y[], int n)
{
	if (n == 1) return;
	merge_sort(&(x[0]), &(y[0]), n/2);
	merge_sort(&(x[n/2]), &(y[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) {
			z[i] = y[q];
			w[i] = x[q++];
		} else if (q >= n) {
			z[i] = y[p];
			w[i] = x[p++];
		} else {
			z[i] = (x[p] < x[q])? y[p]: y[q];
			w[i] = (x[p] < x[q])? x[p++]: x[q++];
		}
	}
	for (i = 0; i < n; i++) {
		x[i] = w[i];
		y[i] = z[i];
	}
}

int main()
{
	int i, N, M, B[100001];
	long long A[100001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < N; i++) scanf("%lld %d", &(A[i]), &(B[i]));
	
	long long cost = 0;
	merge_sort(A, B, N);
	for (i = 0; i < N; i++) {
		if (M - B[i] >= 0) {
			cost += A[i] * B[i];
			M -= B[i];
		} else {
			cost += A[i] * M;
			break;
		}
	}
	
	printf("%lld\n", cost);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
long long A, B, C;
cin >> A >> B >> C;
bool check = 0;
bool mugen = 0;
if(A % 2 == 1 || B%2 == 1 || C%2 == 1){
    check = 1;
}
long long afa, afb, afc;
int count = 0;
while(check == 0){

afa = A / 2;
afb = B / 2;
afc = C / 2; 
A = afb + afc;
B = afa + afc;
C = afa + afb;
count++;


if(A % 2 == 1 || B%2 == 1 || C%2 == 1) check = 1;
if(count > 1000){
check = 1;
mugen = 1;
break;
}

}
if(mugen == 1)cout << -1 << endl;
else cout << count << endl;



}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstdio>
using namespace std;
int father[200001],le[200001],o[200001],br[200001],used[200001];
vector<int>v[200001];
int fin(int x)
{
    if(father[x]==x)return x;
    return father[x]=fin(father[x]);
}
void dfs(int x)
{
    used[x]=1;
    int i,n=v[x].size(),a;
    a=fin(x);
    br[a]++;
    for(i=0;i<n;i++)
        if(!used[v[x][i]])dfs(v[x][i]);
}
void re(int x)
{
    used[x]=3;
    int i,n=v[x].size(),a;
    a=fin(x);
    br[a]=0;
    for(i=0;i<n;i++)
        if(used[v[x][i]]==2)re(v[x][i]);
}
void ois(int x)
{
    used[x]=2;
    int i,n=v[x].size(),a;
    a=fin(x);
    o[x]+=br[a];
    for(i=0;i<n;i++)
        if(used[v[x][i]]==1)ois(v[x][i]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int i,a,b,n,m,k;
    cin>>n>>m>>k;
    for(i=0;i<=n;i++)
        father[i]=i;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        a=fin(a);
        b=fin(b);
        if(a!=b)
        {
            if(le[a]>=le[b])father[b]=a;
            if(le[a]==le[b])le[a]++;
            if(le[a]<le[b])father[a]=b;
        }
    }
    for(i=0;i<k;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(i=1;i<=n;i++)
    {
        if(!used[i])
        {
            dfs(i);
            ois(i);
            re(i);
        }
    }
    for(i=1;i<n;i++)
        cout<<o[i]<<' ';
    cout<<o[i]<<'\n';
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int DX9[9]={0,1,1,1,0,-1,-1,-1,0}, DY9[9]={-1,-1,0,1,1,1,0,-1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":"\n");return os;}
//------------------------------------------------------------------------------

signed main() {
    string s[3];
    cin>>s[0]>>s[1]>>s[2];
    int p=0;
    map<char,int> pc = {make_pair('a',0),make_pair('b',1),make_pair('c',2)};
    map<int,char> pc_ = {make_pair(0,'A'),make_pair(1,'B'),make_pair(2,'C')};
    while(true) {
        if(s[p]=="") {
            cout<<pc_[p]<<endl;
            break;
        }
        char c=s[p][0];
        s[p]=s[p].substr(1,s[p].size()-1);
        p=pc[c];
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
// cin=sc.nextInt();
// List<Integer> a = new ArrayList<Integer>(n);
 
public class Main {
    public static void main(String args[]){
		    Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            b = sc.nextInt();
            if(a != b){
                System.out.println(1);
            }
            else{
                System.out.println(0);
            }
	}
}


Measured memory_bytes: 21844
import java.util.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      int a;
      int b;
      int gcd;
      int lcm;
         
         
      while(sc.hasNext()){
         str = sc.nextLine();
         arr = str.split(" ");
         Arrays.sort(arr);
         a = Integer.parseInt(arr[0]);
         b = Integer.parseInt(arr[1]);
            
         gcd = Euclid(a,b);
         lcm = LCM(a,b);
         
         
         System.out.println(gcd + " " + lcm);
      }    
   }//main
   
   public static int Euclid(int a, int b){
      int remainder;
      if(a%b == 0){
         return b;
      }else{
         remainder = a%b;
         return Euclid(b,remainder);
      }
   }
   
   public static int LCM(int a, int b){
      int k = 1;
      while(true){
         if((b*k)%a == 0){
            return b*k;
         }else{
            k++;
         }
      }
   }
   
}//class

Measured memory_bytes: 25812
use std::io::BufRead;
fn main() {
    let stdin = std::io::stdin();
    let mut stdinlock = stdin.lock();
    let mut s = String::new();
    let mut t = String::new();
    let _ = stdinlock.read_line(&mut s).expect("read s");
    let _ = stdinlock.read_line(&mut t).expect("read t");
    println!(
        "{}",
        if solve(&s.trim(), &t.trim()) {
            "Yes"
        } else {
            "No"
        }
    );
}

fn solve(s: &str, t: &str) -> bool {
    let mut ss: Vec<char> = s.chars().collect();
    ss.sort();
    let mut tt: Vec<char> = t.chars().collect();
    tt.sort_by(|a, b| b.cmp(a));
    ss < tt
}


Measured memory_bytes: 2156
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int n,hp[111];
int m1,mp1[111],d1[111];
int m2,mp2[111],d2[111];
ll dp1[200010],dp2[200010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n && n){
		rep(i,n)cin>>hp[i];
		int m;
		cin>>m;
		m1=m2=0;
		rep(i,m){
			string s,t;
			int mp,d;
			cin>>s>>mp>>t>>d;
			d=min(d,100000);
			if(t=="Single"){
				mp1[m1]=mp;
				d1[m1]=d;
				m1++;
			}else{
				mp2[m2]=mp;
				d2[m2]=d;
				m2++;
			}
		}
		fill(dp1,dp1+200001,INF);
		fill(dp2,dp2+200001,INF);
		dp1[0]=dp2[0]=0;
		rep2(i,1,200001){
			rep(j,m1)if(d1[j]<=i){
				dp1[i]=min(dp1[i],mp1[j]+dp1[i-d1[j]]);
			}
			rep(j,m2)if(d2[j]<=i){
				dp2[i]=min(dp2[i],mp2[j]+dp2[i-d2[j]]);
			}
		}
		for(int i=199999;i>=0;i--){
			dp1[i]=min(dp1[i],dp1[i+1]);
			dp2[i]=min(dp2[i],dp2[i+1]);
		}
		ll ans=INF*INF;
		rep(i,200001){
			ll res=dp2[i];
			rep(j,n){
				ll rest=max(0,hp[j]-i);
				res+=dp1[rest];
			}
			ans=min(ans,res);
		}
		cout<<ans<<endl;
	}
}

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

int64_t gcd(int64_t a, int64_t b) {
  return b != 0 ? gcd(b, a % b) : a;
}

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

    int64_t A, B;
    cin >> A >> B;
    int64_t g = gcd(A, B);
    int64_t cnt = 1;
    if (g % 2 == 0) {
        cnt++;
        while (g % 2 == 0) g /= 2;
    }
    for (int64_t i = 3; i * i <= g; i += 2) {
        if (g % i == 0) {
            cnt++;
            while (g % i == 0) g /= i;
        }
    }
    if (g != 1) cnt++;
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int main() {
	int N;
	int V[30];
	int C[30];
	scanf("%d", &N);
	for (int i = 0; i < N; i++)scanf("%d", &V[i]);
	for (int i = 0; i < N; i++)scanf("%d", &C[i]);

	int ans = 0;

	for (int i = 0; i < N; i++)
		if (V[i] - C[i] > 0)ans += V[i] - C[i];

	printf("%d", ans);



}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++) cin >> a.at(i);
  vector<int> numBall(N, 0);
  int sum = 0;
  for(int i = N - 1; i >= 0; i--){
    int label = i + 1;
    int tempSum = 0;
    
    for(int j = 1; j < N; j++){
      if(label * (1 + j) - 1 < N){
        tempSum += numBall.at(label *(1 + j) - 1);
      }else break;
    }//j
    if(tempSum % 2 != a.at(i)){
      numBall.at(i) = 1;
      sum++;
    }
  }//i
  cout << sum << endl;
  int check = 0;
  for(int i = 0; i < N; i++){
    if(numBall.at(i) != 0){
      if(check == 0){
        cout << i + 1;
        check++;
      }else cout << " " << i + 1;
    }
  }
  cout << endl;
}

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>

using namespace std;
int main(void){
  char a[4];
  int i,sum=0;
  cin>>a;
  
  for(i=0;i<3;i++){
    if(a[i]=='o')
      sum++;
  }
  cout<<(7+sum)*100<<endl;
  return 0;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;


const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 * 100 + 47;
vector<PII> g[MAX];
vector<PLL> A[MAX];
int sz;

bool cmp(PLL a, PLL b)
{
	return a.second < b.second;
}

int dfs(int v, LL T)
{
	if (SZ(g[v]) == 0)
	{
		A[sz].push_back(MP(0, 0));
		sz++;
		return sz - 1;
	}

	int i1 = dfs(g[v][0].first, T);
	int i2 = dfs(g[v][1].first, T);
	int vi = g[v][0].second;
	int vk = g[v][1].second;
	int p = 0;
	sort(ALL(A[i1]), cmp);
	sort(ALL(A[i2]));
	LL mind = LINF;
	RFOR(i, SZ(A[i1]), 0)
	{
		LL a = A[i1][i].first;
		LL b = A[i1][i].second;
		while (p != SZ(A[i2]) && b + A[i2][p].first + vi + vk <= T)
		{
			mind = min(A[i2][p].second, mind);
			p++;
		}

		if (mind == LINF) continue;
		A[sz].push_back(MP(a + vi, mind + vk));
	}

	sort(ALL(A[i1]));
	sort(ALL(A[i2]), cmp);
	LL minc = LINF;
	p = 0;
	
	RFOR(i,SZ(A[i1]), 0)
	{
		LL a = A[i1][i].first;
		LL b = A[i1][i].second;

		while (p != SZ(A[i2]) && a + A[i2][p].second + vi + vk <= T)
		{
			minc = min(minc, A[i2][p].first);
			p++;
		}

		if (minc == LINF) continue;
		A[sz].push_back(MP(minc + vk, b + vi));
	}

	sz++;
	return sz - 1;
}

bool ok(LL c)
{
	FOR(i, 0, sz) A[i].clear();
	sz = 0;
	int ind = dfs(0, c);
	return SZ(A[ind]);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p, v;
	cin >> n;
	FOR(i, 0, n - 1)
	{
		cin >> p >> v;
		p--;
		g[p].push_back(MP(i + 1, v));
	}

	LL l = -1, r = 1000 * (LL)1000 * (LL)1000 * (LL)1000;
	while (r - l > 1)
	{
		//cout << l << " " << r << endl;
		LL c = (r + l) / 2;
		if (ok(c))
		{
			r = c;
		}
		else
		{
			l = c;
		}
	}

	cout << r << endl;
}

Measured memory_bytes: 62432
#include<stdio.h>
int main()
{
	int k;
	int a,b,c,d;
	scanf("%d",&k);
	scanf("%d",&a);
	scanf("%d",&b);
	if(a%k==0){
		printf("OK");
	}else{
	c =k - a%k;
	d = c+a;
	if(d<=b){
		printf("OK");
	}else{
		printf("NG");
	}
	}

	return 0;
}

Measured memory_bytes: 1696
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  string s;
  cin>>s;
  int count=0,max_=0;
  for(int i=0;i<s.length();i++)
  {
    if(s[i]=='R')
      count++;
    else
    {
      if(count>max_)
        max_=count;
      count=0;
    }
    if(count>max_)
        max_=count;
  }
  cout<<max_;
  
  return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r; cin >> r;
	rep(i, 0, r) {
		int n, k; cin >> n >> k;
		vector<int> x(n); rep(i, 0, n) { cin >> x[i]; }
		vector<int>	d(n - 1);
		rep(i, 0, n - 1)d[i] = x[i + 1] - x[i];
		sort(all(d));
		k = min(n, k);
		int ans = accumulate(d.begin(), d.end() - (k - 1), 0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3544
#include <stdio.h>
int main(){

  int a, b, c, tmp;
  scanf ("%d%d%d", &a, &b, &c);
  if ( a > b  ) {
    tmp = a; a = b; b = tmp;
  }
  if ( b > c  ) {
    tmp = b; b = c; c = tmp;
  }
  if ( a > b  ) {
    tmp = a; a = b; b = tmp;
  }
    printf("%d %d %d\n", a, b, c);
  return 0;

}



Measured memory_bytes: 2040
#include<iostream>
#define ll long long int
using namespace std ;

const ll maxn = 3000+4;

ll dp[maxn][maxn];


ll min(ll a, ll b)
{
    if (a <= b) return a;
    return b;
}


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


ll abs(ll x)
{
    if(x<0)
        return (-1*x);
    return x;
}

string str1, str2, ans = "" ;


int LCS(int i, int j )
{
    /// base case
    if( str1[i]=='\0' or str2[j]=='\0') return 0;

    if(dp[i][j]!=-1)  return dp[i][j];


    int ans = 0 ;
    if( str1[i] == str2[j] )
    {
        // cout << str1[i] <<" ";
        ans = 1 +  LCS(i+1, j+1);
    }
    else
    {
        //cout << ans <<" -- \n";
        int val1 = LCS( i, j+1 );
        int val2 = LCS( i+1, j );
        ans = max(val1, val2);
    }
    dp[i][j] = ans;
    return dp[i][j];
}



void printLCS(int i,int j)
{
    if( str1[i]=='\0' or str2[j]=='\0' )
    {
        cout << ans <<endl;
        return ;
    }

    if( str1[i] == str2[j] )
    {
        ans+=str1[i];

        printLCS(i+1,j+1);
    }
    else
    {
        if( dp[i+1][j] > dp[i][j+1] ) printLCS(i+1,j);
        else printLCS(i,j+1);
    }
}



int main()
{
    cin >> str1 >> str2 ;

    for(int i=0 ; i<=str1.length() ; i++)
    {
        for(int j=0 ; j<=str2.length() ; j++)
        {
            dp[i][j] = -1;
        }
    }


    LCS(0,0) ;
    printLCS(0,0);

    return 0 ;
}


Measured memory_bytes: 70912
#include <cmath>
#include <cstdio>

const int size = 1000000;
int n[size];

int main() {
    for(int i = 0 ; i < size ; ++i) {
		n[i] = (i < 2) ? false : true;
	}
    for (int i = 0; i < std::sqrt(size); ++i) {
        if (n[i]) {
            for (int j = 2; i * j < size; ++j) {
                n[i * j] = false;
            }
        }
    }
    
    int m;
    while (~scanf("%d\n", &m)) {
        int ans = 0;
        for (int i = 0; i <= m; ++i) {
            if (n[i]) {
                ++ans;
            }
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 4912
var a,b:array[1..10000000] of int64;
    i,j:longint;
    res,k,n,d:int64;
begin
 for i:=1 to 200 do   b[i]:=0;
 read(n,k);
 for i:=1 to k do
 begin
  readln(d);
  for j:=1 to d do
   begin
    read(a[j]);
    b[a[j]]:=1;
   end;
 end;
 for i:=1 to n do if(b[i]=0) then res:=res+1;
 write(res);
end.


Measured memory_bytes: 1392
<?php

fscanf(STDIN,"%s",$s);



for ($i = 0; $i<=7; $i++){
    //3桁ずつ分割
    $datas = substr($s,$i,3);

    //詰め込む
    $total[] = $datas;

    //Xとの差の結果を求める
    $c[] = 753 - $total[$i];

    //マイナスを取り除く
    $wa[] = abs($c[$i]);
}

echo min($wa);

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>

#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

pair<pair<string, int>, int> p[110];
int main(){
    int N; cin >> N;
    int res = 10010;
    int w[110];
    int allSum = 0;
    int s1 = 0;
    rep(i, N) {
        cin >> w[i];
        allSum += w[i];
    }
    rep(i, N) {
        s1 += w[i];
        int s2 = allSum - s1;
        if (abs(s2 - s1) < res) {
            res = abs(s2 - s1);
        }
    }
    cout << res << endl;
}



Measured memory_bytes: 256
N,M = [int(x) for x in input().split()]
XYZ = [[int(x) for x in input().split()]for _ in range(M)]

class UnionFind():
    def __init__(self,n):
        self.parent = [-1 for _ in range(n)]

    def size(self,x):
        return -self.parent[self.find(x)]

    def find(self,x):
        if(self.parent[x]<0):
            return x
        else:
            self.parent[x]=self.find(self.parent[x])
            return self.parent[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return False
        if(self.size(x)<self.size(y)):
            self.parent[y]+=self.parent[x]
            self.parent[x]=y
        else:
            self.parent[x]+=self.parent[y]
            self.parent[y]=x
        return True

    def same(self,x,y):
        return self.find(x)==self.find(y)

un = UnionFind(N)
cnt = 0
for i in XYZ:
    un.unite(i[0]-1,i[1]-1)
for i in un.parent:
    if(i<0):
        cnt+=1
print(cnt)


Measured memory_bytes: 23608