akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  long long n;
  cin >> n;
  long long a[n],ans[n];
  pair<ll, ll> p[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    p[i]=make_pair(a[i],i);
  }
  sort(p,p+n);
  for(int i=0;i<n;i++){
    if(i<n/2){
      ans[p[i].second]=p[n/2].first;
    }else{
      ans[p[i].second]=p[n/2-1].first;
    }
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 8448
A = int(input())
B = int(input())
C = int(input())
X = int(input())

answer = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      total = 500 * i + 100 * j + 50 * k
      if total == X:
        answer += 1
print(str(answer))

Measured memory_bytes: 9172
#include<stdio.h>
int solve(int,int);
int A[20],n;

int main(){
  int q,m[200],i,flag;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&m[i]);

  for(i=0;i<q;i++){
  flag = solve(0,m[i]);
  if(flag == 0) printf("no\n");
  if(flag == 1) printf("yes\n");
  }
  
  return 0;
}
int solve(int i,int m){
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}



Measured memory_bytes: 2108
#!/usr/bin/env python3
import collections as cl
import sys
import copy


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


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


class Maze:
    def __init__(self, base_map, H, W):
        self.H = H
        self.W = W
        self.maze = base_map

        reachable = []
        for i in range(self.H):
            for j in range(self.W):
                reachable.append([i, j])

        self.reachable = reachable

    def solve(self):
        ans = 0
        for start in self.reachable:
            max_cost = self.calc_cost(start)
            ans = max(ans, max_cost)

        print(ans)

    def isNotReachable(self, i, j):
        return i < 0 or i >= self.H or j < 0 or j >= self.W or self.maze[i][j] == -1

    def calc_cost(self, start):
        costs = copy.deepcopy(self.maze)
        deque = cl.deque([])
        deque.append(start)
        ways = [[1, 0], [-1, 0], [0, 1], [0, -1]]
        visited = [[False for j in range(self.W)] for i in range(self.H)]
        visited[start[0]][start[1]] = True

        while len(deque) > 0:
            cur_point = deque.popleft()
            i, j = cur_point[0], cur_point[1]
            for way in ways:
                next_i = i + way[0]
                next_j = j + way[1]
                if self.isNotReachable(next_i, next_j) or visited[next_i][next_j]:
                    continue
                visited[next_i][next_j] = True
                costs[next_i][next_j] = costs[i][j] + 1
                deque.append([next_i, next_j])
        max_cost = 0
        for row in costs:
            max_cost = max(max_cost, *row)
        return max_cost


def main():
    H, W = MI()
    base_map = []
    for _ in range(H):
        row = input()
        row_in_num = []
        for j in range(len(row)):
            if row[j] == ".":
                row_in_num.append(0)
            else:
                row_in_num.append(-1)

        base_map.append(row_in_num)

    maze = Maze(base_map, H, W)
    maze.solve()


main()


Measured memory_bytes: 78212
from math import sqrt

N, D = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
cou = 0
for i in range(N):
    for j in range(N):
        ans = 0
        if i == j:
            continue
        for k in range(D):
            ans += abs(L[i][k] - L[j][k]) ** 2
        if sqrt(ans).is_integer():
            cou += 1
print(int(cou/2))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string.h>

using namespace std;

struct TeamData{
	int cn;
	int pnp;
	int pn[10];
};

struct ansData{
	int tn;
	int same;
};

vector<vector<ansData> > ans;

