akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const ll INF = 1LL<<60;

vector<ll> dijkstra(int n, int s, vector<vector<P>> G) {
  priority_queue<P, vector<P>, greater<P> > que;
  vector<ll> d(n,INF);
  d[s] = 0;
  que.push(P(0,s));
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      int to = G[v][i].first;
      ll cost = G[v][i].second;
      if (d[to] > d[v] + cost) {
        d[to] = p.first + cost;
        que.push(P(d[to], to));
      }
    }
  }
  return d;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<vector<P> > G(n);
  rep(i,n) {
    int a;
    cin >> a;
    a--;
    G[i].emplace_back(P(a,1));
  }
  vector<ll> dist = dijkstra(n, 0, G);
  if (dist[1] == INF) cout << -1 << endl;
  else cout << dist[1] << endl;
  return 0;
}

Measured memory_bytes: 12032
N,K = map(int, input().split())
A = [(1+int(x))/2 for x in input().split()]
wa = []
w = 0
for i in range(0,K):
    w = w+A[i]
wa.append(w)
for j in range(N-K):
    w = w + A[j+K] - A[j]
    wa.append(w)
print(max(wa))


Measured memory_bytes: 22884
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,f=0,g=0;
	cin>>a>>b>>c;
	if(a==5)
		f++;
	if(a==7)
		g++;
	if(b==5)
		f++;
	if(b==7)
		g++;
	if(c==5)
		f++;
	if(c==7)
		g++;
		if(f==2&&g==1)
			cout<<"YES";
		else
			cout<<"NO";
	return 0;
}

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

const int INF = 1 << 12;

int main(){
  int N  ;
  cin >> N ;
  vector<int> W(N);
  for(int i = 0; i < N; i++) cin >> W[i];
  vector<int> XW(N + 1, 0);
  for(int i = 1; i <= N; i++) XW[i] = XW[i - 1] + W[i - 1];
  int ans = INF;
  for(int i = 1; i < N; i++) ans = min(ans, abs(XW[N] - 2 * XW[i]));
  
  cout << ans;
  
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N,M,X;
	scanf("%d %d %d",&N,&M,&X);

	int table[N+1];
	for(int i = 0; i <= N; i++){

		table[i] = 0;
	}

	int tmp;
	for(int i = 0; i < M; i++){

		scanf("%d",&tmp);
		table[tmp] = 1;
	}

	int L = 0, R = 0;

	for(int i = X-1; i >= 0; i--){

		L += table[i];
	}
	for(int i = X+1; i <= N; i++){

		R += table[i];
	}

	printf("%d\n",min(L,R));

	return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main()
{
    ll a,b,c,d,flag=0;
    cin>>a>>b>>c>>d;
  while(a>0 && c>0)
  {
    c=c-b;
    if(c<=0)
    {
      flag=1;
      break;
    }
    a=a-d;
  }
    if(flag==1)
      cout<<"Yes";
    else 
      cout<<"No";
    
 
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

main(){
  int n,m,i,j,u,tmp;
  int adj[101][101];

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

  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&m);
    for(j=1;j<=m;j++){
      scanf("%d",&tmp);
      adj[u][tmp]++;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",adj[i][j]);
      if(j<n)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 644
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int T = scanner.nextInt();
    for (int i = 0; i < T; i++) {
      long A = scanner.nextLong();
      long B = scanner.nextLong();
      long C = scanner.nextLong();
      long D = scanner.nextLong();
      if (solve(A, B, C, D)) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }

  static boolean solve(long A, long B, long C, long D) {
    if (A < B) return false;
    if (D < B) return false;
    if (C > B) return true;

    long gcd = gcd(B, D);
    long max = ((B - 1 - (A % B)) / gcd) * gcd + (A % B);
    return max <= C;
  }

  public static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    if (i == 0) return j;
    long r = j % i;
    return gcd(r, i);
  }
}


Measured memory_bytes: 23444
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 100005;
const int inf = 1e9;

int main(){__
	lli a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max({a*c,b*d,a*d,b*c}) << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int solve(int i,int m);


int n,q,A[2000],M[2000];

int main(){
  int i,j,ans,flag = 0;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++)
    scanf("%d",&A[i]);

  scanf("%d",&q);
  
  for(i = 0 ; i < q ; i++)
    scanf("%d",&M[i]);

  for(i = 0 ; i < q ; i++){
    flag = 0;
    for(j = 0 ; j < n ; j++){
      ans = solve(j,M[i]);
      if(ans == 0){
	flag = 1;
	printf("yes\n");
	break;
      }
      if(ans == 1){
	flag = 1;
	printf("no\n");
	break;
      }
    }
  }
  return 0;
}


int solve(int i, int m){
  int res1,res2;
  
  if(m == 0)
    return 0;
  
  if(i >= n)
    return 1;

  res1 = solve(i + 1, m);
  res2 = solve(i + 1,m - A[i]);

  if(res1 == 0 || res2 == 0) return 0;
  else return 1;
}

Measured memory_bytes: 588
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int p, q;
	REP(i, s.size()) {
		if (s[i] == 'A') {
			p = i;
			break;
		}
	}
	RREP(j, s.size()) {
		if (s[j] == 'Z') {
			q = j;
			break;
		}
	}
	cout << q - p+1 << endl;
		return 0;
}


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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

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;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

