akhauriyash/Code-Regression huggingface dataset:
/*
 * FileName:     Stack
 * CreatedDate:  2020-02-10 00:25:47 +0900
 * LastModified: 2020-04-13 17:20:42 +0900
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define N 500
void chomp(char *moji){
    for(int i=0;;i++){
        if(moji[i]=='\n'){
            moji[i]='\0';
            return ;
        }
    }
}
//void push()
void push(long int s, long int *stack, int *i){
    stack[*i]=s;
    *i=*i+1;
}
long int pop(long int *stack, int *i){
    *i=*i-1;
    long int pop_obj=stack[*i];
    stack[*i]=0;
    return pop_obj;
}
int main(void){
    long int *stack=(long int *)calloc(100,sizeof(long int));
    char line[N];
    fgets(line,N,stdin);
    chomp(line);
    int i=0;
    
    char *ptr;
    ptr=strtok(line," ");
//    printf("%s\n",ptr);
    if(isdigit(*ptr)){
        push(atol(ptr),stack,&i);
    }
    while(ptr!=NULL){
        ptr=strtok(NULL," ");
        if(ptr!=NULL){
//            printf("%s:%d:%d\n",ptr,isdigit(*ptr),i);
            if(isdigit(*ptr)){
                push(atol(ptr),stack,&i);
            }
            else{
                long int b=pop(stack,&i);
                long int a=pop(stack,&i);
                if(strcmp(ptr,"+")==0){
                    push(a+b,stack,&i);
                }
                else if(strcmp(ptr,"-")==0){
                    push(a-b,stack,&i);
                }
                else if(strcmp(ptr,"*")==0){
                    push(a*b,stack,&i);
                }
            }
        }
    }
    printf("%ld\n",pop(stack,&i));
    return 0;
}



Measured memory_bytes: 2112
import Control.Monad
main :: IO ()
main = do
    [_,w] <- map read . words <$> getLine :: IO [Int]
    a <- lines <$> getContents :: IO [String]
    putStrLn $ replicate (w+2) '#'
    forM_ a $ \i -> do
        putChar '#'
        putStr i
        putStrLn "#"
    putStrLn $ replicate (w+2) '#'


Measured memory_bytes: 1020
n = int(input())

c0 = 0
c1 = 0
c2 = 0
c3 = 0

for i in range(n):
    st = input()
    if st == 'AC':
        c0 = c0 + 1
    elif st == 'WA':
        c1 = c1 + 1
    elif st == 'TLE':
        c2 = c2 + 1
    else: 
        c3 = c3 + 1
        

print('AC x',c0)
print('WA x',c1)
print('TLE x',c2)
print('RE x',c3)


Measured memory_bytes: 9196
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
	int i, j, k;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i=0;i<n1;i++) L[i] = A[left + i];
	for(i = 0;i<n2;i++) R[i] = A[mid + i];
	L[n1].value = R[n2].value = SENTINEL;
	i = j = 0;
	for(k=left;k<right;k++){
		if(L[i].value <= R[j].value){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(struct Card A[], int n, int left, int right){
	int mid;
	if(left + 1 < right){
		mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int partition(struct Card A[], int n, int p, int r){
	int i,j;
	struct Card t, x;
	x = A[r];
	i = p - 1;
	for(j=p;j<r;j++){
		if(A[j].value <= x.value){
			i++;
			t = A[i]; A[i] = A[j]; A[j] = t;
		}
	}
	t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
	return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
	int q;
	if(p < r){
		q = partition(A, n, p, r);
		quickSort(A, n, p, q - 1);
		quickSort(A, n, q+1, r);
	}
}

int main(){
	int n, i, v;
	struct Card A[MAX], B[MAX];
	char S[10];
	int stable = 1;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %d",S,&v);
		A[i].suit = B[i].suit = S[0];
		A[i].value = B[i].value = v;
	}

	mergeSort(A, n, 0, n);
	quickSort(B, n, 0, n-1);

	for(i=0;i<n;i++){
		if(A[i].suit != B[i].suit) stable = 0;
	}

	if(stable == 1) printf("Stable\n");
	else printf("Not stable\n");
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit, B[i].value);
	}

	return 0;
}

Measured memory_bytes: 5012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int N;
    cin >> N;
    bool ans = false;
    for (int f = 0; f <= 25; f++)
    {
        for (int s = 0; s <= 15; s++)
        {
            if (N == f * 4 + s * 7)
                ans = true;
        }
    }
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int h,w;
  cin>>h>>w;
  cout<<h+1-w<<endl;
}

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

int a[200100];
int ans[200100];
int sum[200200];
int k;
int n;
int l[2][11];
const int mod = 998244353;
int get(int now){
	if(now<=0) return 0;
	else {
		return sum[now];
	}
}

int main(){
	scanf("%d%d",&n,&k);
	ans[1]=1;sum[1]=1;
	for (int j = 1;j <= k;j++) {
		scanf("%d%d",&l[0][j],&l[1][j]);
	}
	for(int i = 2;i <= n;i++) {
		long long now= 0;
		for(int j = 1;j<=k;j++) {
			now+=get(i-l[0][j]);
			now-=get(i-l[1][j]-1);
		}
		now%=mod;now+=mod;
		now%=mod;ans[i]=now;
		sum[i]=sum[i-1]+ans[i];
		sum[i]%=mod;
		//printf("ans[%d]=%d %d\n",i,ans[i],sum[i]);
	}
	
	printf("%d\n",ans[n]);
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 t;
    cin >> t;

    for (i64 i = 0; i < t; i++) {
        i64 a, b, c, d;
        cin >> a >> b >> c >> d;

        if (a < b) {
            cout << "No" << endl;
            continue;
        }

        if (d < b) {
            cout << "No" << endl;
            continue;
        }

        if (b < c) {
            cout << "Yes" << endl;
            continue;
        }

        i64 g = __gcd(b, d);
        if (b - g + (a % g) > c) {
            cout << "No" << endl;
            continue;
        }

        cout << "Yes" << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i32 = input();
    let b: i32 = input();
    println!(
        "{}",
        if a >= 13 {
            b
        } else if 6 <= a && a <= 12 {
            b / 2
        } else {
            0
        }
    );
}


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

using namespace std;

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    bool same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    bool merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u == v) return false;
        root[u] = v;
        size[v] += size[u];
        return true;
    }
private:
    vector<int> root;
    vector<int> size;
};

void search(const vector<vector<int>>& g, vector<int>& deg, int pos, int prev){
    for(auto& t : g[pos]){
        if(t == prev) continue;
        search(g, deg, t, pos);
    }
    if(prev != -1){
        if(deg[pos]){
            cout << pos << " " << prev << endl;
        } else {
            cout << prev << " " << pos << endl;
            deg[prev] = 1 - deg[prev];
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    UnionFind uf(N+1);
    if(M%2 == 1){
        cout << -1 << endl;
        return 0;
    }
    vector<int> deg(N+1, 0);
    vector<vector<int>> g(N+1);
    for(int i=0;i<M;i++){
        int a, b; cin >> a >> b;
        if(uf.merge(a, b)){
            g[a].push_back(b);
            g[b].push_back(a);
        } else {
            cout << a << " " << b << endl;
            deg[a] = 1 - deg[a];
        }
    }
    search(g, deg, 1, -1);
}

Measured memory_bytes: 14720
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

int main() {
	ll N, i, ans = 1;
	scanf("%lld", &N);
	for (i = 1; i <= N; i++) ans = ans*i%MOD;
	return !printf("%lld\n", ans);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        List<Integer> nl = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            nl.add(in.nextInt());
        }
        int a = nl.get(0);
        int b = 0;
        int c = 0;
        int ac = 0;
        int bc = 0;
        int cc = 0;
        boolean isNo = false;
        boolean isContainsZero = false;
        String ans = "No";
        isContainsZero = nl.contains(Integer.valueOf(0));

        if (!isContainsZero) {
            for (int i = 0; i < nl.size(); i++) {
                if (nl.get(i) != a) {
                    b = nl.get(i);
                    break;
                }
            }
            for (int i = 0; i < nl.size(); i++) {
                if (nl.get(i) != a && nl.get(i) != b) {
                    c = nl.get(i);
                    break;
                }
            }
            for (int i = 0; i < nl.size(); i++) {
                if (nl.get(i) == a) {
                    ac++;
                } else if (nl.get(i) == b) {
                    bc++;
                } else if (nl.get(i) == c) {
                    cc++;
                } else {
                    isNo = true;
                    break;
                }
            }
            if ((a ^ b) != c) {
                isNo = true;
            }
            if (ac == bc && ac == cc && !isNo) {
                ans = "Yes";
            }
        } else {
            for (int i = 0; i < nl.size(); i++) {
                if (nl.get(i) != 0) {
                    a = nl.get(i);
                    break;
                }
              	if (i == nl.size() - 1 && nl.get(i) == 0) {
                    ans = "Yes";
                }
            }
            for (int i = 0; i < nl.size(); i++) {
                if (nl.get(i) == a) {
                    ac++;
                } else if (nl.get(i) == 0) {
                    bc++;
                } else {
                    isNo = true;
                    break;
                }
            }
            if (!isNo && ac == 2 * bc) {
                ans = "Yes";
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 61524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n,m;
ll a[100010];
PLL p[100010];
vector<ll> v;
ll res;
int len;
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=0;i<m;i++) cin >>p[i].S>>p[i].F;
	sort(p,p+m);
	len=n;
	for (int i=m-1;i>=0;i--)
	{
		//cout <<p[i].F<<" "<<p[i].S<<" "<<len<<" ##\n";
		if (p[i].S<len)
		{
			for (int j=0;j<p[i].S;j++) v.push_back(p[i].F);
			len-=p[i].S;
		}
		else
		{
			for (int j=0;j<len;j++) v.push_back(p[i].F);
			len=0;
			/*for (int i=0;i<n;i++) cout <<v[i]<<" ";
			cout <<"\n";*/
			break;
		}
		/*for (int i=0;i<n;i++) cout <<v[i]<<" ";
		cout <<"\n";*/
	}
	sort(a,a+n);
	for (int i=0;i<v.size();i++) if (v[i]<a[i]) v[i]=a[i];
	for (int i=0;i<v.size();i++) res+=v[i];
	for (int i=v.size();i<n;i++) res+=a[i];
	/*for (int i=0;i<n;i++) cout <<v[i]<<" ";
	cout <<"\n";*/
	cout <<res;
	return 0;
}

