akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

int main(){
  vector<int> x(5);
  int cnt = 0;
  for(int i = 0;i < 5;i++){
    cin >> x[i];
    cnt++;
    if (x[i] == 0) break;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <set>

using namespace std;

int all_digits_same(int n)
{
    set <int> digits;

    while(n)
    {
        digits.insert(n%10);

        n /= 10;
    }

    return (digits.size() == 1);
}

int main()
{
    int n;
    scanf("%d", &n);

    while(!all_digits_same(n))
        n++;

    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 256
#重み付きUnion-Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        px = find(par[x])
        wei[x] += wei[par[x]]
        par[x] = px
        return px

#xの根から距離
def weight(x):
    find(x)
    return wei[x]


#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
    w += wei[x]-wei[y]
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
            w = -w
        par[x] += par[y]
        par[y] = x
        wei[y] = w
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
    return weight(y)-weight(x)

n,m = map(int,input().split())

#初期化
#par:根なら-size,子なら親の頂点
#wei:親からの距離,根なら0
par = [-1]*n
wei = [0]*n

for i in range(m):
    l,r,d = map(int,input().split())
    l,r = l-1,r-1
    if same(l,r):
        if d != diff(l,r):
            print('No')
            exit()
    else:
        unite(l,r,d)
print('Yes')

Measured memory_bytes: 103512
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let input = read_vec::<usize>();
    let (n, m) = (input[0], input[1]);
    let mut l = 1;
    let mut r = n;

    for _ in 0..m {
        let lr = read_vec::<usize>();
        l = std::cmp::max(l, lr[0]);
        r = std::cmp::min(r, lr[1]);
    }

    if r >= l {
        println!("{}", r - l + 1);
    } else {
        println!("0");
    }
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	
	
	public boolean prime(int x) {
		
		if(x < 2) {
			return false;
		}
		if(x == 2) {
			return true;
		}
		for(int i = 2; i <= Math.sqrt(x); i++) {
			if(x % i == 0) {
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Main program = new Main();
		int results = 0;
		int size = in.nextInt();
		for(int i = 0; i < size; i++) {
			int value = in.nextInt();
			if(program.prime(value) == true) {
				results++;
			}
		}
		System.out.println(results);
	}
}



Measured memory_bytes: 41316
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{	
	auto N = RD;
	auto S = RD!string;
	/*long N = 2*(10^^5);
	auto SS = new char[][](1);
	foreach (i; 0..1)
	{
		SS[i] = new char[](N);
		foreach (j; 0..N)
			SS[i][j] = dice(0.5, 0.5) == 0 ? '.' : '#';
	}
	
	foreach (S; SS)
	{ writeln(S);*/

	long[] cnt = [0];
	char last = S[0];
	foreach (i; 0..N)
	{
		if (S[i] == last)
		{
			++cnt[$-1];
		}
		else
		{
			cnt ~= 1;
			last = S[i];
		}
	}
	debug writeln(cnt);

	auto b_pos = S[0] == '#' ? 0 : 1;
	auto b = new long[](cnt.length+100);
	auto w = new long[](cnt.length+100);
	foreach (i, e; cnt)
	{
		b[i+1] = b[i];
		
		if (i % 2 == b_pos)
			b[i+1] += e;
	}
	foreach_reverse (i, e; cnt)
	{
		w[i] = w[i+1];
		if (i % 2 != b_pos)
			w[i] += e;
	}

	long ans = long.max;
	foreach (i; 0..cnt.length+1)
	{
		ans = min(ans, w[i] + b[i]);
	}

	writeln(ans);
	stdout.flush();
	//}
	debug readln();
}

Measured memory_bytes: 7548
N, K = map(int, input().split(" "))

h = [int(input()) for i in range(N)]

sort_h = sorted(h)
diff_h = 0
ans = []
for i in range(len(h)-K+1):
    diff_h = sort_h[i+(K-1)] - sort_h[i] 
    ans.append(diff_h)

print(min(ans))

Measured memory_bytes: 11960
from collections import deque,Counter

N = int(input())
lisA = list(map(int,input().split()))

cnt = Counter(lisA)

if len(cnt)>3:
    print("No")
    exit()

if len(cnt) == 1:
    if lisA[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
elif len(cnt) == 2:
    if not 0 in cnt:
        print("No")
        exit()
    else:
        keys = sorted(list(cnt.keys()))
        another = keys[-1]
        if cnt[0]*2 == cnt[another]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
else:
    keys = sorted(list(cnt.keys()))
    if keys[0]^keys[1]^keys[2] != 0:
        print("No")
        exit()
    else:
        if cnt[keys[0]]==cnt[keys[1]]==cnt[keys[2]]:
            print("Yes")
            exit()
        else:
            print("No")
            exit()


Measured memory_bytes: 14468
// 7/25 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

    int ans = (1999 - X) / 200 + 1;
    cout << ans << endl;
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int cnt = 0, sum;
  for (int i = 0; i <= A; i++) {
    for (int j = 0; j <= B; j++) {
      for (int k = 0; k <= C; k++) {
        sum = 500 * i + 100 * j + 50 * k;
        if (sum == X) cnt++;
      }
    }
  }
  cout << cnt << endl;
}


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

using namespace std;

int na, nb, q;
const int MAX_LEN = 1e5 + 10;
long long a[MAX_LEN], b[MAX_LEN];
long long left_bound(long long *a, int size, long long x)
{
	int l = 1, r = size;
	long long res = -1;
	while (l <= r)
	{
		int mid = (l + r) / 2;
		if (a[mid] <= x)
		{
			l = mid + 1;
			res = a[mid];
		}
		else
			r = mid - 1;
	}
	return res;
}
long long right_bound(long long *a, int size, long long x)
{
	int l = 1, r = size;
	long long res = -1;
	while (l <= r)
	{
		int mid = (l + r) / 2;
		if (a[mid] >= x)
		{
			r = mid - 1;
			res = a[mid];
		}
		else
			l = mid + 1;
	}
	return res;
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> na >> nb >> q;
	for (int i = 1; i <= na; i++)
		cin >> a[i];
	for (int i = 1; i <= nb; i++)
		cin >> b[i];
	sort(a + 1, a + na + 1);
	sort(b + 1, b + nb + 1);
	for (int i = 1; i <= q; i++)
	{
		long long x;
		cin >> x;
		long long ans(LONG_LONG_MAX);
		long long la = left_bound(a, na, x), ra = right_bound(a, na, x), lb = left_bound(b, nb, x), rb = right_bound(b, nb, x);
		if (la != -1 && lb != -1) ans = min(ans, max(x - la, x - lb));
		if (la != -1 && rb != -1)
		{
			ans = min(ans, x - la + rb - la);
			ans = min(ans, rb - x + rb - la);
		}
		if (ra != -1 && lb != -1) 
	    {
	    	ans = min(ans, x - lb + ra - lb);
	    	ans = min(ans, ra - x + ra - lb);
	    }
		if (ra != -1 && rb != -1) ans = min(ans, max(ra - x, rb - x));
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int n,a,b,f[5005];
long long dp[5005][5005];
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        f[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
        int pos=f[i];
        long long t=1e18;
        for(int j=1;j<=n;j++)
        {
            int p;
            if(pos==j) p=0;
            else if(pos>j) p=b;
            else p=a;
            t=min(t,dp[i-1][j]);
            dp[i][j]=t+p;
        }
    }
    long long ans=1e18;
    for(int i=1;i<=n;i++)
        ans=min(ans,dp[n][i]);
    printf("%lld\n",ans);
}


Measured memory_bytes: 195840
import java.util.*;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int N;
		int idx = 0;
        N = sc.nextInt();

        for(int i = 1;i <= 9; i++) {
            for(int j = 1; j <= 9; j++) {
                if(i * j == N) {
                    idx++;
                    break;
                }
            }
        }
      
        if(idx > 0) {
          System.out.print("Yes");
        } else {
          System.out.print("No");
        }
 
        sc.close();

    }

}

Measured memory_bytes: 23892
#include<iostream>
#include<math.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  if (x != 2 && x % 2 == 0){
    x++;
  }
  while(true){
    int flag = 1;
    for(int y = 3; y<sqrt(x); y+=2){
      if(x % y == 0){
        flag = 0;
        break;
      }
    }
    if(flag == 1) break;
    x = x+2;
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> lol(n);
    for (int i = 0; i < n; i++) {
        cin >> lol[i];
    }
    sort(lol.begin(), lol.end());
    cout << lol[lol.size() - 1] - lol[0];
}

Measured memory_bytes: 3616
import numpy as np

def get_angle(h, m):
  tmp_h = np.pi * h / 6 + np.pi * m / 360
  tmp_m = np.pi * m /30
  return abs(tmp_h - tmp_m)

def calc(a, b, h, m):
  angle = get_angle(h, m)
  return np.sqrt(a*a + b*b - 2*a*b*np.cos(angle))

a, b, h, m = map(int, input().split())
print(calc(a, b, h, m))


Measured memory_bytes: 27220
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem162b(n))
}

