akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

template<int MOD> struct Fp {  
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint  dp[10010][110][2];

signed main(){
	//cout << fixed << setprecision(10);
	string s; cin >> s;
	int m; cin >> m;
	int n = s.size();
	dp[0][0][0] = 1;
	rep(i,0,n)rep(j,0,m)rep(k,0,2){
		int now = s[i] - '0';
		rep(d,0,10){
			int ni = i + 1 , nj = (j + d) % m , nk = k;
			if(nk == 0){
				if(d > now) continue;
				if(d < now) nk = 1;
			}
			dp[ni][nj][nk] += dp[i][j][k];
		}
	}
	cout << dp[n][0][0] + dp[n][0][1] - 1 << endl;

	return 0;
}

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

#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)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;

ll mod(ll a, ll b){
  a %= b;
  return a < 0 ? a + b : a;
}

ll powmod(ll a, ll b){
  if(b == 0) return 1;
  if(b & 1) {
    return a * powmod(a, b - 1) % MOD;
  } else {
    ll d = powmod(a, b / 2) % MOD;
    return d * d % MOD;
  }
}

ll sub(ll a, ll b){
  a %= MOD, b %= MOD;
  a -= b;
  return a < 0 ? a + MOD : a;
}


ll inv(ll a){
	return powmod(a, MOD - 2);
}

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

	ll n;
	cin >> n;

	ll a[n];
	rep(i, n) cin >> a[i];

	ll fact_n = 1;
	// fact_n = 1 * 2 * ... * n
	for(ll i = 1; i <= n; i++){
		fact_n *= i;
		fact_n %= MOD;
	}
	// cout << fact_n << endl;

	ll invs[n+1];
	// invs[i] = 1/i
	for(ll i = 1; i <= n; i++){
		invs[i] = inv(i);
	}

	ll s[n];
	// s[i] = 1/1 + 1/2 + ... + 1/(i+1)
	s[0] = 1;
	for(ll i = 1; i < n; i++){
		s[i] = s[i-1] + invs[i+1];
		s[i] %= MOD;
	}

	ll ans = 0;
	rep(i, n){
		ans += (s[i] + s[n-1-i] - 1) * a[i];
		ans %= MOD;
		// cout << i << " " << ((s[i] + s[n-1-i] - 1) * a[i]) % MOD << endl;
	}
	ans *= fact_n;
	ans %= MOD;

	cout << ans << endl;
}


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

void fnTrace(vector<int> argviSort)
{
  for (int i = 0; i < argviSort.size(); i++)
  {
    if (i) cout << " ";
    cout << argviSort[i];
  }
  cout << endl;
}

void fnInsertionSort(vector<int> &argviSort)
{
  for (int i = 1; i < argviSort.size(); i++)
  {
    int iTarget = argviSort[i];
    int j = i - 1;
    while (iTarget < argviSort[j] &&
           j       >= 0            )
    {
      argviSort[j + 1] = argviSort[j];
      j--;
    }
    argviSort[j + 1] = iTarget;
    fnTrace(argviSort);
  }
}

int main()
{
  vector<int> viSort;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iNum;
    cin >> iNum;
    viSort.push_back(iNum);
  }

  fnTrace(viSort);
  fnInsertionSort(viSort);

  return 0;
}

Measured memory_bytes: 1220
n = int(input())
s = [input() for i in range(n)]

cnt = 0

def is_symmetry():
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return False
    return True

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry():
        cnt += 1

print(cnt*n)

Measured memory_bytes: 3064
N, A, B, C = map(int, input().split())
l_list = [int(input()) for _ in range(N)]

INF = 10 ** 5

def dfs(current, a, b, c):
    if current == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return INF

    ret0 = dfs(current + 1, a, b, c)
    ret1 = dfs(current + 1, a + l_list[current], b, c) + 10
    ret2 = dfs(current + 1, a, b + l_list[current], c) + 10
    ret3 = dfs(current + 1, a, b, c + l_list[current]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import sys
from collections import defaultdict
from collections import deque
from copy import deepcopy

def perm(h,r):
    n=len(r)
    stack=[]
    if n==0:
        return [h]
    for i in range(n):
        nh=h+[r[i]]
        nr=r[:i]+r[i+1:]
        stack+=perm(nh,nr)
    return stack
        
def main():
    n,m=map(int,input().split())
    e=[tuple(map(int,input().split())) for _ in range(m)]
    gm=[[0]*n for _ in range(n)]
    for edge in e:
        gm[edge[0]-1][edge[1]-1]=1
        gm[edge[1]-1][edge[0]-1]=1
    l=perm([],list(range(2,n+1)))
    c=0
    for s in l:
        s=[1]+s
        f=1
        for i in range(n-1):
            if gm[s[i]-1][s[i+1]-1]==0:
                f=0
                break
        if f:
            c+=1
    print(c)

if __name__=='__main__':
    main()


Measured memory_bytes: 10164
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;cin>>N;
    vector<int> A,B,C;
    vector<long long> Ma,Mb,Mc;

    for(int i=0;i<N;i++){
        int a,b,c; cin>>a>>b>>c;
        A.push_back(a);
        B.push_back(b);
        C.push_back(c);
    }

    Ma.push_back(A[0]);
    Mb.push_back(B[0]);
    Mc.push_back(C[0]);
    for(int i=1;i<N;i++){
        Ma.push_back(max(Mb[i-1]+A[i],Mc[i-1]+A[i]));
        Mb.push_back(max(Ma[i-1]+B[i],Mc[i-1]+B[i]));
        Mc.push_back(max(Ma[i-1]+C[i],Mb[i-1]+C[i]));
    }

    cout << max(Ma[N-1],max(Mb[N-1],Mc[N-1]));


    return 0;
}