Measured memory_bytes: 3704
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int X = sc.nextInt();
    int Y = sc.nextInt();
    int Z = sc.nextInt();

    sc.close();

    System.out.println((X-Z)/(Y+Z));

  }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
lld fac_ (lld n)
{
	for(lld i = 1; i <= sqrt(n); i++)
	{
		if (n % i == 0)
		{
			lld y = n/i;
			if ((i >= 1 && i <= 9) && (y >= 1 && y <= 9))
				return 1;
		}
	}
	return 0;
}
int main ()
{
	FastIO
	lld n, i;
	cin >> n;
	if (fac_(n) == 1)
		cout << "Yes";
	else
		cout <<  "No";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        long N = sc.nextInt();	
	        int K = sc.nextInt();	
	        long[] a = new long[(int)N];
	        long ans =0;
	        long tmp=0;
	        for (int i=K ; i<=N+1; i++) {
	        	tmp=i;
	        	tmp=(tmp*(tmp-1)/2);
	            ans=(ans+(i*N)-2*tmp+1)%mod;
	            
	        }
	        
	        System.out.println(ans);
	        
	 }

}

Measured memory_bytes: 37308
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        N: usize,
        M: usize,
        C: isize,
        B: [isize; M],
        A: [[isize; M]; N],
    }
    let mut cnt = 0;
    for n in 0..N {
        let mut ans = C;
        for m in 0..M {
            ans += A[n][m] * B[m];
        }
        if ans > 0 {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}



Measured memory_bytes: 4352
#include <cstdio>

int main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);

     if(a >= b && b >= c) {
         printf("%d %d %d\n", c, b, a);
     }

     else if(a <= b && b <= c) {
         printf("%d %d %d\n", a, b, c);
     }

     else if(b <= a && a <= c) {
         printf("%d %d %d\n", b, a, c);
     }

     else if(b >= a && a >= c) {
         printf("%d %d %d\n", c, a, b);
     }

     else if(b <= c && c <= a) {
         printf("%d %d %d\n", b, c, a);
     }

     else if(a <= c && c <= b) {
         printf("%d %d %d\n", a, c, b);
     }
}


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