fun problem162b(n: Int): Long {
    var sum = 0L
    for (i in 1..n) {
        if (i % 3 == 0 || i % 5 == 0) continue
        sum += i
    }
    return sum
}

Measured memory_bytes: 36388
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    vi h(n+1);
    vi ans(n+1);
    int num = 0;
    rep(i,n){
        int x; cin >> x;
        h[i+1] = x;
        if(h[i] >= h[i+1]) ans[i+1] = ans[i]+1;
        chmax(num,ans[i+1]);
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int judge(int y){
  int i;
  if(y<2)return 0;
  else if(y==2)return 1;
  else if(y%2==0)return 0;
  for(i=3;i*i<=y;i+=2){
    if(y%i==0)return 0;
  }
  return 1;
}

int main() {
  int i,n,x;
  int count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    if(judge(x))count++;
    
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2064
import java.util.Scanner;

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

        int input = sc.nextInt();

        int fivehundreds = input / 500;

        int fivehundredrem = input % 500;

        int fives = fivehundredrem / 5;

        System.out.println(fivehundreds * 1000 + fives * 5);
    }
}


Measured memory_bytes: 23252
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int r,c;
int n,res;
int visx[maxn],visy[maxn];
int ri[maxn],ci[maxn],ai[maxn];
vector < int > edger[maxn], edgec[maxn];
 
