akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <iomanip>
#define FI first
#define SE second
#define EB emplace_back
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 1100000000
#define LLINF 1100000000000000000LL
#define Decimal fixed << setprecision(20)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v, sz) for(int i = 0; i < sz; i++) cerr << v[i] << ' '; cerr << endl;
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWP(p) cerr << "[" << p.first << ',' << p.second << "]";

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

bool check(ll K, ll X, vector<ll>& A, vector<ll>& F) {
  // whether Ai * Fi <= X
  vector<ll> v;
  auto op = [&](ll a, ll f) {
    return max(0LL, a - X/f);
  };
  transform(ALL(A), F.begin(), back_inserter(v), op);
  return accumulate(ALL(v), 0LL) <= K;
}

int main()
{
  ll N, K; cin >> N >> K;
  vector<ll> A(N), F(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> F[i];

  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());

  ll l = -1, r = 1100000000000000000;
  while (r - l > 1) {
    ll mid = (l + r) / 2;
    if (check(K, mid, A, F)) r = mid;
    else l = mid;
  }
  cout << r << endl;

  return 0;
}

Measured memory_bytes: 7616
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")
    };
}
use std::collections::HashSet;
fn main() {
    input! {
        x: usize,
    }
    let mut res = 1;
    for i in 2..100 {
        let mut y = i * i;
        while y <= x {
            res = std::cmp::max(res, y);
            y *= i;
        }
    }

    println!("{}", res);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

Int N, X;
struct elem {
  Int L, U, B;
  Int val(Int x) const {
    return L * min(B, x) + U * max(0LL, x - B);
  }
  Int tot() const {
    return val(X);
  }
  Int lb(Int y) const {
    if (tot() < y) return INFLL;
    if (y <= 0) return 0;
    Int lo = 0, hi = X;
    while (hi - lo > 1) {
      const Int mid = (hi + lo) / 2;
      if (val(mid) >= y) {
        hi = mid;
      } else {
        lo = mid;
      }
    }
    return hi;
  }
} E[100050];

int main() {
  N = in();
  X = in();

  Int goal = 0;
  for (int i = 0; i < N; ++i) {
    E[i].B = in();
    E[i].L = in();
    E[i].U = in();
    goal += E[i].B * E[i].L;
  }
  if (goal == 0) {
    puts("0");
    return 0;
  }

  sort(E, E + N, [=] (const elem& a, const elem& b) {
    return a.tot() > b.tot();
  });

  Int alls = 0;
  Int csum = 0;
  for (int i = 0; i < N; ++i) {
    csum += E[i].tot();
    if (csum >= goal) {
      alls = i + 1;
      break;
    }
  }
  Int res = alls * X;

  for (int i = 0; i < alls; ++i) {
    Int rsum = csum - E[i].tot();
    chmin(res, (alls - 1) * X + E[i].lb(goal - rsum));
  }

  --alls;
  csum -= E[alls].tot();
  for (int i = alls + 1; i < N; ++i) {
    while (csum + E[i].tot() < goal) {
      csum += E[alls].tot();
      ++alls;
    }
    chmin(res, alls * X + E[i].lb(goal - csum));
  }

  printf("%lld\n", res);

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <valarray>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using Wbool = std::vector<Vbool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define DEBUG(x) std::cerr << #x << " = " << x << '\n';
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
#define rSORT(A) std::sort((A).rbegin(), (A).rend())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){if(a < b) a = b;}
template <class T> inline void chmin(T &a, T b){if(a > b) a = b;}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1LL << k;}
inline int toInt(const string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res;
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




int main(void){
  int n, k; cin >> n >> k;
  cout << n - k + 1 << BR; 
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

	char X, Y;
	cin >> X >> Y;

	if ( X > Y ) cout << ">" << endl;
	else if (X == Y) cout << "=" << endl;
	else cout << "<" << endl;



	return 0;
}

Measured memory_bytes: 256
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)

n,m=map(int,stdin.readline().rstrip().split())
s=[list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
c=[]
ans=0
for i in s:
    c.append(i[0])
    i.pop(0)
p=[int(i) for i in stdin.readline().rstrip().split()]
cnt=0
for i in range(2**n):
    ch=True
    r=bin(i)[2:].zfill(n)[::-1]
    for j in range(m):
        cnt=0
        for k in range(c[j]):
            if r[s[j][k]-1]=="1":
                cnt+=1
        if cnt%2!=p[j]:
            ch=False
            break
    if ch:
        ans+=1
print(ans)

Measured memory_bytes: 41200
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S;
	int X[3] = {};
	cin >> S;
	for (int i = 0; i < S.size(); i++) X[S[i] - 'a']++;
	sort(X, X + 3);
	if (X[2] - X[0] <= 1) cout << "YES";
	else cout << "NO";
}

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

int main(void)
{
	char str[100][21];
	char search_word[11];
	char ring_str[11];
	int i, n;
	int ans;
	
	scanf("%s", search_word);
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%s", ring_str);
		strcpy(str[i], ring_str);
		strcat(str[i], ring_str);
	}
	
	ans = 0;
	for (i = 0; i < n; i++){
		if (strstr(str[i], search_word) != NULL){
			ans++;
		}
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define PI 3.141592653589793238
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(int i=0;i<(int)v.size();i++) cout<<" "<<v[i]; cout<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){ 
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	int n,m;
	cin>>n>>m;
	vector<int>a[n+1];
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		a[x].pb(y);
		a[y].pb(x);
	}
	queue<int>q;
	int lev[n+1]={0};
	q.push(1);
	int vis[n+1]={0};
	vis[1]=1;
	while(!q.empty()){
		int p=q.front();
		q.pop();
		for(auto x:a[p]){
			if(!vis[x]){
				lev[x]=p;
				q.push(x);
				vis[x]=1;
			}
		}
	}
	int f=0;
	for(int i=2;i<=n;i++){
		if(!lev[i])
			f=1;
	}
	if(f)
		cout<<"No\n";
	else
	{
		cout<<"Yes\n";
		for(int i=2;i<=n;i++)cout<<lev[i]<<endl;
	}
			
}


