akhauriyash/Code-Regression huggingface dataset:
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	200005

int		N, d1, x;

DB		Ans, A[n];

int		main(int argc, char* argv[]){
		N= IN();
		d1= IN();
		x= IN();
		
		For(i, 1, N)	A[i]= A[i-1] + .25 / (i+1);
		
		For(i, 1, N)	{
			DB	a= d1 + (2*i-2)*x,
				b= d1 + (2*i-1)*x;
			
			Ans+= .5 * (a + b);
			Ans+= (a + b) * (A[i-1] + A[N-i]);
		}
		
		printf("%.12lf\n", Ans);
		
		return	0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int N,n;
	char m;
	int s[13]={},h[13]={},c[13]={},d[13]={};
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>m>>n;
		switch(m)
		{
			case 'S':
                    s[n-1] = 1;
                    break;
            case 'H':
                    h[n-1] = 1;
                    break;
            case 'C':
                    c[n-1] = 1;
                    break;
            case 'D':
                    d[n-1] = 1;
                    break;
        }
    }
    for(int i = 1;i<=13;i++)
	{
        if(s[i-1] == 0) cout << "S" << " " << i <<endl;
    }
    for(int i = 1;i<=13;i++)
	{
        if(h[i-1] == 0) cout << "H" << " " << i <<endl;
    }
    for(int i = 1;i<=13;i++)
	{
        if(c[i-1] == 0) cout << "C" << " " << i <<endl;
    }
    for(int i = 1;i<=13;i++)
	{
        if(d[i-1] == 0) cout << "D" << " " << i <<endl;
    }				
}

Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>

using namespace std;

void trace(int A[], int N) {
	int i;
	for (int i = 0; i < N; ++i) {
		if (i > 0)printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insert(int A[], int N) {
	int j, i, v;
	for(i = 1;i<N;++i){
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	bool flag = false;
	while (true) {
		C -= B;
		if (C <= 0) {
			cout << "Yes" << endl;
			break;
		}
		A -= D;
		if (A <= 0) {
			cout << "No" << endl;
			break;
		}
	}


	return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
from collections import Counter

MOD = 1000000007  # type: int

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = {i:0 for i in range(1, n+1) if is_prime[i-1]}
    # return is_prime, table
    return table

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def solve(N: int, A: "List[int]"):
    table = dict()

    for i in range(N):
        decom = Counter(prime_decomposition(A[i]))

        for d,number in decom.items():
            if table.get(d) == None:
                table[d] = number
                continue

            if table[d] < number:
                table[d] = number
    LCM = 1
    for key,value in table.items():
        LCM *= key**value
        LCM %= MOD

    print(sum([LCM*pow(a,MOD-2,MOD) for a in A])%MOD)

    return


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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

using namespace std;

using int64 = long long;
const int INF = 1 << 30;


int main() {
  int H, W, N;
  cin >> H >> W >> N;
  set< pair< int, int > > mp;
  for(int i = 0; i < N; i++) {
    int y, x;
    cin >> y >> x;
    --y, --x;
    mp.emplace(y, x);
  }
  set< pair< int, int > > added;
  vector< int64 > sum(10);
  for(auto &p : mp) {
    for(int i = -2; i <= 0; i++) {
      for(int j = -2; j <= 0; j++) {
        int y = p.first + i, x = p.second + j;
        if(y < 0 || x < 0) continue;
        if(y + 2 >= H || x + 2 >= W) continue;
        if(added.count({y, x})) continue;
        added.emplace(y, x);
        int cost = 0;
        for(int k = 0; k < 3; k++) {
          for(int l = 0; l < 3; l++) {
            cost += mp.count({y + k, x + l});
          }
        }

        sum[cost]++;
      }
    }
  }
  int64 all = 1LL * (H - 2) * (W - 2);
  for(int i = 1; i < 10; i++) all -= sum[i];
  sum[0] = all;
  for(auto &p : sum) cout << p << endl;
}

Measured memory_bytes: 47104
#include<stdio.h>

int main(){

  int n, i; 
  double x[4], y[4], kat[2];

  scanf("%d",&n);

  for(i = 0 ; i < n; i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]);


    kat[0] = (y[1] - y[0]) / (x[1] - x[0]);
    kat[1] = (y[2] - y[3]) / (x[2] - x[3]);

    if(x[0] == x[1] && x[2] == x[3]){
      printf("YES\n");
    }else if(x[0] == x[1] || x[2] == x[3]){
      printf("NO\n");
    }else if(kat[0] == kat[1]){
      printf("YES\n");
    }else{
      printf("NO\n");
    }

  }

  return 0;
}

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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    long long n, k, a, b, c;
    cin >> n >> k;
    c = (n/k)*k;
    a = abs(c - n);
    b = abs(c+k - n);
    cout << min(a, b) << endl;
    return 0;
}

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

int main(void) {
	int A, B, H, M;
	double theta_zi, theta_fun;
	double pi = atan(1) * 4;
	double yukati;
	double zix, ziy, funx, funy;
	if (scanf("%d%d%d%d", &A, &B, &H, &M) != 4) return 1;
	yukati = H + M / 60.0;

	theta_zi = 2 * pi * yukati / 12;
	theta_fun = 2 * pi * yukati;

	zix = A * sin(theta_zi);
	ziy = A * cos(theta_zi);
	funx = B * sin(theta_fun);
	funy = B * cos(theta_fun);

	printf("%.15f\n", sqrt((zix - funx) * (zix - funx) + (ziy - funy) * (ziy - funy)));
	return 0;
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H=0,A=0,ans=0;
  cin >> H >> A;
  if(H%A==0){
    ans=H/A;
  }
  else{
    ans=H/A+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//atcoderはScannerクラスのsc.next()で行ける
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int flagcnt = 0;
        boolean flag = false;
        for (int i = 0; i < n; i++) {
            int i1 = sc.nextInt();
            int i2 = sc.nextInt();
            if (i1 == i2) {
                flagcnt += 1;
            } else {
                flagcnt = 0;
            }
            if (flagcnt > 2) {
                flag = true;
                break;
            }
        }
        if (flag) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }


    }
}