ll low,up;
ll xmin[maxn],ymax[maxn];
 
void dfsmax(int,int);
void dfsmin(int,int);
 
void dfsmin(int x,int va)
{
	visx[x]=1;
	xmin[x]=va;
	low=max(low,-xmin[x]);
	for(int i=0;i<edger[x].size();i++)
	{
		int v = ai[edger[x][i]];
		int to= ci[edger[x][i]];
 
		if(visy[to])
		{
			res&=(xmin[x]+ymax[to]==v);
		}
		else
		{
			dfsmax(to,v-xmin[x]);
		}
	}
}
 
void dfsmax(int y,int va)
{
	visy[y]=1;
	ymax[y]=va;
	up=min(up,ymax[y]);
	for(int i=0;i<edgec[y].size();i++)
	{
		int v = ai[edgec[y][i]];
		int to= ri[edgec[y][i]];
 
		if(visx[to])
		{
			res&=(xmin[to]+ymax[y]==v);
		}
		else
		{
			dfsmin(to,v-ymax[y]);
		}
	}
}
 
void solve()
{
	scanf("%d%d",&r,&c);
	scanf("%d",&n);
 
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&ri[i],&ci[i],&ai[i]);
		edger[ri[i]].push_back(i);
		edgec[ci[i]].push_back(i);
	}
	res=1;
	for(int i=1;i<=r&&res;i++)
	{
		if(!visx[i])
		{
			low=-1e18;
			up=1e18;
			dfsmin(i,0);
			res &= (low<=up);
			/*
			if(res==0)
			{
				cout<<low<<" "<<up<<endl;
				cout<<i<<endl;
			}
			*/
		}
	}
	if(res)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
}
int main()
{

	solve();
	return 0;
}

Measured memory_bytes: 16256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String ans;
    if(S.contentEquals("ABC")) {
    	ans = "ARC";
    }else {
    	ans = "ABC";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 35652
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int num;

  int n; cin >> n;
  string s; cin >> s;

  vector<int> mem(n);

  int white = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != '#') ++white;
    mem[i] = white;
  }

  int tmp = mem[n - 1];
  num = min(tmp, n - tmp);

  for (int i = 1; i < n; ++i) {
    num = min(num, i + tmp - 2 * mem[i - 1]);
  }
  
  cout << num << endl;
  
  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, m, k);

  if (m == 0) {
    if (k == 0) {
      out(0, 0);
    } else {
      out(-1);
    }
    return 0;
  }
  if (m == 1) {
    if (k == 0) {
      out(0, 0, 1, 1);
    } else {
      out(-1);
    }
    return 0;
  }

  int pow2 = 1 << m;

  int xors = 0;
  rep(i, pow2) xors ^= i;
  dbg(xors);

  if (0 <= k && k < pow2) {
    for (int i = 0; i < pow2; ++i) {
      if (i == k) continue;
      cout << i << " ";
    }
    cout << k << " ";
    for (int i = pow2 - 1; i >= 0; --i) {
      if (i == k) continue;
      cout << i << " ";
    }
    cout << k << endl;
  } else {
    out(-1);
  }
}