struct xyz {ll x; ll y; ll z;};

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,m;cin>>n>>m;
  vector<xyz> cakes(n);

  for(int i=0;i<n;i++){
    ll x,y,z;
    cin>>x>>y>>z;
    cakes[i] = {x,y,z};
  }

  ll res=0;
  for(int i=0;i<8;i++){
    vector<ll> v(n);
    for(int j=0;j<n;j++){
      v[j] = 0;
      v[j] += (0b100 & i) ? cakes[j].x : -cakes[j].x;
      v[j] += (0b010 & i) ? cakes[j].y : -cakes[j].y;
      v[j] += (0b001 & i) ? cakes[j].z : -cakes[j].z;
    }
    ll t_sum=0;
    sort(v.rbegin(), v.rend());
    for(int j=0;j<m;j++){
      t_sum += v[j];
    }
    res = max(t_sum, res);
  }
  cout<<res<<endl;

  return 0;
}


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

int count(int N){
    int cnt = 0;
    while(N != 0){
        N /= 10;
        cnt++;
    }
    return cnt;
}

int main(){
    int N;
    cin >> N;
    int cnt = 0;

    for(int i = N;i > 0;i--){
        int NN = count(i);
        if(NN % 2 != 0)cnt++;
    }

    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 256
import math

N = int(input())
f = False
for h in range(1,3501):
    if f:
        break
    for n in range(1,3501):
        if 4*n*h-N*n-N*h == 0:
            continue
        check = N*n*h/(4*n*h-N*n-N*h)
        if check < 0:
          continue
        if check.is_integer():
            print(h, n, math.floor(check))
            f = True
            break

Measured memory_bytes: 73720
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    n, x, y = map(int, input().split())
    x -= 1
    y -= 1
    dis = defaultdict(int)
    for i1 in range(n):
        for i2 in range(i1+1, n):
            d = min(abs(i2-i1), abs(x-i1)+abs(y-i2)+1, abs(x-i2)+abs(y-i1)+1)
            dis[d] += 1

    for k1 in range(1, n):
        print(dis[k1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 9568
#include<ios>
#include<cstring>
int cnt[4];char s[9];
main()
{
    while(~scanf("%*d,%s\n",s))
    {
        cnt[strcmp(s,"AB")?strcmp(s,"A")?strcmp(s,"B")?3:1:0:2]++;
    }
    for(int i=0;i<4;i++)printf("%d\n",cnt[i]);
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int x=1; // 掲示板初期値
  for (int i = 0; i < N; i++) {
  int A, B;
    A = x * 2;
    B = x + K;
    if( A < B)
      x = A;
    else
      x = B;
}
      cout << x << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>

void smallInk(int Field[][10],int ink[]);
void regularInk(int Field[][10],int ink[]);
void largeInk(int Field[][10],int ink[]);

void applyInk(int Field[][10],int ink[]){
	if(ink[2]==1){
		smallInk(Field,ink);
	}else if(ink[2]==2){
		regularInk(Field,ink);
	}else if(ink[2]==3){
		largeInk(Field,ink);
	}
}

int WhiteField(int Field[][10]){
	int count=0,i,j;
	
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			if(Field[i][j]==0) count++;
		}
	}
	return count;
}

int MostDeep(int Field[][10]){
	int max=0,i,j;
	
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			max = max<Field[i][j] ? Field[i][j] : max;
		}
	}
	return max;
}