Measured memory_bytes: 36096
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,r = I()
if n < 10:
    print(100*(10-n)+r)
else:
    print(r)


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

int main() {
  int H, W; cin >> H >> W;
  int sum=0;
  vector<vector<char>> grid(H,vector<char>(W));
  vector<int> Hgrid(H);
  vector<int> Wgrid(W);
  for (int i=0;i<H;i++){
  	for (int j=0;j<W;j++){
  		cin >> grid.at(i).at(j);
  	}
  }
  	for(int i=0;i<H;i++){
  		for(int j=0;j<W;j++){
  			if(grid.at(i).at(j)=='#') sum++;
  		}
  		if (sum==0) Hgrid.at(i)=1;
  		sum=0;
  	}
  	for(int j=0;j<W;j++){
  		for(int i=0;i<H;i++){
  			if(grid.at(i).at(j)=='#') sum++;
  		}
  		if (sum==0)Wgrid.at(j)=1;
  		sum=0;
  	}
  	for(int i=0;i<H;i++){
  		for (int j=0;j<W;j++){
  			if(Hgrid.at(i)==0 && Wgrid.at(j)==0){
  				cout << grid.at(i).at(j);
  			}
  		}
      if (Hgrid.at(i)==0) cout << endl;
  	}
  }

Measured memory_bytes: 256
# coding: utf-8

N = int(input())
ans = N

robot_list = []
for i in range(N):
    x, l = map(int,input().split())
    s = x - l
    t = x + l
    robot_list.append([s, t])

robot_list.sort(key=lambda x:x[1])
#print(robot_list)
c = robot_list[0][1]
for i in range(1,N):
    if robot_list[i][0] < c:
        ans -= 1
        #print(robot_list[i][0], c)
    else:
        c = robot_list[i][1]
        #print(ans)

print(ans)