Measured memory_bytes: 3640
var
  n,i,t,x,y:longint;
  p:boolean;
begin
  readln(n);
  p:=true;
  for i:=1 to n do
  begin
    readln(t,x,y);
    if not(((((x+y) mod 2=0)and(t mod 2=0))or(((x+y) mod 2=1)and(t mod 2=1)))and(t>=x+y)) then begin p:=false;write('No');break;end;
  end;
  if p then write('Yes');
end.

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

int main() {
    int n;
    cin >> n;
    map<int, int> member;
    for (int i=0; i<n-1; i++) {
        int a;
        cin >> a;
        if (member.count(a)) member.at(a)++;
        else member[a] = 1;
    }
    for (int i=1; i < n+1; i++) {
        if (member.count(i)) cout << member.at(i) << endl;
        else cout << 0 << endl;
    }
}

Measured memory_bytes: 12972
import itertools
a=input().split()
cnt=0
ans=[]
while(True):
    a=[int(i) for i in a]
    b=input().split()
    b=[int(i) for i in b]
    c=list(itertools.combinations(b,2))
    for i in range(len(c)):
        if cnt<=c[i][0]+c[i][1] and c[i][0]+c[i][1]<=a[1]:
            cnt=c[i][0]+c[i][1]
    if cnt==0:
      ans.append("NONE")
    else:
      ans.append(cnt)
    a=input().split()
    if(a[0]=='0' and a[1]=='0'):
      break
    cnt=0
for i in range(len(ans)):
  print(ans[i])   


Measured memory_bytes: 49760
import java.util.Scanner;

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

		int N = scan.nextInt();
		int AC = 0;
		int WA = 0;
		int TLE = 0;
		int RE = 0;
		String b;

		for(int i = 0;i < N;i++) {
			switch(b = scan.next()) {
			case "AC":
				AC++;
				break;
			case "WA":
				WA++;
				break;
			case "TLE":
				TLE++;
				break;
			case "RE":
				RE++;
				break;
			}
		}

		System.out.println("AC x " + AC);
		System.out.println("WA x " + WA);
		System.out.println("TLE x " + TLE);
		System.out.println("RE x " + RE);
	}
}

Measured memory_bytes: 48772
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, M;
vector<int> e[100000];

int cost[100000];
queue<int> que;