int main(){
	while(1){
		int M,T,P,R;
		cin >> M >> T >> P >> R;
		if(M+T+P+R == 0) break;
		TeamData td[50];
		
		memset(td,0,sizeof(td));
		
		for(int i = 0;i < R;i++){
			int m,t,p,j;
			cin >> m >> t >> p >> j;
			if(j == 0){
				td[t - 1].cn++;
				td[t - 1].pnp += td[t - 1].pn[p - 1] * 20 + m;
			}else{
				td[t - 1].pn[p - 1]++;
			}
		}
		
		
		int index[50];
		for(int i = 0;i < 50;i++) index[i] = i;
		
		for(int i = 0;i < T;i++){
			int now = index[i];
			for(int j = T-1;j > i;j--){
				int target = index[j];
				if(td[now].cn < td[target].cn){
					index[i] = target;
					index[j] = now;
					now = target;
				}else if(td[now].cn == td[target].cn){
					if(td[now].pnp > td[target].pnp){
						index[i] = target;
						index[j] = now;
						now = target;
					}else if(td[now].pnp == td[target].pnp){
						if(now < target){
							index[i] = target;
							index[j] = now;
							now = target;
						}
					}
				}
			}
		}

		vector<ansData> tans;
		
		for(int i=0;i<T;i++){
			ansData ad;
			ad.tn = index[i]+1;
			if(i == 0){
				ad.same = 0;
			}else{
				if((td[index[i]].cn == td[index[i-1]].cn) && (td[index[i]].pnp == td[index[i-1]].pnp)){
					ad.same = 1;
				}else ad.same = 0;
			}
			tans.push_back(ad);
		}
		ans.push_back(tans);
	}
	for(int i = 0;i < ans.size();i++){
		for(int j = 0;j < ans[i].size();j++){
			if(j == 0){
				cout << ans[i][j].tn;
			}else{
				if(ans[i][j].same == 0){
					cout << "," << ans[i][j].tn;
				}else{
					cout << "=" << ans[i][j].tn;
				}
			}
		}cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3120
#include<iostream>

using namespace std;

int main(){
  string in;
  // while(cin >> in){
  cin >> in;
  int num[3] = {0,0,0};
  int lev = 0;
  int status = 3;
  for(int i = 0; i < in.length(); i++){
    if(in[i] == 'J'){
      //cout << num[0] << " " << num[1] << " " << num[2] << endl;
      if(status != 0) num[0] = num[1] = num[2] = 0;
      num[0]++;
      status = 0;
      continue;
    }
    if(in[i] == 'O' && (status == 0 || status == 1)){
      num[1]++;
      status = 1;
      continue;
    }
    if(in[i] == 'I' && (status == 1 || status == 2)){
      num[2]++;
      status = 2;
      if(num[1] <= num[0] && num[1] <= num[2]) lev = max(lev,num[1]);
      continue;
    }
    status = 3;
  }
  cout << lev << endl;
  // }
  return 0;
}

Measured memory_bytes: 1984
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
inline int read()
{int x=0,f=0;
char c=getchar();
while (c<'0'||c>'9') 
{if (c=='-') f=1;
c=getchar();
}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
if (f) x=-x;
return x;
}
int main (){
	int i,lx=0,ly=0,lt=0;
	int x,y,t,n;
	n=read();
	for (i=1;i<=n;i++)
	{t=read();x=read();y=read();
	int dis=abs(x-lx)+abs(y-ly);
	int del=t-lt-dis;
	if (del<0||(del&1)) {puts("No");return 0;}
	lx=x;ly=y;lt=t;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a,b = [],[]
for _ in [0]*n:
  a += [list(map(int,input().split()))]
a.sort()
for _ in [0]*n:
  b += [list(map(int,input().split()))]
b.sort(key=lambda s:s[1])
c = 0
for t in a[::-1]:
  for s in b:
    if t[0]<s[0] and t[1]<s[1]:
      c += 1
      b.remove(s)
      break
print(n-len(b))

Measured memory_bytes: 3064
"""
dp[i][j] => i回目の移動が終了したタイミングでj列目にいる場合の数
dp[i][j] 
= dp[i-1][j-1]*(j-1列目とj列目の間に横棒があるような横棒の配置パターン数)
+ dp[i-1][j+1]*(j+1列目とj列目の間に横棒があるような横棒の配置パターン数)
+ dp[i-1][j]*(j列目の両サイドに横棒がないような横棒の配置パターン数)
"""

H,W,K = map(int,input().split())
mod = 10**9 +7

"""
横棒の配置パターンを前計算しておく
patternA[i] => i列目とi-1列目の間に横棒があるような横棒の配置パターン数
patternB[i] => i列目の両サイドに横棒がないような横棒の配置パターン数
"""
patternA = [0]*(W)
patternB = [0]*(W)
for i in range(2**(W-1)):
    pattern = format(i,"0"+str(W-1)+"b")
    for j in range(1,W-1):
        if pattern[j] == "1" and pattern[j-1]=="1":
            break
    else:
        for j in range(W-1):
            if pattern[j] == "1":
                patternA[j+1] += 1

        for j in range(W):
            if j == 0:
                if pattern[j] == "0":
                    patternB[j] += 1
            elif 0 < j < W-1:
                if pattern[j-1] == "0" and pattern[j] == "0":
                    patternB[j] += 1
            elif j == W-1:
                if pattern[j-1] == "0":
                    patternB[j] += 1

dp = [[0]*W for _ in range(H+1)]
dp[0][0] = 1

for i in range(1,H+1):
    for j in range(W):
        #左上から降りてくるパターン
        if j > 0:
            dp[i][j] += dp[i-1][j-1]*patternA[j]%mod
        #右上から降りてくるパターン
        if j < W-1:
            dp[i][j] += dp[i-1][j+1]*patternA[j+1]%mod
        
        #真上から降りてくるパターン
        dp[i][j] += dp[i-1][j]*patternB[j]%mod

        dp[i][j] %= mod

print(dp[-1][K-1])


Measured memory_bytes: 63160
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int P[10001];

void init(int n) {
	for (int i = 0; i <= n; i++)
		P[i] = i;
}

int root(int a) {
	if (P[a] == a)
		return a;
	return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b) {
	return root(a) == root(b);
}

void unite(int a, int b) {
	P[root(a)] = root(b);
}

bool span(int n) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (!is_same_set(i, j))
				return false;
		}
	}
	return true;
}

int main() {
	int n;
	cin >> n;
	init(n);
	vector<vector<int> > map(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> map[i][j];
		}
	}
	vector<pair<int, pair<int, int> > > edges;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++) {
			if (map[i][j] >= 0)
				edges.push_back(pair<int, pair<int, int> >(map[i][j], pair<int, int>(i, j)));
		}
	}
	sort(edges.begin(), edges.end());
	int result = 0;
	while (!span(n)) {
		pair<int, pair<int, int> > edge = edges.front();
		edges.erase(edges.begin());
		int a = edge.second.first;
		int b = edge.second.second;
		if (!is_same_set(a, b)){
			unite(a, b);
			result += edge.first;
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 1344
import sys

input = sys.stdin.readline


def main():
    X, N = list(map(int, input().split(" ")))
    if N == 0:
        print(X)
        exit(0)
    arr = list(map(int, input().split(" ")))
    if X not in arr:
        print(X)
        exit(0)

    arr.sort()
    for i in range(len(arr)):
        if arr[i] >= X:
            diff = 1
            while True:
                if X - diff not in arr:
                    print(X - diff)
                    exit(0)
                if X + diff not in arr:
                    print(X + diff)
                    exit(0)
                diff += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 61980
from collections import deque

N, M = map(int, input().split())
edge = [[] for i in range(N)]
for i in range(M):
    u, v = map(int, input().split())
    edge[u-1].append(v-1)
S, T = map(int, input().split())
S, T = S-1, T-1

INF = float('inf')
dist = [[INF for i in range(3)] for j in range(N)]

def bfs():
    q = deque()
    q.append((S, 0))
    dist[S][0] = 0
    while q:
        p = q.popleft()
        v = p[0]
        l = p[1]
        for nv in edge[v]:
            nl = (l+1)%3
            if dist[nv][nl] != INF:
                continue
            dist[nv][nl] = dist[v][l] + 1
            q.append((nv, nl))
    return dist[T][0]

ans = bfs()
if ans == INF:
    ans = -1
else:
    ans = ans // 3
print(ans)

Measured memory_bytes: 82336
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = getLine >>= print . solve . map read . words
solve :: [Integer] -> Integer
solve (n:m:k:_) = otherPatterns `modmul`
  ( foldl' (modadd) 0 [ d * (dxPatterns d) | d <- [1..(n - 1)] ]
  + foldl' (modadd) 0 [ d * (dyPatterns d) | d <- [1..(m - 1)] ]
  )
  where
    otherPatterns = select (n * m - 2) (k - 2)
    dxPatterns d = (n - d) * power m 2
    dyPatterns d = (m - d) * power n 2

cost a b = abs $ a - b

-- cost = 
--   where
--     go [] = 0
--     go (a:as) = (sum $ map (calc a) as) + go as
--     calc (x, y) (a, b) = abs (x - a) + abs (y - b)



divConst = 10^9 + 7 :: Integer
modadd x y = (x + y) `mod` divConst
modsub x y = (x - y) `mod` divConst
modmul x y = ((x `mod` divConst) * (y `mod` divConst)) `mod` divConst
moddiv x y = modmul x (power y (divConst - 2))
power x y
  | y == 0 = 1
  | y == 1 = x `mod` divConst
  | y `mod` 2 == 0 = (power x (y `div` 2))^2 `mod` divConst
  | otherwise = (power x (y `div` 2))^2 * x `mod` divConst

-- 階乗 n!
factorial :: Integer -> Integer
factorial n = foldr modmul 1 [1..n]

-- n! / m!
fact :: Integer -> Integer -> Integer
fact n m = foldr modmul 1 [(m+1)..n]


-- nCk = n! / (k! * (n - k)!)
-- n個からk個えらぶ
select :: Integer -> Integer -> Integer
select n k = foldl' moddiv (fact n (n - k)) [1..k]


Measured memory_bytes: 9596
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, k;
    cin >> n >> k;

    if (k==1) {
        cout << 0 << endl;
    }
    else {
        cout << n - (k - 1) - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	string s;
	cin >> s;
	int n = s.length();
	int ans = 1e9;
	for(int i = 0;i < n - 2;++i){
		int num = stoi(s.substr(i,3));
		ans = min(ans,abs(num - 753));
	}
	cout << ans << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, Q;
    cin >> N >> Q;
    vec<vec<int>> G(N,vec<int>());
    
    rep(i, N-1) {
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    vec<ll> p(N);
    rep(i, Q) {
        int index,x;
        cin >> index >> x;
        --index;
        p[index] += x;
    }

    function<void(int,int)> dfs = [&](int now, int par){
        if(par != -1) p[now]+=p[par];
        for(auto e:G[now]){
            if(e == par) continue;
            dfs(e,now);
        }
    };
    dfs(0,-1);

    rep(i,N) {
        cout << p[i] << " ";
    }
    cout << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll cnt = 0;
  for (ll i = X; i <= Y; i*=2) {
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
    int n;
    int a[110];
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i];
    
    int min = a[0], max = a[0];
    for(int i = 0; i < n; ++i) {
        if(min > a[i]) min = a[i];
        if(max < a[i]) max = a[i];
    }
    
    cout << max - min << endl;
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if p[i-1]<=p[i]<=p[i+1]:
        ans+=1
    if p[i+1]<=p[i]<=p[i-1]:
        ans+=1
print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <string>
 
int main() {
  std::string a;
  std::cin >>a;
  
  std::string ss[19];
  for(int i=0;i < 19;i++){
    ss[i] = a.substr(i,1);
    if(ss[i] ==","){
      ss[i] =" ";
    }
    std::cout << ss[i];
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100100;
LL n,x;
struct E{
	LL b,l,u;
	E(){}
	E(LL _b,LL _l,LL _u){
		b=_b;
		l=_l;
		u=_u;
	}
	inline LL val()const{
		return b*l+u*(x-b);
	}
	inline LL de(LL rest)const{
		if(rest<=0)return 0;
		if(l*b>=rest)return (rest-1)/l+1;
		else return b+(rest-l*b-1)/u+1;
	}
	bool operator<(const E o)const{
		return val()>o.val();
	}
};

E es[N];
LL pf[N];

int main(){
	scanf("%lld%lld",&n,&x);
	LL delta=0;
	LL ans=LONG_LONG_MAX;
	for(int i=0;i<n;i++){
		LL b,l,u;
		scanf("%lld%lld%lld",&b,&l,&u);
		es[i]=E(b,l,u);
		delta+=(LL)b*l;
	}
	sort(es,es+n);
	for(int i=0;i<n;i++){
		pf[i]=es[i].val();
		if(i)pf[i]+=pf[i-1];
	}
	for(int i=0;i<n;i++){
		int l=-1,r=n-1;
		LL qq=delta-es[i].val();
		LL cc;
		// cerr<<i<<endl;
		while(l<r){
			int mid=(l+r)>>1;
			// cerr<<l<<" "<<r<<endl;
			cc=mid==-1?0:pf[mid]-(mid>=i?es[i].val():0);
			// cerr<<cc<<endl;
			if(cc>=qq){
				r=mid;
			}else{
				l=mid+1;
			}
		}
		// cerr<<"l "<<l<<endl;
		cc=l==-1?0:pf[l]-(l>=i?es[i].val():0);
		// cerr<<"cc "<<cc<<endl;
		ans=min(ans,es[i].de(delta-cc)+(l+(l<i?1:0))*x);
	}
	printf("%lld\n",ans);
	return 0;
}

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

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

long long x;

int main(){
    cin >> x;
    long long move = 0;
    for(long long i = 1; i < 1000000000; i++){
        move += i;
        if(move >= x){
            cout << i << endl;
            return 0;
        }
    }
}

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

const int S = 100;
int dp[S + 10][S + 10], is_prime[S + 10];

signed main(){

    fill(is_prime, is_prime + S, true);
    is_prime[0] = is_prime[1] = false;

    vector<int> primes;
    // 篩
    for(int k = 2; k < S; k++){
        if(is_prime[k]){
            primes.push_back(k);
            for(int num = 2 * k; num < S; num += k){
                is_prime[num] = false;
            }
        }
    }

    int n; cin >> n;
    dp[0][1] = 1;
    for(int i = 0; i < primes.size(); i++){
        int x = primes[i];
        int cnt = 0;
        for(int k = 1; k <= n; k++){
            int num = k;
            while(num % x == 0) cnt++, num /= x;
        }
    

        for(int j = 0; j < S; j++){
            for(int k = 1; k <= cnt + 1; k++){
                int nj = j * k;  // 約数の個数の式から
                if(nj > S) continue;
                dp[i + 1][nj] += dp[i][j];
            }
        }
    }

    cout << dp[primes.size()][75] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fast() ios_base::sync_with_stdio (false); cin.tie (NULL)

using namespace std;
const unsigned int MOD = 1e9+7;

int N,K;

void solve () {
    cin >> N;
    vector <int> A(N); vector <int> B(N); vector <int> C(N);
    for (int i=0;i<N;i++) {
        cin >> A[i] >> B[i] >> C[i];
    }
    
    vector <vector <int>> dp(N,vector <int> (3));
    //0->A, 1->B, 2->C
    dp[0][0] = A[0];dp[0][1] = B[0];dp[0][2] = C[0];
    
    for (int i=1;i<N;i++) {
        //choose A
        dp[i][0] = max (dp[i-1][1],dp[i-1][2]) + A[i];
        
        //choose B
        dp[i][1] = max (dp[i-1][0],dp[i-1][2]) + B[i];
        
        //choose C
        dp[i][2] = max (dp[i-1][0],dp[i-1][1]) + C[i];
    }
    
    cout << max ({dp[N-1][0],dp[N-1][1],dp[N-1][2]}) << endl;
    
}

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





Measured memory_bytes: 6912
L, R = map(int, input().split())
i = 2017
j = 2018
i_mod = 2017
j_mod = 2018
end = min(R, L + 4038)

ans = 2018

# for n in range(L, (end + 1)):
#     n_mod = n % 2019
#     if n_mod < i_mod:
#         i, j = n, i
#         i_mod, j_mod = n_mod, i_mod
#     elif n_mod < j_mod:
#         j = n
#         j_mod = n_mod

# print((i * j) % 2019)

for a in range(L, end):
    for b in range(a + 1, end+ 1):
        tmp = (a * b) % 2019
        if tmp < ans:
            ans = tmp

print(ans)


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

int sum_of_digit(int num)
{
    int sum = 0;
    while(num)
    {
        sum+=num%10;
        num/=10;
    }
    return sum;
}

int main()
{
    long int n,a,b,sum=0;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        if(sum_of_digit(i)<=b&&sum_of_digit(i)>=a)
          sum+=i;
    }
    cout<<sum;
}




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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans, b;
    vector<int> dp(n+2);
    
    dp[0] = 0;
    
    for (int i = 0; i <= n; i++) {
        dp[i + 1] = dp[i] + abs(((i == 0) ? 0 : a[i - 1]) - a[i]);
    }
    
    dp[n + 1] = dp[n] + abs(a[n - 1]);
    
    rep(i, n) {
        ans = dp[i] + dp[n + 1] - dp[i + 2] + abs(((i == 0) ? 0 : a[i - 1]) - ((i == (n - 1)) ? 0 : a[i + 1]));
        cout << ans << endl;
    }
     
    return 0;
}

Measured memory_bytes: 2048
n, m = gets.to_s.split.map{|t|t.to_i}
h    = [0] + gets.to_s.split.map{|t|t.to_i}
# d = gets.to_s.to_i
# s = gets.to_s.chomp

ans = [1] * (n+1)
ans[0] = 0

m.times do
  
  a, b = gets.to_s.split.map{|t|t.to_i}
  
  if h[a] < h[b]
    ans[a] = 0
  elsif h[a] > h[b]
    ans[b] = 0
  else
    ans[a] = ans[b] = 0
  end
end

puts ans.sum

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

int main () {
    int r, d, x;
    cin >> r >> d >> x;

    int x1[11];

    for (int i=0 ; i<10 ; i++) {
        if (i==0) {
            x1[i] = (r*x) - d;
        }
        else {
            x1[i] = (r*x1[i-1]) - d;
        }
    }

    for (int i=0 ; i<10 ; i++) {
        cout << x1[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    vector<p>  AB(N);
    rep(i,N){
        int A,B;
        cin >> A >> B;
        AB[i] = p(B,A);
    }
    sort(AB.begin(),AB.end());
    ll nowTime = 0;
    rep(i,N){
        nowTime += AB[i].second;
        if(AB[i].first>=nowTime){
            continue;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 3328
import copy

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

result = max(A)
ind = A.index(result)

for i in range(N):
    if i == ind:
        a = copy.deepcopy(A)
        a.remove(result)
        print(max(a))
    else:
        print(result)




Measured memory_bytes: 14684
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)
N, M, P = map(int,input().split())
es = []
to = defaultdict(list)
rto = defaultdict(list)
rf = [False]*N
rt = [False]*N
for i in range(M):
  a, b, c = map(int, input().split())
  es += [(a-1,b-1,-c+P)]
  to[a-1] += [b-1]
  rto[b-1] += [a-1]

def dfs(v):
  if rf[v]:
    return
  rf[v] = True
  for u in to[v]:
    dfs(u)

def rdfs(v):
  if rt[v]:
    return
  rt[v] = True
  for u in rto[v]:
    rdfs(u)

dfs(0)
rdfs(N-1)
ok = [False]*N
for i in range(N):
  ok[i] = rf[i]&rt[i]

dist = [float('inf')]*N
dist[0] = 0
upd = True
cnt = 0
while upd:
  upd = False
  for j in range(M):
    f, t, c = es[j]
    if (not ok[f]) or (not ok[t]):
      continue
    if dist[t]>dist[f]+c:
      upd = True
      dist[t] = dist[f]+c
  cnt += 1
  if cnt>N:
    print(-1)
    break
else:
  print(max(0,-dist[N-1]))

Measured memory_bytes: 67288
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ", 2);
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);

        if (b % a == 0) {
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }
    }
}


Measured memory_bytes: 22608
from math import log2

n, k = map(int, input().split())
ai   = list(map(lambda x: log2(int(x)), input().split()))

before = sum(ai[ 0 : k ])

for i in range(n - k):
    after = before + ai[i + k] - ai[i]

    if before < after:
        print('Yes')

    else:
        print('No')

    before = after


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

int main() {
    int t;
    cin>>t;
    int a[t];
    for(int i = 0;i<t;i++){
        cin>>a[i];
    }
    int temp = 1;
    int ans = 0;
    for (int i = 1; i < t; i++) {
        if(a[i] == a[i-1]){
            temp ++;
        } else {
            if(temp % 2 == 0){
                ans += temp/2;
            } else {
                ans += (temp-1)/2;
            }
            temp = 1;
        }
    }
    if (temp % 2 == 0) {
        ans += temp / 2;
    } else {
        ans += (temp - 1) / 2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main()
	{
		for (int i = 0; i < 7; i++)//7回繰り返す
		{
		string 入力 = Console.ReadLine();//入力を一行読み込む
string[] 分割された文字列 = 入力.Split(' ');//スペースを基準に分割
int 最高気温 = int.Parse(分割された文字列[0]);//1つ目のデータint型にを変換
int 最低気温 = int.Parse(分割された文字列[1]);//2つ目のデータをint型に変換
Console.WriteLine(最高気温 - 最低気温);//最高気温と最低気温の差を画面に出力
}
	}
}

Measured memory_bytes: 11740
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;


int main(){
    ll n,k,l,r; cin >> n >> k >> l >> r;
    vl a(n); rep(i,n) cin >> a[i];
    vpl fr,ba;
    rep(bit,1<<(n/2)){
        ll s = 0;
        ll cnt = 0;
        rep(i,n) if(bit>>i & 1) s += a[i], cnt++;
        fr.emplace_back(cnt,s);
    }
    rep(bit,1<<(n-n/2)){
        ll s = 0;
        ll cnt = 0;
        rep(i,n-n/2) if(bit>>i & 1) s += a[i+n/2], cnt++;
        ba.emplace_back(cnt,s);
    }
    sort(all(fr)); sort(all(ba));
    ll ans = 0;
    for(auto v : fr){
        if(v.first > k) break;
        ans += upper_bound(all(ba),P(k-v.first,r-v.second)) - lower_bound(all(ba),P(k-v.first,l-v.second));
    }
    cout << ans << endl;
}


Measured memory_bytes: 43720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication45
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                int a = int.Parse(line);
                int b = a % 39;
                if (b == 0)
                    Console.WriteLine("3C39");
                else if (b < 10) Console.WriteLine("3C0{0}", b);
                else Console.WriteLine("3C{0}", b);
            }
        }
    }
}

Measured memory_bytes: 9068
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int t=1e9,n=200000;
  string s;//(n,'A');
  cin>>n>>t>>s; s.reserve(512345);
  if(n==1,0){
    
    return 0;
  }
  int o=0,f=0;
  int sum=0+'A'+'B';
  rep(i,t){
    if(s[o]=='A'+f){
      s[o]=sum-s[o];
    }else{
      ++o;
      f=1-f;
      s+='A'+f;
    }
    //out(f,o,s,o+n,s.size(),1);
    if(o>n && i%2!=t%2) break;
  }
  rep(i,n) cout<<char(f?sum-s[o+i]:s[o+i]); cout<<endl;
  return 0;
}


Measured memory_bytes: 980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s;
    string tmp;
    for (int i = 0; i < h; i++)
    {
        cin >> tmp;
        s.push_back(tmp);
    }
    for (int i = 0; i < h; i++)
    {
        cout << s[i] << endl;
        cout << s[i] << endl;
    }
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}


int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vi a(n);
  REP(i, n) cin >> a[i];
  sort(ALL(a));
  reverse(ALL(a));

  int mi = a[1];
  FOR(i, 1, n-1) {
    if(abs(a[0]/2 - a[i]) <= abs(a[0]/2 - a[i+1])) {
      mi = a[i];
      break;
    }
  }

  cout << a[0] << " " << mi << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  int ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(a[i]!=a[j]&&a[j]!=a[k]){
          if(a[k]<a[i]+a[j]){
            ans++;
          }
        }
      }
    }
  }
  cout<< ans<< endl;
}

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