ps = []
for i in range(m):
  ps.append(input())

ans = [0] * (n+1)
pen = [0] * (n+1)
sum1 = 0
for i in range(m):
  p,s = ps[i].split()
  if ans[int(p)] == 0:
    if s == "AC" :
      ans[int(p)] += 1
      sum1 += pen[int(p)]
    else:
      pen[int(p)] += 1

print("{} {}".format(sum(ans),sum1))


Measured memory_bytes: 11676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for (int i = 1; i*i <= m; i++) {
        if (m % i == 0) {
            if (i <= m / n) ans = max(ans, i);
            if (i >= n) ans = max(ans, m / i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
long long D[N_];
int a, b, n, W;
int main() {
	int i, j;
	scanf("%d%d", &n,&W);
	for (i = 0; i <= 100000; i++)D[i] = 1e18;
	D[0] = 0;
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &a, &b);
		for (j = 1000 * i; j >= b; j--) {
			D[j] = min(D[j], D[j - b] + a);
		}
	}
	long long r = 0;
	for (i = 0; i <= 100000; i++)if (D[i] <= W)r = i;
	printf("%lld\n", r);
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    string N;
    cin >> N;

    int ans = 0;
    int l = (int)N.length();

    for (int i = l - 1; i >= 1; i--)
    {
        if (N[i] == '9')
        {
            ans += 9;
        }else
        {
            ans = (int)(N[0] - '0') - 1 + 9 * (l - 1);
            cout << ans << endl;
            return 0;
        }
        
    }
    
    ans += (int)(N[0] - '0');
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a = input()
b = input()
c = input()

cards = {'a': a, 'b': b, 'c': c}
turn = 'a'

while True:
    if len(cards[turn]) == 0:
        print(turn.upper())
        break
    draw = cards[turn][0]
    cards[turn] = cards[turn][1:]
    turn = draw


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    int n, sum;
    sum = 0;
    cin >> n;
    int v[n], c[n], s[n];
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    for (int i = 0; i < n; i++){
        cin >> c[i];
        s[i] = v[i] - c[i];
        if(s[i] > 0){
            sum += s[i];
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0


H,W,M = map(int,readline().split())

col = [0]*W
row = [0]*H
elements = []
for i in range(M):
    h,w = map(int,readline().split())
    h,w = h-1,w-1
    elements.append((h,w))
    col[w] += 1
    row[h] += 1

def rank(lst,syoujun=False):
    res2 = list(set(lst))
    ans = []
    if syoujun:
        res2.sort()
    else:
        res2.sort(reverse=True)
    dic1 = dict()
    for i in range(len(res2)):
        dic1[res2[i]] = i
    for i in lst:
        #ans.append(dic1[i]) #zero-indexed
        ans.append(dic1[i] + 1) #one-indexed
    
    return ans

col2 = rank(col)
row2 = rank(row)

cmax = col2.count(1)
rmax = row2.count(1)

counter = 0
for i,j in elements:
    if col2[j] == 1 and row2[i] == 1:
        counter += 1

if counter == cmax*rmax:
    print(max(col) + max(row)-1)
else:
    print(max(col) + max(row))

Measured memory_bytes: 143244
n=int(input())
s=0
ok=0
for i in range(n):
  lis=input().split()
  if lis[0]==lis[1]:
    s+=1
    if s>=3:
      ok=1
  else:
    s=0
if ok==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9092
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    int n,m,near=0,ans=0;
    scanf("%d%d",&n,&m);
    int a[m],b[m],c[n];
    for (int i=0; i<n; i++){
        c[i]=1e9;
    }
    for (int i=0; i<m; i++){
        scanf("%d%d",&a[i],&b[i]);
        a[i]--;
        b[i]--;
        if(c[a[i]]>b[i]){
            c[a[i]]=b[i];
        }
    }
    for (int i=0; i<n; i++){
        if (c[i]!=1e9){
            if (i>=near){
                ans++;
                near=c[i];
            } else if (c[i]<near){
                near=c[i];
            }
        }
    }
    printf("%d\n",ans);
	return 0 ;
}

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

int n,A[50];

int solve(int i,int m){
    if(m==0)return 1;
    if(i>=n)return 0;
    int res=solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    int q,m,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&m);
        if(solve(0,m))printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 3152
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
A.reverse()

M = m = 2
for i,ai in enumerate(A):
  # print(m , (m-1+ai)//ai*ai , M//ai*ai + ai-1 , M)
  if not (m <= (m-1+ai)//ai*ai<= M):
    print(-1);exit()
  M = M//ai*ai + ai-1
  m = (m-1+ai)//ai*ai
  # print(m,M,i)
print(m,M)

# # 最大ケースを求める
# M = 2
# for i,ai in enumerate(A):
#   if M < ai:
#     print(-1);exit()
#   M = M//ai*ai + ai-1
#   print(M,i)
# print(M)

# # 最小ケースを求める
# m = 2
# for i,ai in enumerate(A):
#   m = (m-1+ai)//ai*ai

# print(m,M)



Measured memory_bytes: 71152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC148C - Snack

        Scanner sc = new Scanner(System.in);

        long a = (long)sc.nextInt();
        long b = (long)sc.nextInt();

        long x = a * b;
        
        long tmp = 0;
        if (a < b) {
            tmp = a;
            a = b;
            b = tmp;
        }
            
        long r = a % b;
        while(r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        
        System.out.println(x / b);
    }
}

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

int main() {
    vector<int> sSize;
    int i, n, num;

    cin >> n;
    n *= 2;

    sSize.resize(n);

    for (i = 0; i < n; i++) {
        cin >> sSize.at(i);
    }

    sort(sSize.begin(), sSize.end());
    num = 0;
    for (i = 0; i < n; i += 2) {
        num += sSize.at(i);
    }

    cout << num << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	int ans = 0;
	int ans2 = 1;
	for (int i = 1;i <= n;++i) {
		int res = 0;
		int target = i;
		while (target % 2 == 0) {
			res++;
			target /= 2;
		}
		ans = max(ans, res);
	}
	if (ans == 0)cout << 1 << endl;
	else {
		rep(i, ans) {
			ans2 *= 2;
		}
		cout << ans2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const int MOD = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

//-------------------ここから回答する-----------------------

void solve(void)
{
    string s;
    cin >> s;
    string ans = "";
    deque<char> q;
    rep(i, s.size())
    {
        if (s[i] == 'B' && q.size() > 0)
            q.pop_back();
        if (s[i] == 'B')
            continue;
        else
            q.emplace_back(s[i]);
    }
    for (auto i : q)
        cout << i;
    cout << endl;
}
int main(void)
{
    solve();
}


Measured memory_bytes: 3572
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! dbg { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        uv: [(usize, usize); m]
    }
    let scc = Scc::from_edges(n, &uv);
    println!("{}", scc.len());
    for s in &scc {
        println!("{} {}", s.len(), s.iter().format(" "));
    }
}

struct Scc {
    n: usize,
    to: Vec<Vec<usize>>,
    rev: Vec<Vec<usize>>,
}

impl Scc {
    fn new(n: usize) -> Self {
        Scc {
            n,
            to: vec![vec![]; n],
            rev: vec![vec![]; n],
        }
    }
    fn from_edges(n: usize, uv: &[(usize, usize)]) -> Vec<Vec<usize>> {
        let mut scc = Scc::new(n);
        for &(u, v) in uv {
            scc.add_edge(u, v);
        }
        scc.scc()
    }
    fn add_edge(&mut self, u: usize, v: usize) {
        self.to[u].push(v);
        self.rev[v].push(u);
    }
    fn dfs(&self, c: &mut usize, v: usize, visit: &mut Vec<bool>, num: &mut Vec<usize>) {
        if visit[v] {
            return;
        }
        visit[v] = true;
        for &u in self.to[v].iter() {
            if visit[u] {
                continue;
            }
            self.dfs(c, u, visit, num);
        }
        num[v] = *c;
        *c += 1;
    }
    fn scc(&self) -> Vec<Vec<usize>> {
        let mut visit = vec![false; self.n];
        let mut num = vec![0; self.n];
        {
            let mut c = 0;
            for i in 0..self.n {
                self.dfs(&mut c, i, &mut visit, &mut num);
            }
        }
        let mut num = num
            .iter()
            .enumerate()
            .map(|(i, &k)| (k, i))
            .collect::<Vec<_>>();
        num.sort();

        let mut ss = vec![];
        let mut visit = vec![false; self.n];
        for &(_, v) in num.iter().rev() {
            if visit[v] {
                continue;
            }
            let mut s = vec![];
            let mut q = std::collections::VecDeque::<usize>::new();
            q.push_back(v);
            while let Some(v) = q.pop_front() {
                if visit[v] {
                    continue;
                }
                s.push(v);
                visit[v] = true;
                for &u in self.rev[v].iter() {
                    if visit[u] {
                        continue;
                    }
                    q.push_back(u);
                }
            }
            ss.push(s);
        }
        ss
    }
}


Measured memory_bytes: 101160
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> vec(m);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        vec[i].first = b;
        vec[i].second = a;
    }
    sort(vec.begin(), vec.end());

    int cur = -1e9;
    int ans = 0;
    rep(i,m){
        if (vec[i].second >= cur){
            cur = vec[i].first;
            ans++;
        }
    }

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


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

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
const int MOD = 1000000007;

typedef long long ll;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll LCM(ll x, ll y)
{
    return x * y / GCD(x, y);
}

using Graph = vector<vector<int>>;

// typedef pair<int, int> P;
int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    if (a >= k) {
        a -= k;
    } else if (a + b >= k) {
        b -= (k - a);
        a = 0;
    } else {
        a = 0;
        b = 0;
    }

    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCm(ll n, ll m){
    if(m == 0 || m == n){
        return 1;
    } else if(m == 1){
        return n;
    }
    return (nCm(n - 1, m) + nCm(n - 1, m - 1));
}

//-----------------------ここから-----------

int main(void){
    int n;
    cin >> n;
    
    vector<pair<int, int>> l;
    for(int i = 1; i <= n; i++){
        int tmp = i;
        int counter = 0;
        while(tmp % 2 == 0){
            tmp /= 2;
            counter++;
        }
        pair<int,int> p;
        p.first = counter;
        p.second = i;
        l.push_back(p);
    }

    sort(l.begin(),l.end());
    reverse(l.begin(), l.end());
    cout << l[0].second << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];

void solve() {
  string s; cin >> s;
  int num = s.size();
  int cnt=0;
  for (int i = 0; i < num; i++) {
    if (s[i] == 'x') cnt++;  
  }

  if (cnt < 8) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    char c; cin >> c;
    cout << char(c+1) << endl;
    return 0;
}

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

int main()
{
	int N,M,X,Y;
	cin >> N >> M >> X >> Y;
	int x[100] = { -100 };
	int y[100] = { 100 };
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> y[i];
	}
	sort(x, x + N, greater<int>());
	sort(y, y + M);

	if (x[0] >= y[0] || x[0] >= Y || y[0] <= X) {
		cout << "War" << endl;
	}
	else {
		cout << "No War" << endl;

	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		if(a<1200) {
			System.out.println("ABC");
		}
		else if(a<2800) {
			System.out.println("ARC");
		}
		else {
			System.out.println("AGC");
		}
	}
}

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

typedef pair<int, int> P;
typedef long long ll;
const int mod = 1000000007;

bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a);//a進数におけるNの各桁の和、計算量はloga(N)
ll mpow(ll x, ll n);
ll inv_mod(ll a){return mpow(a,mod-2);}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> a(M);
    if(M>0) REP(i, M) cin >> a[i];
    else a.push_back(INT_MAX);
    vector<int> dp(N+1);
    dp[0]=1;
    if(a[0]==1){
        dp[1]=0;
        a.erase(a.begin());
    }
    else dp[1]=1;
    for(int i=0;i<N-1;i++){
        if(a.empty()) a.push_back(INT_MAX);
        if(i+2==a[0]){
            dp[i+2]=0;
            a.erase(a.begin());
        }
        else dp[i+2]=(dp[i+1]+dp[i])%mod;
    }
    cout<<dp[N]<<endl;
}