Measured memory_bytes: 3936
import java.util.*;

public class Main {

    int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        char[] a = A.toCharArray();
        Arrays.sort(a);
        long c = 1;
        long ans = 0;
        for (int i = 1; i < (long) A.length(); i++) {
            if (a[i] != a[i - 1]) {
                ans += (c * (c - 1)) / 2;
                c = 1;
            } else {
                c++;
            }
        }
        ans += (c * (c - 1)) / 2;
        System.out.println(((long) A.length() * ((long) A.length() - 1)) / 2 - ans + 1);
    }
}


Measured memory_bytes: 28048
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; cnt = 0; ansli = []; tmpli = []; candili = []; stillset = set()
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def s_list(): return list(input())
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]#NumberGrid
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def grid(n): return [s_list() for _ in range(n)]

n = i()
d = wi()

time = [[] for _ in range(13)]

for t in d:
    time[t].append(t)

for idx, kosu in enumerate(time):
    if len(kosu) >= 3:
        print(0)
        exit()

if n > 11:
    if len(time[0]) >= 1 or len(time[12]) > 1:
        print(0)
        exit()
    else:
        print(1)
        exit()

time = functools.reduce(lambda a, b: a + b, time)
ans = INF; A = 0

for ti in itertools.product([0, 1], repeat=len(time)):  # 11**2
    kyu = []
    for kk in range(len(ti)):
        if ti[kk] == 0:
            kyu.append(time[kk])
        else:
            kyu.append(24 - time[kk])
    kyu.append(0)

    for k in itertools.combinations(kyu, 2):  # nC2
        ans = min(ans, abs(k[0] - k[1]), 24 - abs(k[0] - k[1]))
    A = max(ans, A)
    ans = INF  # 初期化を忘れない
print(A)

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

int main() {
    long N, K, S;
    cin>>N>>K>>S;
    long A[N];
    for(int i=0;i<K;++i){
        A[i] = S;
    }
    for(int i=K;i<N;++i){
        if(S<1e9) A[i] = S+1;
        else A[i] = 1;
    }
    for(int i=0;i<N;++i){
        cout<<A[i]<<" ";
    }
    cout<<endl;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    cin >> m[i];
    X -= m[i];
  }
  
  int ans = N;

  sort(m.begin(), m.end());
  ans += X / m[0];

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_S = 2000010;
const int MOD = 1000000007;
typedef long long Int;

Int fac[MAX_S + 1];
Int inv[MAX_S + 1], ifac[MAX_S + 1];

Int comb(int n, int r)
{
  Int ret = 1;
  ret = (ret * fac[n]) % MOD;
  ret = (ret * ifac[r]) % MOD;
  ret = (ret * ifac[n - r]) % MOD;
  return ret;
}

int main()
{
  int r1, r2, c1, c2;
  
  scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
  
  int n = r2 + c2 + 1;
  
  inv[1] = 1;
  fac[0] = ifac[0] = 1;
  fac[1] = ifac[1] = 1;
  for (int i = 2; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = (inv[MOD % i] * (MOD - MOD / i)) % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
  
  Int ans = 0;
  
  for (int i = r1; i <= r2; i++) {
    ans = (ans + comb(i + c2 + 1, c2)) % MOD;
    ans = (ans + MOD - comb(i + c1, c1 - 1)) % MOD;
  }
  
  printf("%lld\n", ans);
  
  return 0;
}


Measured memory_bytes: 46976
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll a,b;
    cin>>a>>b;
    ll x1=ceil((25*a)/2.0),y1=ceil(((25*a)+25)/2.0),x2=10*b,y2=(10*b)+10;
    ll ans=max(x1,x2);
    if((y1>x2 && y1<=y2)||(y2>x1 && y2<=y1))
        cout<<ans;
    else
        cout<<-1;
    subt;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if(B % A == 0){
		cout << A + B << endl;
	}
	else {
		cout << B - A << endl;
	}

	return 0;
}

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

using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PI;