signed main(){
	cin >> N >> M;
	rep(i, M){
		int A, B;
		cin >> A >> B;
		e[A-1].pb(B-1);
		e[B-1].pb(A-1);
	}

	rep(i, N) cost[i] = INT_MAX;
	cost[0] = 0;
	que.push(0);
	while(!que.empty()){
		int n = que.front();
		que.pop();
		rep(i, e[n].size()){
			if(cost[e[n][i]] > cost[n]+1){
				cost[e[n][i]] = cost[n]+1;
				que.push(e[n][i]);
			}
		}
	}

	cout << "Yes" << endl;
	rep(i, N){
		if(i == 0) continue;
		rep(j, e[i].size()){
			if(cost[e[i][j]]+1 == cost[i]){
				cout << e[i][j]+1 << endl;
				break;
			}
		}
	}
}

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

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    string s;
    cin >> s;
    string f, b;
    int q;
    cin >> q;
    int rv = 0;
    rep(i, q)
    {
        int x;
        cin >> x;
        if (x == 1)
            rv = 1 - rv;
        else if(x == 2) {
            int ff;
            char c;
            cin >> ff >> c;
            if(rv) {
                if(ff == 1) b += c;
                else f += c;
            } else {
                if(ff == 1) f += c;
                else b += c;
            }
        }
    }
    string ans;
    if(rv) {
        reverse(all(b));
        reverse(all(s));
        cout << b << s << f << endl;
    }
    else {
        reverse(all(f));
        cout << f << s << b << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct UnionFind{
  vi data;
  UnionFind(int N): data(N,-1) {}

  int find(int x){
    if (data[x]<0){return x;}
    else{return find(data[x]);}
  }
  
  void unite(int x, int y){
    x=find(x);y=find(y);
    if(data[x]>data[y]){swap(x,y);}
    data[x]+=data[y];
    data[y]=x;
  }

  int size(int x){return -data[find(x)];}
};

int main(){
  int N,M;cin>>N>>M;
  vi A, B;
  
  for (int i=0;i<M;++i){
    int a,b;cin>>a>>b;
    A.push_back(a-1);B.push_back(b-1);
  }

  UnionFind uf(N);

  vll ans(M);
  ll inconvenience=(ll)N*(N-1)/2;
  
  for (int i=M-1;i>=0;--i){
    ans[i]=inconvenience;
    int ra=uf.find(A[i]);int rb=uf.find(B[i]);
    if (ra!=rb){
      int sa=uf.size(A[i]);int sb=uf.size(B[i]);
      inconvenience+=(ll)sa*(sa-1)/2+(ll)sb*(sb-1)/2;
      uf.unite(A[i], B[i]);
      int s=uf.size(A[i]);
      inconvenience-=(ll)s*(s-1)/2;
    }
  }

  for (int i=0;i<M;++i){
    cout << ans[i] << endl;
  }
  return 0;
}

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

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n,m;
    cin >> n >> m;
    if(!n&&!m) return 0;
    vector<int> len;
    len.assign(11,0);
    REP(i,n){
      int d,p;
      cin >> d >> p;
      len[p]+=d;
    }
    for(int i=10;i>0;i--){
      int g=min(m,len[i]);
      m-=g;
      len[i]-=g;
    }
    int answer=0;
    REP(i,11) answer+=len[i]*i;
    cout << answer << endl;
  }
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, s;

int main() {
	cin >> n;
	repst(i,1,n) {
		s += i;
		if (s>=n) {
			repst(j,1,i) {
				if (j==s-n) continue;
				cout << j << ln;
			}
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

	int a[3] = {0,0,0};
	int b,c;

	for(int i = 0; i < 10; i++){
		scanf("%d", &b);
		for(int j = 2; j >= 0; j--){
			if(a[j] < b){
				c = a[j];
				a[j] = b;
				b = c;
			}
		}
	}
	for(int i = 2; i >= 0; i--)
		printf("%d\n", a[i]);


return 0;
}

Measured memory_bytes: 0
n = int(input())
s = input()
C = [0]*(n)
C[0] = 1 if s[0]=="E" else 0
for i in range(1,n):
    C[i] = C[i-1] + (1 if s[i]=="E" else 0)
ans = n
for i in range(n):
    l = i - C[i-1] if i >0 else 0
    r = C[-1] - C[i] if i < n-1 else 0
    tmp =  l + r
    ans =min(ans,tmp)
print(ans)

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n;
	cin >> n;
	int a[n+1];
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (a[i]==i) {
			ans++;
			int tmp = a[i];
			a[i] = a[i+1];
			a[i+1] = tmp;
		}
	}
	if (a[n]==n) {
		ans++;
		int tmp = a[n];
		a[n] = a[n-1];
		a[n-1] = tmp;
	}
	cout << ans << "\n";
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define pb push_back
#define eb emplace_back
const  int MAX=1000000;

int main()
{
   ll t;

   t=1;

   while(t--)
   {


       ll x,n;

       cin>>x>>n;

       map<ll,ll>m;

       while(n--)
       {
           ll a;
           cin>>a;
           m[a]=1;
       }
       ll i=x-1;
       ll j=x+1;
       while(1)
       {
           if(m[x]==0)
           {
               cout<<x<<endl;
               break;
           }
           if(m[i]==0)
           {
               cout<<i<<endl;
               break;
           }
           if(m[j]==0)
           {
               cout<<j<<endl;
               break;
           }
           i--;
           j++;

       }







   }

    }











Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	const int ms = 100100;
	std::vector<int> ans(ms, 0);
	long long sum = 0;
	while(n--) {
		int x;
		std::cin >> x;
		ans[x]++;
		sum += x;
	}
	std::cin >> n;
	while(n--) {
		int a, b;
		std::cin >> a >> b;
		ans[b] += ans[a];
		sum += (b - a) * (long long) ans[a];
		ans[a] = 0;
		std::cout << sum << '\n';
	}
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int k;
    cin >> k;

    set<ll> st;

    FOR(i, 1, 10) st.insert((ll) i);
    while(st.size() < k) {
        set<ll> st2;
        for(ll a : st) {
            ll d = a % 10;
            st2.insert(a);
            st2.insert(10*a + d);
            if(d > 0) st2.insert(10*a + d - 1);
            if(d < 9) st2.insert(10*a + d + 1);
        }
        st = st2;
    }

    auto itr = st.begin();
    REP(i, k-1) itr++;
    cout << *itr << endl;
    return 0;
}