Measured memory_bytes: 10940
#include <stdio.h>


struct card {
  char pattern;
  int number;
};

int main(){
  int N,i,j,min,flg=0;
  struct card card1[36],card2[36],tmp;
  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf(" %c%d",&card1[i].pattern,&card1[i].number);
    //printf("%c %d\n",card[i].pattern,card[i].number);
  }
  for(i=0;i<N;i++){
    card2[i]=card1[i];
  }
  
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(card1[j].number < card1[j-1].number){
	tmp=card1[j];
	card1[j]=card1[j-1];
	card1[j-1]=tmp;
      }
    }
  }
    for(i=0;i<N;i++){
      if(i>0)printf(" ");
      printf("%c%d",card1[i].pattern,card1[i].number);
    }
    printf("\n");

    printf("Stable\n");
    
    for(i=0;i<N;i++){
      min = i;
      for(j=i;j<N;j++){
	if(card2[j].number < card2[min].number) min=j;
      }
      tmp=card2[i];
      card2[i]=card2[min];
      card2[min]=tmp;
    }
    for(i=0;i<N;i++){
      if(i>0)printf(" ");
      printf("%c%d",card2[i].pattern,card2[i].number);
    }
    printf("\n");

    for(i=0;i<N;i++){
      if(card1[i].number != card2[i].number || card1[i].pattern != card2[i].pattern){
	flg=1;
      }
    }
    if(flg==0){
      printf("Stable\n");
    }else{
      printf("Not stable\n");
    }
    return 0;
  }

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

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

class modInt{
    ll value;
    static const ll mod = 1000000007;

public:
    modInt(ll x=0): value{x % mod}{}

    inline modInt& operator+=(modInt x){
        value = (value + x.value) % mod;
        return *this;
    }

    inline modInt& operator-=(modInt x){
        value = (value + mod - x.value) % mod;
        return *this;
    }

    inline modInt& operator*=(modInt x){
        value = (value * x.value) % mod;
        return *this;
    }


    inline modInt operator/=(modInt x){
        *this *= x.inv();
        return *this;
    }

    inline modInt pow(modInt x, int n){
        modInt res = modInt(1LL);
        while(n > 0){
            if(n & 1)   res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }

    inline modInt inv(){
        modInt res = pow(value, mod-2);
        return res;
    }

    inline ll get(){
        return value;
    }
};

modInt operator+(modInt x, modInt y){
    return x += y;
}

modInt operator-(modInt x, modInt y){
    return x -= y;
}

modInt operator*(modInt x, modInt y){
    return x *= y;
}

modInt operator/(modInt x, modInt y){
    return x /= y;
}

ostream& operator<<(ostream& os, modInt x){
    return os << x.get();
}


class modIntCombinations{
    vector<modInt> factArray;

    void make_fact(ll x){
        for(auto i = factArray.size(); i <= x+1; i++){
            modInt y = factArray[i-1] * i;
            factArray.push_back(y);
        }
    }

public:
    modIntCombinations(){
        factArray.emplace_back(1);
    }

    modInt fact(ll x){
        if(factArray.size() < x+1){
            make_fact(x);
        }
        return factArray[x];
    }

    modInt comb(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k) / fact(n - k);
        }
    }

    modInt perm(ll n, ll k){
        if(n < k){
            return modInt{0};
        }
        else{
            return fact(n) / fact(k);
        }
    }
};