int main()
{
	int Field[10][10],ink[3],
		i,j;
	
	for(i=0;i<10;i++){			/*ú»*/
		for(j=0;j<10;j++){
			Field[i][j]=0;
		}
	}
	
	while(scanf("%d,%d,%d",&ink[0],&ink[1],&ink[2])!=EOF){
		applyInk(Field,ink);
	}
	printf("%d\n",WhiteField(Field) );
	printf("%d\n",MostDeep(Field) );
	
	return 0;
}

void smallInk(int Field[][10],int ink[]){
	int x,y;										/*iÍx,jÍy*/
	for(x=ink[0]-1;x<=ink[0]+1;x++){
		if(x==ink[0]){								/*^ñÌÆ±ë*/
			for(y=ink[1]-1;y<=ink[1]+1;y++){
				if(0<=y && y<10){						/*¿éÆ±ëÍ0<=x<9ÈÌÅAiÍwèµÈ¢B*/
					Field[y][x]++;
				}
			}
		}else{										/*ÐÆÂÌÆ±ë*/
			if(0<=x && x<10){
				Field[ ink[1] ][x]++;
			}
		}
	}
}
		
void regularInk(int Field[][10],int ink[]){
	int x,y;
	for(x=ink[0]-1;x<=ink[0]+1;x++){
		for(y=ink[1]-1;y<=ink[1]+1;y++){
			if( (0<=x && x<10) && (0<=y && y<10)){
				Field[y][x]++;
			}
		}
	}
}