Measured memory_bytes: 18944
#include<stdio.h>

int main(){
		int n,m,i,j,ab[50][2],ans[51]={0};
		scanf("%d%d",&n,&m);
		for(i=0;i<m;i++)scanf("%d%d",&ab[i][0],&ab[i][1]);
		for(j=1;j<=n;j++){
				for(i=0;i<m;i++){
						if(ab[i][0]==j||ab[i][1]==j)ans[j]++;
				}
		}
		for(i=1;i<=n;i++)printf("%d\n",ans[i]);
		return 0;
}


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

constexpr int INF = 1e9;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int maxa = -INF, mina = INF;
    for (auto& e : a) cin >> e, maxa = max(maxa, e), mina = min(mina, e);

    int ans = INF;
    for (int i = mina; i <= maxa; i++) {
        int can = 0;
        for (auto& e : a) can += pow(e - i, 2);
        ans = min(ans, can);
    }

    cout << ans << endl;
}


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

int main()
{
	while (1) {
		int a;
		cin >> a;
		if (a == 0)break;
		vector<int>s(10);
		for (int b = 0; b < a; b++)
		{
			int c;
			cin >> c;
			s[c]++;
		}
		for (int e : s) {
			if (e == 0)cout << '-' << endl;
			else {
				for (int f = 0; f < e; f++) {
					cout << '*';
				}
				cout << endl;
			}
		}
	}
}

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

int main(void) {
  int n;
  cin >> n;
  vector<vector<int>> as(n, vector<int>(2));
  for (vector<int> &a : as) {
    cin >> a[0];
    a[1] = -1;
  }

  int index = 0;
  int cost = 0;
  for (int i = 0; i < n; i++) {
    // as[index]のcostがすでに入力されていたら閉路なので終了
    if (as.at(index).at(1) > -1) { break; }

    as.at(index).at(1) = cost;
    index = as.at(index).at(0) - 1;
    cost++;
  }

  cout << as.at(1).at(1) << endl;
  return 0;
}

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

using namespace std;

int main () {

	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;

	if (a1 + a2 + a3 >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    string s, t;
    cin >> s >> t;
    map<char, char> m1;
    map<char, char> m2;
    rep(i, int(s.size())) {
        if (m1.find(s[i]) == m1.end() && m2.find(t[i]) == m2.end()) {
            m1[s[i]] = t[i];
            m2[t[i]] = s[i];
        }
        else if (m1[s[i]] != t[i] || m2[t[i]] != s[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  ll ans = 1;
  while(ans * 2 <= n){
    ans *= 2;
  }
  cout << ans << endl;
}

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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll i,j,n,m,k,cnt=0,ans=0,t=1;
    ll a,b;
    cin>>a>>b;
    if(abs(a-b)%2==0){
        cout<<(a+b)/2;
    }    
    else ret("IMPOSSIBLE")
    
    return 0;
}

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

int main() {
	int n, k;
	int a[100001];

	cin >> n >> k;

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

	if ((n - 1) % (k - 1) == 0) {
		cout << (n - 1) / (k - 1) << endl;
	} else {
		cout << (n - 1) / (k - 1) + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
# define ll int
#define mmm 1000000007
#define pb push_back

									//nestedcode

 int main(){
   ios::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   ll a,b;
  	cin>>a>>b;
  	
  	if(a != 1 && b != 1){
  		cout<<1<<endl;
	  }
	  	if(a != 2 && b != 2){
  		cout<<2<<endl;
	  }
	  	if(a != 3 && b != 3){
  		cout<<3<<endl;
	  }
  
 }   

Measured memory_bytes: 256
n=int(input())
l = [input() for i in range(n)] 

ac = 0
wa = 0
tle = 0
re = 0

for i in l:
    if i == 'AC':
        ac += 1
    if i == 'WA':
        wa += 1
    if i == 'TLE':
        tle += 1
    if i == 'RE':
        re += 1

print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))

Measured memory_bytes: 16064
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;

long long N, X[1009], Y[1009], H[1009]; vector<tuple<long long, long long, long long>>vec;

int main() {
	cin >> N; tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j); V = max(V, 0LL); bool flag = true;
			for (int k = 1; k <= N; k++) {
				long long VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV, 0LL);
				if (H[k] != VV) flag = false;
			}
			if (flag == true) vec.push_back(make_tuple(i, j, V));
		}
	}
	if (vec.size() == 1) {
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
	}
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int INF=1001001001;
const int MOD=1000000007;