int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
ll mpow(ll x, ll n){ //x^n(mod division) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
/*
class Fuctorical{//階乗とその逆元を求めて計算に利用するクラス
private:
    vector<ll> fac;
public:
    
    Fuctorical(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};
*/

/*
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
*/

Measured memory_bytes: 1024
import collections as cl
#素因数分解
N = int(input())
res = 0
def prime(N):
    l = []
    p = 2
    while N % 2 == 0:
        l.append(p)
        N //= p
    p += 1
    while p * p <= N:
        if N % p == 0:
            l.append(p)
            N //= p
        else:
            p += 2
    if N != 1:
        l.append(N)
    return l

c = cl.Counter(prime(N))

for k,v in c.items():
    i = 1
    while i <= v:
        res += 1
        v -= i
        i += 1

print(res)


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

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


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

int main()
{
    int n;
	cin >> n;
	int i, a;
	int min = 0, max = 0;
	long sum = 0;

	cin >> a;
	min = a, max = a, sum = a;
	for(i = 1; i < n; i++){
        cin >> a;
		if(min > a) min = a;
		if(max < a) max = a;
		sum = sum + a;
	}

    cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
using namespace std;

const int mod = 1e9 + 7;
typedef long long li;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

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

const int maxn = 1e5;
const li infl = 1e18;

int n;
li d[maxn];
map<li, int> id;

int fa[maxn];
int size[maxn];
li sdep[maxn];

void No(void) {
  puts("-1");
  exit(0);
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", d + i);
    id[d[i]] = i;
    size[i] = 1;
    sdep[i] = 0;
  }
  int root = min_element(d, d + n) - d;
  while (id.size() > 1) {
    int u = (--id.end())->second;
    id.erase(--id.end());
    li fa_d = d[u] - (n - size[u]) + size[u];
    if (!id.count(fa_d)) No();
    fa[u] = id[fa_d];
    // printf("fa[%d] = %d\n", u, fa[u]);
    size[fa[u]] += size[u];
    sdep[fa[u]] += sdep[u] + size[u];
  }
  // printf("root = %d\n", root);
  // printf("%lld %d\n", sdep[root], size[root]);
  if (d[root] != sdep[root]) No();
  for (int i = 0; i < n; ++i) {
    if (i != root) {
      printf("%d %d\n", i + 1, fa[i] + 1);
    }
  }
  return 0;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H, W;
string S[20];
//---------------------------------------------------------------------------------------------------
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
vector<vector<int>> bfs(int sx, int sy) {
	queue<pair<int, int>> que;
	vector<vector<int>> res(H, vector<int>(W, inf));
	vector<vector<bool>> vis(H, vector<bool>(W, false));

	res[sy][sx] = 0;
	vis[sy][sx] = true;
	que.push({ sx, sy });

	while (!que.empty()) {
		int x, y;
		tie(x, y) = que.front();
		que.pop();

		rep(d, 0, 4) {
			int xx = x + dx[d];
			int yy = y + dy[d];
			if (0 <= xx and xx < W and 0 <= yy and yy < H) {
				if (S[yy][xx] != '#' and !vis[yy][xx]) {
					res[yy][xx] = res[y][x] + 1;
					vis[yy][xx] = true;
					que.push({xx, yy});
				}
			}
		}
	}

	return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W;
	rep(y, 0, H) cin >> S[y];

	int ans = 0;
	rep(sx, 0, W) rep(sy, 0, H) if(S[sy][sx] != '#') {
		auto res = bfs(sx, sy);
		rep(x, 0, W) rep(y, 0, H) if (S[y][x] != '#') chmax(ans, res[y][x]);
	}
	cout << ans << endl;
}







Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
int n,m;
char s[1000];
int main()
{
    scanf("%s",&s[0]);
    printf("%c%d%c",s[0],strlen(s)-2,s[strlen(s)-1]);
    return 0;
}

Measured memory_bytes: 128
d = int(input())
dd = d * (d + 1) // 2
*C, = map(int, input().split())
S = [list(map(int, input().split())) for i in range(d)]
T = [int(input()) - 1 for i in range(d)]
m = int(input())
PQ = [tuple(map(int, input().split())) for k in range(m)]
PQ = [(p - 1, q - 1) for p, q in PQ]

for p, q in PQ:
    T[p] = q
    L = [-1 for j in range(26)]
    X = [0 for j in range(26)]
    score = 0
    for i in range(d):
        score += S[i][T[i]]
        X[T[i]] += (d - i) * (i - L[T[i]])
        L[T[i]] = i
    for j in range(26):
        score -= C[j] * (dd - X[j])
    print(score)


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

const int N=16,M=1<<N,P=1e9+7;
int n,m,ans,a[N],f[N+1][M],fac[M+5],inv[M+5];

int qpow(int b_,int p_)
{
    int r_=1;
    for(;p_;p_>>=1,b_=1LL*b_*b_%P)
        if(p_&1) r_=1LL*r_*b_%P;
    return r_;
}

inline int C(int n,int m) {return n<m?0:1LL*fac[n]*inv[m]%P*inv[n-m]%P;}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;++i) scanf("%d",a+i);
    reverse(a,a+m); fac[0]=1;
    for(int i=1;i<=1<<n;++i) fac[i]=1LL*fac[i-1]*i%P;
    inv[1<<n]=qpow(fac[1<<n],P-2);
    for(int i=(1<<n)-1;~i;--i) inv[i]=1LL*(i+1)*inv[i+1]%P;
    f[0][0]=1;
    for(int i=0;i<m;++i)
        for(int S=0;S<1<<n;++S)
        {
            int chs=(1<<n)-a[i]-S;
            (f[i+1][S]+=f[i][S])%=P;
            for(int j=0;j<n;++j) if(!(S>>j&1))
                (f[i+1][S|1<<j]+=1LL*f[i][S]*C(chs,(1<<j)-1)%P*fac[1<<j]%P)%=P;
        }
    for(int S=0;S<1<<n;++S)
        if(__builtin_popcount(S)&1) (ans+=P-1LL*f[m][S]*fac[(1<<n)-1-S]%P)%=P;
        else (ans+=1LL*f[m][S]*fac[(1<<n)-1-S]%P)%=P;
    printf("%lld",1LL*ans*(1<<n)%P);
    return 0;
}