Measured memory_bytes: 21336
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n, cnt=0;cin>>n;
  vector<int> a(n), rate(9,0);
  for(int i=0;i<n;i++){
    cin >> a[i];
    a[i] = min(a[i], 3200);
    rate[a[i]/400]++;
  }
  for(int i=0;i<8;i++){
    if(rate[i]>0){
      cnt++;
    }
  }
  cout << max(cnt, 1) << " " << cnt+rate[8] << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main() {
  int n, a;
  cin >> n >> a;
  if(n % 500 <= a) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

def main():
	N, K = map(int, input().split())
	DIV = 10**9+7
	ab = [[] for _ in range(N)]

	def P(n, r):
		ans = 1
		for i in range(r):
			ans = (ans*(n-i)) % DIV
		return ans

	for _ in range(N-1):
		u, v = map(int, input().split())
		ab[u-1].append(v-1)
		ab[v-1].append(u-1)

	def dfs(v, p=-1):
		c = 0
		ans = 1
		for u in ab[v]:
			if u == p:
				continue
			c += 1
			ans = ans * dfs(u, v) % DIV
		nk = K-1
		if p != -1:
			nk = K-2
		ans *= P(nk, c)
		return ans%DIV
	ans = dfs(0)*K%DIV
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 103724
/*  ex3_3
    key_tree  */
#include<stdio.h>
int main(void){
  
  int N, K, division, digit;
  scanf("%d %d",&N, &K);
  
  // Nをユークリッドの互除法のようにKで何回割れるかを考える
  division = N;
  digit = 0;
  while(division > 0){
    digit ++;
    division = division/K;
  }
  printf("%d",digit);
  
  return 0;
}    


Measured memory_bytes: 128
#include <iostream>
#define ll long long
using namespace std;
int n,m;
char c[410][410];
int d1[4]={0,0,1,-1};
int d2[4]={1,-1,0,0};
bool visit[410][410]={0};
char ch[2]={'.','#'};
ll res=0;
ll t1,t2;
inline bool ok(int x,int y)
{
	return x>=0 && y>=0 && x<n && y<m && !visit[x][y];
}
int dfs(int x,int y,int b)
{
	//cout <<x<<" "<<y<<" "<<b<<" ###\n";
	visit[x][y]=1;
	int t=1;
	if (!b) t1++;
	else t2++;
	for (int i=0;i<4;i++)
	{
		int xi=x+d1[i];
		int yi=y+d2[i];
		if (ok(xi,yi) && c[xi][yi]==ch[b^1]) t+=dfs(xi,yi,b^1);
	}
	return t;
}
bool b=0;
int main()
{
	cin >>n>>m;
	/*for (int i=0;i<400;i++)
	{
		b=i%2;
		for (int j=0;j<400;j++)
		{
			if (!b) c[i][j]='.';
			else c[i][j]='#';
			b^=1;
		}
	}*/
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			cin >>c[i][j];
		}
	}
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (!visit[i][j])
			{
				//cout <<i<<" "<<j<<" "<<res<<"\n";
				t1=t2=0;
				if (c[i][j]=='.') dfs(i,j,0);
				else dfs(i,j,1);
				res+=t1*t2;
				//cout <<t1<<" "<<t2<<"\n";
			}
		}
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a;
bool dp[10010];

int main(){
	cin >> n; dp[0]=true;
	REP(i,0,n){
		cin >> a;
		RREP(j,10010,0) if(dp[j]) dp[j+a]=true;
	}
	
	RREP(j,10010,0) if(dp[j] and j%10){cout << j << endl; return 0;}
	cout << 0 << endl;
	return 0;
}


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

#define max(a,b) (((a) < (b)) ? (b) : (a))
int main(void) {
    int64_t A,B,C,D;

    cin >> A >> B >> C >> D;
    cout << max(A*B,C*D) << "\n";

    return 0;
}


Measured memory_bytes: 256
//18
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

struct S{
  double t;
  int v,c;
  S(){};
  S(double a,int b,int d){
    t=a;
    v=b;
    c=d;
  }
  bool operator<(S a)const{
    return t>a.t;
  }
};

struct E{
  int t;
  double d;
  E(){}
  E(int a,double b){
    t=a;
    d=b;
  }
};

