akhauriyash/Code-Regression huggingface dataset:
mod = 10**9 + 7
n, k = map(int, input().split())
a = list(map(int, input().split()))
v1 = v2 = 0
for i in range(n-1):
    for j in range(i+1, n):
        if a[i] > a[j]: v1 += 1
for i in range(1, n):
    for j in range(i):
        if a[i] > a[j]: v2 += 1
x1 = k * (k + 1) // 2
x2 = k * (k - 1) // 2
ans = ((v1 * x1) + (v2 * x2)) % mod
print(int(ans))

Measured memory_bytes: 3188
#include <stdio.h>
int main(void){
  long long N, A, B, x1, x2, ans=0;
  scanf("%lld %lld %lld %lld", &N, &A, &B, &x1); 
  for(int i = 0; i<N-1; i++){
    scanf("%lld", &x2);
    if(A*(x2-x1) > B){ans+=B;}
    else{ans+=A*(x2-x1);}
    x1=x2;
  }
  printf("%lld", ans);
  
}

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

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int n=in.nextInt(), k=in.nextInt();
			if(n==0 && k==0) break;
			int ss[] = new int[k];
			for(int i=0; i<k; i++){
				ss[i] = in.nextInt();
			}
			for(int i=0; i<n; i++){
				for(int j=0; j<k; j++){
					ss[j] -= in.nextInt();
				}
			}
			int i=0;
			for(i=0; i<k; i++){
				if(ss[i] < 0) break;
			}
			System.out.println(i==k?"Yes":"No");
		}
	}
}

Measured memory_bytes: 12000
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 0

for i, h in enumerate(H):
    if abs((T - 0.006 * H[ans]) - A) > abs((T - 0.006 * h) - A):
        ans = i

print(ans + 1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    int n;
    cin>>n;
    int ans;
    int x=n/500;
    ans=x*1000;
    n=n%500;
    ans=ans+(n/5)*5;
    cout<<ans<<endl;



    return 0;
}



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


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

    vector<ll>f(n+1, 1);
    for(ll i=2;i<=n;i++){
        for(ll j=i;j<=n;j += i){
            f[j]++;
        }
    }

    ll ans = 0;
    for(ll i=1;i<=n;i++){
        ans += f[i]*i;
    }

    cout << ans << endl;
}

Measured memory_bytes: 81400
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
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 long long MOD = 1000000007;
//* calculate x^n mod something in O(log n) -- recursive version
ll mod_pow(ll x, ll n, ll mod){
    if(n == 0) return 1;
    ll res = mod_pow(x*x % mod, n/2, mod);
    if(n & 1) res = res * x % mod;
    return res;
}
void solve(long long N, long long K){
    vll num(K+1, 0);
    for(ll X = K; X >= 1; X--){
        ll tmp = K/X;
        num[X] = mod_pow(tmp, N, MOD);
        for(ll Y = X*2; Y<= K; Y+=X){
            num[X] = (num[X] - num[Y]) % MOD;
        }
    }
    ll res = 0;
    for(ll X = 1; X <= K; X++){
        res = (res + (num[X]*X) % MOD) % MOD;
    }
    cout<<res<<endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 3648
# coding: utf-8
# Here your code !

def func():
    data=[]
    while(True):
        try:
            line=[ int(item) for item in input().rstrip().split(" ") ]
            if(line == [-1, -1, -1]):
                break
            data.append(line)
        except EOFError:
            break
        except:
            return inputError()

    result=""
    for score in data:
        if( (score[0]<0) or (score[1]<0)):
            result+="F\n"
        elif(score[0]+score[1] >= 80):
            result+="A\n"
        elif(score[0]+score[1] >= 65):
            result+="B\n"
        elif(score[0]+score[1] >= 50):
            result+="C\n"
        elif(score[0]+score[1] >= 30):
            if(score[2] >= 50):
                result+="C\n"
            else:
                result+="D\n"
        else:
            result+="F\n"
    
    print(result.rstrip())

def inputError():
    print("input error")
    return -1

func()

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

using namespace std;

const int maxn = 2e5 + 5,mod = 1e9 + 7;

long long n,a[maxn],fac[maxn],l,makh[maxn] , counter[maxn],p,x,y;

long long ans;

long long choose (long long a , long long b)
{

}

int main()
{
    cin>>n>>p;
    fac[0] = 1;
    for(int i=1;i<=n;i++)
        fac[i] = fac[i - 1] * 2;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i] % 2 == 0)
            x++;
        else
            y++;
    }
    ans = (fac[y - 1] * fac[x]);
    if(y == 0 && p == 1)
        ans = 0;
    if(y == 0 && p == 0)
        ans = fac[x];
    cout<<ans;
}


