akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

string board[16];

void dfs(int r, int c) {
  if (board[r][c] != '1') return ;

  board[r][c] = '.';
  REP(i, 4) {
    int nr = r+dr[i], nc = c+dc[i];
    if (0 <= nr && nr < 12 && 0 <= nc && nc < 12) {
      dfs(nr, nc);
    }
  }
}

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (cin >> board[0]) {
    REP(i, 11) cin >> board[i+1];
    int cnt = 0;
    REP(r, 12) {
      REP(c, 12) {
	if (board[r][c] == '1') {
	  cnt++;
	  dfs(r, c);
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
n = int(input())
A = list(map(int, input().split()))

checker = []
for a in A:
    cnt = 0
    if a % 2 == 0:
        cnt = 1
    if a % 4 == 0:
        cnt += 1
    checker.append(cnt)

count_2 = checker.count(2)
count_1 = checker.count(1)
count_0 = checker.count(0)

if (count_0 <= count_2+1 and count_0 + count_1 <= count_2 + 1) or count_0 == count_2:
    answer = 'Yes'
else:
    answer = 'No'

print(answer)


Measured memory_bytes: 14252
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t

int main() {
	int k, s;
	cin >> k >> s;
	int ans = 0;
	ff(i, 0, k + 1) {
		ff(j, 0, k + 1) {
			if (s - i - j <= k&&s-i-j>=0)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(arr: Array<String>) {
    solve()
}

fun solve() {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!!.split(" ").map { it.toInt() }.toMutableList() }
    val ans = mutableListOf<List<Int>>()
    for(i in (0 until h)) {
        val keyList = (if(i%2==0) (0 until w) else (0 until w).reversed()).toList()
        for(j in keyList) {
            if(map[i][j] % 2 == 0) {
                continue
            }
            var nextX = j
            var nextY = i
            if(j == keyList.last()) {
                nextY++
            } else {
                nextX = keyList[keyList.indexOf(j) + 1]
            }
            if(nextY >= h) {
                break
            }
            map[i][j]--
            map[nextY][nextX]++
            ans.add(listOf(i,j,nextY,nextX))
        }
    }
    println(ans.size)
    ans.forEach { println(it.map { it+1 }.joinToString(" ")) }
}

Measured memory_bytes: 83920
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define lp(i, a, b) for (int i=a;i<=(int)b;++i)
#define lp2(i, a, b) for (ll i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define clr(c, x) memset(c,x,sizeof(c));
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = (int) 3e2 + 5, INF = 0x3f3f3f3f, ALPHA = 26;
const ll mod = 998244353;
int n,m;
ll l,floyd[N][N];
int main()
{
#ifdef ONLINE_JUDGE
    FAST;
#endif
    cin>>n>>m>>l;
    lp(i,1,n)lp(j,1,n)
    {
        floyd[i][j]=INF;
        if (i==j)
            floyd[i][j]=0;
    }
    lp(i,1,m)
    {
        int x,y,c;
        cin>>x>>y>>c;
        if (c>l)
            continue;
        floyd[x][y]=c;
        floyd[y][x]=c;
    }
    lp(k,1,n)lp(i,1,n)lp(j,1,n) floyd[i][j]=min(floyd[i][j],floyd[i][k]+floyd[k][j]);
    lp(i,1,n)lp(j,1,n) if (floyd[i][j]<=l)
        floyd[i][j]=1;
    lp(i,1,n) floyd[i][i]=0;
    lp(k,1,n)lp(i,1,n)lp(j,1,n) floyd[i][j]=min(floyd[i][j],floyd[i][k]+floyd[k][j]);
    int q;
    cin>>q;
    while(q--)
    {
        int s,t;
        cin>>s>>t;
        if (floyd[s][t]==INF)
            cout<<-1<<"\n";
        else
            cout<<floyd[s][t]-1<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1280
import collections

N = int(input())
l=[]
for i in range(N):
  l.append(input())

c = collections.Counter(l)

v, counts = zip(*c.most_common())#出現回数順に並べた要素リストと出現回数リスと

c1 = collections.Counter(list(counts))
n = c1[max(c1.keys())]

v = list(v)
v = v[:n]
v.sort()

#print(c1,n,v)
for i in v:
  print(i)

Measured memory_bytes: 59508
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())

def divisor(n):
    res = []
    rn = int(n**0.5) + 1 
    for i in range(1, rn):
        if n % i == 0:
            res.append(i)
            if i != n / i:
                res.append(int(n / i))
    return sorted(res)

l = divisor(N)

s = 0
t = len(l)-1
while s < t:
    s += 1
    t -= 1

print(l[s]+l[t]-2)

Measured memory_bytes: 3264
#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 1e5+7;
static const int INF = 0x3f3f3f3f;
static const int MOD = 1e9+7;



int main() {

  FASTIO;

  int n;cin >> n;
  vii val(n);
  FOR(i,0,n){
      cin >> val[i].ff >> val[i].ss;
  }

  sort(val.begin(),val.end(),[](const pii &x,const pii &y){

      return x.ff + x.ss > y.ff + y.ss;
  });


  ll takashi=0,aoki=0;

  FOR(i,0,n){

      if(i%2==0){
          takashi += val[i].ff;
      }
      else{
          aoki += val[i].ss;
      }
  }


  cout << takashi - aoki;

}

Measured memory_bytes: 1024
#include<stdio.h>
#define SENTINEL 1000000000
 
int count=0,A[500000];
 
void Merge(int left, int mid, int right){
  int n1 = mid-left;
  int n2 = right-mid;
  int L[n1],R[n2];
  int i,j,k;
  for (i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for (i=0;i<=n2-1;i++){
    R[i]=A[mid+i];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  /*
  printf("L[");
  for (i=0;i<=n1;i++){
    if (i!=0){
      printf(" ");
    }
    printf("%d",L[i]);
  }
  printf("]\n");
  printf("R[");
  for (i=0;i<=n2;i++){
    if (i!=0){
      printf(" ");
    }
    printf("%d",R[i]);
  }
  printf("]\n");
  */
  for (k=left;k<=right-1;k++){
    count++;
    if (L[i]<=R[j]){
      A[k]=L[i];
      i++;
    } else {
      A[k]=R[j];
      j++;
    }
  }
}
 
void MergeSort(int left, int right){
  int mid;
  if (left+1<right){
    mid = (left+right)/2;
    MergeSort(left,mid);
    MergeSort(mid,right);
    Merge(left,mid,right);
  }
}
 
int main(){
  int i,n;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  MergeSort(0,n);
  for (i=0;i<n;i++){
    if(i!=0){
      printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 4504
def tmp(x,y):
  tmp = 0
  tmp = x
  x = y
  y = tmp

  return x,y

def main():
  x,y,z = (int(x) for x in input().split())
  x,y = tmp(x,y)
  x,z = tmp(x,z)

  print(x,y,z)

if __name__ == '__main__':
  main()


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define AL 26
#define LS 5
ll d;
map<ll,ll> losses;
ll c[26],s[365][26],interval[26]={0};
ll lossCheck(int j,int day){
  int cc = c[j];
  int dd = interval[j];
  if(losses.count(j)) return losses[j];
  ll i,result=0;
  rep(i,min(d-day,LS)){
    result += cc*dd;
    dd++;
  }
  losses[j] = result;
  return result;
}
int main(){
  int i,j,tmp=0;
  
  cin >> d;
  rep(i,AL) cin >> c[i];
  rep(i,d){
    rep(j,AL) cin >> s[i][j];
  }
  rep(i,d){
    tmp=0;
    losses.clear();
    rep(j,AL){
      if(s[i][tmp]+lossCheck(tmp,i+1)<s[i][j]+lossCheck(j,i+1)){
        tmp = j;
      }
    }
    rep(j,AL){
      if(j==tmp) interval[j]=0;
      else interval[j]++;
    }
    cout << tmp+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut is_coprime = true;
    let mut counts: Vec<usize> = vec![0; 1_000_005];
    for i in 0..n {
        let is_over = count_divisors(a[i], &mut counts);
        if is_over {
            is_coprime = false;
            break;
        }
    }

    if is_coprime {
        return "pairwise coprime".to_string();
    }

    let mut g = a[0];
    for i in 1..n {
        g = gcd(g, a[i]);
    }

    if g == 1 {
        "setwise coprime".to_string()
    } else {
        "not coprime".to_string()
    }
}

fn count_divisors(n: usize, counts: &mut Vec<usize>) -> bool {
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            counts[i] += 1;
            if i != 1 && counts[i] > 1 {
                return true;
            }
            if n / i != i {
                counts[n / i] += 1;
                if n / i != 1 && counts[n / i] > 1 {
                    return true;
                }
            }
        }
        i += 1;
    }
    return false;
}

fn gcd(mut x: usize, mut y: usize) -> usize {
    while y > 0 {
        let r = x % y;
        x = y;
        y = r;
    }
    return x;
}


Measured memory_bytes: 17776
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=1000005;
using namespace std;


ll pow(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    ll d = pow(a, b / 2);
    return (d * d) % MOD;
  } else {
    ll d = pow(a, b - 1);
    return (a * d) % MOD;
  }
}
map<ll, ll> prime_factorize(long long N) {
    map<ll,ll> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res[a]=ex;
    }

    // 最後に残った数について
    if (N != 1) res[N] = 1;
    return res;
}

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

    map<ll,ll> mm[n];
    map<ll,ll> mp;
    for(int i = 0; i < n; i++){
        mm[i] = prime_factorize(a[i]);
        for(auto it = mm[i].begin(); it != mm[i].end(); it++){
            auto k = (*it);
            if(mp.find(k.first) == mp.end()){
                mp[k.first] = k.second;
            } else if(mp[k.first] < k.second){
                mp[k.first] = k.second;
            }
        }
    }
    
    ll multiple = 1;
    for(auto it = mp.begin(); it != mp.end(); it++){
        multiple *= pow((*it).first, (*it).second);
        multiple %= MOD;
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll cnt = 1;
        ll inv = pow(a[i], MOD-2);
        cnt = multiple * inv % MOD;
        ans += cnt;
        ans %= MOD;
    }

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

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

int H, W;
string S[60];

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

int main()
{
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (S[i][j] == '#')
                continue;


            int bum = 0;
            for (int k = 0; k < 8; k++)
            {
                int y = i + dy[k];
                int x = j + dx[k];

                if (0 <= y && y < H && 0 <= x && x < W && S[y][x] == '#')
                {
                    bum++;
                }
            }

            S[i][j] = '0' + bum;
        }
    }

    for (int i = 0; i < H; i++)
    {
        cout << S[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			boolean[] f = new boolean[1<<n];
			boolean[][] a = new boolean[n][n];
			int[] c = new int[n];
			
			int[][] b = new int[n][3];
			for(int i=0;i<n;i++){
				for(int j=0;j<3;j++) b[i][j] = sc.nextInt();
				c[i] = sc.nextInt() - 1;
				for(int j=i-1;j>=0;j--){
					if(Math.sqrt((b[i][0]-b[j][0])*(b[i][0]-b[j][0])+(b[i][1]-b[j][1])*(b[i][1]-b[j][1]))<b[i][2]+b[j][2]){
						a[i][j] = true;
					}
				}
			}
		
			f[(1<<n)-1] = true;
			int max = 0;
			boolean flag;
			int sum;
			for(int i=(1<<n)-1;i>=0;i--){
				sum = 0;
				if(f[i]==false) continue;
				for(int j=0;j<n;j++){
					if(((i>>j)&1)==0) sum++;
					if(((i>>j)&1)==0) continue;
					flag = false;
					for(int k=j-1;k>=0;k--){
						if(((i>>k)&1)==1 && a[j][k]==true){
							flag = true;
							break;
						}
					}
					if(flag==true) continue;
					for(int k=j+1;k<n;k++){
						if(((i>>j)&1)==0 || c[j]!=c[k]) continue;
						flag = false;
						for(int s=k-1;s>=0;s--){
							if(((i>>s)&1)==1 && a[k][s]==true){
								flag = true;
								break;
							}
						}
						if(flag==true) continue;
						f[i^(1<<j)^(1<<k)] = true;
					}
				}
				max = Math.max(max, sum);
			}
			System.out.println(max);
		}
	}	
}

Measured memory_bytes: 223940
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
 int n;
 cin>>n;
 long long int arr[n];
 long long int sum=0;
 for(int i=0;i<n;i++)
 {
    cin>>arr[i];
 }
 sort(arr,arr+n);
 for(int i=0;i<n-1;i++)
 {
    sum=sum+arr[i];
 }
 if(sum>arr[n-1])
    cout<<"Yes";
else
    cout<<"No";

 return 0;
}








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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    // vector<ll> p(n);
    // for(ll i=0; i<n; i++) {
    //     cin>>p[i];
    // }
    // ll ans=0;

    vector<ll> swap;
    ll tmp;
    for(ll i=0; i<n; i++) {
        cin>>tmp;
        if(tmp == i+1){
            swap.push_back(tmp);
        }
    }
    ll ans=0;

    ll size = swap.size();
    ans = size;
    
    if(size != 0){
        for(ll i=0; i<size-1; i++) {
            if(swap[i]+1==swap[i+1]){
                ans = ans-1;
                swap[i+1]=0;
            }
        }
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 1400
#include<stdio.h>

char train[27];
int head;
int tail;
int main(){
  int i,n,j,now,tr;
  char str[1025];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",str);
    now=j=head=tail=0;
    while(str[j]){
      train[now]=str[j];
      if(str[j+1]=='\0') break;
      if(str[j+1]=='-'){
	if(now==tail){
	  tail=(tail+1)%26;
	  now=tail;
	}else{
	  now=(now+1)%26;
	}
      }else{
	if(now==head){
	  head=head-1>-1?head-1:25;
	  now=head;
	}else{
	  now=now-1>-1?now-1:25;
	}
      }
      if(tail==head) break;
      j+=3;
    }
    tr=head>=tail?26:tail;
    if(head>tail){
      for(j=head;j<26;j++)
	printf("%c",train[j]);
      for(j=0;j<tail+1;j++)
	printf("%c",train[j]);
      printf("\n");
    }else{
      train[tail+1]='\0';
      printf("%s\n",train);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>k;
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
} 

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int A,B,C;
  cin >> A >> B >> C;
  
  int now = 0;
  bool flg = false;
  for(int i = 0; i <= 100; i++){
    if(now%B == C){
      flg = true;
    } else{
      now += A;
      continue;
    }
  }
  cout << (flg ? "YES" : "NO") << endl;
}


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

int main(){
  int M, N, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  int cnt1=0;
  int cnt2=0;
  for(int i=0; i<M; i++){
    cin >> A[i];
    if(X<A[i] && A[i]<N) cnt1++;
    else if(0<A[i] && X>A[i]) cnt2++;
  }
  cout << min(cnt1, cnt2) <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n, c[100], d, dp[50001], s;
void solve() {
	if (c[0] != 1) { cout << "Cannot pay some amount" << endl; return; }
	for (int i = 0; i <= s; i++)dp[i] = 9999999; dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= s - c[i]; j++) {
			dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1);
		}
	}
	for (int i = 1; i <= s; i++) {
		int t = 0, r = i;
		for (int j = n - 1; j >= 0; j--) {
			t += r / c[j]; r %= c[j];
		}
		if (dp[i] < t) { cout << "Cannot use greedy algorithm" << endl; return; }
	}
	cout << "OK" << endl;
}
int main() {
	while (true) {
		cin >> n; if (n == 0)break; s = 0; d++; cout << "Case #" << d << ": ";
		for (int i = 0; i < n; i++) { cin >> c[i]; s += c[i]; }
		solve();
	}
	return 0;
}

Measured memory_bytes: 3092
def main():
    import sys
    input = sys.stdin.readline
    from bisect import bisect_left

    N, Q = map(int, input().split())
    c = []
    c_append = c.append
    for _ in range(N):
        s, t, x = map(int, input().split())
        c_append((x, s, t))
    c.sort()

    D = [int(input()) for _ in range(Q)]

    ans = [-1] * Q
    skip = [-1] * Q

    for x, s, t in c:
        left = bisect_left(D, s - x)
        right = bisect_left(D, t - x)
        while left < right:
            if skip[left] == -1:
                ans[left] = x
                skip[left] = right
                left += 1
            else:
                left = skip[left]

    print ('\n'.join(map(str, ans)))

if __name__ == '__main__':
    main()

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

int main(){
  int N;
  cin >> N;
  vector<int> T(N+1),X(N+1),Y(N+1);
  for(int i=1;i<N+1;i++){
    cin >> T.at(i) >> X.at(i) >> Y.at(i);
  }
  bool a=false;//だめならtrue
  for(int i=0;i<N;i++){
    int dt=T.at(i+1)-T.at(i);
    int dist=abs(X.at(i+1)-X.at(i))+abs(Y.at(i+1)-Y.at(i));
      if((dist+dt)%2==1){
        a=true;
        break;
      }
      if(dist>dt){
        a=true;
        break;
      }
  }
  if(a){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define all(v) begin(v),end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)

int main() {


  int a,b,c;
  while (cin >> a >> b >> c) {
    int k = 0;
    for (int i=1;i<=10;++i) {
      if (i == a) continue;
      if (i == b) continue;
      if (i == c) continue;
      if (a+b+i <= 20) ++k;
    }
    cout << (
        (k >= 4) ? "YES" : "NO"
        ) << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  bool ans = true;
  for (int i=0; i<n; i++) {
    if (a[i]%2 == 1) continue;
    if (a[i]%3 != 0 && a[i]%5 != 0) {
      ans = false;
    }
  }
  string o = ans ? "APPROVED" : "DENIED";
  cout << o << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int x,y;
  cin >> x >> y;
  int ans_x,ans_y;
  vector<int> A{1,3,5,7,8,10,12};
  vector<int> B{4,6,9,11};
  vector<int> C{2};
  rep(i,7){
    if(A.at(i) == x)ans_x = 0;
    if(A.at(i) == y)ans_y = 0;
  }
  rep(i,4){
    if(B.at(i) == x)ans_x = 1;
    if(B.at(i) == y)ans_y = 1;

  }
  if(C.at(0) == x )ans_x = 2;
  if(C.at(0) == y )ans_y = 2;

 if(ans_x == ans_y){
   cout << "Yes" <<endl;
    return 0;
  }else{
    cout << "No" <<endl;
  }
  return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a + b > c + d) cout << "Left" << endl;
    else if (a + b == c + d) cout << "Balanced" << endl;
    else cout << "Right" << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize "trapv"
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }

const int sz = 1e6+1;
bool vis[sz];
int cnt = 0;
vector<vector<int>> graph(sz+1);


void dfs(int node){
  if(vis[node]) return;
  else{
    // print(node);
    // print(graph[node]);
    vis[node] = true;
    cnt++;
    for(int child : graph[node]){
      dfs(child);
    }
  }
}

int32_t main(){
    
  fast;
  int n,m; cin >> n >> m;

  for(int i=1;i<=m;i++){
    int x,y; cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }

  int ans = INT_MIN;

  for(int i=1;i<=n;i++){
    if(vis[i]==false){
      cnt = 0;
      dfs(i);
      // print(cnt);
      ans = max(ans,cnt);
    }
  }
  
  
  // print(graph);

  cout << ans << '\n';


  return 0;
}

Measured memory_bytes: 45484
#include <bits/stdc++.h>
#define r1(i, n) for (int i=0;i<n;i++)
#define r2(i, n) for (int i=1;i<n;i++)
#define intc(n) int n; cin >> n;
#define ll long long
#define llc(n) ll n; cin >> n;
using namespace std;
int main() {
  vector<int> v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  intc(n);
  cout << v.at(n-1) << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

const ll inf = 10e17;
const ll mod = 1000000007;
const ld eps = 10e-9;


ll solve(void);

ll mulmod(ll x, ll y, ll m = mod)
{
	return (x * y) % m;
}

ll power(ll n, ll r, ll m = mod)
{
	if (r == 0) { return 1; }
	if (r == 1) { return n; }
	if (n == 0) { return 0; }
	if (n == 1) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r / 2, m);
		return mulmod(y, y, m);
	}
	else
	{
		ll y = power(n, (r - 1) / 2, m);
		return n * mulmod(y, y, m) % m;
	}
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);

	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i - 1], i);
	}

	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

vector<ll> primes;
map<ll, ll> big_primes;
void init_primes(ll n)
{
	vector<bool> is_prime(sqrt(n)+100, true);
	is_prime[1] = false;
	is_prime[0] = false;
	for (ll i = 2; i < is_prime.size(); i++)
	{
		if (!is_prime[i]) { continue; }
		for (ll j = 2; i*j < is_prime.size(); j++)
			is_prime[i*j] = false;
		primes.push_back(i);
	}
}

map<ll, ll> prime_div(ll x)
{
	map<ll, ll> m;
	for (ll i = 0; x > 0 && i < primes.size();)
	{
		if (x % primes[i]) { i++; continue; }
		m[primes[i]] = m[primes[i]] + 1;
		x /= primes[i];
	}
	if (x > 0) big_primes[x] = 1;
	return m;
}

map<ll, ll> prime_lcm(ll x, map<ll, ll>  vy)
{
	auto vx = prime_div(x);
	
	map<ll, ll> result;
	for (auto k: vx)
		result[k.first] = max(vx[k.first], vy[k.first]);
	for (auto k: vy)
		result[k.first] = max(vx[k.first], vy[k.first]);

	return result;
}

ll gcd(ll x, ll y)
{
	if (y % x == 0) { return x; }
	return gcd(y % x, x);
}

ll lcm(ll x, ll y)
{
	return (x * y) / gcd(x, y);
}

ll solve(void)
{
	ll n;
	cin >> n;
	vector<ll> A(n);
	for (auto& a : A)
		cin >> a;

	init_primes(10e6+10);

	auto v = prime_div(A[0]);
	for (ll i = 1; i < n; i++) {
		v = prime_lcm(A[i], v);
	}

	ll L = 1;
	for (auto w: v)
		L = mulmod(L, power(w.first, w.second));
	for (auto a: big_primes)
		L = mulmod(L, a.first);

	ll ans = 0;
	for (auto a: A)
		ans = (ans + mulmod(L, power(a, mod-2)))%mod;

	cout << ans << endl;

	return 0;
}

int main(void)
{
	while (solve())
	{
	}
	return 0;
}


Measured memory_bytes: 896
fun main(args: Array<String>) {
    val n = readInt()
    val s = readString()
    val t = readString()
    
    for (i in n - 1 downTo 0) {
        if (s.substring(n - 1 - i until n) == t.substring(0..i)) {
            println(2 * n - (i + 1))
            return
        }
    }
    println(2 * n)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

Measured memory_bytes: 36024
import sys

N, M = map(int, input().split())
ab = [list(map(int, line.split())) for line in sys.stdin.readlines()]
ab.sort(key = lambda x : x[1])

ans = 0
last = -1
for a, b in ab:
    if a < last:
        continue
    else:
        ans += 1
        last = b

print(ans)

Measured memory_bytes: 34476
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const long double pi=acos(-1);

int main(){cout<<fixed<<setprecision(10);
		   string s;
           cin>>s;
           ll n=s.size();
           //abjka 両端が同じなら数えない
           ll ans=1;
           map<char,ll> cnt;
           rep(i,0,n)cnt[s[i]]++;
           ans+=n*(n-1)/2;
           ll c;
           for(auto v:cnt){
              c=v.second;
            ans-=c*(c-1)/2;
           }
           cout<<ans<<endl;
}


Measured memory_bytes: 3756
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int[][] flag = new int[N][3];
		ArrayList<ArrayList<Integer>> edge = new ArrayList<ArrayList<Integer>>();
		for (int i=0;i<N;i++) {
			ArrayList<Integer> add = new ArrayList<Integer>();
			edge.add(add);
		}
		for (int i=0;i<M;i++) {
			int u = Integer.parseInt(sc.next())-1;
			int v = Integer.parseInt(sc.next())-1;
			edge.get(u).add(v);
		}
		int S = Integer.parseInt(sc.next())-1;
		int T = Integer.parseInt(sc.next())-1;

		LinkedList<Integer> dfs = new LinkedList<Integer>();
		dfs.add(S);
		dfs.add(0);
		dfs.add(0);
		dfs.add(0);

		int ans=-1;
		while (dfs.size()>0) {
			Integer rem = dfs.remove(0);
			Integer index = dfs.remove(0);
			Integer steps = dfs.remove(0);
			Integer before = dfs.remove(0);
			if (rem==T && index==0) {
				System.out.println(steps/3);
				ans=0;
				break;
			}
			if (flag[rem][index]==1) {
				continue;
			}
			flag[rem][index]=1;
			for (Integer element : edge.get(rem)) {
				int add_index;
				if (index==2) {
					add_index=0;
				} else {
					add_index=index+1;
				}
				dfs.add(element);
				dfs.add(add_index);
				dfs.add(steps+1);
				dfs.add(rem);
			}
		}
		if (ans==-1) {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 82852
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)

ans = A[0]
for i in range(len(A)-1):
    ans = gcd(ans, A[i+1])

print(ans)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e5+7;
int read(){
    int c = getchar(),Nig = 1,x = 0;
    while(!isdigit(c))
        c = getchar();
    if(c == '-')
        Nig = -1,c = getchar();
    while(isdigit(c))
        x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
    return Nig*x;
}
#define read read()
int main(){
    int n = read,cnt = 0;
    while(n){
        if(n%10==2)
            cnt++;
        n/=10;
    }
    printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll f(ll a, ll x){
  if(a==0){
    return 1;
  }
  if(a==-1) return 0;

  return a/x + 1;
}

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

    // input
    ll a, b, x;
    cin >> a >> b >> x;

    ll ans = f(b, x) - f(a-1, x);
    debug(f(b, x));
    debug(f(a-1, x));
    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
int main(){
  int h[10];
  for(int n=0;n<10;n++){
    using std::cin;
    cin>>h[n];
  }
  using std::sort;
  using std::greater;
  sort(h,h+10,greater<int>());
  for(int n=0;n<3;n++){
    using std::cout;
    using std::endl;
    cout<<h[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}









 int main(void) {
   ll n;
   cin >> n;
   ll a[n+1];
   map <ll,bool> ok;
   rep (i,n){
     cin >> a[i];
     --a[i];
   }


  ll  j = 0,cnt=0;
   while (j!=1){
    ok[j]=true;
     j = a[j];
     //cout << j << endl;
     cnt++;
     if (ok[j]) {
       cout << -1 << endl;
       return 0;
       //break;
     }
     //ok[j]=true;
   }
   cout << cnt << endl;
  


}


 

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);
	
	int n;
	cin >> n;
	int a[n];
	int xr = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		xr ^= a[i];
	}
	for(int i = 0; i < n; i++)
	{
		cout << (a[i] ^ xr) << " ";
	}

	return 0;
}


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

//#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int t;
	while (cin >> t && t) {
		V ts(t);
		rep(i, t) {
			int x; cin >> x;
			ts[i] = x;
		}
		int n; cin >> n;
		V ms(101, 1 << 29);
		rep(i, n) {
			int d, m;
			cin >> d >> m;
			minup(ms[d - 1], m);
		}
		VV dp(101, V(t, 1 << 29)); //dp[day][t_i]

		dp[0][0] = 0;
		rep(i, 0, 100) rep(j, t) {
			minup(dp[i + 1][1], dp[i][j] + 1);
			if (ts[j] <= ms[i]) minup(dp[i + 1][(j + 1) % t], dp[i][j]);
		}
		int ans = *min_element(all(dp[100]));
		cout << ans << endl;
	}
}

Measured memory_bytes: 3092
#include <iostream>
#include <string>
using namespace std;
int n,m;
int main(){
        cin >> n;
        string s[n];
        for(int i=0; i<n; i++) {
                cin >> s[i];
        }
        cin >> m;
        string t[m];
        for(int i=0; i<m; i++) {
                cin >> t[i];
        }
        int ans=0;
        for(int i=0; i<n; i++) {
                int sum=1;
                for(int j=i+1; j<n; j++) {
                        if(s[i]==s[j]) sum++;
                }
                for(int j=0; j<m; j++) {
                        if(s[i]==t[j]) sum--;
                }
                ans=max(ans,sum);
        }
        cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};





double prob[4];
bool grid[100][100] = {false};

double dfs(int x,int y,int n){
  if(n==0) return 1;
  else{
    if(grid[y][x]) return 0;
    grid[y][x] = true;
    double ans = 0;
    rep(i,4){
      ans += prob[i] * dfs(x+dx[i],y+dy[i],n-1);
    }
    return ans;
  }
}

int main(){
  int a,b,c;
  cin >> a >>b >> c;
  if(a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;

  
  return 0;
}



// int gcd(int a, int b){
//   if (b==0) return a;
//   else return gcd(b,a%b);
// }


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 1000; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j])%mod;
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   pascal_triangle();
//   return memo[n][k];
// }

// int cans(bool f){
//   if(f) cout << "Yes" << endl;
//   else cout << "No" << endl;
//   return 0;
// }







//二項係数(mod剰余)----------------------------

// const int MAX = 3000010;
// const int M = 1000000007;

// vector<ll> fac(MAX); //n!(mod M)
// //a,bの範囲的にこれだけ配列を用意していけば十分
// vector<ll> ifac(MAX); //k!^{M-2} (mod M)

// ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
//     ll ans = 1;
//     while(n != 0){
//         if(n&1) ans = ans*x % M;
//         x = x*x % M;
//         n = n >> 1;
//     }
//     return ans;
// }

// ll COMinit(){
//   //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
//   fac[0] = 1;
//   ifac[0] = 1;
//   for(ll i = 0; i<MAX; i++){
//     fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
//     ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
//   }
//   return 0;
// }

// ll COM(ll a, ll b){ //aCbをmod計算
//   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;
// }

//-----------------------------------------


Measured memory_bytes: 256
import queue
import sys
input = sys.stdin.readline

def calc_next_point(x, y, vec, dist):
    if vec == 0:
        return x-dist, y
    elif vec == 1:
        return x, y+dist
    elif vec == 2:
        return x+dist, y
    else:
        return x, y-dist

def main():
    h, w, k = map(int, input().split())
    x1, y1, x2, y2 = map(int, input().split())
    pond = [[[-1]*4 for j in range(w+2)] for i in range(h+2)]
    for i in range(1, h+1):
        s = input()
        for j in range(w):
            if s[j] == ".":
                for l in range(4):
                    pond[i][j+1][l] = float("inf")
    qs = [queue.Queue(), queue.Queue()]
    for i in range(4):
        pond[x1][y1][i] = 0
        qs[0].put([0, x1, y1, i])
    p = 0
    minans = float("inf")
    g = False
    while not qs[0].empty() or not qs[1].empty():
        while not qs[p].empty():
            cost, x, y, vec = qs[p].get()
            np = (p+1)%2
            if cost >= minans:
                g = True
                break
            if x == x2 and y == y2:
                if cost < minans:
                    minans = cost
                g = True
                break
            for i in range(1, k+1):
                nx, ny = calc_next_point(x, y, vec, i)
                if pond[nx][ny][vec] == -1:
                    break
                ncost = cost + 1
                if pond[nx][ny][vec] < ncost:
                    break
                if pond[nx][ny][vec] == ncost:
                    continue
                pond[nx][ny][vec] = ncost
                if nx == x2 and ny == y2:
                    if ncost < minans:
                        minans = ncost
                    g = True
                    break
                for j in range(4):
                    if i == k:
                        if j != (vec+2)%4:
                            if j == vec or pond[nx][ny][j] > ncost:
                                pond[nx][ny][j] = ncost
                                qs[np].put([ncost, nx, ny, j])
                    elif i == 1:
                        if j != vec:
                            if j == (vec+2)%4 or pond[nx][ny][j] > ncost:
                                pond[nx][ny][j] = ncost
                                qs[np].put([ncost, nx, ny, j])
                    else:
                        if j != vec and j != (vec+2)%4:
                            if pond[nx][ny][j] > ncost:
                                pond[nx][ny][j] = ncost
                                qs[np].put([ncost, nx, ny, j])
            if g:
                break
        if g:
            break
        p = (p+1)%2
    if min(pond[x2][y2]) == float("inf"):
        print(-1)
    else:
        print(min(pond[x2][y2]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 493228
public class Main {

	public static void main(String[] args) {
		String input = new java.util.Scanner(System.in).nextLine();
		String[] input2 = input.split(" ");
		int W = Integer.parseInt(input2[0]);
		int H = Integer.parseInt(input2[1]);
		int x = Integer.parseInt(input2[2]);
		int y = Integer.parseInt(input2[3]);
		int r = Integer.parseInt(input2[4]);
		if((x + r) <= W && (y + r) <= H && x > 0 && y > 0 && r <= x && r <= y)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17324
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
struct xy {
	int x; int y; int d;
	bool operator<(const xy &another) const {return d > another.d;};
};

int main(){
	int h, w; cin >> h >> w;
	vector<vector<bool>> f(h, vector<bool>(w, false));
	int cx, cy; cin >> cx >> cy;
	cx--; cy--;
	int gx, gy; cin >> gx >> gy;
	gx--; gy--;
	vector<string> s(h);
	REP(i,h) cin >> s[i];
	priority_queue<xy> q;
	q.push({cx, cy, 0});
	VVI dis(h, VI(w, INF));
	while (!q.empty()) {
		int x=q.top().x, y=q.top().y;
		int d=q.top().d;
		q.pop();
		if(dis[x][y]<d)
			continue;
		for(int i=-2;i<=2;i++)for(int j=-2;j<=2;j++){
			int tox=x+i, toy=y+j;
			if(i==0&&j==0)
				continue;
			if(tox<0||tox>=h||toy<0||toy>=w)
				continue;
			if(s[tox][toy]=='#')
				continue;
			int pls=1;
			if(abs(i)+abs(j)<=1)
				pls=0;
			if(dis[tox][toy]>d+pls){
				q.push({tox,toy,d+pls});
				dis[tox][toy]=d+pls;
			}
		}
	}
	if(dis[gx][gy]==INF)
		cout << -1 << endl;
	else
		cout << dis[gx][gy] << endl;
	return 0;
}

Measured memory_bytes: 13532
ticket = list(input())
if int(ticket[0])+int(ticket[1])+int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"+"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])+int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"+"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])-int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"-"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])+int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"+"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])-int(ticket[2])+int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"-"+ticket[2]+"+"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])+int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"+"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])+int(ticket[1])-int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"+"+ticket[1]+"-"+ticket[2]+"-"+ticket[3]+"=7")
elif int(ticket[0])-int(ticket[1])-int(ticket[2])-int(ticket[3])==7:
    print(ticket[0]+"-"+ticket[1]+"-"+ticket[2]+"-"+ticket[3]+"=7")


Measured memory_bytes: 38256
q=int(input())
lr=[list(map(int, input().split())) for i in range(q)]
l,r=[],[]
for a in lr:
    l.append(a[0])
    r.append(a[1])
mr=max(r)
x = [True]*(mr+1)
x[0]=False
x[1]=False

for i in range(mr+1):
    if x[i]:
        for j in range(2*i, mr+1, i):
            x[j] = False
c=[0]*(mr+1)
for i in range(1,mr+1):
    if x[i] and x[(i+1)//2]:
        c[i] = c[i-1]+1
    else:
        c[i] = c[i-1]
for i in range(q):
    print(c[r[i]]-c[l[i]-1])

Measured memory_bytes: 31500
def solve():
    N = int(input())
    b = list(map(int, input().split()))
    del_list = []

    while True:
        del_index = -1
        for k in range(len(b)):
            if b[k] == k + 1:
                del_index = max(del_index, k)
        if del_index < 0:
            break
        else:
            del_list.append(b[del_index])
            b.pop(del_index)

    if len(b) > 0:
        print(-1)
    else:
        for key in del_list[::-1]:
            print(key)

solve()

Measured memory_bytes: 38640