using namespace std;

#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz(x) ((int)(x).size())

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

const int N = 1e5 + 5;

int a[] = {1, 3, 5, 7, 8, 10, 12};
int b[] = {4, 6, 9, 11};

int group(int x) {
	if(x == 2) return 3;
	for(int i = 0; i < 7; ++i) if(a[i] == x) return 1;
	for(int i = 0; i < 4; ++i) if(b[i] == x) return 2;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	if(group(x) == group(y))
		cout << "Yes\n";
	else
		cout << "No\n";


	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    char c[] = {'S','W'};
    rep(i,2){
        rep(j,2){
            string t;
            t += c[i];
            t += c[j];
            for(int k = 1; k < n - 1; k++){
                if(t[k] == 'S'){
                    if(s[k] == 'o'){
                        t += t[k-1];
                    }else{
                        rep(_,2)if(t[k-1]!=c[_])t += c[_];
                    }
                }else{
                    if(s[k] != 'o'){
                        t += t[k-1];
                    }else{
                        rep(_,2)if(t[k-1]!=c[_])t += c[_];
                    }
                }
            }
            bool f = true;
            if(t[n-1] == 'S'){
                if(s[n-1] == 'o')f &= t[n-2] == t[0];
                else f &= t[n-2] != t[0];
            }else{
                if(s[n-1] != 'o')f &= t[n-2] == t[0];
                else f &= t[n-2] != t[0];
            }
            if(t[0] == 'S'){
                if(s[0] == 'o')f &= t[n-1] == t[1];
                else f &= t[n-1] != t[1];
            }else{
                if(s[0] != 'o')f &= t[n-1] == t[1];
                else f &= t[n-1] != t[1];
            }
            if(f){
                cout << t << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

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

int main(){
    int n,t;
    cin>>n>>t;
    int res=1e9;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(b<=t) res=min(res,a);
    }
    if(res==1e9){
        cout<<"TLE"<<endl;
    }
    else{
        cout<<res<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define N 15
using namespace std;
int main(){
	int n,d,x[N][N],i,j,k,p,sum,ans=0;
	cin>>n>>d;
	for(i=0;i<n;i++)
	{
		for(j=0;j<d;j++)
		{
			cin>>x[i][j];
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			sum=0;
			for(k=0;k<d;k++)
			{
				p=x[i][k]-x[j][k];
				sum+=p*p;
			}
			p=sqrt((double)sum);
			while(p*p<sum)
			{
				p++;
			}
			if(p*p==sum)
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
A = [int(a) for a in input().split()]

import heapq

h = []
for i in range(N):
    heapq.heappush(h, A[i]*(-1))
    
for i in range(M):
    temp = heapq.heappop(h)
    temp *= (-1)
    temp //= 2
    temp *= (-1)
    heapq.heappush(h, temp)
    
print(sum(h)*(-1))

Measured memory_bytes: 14252
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=len(a)
a=dict(Counter(a))
count=0
a = sorted(a.items(), key=lambda x:x[1], reverse=True)
for i,j in a:
  count+=1
  ans-=j
  if count==k:
    break
print(ans)

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

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

  int n;
  cin >> n;
  int r, t;
  for(int i = 0;i < n;++i){
    cin >> r >> t;

    if(r % 100 == 0 && t % 30 == 0){
      cout << 5 * (t / 30) + r / 100 << endl;
    }
    else if(r % 100 == 0){
      cout << 5 * (t / 30) + r / 100 << ' ';
      cout << 5 * ((t + 30) / 30) + r / 100 << endl;
    }
    else if(t % 30 == 0){
      cout << 5 * (t / 30) + r / 100 << ' ';
      cout << 5 * (t / 30) + (r + 100) / 100 << endl;
    }
    else{
      cout << 5 * (t / 30) + r / 100 << ' ';
      cout << 5 * (t / 30) + (r + 100) / 100 << ' ';
      cout << 5 * ((t + 30) / 30) + r / 100 << ' ';
      cout << 5 * ((t + 30) / 30) + (r + 100) / 100 << endl;
    }
  }

  return 0;
}
 


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>

using namespace std;

const int imax = numeric_limits<int>::max();

class Solve {
    vector<int> heights;
    vector<int> costs;
    int count;
    int max_step;
public:
    Solve(const vector<int> hs, const int max_s): heights(hs), max_step(max_s) {
        count = hs.size(); 
        costs = vector<int>(count, -1);
        costs[0] = 0;
        costs[1] = abs(heights[1] - heights[0]);
    }

    int cost_of(const int index) {
        if (costs[index] >= 0) {
            return costs[index];
        }

        int min_index = max(0, index - max_step);
        int min_cost = imax;
        int current = heights[index];
        for (int i = min_index; i < index; ++i) {
            int cost = cost_of(i) + abs(heights[i] - current);
            if (min_cost > cost) {
                min_cost = cost;
            }
        }
        
        costs[index] = min_cost;
        return costs[index];
    }

    int cost_of_last() {
        return cost_of(count - 1);
    }
};

int main() {
    int count, max_step;
    cin >> count >> max_step;
    vector<int> heights;
    for (int i = 0; i < count; ++i) {
        int height;
        cin >> height;
        heights.push_back(height);
    }

    Solve s(heights, max_step);
    cout << s.cost_of_last();

    return 0;
}

Measured memory_bytes: 4208
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K) = Slice2<long>();
            var KKB = new long[K, K];
            var KKW = new long[K, K];
            for (var i = 0; i < N; ++i)
            {
                var xyc = ReadLine().Split();
                var x = long.Parse(xyc[0]);
                var y = long.Parse(xyc[1]);
                var c = xyc[2][0] == 'B';
                var rev = false;
                if ((x / K % 2) != 0) rev = !rev;
                if ((y / K % 2) != 0) rev = !rev;
                x = x % K;
                y = y % K;
                c = rev ? !c : c;
                if (c)
                    ++KKB[x, y];
                else
                    ++KKW[x, y];
            }
            var ruiB = new long[K + 1, K + 1];
            var ruiW = new long[K + 1, K + 1];
            for (var i = 1; i <= K; ++i)
                for (var j = 1; j <= K; ++j)
                {
                    ruiB[i, j] = KKB[i - 1, j - 1] + ruiB[i, j - 1] + ruiB[i - 1, j] - ruiB[i - 1, j - 1];
                    ruiW[i, j] = KKW[i - 1, j - 1] + ruiW[i, j - 1] + ruiW[i - 1, j] - ruiW[i - 1, j - 1];
                }
            var ans = 0L;
            for (var i = 0; i <= K; ++i)
                for (var j = 0; j <= K; ++j)
                {
                    var num = 0L;
                    num += ruiB[K, K] - ruiB[i, K] - ruiB[K, j] + 2 * ruiB[i, j];
                    num += ruiW[i, K] + ruiW[K, j] - 2 * ruiW[i, j];
                    ans = Max(ans, Max(num, N - num));
                }
            WriteLine(ans);
        }
        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 77144
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;

int main(){
      
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
    
       int n,m,sum=0,t;
       cin >> n>>m;
       for(int i=0;i<m;i++){
        cin >> t;
        sum+=t;
       }
       if(sum>n)
        cout << "-1";
      else{
        cout << n-sum;
      }
}

Measured memory_bytes: 3164
// Aizu Vol-0 0069: Drawing Lots II
// 2017.8.6

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p) || *p == ',') p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int a[32][10], N, D;
int s[32][10];

int main()
{
	int i, j, k, n, m;

	while (1) {
		gets(buf); N = atoi(buf); if (!N) break;
		gets(buf); m = atoi(buf);
		gets(buf); n = atoi(buf);
		gets(buf); D = atoi(buf);
		memset(a, 0, sizeof(a)), memset(s, 0, sizeof(s));
		for (i = 1; i <= D; i++) {
			gets(p = buf); while (isspace(*p)) p++;
			for (j = 1; j < N; j++) a[i][j] = (*p++ == '1');
		}
		for (j = 1; j <= N; j++) s[D+1][j] = j;
		for (i = D; i > 0; i--) {
			for (j = 1; j <= N; j++) s[i][j] = s[i + 1][j];
			for (j = 1; j < N; j++) {
				if (a[i][j]) k = s[i][j], s[i][j] = s[i][j + 1], s[i][j + 1] = k;
			}
		}
		if ((k = s[1][m]) == n) puts("0");
		else {
			for (i = 1; i <= D; i++) {
				for (j = 1; j < N; j++) {
					if (((s[i][j] == k && s[i][j + 1] == n) || (s[i][j] == n && s[i][j + 1] == k))
						&& a[i][j-1] == 0 && a[i][j] == 0 && a[i][j + 1] == 0) {
					printf("%d %d\n", i, j); goto Done; }
				}
			}
			puts("1");
		}
	Done:;
	}
	return 0;
}

Measured memory_bytes: 532
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n, k;
	cin >> n >> k;
	long long ans=pow(n/k,3);
	if(k/2<=n && !(k%2))
		ans+=pow((n-k/2)/k+1,3);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  string s;
  cin >> s;

  lint a = 0, ans = 0;
  rep(i, s.size()) {
    if (s.substr(i, 3) == "ABC") {
      ans++;
      ans += a;
      a++;
      i += 2;
    } else if (s[i] == 'A') {
      a++;
    } else if (s.substr(i, 2) == "BC") {
      if (0 < a) ans += a;
      i++;
    } else {
      a = 0;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
	int N, Y;
	cin >> N >> Y;

	int sum;
	for(int i=0; i<=N; i++){
		for(int j=0; j<=N-i; j++){
			int k=N-i-j;
			sum = 10000*i + 5000*j + 1000*k;		
			//cout << i << " " << j << " " << k << " " << sum <<endl;
			if(sum==Y){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	
	cout << "-1 -1 -1" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 1; i <= (ll)c; i++)
#define ll long long
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
const int inf = 1000000000; // 10^9

int main(){
    ll n, m, a[11000], cnt = 0;
    cin >> n >> m;
    rep(i, m){
        cin >> a[i];
        cnt += a[i];
    }
    n -= cnt;

    if(n < 0) cout << -1 << endl;
    else cout << n << endl;


    return 0;
}

Measured memory_bytes: 3660