int main(){
    ll n, k;    cin >> n >> k;
    modInt res = 0;
    for(ll i = k; i <= n+1; i++){
        modInt ma = (2 * n - i + 1) * i / 2;
        modInt mi = i * (i-1) / 2;
        res += (ma - mi + 1);
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        int count[100001] = {0}, ans = 0;
        rep(i,n){
            int a, b;
            cin >> a >> b;
            a--; b--;
            range(j,a,b + 1){
                count[j]++;
            }
        }
        rep(i,n + 1) if(count[i] >= i && count[i] > ans) ans = i;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1560
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int MaxN = 2e5;
long long a[MaxN + 5];
int N;
long long T, x;

int main()
{
	long long flag = 0;
	scanf("%d %lld", &N, &T);
	for(int i = 1; i <= N; i++)
		scanf("%lld", &a[i]);
		for(int i = 1; i <= N; i++)
		{
			if(a[i] <= T)
			{
				flag = a[i];
				x = a[i];
			}
			else if(a[i] - a[i - 1] > T)
				x += T;
			else
				x += a[i] - a[i - 1];
		}
		printf("%lld\n", x + T);
		return 0;
}

Measured memory_bytes: 1664
import sys


# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

# ===CODE===
def main():
    n, m, z = map(int, input().split())
    ruisekiwa = [[0 for i in range(n + 1)] for j in range(n + 1)]

    d = []
    for i in range(m):
        l, r = map(int, input().split())
        ruisekiwa[r][l] += 1

    for i in range(n):
        for j in range(n):
            ruisekiwa[i + 1][j + 1] += ruisekiwa[i][j + 1] + ruisekiwa[i + 1][j] - ruisekiwa[i][j]

    for _ in range(z):
        p, q = map(int, sys.stdin.readline().split())
        ans = ruisekiwa[q][q] - ruisekiwa[p - 1][q] - ruisekiwa[q][p - 1] + ruisekiwa[p - 1][p - 1]
        print(ans)


if __name__ == '__main__':
    main()


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> p(N);
    REP(i, N) cin >> p[i];

    vector<ll> sum(N);
    sum[0] = p[0] + 1;
    REP(i, N - 1) sum[i + 1] = sum[i] + p[i + 1] + 1;
    ll ans = 0;
    REP(i, N - K + 1)
    {
        if (i == 0) ans = max(ans, sum[K - 1]);
        else ans = max(ans, sum[i + K - 1] - sum[i - 1]);
    }

    cout << fixed;
    cout << setprecision(10) <<  (double)ans / 2.0 << endl;
}


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

int main(){

  int num[36],A[36];
  char mar[36],Am[36];
  int N,i,j,boxi,flag = 0,minj,box;
  char boxc;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf(" %c%d",&mar[i],&num[i]);
  }

  for(i=0;i<N;i++){
    Am[i] = mar[i];
    A[i] = num[i];
  }
  
  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
            
      if(num[j]<num[j-1]){
	boxi = num[j];
	boxc = mar[j];
	num[j] = num[j-1];
	mar[j] = mar[j-1];
	num[j-1] = boxi;
	mar[j-1] = boxc;
      }
    }
  }
  for(i=0;i<N-1;i++){
    printf("%c%d ",mar[i],num[i]);
  }
  printf("%c%d\n",mar[i],num[i]);
  printf("Stable\n");


  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])
	minj = j;
    }
    if(i != minj){
      box = A[i];
      boxc = Am[i];      
      A[i] = A[minj];
      Am[i] = Am[minj];
      A[minj] = box;
      Am[minj] = boxc;
    }
  }

  for(i=0;i<N-1;i++){
    printf("%c%d ",Am[i],A[i]);
  }
  printf("%c%d\n",Am[i],A[i]);

  flag = 0;
  for(i=0;i<N;i++)
    if(Am[i]!=mar[i])flag=1;

  if(flag==1)printf("Not stable\n");
  else printf("Stable\n");
  
  return 0;
}

Measured memory_bytes: 608
import itertools as it
N=int(input())
W=list(range(1,N+1))
c1=-1
c2=-1
c=0
L=tuple(map(int,input().split()))
M=tuple(map(int,input().split()))
if L==M:
  print(0)
  exit()
for i in it.permutations(W,N):
  c+=1
  if i==L:
    c1=c
  elif i==M:
    c2=c
print(abs(c1-c2))

Measured memory_bytes: 9136
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

bool g[200][200];
bool tate[200];
bool same[200][200];
bool visited[200];
bool func(int a, int b, int n) {
  if (a==b) return 1;
  visited[a] = 1;
  REP(i,n) {
    if (g[a][i] && !visited[i] && func(i, b, n)) return 1;
  }
  return 0;
}

