akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
#import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def bfs(MAP, queue):

    while queue:
        turn, ci, cj = queue.popleft()
        for ii, jj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ni = ci + ii
            nj = cj + jj
            if MAP[ni][nj] == 0:
                MAP[ni][nj] = 1
                queue.append((turn + 1, ni, nj))
    return turn


def run():
    H, W = map(int, input().split())
    queue = deque([])
    MAP = [[1] * (W+2)]
    d = {'#' : 1, '.' : 0}
    for i in range(1, H+1):
        X = input()
        S = [1]
        for j, s in enumerate(X, 1):
            S.append(d[s])
            if s == '#':
                queue.append((0, i, j))
        S.append(1)
        MAP.append(S)

    #print(queue)
    MAP.append([1] * (W+2))

    print(bfs(MAP, queue))


if __name__ == "__main__":
    #print(math.gcd(0, 10))
    run()


Measured memory_bytes: 113444
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<int, char> i2en;
  map<char, int> en2i;
  char a = 'a', A = 'A';
  FOR(i,0,26) i2en[i] = a++;
  FOR(i,26,52) i2en[i] = A++;
  a = 'a', A = 'A';
  FOR(i,0,26) en2i[a++] = i;
  FOR(i,26,52) en2i[A++] = i;
  int n;
  while(cin>>n,n) {
    int k[n]; FOR(i,0,n) cin >> k[i];
    int key = 0;
    string s; cin >> s;
    int len = s.length();
    string ans = "";
    FOR(i,0,len) {
      key %= n;
      ans += i2en[(en2i[s[i]]-k[key]+52)%52];
      key++;
    }
    cout << ans << '\n';
  }
  return 0;
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024 * 1024;

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(NULL);
	LL s;
	scanf("%lld", &s);
	LL sq = sqrt(s);
	
	if (sq * sq < s)
	{
		sq++;
	}
	
	sq = sq * sq;
	LL x2 = sqrt(sq), y3 = x2;
	if (x2 * y3 - x2 >= s)
	{
		x2--;
	}
	LL rem = x2 * y3 - s;
	debug(rem);
	LL x3 = 1, y2 = rem;
	printf("0 0 %lld %lld %lld %lld\n", x2, y2, x3, y3);
	return 0;
}

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

using namespace std;