int main(){
  for(int n,m,p,a,b;cin>>n>>m>>p>>a>>b,n|m|p|a|b;){
    int t[8];
    for(int i=0;i<n;i++){
      cin>>t[i];
    }
    vector<E> e[31];
    for(int i=0;i<p;i++){
      int a,b;
      double c;
      cin>>a>>b>>c;
      e[a].push_back(E(b,c));
      e[b].push_back(E(a,c));
    }
    priority_queue<S> que;
    que.push(S(0,a,(1<<n)-1));
    bool p[31][1<<8]={{}};
    while(!que.empty()){
      if(que.top().v==b)break;
      S c=que.top();
      que.pop();
      if(p[c.v][c.c]++)continue;
      for(int i=0;i<e[c.v].size();i++){
	for(int j=0;j<n;j++){
	  if(c.c&1<<j){
	    que.push(S(c.t+e[c.v][i].d/t[j],e[c.v][i].t,c.c&~(1<<j)));
	  }
	}
      }
    }
    if(que.empty()){
      cout<<"Impossible"<<endl;
    }else{
      cout<<fixed<<que.top().t<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 17016
fun main() {
    val x = readLine()!!.toLong()
    for (a in 0L..1000L) {
        for (b in -a until a) {
            if ((a * a * a * a * a) - (b * b * b * b * b) == x) {
                println("$a $b")
                return
            }
        }
    }
}

Measured memory_bytes: 34484
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args){

		solve_abc166_b();
	}
  
  	public static void solve_abc166_b(){

		FastScanner sc = new FastScanner(System.in);
		
		long x = sc.nextLong();
		long y = 100;
		long ans = 0;
		
		while(y < x){
			y = (long)Math.floor((double)y * 1.01);
			ans++;
		}
		
		System.out.println(ans);
		


	}

}

Measured memory_bytes: 27044
import           Control.Monad
import           Data.Maybe                     ( fromJust )
import qualified Data.Vector.Unboxed           as V
import qualified Data.ByteString.Lazy.Char8    as BC

main = do
    n  <- readLn
    as <-
        V.fromList
        .   map (pred . fst . fromJust . BC.readInt)
        .   BC.lines
        <$> BC.getContents
    print $ solve as 0 0 n

solve as 1 i _ = i
solve as k i n | i == n    = -1
               | otherwise = solve as (as V.! k) (succ i) n


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

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();
    System.out.println(b/x - a/x + (a%x==0 ? 1:0) );
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  string s;
  cin>>s;
  int n=len(s);
  rep(i,n){
    cout<<"x";
  }
  cout<<endl;
}

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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;