int main() {
  int n,m;
  while(cin >> n, n) {
    memset(g, 0, sizeof(g));
    map<string, int> id;
    int num = 0;
    UnionFind uf(n*4);
    REP(i, n) {
      string s;
      cin >> s;
      int p = s.find('-');
      string a = s.substr(0, p);
      string b = s.substr(p+1);
      if (id.count(a) == 0) id[a] = num++;
      if (id.count(b) == 0) id[b] = num++;
      g[id[a]][id[b]] = 1;
      uf.unionSet(id[a]*2, id[b]*2+1);
      uf.unionSet(id[a]*2+1, id[b]*2);
    }
    memset(same, 0, sizeof(same));
    REP(i, num) {
      REP(j, num) {
        if (i == j) continue;
        bool f1=0,f2=1;
        REP(k, num) {
          if (k==i||k==j) continue;
          if (g[i][k]&&g[j][k] || g[k][i]&&g[k][j]) f1 = 1;
          if (g[i][k]&&g[k][j] || g[k][i]&&g[j][k]) f2 = 0;
        }
        if (f1&&f2) {
          same[i][j] = 1;
          same[j][i] = 1;
        }
      }
    }
    REP(i, num) REP(j, num)
      g[i][j] |= same[i][j];
    // REP(i, num) {
    //   REP(j, num) {
    //     cout << g[i][j];
    //   }
    //   cout << endl;
    // }

    cout << num << endl;
    cin >> m;
    REP(i,m) {
      string s;
      cin >> s;
      int p = s.find('-');
      string a = s.substr(0, p);
      string b = s.substr(p+1);
      if (id.count(a) == 0 || id.count(b) == 0 || uf.findSet(id[a]*2, id[b]*2) || uf.findSet(id[a]*2+1, id[b]*2+1)) {
        cout << "NO" << endl;
        continue;
      }
      memset(visited,0,sizeof(visited));
      if (func(id[a], id[b], num)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
}

Measured memory_bytes: 1048
/*Author : Hrishi*/

/*When I wrote this, only God and I understood what I was doing.
Now, only God knows.*/

#include <bits/stdc++.h>

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define ff first
#define ss second
#define PB push_back
#define F(i,L,R) for(auto i=L; i<R ;i++)
#define FR(i,R,L) for(auto i=R;i>L;i--)
#define all(x) (x).begin(),(x).end()
#define show(x) cout<<(#x)<<" = "<<(x)<<"\n";
#define show2(x,y) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<"\n";
#define show3(x,y,z) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<" & "<<(#z)<<" = "<<(z)<<"\n";
#define endln "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define M 1000000007
#define INT_MAX 2147483647

using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
    fastio;
    ll n,d;
    cin>>n>>d;
	    ll ans = 0;
    d = d*d;
    while(n--)
    {
    ll a,b;
    cin>>a>>b;

        a = a*a;
        b = b*b;

        if(d-a>=b)
            ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3648
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)
input=sys.stdin.readline


N = int(input())
par = {i:[] for i in range(1, N+1)}

for i in range(2, N+1):
    a = int(input())
    par[a].append(i)

@lru_cache(maxsize=None)
def dfs(s):
    depth = 1
    res = []
    for t in par[s]:
        res.append(dfs(t))
    res.sort(reverse=True)
    for i, j in enumerate(res, start=1):
        depth = max(depth, i+j)
    return depth

print(dfs(1)-1)

Measured memory_bytes: 162848
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
ll t[1000000];
ll a[1000000];
ll h[1000000];
ll sum=1;
ll amax,tmax;

int main(){
  cin>>n;
  rep(i,n){
    cin>>t[i];
    tmax = max(tmax,t[i]);
  }
  rep(i,n){
    cin>>a[i];
    amax = max(amax,a[i]);
  }

  h[0]=t[0];
  h[n-1]=a[n-1];

  rep(i,n){
    if(t[i]<t[i+1])
      h[i+1]=t[i+1];
  }
  rep(i,n){
    if(a[i]>a[i+1]){
      h[i]=a[i];
    }
  }

  rep(i,n){
    if(h[i]<a[i]&&h[i]<t[i]){
      sum*=min(a[i],t[i]);
      sum%=M;
    }
    if(h[i]==t[i]&&h[i]>a[i]||h[i]==a[i]&&h[i]>t[i]){
      cout<<0<<endl;
      return 0;
    }
  }
  if(tmax!=amax){
    cout<<0<<endl;
    return 0;
  }
  
  cout<<sum<<endl;



  return 0;
}




Measured memory_bytes: 9216
n = gets.to_i
s = gets.chomp

result = s.count("R") * s.count("G") * s.count("B")

i = 0

while i < n
  j = i + 1
  while j < n
    k = 2 * j - i
    if j < k && k < n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
      result -= 1
    end
    j += 1
  end
  i += 1
end

puts result

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

using namespace std;

int main() {
    int n;
    cin >> n;
    long long ans = 0LL;
    int mx;
    cin >> mx;
    for (int i = 1; i < n; ++i) {
        int x;
        cin >> x;
        ans += max(0, mx - x);
        mx = max(x, mx);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3588
x = int(input())

if x >= 4000:
    print(1)
else:
    found = False
    for i0 in range(x // 100 + 1):
        if found:
            break
        for i1 in range(x // 101 + 1):
            if found:
                break
            for i2 in range(x // 102 + 1):
                if found:
                    break
                for i3 in range(x // 103 + 1):
                    if found:
                        break
                    for i4 in range(x // 104 + 1):
                        p = x - (i0 * 100 + i1 * 101 + i2 * 102 + i3 * 103 + i4 * 104)
                        if p >= 0 and p % 105 == 0:
                            print(1)
                            found = True
                            break
    if not found:
        print(0)


Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

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

		// 入力値の取得
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		long[] H = new long[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextLong();
		}
		
		Map<Integer, Set<Integer>> routes = new HashMap<>();
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			
			if (routes.get(A) == null) {
				Set<Integer> route = new HashSet<>();
				route.add(B);
				routes.put(A, route);
			}
			else {
				routes.get(A).add(B);
			}
			
			if (routes.get(B) == null) {
				Set<Integer> route = new HashSet<>();
				route.add(A);
				routes.put(B, route);
			}
			else {
				routes.get(B).add(A);
			}
		}

		// 結果の出力
		int count = 0;
		for (int i = 1; i <= N; i++) {
			if (routes.get(i) == null) {
				count++;
			}
			else {
				boolean goodObservatory = true;
				for (int j : routes.get(i)) {
					if (H[i-1] <= H[j-1]) {
						goodObservatory = false;
						break;
					}
				}
				if (goodObservatory) {
					count++;
				}
			}
		}
		
		System.out.println(count);

		sc.close();
	}
}


Measured memory_bytes: 86848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest.cs
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = ReadIntList()[0];
			int sum = 0;
			int temp = n;
			while(temp != 0)
			{
				sum += temp % 10;
				temp /= 10;
			}
			string ans;
			if(n%sum == 0)
			{
				ans = "Yes";
			}
			else
			{
				ans = "No";
			}
			Console.WriteLine(ans);
		}

		static string[] ReadStr()
		{
			return Console.ReadLine().Split(' ').ToArray();

		}

		static int[] ReadIntList()
		{
			return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
		}
	}
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>//小数精度 	cout << fixed << setprecision(5) << tmp << endl;
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define All(X)      (X).begin(),(X).end()

int n,w;
int dp[101][100001];
int val[101];
int wei[101];
int rec(int i,int j){
  if(dp[i][j] >= 0) return dp[i][j];
  int res;
  if(i==n){
    res = 0;
  }else if(j<wei[i]){
    res = rec(i+1,j);
  }else{
    res = max(rec(i+1,j),rec(i,j-wei[i]) + val[i]);
  }
  return dp[i][j] = res;
}

int main(){

  cin >> n >> w;
  REP(i,n) cin >> val[i] >> wei[i];

  memset(dp,-1,sizeof(dp));
  cout << rec(0,w) <<endl;
  return 0;
}

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

import static java.lang.System.in;

class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String[] buf = reader.readLine().split(" ");
        int n = Integer.parseInt(buf[0]), K = Integer.parseInt(buf[1]), L = Integer.parseInt(buf[2]);
        int[] idRoad = new int[n+1], idRail = new int[n+1];;
        for(int i=1;i<=n;i++) idRoad[i]=idRail[i]=i;
        for(int i=0;i<K+L;i++){
            buf = reader.readLine().split(" ");
            int p = Integer.parseInt(buf[0]), q = Integer.parseInt(buf[1]);
            if(i<K) union(p,q,idRoad);
            else union(p,q,idRail);
        }
        HashMap<String,Integer> rec = new HashMap<>();
        for(int i=1;i<=n;i++){
            String key = getKey(i,idRoad,idRail);
            rec.put(key,rec.getOrDefault(key,0)+1);
        }
        PrintWriter out = new PrintWriter(System.out);
        for(int i=1;i<=n;i++){
            String key = getKey(i,idRoad,idRail);
            out.print(rec.get(key));
            out.print(" ");
        }
        out.flush();
    }
    static String getKey(int i, int[] idRoad, int[] idRail){
        return Integer.toString(find(i,idRoad))+" "+Integer.toString(find(i,idRail));
    }
    static int find(int p, int[] id){
        while(p!=id[p]){
            id[p] = id[id[p]];
            p = id[p];
        }
        return p;
    }
    static void union(int p, int q, int[] id){
        int i = find(p, id), j = find(q, id);
        if(i==j) return;
        id[j] = i;
    }
}


Measured memory_bytes: 110212
function Main(input) {
	input = input.trim();
  var H = parseInt(input.split("\n")[0].split(" ")[0]);
  var W = parseInt(input.split("\n")[0].split(" ")[1]);
  var h = parseInt(input.split("\n")[1].split(" ")[0]);
  var w = parseInt(input.split("\n")[1].split(" ")[1]);
  console.log((H - h) * (W - w));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {
        String line = readLine();
        StringTokenizer st = new StringTokenizer(line, "");
        String s = (String)st.nextToken();

        String[] strArray = s.split("");
        String a = strArray[0];
        String b = strArray[1];
        String c = strArray[2];
        if ((a.equals(b))||(a.equals(c))||(b.equals(c))) {
        	System.out.println("No");
        }else {
        	System.out.println("Yes");
        }

    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }

}

Measured memory_bytes: 21204
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
int main() {
	int n;
	while (cin >> n, n) {
		string a[1000];
		rep(i, n) {
			cin >> a[i];
		}
		bool f = false;
		rep(i, n - 1) {
			if (a[i] == a[i + 1] && a[i] == "x")f = true;
			if (a[i] != "x"&&a[i + 1] != "x") {
				if (i % 2 && stoi(a[i]) <= stoi(a[i + 1]))f = true;
				else if (i % 2 == 0 && stoi(a[i]) >= stoi(a[i + 1]))f = true;
			}
		}
		if (f) {
			cout << "none" << endl;
			continue;
		}
		int le = (int)-MOD; int ri = (int)MOD;
		rep(i, n) {
			if (a[i] == "x") {
				if (i % 2) {
					if (i - 1 >= 0) {
						le = max(le, stoi(a[i - 1]) + 1);
					}
					if(i+1<n){
						le = max(le, stoi(a[i + 1]) + 1);
					}
				}
				else {
					if (i - 1 >= 0) {
						ri = min(ri, stoi(a[i - 1]) - 1);
					}
					if (i + 1 < n) {
						ri = min(ri, stoi(a[i + 1]) - 1);
					}
				}
			}
		}
		if (ri - le == 0) {
			cout << ri << endl;
		}
		else if (ri > le) {
			cout << "ambiguous" << endl;
		}
		else {
			cout << "none" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3156
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

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

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int d[101][101];
int know[101];
int main(){
	int n;
	while(cin>>n,n){
		for(int i = 0;i <=n;i++){
			for(int j = 0;j <=n;j++){
				d[i][j] =0;
			}
		}
		for(int i = 1;i <=n;i++){
			int m;
			cin>>m;
			for(int j = 0;j < m;j++){
				int k;
				cin>>k;
				d[i][k] = 1;
			}
		}
		int k;//流失した数
		cin>>k;
		vector<int> ans;
		ans.clear();
		for(int i = 0;i <k;i++){
			cin>>know[i];//流失した番号
		}
		for(int j = 1;j <=n;j++){
			bool flag = true;
			for(int i = 0;i <k;i++){
				if(d[j][know[i]]==1){
					continue;
				}
				flag =false;
			}
			if(flag){
				ans.push_back(j);
			}
		}
		if(ans.size()==1){
			cout <<ans.front()<<endl;
		}else{
			cout <<-1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>


int main() {

    int N, M;
    std::cin >> N >> M;
    std::vector<int> vs;
    for (int i = 0; i < N; ++i) {
        vs.push_back(i);
    }

    bool adj[8][8];

    for (int k = 0; k < 8; ++k) {
        for (int i = 0; i < 8; ++i) {
            adj[k][i] = false;
        }
    }

    int a, b;
    for (int j = 0; j < M; ++j) {
        std::cin >> a >> b;
        adj[a - 1][b - 1] = true;
        adj[b - 1][a - 1] = true;
    }

    int cnt = 0;
    do {
        if (vs[0] != 0) {
            continue;
        }
        bool ok = true;
        for (int i = 0; i < vs.size() - 1; ++i) {
            if (!adj[vs[i]][vs[i + 1]]) {
                ok = false;
                break;
            }
        }

        if (ok) {

            cnt += 1;
        }
    } while (std::next_permutation(vs.begin(), vs.end()));

    std::cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static final int TOTAL = 1000000;
	static long[][] matrix;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		matrix = new long[n][2];
		for(int i = 0; i < n; i++){
			matrix[i][0] = sc.nextLong();
			matrix[i][1] = sc.nextLong()*sc.nextLong();
		}
		return true;
	}
	
	static void solve(){
		boolean isOver = false;
		for(int i = 0; i < matrix.length; i++){
			long ID = matrix[i][0];
			long value = matrix[i][1];
			for(int j = i+1; j < matrix.length; j++){
				if(ID == matrix[j][0]){
					value += matrix[j][1];
				}
			}
			if(value >= TOTAL){
				System.out.println(ID);
				isOver = true;
			}
		}
		if(!isOver)System.out.println("NA");
	}
}

Measured memory_bytes: 24648
#include <iostream>
#include <vector>
#include <array>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<array<ll, 3>> obs(n);
    ll min_h = 1000000000;
    for(int i = 0; i < n; ++i){
        cin >> obs.at(i).at(0);
        cin >> obs.at(i).at(1);
        cin >> obs.at(i).at(2);
        min_h = min(min_h, obs.at(i).at(2));
    }

    for(ll cx = 0; cx <= 100; ++cx){
        for(ll cy = 0; cy <= 100; ++cy){
            for(ll dh = 0; dh <= 200; ++dh){
                const ll h = min_h + dh;
                bool ng = false;
                for(auto a : obs){
                    ll est_h = max(
                        h - abs(a.at(0) - cx) - abs(a.at(1) - cy),
                        0LL);
                    if(est_h != a.at(2)){
                        ng = true;
                        break;
                    }
                }
                if(!ng){
                    cout << cx << ' ' << cy << ' ' << h << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#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 = x * 2;
    int b = x + K;
    x = min(a, b);
  }

  cout << x << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll m,tmp;
    ll n;
    string s[200000];
    string str;
    ll minj=1000000000002;
    ll mini=1000000000002;
    int strr[200005];

    cin>>n;
    for(i=1;i<1000001;i++){
        if(n%i==0){
            if(mini+minj>n/i+n/(n/i)){
                minj=n/i;
               mini=n/minj;
            }
        }
    }
    cout<<mini+minj-2<<endl;
    return 0;
}

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

int comp(const void *a, const void *b){
	return *(long*)a > *(long*)b;
}

long gcd(long a, long b){
	if(a % b == 0)return b;
	return gcd(b, a % b);
}

long absl(long in){
	if(in < 0)return -in;
	return in;
}

int main(void){
	long n, x, in, res;
	scanf("%ld %ld", &n, &x);
	for(int i = 0; i < n; i++){
		scanf("%ld", &in);
		if(i == 0)res = absl(in - x);
		res = gcd(res, absl(in - x));
	}
	printf("%d\n", res);
	return 0;
}


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

int main()
{
     int n,i;
     long long  sum=0;

     cin>>n;

     for(i = 1; i <= n; i++)
     {
          if(i%3==0 && i%5==0)
               sum=sum;
          else if(i%3==0)
               sum==sum;
          else if(i%5==0)
               sum==sum;
               else
                    sum+=i;

     }
     cout<<sum<<endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=1; i<N; i++){
    cin >> A.at(i);
  }
  vector<int> Ans(N, 0);
  for(int i=1; i<N; i++){
    Ans.at(A.at(i)-1)++;
  }
  for(int i=0; i<N; i++){
    cout << Ans.at(i) << endl;
  }
}

Measured memory_bytes: 4768
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int main()
{
    int N;
    int M;
    long long int ans;
    ans = 0;
    
    cin >> N;
    cin >> M;
    
    priority_queue<long int> A;
    
    for(int i=0; i<N; i++){
        long int a;
        cin >> a;
        A.push(a);
    }
    
    for(int i=0; i<M; i++){
        long int at;
        at = A.top();
        at = at/2;
        A.pop();
        A.push(at);
    }
    for(int i=0; i<N; i++){
        ans = ans + A.top();
        A.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#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 rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s,t) sort((s).begin(),(s).end(),greater<t>())

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int a,b;
void input()
{
    cin>>a>>b;
    return;
}

void solve()
{
    if((a+b)%2) cout<<"IMPOSSIBLE\n";
    else cout<<(a+b)/2<<endl;
    return;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++) cout << "x";
	cout << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int j[1001][1001];
int o[1001][1001];
int i[1001][1001];
int main(){
  int M, N;
  while(cin>>M>>N && M){
    int K; cin>>K;
    memset(j, 0, sizeof(j));
    memset(o, 0, sizeof(o));
    memset(i, 0, sizeof(i));
    vector<string> grid(M);
    REP(i, M) cin>>grid[i];
    REP(y, M)REP(x, N){
      j[y+1][x+1] = j[y][x+1] + j[y+1][x] - j[y][x];
      o[y+1][x+1] = o[y][x+1] + o[y+1][x] - o[y][x];
      i[y+1][x+1] = i[y][x+1] + i[y+1][x] - i[y][x];
      if(grid[y][x] == 'J') j[y+1][x+1] ++;
      if(grid[y][x] == 'O') o[y+1][x+1] ++;
      if(grid[y][x] == 'I') i[y+1][x+1] ++;
    }
    REP(iter, K){
      int y1, x1, y2, x2;
      cin>>y1>>x1>>y2>>x2;
      x1--; y1--;
      int xj = j[y2][x2] - j[y1][x2] - j[y2][x1] + j[y1][x1];
      int xo = o[y2][x2] - o[y1][x2] - o[y2][x1] + o[y1][x1];
      int xi = i[y2][x2] - i[y1][x2] - i[y2][x1] + i[y1][x1];
      printf("%d %d %d\n", xj, xo, xi);
    }
  }

  return 0;
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
long long a,b,c,k,res=0;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>a>>b>>c>>k;
    if (k>0)
    {
        res+=min(k,a);
        k-=min(k,a);
    }

    if (k>0)
    {
        k-=min(k,b);
    }

    if (k>0)
    {
        res-=min(k,c);
        k-=min(k,c);
    }

    cout<<res;
}
        




Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	cnt := map[pii]int{}
	a := make([]int, n)
	b := make([]int, n)
	zero := 0
	ca := 0
	cb := 0
	for i := 0; i < n; i++ {
		a[i], b[i] = scanInt(), scanInt()
		if a[i] == 0 && b[i] == 0 {
			zero++
		} else if a[i] == 0 {
			ca++
		} else if b[i] == 0 {
			cb++
		} else {
			c := gcd(a[i], b[i])
			a[i] /= c
			b[i] /= c
			cnt[pii{a[i], b[i]}]++
		}
	}

	ans := mpow(2, ca) + mpow(2, cb) - 1
	f := map[pii]bool{}
	for e, c := range cnt {
		if f[e] {
			continue
		}
		cc := cnt[pii{-e.b, e.a}] + cnt[pii{e.b, -e.a}]
		f[pii{-e.b, e.a}] = true
		f[pii{e.b, -e.a}] = true
		// debug(e, c, cc)
		ans *= (mpow(2, c) + mpow(2, cc) - 1) % mod
		ans %= mod
	}
	ans += zero - 1
	ans += mod
	ans %= mod

	fmt.Fprintln(wr, ans)

}

const mod = 1000000007

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

type pii struct {
	a, b int
}

func mpow(a, n int) int {
	res := 1
	for n > 0 {
		if n&1 == 1 {
			res = res * a % mod
		}
		a = a * a % mod
		n >>= 1
	}
	return res
}


Measured memory_bytes: 43308
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    string s, t; cin>>s>>t;
    int dp[s.length()+1][t.length()+1];
    for(int i=0; i<=s.length(); ++i){
        for(int j=0; j<=t.length(); ++j) dp[i][j] = 0;
    }
    for(int i=1; i<=s.length(); ++i){
        for(int j=1; j<=t.length(); ++j){
            if(s[i-1]==t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string ans = "";
    int i = s.length(), j=t.length();
    while(i!=0 && j!=0){
        if(s[i-1]==t[j-1]) {ans = s[i-1] + ans; i--; j--;}
        else{
            if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 38852
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
xyh = [input() for _ in range(n)]
#print(xyh)
for x_ in range(101):
    for y_ in range(101):
        cur_h = 0 #flga の場所をループの中に入れない
        for i in range(n):
            x = int(xyh[i].split()[0])
            y = int(xyh[i].split()[1])
            h = int(xyh[i].split()[2])
            h_ = h + (abs(x_ - x) + abs(y_ - y))
            if cur_h == 0 and h > 0:
                cur_h = h_  #決め打ちの高さ        
            else:
                if h > 0:
                    if cur_h != h_: break
                elif cur_h -(abs(x_ - x) + abs(y_ - y)) > 0: break
        for i in range(n):
            x = int(xyh[i].split()[0])
            y = int(xyh[i].split()[1])
            h = int(xyh[i].split()[2])
            h_ = h + (abs(x_ - x) + abs(y_ - y))
            if cur_h == 0 and h > 0:
                cur_h = h_  #決め打ちの高さ        
            else:
                if h > 0:
                    if cur_h != h_: break
                elif cur_h -(abs(x_ - x) + abs(y_ - y)) > 0: break   
                if i == n-1: 
                    print(x_,y_,cur_h)
                    #print("hello")
                    exit(0)

Measured memory_bytes: 3064