akhauriyash/Code-Regression huggingface dataset:
using System;

namespace agc013_a
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            if (n == 1)
            {
                Console.ReadLine();
                Console.WriteLine(1);
            }
            else
            {
                string[] s = Console.ReadLine().Split();
                int[] x = new int[n];
                for (int i = 0; i < n; i++)
                {
                    x[i] = int.Parse(s[i]);
                }
                int ret = 0;
                bool up = x[1] - x[0] >= 0;
                for (int i = 2; i < n; i++)
                {
                    if ((up == true && x[i] - x[i - 1] < 0 == true) || (up == false && x[i] - x[i - 1] > 0 == true))
                    {
                        ret++;
                        i++;
                        if (i >= n)
                        {
                            break;
                        }
                        while (x[i] == x[i - 1])
                        {
                            i++;
                            if (i >= n)
                            {
                                break;
                            }
                        }
                        if (i >= n)
                        {
                            break;
                        }
                        up = x[i] - x[i - 1] >= 0;
                    }
                }
                Console.WriteLine(ret + 1);
            }
            //Console.ReadLine();
        }
    }
}

Measured memory_bytes: 18528
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi a(n),b(n),c(n),d(n);
    rp(i,n) cin >> a[i] >> b[i];
    rp(i,n) cin >> c[i] >> d[i];
    ll ctr=0;
    vi usedr(n,0),usedb(n,0);
    
    rp(i,n){
        ll which;
        ll minx=1000;
        rp(j,n){
            if(usedb[j]==0&&chmin(minx,c[j])){
                which=j;
            }
        }
        usedb[which]=1;
        ll pos=-1;
        ll maxy=-1;
        rp(j,n){
            if(usedr[j]==1) continue;
            if(a[j]<c[which]&&b[j]<d[which]){
                if(chmax(maxy,b[j])){
                    pos=j;
                }
            }
        }
        if(pos>=0){
            usedr[pos]=1;
            ctr++;
        }
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

using namespace std;

#define ll long long

ll n, k, st = -1;

int main(){
    cin >> n >> k;
    for (int i = 1; i <= k; i++){
        st += 2;
    }
    if (st > n){
        cout << "NO";
    }
    else{
        cout << "YES";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long

int main(){
  ll x,y,sum=0;
  scanf("%lld %lld",&x,&y);
  if(x==1)sum+=300000;
  if(x==2)sum+=200000;
  if(x==3)sum+=100000;
  if(y==1)sum+=300000;
  if(y==2)sum+=200000;
  if(y==3)sum+=100000;
  
  if(x==1&&y==1){
    sum+=400000;
  }
  printf("%lld\n",sum );

  return 0;
  
}

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


int main() {
    std::string str;
    std::cin >> str;
    if (str[str.length() - 1] == 's') {
        std::cout << str << "es" << std::endl;
    } else {
        std::cout << str << "s" << std::endl;
    }
}


Measured memory_bytes: 3628
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int A, B;
	cin >> A >> B ;
	string s = "No";
	if (A%500<=B) {
		s = "Yes";
	}
	cout <<s<< endl;
}


Measured memory_bytes: 256
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]

p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**9
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Measured memory_bytes: 11932
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << " "
#define debugln(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define vvdebug(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N, M; cin >> N >> M;
	string S; cin >> S;
	vi ans = {}; bool f = true;
	while (N > 0 && f) {
		// debugln(N);
		for (int k = M; k >= 0; k--) {			
			// debug(k); vdebug(ans);
			if (N - k >= 0 && S.at(N - k) == '0') {
				ans.push_back(k);
				N -= k;
				break;
			}
			if (k == 1) f = false;
		}
	}	
	if (f) {
		reverse(all(ans));
		for (int k : ans) {
			cout << k << " ";
		}
		cout << endl;
	} else {
		cout << -1 << endl;
	}	
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct edge{
    int from, to, cost;
};

edge es[5010];
int N, M, P;
int d[2510];

bool shortest_path(int s){
    for(int i = 1; i <= N; i++) d[i] = inf;
    d[s] = 0;
    int cnt = 0;
    bool update = true;
    while(update && cnt <= N){
        update = false;
        cnt++;
        for(int i = 0; i < M; i++){
            edge e = es[i];
            if(d[e.from] != inf && d[e.from] + e.cost < d[e.to]){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
    }

    int res = d[N];

    cnt = 0;
    update = true;
    while(update && cnt <= N){
        update = false;
        cnt++;
        for(int i = 0; i < M; i++){
            edge e = es[i];
            if(d[e.from] != inf && d[e.from] + e.cost < d[e.to]){
                d[e.to] = d[e.from] + e.cost;
                d[e.to] = -(2e9);
                update = true;
            }
        }
    }
    return d[N] != res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M >> P;
    for(int i = 0; i < M; i++){
        int A, B, C;
        cin >> A >> B >> C;
        es[i] = {A, B, P - C};
    }
    cout << (shortest_path(1) ? -1 : max(-d[N], 0)) << endl;
    return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
n = int(input())
# 長さN になるまで、%5 = 1となる整数を列挙する
def sleve_of_Eratosthenes(n):
    # N 以下の素数を全列挙
    res = []
    if n == 1:
        return res
    ok = [False] * (1 + n)
    for i in range(2, n + 1):
        if ok[i]:
            continue
        tmp = 1
        res.append(i)
        while tmp * i <= n:
            ok[tmp * i] = True
            tmp += 1
    return res


prime = sleve_of_Eratosthenes(55555)
len_arr = 0
arr = []
for a in prime:
    if a % 5 == 1:
        arr.append(a)
        len_arr += 1
        if len_arr == n:
            break
print(*arr)


Measured memory_bytes: 65852
<?php
# 数値の入力
fscanf(STDIN, "%d %d %d", $data1, $data2, $data3);

if(($data3 - $data1 + $data2) < 0){
    echo 0;
}else{
    echo($data3 - $data1 + $data2)."\n";
}
?>

Measured memory_bytes: 3576
#!/usr/bin/env python3
import sys
import math
def is_int_distance_yz(y, z):
    dist = 0
    for (yi, zi) in zip(y, z):
        dist += (yi - zi)**2
    dist_sqrt = int(math.sqrt(dist))
    return dist == dist_sqrt**2

def solve(N: int, D: int, X: "List[List[int]]"):
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            if is_int_distance_yz(y=X[i], z=X[j]):
                ans += 1
    print(ans)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [[int(next(tokens)) for _ in range(D)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int oo = 1<<29;
int n;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	int res = oo;
	forn(i,1,n){
		int a = i;
		int b = n-i;
		string _a = to_string(a);
		string _b = to_string(b);
		int act = 0;
		forn(j,0,_a.size()) act += _a[j]-'0';
		forn(j,0,_b.size()) act += _b[j]-'0';
		res = min(res,act);
 	}
	cout << res << '\n';
	return 0;
}


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

#define int long long

int32_t main(){ 

    ios::sync_with_stdio(0);
    cin.tie(0);

    int a, b, n;
    cin >> a >> b >> n;
    int ans = min(n, b - 1);
    cout << floor(a * ans / b) - a * floor(ans / b);
    
    return 0;
} 

Measured memory_bytes: 3776
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2401
	
	ACM-ICPC Japan Alumni Group Practice Contest for Japan Domestic 2012, 2012-06-17 

	Equation

	構文解析の問題

	定数: T, F
	変数: a, b, c, d, e, f, g, h, i, j, k
	論理否定: -X
	論理積: (X*Y)
	論理和: (X+Y)
	論理包含: (X->Y)


	x	y	-x	(x*y)	(x+y)	(x->y)
	T	T	F	T	T	T
	T	F	F	F	T	F
	F	T	T	F	T	T
	F	F	T	F	F	T

	<equation> ::= <formula> "=" <formula>
	<formula>  ::= "T" | "F" |
	"a" | "b" | "c" | "d" | "e" | "f" |
	"g" | "h" | "i" | "j" | "k" |
	"-" <formula> |
	"(" <formula> "*" <formula> ")" |
	"(" <formula> "+" <formula> ")" |
	"(" <formula> "->" <formula> ")"

*/
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int idx = 0;
string eq;
bool formula (void ){

	bool f1 = false, f2 = false;
	if (eq[idx] == '-' ){
		idx++;
		f1 = !formula ();
		return f1;
	}else
	if (eq[idx] == '(' ){
		idx++;
		f1 = formula ();
		if (eq[idx] == '*' ){
			idx++;
			f2 = formula ();
			idx++;	// omit ')'
			return f1 & f2;
		}else
		if (eq[idx] == '+' ){
			idx++;
			f2 = formula ();
			idx++;	// omit ')'
			return f1 | f2;
		}else
		if (eq[idx] == '-' && idx + 1 < eq.size() && eq[idx+1] == '>' ){
			idx += 2;
			f2 = formula ();
			idx++;	// omit ')'
			return !(f1 & !f2 );
		} // end if
	}else{
		if (eq[idx] == 'T' ){
			f1 = true;
		}else{
			f1 = false;
		} // end if
		idx++;
		return f1;
	} // end if

	return false;
}

bool equation (void ){
	bool f1 = formula ();
	if (eq[idx] == '=' ) idx++;
	bool f2 = formula ();

	return (f1 == f2 );
}

bool parse (string s ){
	eq = s;
	idx = 0;
	bool res = equation ();

	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	string s = "";
	while (cin >> s && s != "#" ){
		int n = s.length();
		vector<char> val; val.clear();
		rep (i, n ){
			if (s[i] >= 'a' && s[i] <= 'k' ) val.push_back (s[i] );
		} // end rep
		sort (ALL (val ) );
		val.erase (unique (ALL (val ) ), val.end() );

		bool res = true;

		if (val.empty() ){
			res = parse (s );
		}else{
			rep (i, 1<<val.size() ){
				string t = s;
				rep (j, val.size() ){
					if (i&(1<<j) ){
						rep (k, t.size() ) if (t[k] == val[j] ) t[k] = 'T';
					} // end if
				} // end rep
				rep (k, t.size() ) if (islower (t[k] ) ) t[k] = 'F';
				res &= parse (t );
			} // end rep
		} // edn if
		cout << (res ? "YES" : "NO" ) << endl;
	} // end while
	
	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

struct edge{ll to, cost;};
vector<vector<edge>> G(100005);

vector<bool> ans(100005);

void dfs(ll v, ll p, bool c){
    ans[v] = c;

    rep(i, G[v].size()){
        if(G[v][i].to == p)continue;

        // 距離が奇数なので違う色で塗る
        if(G[v][i].cost & 1)dfs(G[v][i].to, v, !c);
        else dfs(G[v][i].to, v, c);
    }
}

int main(){
    ll n;
    cin >> n;

    rep(i, n-1){
        ll u, v, w;
        cin >> u >> v >> w;
        u--, v--;

        G[u].push_back(edge{v, w});
        G[v].push_back(edge{u, w});
    }

    dfs(0, 0, true);

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

Measured memory_bytes: 13816
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node{ int bwhite, bbrack, wwhite, wbrack; };

int n, p[1000], x[1000];
vector<int> g[1000];
node v[1000];

void check(int num) {
	v[num] = node{ INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX};

	for (int i = 0; i < g[num].size(); i++) {
		check(g[num][i]);
	}

	int brack = 0, white = 0;
	int bbsum = 0, bwsum = 0, wwsum = 0, wbsum = 0;
	vector<int> bvec, wvec;
	for (int i = 0; i < g[num].size(); i++) {
		node a = v[g[num][i]];
		if (a.bbrack == INT32_MAX && a.wwhite == INT32_MAX) {
			return;
		}

		if (a.bbrack != INT32_MAX && a.wwhite == INT32_MAX)brack += a.bbrack;
		if (a.bbrack == INT32_MAX && a.wwhite != INT32_MAX)white += a.wwhite;

		if (a.bbrack != INT32_MAX && a.wwhite != INT32_MAX) {
			bvec.push_back(g[num][i]);
			wvec.push_back(g[num][i]);
			bbsum += v[g[num][i]].bbrack;
			bwsum += v[g[num][i]].bwhite;
			wwsum += v[g[num][i]].wwhite;
			wbsum += v[g[num][i]].wbrack;
		}
	}
	if (brack <= x[num])v[num].bbrack = x[num];
	if (white <= x[num])v[num].wwhite = x[num];

	vector<vector<int>> dpb(bvec.size() + 1, vector<int>(x[num] - brack + 1, INT32_MAX));
	vector<vector<int>> dpw(wvec.size() + 1, vector<int>(x[num] - white + 1, INT32_MAX));

	dpb[0][0] = 0; dpw[0][0] = 0;
	for (int i = 0; i < dpb.size()-1; i++) {
		for (int j = 0; j <= x[num] - brack; j++) {
			if (dpb[i][j] != INT32_MAX) {
				if (j + v[bvec[i]].wbrack <= x[num] - brack) {
					dpb[i + 1][j + v[bvec[i]].wbrack] = min(dpb[i + 1][j], dpb[i][j] + v[bvec[i]].wwhite);
				}
				if (j + v[bvec[i]].bbrack <= x[num] - brack) {
					dpb[i + 1][j+v[bvec[i]].bbrack] = min(dpb[i + 1][j+v[bvec[i]].bbrack], dpb[i][j]+v[bvec[i]].bwhite);
				}
			}
		}

		for (int j = 0; j <= x[num] - white; j++) {
			if (dpw[i][j] != INT32_MAX) {
				if (j + v[wvec[i]].bwhite <= x[num] - white) {
					dpw[i + 1][j + v[wvec[i]].bwhite] = min(dpw[i + 1][j], dpw[i][j] + v[wvec[i]].bbrack);
				}
				if (j + v[wvec[i]].wwhite <= x[num] - white) {
					dpw[i + 1][j + v[wvec[i]].wwhite] = min(dpw[i + 1][j + v[wvec[i]].wwhite], dpw[i][j] + v[wvec[i]].wbrack);
				}
			}
		}
	}

	int bwmin = INT32_MAX, wbmin = INT32_MAX;
	for (int i = 0; i <= x[num]-brack; i++) {
		if (dpb[bvec.size()][i] != INT32_MAX) {
			bwmin = min(dpb[bvec.size()][i], bwmin);
			v[num].bwhite = bwmin;
		}
	}
	for (int i = 0; i <= x[num] - white; i++) {
		if (dpw[wvec.size()][i] != INT32_MAX) {
			wbmin = min(dpw[wvec.size()][i], wbmin);
			v[num].wbrack = wbmin;
		}
	}

	if (brack <= x[num]) {
		v[num].bwhite += white;
		v[num].bbrack = (v[num].bwhite == INT32_MAX)?INT32_MAX:v[num].bbrack;
	}
	if (white <= x[num]) {
		v[num].wbrack += brack;
		v[num].wwhite = (v[num].wbrack == INT32_MAX)?INT32_MAX:v[num].wwhite;
	}
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> p[i];
		g[p[i] - 1].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	check(0);

	if ((v[0].bbrack != INT32_MAX) && (v[0].wwhite != INT32_MAX)) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
}

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

int main(){
    //入力の取得
    int n, m;
    cin >> n >> m;
    int a[n][m];
    int b[m];
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    // 出力の計算
    for (int i=0; i<m; i++) cin >> b[i];
    for (int i=0; i<n; i++) {
        int sum = 0;
        for (int j=0; j<m; j++) {
            sum += a[i][j]*b[j];
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
N, M, Q = map(int, input().split())
train = [[0 for _ in range(N+1)] for _ in range(N+1)]

for i in range(M):
    l, r = map(int, input().split())
    train[l][r] +=1
    
for i in range(N+1):
    for j in range(N):
        train[i][j+1] += train[i][j]
        
for i in range(N):
    for j in range(N+1):
        train[i+1][j] += train[i][j]
        
for i in range(Q):
    p, q = map(int, input().split())
    print(train[q][q]+train[p-1][p-1]-train[p-1][q]-train[q][p-1])

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

int main(){
    ll N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    vector<vector<ll>> dp(N, vector<ll>(3, 0));
    int r = 0, s = 1, p = 2;
    if (T[0] == 's') dp[0][r] = R;
    if (T[0] == 'p') dp[0][s] = S;
    if (T[0] == 'r') dp[0][p] = P;
    for (int i = 1; i < N; i++) {
        if (i < K) {
            if (T[i] == 's') dp[i][r] += R;
            if (T[i] == 'p') dp[i][s] += S;
            if (T[i] == 'r') dp[i][p] += P;
        }
        else {
            dp[i][r] = max(dp[i-K][s], dp[i-K][p]);
            dp[i][s] = max(dp[i-K][r], dp[i-K][p]);
            dp[i][p] = max(dp[i-K][s], dp[i-K][r]);
            if (T[i] == 's') dp[i][r] += R;
            if (T[i] == 'p') dp[i][s] += S;
            if (T[i] == 'r') dp[i][p] += P;
        }
    }
    ll ans = 0;
    for (int i = N-K; i < N; i++) {
        ans += max(max(dp[i][r], dp[i][s]), dp[i][p]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<math.h>
int min(int a,int b)
{
    return a<b?a:b;
}
int main() {
    int n,a[100000],i,diff,b[100000];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        b[i]=min(b[i-1]+abs(a[i]-a[i-1]),b[i-2]+abs(a[i]-a[i-2]));
    }
   /*for(i=0;i<n;i++)
    {
        printf("%d ",b[i]);
    }*/
    printf("%d ",b[n-1]);
  return 0;
}

Measured memory_bytes: 896
# https://atcoder.jp/contests/abc142/submissions/7753443
 
N,M = map(int,input().split())
 
lis = [float("inf")] * (2 ** N)
lis[0] = 0
 
for i in range(M):
 
    a,b = map(int,input().split())
 
    c = list(map(int,input().split()))
 
    num = 0
    for j in c:
        num += 2 ** (j-1)
 
    nlis = lis.copy()
    for j in range(2 ** N):
 
        if lis[j | num] > nlis[j] + a:
            lis[j | num] = nlis[j] + a     
 
#print (lis)
if lis[2 ** N -1] == float("inf"):
    print (-1)
 
else:
    print (lis[2 ** N - 1])

Measured memory_bytes: 3316
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt(), q = scanner.nextInt();
			int[][] x = new int[n][n], c = new int[n + 1][n + 1];
			IntStream.range(0, n).forEach(i -> Arrays.fill(x[i], 0));
			IntStream.range(0, m).forEach(i -> {
				int l = scanner.nextInt() - 1, r = scanner.nextInt() - 1;
				x[l][r]++;
			});
			Arrays.fill(c[0], 0);
			IntStream.rangeClosed(1, n).forEach(i -> c[i][0] = 0);
			IntStream.rangeClosed(1, n)
					.forEach(i -> IntStream.rangeClosed(1, n).forEach(j -> c[i][j] = c[i][j - 1] + x[i - 1][j - 1]));
			IntStream.range(0, q).forEach(i -> {
				int l = scanner.nextInt(), r = scanner.nextInt();
				System.out.println(IntStream.rangeClosed(l, r).map(j -> c[j][r] - c[j][l - 1]).sum());
			});
		}
	}
}


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

namespace ABC128
{
	class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
			var N = nk[0];
			var K = nk[1] + 1;
			var V = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

			var ans = 0;
			foreach (var a in Enumerable.Range(0, K))
			{
				var queueA = V.Take(a).ToList();
				foreach (var b in Enumerable.Range(0, K - a))
				{
					var queueB = queueA.Concat(V.Skip(Math.Max(a, N - b))).ToList();
					foreach (var c in Enumerable.Range(0, Math.Min(K - (a + b), queueB.Count() + 1)))
					{
						var queueC = queueB.OrderBy(x => x).Skip(c);
						ans = Math.Max(ans, queueC.Sum());
					}
				}
			}
			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 15584
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll S, temp;
int main()
{
    std::ios::sync_with_stdio(0);
	std::cin.tie(0);
    cin >> S;
    if (S <= 1000000000)
    {
        cout << S << " 0 0 0 0 1" << endl;
    }
    else if(S == 1000000000000000000)
    {
        cout << "0 0 1000000000 0 0 1000000000" << endl;
    }
    else
    {
        S += 1000000000;
        temp = S % 1000000000;
        S -= temp;
        cout << "0 1000000000 1 0 " << S / 1000000000 << " " << temp << endl; 
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 3656
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	class D implements Comparable<D>{
		int l, p;

		D(int l, int p) {
			this.l = l;
			this.p = p;
		}

		@Override
		public int compareTo(D o) {
			return o.p - this.p;
		}

		@Override
		public String toString() {
			return "(" + l + ", " + p + ")";
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if ((n | m) == 0) {
				break;
			}
			D[] d = new D[n];
			for (int i = 0; i < n; i++) {
				d[i] = new D(sc.nextInt(), sc.nextInt());
			}
			Arrays.sort(d);
			int id = 0;
			while (0 < m && id < n) {
				if (d[id].l == 0) {
					id++;
					continue;
				}
				d[id].l--;
				m--;
			}

			int ans = 0;
			for (int i = 0; i < n; i++) {
				ans += d[i].l * d[i].p;
			}
			System.out.println(ans);
		}
	}

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

Measured memory_bytes: 80796
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		int k = sc1.nextInt();

		int ans = n - k + 1;

		System.out.println(ans);

		sc1.close();

	}

}

Measured memory_bytes: 22868
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
        int N;
        map<int,int> counter;
        vector<long long int> each;
        map<int,bool> past;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                int x;
                cin >> x;
                counter[x]++;
                each.push_back(x);
                past[x]=false;
        }
        int count=0;
        long long int S[2];
        vector<long long int>::iterator itr;
        sort(each.begin(),each.end(),greater<long long int>());
        for( itr=each.begin() ; itr!=each.end() ; ++itr ){
                if(past[*itr])continue;
                if(counter[*itr]>=4 && count==0){
                        cout<<*itr*(*itr)<<endl;
                        return 0;
                }
                if(counter[*itr]>=2){
                        past[*itr]=true;
                        S[count]=*itr;
                        count++;
                }
                if(count>1)break;
        }
        if(count>1)
                cout << S[0]*S[1] << endl;
        else
                cout<<0<<endl;
        return 0;
}

Measured memory_bytes: 10356
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  string s; int k; cin >> s >> k;
  vector<string> arr;
  for(int i=1; i<=s.size() && i<=k; ++i) {
    rep(j, s.size()-i+1) {
      arr.push_back(s.substr(j, i));
    }
  }
  sort(arr.begin(), arr.end());
  unique(arr.begin(), arr.end());
  cout << arr[k-1] << endl;
}

Measured memory_bytes: 1660
(let* ((n (read))
    (a (make-array 100001 :initial-element 0))
    (q 0)
    (ans 0))
    (dotimes (i n)
        (let ((d (read)))
        (incf (aref a d))
        (incf ans d)
        )
    )
    (setq q (read))
    (dotimes (i q)
        (let ((b (read))
            (c (read)))
            (incf (aref a c) (aref a b))
            (incf ans (* (aref a b) (- c b)))
            (setf (aref a b) 0)
        )
        (format t "~D~%" ans)
    )
)

Measured memory_bytes: 77772
public class Main {

  private static void solve() {
    int x = ni();

    boolean[] dp = new boolean[x + 1000];
    dp[0] = true;

    int[] a = {100, 101, 102, 103, 104, 105};
    for (int i = 0; i < x; i++) {
      if (dp[i]) {
        for (int v : a) {
          dp[i + v] = true;
        }
      }
    }
    System.out.println(dp[x] ? 1 : 0);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

int a[100000];
int ans = 0, N;

bool dfs(int x) {
  ans++;
  if (a[x] == 2) {
    return true;
  }
  else if (ans == N) {
    return false;
  }
  else {
    dfs(a[x]);
  }
} 

int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  if (dfs(1)) {
    cout << ans;
  }
  else {
    cout << -1;
  }
}

Measured memory_bytes: 640
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    K = int(input())
    A, B = map(int, input().split())
    mx = (B//K)*K

    print('NOGK'[mx>=A::2])

if __name__ == '__main__':
    main()

Measured memory_bytes: 9120
import math

from functools import reduce
K=int(input())

def gcd_list(numbers):
  return reduce(math.gcd, numbers)


count=0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      if i==j and j==k and k==i:
        n=1
      elif i==j or j==k or k==i:
        n=3
      else:
        n=6
      count+=n*gcd_list([i,j,k])

print(count)

Measured memory_bytes: 9540
# abc085

N, Y = map(int, input().split())
ans = "-1 -1 -1"

for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if x*10000 + y*5000 + z*1000 == Y:
            ans = (" ".join(list(map(str, [x, y, z]))))
            break

print(ans)

Measured memory_bytes: 9196
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;


int main()
{
	int n;
	while (cin >> n, n) {
		int y;
		double ans = 0,ans_n=0;
		cin >> y;
		for (int i = 0; i < n; i++) {
			int b, r, t;
			cin >> b >> r >> t;
			double num;
			if (t == 1) {
				num = 1+y*r/100.0;
			}else if(t == 2){
				num = pow(1 + r / 100.0, y);
			}
			if (ans < num) {
				ans = num;
				ans_n = b;
			}
		}
		cout << ans_n << endl;
	}
	return 0;
}

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

int main()
{
    int A, P, ap=0;
    cin >> A>>P;

    ap = A * 3 + P;
    ap = ap - (ap % 2);
    /*
    if(ap<2){
        cout<<
    }
    */
    cout << ap/2 << endl;

}


Measured memory_bytes: 256
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define oo 2000000007
#define sz(a) (int)a.size()
#define BASE 100

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, a[maxN];
map<int, int> cnt;

int main () {
    scanf("%d", &n);
    fto(i, 1, n) scanf("%d", &a[i]);

    fto(i, 1, n) {
        fto(j, -1, 1) ++cnt[a[i]+j];
    }

    int ans = 0;
    fto(i, 1, n) {
        fto(j, -1, 1) ans = max(ans, cnt[a[i]+j]);
    }
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 5120
n = int(input())
x = list(map(int, input().split()))
hp = 0
ans = 0

for p in range(min(x), max(x)+1):
  hp = 0
  for j in range(n):
    hp += (x[j]-p) ** 2
  if p == min(x):
    ans = hp
  elif ans >= hp:
    ans = hp

print(ans)

Measured memory_bytes: 3064
S=input()
N=len(S)
S_r=S[:(N-1)//2]
S_l=S[(N-1)//2+1:]


for i in range(N):
  if S[i]!=S[-i-1]:
    print("No");exit()
for i in range(N//2):
  if S_l[i]!=S_l[-i-1]:
    print("No");exit()
  if S_r[i]!=S_r[-i-1]:
    print("No");exit()
print("Yes")

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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

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

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

typedef long long LL;
typedef pair<int, int> PII;

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

const int MAX = 1 << 18;

int a[MAX], b[MAX];

int main()
{
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	LL s = 0;
	int mn = INF;
	FOR(i, 0, n)
	{
		cin >> a[i] >> b[i];
		s += b[i];
		if(a[i] > b[i])
			mn = min(mn, b[i]);
	}
	cout << (mn == INF ? 0 : s - mn) << "\n";
	return 0;
}

Measured memory_bytes: 384
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)
ass = set()
N,K=map(int,input().split())
uni = UnionFind(K-1)
for _ in range(N):
    t = list(map(int,input().split()))
    ass.add(t[1]-1)
    if t[0] !=1:
        for k in t[2:]:
            uni.union(t[1]-1,k-1)
            ass.add(k-1)
            #print(t[1]-1,k-1)
p = set()
for i in ass:
    d = uni.find(i)
    p.add(d)
print("YES" if 1 ==len(p) else "NO")


Measured memory_bytes: 11608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2e5+5;
int par[N],r[N];
int Find(int x)
{
	if(par[x]!=x) par[x]=Find(par[x]);
	return par[x];
}
void Union(int a,int b)
{
	int x=Find(a),y=Find(b);
	if(x==y) return;
	if(r[x]<r[y]) par[x]=y;
	else if(r[x]>r[y]) par[y]=x;
	else
	{
		par[y]=x;
		r[x]++;
	}
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++) par[i]=i,r[i]=0;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		Union(a,b);
	}
	for(int i=0;i<n;i++) par[i]=Find(i);
	sort(par,par+n);
	int c=0,i=0;
	while(i<n)
	{
		int tc=1;
		i++;
		while(i<n&&par[i]==par[i-1]) i++,tc++;
		c=max(c,tc);
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 5160
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d; cin>>a>>b>>c>>d;
	int x=(c+b-1)/b, y=(a+d-1)/d;
	cout<< (x<=y?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(m);
	vector<vector<int>>L(n);
	rep(i,n){
		int k;
		cin>>k;
		int parent;
		rep(j,k){
			int l;
			cin>>l;
			l--;
			if(j==0){
				parent=l;
			}
			uf.merge(l,parent);
			L[i].push_back(l);
		}
	}
	 m=L[0][0];
	bool ok=true;
	rep(i,n){
		if(uf.issame(L[i][0],m)){

		}else{
			ok=false;
		}
	}
	if(ok){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}


}



Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int C = (A+K-1)/K*K;
  if(A <= C && C <= B) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        int[] nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int[] h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int n = nm[0];
        int m = nm[1];
        List<List<int>> t = new List<List<int>>();
        for (int i = 0; i < n; i++)
        {
            t.Add(new List<int>());
        }
        for (int i = 0; i < m; i++)
        {
            int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s) - 1).ToArray();
            t[ab[0]].Add(h[ab[1]]);
            t[ab[1]].Add(h[ab[0]]);
        }
        int cnt = 0;
        for (int i = 0; i < t.Count(); i++)
        {
            if (t[i].Count() == 0)
                cnt++;
            else if (t[i].Max() < h[i])
                cnt++;
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 56192
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(b>=a || 2*b>=a)
    cout<<0<<"\n";
    else if(a>b)
    cout<<(a-2*b)<<"\n";
}

Measured memory_bytes: 3616
marks = ["S","H","C","D"]
all_cards = []
for i in marks:
    for j in range(1,14):
        all_cards.append(str(i) + " " + str(j))

n = int(input())
p_cards = []

for x in range(n):
    p_cards.append(str(input()))

for y in p_cards:
    all_cards.remove(y)

for z in all_cards:
    print(z)

Measured memory_bytes: 7740
object Main extends App {
    val stdin = new java.util.Scanner(new java.io.BufferedInputStream(System.in))
    val stdout = new java.io.PrintWriter(new java.io.BufferedOutputStream(System.out))

    while (stdin.hasNext()) {
        val foo = stdin.nextInt()
        val bar = foo + foo * foo + foo * foo * foo : java.lang.Integer
        stdout.printf("%d\n", bar)
    }

    stdin.close()
    stdout.close()
}

Measured memory_bytes: 55212
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// N - 取得
	long long llN;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &llN);
	llN--;

	// 桁数 - 取得
	long long llMax = 26;
	int liDCnt;
	for (liDCnt = 1; llN >= llMax; liDCnt++) {
		llN -= llMax;
		llMax *= 26;
	}

	// 名前 - セット
	for (i = 0; i < liDCnt; i++) {
		llMax /= 26;
		lc1Buf[i] = 'a' + (char)(llN / llMax);
		llN %= llMax;
	}
	lc1Buf[liDCnt] = '\n';
	lc1Buf[liDCnt + 1] = '\0';

	// 出力
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

typedef long long int llint;

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

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

    int cc = 0; 
    int t = i;  

    while(t > 0) cc += t % 6, t /= 6;
    t = n - i;

    while(t > 0) cc += t % 9, t /= 9;

    mn = min(mn, cc);
    
  }

  cout<< mn <<endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  ll n;
  cin >> n;
  vector<ll> from(n-1, 0);
  vector<ll> to(n-1, 0);
  vector<ll> cost(n-1, 0);
  for (ll i = 0; i < n-1; i++)
  {
    cin >> from[i] >> to[i] >> cost[i];
  }
  vector<vector<p>> graph(n, vector<p>());
  for(ll i = 0; i < n-1; i++)
  {
    graph[from[i]-1].push_back({to[i], cost[i]});
    graph[to[i]-1].push_back({from[i], cost[i]});
  }

  ll q, k;
  cin >> q >> k;
  vector<p> qv(q, {0,0});
  for(ll i = 0; i < q; i++)
  {
    cin >> qv[i].first >> qv[i].second;
  }


  queue<p> bfs;
  for(auto a : graph[k-1])
  {
    bfs.push(a);
  }
  vector<bool> visited(n, false);
  visited[k-1] = true;
  vector<ll> distance(n, 0);
  // cout << k-1 << " : " << distance[k-1] << endl;
  distance[k-1] = 0;


  while(ll(bfs.size()) != 0)
  {
    p tmp = bfs.front();
    bfs.pop();

    ll beforeCost = 0;
    for(auto a : graph[tmp.first-1])
    {
      if(visited[a.first-1]){
        beforeCost = distance[a.first-1];
        break;
      }
    }

    distance[tmp.first-1] = tmp.second + beforeCost;

    //cout << tmp.first << " : " << tmp.second << endl;
    // for(auto a : graph[tmp.first-1]) cout << a.first << " : " << a.second << endl;

    // cout << "==========" << endl;
    // cout << tmp.first-1 << endl;
    // cout << "==========" << endl;
    // for(bool a : visited) cout << a << endl;
    for(auto a : graph[tmp.first-1])
    {
      if(!visited[a.first-1])//cout << "push!" << endl;
      bfs.push(a);
    }
    visited[tmp.first-1] = true;

  }

  for(ll i = 0; i <q; i++)
  {
    cout << distance[qv[i].first-1] + distance[qv[i].second-1] << endl;
  }

  // cout << "==========" << endl;
  //
  //
  // for(auto a : distance)
  // {
  //   cout << a << endl;
  // }

}

Measured memory_bytes: 14704
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int N;
pair<int, int> ai[100000];

int main(int argc, char **argv) {
	cin >> N;
	REP(i, N) {
		cin >> ai[i].first;
		ai[i].second = i;
	}
	sort(ai, ai + N);
	int res = 0;
	REP(i, N) if (i % 2 != ai[i].second % 2) ++res;
	cout << (res / 2) << endl;
	return 0;
}


Measured memory_bytes: 1024