using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define PI 3.1415926535897932384626433832795
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    ll a,b;
    cin>>a>>b;
    ll x1,x2;
    if(b%4==0)
    {
        x1 = b;
    }
    else if(b%4==1)
    {
        x1 = 1;
    }
    else if(b%4==2)
    {
        x1  =  b+1;
    }
    else
    {
        x1 = 0;
    }

    if((a-1)%4==0)
    {
        x2 = a-1;
    }
    else if((a-1)%4==1)
    {
        x2 = 1;
    }
    else if((a-1)%4==2)
    {
        x2  =  a;
    }
    else
    {
        x2 = 0;
    }
    ll x = x1^x2;
    cout << x << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int main(){
	char s[100001]={};
	scanf("%s",s);
	int ans=-1;
	int l=strlen(s);
	int x=s[0];
	for(int i=0;i<l;i++){
		if(s[i]!=x){
			int p=i;
			int q=l-p;
			if(p<q)p=q;
			if(ans<0)ans=p;
			if(ans>p)ans=p;
			x=s[i];
		}
	}
	if(ans==-1){
		ans=l;
	}
	printf("%d\n",ans);
	return 0;
}
		

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, m;
const int maxN = 2 * (int)1e5 + 100;
int d[maxN];
map < int, vector < int > > all;
map < pair < int, int >, int > id;
map < pair < int, int >, int > mp;
bool used[maxN];
vector < int > g[maxN];
int batya[maxN];
vector < int > order_of;
int clr[maxN];
int fr[maxN], to[maxN];
void dfs(int v, vector < int >& cmp) {
    used[v] = true;
    cmp.push_back(v);
    for (int to : g[v]) {
        if (d[to] == d[v] && !used[to]) dfs(to, cmp);
    }
}
void dfs_second(int v) {
    used[v] = true;
    for (int to : g[v]) {
        if (d[to] != d[v]) continue;
        if (used[to]) continue;
        batya[to] = v;
        mp[minmax(v, to)] = d[v];
        dfs_second(to);
    }
    order_of.push_back(v);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> d[i];
        all[-d[i]].push_back(i);
    }
    memset(batya, -1, sizeof batya);
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        fr[i] = u;
        to[i] = v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    memset(batya, -1, sizeof batya);
    for (auto it : all) {
        vector < int > inds = it.second;
        for (int v : inds) {
            if (used[v]) continue;
            vector < int > his_cmp;
            dfs(v, his_cmp);
            if (his_cmp.size() != 1) {
                for (int p : his_cmp) used[p] = false;
                dfs_second(v);
            }
            else {
                bool ok = false;
                order_of.push_back(v);
                for (int to : g[v]) {
                    if (d[to] < d[v]) {
                        ok = true;
                        batya[v] = to;
                        mp[minmax(to, v)] = d[v];
                        break;
                    }
                }
                if (!ok) {
                    cout << -1 << '\n';
                    return 0;
                }
            }
        }
    }
    reverse(order_of.begin(), order_of.end());
    for (int v : order_of) {
        if (batya[v] == -1) {
            clr[v] = 0;
        }
        else {
            clr[v] = clr[batya[v]] ^ 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ((clr[i] == 1) ? 'B' : 'W');
    }
    cout << '\n';
    const int INF = (int)1e9;
    for (int i = 1; i <= m; i++) {
        if (mp.find(minmax(fr[i], to[i])) == mp.end()) {
            cout << INF << '\n';
        }
        else {
            cout << mp[minmax(fr[i], to[i])] << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 31096
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll fun(int k)
{
    ll sum=5,ans=1;
    while(k)
    {
        if(k&1)
            ans*=sum;
        k=k>>1;
        sum=sum*sum;
    }
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    if(n%2)
        cout<<0;
    else
    {
        ll ans=0;
        n=n/2;
        for(ll i=1; ; i++)
        {
            ll p=fun(i);
            if(p>n)
                break;
            ans+=n/p;
        }

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

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

int T, card[10];

bool is_same_number(int a, int b, int c){
    //同色同数値かどうか
    if(a == b && a == c) return true;
    else return false;
}
bool is_sequence(int a, int b, int c){
    //同色連番かどうか
    if(a + 2 == c && b + 1 == c) return true;
    else return false;
}
bool is_good_set(int a, int b, int c){
    //同色同数値である　または　同色連番である
    return ((is_same_number(a, b, c))|| is_sequence(a, b, c));
}
bool is_all_good_set(){
    //勝利状態の判定
    return is_good_set(card[0], card[1], card[2]) && is_good_set(card[3], card[4], card[5]) && is_good_set(card[6], card[7], card[8]);
}
int win(){
        sort(card, card + 9);
        do{
            if(is_all_good_set()) return 1;
        }while(next_permutation(card, card + 9));
        return 0;
    }
int main(){
    //cout << is_same_number(3, 4, 5) << endl;
    //cout << is_sequence(3, 4, 5) << endl;
    cin >> T;

    //入力の処理
    for(int i = 0; i < T; i++){
        for(int j = 0; j < 9; j++){
            cin >> card[j];
        }
        string color;
        for(int j = 0; j < 9; j++){
            cin >> color;
            /*各カードは色と数の２つの情報の組み合わせなので、
            これを整数で表現するための処理*/
            if(color == "G") card[j] += 10;
            else if(color == "B") card[j] += 20;
        }
        cout << win() << endl; 
    }
}



Measured memory_bytes: 3052
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    Int N, U, V;
    vector<vector<Int>> tree;
    vector<Int> tdist, adist;

    void tdfs(int v, int d = 0, int p = -1) {
        if (V == v) return;
        tdist[v] = d;
        for (auto e : tree[v]) {
            if (e != p) {
                tdfs(e, d + 1, v);
            }
        }
    }

    void adfs(int v, int d = 0, int p = -1) {
        adist[v] = d;
        for (auto e : tree[v]) {
            if (e != p) {
                adfs(e, d + 1, v);
            }
        }
    }

    void solve() {
        cin >> N >> U >> V;
        tree.resize(N);
        tdist.resize(N, -1);
        adist.resize(N);

        U--, V--;
        for (int i = 0; i + 1 < N; ++i) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            tree[a].push_back(b);
            tree[b].push_back(a);
        }

        tdfs(U);
        adfs(V);

        Int best_key = -1;
        Int best_value = -1;
        for (int i = 0; i < N; ++i) {
            if (tree[i].size() == 1) {
                if (best_value < adist[i] && tdist[i] < adist[i] && tdist[i] != -1) {
                    best_value = adist[i];
                    best_key = i;
                }
            }
        }

        Int ans = adist[best_key] - 1;
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 12544
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int n;
  cin >> n;
  
  int h[100010] = {0};
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  
  int dp[100010] = {0};
  for(int i = 0; i < n; i++){
    if(i == 0) dp[i] = 0;
    else dp[i] = INT_MAX;
  }
  for(int i = 1; i < n; i++){
  	chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    if(i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  
  cout << dp[n-1] << endl; 
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
int a,b,c,i,num[3];
for(i=0;i<3;i++)
{scanf("%d",&num[i]);}
if(num[0]>num[1])
{a=num[0];
num[0]=num[1];
num[1]=a;}
if(num[1]>num[2])
{b=num[1];
num[1]=num[2];
num[2]=b;
if(num[0]>num[1])
{c=num[0];
num[0]=num[1];
num[1]=c;
}
}
printf("%d %d %d\n",num[0],num[1],num[2]);
return 0;
}

Measured memory_bytes: 596
from collections import deque


def solve():
    N = int(input())
    S = input()
    ans = deque(S)
    
    l, r = 0, 0
    for i in range(N):
        if S[i] == '(':
            l += 1
        else:
            if 0 < l:
                l -= 1
            else:
                r += 1
    
    for _ in range(l):
        ans.append(')')
    for _ in range(r):
        ans.appendleft('(')
    print(''.join(ans))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int N, A;
	cin >> N;
	int ans = 1e9;
	for(int i = 1; i <= N; i++){
		cin >> A;
		int cnt = 0;
		while(A % 2 == 0){
			A /= 2;
			cnt++;
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    
    sort(A.begin(), A.end());
    
    cout << A[0] << " " << A[1] << " " << A[2] << endl;
}


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

int main(void) {
	int N, a[100];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];

	sort(a, a + N, greater<int>());

	int alice_total, bob_total = 0;
	for (int i = 0; i < N; i++) {
		if (i%2 == 0) {
			alice_total += a[i];
		} else {
			bob_total += a[i];
		}
	}

	cout << (alice_total - bob_total) << endl;
	return 0;	
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
    return x;

}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->left;
  }
    return x;
  
}

Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key)
    return x;
  if(k < x->key)
    return treeSearch(x->left,k);
  else return treeSearch(x->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL)
    return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x=y;
    y = y->parent;
    return y;
  }

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

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

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

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


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

 void inorder(Node u){
   if( u == NIL)return;
   inorder(u->left);
   printf(" %d",u->key);
   inorder(u->right);
 }
 void preorder(Node u){
  if( u == NIL )return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
 
}
 
 
 int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  
  return 0;
}



Measured memory_bytes: 20456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;cin >> k;
    int ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                int g=gcd(i,j);
                g=gcd(g,l);
                ans+=g;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    String edita="";
    sc.close();

    for(int i=0;i<s.length();i++){
      if(s.charAt(i)=='0'){
        edita+="0";
      }else if(s.charAt(i)=='1'){
        edita+="1";
      }else{
        if(edita.length()>0){
          edita=edita.substring(0,edita.length()-1);
        }
      }
    }

    System.out.println(edita);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
class DisjSet { 
    int *rank, *parent, n; 
  
public: 
    // Constructor to create and 
    // initialize sets of n items 
    DisjSet(int n) 
    { 
        rank = new int[n]; 
        parent = new int[n]; 
        this->n = n; 
        makeSet(); 
    } 
  
    // Creates n single item sets 
    void makeSet() 
    { 
        for (int i = 0; i < n; i++) { 
            parent[i] = i; 
        } 
    } 
  
    // Finds set of given item x 
    int find(int x) 
    { 
        // Finds the representative of the set 
        // that x is an element of 
        if (parent[x] != x) { 
  
            // if x is not the parent of itself 
            // Then x is not the representative of 
            // his set, 
            parent[x] = find(parent[x]); 
  
            // so we recursively call Find on its parent 
            // and move i's node directly under the 
            // representative of this set 
        } 
  
        return parent[x]; 
    } 
  
    // Do union of two sets represented 
    // by x and y. 
    void Union(int x, int y) 
    { 
        // Find current sets of x and y 
        int xset = find(x); 
        int yset = find(y); 
  
        // If they are already in same set 
        if (xset == yset) 
            return; 
  
        // Put smaller ranked item under 
        // bigger ranked item if ranks are 
        // different 
        if (rank[xset] < rank[yset]) { 
            parent[xset] = yset; 
        } 
        else if (rank[xset] > rank[yset]) { 
            parent[yset] = xset; 
        } 
  
        // If ranks are same, then increment 
        // rank. 
        else { 
            parent[yset] = xset; 
            rank[xset] = rank[xset] + 1; 
        } 
    } 
}; 
int main() {
  int N,M;
  cin >> N >> M;
  int p[N],x,y,answer=0;
  DisjSet q(2*N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    q.Union(i,--p[i]+N);
  }
  while (M--) {
    cin >> x >> y;
    q.Union(--x,--y);
    q.Union(p[x]+N,p[y]+N);
  }
  for (int i = 0; i < N; i++) {
    answer += q.find(i) == q.find(i+N);
  }
  cout << answer;
}

Measured memory_bytes: 5140
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  A[i][0], A[i][1] = A[i][1], A[i][0]
A.sort()
S = 0
p = "Yes"
for i in range(N):
  S += A[i][1]
  if S > A[i][0]:
    p = "No"
    break
print(p)

Measured memory_bytes: 51292
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

const Int MAX_DIGIT = 50;
Int dp[100][2];

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, K;
	cin >> N >> K;

	vector<Int> A(N);
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}
	fill(dp[0], dp[100], -1);
	dp[MAX_DIGIT][0] = 0; 

	for (Int digit = MAX_DIGIT - 1; digit >= 0; digit--) {
		Int mask = 1LL << digit; // 上からdigit桁目を立てたマスク

		// Aでもともと上からdigit桁目にビットが立っているものの個数
		Int num = 0;
		for (Int i = 0; i < N; i++) {
			if (A[i] & mask) {
				num++;
			}
		}

		// マスク値の上からdigit桁目を0, 1にしたときのスコア
		Int score0 = mask * num;
		Int score1 = mask * (N - num);

		// 1 -> 1(マスク値がK以下に確定した状態 -> マスク値がK以下に確定した状態）
		// マスク値がK以下であることは確定しているので、上からdigit桁以降のビットは立てても立てなくても良い
		// なので、ビットを立てたときと立ててないときのスコアの大きい方を採用する
		if (dp[digit + 1][1] != -1) {
			dp[digit][1] = max(dp[digit][1], max(dp[digit + 1][1] + score0, dp[digit + 1][1] + score1));
		}

		// 0 -> 1(マスク値がK以下に確定していない状態 -> マスク値がK以下に確定した状態)
		// Kの立っている上からdigit桁目を引っ込めることでマスク値がK以下に確定する。なのでscore0を採用する
		if (dp[digit + 1][0] != 1) {
			if (K & mask) { // Kの上からdigit桁目が立っていたら引っ込める
				dp[digit][1] = max(dp[digit][1], dp[digit + 1][0] + score0);
			}
		}

		// 0 -> 0(マスク値がK以下に確定していない状態 -> マスク値がK以下に確定していない状態)
		// Kの上からdigit桁目をそのままにするということ
		// なので、Kの上からdigit桁目が0ならscore0を採用し、 Kの上からdigit桁目が1ならscore1を採用する
		if (dp[digit + 1][0] != -1) {
			if (K & mask) { // Kの上からdigit桁目が立ってる
				dp[digit][0] = max(dp[digit][0], dp[digit + 1][0] + score1);
			}
			else { // Kの上からdigit桁目が立ってない
				dp[digit][0] = max(dp[digit][0], dp[digit + 1][0] + score0);
			}
		}
	}

	
	cout << max(dp[0][1], dp[0][0]) << endl;

}


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