int main(){
    int64_t n,m;
    cin >> n >> m;
    vector<int> h(n,0);
    vector<set<int>> map(n);
    for (int64_t i = 0; i < n; i++)
        cin >> h[i];

    for (int64_t i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        map[a - 1].insert(b - 1);
        map[b - 1].insert(a - 1);
    }

    int cnt = 0;
    for (size_t i = 0; i < n; i++)
    {
        bool ok = true;
        for(auto a : map[i])
        {
            if(h[a] >= h[i])
            {
                ok = false;
                break;
            }
        }
        if(ok){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;
typedef long long ll;


#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  int h,a;cin>>h>>a;

  int ans=0;
  while(h>0){
    h-=a;
    ans++;
  }
  out(ans);


  return 0;
}


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

typedef signed long long ll;
typedef long double ld;

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

#define DEBUG

int main()
{
	int n;
	int d;
	cin >> n >> d;

	d = (2 * d) + 1;
	int ans = (n + d - 1) / d;

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


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

template <typename T> ostream &operator<<(ostream &o,vector<T> &v)
{for(T &x:v)o<<(&x!=&v[0]?" ":"")<<x;return o;}

int main()
{
    int n, c = 0;
    cin >> n;
    vector<int> a(n);

    for (int &x: a)
        cin >> x;

    for (auto i = a.begin(), e = a.end() - 1; i != e; i++)
        for (auto j = e; j != i; j--)
            if (*j < *(j - 1)) {
                swap(*j, *(j - 1));
                c++;
            }

    cout << a << endl
        << c << endl;
}


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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

ll t[800000];

void build(int a[], int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(a, v * 2, tl, tm);
        build(a, v * 2 + 1, tm + 1, tr);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }
}

ll mx(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return max(mx(v * 2, tl, tm, l, min(r, tm)), mx(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r));
}

void update(int v, int tl, int tr, int pos, ll new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v * 2, tl, tm, pos, new_val);
        else
            update(v * 2 + 1, tm + 1, tr, pos, new_val);
        t[v] = max(t[v * 2], t[v * 2 + 1]);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // srand(time(NULL));
    int n;
    cin >> n;
    // n = rand() % 4 + 6;
    // cout << n << endl;

    vector<int> h(n);
    int a[n] = {};

    build(a, 1, 0, n - 1);

    // seg.resize(4 * n);
    // create(0, 0, n - 1, a);

    for (int i = 0; i < n; i++) {
        cin >> h[i];
        h[i]--;
        // h[i] = i;
    }
    // unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    // shuffle(h.begin(), h.end(), std::default_random_engine(seed));
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        // a[i] = rand() % 10;
    }

    // for (int i = 0; i < n; i++) cout << h[i] << " ";
    // cout << endl;
    // for (int i = 0; i < n; i++) cout << a[i] << " ";
    // cout << endl;

    ll ans = 0;

    for (int i = n - 1; i >= 0; i--) {
        ll temp = 0;
        if (h[i] + 1 <= n - 1) temp = mx(1, 0, n - 1, h[i] + 1, n - 1);
        temp += (ll)a[i];
        // cout << temp << endl;
        update(1, 0, n - 1, h[i], temp);
        ans = max(ans, temp);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T>
inline bool dpmin(T& a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool dpmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

void solve(long long N, vector<long long> x, vector<long long> y) {

    vector<int> order(N);
    rep(i, N) order[i] = i;

    int n_perm = 1;
    rep(i, N) n_perm *= i + 1;

    double ans = 0;
    do {
        double dist = 0;
        for (int i = 1; i < N; i++) {
            dist = sqrt(pow(x[order[i-1]] - x[order[i]], 2.0) + pow(y[order[i-1]] - y[order[i]], 2.0));
            /* cout << dist << endl; */
            ans += dist;
        }
    } while (next_permutation(order.begin(), order.end()));

    ans /= (double)n_perm;
    printf("%lf\n", ans);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use
// the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    cin >> N;
    vector<long long> x(N);
    vector<long long> y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> x[i];
        cin >> y[i];
    }
    solve(N, move(x), move(y));
    return 0;
}


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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef pair<ll, ll> pint;


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



void print(const vint& v)
{
  for(int i=0; i+1<v.size(); ++i){
    std::cout << v[i] << " ";
  }
  cout<<v.back()<<endl;
}




int main() {


  cout<<fixed<<setprecision(10);

  stack<int> s;

  string snt;
  getline(cin, snt);
  vector< string > vec;

  stringstream ss{snt};
  string buf;
  while(getline(ss, buf, ' ')){
    vec.push_back(buf);
  }


  rep(i, vec.size()){
    string x = vec[i];
    if(x == "+"){
      int a,b;
      a = s.top(); s.pop();
      b = s.top(); s.pop();
      s.push(b+a);
    }else if( x == "-"){
      int a,b;
      a = s.top(); s.pop();
      b = s.top(); s.pop();
      s.push(b-a);      
    }else if( x == "*"){
      int a,b;
      a = s.top(); s.pop();
      b = s.top(); s.pop();
      s.push(b*a);      
    }else{
      s.push(stoi(x));
    }
  }

  cout << s.top() << endl;

}





//




Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int priceA = 0;
        int priceB = 0;
        priceA = A * N;
        priceB = B;
        if(priceA > priceB) {
            System.out.println(priceB);
        } else {
            System.out.println(priceA);
        }

    }
}