void solve()
{
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}
	map<int, int> emap;
	map<int, int> omap;
	for (int i = 0; i < n; i += 2)
	{
		emap[v[i]]++;
	}
	for (int i = 1; i < n; i += 2)
	{
		omap[v[i]]++;
	}
	if (emap.size() == 1 && omap.size() == 1)
	{
		if (emap.begin()->first == omap.begin()->first)
		{
			cout << (int)(n / 2) << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
	else
	{
		vector<P> evec;
		for (map<int, int>::iterator it = emap.begin(); it != emap.end(); ++it)
		{
			evec.push_back(P(it->second, it->first));
		}
		vector<P> ovec;
		for (map<int, int>::iterator it = omap.begin(); it != omap.end(); ++it)
		{
			ovec.push_back(P(it->second, it->first));
		}
		sort(evec.begin(), evec.end());
		sort(ovec.begin(), ovec.end());

		if (evec[evec.size() - 1].second == ovec[ovec.size() - 1].second)
		{
			int ans = 1e9;
			ans = min(ans, (int)(n / 2) - evec[evec.size() - 1].first + (int)(n / 2) - ovec[ovec.size() - 2].first);
			ans = min(ans, (int)(n / 2) - ovec[ovec.size() - 1].first + (int)(n / 2) - evec[evec.size() - 2].first);
			cout << ans << endl;
		}
		else
		{
			cout << (int)(n / 2) - evec[evec.size() - 1].first + (int)(n / 2) - ovec[ovec.size() - 1].first << endl;
		}
	}
}

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

Measured memory_bytes: 6520
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans = 100000;
    for(int i = 1; i < n; i++){
        int a = i, sum = 0;
        while(a > 0){
            sum += a % 10;
            a /= 10;
        }
        a = n - i;
        while(a > 0){
            sum += a % 10;
            a /= 10;
        }
        if(sum < ans)
            ans = sum;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left, bisect_right


W, H = map(int, input().split())
P = [int(input()) for _ in range(W)]
P.sort()

Q = [int(input()) for _ in range(H)]
Q.sort()

ans = 0
for q in Q:
    tmp = bisect_right(P, q)
    # print ('tmp=', tmp)
    ans += q * (1 + W - tmp)
    # print (ans)

for p in P:
    tmp = bisect_left(Q, p)
    ans += p * (1 + H - tmp)

print (ans)
# print ('P:', P)
# print ('Q:', Q)

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

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

int main(){
    int N;
    cin >> N;
    int d[N];
    for(int i = 0; i < N; i++) cin >> d[i];
    sort(d, d+N);

    int ans = d[N/2] - d[N/2-1];
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
### constant

DXYS = [[0, 0], [-1, 0], [0, -1], [0, 1], [1, 0]]

### subroutines

def conflict?(d, h, lw, llines, rw, rlines)
  for y in (0...h)
    for x in (0...rw)
      next if rlines[y][x] == ' '
      x0 = x + d
      DXYS.each do |dx, dy|
        x1 = x0 + dx
        y1 = y + dy
        if x1 >= 0 && x1 < lw && y1 >= 0 && y1 < h
          l = llines[y1][x1]
          return true if l && l != ' '
        end
      end
    end
  end
  false
end

def merge(ld, rd, h, lw, llines, rw, rlines)
  w = [lw + ld, rw + rd].max
  lines = h.times.map{' ' * w}

  for y in (0...h)
    for x in (0...lw)
      ch = llines[y][x]
      if ch && ch != ' '
        lines[y][x + ld] = ch
      end
    end
    for x in (0...rw)
      ch = rlines[y][x]
      if ch && ch != ' '
        lines[y][x + rd] = ch
      end
    end
  end

  lines
end

### <but> := <l> | <l> '(' <but> ')' | <l> '(' <but> ',' <but> ')'
### <l> := 'A'..'Z' | 'a'..'z'

### [ h, w, x, [lines,..]]

def parse(str)
  root = str[$pos]
  $pos += 1

  if str[$pos] != '('
    return [1, 1, 0, [root]]	# 0-ary
  end
  $pos += 1

  llf = parse(str)
  lh, lw, lx, llines = llf

  ch = str[$pos]
  $pos += 1
  if ch == ')'
    sep = ' ' * lw
    sep[lx] = '-'
    bline = ' ' * lw
    bline[lx] = root
    return [lh + 2, lw, lx, llines + [sep, bline]]
  end

  rlf = parse(str)
  rh, rw, rx, rlines = rlf

  $pos += 1

  llines0 = llines.clone
  rlines0 = rlines.clone
  h = lh
  if lh < rh
    llines0 = [' ' * lw] * (rh - lh) + llines0
    h = rh
  elsif lh > rh
    rlines0 = [' ' * rw] * (lh - rh) + rlines0
    h = lh
  end

  rd = lx + 2 - rx
  rd = 0 if rd < 0
  while conflict?(rd, h, lw, llines0, rw, rlines0)
    rd += 1
  end

  ld = 0
  if rd == 0
    while ! conflict?(ld, h, rw, rlines0, lw, llines0)
      ld += 1
    end
    ld -= 1
  end

  lines = merge(ld, rd, h, lw, llines0, rw, rlines0)
  w = lines[0].length
  
  slen = rx + rd - (lx + ld) + 1
  x = (lx + ld) + (slen - 1) / 2

  sep = ' ' * w
  sep[lx + ld, slen] = '-' * slen
  bline = ' ' * w
  bline[x] = root

  [h + 2, w, x, lines + [sep, bline]]
end

### main

strs = ''

loop do
  line = gets.strip
  strs += line.gsub(/\s/, '')
  break if line.include?('.')
end

strs.split(/[;\.]/).each_with_index do |str, id|
  #p str

  $pos = 0
  but = parse(str)
  #p but

  h, w, x, lines = but
  #p [h, w, x]

  puts "#{id + 1}:"
  lines.each{|l| puts l.rstrip}
end

Measured memory_bytes: 6172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int B[2222][2222], W[2222][2222];
int N, K;

int cal(int x, int y, int c) // 1 : B, 0 : W
{
    if(x - K + 1 >= K + K || y - K + 1 >= K + K) return 0;
    if(x < 0 || y < 0) return 0;
    int ux = min(K + K - 1, x), uy = min(K + K - 1, y);
    int dx = max(0, x - K + 1), dy = max(0, y - K + 1);
    if(c)
    {
        int ret = B[ux][uy];
        if(dx) ret -= B[dx-1][uy];
        if(dy) ret -= B[ux][dy-1];
        if(dx && dy) ret += B[dx-1][dy-1];
        return ret;
    }
    else
    {
        int ret = W[ux][uy];
        if(dx) ret -= W[dx-1][uy];
        if(dy) ret -= W[ux][dy-1];
        if(dx && dy) ret += W[dx-1][dy-1];
        return ret;
    }
}

int main(void)
{
    scanf("%d %d", &N, &K);
    int wt = 0;
    for(int i = 1; i <= N; i++)
    {
        int x, y;
        char s[1111];
        scanf("%d %d %s", &x, &y, s);
        x = x % (K + K), y = y % (K + K);
        if(s[0] == 'B') B[x][y]++;
        else W[x][y]++, wt++;
    }
    for(int i = 0; i < K + K; i++)
        for(int j = 1; j < K + K; j++)
            B[i][j] += B[i][j-1], W[i][j] += W[i][j-1];
    for(int i = 1; i < K + K; i++)
        for(int j = 0; j < K + K; j++)
            B[i][j] += B[i-1][j], W[i][j] += W[i-1][j];
    int ans = 0;
    for(int i = 0; i < K + K; i++)
    for(int j = 0; j < K + K; j++)
    {
        int tmp = wt;
        for(int x = i - K - K; x <= i + K + K; x += K)
        for(int y = j - K - K; y <= j + K + K; y += K)
        if(abs(x - i + y - j) / K % 2 == 0)
            tmp += cal(x, y, 1) - cal(x, y, 0);
        ans = max(ans, tmp);
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int val = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
        val ^= a[i];
	}
    vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		ans[i] = val ^ a[i];
		cout << ans[i] << " ";
	}
 //   for (int &it : ans) cout << it << " ";
	return 0;
}

Measured memory_bytes: 4840
import numpy as np

N, M, K = (int(i) for i in input().split())
ans = False
for s in range(N + 1):
  for t in range(M + 1):
    if(s * M + t * N - s * t * 2 == K):
      ans = True
      break
  if(ans):
    break
if(ans):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 13964
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
using namespace std;

string ca, cb, cc;
unsigned int ia = 0;
unsigned int ib = 0;
unsigned int ic = 0;
char turn = 'a';

char simulation(char turn){
    if(turn == 'a'){
        if(ia == ca.size()) return 'a';
        else {
            ia++;
            return simulation(ca.c_str()[ia-1]);
        }
    }
    else if(turn == 'b'){
        if(ib == cb.size()) return 'b';
        else {
            ib++;
            return simulation(cb.c_str()[ib-1]);
        }
    }
    else{
        if(ic == cc.size()) return 'c';
        else {
            ic++;
            return simulation(cc.c_str()[ic-1]);
        }
    }
}

int main(){
    cin >> ca >> cb >> cc;
    char winner = simulation(turn);
    cout << (char)toupper(winner) << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import math
X=int(input())
maxnum=0
p=int(math.log2(X))
for x in range(2,p+1):
    for y in range(int(math.sqrt(X))+1):
        if y**x<=X:
            maxnum=max(maxnum,y**x)
        else:
            break
print(max(1,maxnum))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>

using namespace std;

struct uni {
  int p[111111];
  uni(){memset(p,-1,sizeof(p));}
  int root(int a){return p[a]<0?a:(p[a]=root(p[a]));}
  bool find(int a,int b){return root(a)==root(b);}
  // aをbの親に
  void merge(int a,int b){if(!find(a,b))p[root(b)]=root(a);}
};

int p[111111];
int m[111111];
int Q[111111];
int Qm[111111];
int Qi[111111];
int Qc,Qmc;
int main(void)
{
  int n,q;
  long long res;
  for(;;) {
    scanf("%d%d",&n,&q); if(n+q==0)return 0;
    uni u;
    memset(m,-1,sizeof(m));
    res = 0;
    Qc = 0;
    Qmc = 0;
    m[0] = 0;
    for(int i = 0; i < n-1; i++) {
      int a; scanf("%d",&a);
      p[i+1] = a-1;
    }
    for(int i = 0; i < q; i++) {
      char c;int a; scanf(" %c%d",&c,&a);
      --a;
      if(c=='Q') {
        Qi[Qc] = i;
        Q[Qc++] = a;
      } else {
        if(m[a] < 0) {
          m[a] = i;
          Qm[Qmc++] = a;
        }
      }
    }
    for(int i = 0; i < n; i++) {
      if(m[i]<0) u.merge(p[i],i);
    }
    while(Qmc--) {
      while( Qc && Qi[Qc-1] > m[Qm[Qmc]] ) {
        Qc--;
        res += u.root(Q[Qc])+1;
      }
      u.merge(p[Qm[Qmc]],Qm[Qmc]);
    }
    
    res += Qc;
    printf("%lld\n",res);
  }
  return 0;
}

Measured memory_bytes: 2852
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 300 + 10;
char s[N][N];
int cost[N][N], dp[N][N];
int n, m;

int solve(int x, int y) {
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (i == 0 || j == 0) {
        cost[i][j] = 0;
      } else {
        cost[i][j] = cost[i - 1][j - 1] +
          (s[i - 1][x] == s[j - 1][y]);
      }
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (i == 0 || j == 0) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = cost[i][j] + min(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  return dp[n][n];
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  int ret = 0;
  for (int i = 1; i < m; ++i) {
    ret += solve(i - 1, i);
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int head[100001],to[100001],nxt[100001],tot=0;
int degree[100001],f[100001];
void addedge(int u,int v)
{
	tot++;
	nxt[tot]=head[u];
	to[tot]=v;
	head[u]=tot;
}
int dfs(int index)
{
	if(f[index]>=0)
		return f[index];
	if(head[index]==0)
		return f[index]=0;	
	int i,v;
	for(i=head[index];i;i=nxt[i])
	{
		v=to[i];
		f[index]=max(f[index],dfs(v)+1);
	}
	return f[index];
}
int main()
{
	int n,m,i,j,v,u,max_v=0;
	scanf("%d %d",&n,&m);
	memset(f,0xff,sizeof(f));
	for(i=1;i<=m;i++)
	{
		scanf("%d %d",&u,&v);
		addedge(u,v);
		degree[v]++;
	}
	for(i=1;i<=n;i++)
		dfs(i);
	for(i=1;i<=n;i++)
		max_v=max(f[i],max_v);
	printf("%d",max_v);
	return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

#define N 8
#define FREE 0
#define NOT_FREE 1
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int B[N][N];

void initialize();
void putQueen(int i);
void printBoard();

int main(){
  int i,j,n,r,c;
  initialize();
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      B[i][j] = 0;
    }
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    B[r][c] = 1;
  }
  putQueen(0);
  return 0;  
}

void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }
}
void putQueen(int i){
  int j;
  
  if(i == N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE ||
       dneg[i-j+N-1] == NOT_FREE) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    putQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }

}
void printBoard(){
  int i,j;
   for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(B[i][j] == 1){
	if(row[i] != j) return;
      }
    }
   }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2112
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	
      	int h = sc.nextInt();
      	int w = sc.nextInt();
      	int k1 = sc.nextInt();
      	int black = 0;
      	int count = 0;
      	int hp = (int)Math.pow(2,h);
      	int wp = (int)Math.pow(2,w);
      	boolean hd[] = new boolean[h];
      	boolean wd[] = new boolean[w];
      	boolean hws[][] = new boolean[h][w];
      	boolean shws[][] = new boolean[h][w];
      	String str;
      	char ch;
      	int istack;
      	int del = 0;
      	int dstack;
      
      	Arrays.fill(hd,false);
      	Arrays.fill(wd,false);
      
      	for(int i = 0;i < h;i++) {
          str = sc.next();
          for(int j = 0;j < w;j++) {
            ch = str.charAt(j);
            if(ch == '#') {
              black++;
              hws[i][j] = true;
            } else hws[i][j] = false;
          }
        }
      
      	black -= k1;
      
      	for(int i = 0;i < h;i++){
          for(int j = 0;j < w;j++) shws[i][j] = hws[i][j];
        } 
            
      	
      	for(int i = 0;i < hp;i++){
          del = 0;
          istack = i;
          for(int j = 0; j < h && istack > 0;j++){
          	if(istack%2 == 1) hd[j] = true;
          	else hd[j] = false;
          	istack /= 2;
          }
          for(int j = 0; j < h;j++){
            if(hd[j]){
              for(int k = 0; k < w;k++) {
                if(shws[j][k]){
                  del++;
                  shws[j][k] = false;
                }
              }
            }
          }
          dstack = del;
          for(int j = 0;j < wp;j++){
            istack = j;
            for(int k = 0;k < w;k++){
             if(istack%2 == 1) wd[k] = true;
          	 else wd[k] = false;
          	 istack /= 2;
            }
            for(int k = 0;k < w;k++){
              if(wd[k]){
              	for(int l = 0;l < h;l++){
                  if(shws[l][k]) del++;
                }
              }
            }
            if(del == black) count++;
           
            del = dstack;
          }
          
          for(int j = 0;j < h;j++){
          	for(int k = 0;k < w;k++) shws[j][k] = hws[j][k];
          } 
            
        }
  
           
      	System.out.println(count);
        
	}
}