#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
typedef long long ll;

int main(){
    ll h,w;
    cin >> h >> w;
    ll a,b;
    cin >> a >> b;
    REP(i,1,h){
        if(i <= b){
            REP(j,1,w){
                if(j <= a){
                    cout << 1;
                }else{
                    cout << 0;
                }
            }
            cout << endl;
        }else{
            REP(j,1,w){
                if(j <= a){
                    cout << 0;
                }else{
                    cout << 1;
                }
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
     int k,a,b,sum=0;
     scanf("%d",&k);
     scanf("%d%d",&a,&b);
     for(a=a;a<=b;a++)
     {
          if((a%k)==0)
          {
               sum++;
          }
     }
     if(sum==0)
     {
          printf("NG\n");
     }
     else
     {
           printf("OK\n");
     }
}


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


int main () {
    int N,A,B;
    cin >> N >> A >> B;
    string s;
    cin >> s;

    int a=0,b=0; //確定した人数
    for(auto c : s) {
	if( c == 'a' ) {
	    if( a+b < A+B ) {
		cout << "Yes" << endl;
		a++;
	    }
	    else
		cout << "No" << endl;
	}
	else if ( c == 'b' ) {
	    if( a+b < A+B and b < B ) {
		cout << "Yes" << endl;
		b++;
	    }
	    else
		cout << "No" << endl;
	}
	else
	    cout << "No" << endl;
    }
    
    return 0;
}


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

int main() {
	// your code goes here
	long long n,m,i,l,r,ll,rr;
	cin >> n >> m;
	cin >> ll >> rr;
	for(i=2;i<=m;i++){
		cin >> l >> r;
		if(l>rr||r<ll){
			cout << "0" << endl;
			return 0;
		}
		ll=max(l,ll);
		rr=min(r,rr);
	}
	cout << rr-ll+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#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>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

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

  int n;
  cin >> n;
  vector<long> a(n);
  fillLong(a, n);

  long res = 0;

  rep(i, n-1) {
    res += a[i]/2;
    a[i] = a[i]%2;

    res += min(a[i], a[i+1]);
    a[i+1] = max(0L, a[i+1] - a[i]);
  }
  res += a[n-1]/2;

  cout << res << endl;
}


Measured memory_bytes: 1024
#include <cstdio>

int p[100000];

int main()
{
  int N, K, Q, A;
  scanf("%d %d %d", &N, &K, &Q);
  for (int i = 0; i < Q; ++i)
  {
    scanf("%d", &A);
    p[A - 1]++;
  }
  
  for (int i = 0; i < N; ++i)
  {
    puts(K - Q + p[i] > 0 ? "Yes" : "No");
  }
  return 0;  
}

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

int K, N, a[200006], ans;
int main() {
	cin >> K >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	ans = a[0] + K - a[N - 1];
	for (int i = N - 1; i > 0; i--) {
		ans = max(ans, a[i] - a[i - 1]);
	}
	cout << K - ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dsu[100005],vis[100005],m,x,y,z,u,v,n,i,sum=0,tmp=0;
vector<ll> s[100005];
void dfs(int p,int f,int c)
{
	ll i,v;
	sum++;
	vis[p]=c;
	for(i=0;i<s[p].size();i++)
	{
		v=s[p][i];
		if(vis[v]==vis[p])tmp=1;
		if(vis[v])continue;
		dfs(v,p,-c);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)dsu[i]=i;
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		s[u].push_back(v);
		s[v].push_back(u);
	}
	for(i=1;i<=n;i++)
	{
		if(vis[i])continue;
		sum=tmp=0;
		dfs(i,0,1);
		if(sum==1)x++;
		else 
		{
			if(tmp==0)y++;
			else z++;
		}
	}
	printf("%lld\n",2LL*n*x-x*x+2LL*y*y+z*z+2LL*z*y);
	return 0;
}

Measured memory_bytes: 14080
#include <iostream>
#include <array>

using namespace std;

int main() {
    std::array<long long, 5> a;
    long long N;
    cin >> N >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

    long long min = 1000000000000000;

    for (int i = 0; i < 5; i++) {
        if (a[i] < min)
            min = a[i];
    }

    if (N % min == 0)
        cout << N / min + 4 << endl;
    else
        cout << N / min + 5 << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int N, M;
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        M = sc.nextInt();
        int temp = 0;
        while (M > 0)
        {
            temp = sc.nextInt();
            N -= temp;
            M--;
        }
        System.out.println(N >=0 ? N : -1);
    }
}


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

int main() {
  string S;
  cin >> S;
  int Q;
  cin >> Q;
  
  int X = 1;
  string SF = "";
  string SB = "";
  for (int i = 0; i < Q; i++) {
    int T;
    cin >> T;
    if (T == 1) {
      X *= -1;
    }
    else {
      int F;
      char C;
      cin >> F >> C;
      if ((X == 1 && F == 1) || (X == -1 && F == 2)) SF += C;
      else SB += C;
    }
  }
  
  if (X == 1) {
    reverse(SF.begin(), SF.end());
    string ans = SF + S + SB;
    cout << ans << endl;
  }
  else {
    reverse(S.begin(), S.end());
    reverse(SB.begin(), SB.end());
    string ans = SB + S + SF;
    cout << ans << endl;
  }
}

Measured memory_bytes: 1348
/*_BELIEVE_*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

void solve()
{
 int n;
 cin>>n;

 vector<int> dam(n),a(n);
 for(int i=0;i<n;++i)
 cin>>dam[i];

 a[n-1]=2*dam[n-1];
 for(int i=n-2;i>=0;--i)
 a[i]=-a[i+1]+2*dam[i];

 a[0]/=2;
 for(int i=1,sign=1;i<n;++i,sign*=-1)
 a[i]+=a[0]*sign;

 for(int i=0;i<n;++i)
 cout<<a[i]<<" ";

}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}



Measured memory_bytes: 2944