void largeInk(int Field[][10],int ink[]){
	int x,y;
	for(x=ink[0]-2;x<=ink[0]+2;x++){
		/*j,ink[1]ÆÌÇÁ¿Åà¢¢*/
		if(x==ink[0]-2 || x==ink[0]+2){		/*1ÂÌÆ±*/
			if(0<=x && x<10){
				Field[ ink[1] ][x]++;
			}
		}else if(x==ink[0]-1 || x==ink[0]+1){	/*3ÂÌÆ±*/
			for(y=ink[1]-1;y<=ink[1]+1;y++){
				if( (0<=x && x<10) && (0<=y && y<10)){
					Field[y][x]++;
				}
			}
		}else if(x==ink[0]){						/*5ÂÌÆ±*/
			for(y=ink[1]-2;y<=ink[1]+2;y++){
				if( (0<=x && x<10) && (0<=y && y<10)){
					Field[y][x]++;
				}
			}
		}
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

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

  int amin = 0;
  int vmax = -1;
  for (int i = 0; i < n; ++i) {
    int a, v;
    cin >> a >> v;
    if (v < vmax || (v == vmax && amin < a))
      continue;
    amin = a;
    vmax = v;
  }
  cout << amin << " " << vmax << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+5;
typedef long long ll;

ll f(ll a,ll b,ll c)
{
    return b/c-(a-1)/c;
}

ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b-a+1-f(a,b,c)-f(a,b,d)+f(a,b,lcm(c,d));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
string s,t;
int dp[3005][3005],bst[3005][3005],n,m,c;
int solve(int i,int j){
  if(i>=n or j>=m){
    bst[i][j]=-2;
    return 0;
  }
  if(dp[i][j]!=-1)return dp[i][j];
  int ans=0;
    if(s[i]==t[j]){
      bst[i][j]=-1;
      return dp[i][j]=(1+solve(i+1,j+1));
    }
    int ans1=solve(i,j+1);
    int ans2=solve(i+1,j);
    if(bst[i][j]!=-1){
      if(ans1<=ans2){
        bst[i][j]=1;
        dp[i][j]=ans2;
        return dp[i][j];
      }
      else {
        bst[i][j]=2;
        dp[i][j]=ans1;
        return dp[i][j];
      }
    }
}
int32_t main(){
  fastIO
  clr(dp,-1);
   cin>>s>>t;
   n=s.ln,m=t.ln;
   int tar=solve(0,0);
  int h=0;
  string ans="";
  int i=0,j=0;
  while(bst[i][j]!=-2){
    if(bst[i][j]==-1){
      ans+=s[i];
      i++;
      j++;
    }
    elif(bst[i][j]==1){
      i++;
    }
    else j++;
  }
  cout<<ans<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 74396
n=gets.chomp.to_i
t,x,y=[],[],[]
t[0],x[0],y[0]=0,0,0
for i in 1..n
  t[i],x[i],y[i]=gets.chomp.split(" ").map{|s| s.to_i}
end
j=true

for i in 0..n-1
dt=t[i+1]-t[i]
df=(x[i+1]-x[i]).abs+(y[i+1]-y[i]).abs
  unless dt >= df && dt%2==df%2
    puts "No"
    j=false
    break
  end
end

if j
  puts "Yes"
end

Measured memory_bytes: 4264
#include<stdio.h>
#define MAX 2000000

int H,A[MAX+1],temp;

void maxHeapify(int i){
    int l,r,largest;
    l = 2*i;
    r = 2*i+1;

    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;
    if(largest != i){
        temp = A[i];
        A[i] = A[largest];
        A[largest] = temp;
        maxHeapify(largest);
    } 
}

int main(){
    int i;
    scanf("%d",&H);
    for(i = 1; i <= H; i++) scanf("%d",&A[i]);
    for(i = H/2; i >=1; i--) maxHeapify(i);
    for(i = 1; i <= H; i++) printf(" %d",A[i]);
    printf("\n");

}


Measured memory_bytes: 3644
def ABC077C_SnukeFes():
    N = int(input().strip())
    A = sorted(list(map(int, input().strip().split())))
    B = sorted(list(map(int, input().strip().split())))
    C = sorted(list(map(int, input().strip().split())))

    ans = 0
    blist = [0] * N
    cidx = 0
    for bidx in range(N):
        while (cidx < N) and (B[bidx] >= C[cidx]):
            cidx += 1
        
        if cidx >= N:
            break
        blist[bidx] = N - cidx

    bTotal = [0] * N
    bTotal[N - 1] = blist[N - 1]
    for bidx in range(1, N):
        bTotal[N - bidx - 1] = bTotal[N - bidx] + blist[N - bidx - 1]


    bidx = 0
    for aidx in range(N):
        while (bidx < N) and (A[aidx] >= B[bidx]):
            bidx += 1
        if bidx >= N:
            break
        ans += bTotal[bidx]
    
    print(ans)


def main():
    ABC077C_SnukeFes()

if __name__ == "__main__":
    main()


Measured memory_bytes: 23820
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

const int dx[] = {1, 0, -1, 0, 0};
const int dy[] = {0, 1, 0, -1, 0};

const int Maxn = 100010;
const int MOD = (int) 1e9 + 7;

ll h, w, n;
map<P, int> mp;
ll ans[10];

void add(int x, int y) {
    for (int i = -2; i <= 0; ++i) {
        for (int j = -2; j <= 0; ++j) {
            int nx = x + i, ny = y + j;
            if (0 <= nx && nx < h - 2 && 0 <= ny && ny < w - 2) {
                mp[P(nx, ny)]++;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w >> n;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        add(a, b);
    }

    ans[0] = (h - 2) * (w - 2);
    for (auto &m : mp) {
        ans[0]--;
        ans[m.second]++;
    }
    for (int i = 0; i < 10; ++i) {
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 56576
s=input()
sl=list(reversed(s))
ns="".join(list(reversed(s)))
k=int((len(s)-1)/2)
t=s[:k]
tl=list(reversed(t))
nt="".join(list(reversed(t)))
n=int((len(s)+3)/2)
r=s[n-1:len(s)]
rl=list(reversed(r))
nr="".join(rl)
if s==ns and t==nt and r==nr:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

int main() {
  string s;
  ll ans = 0;
  cin >> s;

  for (int i = s.size()-1; i > 0; --i) {
    if (s[i] != s[i-1]) {
      ++ans;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a,b ;
int main(){
    while(1){
        int sou[2][1000]={};
        cin>>a;
        if(a==0)break;
        for(int q=0;q<a;q++){
            cin>>b;
            sou[0][b]=true;
        }
        for(int i=1;i<a*2+1;i++){
            if(!sou[0][i]){sou[1][i]=true;}
        }
        int aaa[2]={a,a};
        int no=0, cu=1;
        while(aaa[0]&&aaa[1]){
            for(;cu<a*2+1;cu++){
                if(sou[no][cu]){
                    aaa[no]--;
                    sou[no][cu]=false;
                    break;
                }
            }
            if(cu==2*a+1){cu=1;}
            int jp=0;
            if(no==1&&jp==0){no=0;jp++;}
            if(no==0&&jp==0){no=1;jp++;}

        }
        cout<<aaa[1]<<"\n"<<aaa[0]<<endl;
    }
}

Measured memory_bytes: 3008
#include <stdio.h>
#define MAX 21

int main(void){
	short i,len;
	char c;
	char cbuf[MAX];
	char cbufinv[MAX];
	for(i = 0; ; i++){
		c = getchar();
		if(c == '\n'){break;}
		cbuf[i] = c;
	}
	cbufinv[i] = 0;
	len = i;
	i--;
	for( ;i >= 0; i--){
		cbufinv[len-i] = cbuf[i];
		putchar(cbufinv[len-i]);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

multiset<int> prob;
 
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        prob.insert(d);
    }
    
    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        int t;
        cin >> t;
        if (prob.count(t) == 0) {
            cout << "NO" << endl;
            return 0;
        } else {
            prob.erase(prob.find(t));
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9604
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAXN = 2e5 + 7;
int A[MAXN], B[MAXN];
set<pii>pr;
multiset<int>ans;
void add(pii x) {
    if (pr.find(x) != pr.end()) return;
    pr.insert(x);
    ans.insert(x.first - x.second);
}
void del(pii x) {
    assert(pr.find(x) != pr.end());
    pr.erase(x);
    ans.erase(ans.find(x.first - x.second));
}
int main() {
    int h, w; scanf("%d %d", &h, &w);
    for (int i = 1; i <= h; i++) scanf("%d %d", &A[i], &B[i]);
    for (int i = 1; i <= w; i++) add({i, i});
    for (int i = 1; i <= h; i++) {
        auto it = pr.lower_bound({A[i], 0});
        int rightmost = -1;
        vector<pii>vec;
        while (it != pr.end() && it->first <= B[i]) {
            rightmost = max(rightmost, it->second);
            vec.push_back(*it);
            it++;
        }
        for (pii &x : vec) del(x);
        if (rightmost != -1 && B[i] != w) {
            add({B[i] + 1, rightmost});
        }
        ans.size() ? printf("%d\n", i + *ans.begin()) : puts("-1");
    }
    return 0;
}

Measured memory_bytes: 23996
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int h,w; cin >> h >> w;
	vector<string> v(h);
	rep(i,h) cin >> v[i];
	rep(i,w+2) cout << '#';
	cout << endl;
	rep(i,h){
		cout << '#' << v[i] << '#' << endl;
	}
	rep(i,w+2) cout << '#';
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=1010, inf=2e9;

int n, m;

vector<int> G[MX];
bool vis[MX], GG[MX][MX];

vector<pii> P;

void init(){
    cin>>n>>m;
    for(int i=1, u, v; i<=m; i++){
        cin>>u>>v;
        GG[u][v]=GG[v][u]=true;
    }
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++)
            if(!GG[i][j]){
                G[i].push_back(j);
                G[j].push_back(i);
            }
    }
}

int C[MX];
bool unvalid;
pii dfs(int v, int c){
    int cnt[2]={};
    cnt[c]++; C[v]=c;
    vis[v]=true;
    for(int x:G[v]){
        if(vis[x]){
            if(C[x]==C[v]) unvalid=true;
            continue;
        }
        pii p=dfs(x,1-c);
        cnt[0]+=p.first, cnt[1]+=p.second;
    }
    return pii(cnt[0], cnt[1]);
}

void process(){
    P.push_back(pii(0,0));
    for(int i=1; i<=n; i++){
        if(vis[i]) continue;
        P.push_back(dfs(i,0));
        if(unvalid){
            cout<<-1;
            exit(0);
        }
    }
}

bool D[MX][MX], done[MX][MX];
bool d(int x, int y){
    if(y<0) return false;
    if(done[x][y]) return D[x][y];
    done[x][y]=true;
    D[x][y]=d(x-1, y-P[x].first) || d(x-1, y-P[x].second);
    return D[x][y];
}


int solve(){
    for(int i=0; i<=n; i++) done[0][i]=true, D[0][i]=false;
    D[0][0]=true;
    int mn=inf;
    for(int i=0; i<=n; i++){
        if(d(P.size()-1U, i))
            mn=min(mn, i*(i-1)/2 + (n-i)*(n-i-1)/2);
    }
    return mn;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    init();
    process();
    cout<<solve();
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(a, b, c) for(ll c=a;c<b;c++)
#define re(b, c) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

vvl ans = vv(99, 99, -1, ll);

void append(ll k, ll mode){
  ll i = (k/33)*3, j = (k%33)*3;
  re(3, p) re(3, t) ans[i+p][j+t] = (mode==1?1:0);
  if(mode==1) ans[i+1][j+1] = 0;
  if(mode==2) ans[i+1][j+1] = 1;
}

int main(int argc, char const *argv[]) {
  ll a, b;std::cin >> a >> b;
  ll num = 0;
  while(a>1){
    append(num, 1);
    num++, a--;
  }
  if(num>0) b--;
  while(b>0){
    append(num, 2);
    num++, b--;
  }
  a--;
  //std::cout << a << " " << b  << " " << num << '\n';
  std::cout << "99 99" << '\n';
  re(99, i) re(99, j) std::cout << (ans[i][j]==1?"#":".") << (j==98?"\n":"");
  return 0;
}


Measured memory_bytes: 1016
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define sc scanf
#define pr printf
using namespace std;
typedef long long ll;
const ll N = 1000000000+7;
int main()
{
    int n;
    while(~sc("%d",&n))
    {
        ll ans = 1;
        for(ll i=1; i<=n; i++)
        {
            ans = ((ans)%N)*((i)%N)%N;
            ans %= N;
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n,c = map(int,input().split())
l = [list() for _ in range(c+1)]
for _ in range(n):
  s,t,ch = map(int,input().split())
  l[ch].append((s,t))
al = list()
for x in l:
  x.sort()
for i in range(c+1):
  if l[i] == []:
    continue
  t = list()
  for j in range(len(l[i])-1):
    if l[i][j][1] == l[i][j+1][0]:
      l[i][j+1] = (l[i][j][0],l[i][j+1][1])
    else:
      t.append(l[i][j])
  t.append(l[i][-1])
  al += t
tl = [0]*(10**5+10)
for s,t in al:
  tl[s] += 1
  tl[t+1] -= 1
for i in range(10**5+9):
  tl[i+1] += tl[i]
print(max(tl))


Measured memory_bytes: 18488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
    a[i]--;
  }
  vector<bool> f(n, false);
  int next = 0, cnt = 0;
  REP(i, n) {
    cnt++;
    if (a[next] == 1) {
      cout << cnt << "\n";
      return 0;
    }
    if(f[next]){
      cout << "-1\n";
      return 0;
    }
    f[next] = true;
    next = a[next];
  }
  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 repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}


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

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    char s[100];
    int k=0;
    cin>>s;
    if ((s[0]==s[1] && s[1]==s[2]) || (s[1]==s[2] && s[2]==s[3]))
        printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();

			if (numA > 16 / 2 || numB > 16 / 2) {
				System.out.println(":(");
				return;
			}

			System.out.println("Yay!");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
int dis[100005],vis[100005];
deque<int>q;
int k;
int main(){
	cin>>k;
	dis[1]=1;q.push_back(1);
	while(!q.empty()){
		int u=q.front();q.pop_front();
		if(vis[u]) continue;
		vis[u]=1;if(!u) return printf("%d\n",dis[0]),0;
		int v;
		v=(u+1)%k;
		if(!vis[v]) dis[v]=dis[u]+1,q.push_back(v);
		v=(u*10)%k;
		if(!vis[v]) dis[v]=dis[u],q.push_front(v);
	}return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        StringBuffer sb = new StringBuffer();

        String[] arr = new String[n+1];
        for (int i=0; i<n; i++) arr[i] = sc.next();
        arr[n] = "X";

        for (int i=0; i<n; i++) {
            if (arr[i].equals("AB")) {
                if (a <= 0 && b <= 0) {
                    System.out.println("No");
                    return;
                }
                if (a < b) {
                    a += 1;
                    b -= 1;
                    sb.append("A\n");
                } else if (b < a) {
                    b += 1;
                    a -= 1;
                    sb.append("B\n");
                } else {
                    if (arr[i+1].equals("BC")) {
                        b += 1;
                        a -= 1;
                        sb.append("B\n");
                    } else {
                        a += 1;
                        b -= 1;
                        sb.append("A\n");
                    }
                }
            } else if (arr[i].equals("AC")) {
                if (a <= 0 && c <= 0) {
                    System.out.println("No");
                    return;
                }
                if (a < c) {
                    a += 1;
                    c -= 1;
                    sb.append("A\n");
                } else if (c < a) {
                    c += 1;
                    a -= 1;
                    sb.append("C\n");
                } else {
                    if (arr[i+1].equals("BC")) {
                        c += 1;
                        a -= 1;
                        sb.append("C\n");
                    } else {
                        a += 1;
                        c -= 1;
                        sb.append("A\n");
                    }
                }
            } else {
                if (b <= 0 && c <= 0) {
                    System.out.println("No");
                    return;
                }
                if (b < c) {
                    b += 1;
                    c -= 1;
                    sb.append("B\n");
                } else if (c < b) {
                    c += 1;
                    b -= 1;
                    sb.append("C\n");
                } else {
                    if (arr[i+1].equals("AC")) {
                        c += 1;
                        b -= 1;
                        sb.append("C\n");
                    } else {
                        b += 1;
                        c -= 1;
                        sb.append("B\n");
                    }
                }
            }
        }

        System.out.println("Yes");
        System.out.println(sb.toString());

    }
}


Measured memory_bytes: 63516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int A,B;
  cin>>A>>B;
  cout<<A*B<<endl;

  return 0;
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int g, r;
  cin >> r >> g;
  cout << 2*g-r << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
ll MOD=1000000007;
int inf=1000000000;
ll INF=10000000000000000;
int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> b(n),l(n),u(n);
    vector<pair<ll,ll>> a(n);
    ll uu=0;
    rep(i,n){
        cin >> b.at(i) >> l.at(i) >> u.at(i);
        a.at(i).first=u.at(i)*(x-b.at(i))+l.at(i)*b.at(i);
        a.at(i).second=i;
        uu+=l.at(i)*b.at(i);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll sum=0,v;
    rep(i,n){
        sum+=a.at(i).first;
        if (sum>uu) {sum-=a.at(i).first;v=i;break;}
        if (sum==uu) {cout << (i+1)*x << endl;return 0;}
    }
    ll ans=INF;
    rep(i,n){
        ll y=sum;
        int p=a.at(i).second;
        if (i<v) y=sum-a.at(i).first+a.at(v).first;
        ll t=uu-y+(u.at(p)-l.at(p))*b.at(p);
        ll o=t/u.at(p);
        if (t%u.at(p)!=0) o++;
        ans=min(ans,v*x+o);
        t=uu-y;
        o=t/l.at(p);
        if (t%l.at(p)!=0) o++;
        ans=min(ans,v*x+o);
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

ll comb(ll n, ll k) {
    if (n < 0 || k < 0)
        return 0;
    else if (n < k)
        return 0;
    ll res = 1;
    ll d = 1;
    for (int i = 0; i < k; i++) {
        res *= n - i;
        d *= i + 1;
    }
    res /= d;
    return res;
}

ll bpow(ll n, ll k) {
    ll res = 1;
    for (; k > 0; k >>= 1) {
        if (k & 1) res *= n;
        n *= n;
    }
    return res;
}

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

    string S;
    cin >> S;

    int n = (int)S.size();

    int K;
    cin >> K;

    ll ans = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        int ni = S[i] - '0';
        if (ni == 0) continue;
        ans += comb(n - i - 1, K - cnt) * bpow(9, K - cnt);
        ans += (ni - 1) * comb(n - i - 1, K - 1 - cnt) * bpow(9, K - 1 - cnt);
        ++cnt;
    }

    cnt = 0;
    for (const auto& v : S) {
        if (v != '0') ++cnt;
    }

    if (cnt == K) ++ans;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

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

long long INF=LLONG_MAX;
map < string, int > v;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int mx = 0;
	int n; cin >> n;
	string s[n];
	for(int i = 0; i < n; i++){
		cin >> s[i];
		v[s[i]]++;
		mx = max(v[s[i]],mx);
	}
	vector < string > ans;
	for(int i = 0; i < n; i++){
		if(v[s[i]]==mx){
			ans.pb(s[i]);
		}
	}
	sort(all(ans));
	unique(all(ans));
	for(int i = 0; i <n; i++){
		if(i&&ans[i]<=ans[i-1])break;
		cout << ans[i] << endl;
	}
}	


Measured memory_bytes: 27120
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>

using namespace std;

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

  int a, b, k;
  cin >> a >> b >> k;

  vector <int> list;
  for (int i = 1; i <= max(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      list.push_back(i);
    }
  }

  cout << list[list.size() - k] << endl;

}

Measured memory_bytes: 256