akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main()
{
	int N, K;
	std::cin >> N >> K;

	int mi = N / K;
	int ma;
	if (N%K == 0)
		ma = N / K;
	else
		ma = N / K + 1;

	std::cout << ma - mi << '\n';

	return 0;
}

Measured memory_bytes: 256
#[allow(unused)]
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (a, b): (usize, usize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    if a <= 9 && b <= 9 {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] P = new int[n], Q = new int[n];
        for(int i=0;i<n;i++) P[i]=sc.nextInt();
        for(int i=0;i<n;i++) Q[i]=sc.nextInt();
        int a = help(n,P), b = help(n,Q);
        System.out.println(Math.abs(a-b));
    }
    int help(int n, int[] a){
        // a is a permutation of n
        boolean[] used = new boolean[n+2];
        int ans = 0;
        int[] fac = new int[10];
        fac[0]=1;
        for(int i=1;i<10;i++) fac[i] = i*fac[i-1];
        for(int i=0;i<n;i++){
            int cnt = 0;
            for(int j=1;j<a[i];j++){
                if(!used[j]) cnt++;
            }
            used[a[i]] = true;
            ans += fac[n-1-i]*cnt;
        }
        return ans;
    }
}



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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/05  Problem: 079_arc_c / Link: https://arc079.contest.atcoder.jp/tasks/arc079_c?lang=en  ----- */
/* ------問題------

長さ N の非負整数列 ai に対し、数列の最大値が N−1 以下になるまで以下の操作を繰り返し行うことを考えます。なお、この操作はD問題で考える操作と同一です。

数列のうち最も大きい要素を求める、複数ある場合はどれか 1 つ選ぶ。この要素の値を N 減らす。これ以外の要素の値を 1 増やす。
なお、この操作を行い続けると、いつかは数列の最大値が N−1 以下になることが証明できます。

ここで、数列 ai が与えられるので、何回操作を行うことになるかを求めてください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VL a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	int update = 1;
	while (update) {
		update = 0;

		FOR(i, 0, N) {
			LL ret = a[i] / N;
			if (ret) {
				a[i] -= ret*N;
				ans += ret;

				FOR(j, 0, N) {
					if (i == j)continue;
					a[j] += ret;
				}
			}
		}
		LL m = 0;
		FOR(i, 0, N) {
			m = max(m, a[i]);
		}

		if (m < N)update = 0;
		else update = 1;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
w, h, n = map(int, input().split())
board = [[1 for _ in range(w)] for _ in range(h)]

for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(h):
            for k in range(x):
                board[j][k] = 0
    if a == 2:
        for j in range(h):
            for k in range(x, w):
                board[j][k] = 0
    if a == 3:
        for j in range(y):
            for k in range(w):
                board[j][k] = 0
    if a == 4:
        for j in range(y, h):
            for k in range(w):
                board[j][k] = 0
ans = 0
for i in board:
    ans += sum(i)
print(ans)


Measured memory_bytes: 3064
# coding: utf-8
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

c = 0
for i in range(N):
    A = list(map(int, input().split()))
    tmp = [A[i]*B[i] for i in range(M)]
    if sum(tmp, C) > 0:
        c += 1
print(c)

Measured memory_bytes: 3060
import math
#import heapq
#import itertools
import sys
def input():
    return sys.stdin.readline().rstrip('\n')

def calc(X):
    a = 100
    n = 0
    while a < X:
        a = math.floor(a * 1.01)
        n += 1
    return n


X = int(input())
print(calc(X))


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

int main(){
	int card[11], C1, C2 , C3, sum, count;

	while( cin >> C1 >> C2 >> C3 ){
		for(int i=1 ; i<=10 ; ++i){
			card[i] = 1;
		}
		count = 0;
		sum = C1 + C2;
		card[C1] = 0;
		card[C2] = 0;
		card[C3] = 0;
		for(int i=1 ; i<=10 ; ++i){
			if( card[i] == 1 && i+sum <= 20 ){
				count++;
			}
		}
		if( count/7.0 >= 0.5 )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

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

string S,T;
ll bit,st,ans;

int main(void){
    cin >> S;
    bit = S.length()-1;
    if(bit==0){cout << stoll(S) << endl; return 0;}
    rep(i,1LL<<bit){
        T = S[0];
        rep(j,bit){
            st = (i>>j)&1;
            if(st){
                ans +=stoll(T);
                T = S[j+1];
            }else{
                T.push_back(S[j+1]);
            }
        }
        ans +=stoll(T);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
vector<int> ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  ans.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int ai;
    cin >> ai;
    ai--;
    ans[ai]++;
  }

  for (auto &v : ans) {
    cout << v << endl;
  }
  return 0;
}

Measured memory_bytes: 3552
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1166&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int w,h;
int getid(int x,int y){
    return w*y+x;
}
ll solve(){
    ll res = 0;
    vector<vector<int>> G(w*h);
    for(int i = 0; i < h;i++){
        for(int j = 0; j < w-1;j++){
            int s; cin >> s;
            if(s == 0){
                int u = getid(j,i),v = getid(j+1,i);
                G[u].push_back(v);
                G[v].push_back(u);
            }
        }
        if(i == h-1) break;
        for(int j = 0; j < w;j++){
            int s; cin >> s;
            if(s == 0){
                int u = getid(j,i),v = getid(j,i+1);
                G[u].push_back(v);
                G[v].push_back(u);
            }
        }
    }
    queue<int> q;
    vector<int> dist(w*h,INF); dist[0] = 1;
    q.push(0);
    while(q.size()){
        int n = q.front(); q.pop();
        for(auto next:G[n]){
            if(dist[next] > dist[n] + 1){
                dist[next] = dist[n] + 1;
                q.push(next);
            }
        }
    }
    res = dist[h*w-1] == INF?0:dist[h*w-1];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> w >> h,w){
        cout << solve() << endl;
    }
    return 0;
}



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

int main() {
  int A;
  A = 1;
  int B;
  cin >> B;
  int M;
  cin >> M;
  int a;
  int b;
  for (int i = 0; i < M; i++) {
    cin >> a;
    cin >> b;
    if (a > A){
      A = a;
    }
    if (b < B){
      B = b;
    }
  }
  if (A > B){
    cout << 0 << endl;
  }
  if (A <= B){
    B = B + 1;
    cout << B - A << endl;
  }
}

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

//min of (hmax-hmin)
//平均？
//中央値


int compare_int(const void *a, const void *b){
	return *(int*)a-*(int*)b;
}

int main(){
	int N, K, i, hmax, hmin, sum=0, min=1000000000;
	scanf("%d %d", &N, &K);
	int h[N], hs[N];
	for(i=0;i<N;i++){
		scanf("%d", &h[i]);
		sum+=h[i];
	}
	for(i=0;i<N;i++){
		hs[i]=h[i];
	}
	qsort(hs, N, sizeof(int), compare_int);
	for(i=0;i<N-K+1;i++){
		if(min>hs[i+K-1]-hs[i]) min=hs[i+K-1]-hs[i];
	}
	printf("%d", min);
}

Measured memory_bytes: 1276
using System;

namespace ABC053C
{
    class Program
    {
        static void Main(string[] args)
        {
            long res = 0;
            long alpha = 0;
            long goal = 0;

            goal = Int64.Parse(Console.ReadLine());
            res = (goal / 11) * 2;
            alpha = goal % 11;
            res += (alpha > 0) ? alpha / 7 + 1 : 0;

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
using lint = long long;
using vi = vector<int>;

int main() {
	int n, r;
	cin >> n;
	vi x(n);
	rep(i, n) {
		cin >> r;
		x[i] = r;
	}
	int hp = 2147483647;
	int hpat = 0;
	rep(i, 100) {
		rep(j, n) {
			hpat += (x[j] - i) * (x[j] - i);
		}
		if (hpat < hp) {
			hp = hpat;
		}
		hpat = 0;
	}
	cou(hp);
}

Measured memory_bytes: 256
from operator import itemgetter

n, m = map(int, input().split())
r = sorted([list(map(int, input().split())) for _ in range(m)], key = itemgetter(0))


last = 0
count = 0
for i in range(m):
    if last > r[i][1]:
        last = r[i][1]
    elif last <= r[i][0]:
        count += 1
        last = r[i][1]

print(count)

Measured memory_bytes: 30056
ABC = list(map(int,input().split()))
ABC.sort(reverse=True)
ans = ABC[0] - ABC[1]
mnn = ABC[2] + ans
if (ABC[0] - mnn) % 2 == 0:
    ans += (ABC[0] - mnn)//2
else:
    ans += (ABC[0] - mnn)//2 + 2
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define endl '\n'
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
signed main(){
	int n , k ; 
	cin >> n >> k ;
	vector<int>stone(n);
	for(int i=0;i<n;i++) cin >> stone[i];
	
	vector<bool>dp(k+1);
	
	for(int stones = 0 ; stones <= k ; stones++ ){
		for(int a : stone){
			if(stones - a >= 0 and !dp[stones-a]){
				debug() << imie(a) imie(stones) imie(dp[stones]) ;
				dp[stones] = true;
			}
		}
	}
	
	cout << ( dp[k]?"First":"Second" ) << endl;
	return 0;
}







Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0111


"""
import sys
from sys import stdin
input = stdin.readline


def solve(data):
    # AOJ 0088?????????
    encoder = {' ':'101', "'":'000000', ',':'000011', '-':'10010001', '.':'010001', '?':'000001', 'A':'100101', 'B':'10011010',
               'C':'0101','D':'0001', 'E':'110', 'F':'01001', 'G':'10011011', 'H':'010000', 'I':'0111','J':'10011000',
               'K':'0110', 'L':'00100', 'M':'10011001', 'N':'10011110', 'O':'00101', 'P':'111', 'Q':'10011111', 'R':'1000',
               'S':'00110', 'T':'00111', 'U':'10011100', 'V':'10011101', 'W':'000010', 'X':'10010010', 'Y':'10010011', 'Z':'10010000'
               }
    rev_encoder = dict(zip(encoder.values(), encoder.keys()))

    decoder = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E', '00101':'F', '00110':'G', '00111':'H',
               '01000':'I', '01001':'J', '01010':'K', '01011':'L', '01100':'M', '01101':'N', '01110':'O', '01111':'P',
               '10000':'Q', '10001':'R', '10010':'S', '10011':'T', '10100':'U', '10101':'V', '10110':'W', '10111':'X',
               '11000':'Y', '11001':'Z', '11010':' ', '11011':'.', '11100':',', '11101':'-', '11110':"'", '11111':'?'
    }
    rev_decoder = dict(zip(decoder.values(), decoder.keys()))


    txt = ''
    for d in data:
        txt += rev_decoder[d]

    result = ''
    while txt:
        match = False
        for k in rev_encoder.keys():
            if txt.startswith(k):
                match = True
                temp = rev_encoder[k]
                txt = txt[len(k):]
                result += temp
                break
        if match is False:
            break
    return result


def main(args):
    for data in sys.stdin:
        # data = "?D-C'KOPUA"
        result = solve(data.strip('\n'))
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7572
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int D_MAX_V=1100;
const int D_v_size=1100;
struct D_wolf{
	int t,c,r;
	D_wolf(){t=c=r=0;}
	D_wolf(int t1,int c1,int r1){
		t=t1;c=c1;r=r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from,int to,int cap){
	D_G[from].push_back(D_wolf(to,cap,D_G[to].size()));
	D_G[to].push_back(D_wolf(from,cap,D_G[from].size()-1));
}
void D_bfs(int s){
	for(int i=0;i<D_v_size;i++)D_level[i]=-1;
	queue<int> Q;
	D_level[s]=0;
	Q.push(s);
	while(Q.size()){
		int v=Q.front();
		Q.pop();
		for(int i=0;i<D_G[v].size();i++){
			if(D_G[v][i].c>0&&D_level[D_G[v][i].t]<0){
				D_level[D_G[v][i].t]=D_level[v]+1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v,int t,int f){
	if(v==t)return f;
	for(;D_iter[v]<D_G[v].size();D_iter[v]++){
		int i=D_iter[v];
		if(D_G[v][i].c>0&&D_level[v]<D_level[D_G[v][i].t]){
			int d=D_dfs(D_G[v][i].t,t,min(f,D_G[v][i].c));
			if(d>0){
				D_G[v][i].c-=d;
				D_G[D_G[v][i].t][D_G[v][i].r].c+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	for(;;){
		D_bfs(s);
		if(D_level[t]<0)return flow;
		for(int i=0;i<D_v_size;i++)D_iter[i]=0;
		int f;
		while((f=D_dfs(s,t,99999999))>0){flow+=f;}
	}
	return 0;
}
int v[510];
void init(){
	for(int i=0;i<510;i++)v[i]=0;
}
int dfs(int a,int b){
	v[a]=1;
	if(a==b)return 1;
	for(int i=0;i<D_G[a].size();i++){
		if(!v[D_G[a][i].t]&&D_G[a][i].c){
			int res=dfs(D_G[a][i].t,b);
			if(res){
				D_G[a][i].c--;
				D_G[D_G[a][i].t][D_G[a][i].r].c++;
				return 1;
			}
		}
	}
	return 0;
}
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<b;i++){
		int p,q;
		scanf("%d%d",&p,&q);p--;q--;
		add_edge(p,q,1);
	}
	int ret=max_flow(0,a-1);
	for(int i=0;i<c;i++){
		int p,q,r;
		scanf("%d%d%d",&r,&p,&q);p--;q--;
		if(r==1){
			bool ok=false;
			for(int j=0;j<D_G[p].size();j++){
				if(D_G[p][j].t==q){
					ok=true;
					D_G[p][j].c=1;
					D_G[q][D_G[p][j].r].c=1;
				}
			}
			if(!ok)add_edge(p,q,1);
			ret+=max_flow(0,a-1);
			printf("%d\n",ret);
		}else{
			for(int j=0;j<D_G[p].size();j++){
				if(D_G[p][j].t==q){
					if(D_G[p][j].c==1){
						D_G[p][j].c=D_G[q][D_G[p][j].r].c=0;
						break;
					}else if(D_G[p][j].c==0){
						D_G[p][j].c=D_G[q][D_G[p][j].r].c=0;
						init();
						int tmp=dfs(p,q);
						if(!tmp){
							ret--;
							init();
							dfs(a-1,q);
							init();
							dfs(p,0);
						}
					}else{
						D_G[p][j].c=D_G[q][D_G[p][j].r].c=0;
						init();
						int tmp=dfs(q,p);
						if(!tmp){
							ret--;
							init();
							dfs(a-1,p);
							init();
							dfs(q,0);
						}
					}
				}
			}
			printf("%d\n",ret);
		}
	}
}

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

using namespace std;
using LLONG = long long;

int main()
{
    LLONG N, M;
    cin >> N >> M;
    multiset<LLONG> cards;
    for (int i = 0; i < N; ++i)
    {
        int Ai;
        cin >> Ai;
        cards.insert(Ai);
    }
    multimap<LLONG, LLONG> C2B;
    for (int i = 0; i < M; ++i)
    {
        LLONG B, C;
        cin >> B >> C;
        C2B.insert({ C, B });
    }
    for (auto itr = C2B.rbegin(); itr != C2B.rend(); ++itr)
    {
        bool finish = false;
        auto card = cards.begin();
        for (int i = 0; i < itr->second; ++i)
        {
            if (*card < itr->first)
            {
                cards.insert(itr->first);
                card = cards.erase(card);
            }
            else
            {
                finish = true;
                break;
            }
        }
        if (finish) break;
    }
    LLONG sum = 0;
    for (const LLONG &card : cards)
        sum += card;
    cout << sum;
    return 0;
}

Measured memory_bytes: 11136
package main

import "fmt"

func main() {
	var d int
	fmt.Scan(&d)

	switch d {
	case 25:
		fmt.Println("Christmas")
	case 24:
		fmt.Println("Christmas Eve")
	case 23:
		fmt.Println("Christmas Eve Eve")
	case 22:
		fmt.Println("Christmas Eve Eve Eve")
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define setbits(x) __builtin_popcountll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define ll long long
#define inf INT_MAX
#define ninf INT_MIN
#define pi 3.14159265358979323846264338327950
 
const int mod=1e9+7;
int main()
{
  int s,w; cin>>s>>w;
  if(s<=w) cout<<"unsafe";
  else cout<<"safe";
   return 0;
} 


Measured memory_bytes: 3596
n = int(input())
x = [input() for i in range(n)]
l = []
foot = x[0][0]
ans = 0
for i in range(len(x)):
  if foot != x[i][0]:
    ans = 1
  foot = x[i][-1]
  if x[i] in l:
    ans = 1
  l.append(x[i])
if ans == 1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 9152
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

#define MAX_N 1000000
#define INF 1145141145141919810LL;

long long x[MAX_N],y[MAX_N],lx[MAX_N],ly[MAX_N],d[MAX_N],n,h,w,sx,sy,c,mx,my,sum,minx,dx,dy;
vector<long long>X,Y,BX,BY;

int main(){
	cin>>h>>w>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		lx[i]=x[i];ly[i]=y[i];
		sx+=x[i];
		sy+=y[i];
	}
	sort(x,x+n);
	sort(y,y+n);
	mx=INF;my=INF;minx=INF;

	for(int i=0;i<n;i++){
		if(i==0){c=x[0];}
		else{c=x[i]-x[i-1];}
		sx+=(-n+i*2)*c;
		if(mx==sx){X.push_back(x[i]);}
		if(mx>sx){mx=sx;X.clear();X.push_back(x[i]);}
	}

	for(int i=0;i<n;i++){
		if(i==0){c=y[0];}
		else{c=y[i]-y[i-1];}
		sy+=(-n+i*2)*c;
		if(my==sy){Y.push_back(y[i]);}
		if(my>sy){my=sy;Y.clear();Y.push_back(y[i]);}
	}
	for(int i=0;i<X.size();i++){
		if(i<10){BX.push_back(X[i]);}
		else{if(X[i]!=X[i-10]){BX.push_back(X[i]);}}
	}
	for(int i=0;i<Y.size();i++){
		if(i<10){BY.push_back(Y[i]);}
		else{if(Y[i]!=Y[i-10]){BY.push_back(Y[i]);}}
	}
	for(int i=0;i<BX.size();i++){
		for(int j=0;j<BY.size();j++){
			memset(d,0,sizeof(d));
			sum=0;
			for(int k=0;k<n;k++){
				d[k]=abs(BX[i]-lx[k])+abs(BY[j]-ly[k]);
				sum+=d[k]*2;
			}
			sort(d,d+n);
			sum-=d[n-1];
			if(minx>sum){
				minx=sum;
				dx=BX[i];
				dy=BY[j];
			}
		}
	}
	cout<<minx<<endl<<dx<<' '<<dy<<endl;
	return 0;
}

Measured memory_bytes: 20428
N, D = map(int, input().split())
XList = [i for _ in range(N) for i in map(int, input().split())]
couInt = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      dist = 0.0
      for k in range(D):
        dist += (XList[i*D+k]-XList[j*D+k])**2
      if dist**0.5%1==0:
        couInt += 1
print(couInt)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,ans=0;
cin >> n;
int p[n];
for(int i=0;i<n;i++){
	cin >> p[i];
}

for(int i=1;i<n-1;i++){
	if(p[i-1]<p[i] && p[i]<p[i+1]){
		ans++;
	}
	else if(p[i-1]>p[i] && p[i]>p[i+1]){
		ans++;
	}
}

cout << ans << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <cstring>
typedef long long int lli;

lli dp[100][21];
int tbl[100];

int main(void) {
    int n;
    scanf("%d", &n);
    for(int i=0; i < n; i++)
        scanf("%d", &tbl[i]);

    memset(dp, 0, sizeof(dp));
    dp[0][tbl[0]] = 1;

    for(int i=0; i < n; i++)
    {
        for(int j=0; j < 21; j++)
        {
            if(j+tbl[i+1] <= 20)
                dp[i+1][j+tbl[i+1]] += dp[i][j];
            if(j-tbl[i+1] >= 0)
                dp[i+1][j-tbl[i+1]] += dp[i][j];
        }
    }
    printf("%ld\n", dp[n-1][tbl[n]]);
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << (x) << std::endl
using ll = long long;
int main()
{
    int N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    S = std::string(N, 'A') + S;
    int Q;
    std::cin >> Q;
    for (int q = 0, k; q < Q; q++) {
        std::cin >> k;
        ll D = 0, M = 0, DM = 0;
        for (int j = 0; j < k; j++) {
            if (S[j] == 'M') { DM += D, M++; }
            if (S[j] == 'D') { D++; }
        }
        ll ans = 0;
        for (int j = 0; j + k < 2 * N; j++) {
            if (S[j] == 'D') {
                DM -= M, D--;
            } else if (S[j] == 'M') {
                M--;
            }
            if (S[j + k] == 'D') {
                D++;
            } else if (S[j + k] == 'M') {
                DM += D, M++;
            } else if (S[j + k] == 'C') {
                ans += DM;
            }
        }
        std::cout << ans << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3332
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[501];
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=500;i++)
	a[i]=i*i*i*i*i;
	for(int i=0;i<=500;i++)
	for(int j=0;j<=500;j++)
	{
		if(a[i]+a[j]==n)
		{
			printf("%lld %lld",i,-j);
			return 0;
		}
		if(a[i]-a[j]==n)
		{
			printf("%lld %lld",i,j);
			return 0;
		}
	}
    return 0;
}

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

int main(){ 
  int n;
  cin >> n;
  vector<ll> p(n);
  rep(i,n) cin >> p[i];
  priority_queue<int, vector<int>, greater<int>> pq;
  int res = 0;
  for (int i = 0; i < n; i++) {
    pq.push(p[i]);
    if (pq.top() >= p[i]) res++;
  }
  
  cout << res << endl;
  return 0;
} 

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

const int MAX_N = 100, MAX_W = 10000;
int dp[MAX_N + 1][MAX_W + 1];

int main()
{
	int N, W; cin >> N >> W;
	int v[MAX_N], w[MAX_N];
	for (int i = 0;i < N;i++) cin >> v[i] >> w[i];

	for (int i = 0;i < N;i++) {
		for (int j = 0;j <= W;j++) {
			if (j < w[i]) dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
		}
	}

	cout << dp[N][W] << endl;
    return 0;
}




Measured memory_bytes: 6980
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

int n;
int t, a;
int h[1000];

double Abs(double x) { if (x > 0) return x; return -x; }

signed main() {
	int i;
	
	cin >> n;
	cin >> t >> a;
	
	double mini = 1145141919;
	int id = -1;
	for (i = 0; i < n; i++) {
		cin >> h[i];
		double tt = t - h[i] * 0.006;
		double score = Abs(a - tt);
		if (mini > score) {
			mini = score;
			id = i;
		}
	}
	cout << id + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(a<=c && c<=b)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
A,B,C = [list(map(int,input().split())) for _ in range(3)]
tmp=A[0]
ans=0
for i in range(N):
    ans+=B[A[i]-1]
    if A[i]-tmp == 1:
        ans+=C[A[i]-2]
    tmp=A[i]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long a,b,c,d,e,f,g;
    string arr,brr;
    cin>>arr;
    cin>>brr;
    vector<char>vc;
    for(long long i=0; i<brr.length(); i++)
    {
        a=arr[i];
        vc.push_back(a);
        a=brr[i];
        vc.push_back(a);


    }
    if(arr.length()>brr.length())
        vc.push_back(arr[arr.length()-1]);

    for(long long i=0; i<vc.size(); i++)
        cout<<vc[i];


}


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


int main()
{
  int k;
  cin >> k;
  if(k%2 == 1) cout << (k/2+1)*(k/2) << endl;
  if(k%2 == 0) cout << (k/2) * (k/2) << endl;

  return 0;

}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    long cnt = 0;
    vector<long> vec(n + 1, 0);  // i番目の積に座っているか
    int a;
    for (int i = 0; i < m; i++) {
        cin >> a;
        vec[a]++;
    }
    for (int i = 1; i <= m; i++) {
        if (vec[i] == 0) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    ll a,b,c;
    std::cin >> a >> b >> c;

    ll ans = a*b*c - 2*(a/2)*b*c;
    ans = std::min(ans, a*b*c - 2*a*(b/2)*c);
    ans = std::min(ans, a*b*c - 2*a*b*(c/2));

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	int cnt=0;
	cin>>n;
	for(int i=1;i<=n;i+=2){
		int ans=0;
	for(int j=1;j<=i;j++){
		if(i%j==0)ans++;
		}
		if(ans==8)cnt++;		
	}
	cout<<cnt<<endl;
	return 0;
}


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


public class Test
{	
    public static void Main()
	{
        int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        Array.Sort(nums);
        bool ok = true;
        if(nums[0] != 5) ok = false;
        if(nums[1] != 5) ok = false;
        if(nums[2] != 7) ok = false;
        
        if(ok) Console.WriteLine("YES");
        else Console.WriteLine("NO");
	}
}

Measured memory_bytes: 11348
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
} 
const int MAX_N = 1e5 + 5; 
int N, M, A[MAX_N], B[MAX_N], C[MAX_N], ans[MAX_N]; 
int c[MAX_N]; 
int lb(int x) { return x & -x; } 
void add(int x, int v) { while (x <= N) c[x] += v, x += lb(x); } 
int sum(int x) { int res = 0; while (x) res += c[x], x -= lb(x); return res; } 
vector<int> pot[MAX_N];
bool used[MAX_N]; 
#define fi first
#define se second
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > Q; 
int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
	N = gi() + 1; 
	for (int i = 1; i < N; i++) A[i] = gi(), B[i] = gi(); 
	for (int i = 1; i <= N; i++) C[i] = gi(); 
	sort(&C[1], &C[N + 1]); 
	for (int i = 1; i < N; i++) A[i] = lower_bound(&C[1], &C[N + 1], A[i]) - C; 
	for (int i = 1; i < N; i++) B[i] = lower_bound(&C[1], &C[N + 1], B[i]) - C; 
	for (int i = 1; i < N; i++) if (B[i] < A[i]) pot[A[i] - 1].push_back(i); 
	for (int i = 1; i <= N; i++) add(i, -1); 
	for (int i = 1; i < N; i++) add(A[i], 1); 
	int now = N - 1; 
	M = gi(); 
	for (int i = N; i; i--) { 
		int q = -1 - sum(i); 
		for (int j : pot[i]) Q.push(make_pair(B[j], j)); 
		while (q-- > 0) { 
			if (Q.empty() || Q.top().fi > i) { while (M--) puts("-1"); return 0; } 
			int t = Q.top().se; used[t] = 1; Q.pop(); 
			add(B[t], 1), add(A[t], -1), --now; 
		} 
	} 
	while (!Q.empty()) Q.pop(); 
	for (int i = 1; i <= N; i++) pot[i].clear(); 
	for (int i = 1; i < N; i++) if (B[i] < A[i] && !used[i]) pot[B[i]].push_back(i); 
	for (int i = 1; i <= N; i++) { 
		ans[i] = now; 
		int q = -sum(i); 
		for (int j : pot[i]) if (!used[j]) Q.push(make_pair(-A[j], j)); 
		while (q-- > 0) { 
			if (Q.empty() || -Q.top().fi < i) { now = -1e9; break; } 
			int t = Q.top().se; used[t] = 1, Q.pop(); 
			add(B[t], 1), add(A[t], -1), --now; 
		} 
	} 
	ans[N + 1] = -1e9; 
	while (M--) { 
		int a = gi(), b = gi(); 
		a = lower_bound(&C[1], &C[N + 1], a) - C; 
		b = lower_bound(&C[1], &C[N + 1], b) - C;
		int res = -1; 
		if (res < ans[a] + 1) res = ans[a] + 1; 
		if (res < ans[b]) res = ans[b]; 
		printf("%d\n", res); 
	} 
    return 0; 
} 

Measured memory_bytes: 11632
#include <bits/stdc++.h>
#define nl endl
#define dbg(a) cout << #a << "=" << a << endl
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define md 998244353
#define mx 200100

using namespace std;

ll t[4*mx];

ll sum(ll v, ll tl, ll tr, ll l, ll r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    ll tm = (tl + tr) / 2;
    return sum(v*2, tl, tm, l, min(r, tm))
           + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
}

void update(ll v, ll tl, ll tr, ll pos, ll new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        ll tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = t[v*2] + t[v*2+1];
    }
}

ll solve()
{
    ll n, k;
    cin>>n>>k;
    vector<pair<long long, long long> > v(k);
    for(ll i=0;i<k;i++)
    {
        ll a, b;
        cin>>a>>b;
        v[i]={a, b};
    }
    sort(v.begin(), v.end());
    vector<long long> dp(n+10);
    dp[1]=1;
    update(1, 1, n, 1, 1);
    for(int i=2;i<=n;i++)
    {
        ll ct=0;
        for(int j=0;j<k;j++)
        {
            ll st=i-v[j].second;
            ll ed=st+v[j].second-v[j].first;
            // if(st>=1)
            if(st<1) st=1;
            ct=(ct+sum(1, 1, n, st, ed))%md;
        }
        dp[i]=ct;
        update(1, 1, n, i, ct);
    }
    cout<<dp[n]<<endl;

    return 0;
}

int main()
{
    fast;
    solve();
    return 0;
}

Measured memory_bytes: 8956
#[allow(unused_macros, dead_code)]
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, dead_code)]
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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros, dead_code)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        t: usize,
    }
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
k = int(input())
from fractions import gcd

ans=0
for i in range(k):
    ans+=i+1
    for j in range(i+1, k):
        x=gcd(i+1,j+1)
        ans+=6*gcd(i+1,j+1)
        for l in range(j+1, k):
            ans+=6*gcd(x,l+1)
print(ans)

Measured memory_bytes: 10580
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int ans = 0;
    int a = 0;
    for(int i = 1;i < S.size();i++){
        if(S[i] != S[i-1])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    cins(all(a));
    ll ans = 0;
    rep(i,n) ans = gcd(ans,a[i]);
    PRINT(ans);
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#define int long 
using namespace std;

signed main() {
	string S;
	int K;
	cin >> S >> K;
	int A = 1000;
	for(int i = 0;i < S.size();i++) {
		if(S.at(i) != '1') {
			A = i;
			break;
		}
	}
	if(A > K - 1) {
		cout << "1" << endl;
	}
	else {
		cout << S.at(A) << endl;
	}
}

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

const long long INF = 1LL<<60;

int N, K;
long long h[100010];

long long dp[100010];

long long rec(int i){
    if (dp[i] < INF) return dp[i];
    
    if (i == 0) return 0;
    
    long long res = INF;

    for(int j = 1; j <= K; j++){
        if (i - j < 0) break;
        res = min(res, rec(i-j) + abs(h[i] - h[i-j]));
    }
    
    return dp[i] = res;
}

int main(){
    cin >> N >> K;
    
    for(int i = 0; i < N; i++) cin >> h[i];

    for(int i = 0; i < 100010; i++) dp[i] = INF;

    cout << rec(N-1) << endl;

    return 0;
}

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

int main() {
  ll n, u, v, w;
  cin >> n;
  vector<vector<P>> g(n);
  rep(i, n - 1) {
    cin >> u >> v >> w;
    u--, v--;
    g[u].emplace_back(v, w);
    g[v].emplace_back(u, w);
  }

  vector<int> ans(n, -1);
  ans[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (auto x : g[a]) {
      int b = x.first, c = x.second;
      if (ans[b] != -1) continue;
      ans[b] = (ans[a] + c) % 2;
      q.push(b);
    }
  }

  rep(i, n) cout << ans[i] << endl;

  return 0;
}


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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    deque<int> A;
    rep(i,N) {
        int a;
        cin >> a;
        if (A.size()==0) {
            A.push_back(a);
        }
        else {
            auto idx = lower_bound(A.begin(),A.end(), a) - A.begin();
            if (idx==0) {
                A.push_front(a);
            }
            else {
                A[idx-1] = a;
            }
        }
        //sort(A.begin(),A.end());
    }
    int ans = A.size();
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

Graph graph;

ll dp[100005][2];

ll dfs(int v, int prev, int c) {
    if (dp[v][c]) return dp[v][c];
    ll res = 1;
    for (int u : graph[v]) {
        if (prev != u) {
            if (c == 1) {
                res *= (dfs(u, v, 1) + dfs(u, v, 0)) % MOD;
            } else {
                res *= dfs(u, v, 1);
            }
            res %= MOD;
        }
    }
    return dp[v][c] = res % MOD;
}

void Main() {
    int N;
    cin >> N;
    graph.resize(N);
    rep(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    cout << (dfs(0, -1, 0) + dfs(0, -1, 1)) % MOD << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    char a, b;
    cin >> a>>b;
    string ans = "H";
  if((a=='H')^(b=='H')) ans="D";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_2-C
 
#include <cstring>
#include <iostream>

struct card {
  char mark;
  unsigned int number;
};

static void print_cards(const card cards[], const unsigned int n) {
  const char* sep = "";
  for (unsigned int i = 0; i < n; ++i) {
    const card* const cardp = &cards[i];
    std::cout << sep << cardp->mark << cardp->number;
    sep = " ";
  }
  std::cout << std::endl;
}

static void swap(card* a, card* b) {
  card tmp = *a;
  *a = *b;
  *b = tmp;
}

void bubble_sort(card cards[], const unsigned int n) {
  for (unsigned int j = 0; j < n-1; ++j) {
    for (unsigned int i = n-1; i > j; --i) {
      if (cards[i-1].number > cards[i].number) {
        swap(&cards[i-1], &cards[i]);
      }
    }
  }
}
 
void selection_sort(card cards[], const unsigned int n) {
  for (unsigned int i = 0; i < n-1; ++i) {
    unsigned int min_j = i;
    for (unsigned int j = i+1; j < n; ++j) {
      if (cards[min_j].number > cards[j].number) {
        min_j = j;
      }
    }
    if (i != min_j) {
      swap(&cards[i], &cards[min_j]);
    }
  }
}
 
int main(void) {
  unsigned int n;
  std::cin >> n;
  card cards1[n], cards2[n];
  for (unsigned int i = 0; i < n; ++i) {
    std::cin >> cards1[i].mark;
    std::cin >> cards1[i].number;
  }
  std::memcpy(cards2, cards1, sizeof(cards1));

  bubble_sort(cards1, n);
  print_cards(cards1, n);
  std::cout << "Stable" << std::endl; // bubble sort is stable

  selection_sort(cards2, n);
  print_cards(cards2, n);
  if (std::memcmp(cards1, cards2, sizeof(cards1)) == 0) {
    std::cout << "Stable" << std::endl;
  } else {
    std::cout << "Not stable" << std::endl;
  }

  return 0;
}
// end

Measured memory_bytes: 1164
def solve(placed, w1, w2):
  global ans
  n = len(N) - len(placed)
  if n==0:
    ans = min(ans, [w1, placed])
    return

  for e in N:
    if e in placed: continue
    w, lim, s = Food[e]
    if w2 > lim: return
    a = w1 + w * n
    if a > ans[0]: return
    solve(placed+[e], a, w2 + w)
  return
 
while 1:
  n = input()
  if n==0: break
  ans = [1e9, []]
  N = range(n)
  f = lambda x: map(int, x[1:3]) + [x[0]]
  Food = [f(raw_input().split()) for _ in [0]*n]
  solve([], 0, 0)
  for e in ans[1][::-1]:
    print Food[e][2]

Measured memory_bytes: 4280
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define y0 u9cqu3jioajc

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

int n, a[100111];
int f[100111];

bool solve() {
    int sum = 0; FOR(i,1,n) sum += a[i];
    int each = n * (n+1LL) / 2;

    if (sum % each) return false;

    int d = sum / each;

    int sumAt = 0;

    a[n+1] = a[1];

    FOR(i,1,n) {
        int u = a[i], v = a[i+1];

        int t = v - u - d;

        if (t % n) return false;

        int at = -t / n;
        if (at < 0) return false;
        sumAt += at;
    }
    return sumAt == d;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (GI(n) == 1) {
        FOR(i,1,n) GI(a[i]);
        cout << (solve() ? "YES" : "NO") << endl;
        break;
    }
}


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

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

    int ans = 1e9;
    rep(off, s.size() - t.size() + 1) {
        int now = 0;
        rep(i, t.size()) {
            if (s[off + i] != t[i])
                now++;
        }
        ans = min(ans, now);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
flag = 1
for i in a:
    if i[0] < i[1] + i[2]:
        flag = 0
    elif i[0] % 2 != (i[1] + i[2]) % 2:
        flag = 0
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27300