Measured memory_bytes: 4352
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;
//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

int main() {
	static const double pi = 3.141592653589793;
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x = x2 - x1;
	int y = y2 - y1;
	cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int SET(int N, int pos)  {return N=N | (1<<pos);}
int RSET(int N,int pos)  {return N= N & ~(1<<pos);}
bool CHK(int N,int pos)  {return (bool)(N & (1<<pos));}

#define ll             long long
#define pll            pair<ll,ll>
#define unique(a)      a.resize(unique(a.begin(), a.end()) - a.begin())
#define fill(v, p)     memset(v,p,sizeof v)
#define all(x)         x.begin(), x.end()
#define index(x,i)     x.find_by_order(i)
#define lesscount(x,i) x.order_of_key(i)
#define PI             acos(-1.0)
#define EPS            0.000000001
#define INF            1e18+10
#define MAX            300005
#define MOD            1000000007


signed int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(0);
	
	ll n;
	cin >> n;
	
	string s;
	
	map<string,ll> mp;
	
	for(int i=0;i<n;i++)
	{
		cin >> s;
		mp[s]++;
	}
	
	ll mx=0;
	for(auto p:mp)
		mx=max(p.second,mx);
	
	set<string> ans;
	
	for(auto p:mp)
		if(p.second == mx) ans.insert(p.first);
		
	for(string str:ans)
	cout << str << endl;
			
	return 0;
}


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