Measured memory_bytes: 24916
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    priority_queue<int, vector<int>, greater<int>> que;
    int N, M;
    cin >> N >> M;
    rep(i, N) {
        int a; cin >> a;
        que.push(a);
    }
    pair<int, int> p[100010];
    rep(i, M) {
        cin >> p[i].second >> p[i].first;
    }
    sort(p, p + M, greater<pair<int,int>>());
    rep(i, M) {
        while(p[i].second > 0) {
            //cout << que.top() << " " << p[i].first << endl;
            if (que.top() >= p[i].first) break;
            p[i].second--;
            que.pop();
            que.push(p[i].first);
        }
    }
    int sum = 0;
    while(que.size()) {
        sum += que.top(); que.pop();
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2804
import math


def divisor(n):
    # 約数
    return [[i, n // i] for i in range(1, int(math.sqrt(n)) + 1) if n % i == 0]


def main():
    N = int(input())
    div = divisor(N)
    print(max(int(math.log10(div[-1][0]) + 1),
              int(math.log10(div[-1][1]) + 1)))
    return


main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n;
    cin>>n;
    vector<double> x(n),y(n);
    rep(i,n)cin>>x[i]>>y[i];
    vector<int> v(n);
    rep(i,n)v[i]=i;
    double lengthsum=0;
    double cnt=0;
    do{
        cnt++;
        rep(i,n-1){
            lengthsum +=pow((pow(x[v[i]]-x[v[i+1]],2)+pow(y[v[i]]-y[v[i+1]],2)),0.5);
        }
        //for(int i=0; i<4; i++){
         //   cout<<v[i];
         //   if(i!=3)cout<<" ";
        //}
        //cout<<endl;
    }while(next_permutation(v.begin(),v.end()));

    double ans = lengthsum/cnt;
    printf("%.12f",ans);
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	sc.Scan()
	s := sc.Text()
	mid := len(s) / 2
	sr := s[:mid]
	sl := s[mid+1:]

	if isPalindrome(sr) && isPalindrome(sl) && isPalindrome(s) {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}

}

func isPalindrome(s string) bool {
	len := len(s)
	mid := len / 2

	for i := 0; i <= mid; i++ {
		r := len - i - 1

		if s[i] != s[r] {
			return false
		}

	}

	return true
}


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


def main():
    from statistics import median

    n = int(input())
    a = list(map(int, input().split()))
    mod_a = list()
    ans = 0

    for index, ai in enumerate(a, 1):
        mod_a.append(ai - index)

    b = int(median(mod_a))

    for mod_ai in mod_a:
        ans += abs(mod_ai - b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27244
import sys
import copy
sys.setrecursionlimit(9**9)
H,W=map(int,input().split())
M=[list(input()) for _ in range(H)]
N=copy.deepcopy(M)
m=x=y=0
def d(c,P):
    global m,x,y
    Q=[]
    for p in P:
        h=p[0]
        w=p[1]
        if h!=H-1 and M[h+1][w]=='.':
            M[h+1][w]='#'
            Q.append([h+1,w])
        if h!=0 and M[h-1][w]=='.':
            M[h-1][w]='#'
            Q.append([h-1,w])
        if w!=W-1 and M[h][w+1]=='.':
            M[h][w+1]='#'
            Q.append([h,w+1])
        if w!=0 and M[h][w-1]=='.':
            M[h][w-1]='#'
            Q.append([h,w-1])
    if len(Q)!=0:
      c+=1
      return d(c,Q)
    else:
        m=max(m,c)
f=False
for i in range(H):
    for j in range(W):
        if M[i][j]=='.':
            M[i][j]='#'
            d(0,[[i,j]])
            M=copy.deepcopy(N)
print(m)

Measured memory_bytes: 84316
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

int main(){
	ll A;
	cin >> A;
	ll B;
	cin >> B;
	if((A+B)%2==0)cout<<(A+B)/2<<endl;
	else cout<<"IMPOSSIBLE"<<endl;

return 0;
}  


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();

		while(true) {
			if(prime(n)) {
				break;
			}
			n++;
		}
		System.out.println(n);
		sc.close();
	}

	private boolean prime(int n) {
		if(n==0||n==1) {
			return false;
		}
		if(n==2) return true;
		if(n%2==0) return false;
		for(int i=3; i*i<=n; i+=2) {
			if(n%i==0) {
				return false;
			}
		}
		return true;
	}
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
#define rep2(i, startValue, N) for (int i = (int)(startValue); i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

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

  if (n >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
from collections import deque
N = int(input())
#グラフ入力受取
G = [[] for _ in range(N)]
for _ in range(N):
    a = list(map(int, input().split()))
    for i in a[2:]:
        G[a[0]-1].append(i-1)

#頂点1をスタートとした探索
dist = [-1]*N
que = deque()
dist[0] = 0
que.append(0)
while len(que)!=0:
    v = que.popleft()
    for nv in G[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v]+1
            que.append(nv)
        
for i in range(N):
    print(str(i+1) + ' ' + str(dist[i]))


Measured memory_bytes: 6004
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<" --------------------------------------- "<<endl
#define LL long long
#define DB double
#define LDB long double	 
using namespace std;
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	inline LL read(){
		LL nm=0; bool fh=true; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) fh^=(cw=='-');
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return fh?nm:-nm;
	}
}using namespace IO;
#define M 400020
#define INF 400000000000000000ll
int last[M],ps[M],n,t[M][64],p[M];
inline LL add(LL x,LL y){return min(x+y,INF);}
LL c[M][64],m;
int S[M],top,vs[M];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) p[i]=read(),p[i+n]=p[i];
	for(int i=1;i<=n+n;i++){
		last[i]=ps[p[i]],ps[p[i]]=i;
		if(last[i]) t[last[i]][0]=i,c[last[i]][0]=i-last[i];
	}
	for(int i=1;i<=n;i++){
		if(t[i][0]>n) t[i][0]-=n;
		t[i][0]%=n,++t[i][0],++c[i][0];
	}
	for(int k=1;k<62;k++) for(int i=1;i<=n;i++){
		t[i][k]=t[t[i][k-1]][k-1];
		c[i][k]=add(c[i][k-1],c[t[i][k-1]][k-1]);
	}
	LL rem=n*m,now=1; int pos=1;
	for(int k=61;k>=0;k--) if(now+c[pos][k]<=rem) now+=c[pos][k],pos=t[pos][k];
	while(now<=rem){
		if(!vs[p[pos]]) vs[p[pos]]=1,S[++top]=p[pos];
		else{while(vs[p[pos]]) vs[S[top]]=0,--top;}
		++now,pos%=n,++pos;
	}
	for(int i=1;i<top;i++) printf("%d ",S[i]);
	if(top) printf("%d",S[top]); puts(""); return 0;
}