Measured memory_bytes: 8344
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=55;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int a;
char s[5000];
int main()
{
	scanf("%d%s",&a,s+1);
	if(a>=3200) printf("%s",s+1);
	else puts("red");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
// x^y≡x^(y%(p-1))mod p
// but there is a condition that x needs to be coprime to p
///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set; */
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);
#define debug(x) cerr << (#x) << " is " << (x) << endl;

#ifndef ONLINE_JUDGE
#define cerr if(true)cerr
#endif

template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template<typename... Args>
	Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
	}
};
template<typename T>
struct Vec<1, T> : public vector<T> {
	Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
	}
};

ll power(ll x, ll y,ll p)
{
    ll res = 1;     // Initialize result
    x = x % p;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;  // Change x to x^2
    }
    return res;
}
int gcd(int a, int b) { if (a == 0)return b;return gcd(b % a, a);}

ll modinv(ll a,ll p){return power(a,p-2,p);}


void solve(){
    ll n;
    cin>>n;
    vll a(n), b(n);
    f(i,0,n){
        cin>>a[i]>>b[i];
    }
    sort(all(b));
    sort(all(a));
    if (n%2)
    {
        cout<<b[n/2]-a[n/2]+1<<endl;
    }
    else {
        ll A = a[n/2]+a[n/2-1];
        // A/=2;
        ll B = b[n/2]+b[n/2-1];
        // B/=2;
        ll ans = 0;
        // deb(A)deb(B)
        ans+=2*(floor(1.0*B/2.0)-ceil(1.0*A/2.0)+1)-1;
        if (A%2)
        {
            ans++;
        }
        if (B%2)
        {
            ans++;
        }
        cout<<ans<<endl;
    }
    return ;
}
int main()