int main(){
    long n,k,q;cin>>n>>k>>q;
    vector<long> ans(n,0);
    for(int i=0;i<q;i++){
        int a;cin>>a;
        ans[a-1]++;
    }
    for(int i=0;i<n;i++){
        ans[i]+=(k-q);
        if(ans[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int MOD = 1e9 + 7;

int tbl[2][2019];
string S;

int main() {
  memset(tbl, 0, sizeof(tbl));
  cin >> S;
  int len = S.size();
  int64 ans = 0;
  int tmp;
  rep(i, len) {
    tmp = S[i] - '0';
    rep(j, 2019) {
      tbl[(i + 1) % 2][(j * 10 + tmp) % 2019] = tbl[i % 2][j];
    }
    tbl[(i + 1) % 2][tmp]++;
    ans += tbl[(i + 1) % 2][0];
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
#define ll long long
using namespace std;


int main() {
    int n; cin >> n;
    int a[n];
    rep(i, 0, n){
        int b;
        cin >> b;
        a[b-1] = i+1;
    }

    rep(i, 0, n){
        cout << a[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

ll F(ll a, ll b) {
	return max(GetDigit(a), GetDigit(b));
}

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

	ll N;
	cin >> N;

	int min = 10000000000;

	for (int i = 1; i*i <= N; i++)
	{
		if (N%i == 0) {
			int tmp = F(i, N/i);
			if (tmp < min) {
				min = tmp;
			}
		}
	}

	cout << min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
long long n, k, s;
long long h[200000];
int main() {
	scanf("%lld%lld", &n, &k);
	for (long long i = 0; i < n; i++) {
		scanf("%lld", h + i);
	}
	std::sort(h, h + n);
	for (long long i = 0; i < n - k; i++) {
		s += h[i];
	}
	printf("%lld\n", s);
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <string.h>

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */
int num = 0;

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M;   /* your task */ }
int h2(int key){ return 1+key%(M-1);/* your task */ }

int find(char str[]){
    /* your task */
  int h,i=0,k;
 
  k = getKey(str);
  while(1){
  h = (h1(k)+i*h2(k))%M;
  if(H[h][0] == '\0')return 0;
  else if(strcmp(H[h],str) == 0)return 1;
  i++;
 }
}

int insert(char str[]){
      /* your task */
    long long int i = 0,h,k;
    k = getKey(str);
    
   while(1){
     h = (h1(k)+i*h2(k))%M;
     if(strcmp(H[h],str)==0)return 0;
     else if(H[h][0] == '\0'){
       strcpy(H[h],str);
       num++;
       return 1;
     }
     else i++;
   }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15460
// AOJ 2340: Carpenters' Language
// 2017.11.13 bal4u@uu

#include <stdio.h>

int main()
{
	int q, p, n;
	long long l, r;
	char b[5];

	l = r = 0;
	scanf("%d", &q);
	while (q--) {
		scanf("%d%s%d", &p, b, &n);
		if (*b == '(') l += n;
		else           r += n;
		puts(l == r ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 1812
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        
        if (k <= 9) {
            System.out.println(k);
            return;
        }
        
        Queue<Long> que = new ArrayDeque<Long>();
        for (int i = 1; i <= 9; i++) {
            que.add((long)i);
        }
        
        int count = 9;
        while (true) {
            long cur = que.poll();
            long last = cur % 10;
            
            if (last != 0) {
                que.add(cur * 10 + last - 1);
                count++;
                if (k == count) {
                    System.out.println(cur * 10 + last - 1);
                    return;
                }
            }
                que.add(cur * 10 + last);
                count++;
                if (k == count) {
                    System.out.println(cur * 10 + last);
                    return;
                }
            if (last != 9) {
                que.add(cur * 10 + last + 1);
                count++;
                if (k == count) {
                    System.out.println(cur * 10 + last + 1);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 25556
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [long(input_raw[0]), long(input_raw[1])]
    if N/2 + N % 2 >= K :
        print "YES"
    else:
        print "NO"

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
#coding:utf-8
N = int(input())
trees = [list(input().split()) for i in range(N)]

class BinaryTree:
    def __init__(self,key,p=None,l=None,r=None):
        self.key = key
        self.p = p
        self.l = l
        self.r = r

def Insert(root,z):
    y = None
    x = root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.l
        else:
            x = x.r
    z.p = y

    if y == None:
        root = z
    elif z.key < y.key:
        y.l = z
    else:
        y.r = z
    return root

def preOrder(root):
    x = root
    if x == None:
        return
    global preList
    preList.append(x.key)
    
    preOrder(x.l)
    preOrder(x.r)

def inOrder(root):
    x = root
    if x == None:
        return
    inOrder(x.l)

    global inList
    inList.append(x.key)
    
    inOrder(x.r)

root = None
for data in trees:
    if data[0] == "insert":
        z = BinaryTree(int(data[1]))
        root = Insert(root,z)
    if data[0] == "print":
        inList = []
        preList = []
        inOrder(root)
        a = " " + " ".join([str(num) for num in inList])
        print(a)

        preOrder(root)
        a = " " + " ".join([str(num) for num in preList])
        print(a)



Measured memory_bytes: 261928
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

int main(){
    int a,b,c; cin >> a >> b >> c;
    if (b+c >= a){
        cout << b+c-a << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        while (true) {
            int height = scan.nextInt();
            int width  = scan.nextInt();

            if (height == 0 && width == 0) {
                break;
            }

            for (int i = 0; i < width; i++) {
                System.out.print("#");
            }
            System.out.println();
            for (int i = 1; i < height - 1; i++) {
                System.out.print("#");
                for (int j = 1; j < width - 1; j++) {
                    System.out.print(".");
                }
                System.out.println("#");
            }
            for (int i = 0; i < width; i++) {
                System.out.print("#");
            }
            System.out.println("\n");
        }
    }

}

Measured memory_bytes: 35716
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    lint N;cin>>N;
    vector<vector<P> > M(N, vector<P>());
    REP(i,N-1){
        lint u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        M[u].push_back(make_pair(v, w));
        M[v].push_back(make_pair(u, w));
    }
    vector<lint> col(N, 0);
    vector<lint> used(N, 0);
    queue<lint> q;
    q.push(0);
    used[0] = 1;
    col[0] = 1;
    while(q.size()){
        lint v = q.front(); q.pop();
        if(col[v]==0) cout << "err;" << v << endl;
        for(int i=0, n=(int)M[v].size(); i<n; i++){
            lint nv = M[v][i].first;
            if(used[nv]) continue;
            if(M[v][i].second%2==1){
                used[nv] = 1;
                col[nv] = col[v]*-1;
                q.push(nv);
            }
            else{
                used[nv] = 1;
                col[nv] = col[v];
                q.push(nv);
            }
        } 
    }
    REP(i, N){
        if(col[i]>0) cout << 1 << "\n";
        else cout << 0 << "\n";
    }
    //REP(i, N){
        //cout << i << " " << col[i] << endl;
    //}
    cout << flush;
    return 0;
}

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

using namespace std;
#define int long long
const int maxn=200005;
vector <pair<int,int> > a;
int t[4*maxn];
void build(int node,int tl,int tr)
{
    if((tr-tl)==1)
    {
        t[node]=a[tl].second;
        return;
    }
    t[node]=0;
    build(2*node+1,tl,(tl+tr)/2);
    build(2*node+2,(tl+tr)/2,tr);
}
void to(int node,int tl,int tr,int l,int r,int val)
{
    if(tl>=l && tr<=r)
    {
        t[node]+=val;
        return;
    }
    if(tl>=r || tr<=l)
    {
        return;
    }
    to(2*node+1,tl,(tl+tr)/2,l,r,val);
    to(2*node+2,(tl+tr)/2,tr,l,r,val);
}
int get(int node,int tl,int tr,int pos,int curr)
{
    //cout<<tl<<" "<<tr<<" rfd "<<endl;
    if(tr<=pos || tl>pos)
    {
        return 0;
    }
    else if((tr-tl)==1)
    {
        return (curr+t[node]);
    }
    curr+=t[node];
    return get(2*node+1,tl,(tl+tr)/2,pos,curr)+get(2*node+2,(tl+tr)/2,tr,pos,curr);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,d,t;
    cin>>n>>d>>t;
    a.resize(n);
    for(int i=0;i<n;++i)
    {
        cin>>a[i].first>>a[i].second;
        a[i].second=(a[i].second+t-1)/t;
    }
    sort(a.begin(),a.end());
    build(0,0,n);
    vector <int> next(n);
    for(int i=0;i<n;++i)
    {
        next[i]=lower_bound(a.begin(),a.end(),(pair<int,int>) make_pair(a[i].first+2*d,1e18))-a.begin();
    }
    int z;
    int ans=0;
    /*for(int i=0;i<n;++i)
    {
        //cout<<a[i].second<<" trfd "<<endl;
        z=get(0,0,n,i,0);
        //cout<<z<<endl;
    }*/
    for(int i=0;i<n;++i)
    {
        z=get(0,0,n,i,0);
        if(z>0)
        {
            ans+=z;
            to(0,0,n,i,next[i],-z);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin >> n >> k;
	vector<ll> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans = 1e18;
	rep(i,n - k + 1){
		if(a.at(i) < 0 && a.at(i + k - 1) >= 0){
			ans = min(ans, min(-a.at(i) * 2 + a.at(i + k - 1), -a.at(i) + a.at(i + k - 1) * 2));
		}
		else if(a.at(i) < 0) ans = min(ans, -a.at(i));
		else ans = min(ans, a.at(i + k - 1));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
N = int(input())
status = [list(map(int, input().split())) for i in range(N)]
dt = []
dist = []
flag = []
status.insert(0, [0, 0, 0])
for i in range(N):
    dt.append(status[i + 1][0] - status[i][0])
    dist.append(abs(status[i + 1][1] - status[i][1]) + abs(status[i + 1][2] - status[i][2]))
    if ((dt[i] % 2 == 0 and dist[i] % 2 == 0) \
        or (dt[i] % 2 == 1 and dist[i] % 2 == 1)) \
        and (dist[i] <= dt[i]):
        flag.append(True)
    else:
        flag.append(False)

if all(flag):
    print('Yes')
else:
    print('No')


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s,t;
	cin >> s >> t;
	ll ans=0;
	rep(i,3){
		if(s[i]==t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll a, b, c, d, e, f, l, m, n, s, t, u, x, y, z;
  string ss, tt;

  cin >> a >> ss;

  if (a >= 3200) cout << ss << endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 256
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ll mod2 = 998244353;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define lwi(x) cout << " your " << #x << " is ---> " << x << " ";
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 1e6+5;
int32_t main(){
    FastIO;
    ll n;
    cin >> n;
    map<string, ll> f;
    while(n--) {
        string s;
        cin >> s;
        f[s]++;
    }
    cout << "AC x " << f["AC"] << endl;
    cout << "WA x " << f["WA"] << endl;
    cout << "TLE x " << f["TLE"] << endl;
    cout << "RE x " << f["RE"] << endl; 
    return 0;
}


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

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

    if (N==25) cout << "Christmas" ;
    else if (N==24) cout << "Christmas Eve";
    else if (N==23) cout << "Christmas Eve Eve";
    else if (N==22) cout << "Christmas Eve Eve Eve";

    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var XY = Console.ReadLine().ToCharArray();
            var ans = "";
            if (XY[0] < XY[2]) ans = "<";
            else if (XY[0] > XY[2]) ans = ">";
            else ans = "=";

            Console.WriteLine(ans);
        }
    }
}


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

class Pg
{
    static void Main()
    {
        var P = new Prime();
        var rd = new Reader();
        var PrmLst = P.GetPrimeNums().ToList();
        rd.Read().ToList().ForEach(n => Console.WriteLine(PrmLst.Where((x,y) => y < n).Sum()));
    }
}
class Prime
{
    const int MAX = 105000;
    internal IEnumerable<int> GetPrimeNums()
    {
        for (int i = 0; i <= MAX; ++i)
        {
            if (IsPrime(i))
                yield return i;
        }
    }
    private bool IsPrime(int num)
    {
        if (num < 2)
            return false;
        else if (num == 2)
            return true;
        else if (num % 2 == 0)
            return false;

        for (int i = 3; i <= Math.Sqrt(num); i += 2)
        {
            if (num % i == 0)
                return false;
        }
        return true;
    }
}
class Reader
{
    internal IEnumerable<int> Read()
    {
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            yield return n;
        }
    }
}




Measured memory_bytes: 18304
#include "bits/stdc++.h"
#define oo 1000000000000000098
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;

using namespace std;

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

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n;
int ans;
int a[MAXN];
int main()
{
    //~ freopen("file.in", "r", stdin);
    scanf("%d",&n);
	int k;scanf("%d",&k);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	ll ans=oo;
	for(int i=k;i<=n;i++){
		int id=i-k+1,sh=0;
		if(a[id]<0&&a[i]>0)
			sh=-a[id];
		umin(ans,abs(a[id])+abs(a[i])+sh+0ll);
	}
	int id = 1;
	for(; id <= n; id ++)
		if(a[id] >= 0)
			break;
	ans=oo;
	for(int i = id - 1, cnt = k-1; i >= 1 && cnt; i --, cnt --)
	{
		if(i + k - 1 > n)
			continue;
		ll dm = abs(a[i])*2 + a[i + k - 1];
		umin(ans, dm);
	}
	if(id - k > 0)
		umin(ans, (ll)(abs(a[id- k])));
	for(int i = id, cnt = k-1; i <= n && cnt; i ++, cnt --)
	{
		if(i - k + 1 < 1)
			continue;
		ll dm = a[i] * 2 + abs(a[i - k + 1]);
		umin(ans, dm);
	}
	if(id + k - 1 <= n)
		umin(ans, (ll)(a[id + k - 1]));
	printf("%I64d\n",ans);
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.RInt;

            var all = new List<long>();

            for (int i = 1; i < 10; i++)
            {
                DFS(1, i, ref all);
            }

            all.Sort();

            WriteLine(all[n - 1]);
        }

        public static void DFS(int d, long val, ref List<long> all)
        {
            //格納
            all.Add(val);

            //10桁だったら終端
            if (d == 10) return;

            //次の桁
            //元の値の1の位の数　-1～+1の範囲なら最下位に付け足せる
            for (int i = -1; i <= 1; i++)
            {
                long add = (val % 10) + i;
                if (add >= 0 && add <= 9) DFS(d + 1, val * 10 + add, ref all);
            }
        }

    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 31360
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int mod;
long long int mypow(long long int a, long long int b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    long long int res = mypow(a, b / 2);
    res = res * res % mod;
    if (b % 2 == 1) res = res * a % mod;
    return res;
}

int main() { 
    int n;
    cin >> n >> mod;
    string s;
    cin >> s;
    long long int res = 0;
    long long int last = 0;
    if (mod == 2 || mod == 5) {
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % mod == 0) {
                res += i + 1;
            }
        }
        cout << res << endl;
        return 0;
    }
    unordered_map<long long int, long long int> um;
    um[0] = 1;
    for (int i = n - 1; i >= 0; i--) {
        long long int next = last + mypow(10, n - 1 - i) * (s[i] - '0') % mod;
        next %= mod;
        res += um[next];
        um[next]++;
        last = next;
    }

    cout << res << endl;
}




Measured memory_bytes: 3972
#include <stdio.h>

int main()
{
	long long int A, B, K, zero = 0;
	
	scanf("%lld %lld %lld", &A, &B, &K);
	
	if(K <= A){
		printf("%lld %lld\n", A-K, B);
	}
	else if(K <= (A+B)){
		printf("%lld %lld\n",zero, A + B - K);
	}
	else{
		printf("%lld %lld\n", zero, zero);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int N = 1000010;
long long fac[N], finv[N], inv[N];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < N; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
int main(){
    int x,y;
    cin>>x>>y;
    if(!((x+y)%3==0)){
        cout<<0<<endl;
        return 0;
    }
    int n=(-x+2*y)/3,m=(2*x-y)/3;
    //cout<<n<<" "<<m<<endl;
    if(n<0 || m<0){
        cout<<0<<endl;
        return 0;
    }

    COMinit();

    cout<<COM(n+m,n)<<endl;
}

Measured memory_bytes: 23680
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]

count=0
for i in range(n-1):
      for j in range(i+1,n):
            c=0
            for k in range(d):
                  c+=(x[i][k]-x[j][k])**2
            if math.sqrt(c)==int(math.sqrt(c)):
                  count+=1
print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<stack>
#include<string>

using namespace std;

int main(void) {
	int N;
	int n;

	cin >> N;
	n = N % 10;

	switch(n){
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		cout << "hon" << endl;
		return 0;
		break;
	case 0:
	case 1:
	case 6:
	case 8:
		cout << "pon" << endl;
		return 0;
		break;
	default:
		cout << "bon" << endl;
		break;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

ll mod=1e9+7;

int main(){
      ll n;
      cin>>n;
      ll a[3*n];
      rep0(i,3*n) cin>>a[i];
      ll summae[n+1];
      fill(summae,summae+n+1,0);
      priority_queue<ll,vector<ll>,greater<ll>> qmae;
      rep0(i,n){
            summae[0]+=a[i];
            qmae.push(a[i]);
      }
      rep1(k,n){
            ll pos=qmae.top();
            qmae.pop();
            if(pos>a[n+k-1]){
                  summae[k]=summae[k-1];
                  qmae.push(pos);
            }
            else{
            summae[k]=summae[k-1]-pos+a[n+k-1];
            qmae.push(a[n+k-1]);
            }
      }
      ll sumusiro[n+1];
      fill(sumusiro,sumusiro+n+1,0);
      priority_queue<ll> qusiro;
      for(int k=2*n;k<3*n;k++){
            sumusiro[n]+=a[k];
            qusiro.push(a[k]);
      }
      for(int k=2*n-1;k>=n;k--){
            ll pos=qusiro.top();
            qusiro.pop();
            if(pos<a[k]){
                  sumusiro[k-n]=sumusiro[k-n+1];
                  qusiro.push(pos);
            }
            else{
            sumusiro[k-n]=sumusiro[k-n+1]-pos+a[k];
            qusiro.push(a[k]);
            }
      }
      ll ans=-longinf;
      for(int i=0;i<=n;i++){
            ans=max(ans,summae[i]-sumusiro[i]);
      }
      /*rep0(i,n+1){
            cout<<summae[i]<<" "<<sumusiro[i]<<endl;
      }*/
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 6516
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){

    int k;
    cin >> k;
    vll x(k),y(k);
    rep(i,k)cin >> x[i] >> y[i];

    char ans[8][8];
    vll r(8);
    rep(i,8)r[i] = i;

    do{
        char ans[8][8];
        rep(i,8)rep(j,8)ans[i][j] = '.';
        rep(i,8)ans[i][r[i]] = 'Q';

        int ok = 1;
        rep(i,k)if(ans[x[i]][y[i]] != 'Q')ok = 0;
        if(!ok)continue;
        rep(i,8){
            int cnt = 0;
            rep(j,8-i)if(ans[j][i+j] == 'Q')cnt++;
            if(cnt >= 2)ok = 0;
        }
        if(!ok)continue;
        rep(i,8){
            int cnt = 0;
            rep(j,8-i)if(ans[i+j][j] == 'Q')cnt++;
            if(cnt >= 2)ok = 0;
        }
        if(!ok)continue;
        rep(i,8){
            int cnt = 0;
            rep(j,8-i)if(ans[i+j][7-j] == 'Q')cnt++;
            if(cnt >= 2)ok = 0;
        }
        if(!ok)continue;
        rep(i,8){
            int cnt = 0;
            rep(j,8-i)if(ans[j][7-i-j] == 'Q')cnt++;
            if(cnt >= 2)ok = 0;
        }
        if(!ok)continue;

        rep(i,8){
            rep(j,8)cout << ans[i][j];
            cout << endl;
        }
        return 0;
        
    }while(next_permutation(all(r)));
   
    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc145.contest.atcoder.jp/tasks/abc145_c


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    vector<int> deg(100);
    int a, b;
    while(cin >> a >> b){

        if(a == 0){
            int ok = (deg[0]&1) && (deg[1]&1);
            for (int i = 2; i < 100; ++i) {
                if(deg[i]&1) ok = 0;
            }
            puts(ok ? "OK" : "NG");
            fill(deg.begin(),deg.end(), 0);
        }else {
            a--; b--;
            deg[a]++;
            deg[b]++;
        }
    }

    return 0;
}


Measured memory_bytes: 3052
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue> 
#include<stack>
#include<cstdio>

using namespace std;

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

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->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);
	cout<<" "<<u->key;
	inorder(u->right);
}
void preorder(Node *u){
	if(u == NIL) return;
	cout<<" "<<u->key;
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n;
	cin>>n;
	
	string str;
	for(int i=0; i<n; i++ ){
		cin>>str;
		if(str[0] == 'i'){
			int k;
			scanf("%d",&k);
			insert(k);
		}else{
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 24692
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
bool f=0;
void dfs(string s,int i){
  if(s=="AKIHABARA"){
    f=1;
    return;
  }
  if(i>s.size()) return;
  dfs(s,i+1);
  s.insert(s.begin()+i,'A');
  dfs(s,i+2);
}
signed main(){
  string s;
  cin>>s;
  if(s.size()>9){
    cout<<"NO"<<endl;
    return 0;
  }
  dfs(s,0);
  if(!f) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}


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

#define int long long

using namespace std;

const long long N = 650;

int dist[N][N], n, p[N * N];
int cx[4] = {-1, 1, 0, 0};
int cy[4] = {0, 0, -1, 1};

int ok(int x, int y)
{
    return 0 <= x && x < n && 0 <= y && y < n;
}
int a[N][N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            a[i][j] = 1;
            dist[i][j] = N;
            dist[i][j] = min(dist[i][j], i);
            dist[i][j] = min(dist[i][j], j);
            dist[i][j] = min(dist[i][j], n - i - 1);
            dist[i][j] = min(dist[i][j], n - j - 1);
        }
    }
    int ans = 0;
    for (int i = 0; i < n * n; i++)
    {
        cin >> p[i];
        p[i]--;
        int r = p[i] / n, c = p[i] % n;
        a[r][c] = 0;
        //cout << dist[r][c] << " ";
        ans += dist[r][c];
        deque<pair<int, int> > q = {{r, c}};
        while (q.size())
        {
            pair<int, int> xy = q.front();
            q.pop_front();
            int x = xy.first;
            int y = xy.second;
            for (int e = 0; e < 4; e++)
            {
                int nx = x + cx[e];
                int ny = y + cy[e];
                if (ok(nx, ny) && dist[nx][ny] > dist[x][y] + a[x][y])
                {
                    dist[nx][ny] = dist[x][y] + a[x][y];
                    if (a[x][y] == 0) q.push_front({nx, ny});
                    else q.push_back({nx, ny});
                }
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 12724
#include <bits/stdc++.h>
using namespace std;
bool pro(string a) {
	int st = 0, ed = a.size() - 1;
	while (st <= ed) {
		if (a[st] != a[ed]) return false;
		st++; ed--;
	}
	return true;
}
int main() {
	string s, s1, s2;
	cin >> s;
	int n = s.size();
	s1 = s.substr(0, (n - 1) / 2 );
	s2 = s.substr((n + 3) / 2 - 1, n );
//	cout << s1 << '\n' << s2 <<'\n';
	if(pro(s) && pro(s1) && pro(s2)) {
		puts("Yes");
	} else {
		puts("No");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <algorithm>
#include <iterator>
#include <vector>

int N, M; // N vertices, M edges
const int N_MAX = 8;

std::vector<int> G[N_MAX+1];

int dfs(const int pos, std::array<bool, N_MAX+1> visited);

int main()
{
  std::cin >> N >> M;
  for (int i=0; i<M; i++) {
    int s, t;
    std::cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  std::array<bool, N_MAX+1> arr= {};
/*
  for (auto itr=empty.begin(); itr!=empty.end(); itr++) {
    std::cout << *itr << ' ';
  }
  std::cout << std::endl;
*/

  arr[1] = true;
  std::cout << dfs(1, arr);

  return 0;
}

int dfs(const int pos, std::array<bool, N_MAX+1> visited)
{
/*
  for (auto itr=visited.begin(); itr!=visited.end(); itr++) {
    std::cout << *itr << ' ';
  }
  std::cout << '\n';
*/

  bool done = true;
  for (int i=1; i<=N; i++) {
    if (!visited[i]) done = false;
  }
  if (done) {
    //std::cout << "done.\n";
    /*
    for (auto itr=visited.begin(); itr!=visited.end(); itr++) {
      std::cout << *itr << ' ';
    }
    std::cout << '\n';
    */
    return 1;
  }

  int ret = 0;
  for (auto itr=G[pos].begin(); itr!=G[pos].end(); itr++) {
    if (!visited[*itr]) {
      visited[*itr] = true;
      ret += dfs(*itr, visited);
      visited[*itr] = false;
    }
  }

  return ret;
}


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

int main(){
  string A;
  cin >> A;
  long long int N = A.length(), ans = N*(N-1)/2 + N + 1;
  map<char, int> M;
  for(int i = 0; i < N; ++i){
    ++M[A[i]];
    ans -= M[A[i]];
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	ll Q;
	cin >> Q;
	
	//2017likeな数を入れておく
	vector<int> A(100001);
	A[0] = 0;
	A[1] = 0;
	for (int i = 2; i <= 100000 ; ++i) {
		if(i % 2 == 0) {
			A[i] = 0;
			continue;
		}
		//iと(i+1)/2が素数かどうか判定する。
		bool ok = true;
		int temp = (i+1)/2;
		for (int j = 2; j*j <= i ; ++j) {
			if(i % j == 0) ok = false;
		}
		for (int j = 2; j*j <= temp; ++j){
			if(temp % j == 0) ok = false;
		}
		if(ok){
			A[i] = 1;
		}else{
			A[i] = 0;
		}
	}
	
	//累積和を取っておく
	rep(i,100000){
		A[i+1] += A[i];
	}
	
	rep(i,Q){
		int l,r;
		cin >> l >> r;
		cout << A[r] - A[l-1] << endl;
	}
	
    return 0;
}



Measured memory_bytes: 1024