Measured memory_bytes: 308224
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
use std::collections::HashSet;

const MOD: usize = 1e9 as usize + 7;

fn main() {
    input!{
      n: usize,
      m: usize,
      aa: [usize; n],
      bb: [usize; m],
    }

    let au: HashSet<usize> = aa.iter().map(|&v| v).collect();
    if au.len() < n {
        return println!("{}", 0);
    }
    let bu: HashSet<usize> = bb.iter().map(|&v| v).collect();
    if bu.len() < m {
        return println!("{}", 0);
    }


    let mut ans = 1;
    let mut rbigger = 0;
    let mut cbigger = 0;
    for i in (1..(n*m)+1).rev() {
        let rmax = au.contains(&i);
        let cmax = bu.contains(&i);

        if rmax {
            rbigger += 1;
        }
        if cmax {
            cbigger += 1;
        }

        if rmax && cmax {
        } else if rmax {
            ans *= cbigger;
            ans %= MOD;
        } else if cmax {
            ans *= rbigger;
            ans %= MOD;
        } else {
            ans *= rbigger*cbigger - (n*m-i);
            ans %= MOD;
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

const int MAX = 50;

int n, m;
bool G[MAX][MAX];
vector<bool> seen;

void dfs(int v){
  seen[v] = true;
  
  rep(nv, n){
    if(G[v][nv] == false) continue;
    if(seen[nv] == true) continue;
    dfs(nv);
  }
}

bool all_true(vector<bool> seen){
  rep(i, n){
    if(seen[i] == false) return false;
  }
  return true;
}

int main(){
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]][b[i]] = true;
    G[b[i]][a[i]] = true;
  }

  int cnt = 0;
  rep(i, m){
    G[a[i]][b[i]] = false;
    G[b[i]][a[i]] = false;

    seen.assign(n, false);
    dfs(0);
    if(!all_true(seen)) cnt++;

    G[a[i]][b[i]] = true;
    G[b[i]][a[i]] = true;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict

geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
h = geta(int)

INF = 1 << 60
h += [INF]
dp = [INF, 0, INF]

for i, h1 in enumerate(h[:-2]):
    dp1 = dp[1]
    dp[0] = dp1
    dp[1] = min(dp[2], dp1 + abs(h1 - h[i + 1]))
    dp[2] = dp1 + abs(h1 - h[i + 2])

print(dp[1])


Measured memory_bytes: 52208
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int i,j;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}

string a[50];

int main(){
	int n,m;
	int x,y;
	cin>>n>>m;
	int a[55];
	for(i=0;i<=n;i++){
		a[i]=0;
	}
	for(i=0;i<m;i++){
		cin>>x>>y;
		a[x]+=1;
		a[y]+=1;
	}
	for(i=1;i<=n;i++){
		cout << a[i] << endl;
	}
	return 0;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(2e6) + 17;

int n;
ll dp[MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    return true;
}

void solve() {
    dp[n] = n;

    for (int i = n + 1; i < MAXN; ++i)
        dp[i] = 1;

    ll sum = 0;

    for (int k = 2; k <= n; ++k)
        sum = (sum + dp[n + k]) % INF;

    for (int i = n - 1; i > 0; --i) {
        dp[i] = dp[i + 1];
        dp[i] += (ll) (n - 1) * (n - 1) % INF;
        dp[i] += sum;
        sum += dp[i + 2];
        sum -= dp[i + n + 1];
        sum %= INF;
    }

    cout << (dp[1] % INF + INF) % INF << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 100
int B[siz];


int main()
{
    int i,j,n,m,c,tem,A,cn=0;
    cin>>n>>m>>c;
    fr(i,m) cin>>B[i];
    while(n--)
    {
        tem=c;
        fr(i,m)
        {
            cin>>A;
            tem+=(A*B[i]);
        }
        if(tem>0) cn++;

    }
    cout<<cn<<"\n";
    return 0;
}




Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    cout << fixed << setprecision(10);
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double pi = 3.14159265358979324;
    double Ax = A * sin(2.0 * pi * (H + M / 60.0) / 12.0);
    double Ay = A * cos(2.0 * pi * (H + M / 60.0) / 12.0);
    double Bx = B * sin(2.0 * pi * M / 60.0);
    double By = B * cos(2.0 * pi * M / 60.0);
    
    double dist = sqrt(pow(Ax - Bx, 2.0) + pow(Ay - By, 2.0));

    cout << dist;

    return 0;
}

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

int main(){
    int N;
    int a,b;
    scanf("%d",&N);
    
    for(a = 1; a <= 9; a++) for(b = 1; b <= 9; b++)
        if(a * b == N){
            printf("Yes");
            return 0;
        }
    printf("No");
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

char remained(char a, char b){
    int x = (int)('R') + (int)('G') + (int)('B');
    x -= (int)a + (int)b;
    return (char)x;
}

int main(){
    int N;
    string S;
    read(N, S);
    map<char, vector<int>> num;
    num['R'].push_back(0);
    num['G'].push_back(0);
    num['B'].push_back(0);
    for(int i = 0; i < N; i++){
        switch(S[i]){
        case 'R':
            num['R'][i]++;
            break;
        case 'G':
            num['G'][i]++;
            break;
        case 'B':
            num['B'][i]++;
            break;
        }
        num['R'].push_back(num['R'][i]);
        num['G'].push_back(num['G'][i]);
        num['B'].push_back(num['B'][i]);
    }
    ll ans = 0;
    for(int i = 0; i < N - 2; i++){
        for(int j = i + 1; j < N - 1; j++){
            if(S[i] == S[j]) continue;
            char r = remained(S[i], S[j]);
            ans += num[r][N - 1] - num[r][j];
            if(j + j - i < N && r == S[j + j - i]) ans--;
        }
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3664
#include <stdio.h>
#include <cmath>
using namespace std;

const double pi = std::acos(-1);

struct coodinate{
  double x;
  double y;
};

void koch(int d, coodinate p1, coodinate p2){
  if(d==0) return;

  coodinate s, u, t;
  s.x = (2 * p1.x + p2.x) / 3;
  s.y = (2 * p1.y + p2.y) / 3;
  t.x = (p1.x + 2 * p2.x) / 3;
  t.y = (p1.y + 2 * p2.y) / 3;
  u.x = s.x + (t.x - s.x) * cos(pi / 3) - (t.y - s.y) * sin(pi / 3);
  u.y = s.y + (t.x - s.x) * sin(pi / 3) + (t.y - s.y) * cos(pi / 3);

  koch(d-1, p1, s);
  printf("%f %f\n", s.x, s.y);
  koch(d-1, s, u);
  printf("%f %f\n", u.x, u.y);
  koch(d-1, u, t);
  printf("%f %f\n", t.x, t.y);
  koch(d-1, t, p2);
}

int main(void){
  int n;
  coodinate start, end;
  start.x = 0;
  start.y = 0;
  end.x = 100;
  end.y = 0;

  scanf("%d", &n);
  printf("%f %f\n", start.x, start.y);
  koch(n, start, end);
  printf("%f %f\n", end.x, end.y);
  return 0;
}



Measured memory_bytes: 2856
a=input()
if a == "SUN":
  print(7)
elif a== "MON":
  print(6)
elif a =="TUE":
  print(5)
elif a =="WED":
  print(4)
elif a =="THU":
  print(3)
elif a =="FRI":
  print(2)
else:
  print(1)
  

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
int main(){
    char s[101];
    int palin,i,flag=0;
    scanf("%s",s);

    int n=strlen(s);
//nos limites do for eu poderia colocar apenas <,mas teria q tirar o -1.
    for(i=0;i <= ((n -1)/2)-1 ;++i){
        if(s[i]!=s[((n-1)/2)-1 - i]){ //comparando o primeiro com o ultimmo
        flag =1;
        break;
    }

    for(int i=(n+ 3)/2; i<=n -1; ++i){
        if(s[i]!=s[n -1 -i]){
            flag =1;
            break;
        }
    }
}
    if(flag){
        printf("No\n");

    }else {
        printf("Yes\n");
    }





    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	double a,b;
	cin >> a >> b;
	cout << ceil((a + b) / 2) << endl;
}


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

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    int ans = 2 * n;
    REP(i, n) {
        string ss = s.substr(i, n - i);
        string tt = t.substr(0, n - i);
        if(ss == tt) {
            ans -= n - i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main(){
  
  string S;
  char t;
  int u;
  int ans;
  
  cin >> S;
  u=S.size();
  for(int i = 0; i < u; i++) {
    if (S.at(i)=='1'){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    for( int i = 1; i <= n; i ++ ) {
        string str;
        cin >> str;
        cout << str << endl << str << endl;
    }
    
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(3*N);
    for (int i=0; i<3*N; i++) {
        cin >> a.at(i);
    }
    long ans = 0;
    sort(a.begin(), a.end(), greater<int>());
    for (int i=1; i<=2*N-1; i+=2) {
        ans += a.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,m;
  cin>>n>>m;
  int a[n];
  int b[n];
  rep(i,0,n) cin>>a[i]>>b[i];
  int c[m];
  int d[m];
  rep(i,0,m) cin>>c[i]>>d[i];
  rep(i,0,n){
    int point=-1;
    int res=3e8;
    rep(j,0,m){
      if(abs(a[i]-c[j])+abs(b[i]-d[j])<res){
        point=j;
        res=abs(a[i]-c[j])+abs(b[i]-d[j]);
      }
    }
    cout<<point+1<<endl;
  }
}

Measured memory_bytes: 256
#ABC 079 C
a,b,c,d=list(input())
s="+-"

for i in range(2):
    for j in range(2):
        for k in range(2):
            if eval(a+s[i]+b+s[j]+c+s[k]+d)==7:
                print(str(a+s[i]+b+s[j]+c+s[k]+d)+"=7")
                exit()

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


int main (){
    int L;
    cin>>L;
    if(L<1200){
        cout<<"ABC"<<endl;
    }
    else if(L<2800){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"AGC"<<endl;
    }

}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
command = []
S = []
for i in range(N):
	S.append(input())

for i in range(N):
	s = S[i]
	if s == "AB":
		if A > B:
			command.append("B")
			B += 1
			A -= 1
		elif A < B:
			command.append("A")
			A += 1
			B -= 1
		else:
			if A == 0:
				print("No")
				exit()
			if i == N-1:
				command.append("A")
				continue
			nxt = S[i+1]
			if nxt == "AB":
				command.append("A")
				A += 1
				B -= 1
			elif nxt == "BC":
				command.append("B")
				B += 1
				A -= 1
			else:
				command.append("A")
				A += 1
				B -= 1
	elif s == "BC":
		if B > C:
			command.append("C")
			C += 1
			B -= 1
		elif B < C:
			command.append("B")
			B += 1
			C -= 1
		else:
			if B == 0:
				print("No")
				exit()
			if i == N-1:
				command.append("B")
				continue
			nxt = S[i+1]
			if nxt == "BC":
				command.append("B")
				B += 1
				C -= 1
			elif nxt == "AC":
				command.append("C")
				C += 1
				B -= 1
			else:
				command.append("B")
				B += 1
				C -= 1
	elif s == "AC":
		if C > A:
			command.append("A")
			A += 1
			C -= 1
		elif C < A:
			command.append("C")
			C += 1
			A -= 1
		else:
			if C == 0:
				print("No")
				exit()
			if i == N-1:
				command.append("C")
				continue
			nxt = S[i+1]
			if nxt == "AC":
				command.append("C")
				C += 1
				A -= 1
			elif nxt == "AB":
				command.append("A")
				A += 1
				C -= 1
			else:
				command.append("C")
				C += 1
				A -= 1
print("Yes")
for c in command:
	print(c)

Measured memory_bytes: 17076
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll ans = N * (N - 1) / 2 + M * (M - 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
function Main(input) {
	tmp = input.split("\n")[0].split(" ");
	var a = parseInt(tmp[0]);
	var b = parseInt(tmp[1]);
	var c = parseInt(tmp[2]);
	console.log(Math.min(c, parseInt(b/a)));
}


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

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

a = [0 for i in range(n)] 
b = [0 for i in range(m)]

for i in range(n):
    a[i] = list(map(int,input().split()))

for i in range(m):
    b[i] = list(map(int,input().split()))

for i in range(n):
    ans = []
    for j in range(l):
        c = 0
        for k in range(m):
            c += a[i][k] * b[k][j]
        ans.append(c)
    print(*ans)


Measured memory_bytes: 6584
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (1 << 21)
using namespace std;

vector<long long int> a(2000000);
int h = 0;

void maxHeapify(int i){
  int largest;
  int l = i*2;
  int r = i*2+1;

  if(l <= h && a[l] > a[i]) largest = l;

  else largest = i;

  if(r <= h && a[r] > a[largest]) largest = r;

  if(largest != i){
    swap(a[i], a[largest]);
    maxHeapify(largest);
  }
}

int heapextract(){
  int maxv;

  if(h < 1) return -INF;

  maxv = a[1];
  a[1] = a[h--];

  maxHeapify(1);

  return maxv;

}

void heapincreaseKey(int i, int key){
  if(key < a[i]) return;

  a[i] = key;

  while(i > 1 && a[i/2] < a[i]){
    swap(a[i], a[i/2]);
    i = i / 2;
  }
}

void insert(int key){
  h++;
  a[h] = -INF;

  heapincreaseKey(h, key);
   
}

int main()
{
  int key;
  string s;

  while(1){
    cin >> s;
    
    if(s == "end") break;
    
    if(s == "insert"){
      cin >> key;
      insert(key);
    }
    
    else{
      cout << heapextract() << endl;;
    }   
  }
  
  return 0;
  
}



Measured memory_bytes: 18236
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


vll len(55), p(55);

ll burg(int n, ll x) {
    if (n == 0) return x <= 0 ? 0 : 1;
    else if (x <= 1 + len[n-1]) {
        return burg(n-1, x-1);
    } else {
        return 1 + p[n-1] + burg(n-1, x - 2 - len[n-1]);
    }
}

int main() {
    ll n, x;
    cin >> n >> x;
    len[0] = 1;
    srep(i, n, 1) len[i] = len[i-1] * 2 + 3;
    rep(i, n) p[i] = pow(2, i+1)-1;
    ll ans = burg(n, x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e15;

int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll rb;
    ll lb=0;
    if(n>=b){
        rb=b-1;
    }
    else{
        rb=n;
    }
    ll left=a*rb/b;
    cout << left << endl;
    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> field(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> field[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if((i%2&&j<w-1)||j==0){
        cout << '#';
      }else{
        cout << field[i][j];
      }
    }
    cout << endl;
  }
  cout << endl;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if((i%2==0&&j>0)||j==w-1){
        cout << '#';
      }else{
        cout << field[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {

int main(void) {
  int n,m;cin>>n>>m;
  int H[n+10];
  rep(i,0,n-1) {
    cin>>H[i];
  }
  vector<int> Load[n+10];
  int a,b;
  rep(i,0,m-1) {
    cin>>a>>b;
    a--;
    b--;
    Load[a].push_back(b);
    Load[b].push_back(a);
  }

  int ans=0;
  rep(i,0,n-1) {
    if(Load[i].size()==0) {
      ans++;
      continue;
    }
    bool mark=true;
    for(auto l:Load[i]) {
      if(H[l]>=H[i]) {
        mark=false;
      }
    }

    if(mark) {
      ans++;
    }
  }

  pr(ans);

  return 0;
}


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

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<double> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    for (int i = 1; i < n; i++) {
        arr[i] = (arr[i] + arr[i - 1]) / 2;
    }
    cout << fixed << setprecision(6) << arr.back();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}


void solve()
{
  ll N;
  std::cin >> N;

  std::vector< std::pair<ll, ll> > vp(N);
  for (ll i = 0; i < N; i++) {
    ll x, l;
    std::cin >> x >> l;
    vp[i].first  = x + l;
    vp[i].second = x - l;
  }

  std::sort(vp.begin(), vp.end(), std::less<>());

  ll ans = 0LL;
  ll tol = -INF;
  for (auto p : vp) {
    ll s = p.second;
    ll t = p.first;

    if (s < tol) {
      continue;
    } else {
      ans++;
      tol = t;
    }
  }

  print(ans);
  return;
}

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  solve();
  return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N; cin >> N; cout << (N-1)/2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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; }

using ll = long long;

ll N;
std::vector<ll> b( 110 ), S[110];
std::vector<ll> ans;

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> b[i], --b[i];

  rep( i, N )
  {
    repd( j, N ) if( b[j] == j )
    {
      ans.emplace_back( j+1 );
      b.erase( b.begin()+j );

      break;
    }

    if( ans.size() != i+1 )
    {
      std::cout << -1 << std::endl;

      return 0;
    }
  }

  repd( i, N )
    std::cout << ans[i] << std::endl;

  return 0;
}

Measured memory_bytes: 256