{
    IO;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // #endif
    int T=1;
	// cin >> T;
	f(c,0,T){
		solve();
	}
    return 0;
}// make_pair make_tuple  tuple<int,int,int> continue resize insert count size else true isValid second first false erase double priority_queue


Measured memory_bytes: 6364
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define umap unordered_map
#define flush fflush(stdout)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define ln "\n"
#define all(v) v.begin(),v.end()
#define MAX 1000000009
#define MOD 1000000007
#define mid (start + end) / 2
#define R(ii) (ii + ii + 1)
#define L(ii) (ii + ii)
#define N 100005
using namespace std;
typedef pair<ll,ll> pp;
typedef vector<ll> vi;
ll n, q, k, t, x, y, a, b, c;
int main(){
    #ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> t;
    string ans = "APPROVED";
    while (t--){
        cin >> n;
        if (n % 2 == 0 && n % 3 != 0 && n % 5 != 0){
            ans = "DENIED";
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
a = []
h.times do
  a << gets.split(//)
end

#p a
hh, ww = 0 ,0

def pos(a,h,w, hh , ww)
  #puts "in --"
  while not ( hh == (h - 1)  and ww == (w - 1) )

    #a.each{|e| puts e.join}

    #puts "#{a[hh][ww]} // #{hh}, #{ww} // #{h} #{w}"
    #puts ""
    
    if hh == (h - 1)
      #p "h+"
      if a[hh][ww+1] == "."
        return false
      end
      a[hh][ww] = "+"
      ww += 1
    elsif ww == (w - 1)
      #p "w+"
      return false if a[hh+1][ww] == "."
      a[hh][ww] = "+"
      hh += 1
    else
      #p "both"
      return false if a[hh+1][ww] == "#" and a[hh][ww+1] == "#"
      return false if a[hh+1][ww] == "." and a[hh][ww+1] == "."

      if a[hh+1][ww] == "#"
           a[hh][ww] = "+"
        return true if pos( a,h,w,hh+1, ww )
      end
      if  a[hh][ww+1] == "#"
        a[hh][ww] = "+"
        return true if pos( a,h,w, hh, ww + 1 )
      end

      return false

    end
  end

  a[hh][ww] = "+"

  for i in 0...h
    for j in 0...w
      if a[i][j] == "#"
        return false 
      end
    end
  end  
  return true
end


puts (pos(a,h,w, 0,0) ? "Possible" : "Impossible")

Measured memory_bytes: 1916
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::cin;
using std::string;

int main(){
  int s,w;
  cin >> s >> w;
  if(s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}


Measured memory_bytes: 3632
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <set>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

int main(){

  ios :: sync_with_stdio(false);
  string s; 
  int k;

  cin >> s >> k;
  set<string> S;

  for(int i=0; i<s.size(); i++){
    string temp = "";
    for(int j=i; j<s.size() && j-i+1<=k; j++){
      temp += s[j];
      S.insert(temp);
    }
  }

  for(auto ss : S){
    k--;
    if(k == 0){
      cout << ss << endl;
      break;
    }
  }

  return 0;
}

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

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


  if (a > b) {
    int data = 0;
    data = b;
    b = a;
    a = data;
  }
  if (b > c) {
    int data = 0;
    data = c;
    c = b;
    b = data;
  }
  if (a > b) {
    int data = 0;
    data = b;
    b = a;
    a = data;
  }
  if (a > c) {
    int data = 0;
    data = c;
    c = a;
    a = data;
  }
  cout << a << " " << b << " " << c << endl;
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>

using std::cin;using std::cout;using std::cerr;using std::endl;

#define rep(i,a,b) for(int i = a;i <= b;++i)
#define per(i,a,b) for(int i = a;i >= b;--i)

const int mmax = 5e5;
int n,q,L,R,cnt,f;
int a[mmax + 10],ans[mmax + 10],vis[mmax + 10];

struct task
{
	int l,r,id;
}ovo[mmax + 10];

bool cmp(task a,task b){
	if(a.r < b.r) return 1;
	return 0;
}

struct node
{
	node *ls,*rs;
	int ans,l,r;
	int dis(){
		return r - l + 1;
	}
}*root,T[mmax * 4 + 10];

void pushup(node* cur){
	cur->ans = cur->ls->ans + cur->rs->ans;
}

node* create(){
	return &T[cnt++];
}

void build(node* cur,int l,int r){
	cur->l = l,cur->r = r;
	if(l == r){
		return ;
	}
	int mid = (l + r) / 2;
	cur->ls = create();
	cur->rs = create();
	build(cur->ls,l,mid);
	build(cur->rs,mid + 1,r);
}

void change(node* cur,int color,int pos,int opt){
	if(cur->l > pos || cur->r < pos){
		return;
	}
	if(cur->dis() == 1){
			cur->ans = opt;
			vis[color] = cur->l;
		return ;
	}
	change(cur->ls,color,pos,opt);
	change(cur->rs,color,pos,opt);
	pushup(cur);
}

int query(node* cur){
	if(L > cur->r || R < cur->l){
		return 0;
	}
	if(L <= cur->l && R >= cur->r){
		return cur->ans;
	}
	return query(cur->ls) + query(cur->rs);
}

int main(){

	std::ios::sync_with_stdio(0);
	cin.tie(0);

	cin>>n>>q;

	// freopen("test1.txt","w",stdout);

	rep(i,1,n){
		cin>>a[i];
	}


	rep(i,1,q){
		cin>>ovo[i].l>>ovo[i].r;
		ovo[i].id = i;
	}

	std::sort(ovo + 1,ovo + 1 + q,cmp);

	root = create();
	build(root,1,n);
	f = 0;

	rep(i,1,q){
		while(f < ovo[i].r){
			f++;
			if(vis[a[f]]) change(root,a[f],vis[a[f]],0);
			change(root,a[f],f,1);
		}

		L = ovo[i].l;
		R = ovo[i].r;
		ans[ovo[i].id] = query(root);
	}

	rep(i,1,q){
		cout<<ans[i]<<endl;
	}


	return 0;
}


Measured memory_bytes: 46760
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin>>N;
  vector<double> v(N);
  REP(i,N) cin >> v[i];
  sort(ALL(v));
  double ans = 0;
  REP(i,N-1){
    v[i+1] = (v[i] + v[i+1])/2;
  }
  cout << setprecision(8) << v[N-1] << endl;
  return 0;
  
}


Measured memory_bytes: 256
n=int(input())
field=[[0 for i in range(20)]for j in range(15)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    h=(b-1)*4+f-1
    w=r*2-1
    n=v
    field[h][w]+=n
for y in range(15):
    for x in range(20):
        if(y%4==3):field[y][x]='#'
        elif x%2==0 :field[y][x]=' '
        print(field[y][x],end='')
    print()


Measured memory_bytes: 5640
n,m=gets.split(' ').map(&:to_i)
drink=Array.new(n){Array.new(2,0)}

for i in 0..n-1
  a,b=gets.split(' ').map(&:to_i)
  drink[i][0]=a
  drink[i][1]=b
end

drink.sort!{|a,b| b[0]<=>a[0]}.reverse!


sum=0
for i in 0..n-1
  if m<drink[i][1]
    sum+= drink[i][0]*m
    break
  else
    m-=drink[i][1]
    sum+=drink[i][0]*drink[i][1]
  end
end
puts sum


Measured memory_bytes: 10104
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
 
int main(){
    unsigned int list[100000];
    int numOfList;
 
    cin >> numOfList;
 
    rep(i,numOfList)cin >> list[i]; 

    int numOfT,val;
    int counter = 0;
    cin >> numOfT;
 
    rep(i,numOfT){
        cin>>val;
        int high = numOfList - 1;
        int low = 0;
        int mid;
 
        while(low <= high){
            mid = (low + high) / 2;
            if(list[mid] < val){
                low = mid + 1;
            }else if(list[mid] > val){
                high = mid - 1;
            }else if(list[mid] == val){
                counter ++;
                break;
            }
        }
    }
    cout << counter << endl;
 
    return 0;
}

Measured memory_bytes: 3472
#include <stdio.h>

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = (n) - 1; i >= 0; i--)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define CHINO(a,n) int n, *a; scanf("%d", &n); a = (int *)malloc(sizeof(int) * n); for(int i = 0; i < n; i++) scanf("%d", a + i)

int main(){
	char ch[120];
	bool table[26];
	REP(i, 26) table[i] = 0;
	int ans = 1145141919, count = 0, ren = 0;
	bool flag;
	scanf("%s", ch);
	for(int i = 0; ch[i]; i++){
		table[ch[i] - 'a'] = 1;
	}
	REP(i, 26) if(table[i]){
		count = 0; ren = 0;
		for(int j = 0; ch[j]; j++){
			if(ch[j] == i + 'a'){
				ren = 0;
			}else{
				ren++;
				if(ren > count) count = ren;
			}
		}
		if(count < ans) ans = count;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

class BIT{
  int n;
  std::vector<int> bit;
public:
  BIT(int n):n(n),bit(n+1,0){}

  int sum(int i){
    int s = 0;
    while(i>0){ s+=bit[i]; i-=i&(-i); }
    return s;
  }
  void add(int i, int x){
    while(i<=n){ bit[i]+=x; i+=i&(-i); }
  }
};

int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  BIT bit(N+100);

  int ret = 0;
  rep(i,N){
    bit.add(v[i], 1);
    if(bit.sum(v[i]-1) == 0) ret++;
  }
  
  cout << ret << endl;
  
  
  return 0;
}


Measured memory_bytes: 1908
c = [list(map(int, input().split(' '))) for _ in range(3)]
a = [-1] * 3
b = [-1] * 3

a[0] = 0
for i in range(3):
    b[i] = c[0][i] - a[0]
for i in range(3):
    a[i] = c[i][0] - b[0]

ans = True
for i in range(3):
    for j in range(3):
        if c[i][j] != a[i] + b[j]:
            ans = False
            break
if ans == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,answer,hikaku;
  cin >> N;
  
  answer = 0;
  vector<int> mochi(N);
  for (int i=0;i < N;i++){
    cin >> mochi.at(i);
  }
  for (int i=0;i < N;i++){
    hikaku = mochi.at(i);
    if (hikaku == 0) {
      continue;
    }
    for (int j=i+1;j < N;j++) {
      if (hikaku == mochi.at(j)) {
        mochi.at(j) = 0;
        
      }
    }
    answer++;
  }
  
  cout << answer << endl;
  
}

Measured memory_bytes: 256