int main() {
  int n,p;

  string s;
  cin>>n>>p>>s;
  //cout<<a%p<<'k';
  ll ans=0;
  vector<int>v(n+1,0);
  map <int,int>mp;
//  priority_queue <int>q;
  if (10%p==0){
    rep(i,n){
      if ((s[i]-'0')%p==0)ans+=i+1;
    }
    cout<<ans;
    return 0;
  }
  else{
    int fac=1;
    mp[0]=1;
    for(int i=n-1;i>=0;i--){
      int s1=s[i]-'0';
      int now=s1%p;

  //    cout<<p<<'p'<<endl;


  //    cout<<s1<<'s'<<s1%11<<'n'<<endl;
      v[i]=v[i+1]+(now*fac)%p;
      v[i]=v[i]%p;
  //    cout<<v[i]<<endl;

     ans+=mp[v[i]];
     mp[v[i]]++;

      


      fac*=10;

      fac=fac%p;
    }
  }


  cout<<ans;

  }


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(ll i = (k); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pll;

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}

int main(){
    ll x;
    cin>>x;
    vector<ll> dp(0);
    int i=0;
    while(true){
        ll bb = pow(i,5);
        dp.push_back(bb);
        if(binary_search(all(dp),x-bb)){
            int a = lower_bound(dp.begin(),dp.end(),x-bb)-dp.begin();
            cout<<i<<" "<<-a<<endl;
            return 0;
        }
        else if(binary_search(all(dp),bb-x)){
            int b = lower_bound(dp.begin(),dp.end(),bb-x)-dp.begin();
            cout<<i<<" "<<b<<endl;
            return 0;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 4112
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val t = sc.nextInt

  val tl = Vector.fill(n)(sc.nextInt)

  val res = tl.tail.foldLeft(0, tl.head){case ( (sum, preT), tt) =>
    (sum + ( if(tt - preT >=  t) t else tt - preT ), tt)
  }._1 + t

  println(res)
}

Measured memory_bytes: 75508
#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
const long long mod = 1e9 + 7;
int h, w;
long long mem[N][N];
bool vis[N][N];
char mat[N][N];

long long dp(int i, int j) {
	if (i == h && j == w) {
		return 1;
	}
	if (vis[i][j]) {
		return mem[i][j];
	}
	vis[i][j] = true;
	long long ans = 0;

	if (i < h && mat[i + 1][j] == '.') {
		ans = (ans + dp(i + 1, j)) % mod;
	}

	if (j < w && mat[i][j + 1] == '.') {
		ans = (ans + dp(i, j + 1)) % mod;
	}

	return mem[i][j] = ans;
}

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

	cin >> h >> w;

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> mat[i][j];
		}
	}

	cout << dp(1, 1) << '\n';

	return 0;
}


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

int main()
{
	int h1,h2,w1,w2,a1,a2,a3,a4;
	cin >> h1 >> w1;
	
	cin >> h2 >> w2;
	a1 = h1 * w1;
	a2 = h2 * w1; 
	a3 = h1 * w2;
	a4 = h2 * w2;
	h1 = a1 - a2 - a3 + a4;
	cout << h1;
	return 0;
} 
	 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<functional>
#include<map>
using namespace std;
typedef long long ll;
#define lscan(x) scanf("%I64d",&x);
#define lprint(x) printf("%I64d",x);
ll gcd(ll a, ll b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) {
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

ll M = 1000000007;

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll mpow2(ll x, ll n, ll mod) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 1000000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
	}
	ifac[1000000] = mpow(fac[1000000], M - 2);
	for (ll i = 1000000; i > 0; i--) {
		ifac[i - 1] = ifac[i] * i%M;
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
ll perm(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	return fac[a] * ifac[a - b] % M;
}
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}