Measured memory_bytes: 38024
package main

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

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()
	n := nint()
	r := fibonacci(n)
	fmt.Println(r)
}

func fibonacci(n int) int{
	if n == 0 || n == 1{
		return 1
	}else{
		fiList := make([]int, n+1)
		fiList[0] = 1
		fiList[1] = 1
		for i:=2; i<n+1; i++{
			fiList[i] = fiList[i-1] + fiList[i-2]
		}
		return fiList[n]

	}

}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}



Measured memory_bytes: 1108
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        char[] sc = s.toCharArray();
        Arrays.sort(sc);
        String out = new String(sc);
        System.out.println(out.charAt(0) == out.charAt(1) && out.charAt(2) == out.charAt(3) && out.charAt(0) != out.charAt(2) ? "Yes" : "No");
        scan.close();
    }
}

Measured memory_bytes: 26876
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

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


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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e5 + 1;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

int32_t main() {
    IOS int Q = 1;
    // cin >> Q;
    while (Q--) {
        int n;  cin>>n;
        cout << (n^1);
    }
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;

typedef long long lli;

map<char,string> conv;

void init() {
  conv['0'] = "0000";
  conv['1'] = "0001";
  conv['2'] = "0010";
  conv['3'] = "0011";
  conv['4'] = "0100";
  conv['5'] = "0101";
  conv['6'] = "0110";
  conv['7'] = "0111";
  conv['8'] = "1000";
  conv['9'] = "1001";
  conv['a'] = "1010";
  conv['b'] = "1011";
  conv['c'] = "1100";
  conv['d'] = "1101";
  conv['e'] = "1110";
  conv['f'] = "1111";
}

int main() {
  init();
  int Tc;
  cin >> Tc;
  while(Tc--) {
    string line;
    cin >> line;
    string bit;
    for(int i = 0; i < line.size(); ++i) bit += conv[line[i]];
    reverse(bit.begin(), bit.end());
    if(bit[31] == '1') cout << '-';
    lli inte = 0;
    for(int i = 7; i <= 30; ++i) {
      if(bit[i] == '1') inte |= 1LL<<(i-7);
    }
    cout << inte;
    cout << '.';
    lli f = 0;
    for(int i = 0; i < 7; ++i) {
      if(bit[i] == '1') {
        f +=  (lli)( pow(0.5, 7-i) * pow(10.0, 7.0) );
      }
    }
    if(f == 0) {
      cout << 0 << endl;
      continue;
    }
    char buff[100];
    sprintf(buff, "%07lld", f);
    string s(buff);
    int k;
    for(k = s.size()-1; k >= 0 && s[k] == '0'; --k);
    cout << s.substr(0, k+1) << endl;
  }
  return 0;
}

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

const long long int MOD = 1e9+7;
#define pb push_back
typedef long long ll;
const long long int N = 1e6;

int main(){
    ll n,w;
    cin>>n>>w;
    ll wt[n+5],val[n+5];
    for(int i=1;i<=n;i++){
        cin>>wt[i]>>val[i];
    }
    vector<vector<ll>> dp(n+5,vector<ll>(w+5, 0 ));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(wt[i]<=j){
                dp[i][j]= max(dp[i-1][j] , val[i]+dp[i-1][j-wt[i]]);
            }
            else{
                dp[i][j]= dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 86324
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a,b;
    bool pd=0;
    string s;
    cin>>a>>b>>s;
    for(int i=0;i<a;i++){
        if(s[i]<'0'||s[i]>'9'){
            pd=1;
            break;
        }
    }
    if(s[a]!='-')pd=1;
    for(int i=a+1;i<a+b+1;i++){
        if(s[i]<'0'||s[i]>'9'){
            pd=1;
            break;
        }
    }
    if(pd) cout<<"No";
    else cout<<"Yes";
    cout<<endl;
    return 0;
}

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

ll cl(ll n, ll x){
	ll ret=n/x;
	if(n%x==0) return ret;
	return (ret+1);
}
int main(){
	ll n,a1,r1,r2;
	vector<pair<ll,ll> > v;
	cin>>n;
	for(a1=0;a1<5;++a1){
		cin>>r1;
		v.push_back(make_pair(r1,a1));
	}
	sort(v.begin(),v.end());
	ll ans=cl(n,v[0].first);
	cout<<ans+5-1;
	return 0;
}

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

struct Node { int key; Node *parent, *left, *right; };

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->parent = NIL;
  z->left = NIL;
  z->right = NIL;
  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;

  if (y == NIL) {
    root = z;
  } else if (z->key < y->key) {
    y->left = z;
  } else {
    y->right = z;
  }
}

void Preorder(Node *p) {
  printf(" %d", p->key);
  if (p->left != NIL) Preorder(p->left);
  if (p->right != NIL) Preorder(p->right);
}

void Inorder(Node *p) {
  if (p->left != NIL) Inorder(p->left);
  printf(" %d", p->key);
  if (p->right != NIL) Inorder(p->right);
}

void Postorder(Node *p) {
  if (p->left != NIL) Postorder(p->left);
  if (p->right != NIL) Postorder(p->right);
  printf(" %d", p->key);
}

Node * find(int key) {
  Node *x = root;
  while (x != NIL) {
    if (key < x->key) {
      x = x->left;
    } else if (key > x->key) {
      x = x->right;
    } else if (key == x->key) {
      return x;
    }
  }
  return x;
}

Node * getMinimum (int key) {
  Node *x = find(key);
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
}

Node * getSuccessor(int key) {
  Node *x;
  x = find(key);
  if ( x->right != NIL ) {
    return getMinimum(x->right->key);
  }
  Node *y = x->parent;
  while ( y != NIL && x == y->right ) {
    x = y;
    y = y->parent;
  }
  return y;
}

void deleteKey(int key) {
  Node *x, *y, *z;
  z = find(key);
  if ( z->left == NIL || z->right == NIL) {
    y = z;
  } else {
    y = getSuccessor(z->key);
  }

  if ( y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if ( x != NIL ) x->parent = y->parent;

  if ( y == NIL ) {
    x = root;
  } else if (y->parent->left == y) {
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }

  if (y != z) {
    z->key = y->key;
  }

  free(y);
}

int main() {
	int n;
  scanf("%d", &n);

  char str[12];
  int key;
  for ( int i = 0; i < n; i++ ) {
    scanf("%s", str);
    if ( strcmp(str, "insert") == 0 ) {
      scanf("%d", &key);
      insert(key);
    } else if ( strcmp(str, "print") == 0 ) {
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    } else if ( strcmp(str, "find") == 0 ) {
      scanf("%d", &key);
      if ( find(key) != NIL ) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    } else if ( strcmp(str, "delete") == 0 ) {
      scanf("%d", &key);
      deleteKey(key);
    }
  }

  return 0;
}



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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	
	int a, b;
	cin >> a >> b;
	ll p = (ll)a * (ll)b;
	int x = __gcd(a, b);
	cout << p / x << "\n";




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3612
#include <iostream>

#include<string>
using namespace std;

int main() {
	string s;
	cin>>s;
	if(s[0]=='Y'){
		if(s[1]=='A'){
			if(s[2]=='K'){
				if(s[3]=='I'){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>


using namespace std;

int main()
{
    stack<int> railroad;
    int num;
    while(cin >> num) {
        if(num == 0) {
            cout << railroad.top() << endl;
            railroad.pop();
        } else {
            railroad.push(num);
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int N,D,count=0;
  double distance;
  cin >> N >> D;
  int X[N],Y[N];
  for(int i=0;i<N;i++){
    cin >> X[i] >> Y[i];
    distance = sqrt(pow(X[i],2.0)+pow(Y[i],2.0));
    if(distance <= double(D)){
      count++;
    }
  }
  cout << count << endl;
}


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

long long int N, M;
int main(){
	cin >> N >> M;
	// long long int ns = N;
	// long long int rc = M - N * 2;
	// while(rc < 0){
	// 	ns --;
	// 	rc = M - rc*2;
	// }
	long long int ns = min(N, M/2);
	long long int rc = M - ns * 2;
	ns += rc / 4;
	cout << ns << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int K, X;
  scanf("%d %d", &K, &X);

  int L = X - K + 1;
  int R = X + K - 1;
  for(int i = L; i <= R; i++) {
    printf("%d ", i);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#define ll long long

using namespace std;

ll mod = 1e9 + 7;

ll dp[101][100005] = {0};

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

  for(int i = 0; i<=n ; i++)
  {
    for(int j = 0 ; j<=k ; j++)
    {
      dp[i][j] = -1;
    }
  }

  int arr[n];

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

  for(int j = 0 ; j<=k ; j++)
    dp[1][j] = (arr[1] - j >= 0) ? 1 : 0;

  for(int i = 2 ; i<=n ; i++)
  {
    for(int j = 0 ; j<=k ; j++)
    {
      if(j==0)
      {
        dp[i][j] = dp[i-1][j];
      }
      else
        dp[i][j] = (mod + dp[i][j-1] + dp[i-1][j] - ((j - arr[i] - 1 >=0) ? dp[i-1][j-arr[i]-1]:0))%mod;
    }
  }


  cout<<dp[n][k];

  
  
  return 0;
}

Measured memory_bytes: 79104
a, b = map(int, input().split())

t1, t2, s = 1, 1 + 2, 3
while not (t1 - a > 0 and t2 - b > 0 and t1 - a == t2 - b):
    t1, t2, s = t2, t2 + s, s + 1

x = t1 - a
print(x)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{
  IOS
  string s;
  cin>>s;
  ll i,cnt=0;
  for(i=0;s[i]!='\0';i++)
    if(s[i]=='o')
      cnt++;
    ll l=s.length();
    if(cnt+15-l>=8)
      cout<<"YES";
    else
      cout<<"NO";

  return 0; 
}

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

minint = 10**9

if N == 2:
    print(abs(a[0] - a[1]))

else:
    s1 = s1 = sum(a[0:1])
    s2 = sum(a[1: N])
    for i in range(1, N - 1):
        s1 += a[i]
        s2 -= a[i]
        
        minint = min(minint, abs(s1 - s2))

    print(minint)

Measured memory_bytes: 30736
fun main(args: Array<String>) {
    val (countN, pointX) = readLine()!!.split(" ").map { it.toInt() }
    val listL = readLine()!!.split(" ").map { it.toInt() }

    var currentPoint = 0
    var boundCount = 1
    for (i in 0 until countN) {
        currentPoint += listL[i]
        if (currentPoint > pointX) break else boundCount++
    }

    print(boundCount)
}

Measured memory_bytes: 37860
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <limits.h>
using namespace std;

void north(int* faces) {
	int tmp[7];

	//top(1) to back(5)
	tmp[5] = faces[1];

	//front(2) to top(1)
	tmp[1] = faces[2];

	//right(3) to right(3)
	tmp[3] = faces[3];

	//left(4) to left(4)
	tmp[4] = faces[4];

	//back(5) to bottom(6)
	tmp[6] = faces[5];

	//bottom(6) to front(2)
	tmp[2] = faces[6];

	memcpy(faces, tmp, sizeof(tmp));

}
void west(int* faces) {
	int tmp[7];

	//top(1) to left(4)
	tmp[4] = faces[1];

	//front(2) to front(2)
	tmp[2] = faces[2];

	//right(3) to top(1)
	tmp[1] = faces[3];

	//left(4) to bottom(6)
	tmp[6] = faces[4];

	//back(5) to back(5)
	tmp[5] = faces[5];

	//bottom(6) to right(3)
	tmp[3] = faces[6];

	memcpy(faces, tmp, sizeof(tmp));

}
bool check(int* faces, int* taget, int frontNum) {
	
	int tmp[7];
	for (int i = 1; i < 7; i++)
	{
		tmp[i] = faces[i];
	}
	
	tmp[frontNum] = INT_MAX;
	

	if (frontNum == 3 || frontNum == 4) west(tmp);

	while (true)
	{
		north(tmp);
		if (tmp[2] == INT_MAX)break;
	}
	tmp[2] = faces[frontNum];



	for (int i = 1; i < 7; i++)
	{
		if (tmp[i] != taget[i]) break;
		if (i == 6) return true;
	}

	for (int i = 0; i < 3; i++)
	{
		west(tmp);
		for (int j = 1; j < 7; j++)
		{
			if (tmp[j] != taget[j]) break;
			if (j == 6) return true;
		}
	}


	return false;
}

bool dice(int *faces, int *taget, int front) {

	for (int i = 1; i < 7; i++)
	{
		if (faces[i] == front) {
			if (check(faces, taget, i)) return true;
		}
	}



	return false;
}


int main() {
	int faces_1[7],faces_2[7];

	for (int i = 1; i < 7; i++) cin >> faces_1[i];

	for (int i = 1; i < 7; i++) cin >> faces_2[i];
	
	if (dice(faces_2, faces_1, faces_1[2])) {
		cout << "Yes" << endl;
		return 0;
	}

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

Measured memory_bytes: 1156
import sys
import collections


def tle_solver():
    # N,M <=10^5
    N, M = [int(ele) for ele in input().split()]
    ans = int('0b' + str(1)*N, 2)

    for i in range(M):
        l, r = [int(ele) for ele in sys.stdin.readline().split()]
        secure = int('1' * (r-l+1) + '0' * (N-r), 2)
        ans = ans & secure

    print(bin(ans).count("1"))


def ac_solver():
    # N,M <=10^5
    N, M = [int(ele) for ele in input().split()]
    ll = 1
    rr = N
    ans = "Error"

    for i in range(M):
        l, r = [int(ele) for ele in sys.stdin.readline().split()]
        ll = max(ll, l)
        rr = min(rr, r)

    ans = max(0, rr - ll+1)
    print(ans)


if __name__ == "__main__":
    # tle_solver()
    ac_solver()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
main(){
  int S,T,D,sum=0,ans=0,p=0,d;
  cin>>S>>T>>D;
  int t=S;
  int a[D];
  r(i,D){
    cin>>a[i],sum+=a[i];
    if(p>sum){
      p=sum;
      d=D;
    }
  }
  sum-=p;
  ///////////
  if(p>=0){
    cout<<-1<<endl;
    return 0;
  }
  r(o,5){r(i,D){
    t+=a[i];
    if(t<=T){
      cout<<i+1+o*D<<endl;
      return 0;
    }
  }
    /////////
    if(o==4&&t>=S){
      cout<<-1<<endl;
      return 0;
    }
  }/////////////
  while(1){
    S+=p;
    ans+=d;
    if(S<=T){
      S-=p;
      ans-=d;
      break;
    }
    S+=sum;
    ans+=D-d;
    if(S<=T){
      S-=sum;
      ans-=D-d;
      break;
    }
  }
  r(i,D){
    S+=a[i];
    if(S<=T){
      cout<<ans+i+1<<endl;
      return 0;
    }
  }
  return 0;
}

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

int main() {
	int A,B,C,ans=3;
	cin >> A>>B>>C;
	if (A == B)ans--;
	if (A == C)ans--;
	if (B == C)ans--;
	if (ans == 0)ans++;
	cout << ans;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int piyo = 0,ans=0;
            int[] hoge = System.Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
            for(int i = 1; i <= hoge[0]; i++)
            {
                piyo = Calc(i.ToString());
                if (piyo <= hoge[2] && piyo >= hoge[1]) ans += i;
            }
            System.Console.WriteLine(ans);
        }

        static int Calc(string  s)
        {
            int sum = 0;
            for(int i = 0; i < s.Length; i++)
            {
                sum += int.Parse(s[i].ToString());
            }
            return sum;
        }
    }
}

Measured memory_bytes: 11348
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int dfs(int now, int sum, int n, vector<bool> &d) {
    if (now >= 1000000) {
        return now;
    }
    if (sum >= n) {
        return sum;
    }
    int ret = 1e8;
    for (int i=0; i<=9; i++) {
        if (d.at(i)) {
            ret = min(ret, dfs(now*10, sum + now*i, n, d));
        }
    }
    return ret;
}

int main() {
    int n = 0, k = 0;
    cin >> n >> k;
    int buf = 0;
    vector<bool> d(10, true);
    for (int i=0; i<k; i++) {
        cin >> buf;
        d.at(buf) = false;
    }
    cout << dfs(1, 0, n, d) << endl;
    return 0;
}


Measured memory_bytes: 256