akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#define all(c) c.begin(),c.end()
#define pb push_back
using namespace std;
int h,w,n;
vector<string> st(vector<string> s,vector<vector<bool> > f){
	for(int i=0;i<w;i++){
		string t="";
		for(int j=h-1;j>=0;j--){
			if(isalpha(s[j][i])&&!f[j][i]){
				t+=s[j][i];
			}
		}
		for(int j=0;j<t.size();j++){
			s[h-1-j][i]=t[j];
		}
		for(int j=t.size();j<h;j++){
			s[h-1-j][i]='.';
		}
	}
	return s;
}
bool ret(vector<string> s,int cnt){
	vector<vector<bool> > f(h,vector<bool>(w));
	int sum=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			if(!isalpha(s[i][j]))
				continue;
			int a=1;
			for(int k=j;k<w-1;k++){
				if(s[i][k]==s[i][k+1]){
					a++;
				}else break;
			}
			if(a>=n){
				for(int k=0;k<a;k++){
					if(!f[i][k+j]){
						sum++;
					}
					f[i][k+j]=true;
				}
			}
		}
	}
	for(int i=0;i<w;i++){
		for(int j=0;j<h-1;j++){
			if(!isalpha(s[j][i]))
				continue;
			int a=1;
			for(int k=j;k<h-1;k++){
				if(s[k][i]==s[k+1][i]){
					a++;
				}else break;
			}
			if(a>=n){
				for(int k=0;k<a;k++){
					if(!f[k+j][i]){
						sum++;
					}
					f[k+j][i]=true;
				}
			}
		}
	}
	if(cnt-sum==0)
		return true;
	if(!sum)
		return false;
	return ret(st(s,f),cnt-sum);
	
}
int main(){
	while(cin>>h>>w>>n){
		int cnt=0;
		vector<string> s(h);
		for(int i=0;i<h;i++){
			cin>>s[i];
		for(int j=0;j<w;j++){
			if(s[i][j]!='.')
				cnt++;
		}
	}
	bool flag=false;
	for(int i=0;i<h;i++){
		for(int j=0;j<w-1;j++){
			swap(s[i][j],s[i][j+1]);
			flag=ret(st(s,vector<vector<bool> >(h,vector<bool>(w))),cnt);
			if(flag){
				cout<<"YES"<<endl;
				break;
			}
			swap(s[i][j],s[i][j+1]);
		}
		if(flag)
			break;
	}
	if(!flag)
			cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 936
#from typing import List


def input_nums():
    # type: () -> List[int]
    return list(map(int, open(0)))


def calc_nums(l):
    # type: (List[int]) -> int
    x, a, b = l
    return (x - a) % b


def main():
    # type () -> None:
    print(calc_nums(input_nums()))


if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
# _*_ coding:utf-8 _*_
#  Atcoder_Regurar_Contest096-C
#  https://atcoder.jp/contests/arc096/tasks/arc096_a
import sys
def solveProblem(priceA,priceB,priceABSet,wantA,wantB):
	minPrice = sys.maxsize
	for buyABSet in range(0,200000+1,+2):
		# ABピザで補えるAピザとBピザの量
		alreadyA = buyABSet//2
		alreadyB = buyABSet//2
		moreWantA = wantA-alreadyA
		moreWantB = wantB-alreadyB
		# さらに必要となるピザの枚数:もう要らないなら0枚、いるならその枚数
		#　ピザA
		if moreWantA <=0 :
			getA = 0
		else :
			getA = moreWantA
		# ピザB
		if moreWantB <= 0:
			getB = 0
		else:
			getB = moreWantB
		needMoney = priceA * getA + priceB * getB + priceABSet * buyABSet
		if needMoney <= minPrice:
			minPrice = needMoney
	answer = minPrice
	return answer

if __name__ == '__main__':
	A,B,C,X,Y = map(int,input().strip().split(' '))
	solution = solveProblem(A,B,C,X,Y)
	print("{}".format(solution))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

template<class Abel> struct WeightedUnionFind {
    int N;
    vector<int> parents;
    vector<Abel> diff_weight;

    WeightedUnionFind(int _N,Abel unit = 0) :N(_N){
        parents = vector<int>(N,-1);
        diff_weight = vector<Abel>(N,unit);
    }

    int find(int x) {
        if (parents[x] < 0) return x;
        else {
            int p = find(parents[x]);
            diff_weight[x] += diff_weight[parents[x]];
            return parents[x] = p;
        }
    }

    Abel weight(int x) {
        find(x);
        return diff_weight[x];
    }

    Abel diff(int x,int y) {//xとyが同じグループであることを確認してから呼ぶ
        return weight(y) - weight(x);
    }

    bool unite(int x, int y,Abel w) {
        w += weight(x);
        w -= weight(y);

        x = find(x);
        y = find(y);
        if (x == y) {
            if (diff(x,y) == w) return true;
            else return false;
        }

        if (parents[x] > parents[y]) {
            swap(x,y);
            w *= -1;
        }

        parents[x] += parents[y];
        parents[y] = x;
        diff_weight[y] = w;
        return true;
    }

    bool same(int x,int y) {
        return find(x) == find(y);
    }

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

int main() {
    int n,m; cin >> n >> m;
    WeightedUnionFind<ll> uf(n);
    bool flag = true;

    for (int i = 0;i < m;i++) {
        int l,r,d; cin >> l >> r >> d;
        l --; r--;
        if (!uf.unite(l,r,d)) {
            flag = false;
            break;
        }
    } 
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;  
}

Measured memory_bytes: 1408
s = input()
s_set = set(list(s))
alphabet = [chr(i) for i in range(97,97+26)]#int to alphabet
#Alphabet = [chi(i) for i in range(65,65+26)]
alphabet_set = set(alphabet)
nokori = alphabet_set - s_set
nokori_sort = sorted(list(nokori))
if len(nokori_sort) == 0:
	print("None")
	exit()
print(nokori_sort[0])



Measured memory_bytes: 3956
#include<iostream>
using namespace std;
int main(){
  int CD,money,oo,go,ooo;
  while(1){
    cin >> CD >> money;
    if(CD==0 && money==0){
      break;
    }
    oo=0;
    go=0;
    ooo=0;

    money-=CD;

    while(money!=0){
      if(money>=1000){
	money-=1000;
	ooo++;
      }
      else if(money>=500){
	money-=500;
	go++;
      }
      else if(money>=100){
	money-=100;
	oo++;
      }
    }
    cout << oo << " " << go << " " << ooo << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int n,m;
int MAX(int stx,int sty,vector<vector<int>> &k){
  queue<pair<int,int>> u;
  vector<vector<int>> ans(m,vector<int>(n,-1));
  pair<int,int> st;
  st=make_pair(stx,sty);
  u.push(st);
  ans.at(stx).at(sty)=0;
  int finans=0;
  while(u.size()!=0){
    pair<int,int> tmp=u.front();
    u.pop();
    int a,b;
    tie(a,b)=tmp;
    int tmp_ans=ans.at(a).at(b);
    if(a<m-1){
      if(k.at(a+1).at(b)==1&&ans.at(a+1).at(b)==-1){
        ans.at(a+1).at(b)=tmp_ans+1;
        finans=max(tmp_ans+1,finans);
        pair<int,int> z=make_pair(a+1,b);
        u.push(z);
      }
    }  
    if(a>0){
      if(k.at(a-1).at(b)==1&&ans.at(a-1).at(b)==-1){
        ans.at(a-1).at(b)=tmp_ans+1;
        finans=max(tmp_ans+1,finans);
        pair<int,int> z=make_pair(a-1,b);
        u.push(z);
      }
    }
    if(b<n-1){
      if(k.at(a).at(b+1)==1&&ans.at(a).at(b+1)==-1){
        ans.at(a).at(b+1)=tmp_ans+1;
        finans=max(tmp_ans+1,finans);
        pair<int,int> z=make_pair(a,b+1);
        u.push(z);
      }
    }  
    if(b>0){
      if(k.at(a).at(b-1)==1&&ans.at(a).at(b-1)==-1){
        ans.at(a).at(b-1)=tmp_ans+1;
        finans=max(tmp_ans+1,finans);
        pair<int,int> z=make_pair(a,b-1);
        u.push(z);
      }
    }  
  }
  return finans;
}
int main(){
  cin >> n >> m;
  int stx,sty;
  vector<vector<int>> k(m,vector<int>(n,1));
  rep(i,n){
    rep(j,m){
      int tmp;
      char t;
      cin >> t;
      if(t=='#'){
        k.at(j).at(i)=0;
      }
    }
  }
  int finfinans=0;
  rep(i,n){
    rep(j,m){
      if(k[j][i]==0) continue;
      finfinans=max(finfinans,MAX(j,i,k));
    }
  }
  
  cout << finfinans << endl;
}


Measured memory_bytes: 256
N = int(input())
t = [0] * (N+1)
x = [0] * (N+1)
y = [0] * (N+1)
for i in range(N):
    t[i+1], x[i+1], y[i+1] = map(int, input().split())
    
f = True
for i in range(N):
    dt = t[i+1] - t[i]
    dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    if dt < dist:
        f = False
    if dist%2 != dt%2:
        f = False

print('Yes' if f else 'No')

Measured memory_bytes: 11636
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n, x;
  cin >> n >> x;
  vector<int> m(n, 0);
  
  rep(i, n){
    cin >> m[i];
    x -= m[i];
  }

  sort(m.begin(), m.end());
  
  cout << n + x / m[0] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  double max, min;
  double x = 0.;
  int out;

  out = scanf ( "%lf", &x );
  min = max = x;
  while ( out == 1 )
  {
    if ( x > max )
      max = x;

    if ( x < min )
      min = x;

    out = scanf ( " %lf", &x );
  }

  printf ( "%lf\n", max - min );

  return ( 0 );
}

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

class Mondai
{
    struct Sw
    {
        public List<int> list;
        public Sw(int index) {
            list = new List<int>();
        }
    }
    static void Main()
    {
        var nm= Console.ReadLine().Split(' ').Select(x=>Int32.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var sw = new Sw[M];
        for (int i=0;i<M;++i)
        {
            var input = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            sw[i]=new Sw(i);
            for (int j=0;j<input[0];++j)
            {
                sw[i].list.Add(input[j+1]);
            }
        }
        var p= Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var ans = 0;
        var count = Math.Pow(2,N);
        for (int i=0;i<count;++i)
        {
            var b = new bool[N];
            for (int j = 0; j < N; j++)
            {
                b[j] = ((1 & i >> j) == 1);
            }
            var flg = true;
            for (int k=0;k<M;++k)
            {
                var target = sw[k];
                var c = 0;
                for (int l=0;l<target.list.Count();++l)
                {
                    if (b[target.list[l] - 1]) c++;
                }
                if (c % 2 != p[k])
                {
                    flg = false;
                    break;
                }
            }
            if (flg) ans++;
        }
        Console.WriteLine(ans);
    }
}   

Measured memory_bytes: 13396
def main():
    H = [int(i) for i in open(0).read().split()[1:]]
    ans = 0
    tmp = 0
    for h1, h2 in zip(H[:-1], H[1:]):
        if h1 >= h2:
            tmp += 1
        else:
            if ans < tmp:
                ans = tmp
            tmp = 0
    if ans < tmp:
        ans = tmp
    print(ans)
    return


main()


Measured memory_bytes: 14092
def main():
    ss = input()
    put_stone = ''
    count = 0
    for stone in ss:
        if put_stone != '' and put_stone == stone:
            count += 1
        if stone == 'B':
            put_stone = 'W'
        else:
            put_stone = 'B'
    print(count)

if __name__ == '__main__':
    main()

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 059 D / Link: http://abc059.contest.atcoder.jp/tasks/abc059_d  ----- */

const int WIN = 1, LOSE = 2;
int memo[102][102][2];



int f(int a, int b, bool p) {
	if (memo[a][b][p])return memo[a][b][p];

	bool gotolose = 0;
	for (int i = 1; 2 * i <= a; i ++) {
		int res = f(a - 2 * i, b + i, !p);
		if (res == LOSE)gotolose = 1;
	}
	for (int i = 1; 2 * i <= b; i ++) {
		int res = f(a + i, b - 2 * i, !p);
		if (res == LOSE)gotolose = 1;
	}



	return memo[a][b][p] = (gotolose ? WIN : LOSE);

}


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

	LL X, Y; cin >> X >> Y;
	if (abs(X - Y) > 1) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Brown" << endl;
	}
	if (0) {
		FOR(i, 0, 51) {
			FOR(j, 0, 51) {
				int res = f(i, j, 0);
				cout << "WL"[res == LOSE];
			}cout << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define max 100000

int A[max],n;

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

int main(){
    int i,q;
    cin >> n;
    for (i=0; i<n;i++){
        cin>>A[i];
    }
    q = partition(0,n-1);
    for (i = 0; i< n; i++){
        if (i>0) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3392
#include<stdio.h>

#define N 100000

int partition(int *, int, int);

int main()
{
  int i, n, j;
  int A[N];

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%d", &A[i]);
    }

  j = partition(A, 0, n-1);

  for(i=0; i<n; i++)
    {
      if(i==j)
	{
	  printf("[%d]", A[i]);
	}
      else
	printf("%d", A[i]);
      
      if(i+1<n) printf(" ");
    }
  printf("\n");
  
  return 0;
}

int partition(int *A, int p, int r)
{
  int x, i, j, t;

  x = A[r];
  i = p-1;

  for(j=p; j<r; j++)
    {
      if(A[j] <= x)
	{
	  i++;
	  t = A[i];
	  A[i] = A[j];
	  A[j] = t;
	}
    }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;
}

Measured memory_bytes: 992
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
template <typename T = int>
T in() {
    T temp; cin >> temp; return temp;
}

template <typename VType = int>
list<VType> const LR(VType start, VType end) {
    list<VType> ret; for (VType i = start; i < end; i++) ret.push_back(i); return move(ret);
}

int main() {
    int N(in());
    map<string, map<int, int>> rest;
    for (int i = 0; i < N; i++) {
        string city(in<string>());
        int score(in());
        auto ite = rest.find(city);
        if (ite != rest.end()) {
            ite->second.insert(pair<int, int>(score, i + 1));
        } else {
            map<int, int> temp;
            temp.insert(pair<int, int>(score, i + 1));
            rest.insert(pair<string, map<int, int>>(city, temp));
        }
    }

    for (auto ite1 : rest) {
        auto ite2 = ite1.second.cend();
        do {
            ite2--;
            cout << ite2->second << endl;            
        } while (ite2 != ite1.second.cbegin());
    }

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>

using namespace std;
typedef long long int ll;
void sayYes() { cout << "Yes" << endl; };
void sayNo() { cout << "No" << endl; };
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define rep(i, n) for (ll i = 0; i < n; i++)

void Main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    int ans = 0;

    rep(i, n)
    {
        for (int j = i + 1; j < n; j++)
        {
            ans += a[i] * a[j];
        }
    }

    cout << ans << endl;
    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define inf 1000000007
#define inf16 0x3f3f3f3f
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

const int N = 107;

int n, ans;

int u[N];
int l[N];

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

	cin >> n;

	for(int i = 1; i <= n; ++i)
	{
		cin >> u[i];
		u[i] += u[i-1];
	}

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

	for(int i = n; i >= 1; --i)
	{
		l[i] += l[i+1];
		ans = max(ans, l[i]+u[i]);
	}

	cout << ans;
}

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

void solve() {
	int c, a, n;
	cin >> c >> a >> n;
	int cnt = 0;
	while (c && a && n) {
		c--; a--; n--;
		cnt++;
	}
	while (c >= 2 && a) {
		c -= 2; a--;
		cnt++;
	}
	while (c >= 3) {
		c -= 3;
		cnt++;
	}
	cout << cnt << endl;
}

int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	var (
		slice = strings.Split(s, "")
		flag0 = 0.0
		flag1 = 0.0
	)
	for _, x := range slice {
		if x == "0" {
			flag0++
		} else {
			flag1++
		}
	}

	answer := math.Min(flag0, flag1) * 2
	fmt.Println(answer)
}


Measured memory_bytes: 2944
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
Sss = [input().rstrip() for _ in range(N)]

cnt = Counter(Sss)
#print('cnt:', cnt)

ress = ['AC', 'WA', 'TLE', 'RE']
for res in ress:
    print(res + ' x ' + str(cnt[res]))


Measured memory_bytes: 16616
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    int N, count=0;
    string S;
    char last='A';
    cin>>N>>S;
    rep(i, N){
        if(last != S[i]) count++;
        last = S[i];
    }
    cout <<count <<endl;
    return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define lp(i,n) for(int i=0;i<n;i++)
#include<bits/stdc++.h>


using namespace std;
int main() {
	char c[3][3],ans[3];
	lp(i, 3) {
		lp(j, 3) {
			cin >> c[i][j];
		}
	}
	lp(i, 3) {
		cout << c[i][i];
	}
	cout<<endl;

	return 0;

}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
a_list = []
point_list = [0] * n

for i in range(q):
    a_list.append(int(input()))

for i in a_list:
    point_list[i-1] += 1

for i in range(n):
    if q - k - point_list[i] < 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 8636
n, m = gets.split.map(&:to_i)

list = ((n == 1 ? "0" : "1" << ("0" * n.pred))...("1" << ("0" * n))).lazy

m.times do
  s, c = gets.split
  list = list.select { |str| str[s.to_i-1] == c }
end

puts list.first || -1


Measured memory_bytes: 1788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String ans = "YES";
    int p = s.length() - 1;
    while(p >= 0) {
      if(s.charAt(p) == 'm') {
        if((s.charAt(p - 1) == 'a') && (s.charAt(p - 2) == 'e') && (s.charAt(p - 3) == 'r') && (s.charAt(p - 4) == 'd')) {
          p -= 5;
        } else {
          ans = "NO";
          break;
        }
      } else if(s.charAt(p) == 'e') {
        if((s.charAt(p - 1) == 's') && (s.charAt(p - 2) == 'a') && (s.charAt(p - 3) == 'r') && (s.charAt(p - 4) == 'e')) {
          p -= 5;
        } else {
          ans = "NO";
          break;
        }
      } else {
        if((s.charAt(p) == 'r') && (s.charAt(p - 1) == 'e') && (s.charAt(p - 2) == 'm') && (s.charAt(p - 3) == 'a') && (s.charAt(p - 4) == 'e') && (s.charAt(p - 5) == 'r') && (s.charAt(p - 6) == 'd')) {
          p -= 7;
        } else if((s.charAt(p) == 'r') && (s.charAt(p - 1) == 'e') && (s.charAt(p - 2) == 's') && (s.charAt(p - 3) == 'a') && (s.charAt(p - 4) == 'r') && (s.charAt(p - 5) == 'e')) {
          p -= 6;
        } else {
          ans = "NO";
          break;
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 39184
from collections import deque


def main():
    side = 0
    S = input()
    len_s = len(S)
   
    d = deque()
    for s in S:
        d.append(s)
   
    n = int(input())
    for i in range(n):
        q = input().split()
        if len(q) == 1:
            side += 1
        elif len(q) == 3:
            len_s += 1
            if side % 2 == 0:
                if q[1] == "1":
                    d.appendleft(q[2])
                else:
                    d.append(q[2])
            else:
                if q[1] == "1":
                    d.append(q[2])
                else:
                    d.appendleft(q[2])
    S = ""
    if side % 2 == 0:
        for i in range(len_s):
            S += d.popleft()
    else:
        for i in range(len_s):
            S += d.pop()
 
    print(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6292
# -*- coding: utf-8 -*-

N,K = list(map(int, input().rstrip().split()))
#-----

sunuke_dic = {}

for i in range(1,K+1):
    d = int(input().strip())
    A_list = list(map(int, input().rstrip().split()))
    
    for a in A_list:
        sunuke_dic.setdefault(a,[])
        sunuke_dic[a].append(i)


cnt = 0
for i in range(1,N+1):
    if i not in sunuke_dic:
        cnt += 1


print(cnt)


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int64_t> A(n);
    copy_n(istream_iterator<int64_t>(cin), n, A.begin());

    vector<int64_t> B;
    for (int l = 0; l < n; l++){
        int64_t S = 0;
        for (int r = l; r < n; r++){
            S += A[r];
            B.push_back(S);
        }
    }

    vector<bool> gomi(B.size());
    int64_t ans = 0;

    for (int64_t i = 62; i >= 0; i--){
        int cnt = 0;
        for (int j = 0; j < B.size(); j++){
            if (gomi[j])
                continue;
            if (B[j] >> i & 1)
                cnt++;
        }
        if (cnt < k)
            continue;
        ans += 1L << i;
        for (int j = 0; j < B.size(); j++)
            gomi[j] = gomi[j] or !(B[j] >> i & 1);
    }

    cout << ans << endl;
}


Measured memory_bytes: 6260
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	ll a[n];
	rep(i,n)cin>>a[i];
	ll ans=0;
	REP(i,1,n-1){
		map<int,int> mp;
		ll ret=0;
		for(int j=0;j<n;j+=i){
			if(n-1-j<i)break;
			ret+=a[j];
			if(++mp[j]==2)ret=-longinf;
			ret+=a[n-1-j];
			if(++mp[n-1-j]==2)ret=-longinf;
			ans=max(ans,ret);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7808
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,t = readline() |> split |> parseMap
    a = Tuple{Int,Int}[(0,0) for i in 1:n]
    for i in 1:n
        p,q = readline() |> split |> parseMap
        a[i] = (p,q)
    end
    a = sort(a,by=x->x[1])
    dp = -ones(Int,n+1,t+1)
    dp[1,1] = 0
    for i in 1:n
        for j in 1:t
            if dp[i,j]>-1
                dp[i+1,j] = max(dp[i+1,j],dp[i,j])
                dp[i+1,min(j+a[i][1],t+1)] = max(dp[i+1,min(j+a[i][1],t+1)], dp[i,j]+a[i][2])
            end
        end
    end
    println(maximum(dp))
end
main()

Measured memory_bytes: 259680
n = int(input())
a = 10**9+7
if n==1:
    print(0)
else:
    ans = 1
    b = 1
    c = 1
    for _ in range(n):
        b *= 9
        c *= 8
        b %= a
        c %= a
        ans *= 10
        ans %= a
    ans = (ans-2*b+c)%a
    if ans< 0:
        ans += a
    print(ans)

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int k,x;
	cin >>  k >> x;
	if(k*500 < x){
		cout << "No";
	}else{
		cout << "Yes";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	priority_queue<int>q;    //优先队列自动从大到小排序
	int m,n,t;
	cin >>n>>m;
	for(int i=0;i<n;i++){
		cin>>t;
		q.push(t);    //每输入一个数都入队
	}
	long long sum=0;
	while(m){
		t=q.top()/2;
		q.pop();
		q.push(t);
		m--;
	}
	while(!q.empty()){
		sum+=q.top();
		q.pop();
	}
	cout<<sum;    //输出都处理完的总和
	return 0;
}


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

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz){ }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    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)]; }
    int size() { return sz; }
};

int main() {
  int n, q;
  cin >> n >> q;
  vector<int> com(q), x(q), y(q);
  for (int i = 0; i < q; i++) {
    cin >> com[i] >> x[i] >> y[i];
  }
  UnionFind uf(n);
  for (int i = 0; i < q; i++) {
    if (com[i] == 0) {
      uf.unionSet(x[i], y[i]);
    }
    else {
      if (uf.findSet(x[i], y[i])) {
        cout << 1 << endl;
      }
      else {
        cout << 0 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4040
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 100000;

struct edge{
	int to; edge *nxt;
}edges[2*MAXN + 5], *adj[MAXN + 5], *ecnt = edges;
void addedge(int u, int v) {
	edge *p = (++ecnt);
	p->to = v, p->nxt = adj[u], adj[u] = p;
	p = (++ecnt);
	p->to = u, p->nxt = adj[v], adj[v] = p;
}

int deg[MAXN + 5], tmp[MAXN + 5];
int ans[MAXN + 5], a[MAXN + 5], cnt;
void dfs(int x, int f) {
	if( !f ) a[++cnt] = 1;
	int p = cnt + 1;
	for(int i=1;i<=deg[x]-2;i++)
		cnt++, a[cnt] = cnt + 1;
	a[++cnt] = p;
	if( f && tmp[x] == 1 ) cnt++, a[cnt] = cnt;
	for(edge *p=adj[x];p;p=p->nxt)
		if( deg[p->to] != 1 && p->to != f ) dfs(p->to, x);
}
void update() {
	for(int i=1;i<=cnt;i++) {
		if( ans[i] < a[i] ) break;
		else if( ans[i] > a[i] ) {
			for(int j=1;j<=cnt;j++)
				ans[j] = a[j];
			break;
		}
	}
	cnt = 0;
}

int main() {
	int n; scanf("%d", &n);
	for(int i=1;i<n;i++) {
		int u, v; scanf("%d%d", &u, &v);
		addedge(u, v), deg[u]++, deg[v]++;
	}
	
	if( n == 2 ) {
		printf("%d %d\n", 1, 2);
		return 0;
	}
	for(int i=1;i<=n;i++) tmp[i] = deg[i];
	for(int i=1;i<=n;i++)
		if( deg[i] == 1 ) tmp[adj[i]->to]--;
	for(int i=1;i<=n;i++)
		if( deg[i] != 1 && tmp[i] > 2 ) {
			puts("-1");
			return 0;
		}
	
	int s = 0, t = 0;
	for(int i=1;i<=n;i++)
		if( deg[i] != 1 && tmp[i] == 1 ) {
			if( !s ) s = i;
			else t = i;
		}
	if( t == 0 ) {
		printf("1");
		for(int i=3;i<n;i++)
			printf(" %d", i);
		printf(" %d %d\n", 2, n);
	}
	else {
		for(int i=1;i<=n;i++) ans[i] = n - i + 1;
		dfs(s, 0), update(), dfs(t, 0), update();
		for(int i=1;i<=n;i++)
			printf("%d%c", ans[i], i == n ? '\n' : ' ');
	}
}

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

class Task implements Comparable<Task>{
    int amount;
    int deadline;
    public Task(int a, int d){
        this.amount=a;
        this.deadline=d;
    }
    public int compareTo(Task another){
        return this.deadline-another.deadline;
    }
    public String toString(){
        return "["+amount+" "+deadline+"]";
    }
}
public class Main {
    static void possible(){
        System.out.println("Yes");
        System.exit(0);
    }
    static void impossible(){
        System.out.println("No");
        System.exit(0);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Task[] task = new Task[N];
        for(int n=0; n<N; n++){
            task[n] = new Task(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(task);

        long curTime = 0;
        for(int n=0; n<N; n++){
            curTime += task[n].amount;
            if(curTime>task[n].deadline) impossible();
        }
        possible();
    }
}

Measured memory_bytes: 105276
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in).useDelimiter("(\\s|,)+");
		char posi = 'A';
		while (in.hasNext()) {
			char c1 = in.next().charAt(0);
			char c2 = in.next().charAt(0);
			if (c1 == posi) {
				posi = c2;
			} else if (c2 == posi) {
				posi = c1;
			}
		}
		System.out.println(posi);
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll number(string t){
    ll ans = 0;
    for(auto u : t){
        ans*=10;
        ans+=u-'0';
    }
    return ans;
}
int main(){
    string s;
    cin>>s;
    ll ans = 0;
    rep(i,1<<(s.size()-1)){
        ll now = 0;
        int left = 0;
        int right = 0;
        rep(j,s.size()-1){
            if((i>>j)&1){
                string ss = s.substr(left,right-left+1);
                now+=number(ss);
                left = right = j+1;
            }else{
                right++;
            }
        }
        now += number(s.substr(left));
        ans+=now;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    rep(i,s.size()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3824
# A  ¥500
# B  ¥100
# C  ¥50
# X  sum

a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

r = []

(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      if i * 500 + j * 100 + k * 50 == x
        r << [i, j, k]
      end
    end
  end
end

puts r.count


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

int main(){

    int a,b;
    int ans=0;
    string temp;


    cin>>a>>b;

    for(int i=a;i<=b;i++){

        temp=to_string(i);
        if(temp[0]==temp[4]&&temp[1]==temp[3]) ans++;

    }

    cout<<ans<<endl;





    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
  }

  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j < m; j++) {
      if (a.at(j) == i + 1) {
        cnt++;
      }
      if (b.at(j) == i + 1) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef long long ll;
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
#define LAR(a, b) ((a)=max((a), (b)))
#define SML(a, b) ((a)=min((a), (b)))

typedef long double ld;
int main(){
	int w, h, x, y; scanf("%d%d%d%d", &w, &h, &x, &y);
	ld a = ((ld)w)*h/2;
	int b = (x*2==w && y*2==h) ? 1 : 0;
	printf("%.10Lf %d\n", a, b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> rec = a;
	sort(a.begin(), a.end());
	int res1 = a[n / 2 - 1];
	int res2 = a[n / 2];
	rep(i, n) {
		if (rec[i] <= res1) {
			printf("%d\n", res2);
		}
		else printf("%d\n", res1);
	}
	return 0;
}


Measured memory_bytes: 3840
honsu = input()


if(honsu[-1]=='2' or honsu[-1]=='4' or honsu[-1]=='5' or honsu[-1]=='7' or honsu[-1]=='9'):
  print('hon')
elif(honsu[-1]=='0' or honsu[-1]=='1' or honsu[-1]=='6' or honsu[-1]=='8'):
  print('pon')
else:
  print('bon')

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

using namespace std;

int main()
{
    int n,a;
    cin>>n;
    int mn=1e9,mx=0;
    while(n--)
    {
        cin>>a;
        mn = min(mn,a);
        mx = max(mx,a);
    }
    cout<<mx-mn<<endl;
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<long double> a(n+1);
    vector<vector<long double> > dp(n+1);
    for (auto &v : dp) v.resize(n+1);
    for (int i = 1; i <= n; i++) cin >> a[i];
    dp[0][0] = (long double) 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (!j) dp[i][j] = dp[i-1][j] * (long double) ((long double) 1 - a[i]);
            else dp[i][j] = dp[i-1][j-1] * a[i] + dp[i-1][j] * (long double) ((long double) 1 - a[i]);
        }
    }
    long double ans = 0;
    for (int i = n/2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }
    cout << setprecision(10) << ans << "\n";
    return 0;
}


Measured memory_bytes: 141056
#include <stdio.h>

void Input(void);
int Operation(void);

int cnt[10];

int main(void)
{
  Input();
  printf("%s\n", Operation() ? "YES" : "NO");
  
  return 0;
}

void Input(void)
{
  int i, tmp;
  for(i = 1; i <= 3; i++)
  {
    scanf("%d", &tmp);
    cnt[tmp]++;
  }
 }

int Operation(void)
{
  if(cnt[5] == 2 && cnt[7] == 1) return 1;
  return 0;
}

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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

int main()
{
    Fast_IO();
    ll n; cin >> n;
    ll freq[n+1]; f(i,1,n) freq[i] = 0;
    f(x,1,100) f(y,1,100) f(z,1,100) {
    	ll N = x * x + y * y + z * z + x * y + y * z + x * z;
    	if(N <= n && N >= 1) freq[N]++;
    }
    f(i,1,n) cout << freq[i] << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=5000000000000000000;
ll MOD=1000000007;

int main() {
    int n,k;
    cin >> n >> k;
    vector<pair<ll,ll>> a(n);
    rep(i,n) cin >> a.at(i).first >> a.at(i).second;
    sort(a.begin(),a.end());
    ll ans=INF;
    for (int i=0;i<n;i++){
        vector<ll> x(0),y(0);
        for (int j=i;j<n;j++){
            ll e=INF;
            x.push_back(a.at(j).first);
            y.push_back(a.at(j).second);
            if (x.size()<k) continue;
            sort(y.begin(),y.end());
            for (int l=0;l<y.size()-k+1;l++){
                e=min(e,y.at(l+k-1)-y.at(l));
            }
            ans=min(ans,e*(x.at(x.size()-1)-x.at(0)));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int n, m;
	scanf("%d %d",&n,&m);
	int i,a[50],b[50],c[50],d[50];
	for(i=0;i<n;i++){scanf("%d %d",&a[i],&b[i]);}
	for(i=0;i<m;i++){scanf("%d %d",&c[i],&d[i]);}
	int j;
	for(i=0;i<n;i++){
		int ab=abs(a[i]-c[0])+abs(b[i]-d[0]), e=1;
		for(j=0;j<m;j++){
			int k=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(k<ab){ab=k;e=j+1;}
		}
		printf("%d\n",e);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

vector<int> ans;
vector<vector<int>> G;
vector<int> p;

pair<int, int> grundy(vector<int> &a){
    int mx = *max_element(a.begin(), a.end());
    vector<bool> flag(mx+1, false);
    for(int x : a) {
        if(x == -1) continue;
        flag[x] = true;
    }
    pair<int, int> ret = pair<int, int>(-1, -1);
    for(int i=0; i<=mx; i++){
        if(!flag[i]){
            if(ret.first == -1) ret.first = i;
            else{
                ret.second = i;
                break;
            }
        }
    }
    if(ret.first == -1) ret.first = mx+1;
    if(ret.second == -1) ret.second = mx+1;
    if(ret.second == ret.first) ret.second++;
    return ret;
}

void setOutside(int s){
    if(ans[s] != -1) return;
    if(G[s].empty()){
        ans[s] = 0;
        return;
    }

    vector<int> nums;
    for(int t : G[s]){
        setOutside(t);
        nums.push_back(ans[t]);
    }
    pair<int, int> gr = grundy(nums);
    ans[s] = gr.first;
}


bool judge(int s){
    int t = s;
    while(true){
        t = p[t];
        if(t == s) break;
        vector<int> nums;
        for(int tt : G[t]) nums.push_back(ans[tt]);

        pair<int, int> gr = grundy(nums);
        ans[t] = gr.first;
    }
    vector<int> nums;
    for(int tt : G[s]) nums.push_back(ans[tt]);
    pair<int, int> gr = grundy(nums);

    if(ans[s] == gr.first) return true;
    return false;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    ans.resize(N, -1);
    G.resize(N);
    p.resize(N);

    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]--;
        G[p[i]].push_back(i);
    }

    vector<int> visit(N);
    int s = 0;
    for(int i=0; i<2*N; i++){
        visit[s]++;
        s = p[s];
    }

    vector<bool> isInCircle(N, false);
    for(int i=0; i<N; i++)
        if(visit[i] >= 2)
            isInCircle[i] = true;

    for(int i=0; i<N; i++){
        if(isInCircle[i]) continue;
        setOutside(i);
    }

    for(int i=0; i<N; i++)
        if(isInCircle[i]){
            s = i;
            break;
        }

    vector<int> nums;
    for(int t : G[s]) nums.push_back(ans[t]);
    pair<int, int> gr = grundy(nums);

    ans[s] = gr.first;
    if(judge(s)){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    ans[s] = gr.second;
    if(judge(s)){
        cout << "POSSIBLE" << endl;
        return 0;
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

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


int main() {
    long long x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    long long subt = x / d;
    subt = min(subt,k);
    k-=subt;
    x = x - d*subt;
    long long mn = x;
    if(k % 2 == 0)k = 0;
    else {
        x-=d;
        mn = x;
    }
    cout<<abs(mn)<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <cmath>
#include <iostream>
#include <iomanip>

const double PI=4.0*std::atan(1.0);

int main(){
  double a, b, x;
  std::cin >> a >> b >> x;

  x /= a;
  double ans;
  if(x >= 0.5*a*b){
    double xb = x/a;
    double db = (b-xb)*2.0;
    ans = std::atan2(db, a)/PI*180.0;
  }else{
    double da = x/b*2.0;
    ans = std::atan2(b, da)/PI*180.0;
  }

  std::cout << std::fixed << std::setprecision(10) << ans << std::endl;


  return 0;
}



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

int main() {
  ll N, W;
  cin >> N >> W;

  vector<vector<ll>> a(4);
  ll w0 = 0;
  vector<ll> w(N + 1), v(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
    if(i == 1) w0 = w[i];
    int itr = w[i] - w0;
    a[itr].push_back(v[i]);
  }
  for (int i = 0; i < 4; i++) {
    sort(a[i].rbegin(),a[i].rend());
    a[i].insert(a[i].begin() + 0,0);
  }
  for (int i = 0; i < 4; i++) {
    for (int j = 1; j < (int)a[i].size(); j++) {
      a[i][j] += a[i][j - 1];
    }
  }
  ll ans = 0;
  for (int i = 0; i < (int)a[0].size(); i++) {
    for (int j = 0; j < (int)a[1].size(); j++) {
      for (int k = 0; k < (int)a[2].size(); k++) {
        for (int l = 0; l < (int)a[3].size(); l++) {
          ll sum = w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l;
          if (sum > W) break;
          ll tmp = a[0][i] + a[1][j] + a[2][k] + a[3][l];
          ans = max(ans, tmp);
        }
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
//push_back
 
vector <ll int> v[100001];
ll int vis[100001];
ll int dist[100001];
 
 
void bfs(ll int src){
	queue<int>q;
	q.push(src);
	vis[src] = 1;
	dist[src] = 0;
 
	while(!q.empty()){
		int curr = q.front();
		q.pop();
 
		for(ll int child: v[curr]){
			q.push(child);
			dist[child] = dist[curr]+1;
			vis[child] = 1;
		}
	}
}
 
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
 	
	int x,a;
	cin>>x>>a;

	if(x < a)
		cout<<0;
	else
		cout<<10;
	
}

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

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string s;
	while(cin >> s)
	{
		bool flag = true;
		for(int i=0;i<7;i += 3)
		{
			if(s[i] != 's' && s[i] == s[i+1] && s[i+1] == s[i+2])
			{
				cout << s[i] << endl;
				flag = false;
				break;
			}
		}

		if(flag)
		{
			rep(i,3)
			{
				if(s[i] != 's' && s[i] == s[i+3] && s[i+3] == s[i+6])
				{
					cout << s[i] << endl;
					flag = false;
					break;
				}
			}
		}

		if(flag)
		{
			if(s[0] != 's' && s[0] == s[4] && s[4] == s[8])
			{
				cout << s[0] << endl;
				flag = false;
			}
		}

		if(flag)
		{
			if(s[2] != 's' && s[2] == s[4] && s[4] == s[6])
			{
				cout << s[2] << endl;
				flag = false;
			}
		}

		if(flag)
		{
			cout << "d" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1176
#include<stdio.h>
int main() {
	int  n,i,data[1000];
	scanf("%d", &n);
	for (i = 1; i <=n; i++) {
		scanf("%d", &data[i]);
	}
	for (i = n; 1 < i; i--) {
		printf("%d ", data[i]);
	}
	printf("%d\n", data[i]);
	return 0;
}


Measured memory_bytes: 2660
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [H, N] = r.nn()
    const A: { cost: number; power: number }[] = []

    const dp: number[] = []

    dp[0] = 0

    for (let i = 0; i < N; i++) {
      const [power, cost] = r.nn()

      A.push({ power, cost })
    }

    A.sort((a, b) => b.power / b.cost - a.power / a.cost)

    let min = Infinity

    // console.log(A)

    A.forEach(({ power, cost }) => {
      for (let i = 0; i < H; i++) {
        if (dp[i] === undefined) continue
        const newCost = dp[i] + cost

        if (i + power >= H) {
          min = Math.min(min, newCost)
          return
        }
        if (dp[i + power] === undefined) {
          dp[i + power] = newCost
        }
        dp[i + power] = Math.min(dp[i + power], newCost)
        // console.log(dp[i])
        // console.log(cost)
        // console.log(dp[i] + cost)
      }
    })
    // console.log(dp)

    return min
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


Measured memory_bytes: 8116
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(a: int, b: int):
    A = str(a) * b
    B = str(b) * a
    print(min(A, B))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
int m,n;
char a[120][120];
int dx[]={0,0,1,1,1,-1,-1,-1};
int dy[]={1,-1,0,1,-1,0,1,-1};
int main(){
	cin>>m>>n;
	for(int i=1;i<=m;i++)
		scanf("%s",a[i]+1);
	for(int i=1;i<=m;i++)
		for(int j=1;j<=n;j++)
			if(a[i][j]=='.'){
				int  cnt=0;
				for(int q=0;q<=7;q++){
					if(a[i+dx[q]][j+dy[q]]=='#')
						cnt++;
				}
				a[i][j]=cnt+'0';
			}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++)
			cout<<a[i][j];
		cout<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 256
#include <stdio.h>

int s[1000000], n;

int binary(int);
int main()
{
    int i, k, q, sum = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &s[i]);
    scanf("%d", &q);
    for (i = 0; i < q; i++)
    {
        scanf("%d", &k);
        if (binary(k))
            sum++;
    }
    printf("%d\n", sum);
    return 0;
}
int binary(int k)
{
    int left = 0, right = n, mid;
    while (left < right)
    {
        mid = (left + right) / 2;
        if (k == s[mid])
            return 1;
        if (k > s[mid])
            left = mid + 1;
        else if (k < s[mid])
            right = mid;
    }
    return 0;
}


Measured memory_bytes: 2172
import math

n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i], y[i] = map(int, input().split())

s = 0.0
for i in range(n-1):
    for j in range(i+1, n):
        s += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
        #print("i:", i,"j:", j, "s:", s)

print(2*s/n)

Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void) {
    int a[4],b[4];
    int hit,brow;
    int i,j;
    while(!feof(stdin)) {
        if(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])==-1)break;
        scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
        hit=0;brow=0;
        for(i=0;i<4;i++) {
            if(a[i]==b[i]) {
                hit++;
                a[i]=-1;
                b[i]=-1;
            }
        }
        for(i=0;i<4;i++) {
            if(a[i]==-1)continue;
            for(j=0;j<4;j++) {
                if(j==i)continue;
                if(a[i]==b[j]) {
                    brow++;
                    a[i]=-1;
                    b[j]=-1;
                    break;
                }
            }
        }
        printf("%d %d\n",hit,brow);
    }
    return 0;
}

Measured memory_bytes: 600