vector<vector<ll>> li(222222);
int main() {
	ll a,b,k;
  cin>>a>>b>>k;
  if(k>a){
    k-=a;
    a=0;
  }
  else{
    a-=k;
    k=0;
  }
  if(k>b){
    k-=b;
    b=0;
  }
  else{
    b-=k;
    k=0;
  }
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 21120
#include <iostream>
#include <string>

std::string S;
std::string T;

int main(void) {

	std::cin >> S;
	std::cin >> T;

	bool pass = false;
	int len = (int)S.size();
	char tc = T[0];
	for (int i = 0; i < len; i++) {
		if (S[i] == tc) {
			pass = true;
			for (int j = 0; j < len; j++) {
				int offset = i + j;
				if (offset >= len) {
					offset -= len;
				}
				if (T[j] != S[offset]) {
					pass = false;
					break;
				}
			}
			if (pass) {
				break;
			}
		}
	}

	std::cout << (pass ? "Yes": "No") << std::endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 1e6 + 5;
int arr[N];

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rw", stdin);
#endif
	int n, k;
	cin >> n >> k;
	ll total = 0;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	for (int i = 0; i < k; ++i) {
		total += arr[i];
	}
	cout << total;
	return 0;
}


Measured memory_bytes: 3660
n, k = map(int, input().split())

hn = list( map(int, input().split()) )

#print (hn)

tab = [0]*n

tab[0] = 0

if n>k+1:

    for i in range(1,k+1):
        tab[i] = abs( hn[i]-hn[0])
#       print(tab[i])

#    print("Initialized")

    for i in range(k+1,n):
        t = 100000000000+1 # > 10^4

        for ki in range(1,k+1):
            tt = abs(hn[i] - hn[i-ki]) + tab[i-ki]
            t = min(t, tt)
#            print((i,ki,tt))

        tab[i] = t
    
    print(tab[-1])

else:
    print( abs(hn[-1] - hn[0]) )


    


Measured memory_bytes: 52448
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct UnionFind{
  vector<int64_t> S;
  vector<int64_t> weight;
  
  UnionFind(int N){
    S = vector<int64_t>(N,0);
    weight = vector<int64_t>(N,1);
    for(int i = 0 ; i < N ; i++){
      S.at(i) = i;
      weight.at(i) = 1;
    }
  }
  
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(S.at(x) == x){
     return x; 
    }
    return S.at(x) = root(S.at(x));
  }
  
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    //cout << rx << ":" << ry <<endl;
    if (rx == ry){
      return;
    }
    if (S.at(x) > S.at(y)){
      swap(x, y);
    }
    //cout << x << ":" << y <<endl;
    weight.at(S.at(x)) += weight.at(S.at(y));
    S.at(y) = S.at(x);
    return; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  
  int size(int x){
    return weight.at(x);
  }
  
  //bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    //int rx = root(x);
    //int ry = root(y);
    //return rx == ry;
  //}
  
};

int main(){//main_program
  int x;
  cin >>x;
  if(x== 1){
    cout << "0" <<endl;
  }else{
    cout << "1" <<endl;
  }
  
  
}


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

const ll MOD = 1e9 + 7;

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

    int n,m;
    cin >> n >> m;


    vector<ll> dp(n+2,-1);

    for(int i = 0; i < m; i++) {
        int a;
        cin >> a;
        dp[a] = 0;
    }

    dp[0] = 1;
    if(dp[1] == 0);
    else dp[1] = 1;

    for(int i = 2; i <= n; i++){
        if(dp[i] == -1) dp[i] = (dp[i-1] + dp[i-2]) % MOD;
    }

    cout << dp[n] << endl;

}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  int D,G;
  cin>>D>>G;
  vector<int> p(D),c(D);
  for(int i(0);i<D;i++){
    cin>>p[i]>>c[i];
  }
    /*  0000
        1000
        0100
        1100
        0010 */
  int ans(1e9);
  for(int bit(0);bit<(1<<D);bit++){
    int tmp(0),cnt(0),maxi(0);
    for(int i(0);i<D;i++){
      if (((bit>>i) & 1)){
        tmp += p[i]*(i+1)*100 + c[i];
        cnt += p[i];
      }else{
        maxi = (i+1)*100;
      }
    }
    bool flag = true;
    if(tmp < G){
      int sa = G - tmp;
      int cnti = (sa+maxi-1)/maxi;
      if(cnti >= p[maxi/100-1]) flag = false;
      cnt+=cnti;
    }
    if(flag) ans = min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256