akhauriyash/Code-Regression huggingface dataset:
A = int(input())
B = int(input())
C = int(input())
X = int(input())

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

Measured memory_bytes: 3060
N, M, X = gets.chomp.split.map(&:to_i)

books = N.times.map do
  gets.chomp.split.map(&:to_i)
end

(1..N).each do |n|
  books.combination(n) do |pattern|
    # p pattern
    rikaido = Array.new(M, 0)
    total_cost = 0
    pattern.each do |book|
      cost = book[0]
      total_cost += cost
      book.each_with_index do |up, index|
        next if index.zero?
        rikaido[index - 1] += up
      end
    end
    if rikaido.all? { |val| val >= X }
      @ans ||= total_cost
      @ans = total_cost if @ans > total_cost
    end
  end
end

@ans = -1 if @ans.nil?

puts @ans


Measured memory_bytes: 14364
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,n;cin>>n;
	llint ans=1;
	static llint dp[200001]={0};
	int mae=-1;
	for(i=0;i<n;i++){
		int c;cin>>c;c--;
		if(c==mae){continue;}
		ans+=dp[c];ans%=mod;
		dp[c]=ans;
		mae=c;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define fr(i,n) for(ll i=0;i<n;i++)
using namespace std;
const ll mod=1e6+7;


int main() {
    ll n,ans=0;cin>>n;
    vector<ll> k(n+1,0);
for(ll i=1;i<=n;i++){
    k[i]++;
    for(ll j=i*2;j<=n;j+=i)
        k[j]++;
}
for(ll i=1;i<=n;i++){
    ans+=(1LL*i*k[i]);
}
cout<<ans;}



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

int n,A[5000001],s,x;
bitset<10000001>bit;

int main(){
  
  cin>>n;
  bit.set(0);
  for(int i=1;i<=n;i++){
  	cin>>x;
    //cout<< (bit<<x) <<endl; 
    bit |= (bit<<x);
  	s += x;
  }
  
  for(int i=(s+1)/2;;i++){
  	if(bit[i]){
    	cout<<i<<endl;
      	return 0;
    }
  }
  
}

Measured memory_bytes: 3968
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

if N == 0:
    if A[0] == 1:
        print(1)
    else:
        print(-1)
    exit()

cond1 = [0] * (N+1)
cond1[N] = A[N]
for i in range(N-1, -1, -1):
    cond1[i] = cond1[i+1] + A[i]

if min(cond1) <= 0:
    print(-1)
    exit()

cond2 = [0] * (N+1)
cond2[0] = 1
for i in range(1, N+1):
    cond2[i] = min(cond1[i], (cond2[i-1]-A[i-1]) * 2)

if min(cond2) <= 0:
    print(-1)
    exit()

if cond2[N] < A[N]:
    print(-1)
    exit()

ans = sum(cond2)
print(ans)


Measured memory_bytes: 650604
#include<cstdio>
#include<algorithm>

int main(int argc, char const *argv[]) {
  int a=0,b=0,c=0,ans=0;
  scanf("%d %d %d",&a ,&b,&c);
  if (a*c<=b) {
    ans = c;
  }else ans = b / a;
  printf("%d\n",ans );
  return 0;
}


Measured memory_bytes: 128
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    A, B, C = map(int, input().split())
    if A == B:
        print(C)
    elif B == C:
        print(A)
    else:
        print(B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
import java.io.*;
import java.util.*;

public class Main{
	
	public static void main(String[] args){
		solve();
	}
	
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		int z = sc.nextInt();
		int x = z;
		int a = x/1000;
		x -= x/1000*1000;
		int b = x/100;
		x -= x/100*100;
		int c = x/10;
		x -= x/10*10;
		int ans = 0;
		int[] count = new int[3];
		for(int i=0;i<2;i++){
			for(int j=0;j<2;j++){
				for(int k=0;k<2;k++){
					ans = a;
					if(i==0){
						ans += b;
					}
					else{
						ans -= b;
					}
					if(j==0){
						ans += c;
					}
					else{
						ans -= c;
					}
					if(k==0){
						ans += x;
					}
					else{
						ans -= x;
					}
					if(ans == 7){
						count[0] = i;
						count[1] = j;
						count[2] = k;
					}
				}
			}
		}
		for(int i=0;i<4;i++){
			System.out.print(z/(int)Math.pow(10,3-i));
			z -= z/(int)Math.pow(10,3-i)*(int)Math.pow(10,3-i);
			if(i!=3){
				if(count[i]==0){
					System.out.print("+");
				}
				else{
					System.out.print("-");
				}
			}
		}
		System.out.println("=7");

	}

}


Measured memory_bytes: 22736
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_n = 200000+10;

int N;
int a[max_n];
int x[max_n];

int main(void) {
    cin>>N;

    for(int i = 1;i <= N;i++) {
        cin>>a[i];
    }

    vector<int> ans;
    for(int i = N;i > 0;i--) {
        int sum = 0;
        for(int j = 1;j*i <= N;j++) {
            sum += x[j*i];
        }
        if(sum % 2 != a[i]) {
            x[i] = 1;
            ans.push_back(i);
        }
    }

    reverse(ans.begin(),ans.end());

    cout<<ans.size()<<endl;
    if(ans.size() == 0)
        return 0;

    for(int u: ans) {
        cout<<u<<" ";
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 2936
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    N, _L = map(int, input().rstrip().split())
    s = [input().rstrip() for _ in range(N)]
    print(''.join(sorted(s)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define int long long
#define Matrix vector<vector<int> >
// #define Matrix vector<vector<int> >
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
double rad(double x){
    return x*pi/180.0;
}
 
bool isleft(pair<int,int> a, pair<int,int> b, pair<int,int> c){
    int det = (b.first-a.first)*(c.second-a.second) - (c.first-a.first)*(b.second-a.second);
    if(det>=0) return true;
    if(det<0) return false;
    return false;
}
 
int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = mod(result*a,MOD);
 
        b >>= 1;
        a = mod(a*a,MOD);
    }
    return result;
}

int memo[123][123456];
int v[123][2];
int n;
int w;
int dp(int pos, int cap){
    if(cap<0){
        return -INF;
    }
    if(pos==n) return 0;
    int &ans = memo[pos][cap];
    if(ans!=-1) return ans;
    ans = max(v[pos][1]+dp(pos+1,cap-v[pos][0]),dp(pos+1,cap));
    return ans;
}
void solve(){
    memset(memo,-1,sizeof(memo));
    cin>>n>>w;
    for(int i=0;i<n;i++){
        cin>>v[i][0];
        cin>>v[i][1];
    }
    cout<<dp(0,w)<<endl;
}
 
signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 122288
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    XY = sorted([list(map(int, input().split())) for _ in range(n)])

    if n == 1:
        print(1)
        exit()

    res = n
    for i in range(n):
        x1, y1 = XY[i]
        for j in range(n):
            if i == j:
                continue
            x2, y2 = XY[j]
            dx, dy = x2 - x1, y2 - y1

            cnt = 0
            for k in range(n):
                x3, y3 = XY[k]
                for l in range(n):
                    if k == l:
                        continue
                    x4, y4 = XY[l]
                    if dx == x4 - x3 and dy == y4 - y3:
                        cnt += 1

            res = min(res, n - cnt)

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <iomanip>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int  n;
    cin >> n;
    vector<vector<long long int>> grid(3,vector<long long int>(n));
    REP(i,3){
        REP(j,n){
            scanf("%lld",&grid[i][j]);
            if(i==0){
                grid[i][j] *= -1;
            }
        }
        sort(grid[i].begin(), grid[i].end());
    }
    long long int result = 0,tmp;

    REP(i,n){

        result += abs(distance(grid[0].end(), upper_bound(grid[0].begin(), grid[0].end(), -grid[1][i])) *
                      distance(grid[2].end(), upper_bound(grid[2].begin(), grid[2].end(), grid[1][i])));
    }
    cout << result << endl;
}


Measured memory_bytes: 3328
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string S;
    cin >> S;
    map<char, int> m;
    for (auto ch : S)
    {
        ++m[ch];
    }
    if (m.size() == 2)
    {
        for (auto p : m)
        {
            if (p.second != 2)
            {
                puts("No");
                return 0;
            }
        }
        puts("Yes");
    }
    else
    {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
itn K, X;
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> K >> X;
    for (int i = X - K + 1; i <= X + K - 1; i++) {
        cout << i << " ";
    }
    cout << endl;

    solve();
    return 0;
}


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

#define ld long double
#define eps 1e-9

bool cmp(ld A , ld B){return A + eps > B && A - eps < B;}

struct vec{
	ld x , y;
	vec(ld _x = 0 , ld _y = 0) : x(_x) , y(_y){}
	friend vec operator +(vec A , vec B){return vec(A.x + B.x , A.y + B.y);}
	friend vec operator -(vec A , vec B){return vec(A.x - B.x , A.y - B.y);}
	friend ld operator *(vec A , vec B){return A.x * B.x + A.y * B.y;}
	friend ld operator %(vec A , vec B){return A.x * B.y - A.y * B.x;}
	friend vec operator *(vec A , ld B){return vec(A.x * B , A.y * B);}
	ld len(){return sqrt(x * x + y * y);}
	ld angle(){return atan2(y , x);}
};

struct segment{
	vec st , ed , dir;
	segment(vec _a = vec() , vec _b = vec()) : st(_a) , ed(_b) , dir(_b - _a){}
	friend bool havesect(segment A , segment B){
		ld P = A.st.x , Q = A.ed.x , X = B.st.x , Y = B.ed.x;
		if(Q < P) swap(P , Q);
		if(Y < X) swap(X , Y);
		if(X - eps > Q || P - eps > Y) return 0;
		P = A.st.y , Q = A.ed.y , X = B.st.y , Y = B.ed.y;
		if(Q < P) swap(P , Q);
		if(Y < X) swap(X , Y);
		if(X - eps > Q || P - eps > Y) return 0;
		return
			((B.st - A.st) % A.dir) * (A.dir % (B.ed - A.st)) > -eps &&
			((B.st - A.ed) % A.dir) * (A.dir % (B.ed - A.ed)) > -eps &&
			((A.st - B.st) % B.dir) * (B.dir % (A.ed - B.st)) > -eps &&
			((A.st - B.ed) % B.dir) * (B.dir % (A.ed - B.ed)) > -eps;
	}
	friend vec getsect(segment A , segment B){
		
	}
};

vec getvec(){int x , y; cin >> x >> y; return vec(x , y);}
segment getseg(){vec A = getvec() , B = getvec(); return segment(A , B);}

int main(){
	int Q;
	for(cin >> Q ; Q ; --Q){
		segment A = getseg() , B = getseg();
		printf("%d\n" , havesect(A , B));
	}
	return 0;
}



Measured memory_bytes: 3192
#coding:utf-8

if __name__ == "__main__":
    n, m = map(int, raw_input().split(" "))
    x_list = map(int, raw_input().split(" "))
    y_list = map(int, raw_input().split(" "))

    x_sum = 0
    for i in range(1, n + 1):
        x_sum += (i - 1) * x_list[i-1] - (n - i) * x_list[i-1]

    y_sum = 0
    for j in range(1, m + 1):
        y_sum += (j - 1) * y_list[j-1] - (m - j) * y_list[j-1]

    print (x_sum * y_sum) % (10 ** 9 + 7)


Measured memory_bytes: 14500
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 N, A, B;
    cin >> N >> A >> B;

    vector<i64> hp(N);
    rep(i, N) {
        cin >> hp[i];
    }

    const auto allDie = [&](i64 cnt) {
        const i64 diffAB = A - B;
        i64 needCnt = 0;
        for(i64 e : hp) {
            e -= B * cnt;
            chmax(e, 0);
            needCnt += (e + diffAB - 1) / diffAB;
        }
        return (needCnt <= cnt);
    };

    i64 ng = 0;
    i64 ok = int(1e9);

    while(ok - ng > 1) {
        const i64 mid = (ok + ng) / 2;
        if (allDie(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;

int ans[5000];
int used[5000];

vector<int> g[2020];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,x,y; cin >> n >> x >> y;
	int k=y-x;
	x--; y--;
	for(int i=0;i<n-1;i++){
		g[i].push_back(i+1);
		g[i+1].push_back(i);
	}
	g[x].push_back(y);
	g[y].push_back(x);
	for(int i=0;i<n;i++){
		ans[i]=0;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			used[j]=0;
		}
		queue<pair<int,int>> q;
		q.push(make_pair(i,0));
		used[i]=1;
		while(q.size()){
			auto p=q.front(); q.pop();
			for(int t:g[p.first]){
				if(!used[t]){
					used[t]=1;
					ans[p.second+1]++;
					q.push(make_pair(t,p.second+1));
				}
			}
		}
	}
	for(int i=1;i<n;i++){
		cout << ans[i]/2 << endl;
	}
}




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

int main(){
	int n, k, a, ans;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> a;
	}

	if(k>n){
		cout << 1 << endl;
		return 0;
	}
	ans = 1 + (n-k)/(k-1);
	if((n-k)%(k-1) != 0){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// 理解した。これは賢い、自分は線形探索以外思いつかなかったので自明にプランクトン
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  else gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  return (a / gcd(a, b) * b);
}

ll f(ll x, ll c, ll d) {
  ll res = x;
  res -= x / c;
  res -= x / d;
  res += x / lcm(c, d);
  return res;
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << f(b, c, d) - f(a - 1, c, d) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#include <set>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){
  
  int a,b;
  
  cin >> a >> b;
  
  int c,d,e;
  
  c = a+b;
  d = a-b;
  e = a*b;
  
  cout << max(c,max(d,e)) << endl;



 return 0;
}

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

int main(){
  int n,mi=10000,s1,s2;cin>>n;
  vector<int> w(n,0);REP(i,n) cin>>w.at(i);
  REP(i,n-1){
    s1=s2=0;
    REP(j,n) j<=i?s1+=w.at(j):s2+=w.at(j);
    mi=min(mi,abs(s1-s2));
  }
  cout<<mi;
}

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

int main()
{
	string a, b;
	cin>>a>>b;
	int l = b.length();
	for(int i=0;i<l;i++) cout<<a[i]<<b[i];
	if(a.length() == l + 1) cout<<a[l];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i <= N; ++i){
        for(int j = 1; i * j < N; ++j){
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
int A[SIZE],ll_mi[SIZE],rr_ma[SIZE],cnt_ll[SIZE],cnt_rr[SIZE];
int main(){
    DRII(N,M);
    int mi=MOD;
    int ma=0;
    REP(i,N)RI(A[i+1]);
    ll_mi[0]=MOD;
    REPP(i,1,N+1){
        ll_mi[i]=min(ll_mi[i-1],A[i]);
        cnt_ll[i]=1;
        if(ll_mi[i]==ll_mi[i-1])cnt_ll[i]+=cnt_ll[i-1];
    }
    rr_ma[N+1]=0;
    for(int i=N;i>0;i--){
        rr_ma[i]=max(rr_ma[i+1],A[i]);
        cnt_rr[i]=1;
        if(rr_ma[i]==rr_ma[i+1])cnt_rr[i]+=cnt_rr[i+1];
        ma=max(ma,rr_ma[i]-ll_mi[i-1]);
    }
    map<int,int>H,nn;
    REPP(i,1,N+1)nn[A[i]]++;
    REPP(i,1,N){
        if(ll_mi[i]+ma==rr_ma[i+1]){
            if(H.count(ll_mi[i]))H[ll_mi[i]]=min(H[ll_mi[i]],cnt_ll[i]+cnt_rr[i+1]);
            else H[ll_mi[i]]=cnt_ll[i]+cnt_rr[i+1];
        }
    }
    int an=0;
    for(map<int,int>::iterator it=H.begin();it!=H.end();it++)an+=min(it->S,min(nn[it->F],nn[it->F+ma]));
    printf("%d\n",an);
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main()
{
	string s;
	cin>>s;
	int n=s.length();
	char g[n],c;
	int a[26];
	for(int i=0;i<26;i++)
	{
		a[i]=0;
	}
	for(int i=0;i<n;i++)
	{
		a[s[i]-97]=1;
		g[i]=s[i];
	}
	for(int i=0;i<26;i++)
	{
		if(a[i]==0)
		{
			c=i+97;
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n;){
		int sugo[1000],pos=0,i;
		for(i=0;i<n;i++)	cin>>sugo[i];
		for(i=0;i<m;i++){
			int go;	cin>>go;
			pos+=go;
			if(n-1<=pos)	break;
			pos+=sugo[pos];
			if(n-1<=pos)	break;
		}
		i++;
		cout<<i<<endl;
		for(int sk;i<m;i++)	cin>>sk;
	}
	return 0;
}

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

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define INF 10e9
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    int n, d;
    cin >> n >> d;
    vector<int> v[n];

    int x;
    int i, j;
    for(i = 0; i < n; i++){
        for(j = 0; j < d; j++){
            cin >> x;
            v[i].push_back(x);
        }
    }

    int k;
    int count = 0;
    double dist = 0;
    int dist2 = 0;
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            dist = 0;
            dist2 = 0;
            if(i == j) continue;
            for(k = 0; k < d; k++){
                dist2 += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
                dist += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
            }

            dist = (int)sqrt(dist);

            if(dist2 == dist*dist) count++;

        }
    }

    cout << count/2 << endl;
}










Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:
    x+=c[a[i]-1]
print(x)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=104;
int v[N],n,sum;
int main() {
	scanf("%d",&n);
	for (int i=1;i<n;++i) scanf("%d",&v[i]);
	sum=v[1]+v[n-1];
	for (int i=2;i<n;++i) sum+=min(v[i-1],v[i]);
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <vector>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true; else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	//return n; }
	return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

#define v vector
struct graph {
	struct node {int n, w;};
	v<v<node>> nodes;

	void read(int n) {
		nodes.resize(n);
		for (auto &x: nodes) {
			gcu();
			for (int i = 0, w; i < n; i++)
				if ((w = in()) != -1)
					x.push_back({i, w});
		}
	}

	int mst_prim() {
		int w = 0;
		v<bool> visited(nodes.size());
		priority_queue<node> q;
		q.push({0, 0});
		while (!q.empty()) {
			node n = q.top();
			q.pop();
			if (visited[n.n])
				continue;
			w += n.w;
			visited[n.n] = true;
			for (node &i: nodes[n.n])
				q.push(i);
		}

		return w;
	}
};

bool operator < (const graph::node &a, const graph::node &b) {
	return a.w > b.w;
}

int main() {
	graph g;
	g.read(in());
	out(g.mst_prim(), '\n');
}



Measured memory_bytes: 2700
N, H = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1 and H >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)

Measured memory_bytes: 11296
#include<stdio.h>
#define null -1

 struct Node{
         int parent;
         int left;
         int right;
         };

 struct Node node[100001];



 int deep(int u){
         int d=0;
         while(node[u].parent!=null){
                     u=node[u].parent;
                     d++;
                     }
         return d;
         }

 void print(int i){
         int j,c;
         printf("node %d: ",i);
         printf("parent = %d, ",node[i].parent);
         printf("depth = %d, ",deep(i));

         if(node[i].parent==null)printf("root, "); 
         else if(node[i].left==null)printf("leaf, ");
         else printf("internal node, ");

         c=node[i].left;
         printf("[");
         for(j=0;c!=null;j++){
                  if(j)printf(", ");
                  printf("%d",c);
                  c=node[c].right;
                 }
         printf("]\n");
         }
         
         


 int main(){
         int i,n,c,j,root,v,C,left;
         scanf("%d",&n);
         for(i=0;i<n;i++){node[i].right=node[i].left=node[i].parent=null;}
         for(i=0;i<n;i++){
                   scanf("%d%d",&v,&c);
                   for(j=0;j<c;j++){
                             scanf("%d",&C);
                             if(j==0)node[v].left=C;
                             else node[left].right=C;
                             left=C;
                             node[C].parent=v;
                             }
                   }


         for(i=0;i<n;i++){print(i);}
         return 0;
         }












Measured memory_bytes: 2964
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main
{
	public static void main(String[] args) {
		BufferedReader in = null;
		try {
			in = new BufferedReader(
				new InputStreamReader(System.in)
				);
			int x;
			int i = 1;
			while (true) {
				x = Integer.parseInt(in.readLine());
				if (x == 0) {
					break;
				}
				System.out.printf("Case %d: %d\n", i, x);
				i++;
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				
			}
		}
		
	}
}

Measured memory_bytes: 46612
import java.util.*;
public class Main {
    public static void main(String[] args) {
        int max = 0;
        
        int[] num;
        num = new int[101];
        Scanner input = new Scanner(System.in);
        while (input.hasNext()){
            int n = input.nextInt();
            num[n]++;
            if (max < num[n]){
                max = num[n];
            }
        }
        for (int i = 1; i <= 100; i++){
            if (num[i] == max){
                System.out.println(i);
            }
        }
    }
}

Measured memory_bytes: 18116
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;
ll intpow(int n,int m){
    if(m==0)return 1;
    return n*intpow(n,m-1);
}
ll gcd(ll n,ll m){
    n = max(n,m);
    m = min(n,m);
    if(n%m == 0)return m;
    return gcd(m,n%m);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
int main(){
    int n,m;
    cin >> n >> m;
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    /////n<m////
    vector<int>x,L;
    x.resize(m);
    L.resize(m-1);
    for(int i=0;i<m;i++)cin >> x[i];

    sort(x.begin(),x.end());
    for(int i=0;i<m-1;i++)L[i]=x[i+1]-x[i];
    sort(L.begin(),L.end(),greater<int>());
    int length = x[m-1]-x[0];
    for(int i=0;i<n-1;i++){
        length -= L[i];
    }
    cout << length << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long x,a,b,ans,c;
int main()
{
    
    cin>>x>>a>>b;
    ans=x-a;
    c=ans/b;
    if(ans%b==0)
    cout<<"0"<<endl;
    else cout<<x-a-b*c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

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

	char x;
	int cnt=0;
	REP(i,3){
		cin>>x;
		if(x=='o') cnt++;
	}
	print(700+100*cnt);
	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  regex re(R"(^(dream|dreamer|erase|eraser)+$)");
  smatch match;
  string t;
  while (cin >> t) {
    puts(regex_match(t, match, re) ? "YES" : "NO");
  }
  return 0;
}


Measured memory_bytes: 39888
/* Generated by cf-tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            ioyhhhhhhyoi    
#define next          sdNNNmNNNNNNNmds. 
#define y0          -hNNNNy_yNNNNNN_lNh-
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy--:smNNNms
#define tm          .+oooooosyysooooo+- 
#define read               :yhy/        
#define rank              :mNmo         
#define index              ... 
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m, d;
    cin >> m >> d;
    int ans = 0;
    rep(i, 1, m) {
        rep(j, 1, d) {
            int a = j % 10, b = j / 10;
            ans += a * b == i && a >= 2 && b >= 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.container; // SList, DList, BinaryHeap

void main()
{
  auto n = readln.chomp.to!size_t;

  auto edge = new size_t[][](n);
  auto parent = new size_t[](n);

  foreach (_; 0..n-1) {
    auto rd = readln.splitter;
    auto a = rd.front.to!size_t-1; rd.popFront();
    auto b = rd.front.to!size_t-1;
    edge[a] ~= b;
    edge[b] ~= a;
  }

  parent[0] = n;
  auto q = DList!size_t([0]), st = SList!size_t();
  while (!q.empty) {
    auto u = q.front; q.removeFront();
    st.insertFront(u);
    foreach (v; edge[u]) {
      if (parent[u] != v) {
        parent[v] = u;
        q.insertBack(v);
      }
    }
  }

  auto rt = new bool[](n), rtn = [n-1], c = n-1;
  while (c != 0) {
    rt[c] = true;
    c = parent[c];
    rtn ~= c;
  }
  rt[0] = true;
  auto nrtn = rtn.length;

  auto nodes = new int[](n);
  while (!st.empty) {
    auto u = st.front; st.removeFront();
    ++nodes[u];
    if (!rt[u]) nodes[parent[u]] += nodes[u];
  }

  auto n1 = nodes.indexed(rtn[0..nrtn/2]).sum;
  auto n2 = nodes.indexed(rtn[nrtn/2..$]).sum;
  if (n1 > n2)
    writeln("Snuke");
  else if (n1 < n2)
    writeln("Fennec");
  else if (nrtn % 2 == 0)
    writeln("Snuke");
  else
    writeln("Fennec");
}


Measured memory_bytes: 12668
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k;
  vector<pair<int, int> > a(n);
  REP(i, n) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  vector<int> ans;
  int prev = -1;
  while (true) {
    sort(ALL(a), greater<pair<int, int> >());
    REP(i, n) if (a[i].second != prev) {
      if (a[i].first == 0) {
        cout << -1 << '\n';
        return 0;
      }
      --a[i].first;
      ans.emplace_back(a[i].second);
    }
    if (prev == a[n - 1].second) prev = a[n - 2].second;
    else prev = a[n - 1].second;
    --k;
    if (k < 0) break;
  }
  int sz = ans.size();
  cout << sz << '\n';
  REP(i, sz) cout << ans[i] << (i == sz - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const double EPS = 1e-8, INF = 1e12, PI = acos(-1.0);
typedef complex<double> P;
namespace std{
	bool operator<(const P& a, const P& b){
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
inline double cross(const P& a, const P& b){ return imag(conj(a)*b); }
inline double dot(const P& a, const P& b){ return real(conj(a)*b); }
struct L : public vector<P>{
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};
typedef vector<P> G;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, r;
	while(cin >> h >> r, h){
		auto in = [](G &g, int n){
			rep(i, n){ int x, y; cin >> x >> y; g.emplace_back(x, y); }
		};
		
		G hs; in(hs, h);
		int U, M, S, du, dm, ds; cin >> U >> M >> S >> du >> dm >> ds;
		G us, ms, ss;
		in(us, U); in(ms, M); in(ss, S);
		G myu = {P(0, 0)};
		
		vi cnt(h);
		rep(it, r){
			int w, a; cin >> w >> a;
			rep(i, h){
				bool my = 0, other = 0;
				auto check = [&](G &ps, int width, P &p){
					for(P o : ps){
						if(abs(p - o) > a) continue;
						double t = arg(p - o) - w * PI / 180;
						if(t > PI) t -= 2 * PI;
						if(t < -PI)t += 2 * PI;
						if(abs(t) < width * PI / 180 / 2) return 1;
					}
					return 0;
				};
				my    |= check(myu, du, hs[i]);
				other |= check(us, du, hs[i]);
				other |= check(ms, dm, hs[i]);
				other |= check(ss, ds, hs[i]);
				if(my && !other) cnt[i]++;
			}
		}
		int best = *max_element(all(cnt));
		vi bests;
		rep(i, h) if(best == cnt[i]) bests.pb(i + 1);
		if(best == 0) cout << "NA" << endl;
		else rep(i, bests.size()) cout << bests[i] << (i==bests.size()-1?"\n":" ");
	}
	return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int N;
    list<int> A;
    cin >> N;
    rep(i, N) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    int result;

    int max = *std::max_element(A.begin(), A.end());
    int min = *std::min_element(A.begin(), A.end());

    result = max - min;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, X;
	cin >> A >> B >> X;

	if ((X >= A) && (X <= A + B)) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

typedef long long int   ll;
#define int             ll
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%lld",&n)
#define pb              push_back
#define PI              3.1415926535897932384626433832795
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" "
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" "
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}

signed main(){
    int t=1;
//    scan(t);
    while(t--){
        int n;cin>>n;
        int x=n%1000;
        cout<<(1000-x)%1000;
        cout<<endl;
    }
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		int num;
		String[] weight;
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){

			String n = br.readLine();
			String w = br.readLine();

			num = Integer.parseInt(n);
			weight = w.split(" ");
		} catch (IOException e) {

			return;
		}
		int minDiff = Integer.MAX_VALUE;
		for (int t = 1; t < num; t++) {

			int s1 = 0;
			for (int index = 0; index < t; index ++) {

				s1 += Integer.parseInt(weight[index]);
			}
			int s2 = 0;
			for (int index = t; index < num; index ++) {

				s2 += Integer.parseInt(weight[index]);
			}
			if (minDiff > Math.abs(s1 - s2)) {

				minDiff = Math.abs(s1 - s2);
			}
		}
		System.out.println(minDiff);
	}
}


Measured memory_bytes: 23892
/*
 *  Author : Jun_SH
 *  Solution for ABC 147 B
 */
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
    int f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return f*x;
}

main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    string s;
    cin>>s;
    n=s.length();
    int ans=0;
    for(int i=0;i<n/2;++i){
        if(s[i]!=s[n-i-1])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import itertools as it

N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

l=[n for n in range(1,N+1)]
p=list(it.permutations(l))
a=p.index(P);b=p.index(Q)
ans=abs(b-a)

print(ans)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

vector<int> g[100005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int a;
		cin >> a;
		a--;
		g[a].push_back(i);
	}
	function<int(int)> Dfs = [&](int v) {
		vector<int> tmp;
		for (int c : g[v]) {
			tmp.push_back(Dfs(c));
		}
		sort(tmp.begin(), tmp.end());
		int ret = 0;
		for (int c : tmp) {
			ret = max(ret, c) + 1;
		}
		return ret;
	};
	printf("%d\n", Dfs(0));
	return 0;
}


Measured memory_bytes: 13568