akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int n,r;
  int p,c;
  while(1){
    cin >> n >> r;
    if(n == 0) break;
    vector<int> A(n);
    for(int i = 0; i< n; i++){
      A[i] = n -i;
    }
    for(int i = 0; i < r; i++){
      cin >> p >> c;
      rotate(A.begin(),A.begin()+p-1,A.begin()+p+c-1);
      
    }
    cout << A[0]<< endl;
  }
  return 0;
}
    
    
    
      
      

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(),a.end());
  int res;
  for(int i=0;i<n;i++){
    res=a[n-1].first;
    if(i==a[n-1].second && a[n-1].first!=a[n-2].first)res=a[n-2].first;
    cout << res << endl;
  }
}


Measured memory_bytes: 3200
fn main() {
    a();
}


fn a() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let nums: Vec<i32> = s.trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
    let ans = if nums[0] == 2 || nums[1] == 2  {
        "No"
    } else {
        "Yes"
    };
    println!("{}",ans);
}


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

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

using namespace std;

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

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

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

int main(){
	int n;
	while(cin>>n,n){
		int a[1000],p[1000],q[1000],r[1000];
		for(int i =0;i <n;i++){
			scanf("%d %d %d %d",&a[i],&p[i],&q[i],&r[i]);
		}
		int P,Q,R,C;
		scanf("%d %d %d %d",&P,&Q,&R,&C);
		bool flag =false;
		for(int i =0;i < n;i++){
			if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&(4*(p[i]+r[i])+9*q[i]<=C)){
				flag =true;
				printf("%d\n",a[i]);
			}
		}
		if(!flag)cout <<"NA"<<endl;
	}
	return 0;
}

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

int main() {
    string a = "CODEFESTIVAL2016";
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a.at(i) != s.at(i)) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }
    int p = 0;
    int ans = 1;
    while (a[p] != 0) {
        if (a[p] == 1) {
            cout << ans << endl;
            return;
        }
        int q = a[p];
        a[p] = 0;
        p = q;
        ans++;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
N = int(input())
A = list(map(int,input().split()))

result = "APPROVED"
for n in A:
    if n % 2 != 0:
        continue
    if n % 3 == 0:
        continue
    if n % 5 == 0:
        continue
    result = "DENIED"
    break
print(result)


Measured memory_bytes: 2940
n, m, k = gets.chomp.split.map(&:to_i)
if k % m == 0 || k % n == 0
  puts "Yes"
else
  1.step(n) do |i|
    1.step(m) do |j|
      if m * i + n * j - 2 * i * j == k
        puts "Yes"
        exit
      end
    end
  end
  puts "No"
end

Measured memory_bytes: 14216
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        while (true)
        {
            var de = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (de[0] == 0) break;
            var d = de[0];
            var e = de[1];
            double min = double.MaxValue;
            for (int i = 0; i <= d; i++)
            {
                var diff = Abs(Sqrt(i * i + (d - i) * (d - i)) - e);
                min = Min(min, diff);
            }
            Console.WriteLine(min);
        }
    }
}


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

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

    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    
    int cnt = 0, bc = 0;
    REP(i, n){
        bool f = false;
        if(s[i] == 'a'){
            if(cnt < a + b){
                f = true;
                cnt++;
            }
        }else if(s[i] == 'b'){
            if(cnt < a + b){
                if(bc < b){
                    f = true;
                    cnt++;
                    bc++;
                }
            }
        }
        if(f) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

bool DFS(int R, vector< vector<int> > & G, vector<int> & par, vector<int> & dep, vector<int> & used, vector< pair<int, int> > & ans) {
	vector<int> free;
	for(auto v : G[R]) {
		if(par[v] == -1) {
			par[v] = R;
			dep[v] = dep[R]+1;
			DFS(v, G, par, dep, used, ans);
			if(!used[v]) free.push_back(v);
		}
		if(par[v] != R && par[R] != v && dep[v] < dep[R]) free.push_back(v); // backlink
	}
	while((int)free.size() >= 2) {
		int v = free.back();
		free.pop_back();
		int u = free.back();
		free.pop_back();
		ans.push_back({R, u});
		ans.push_back({R, v});
	}
	if(!free.empty()) {
		if(par[R] == R) return false;
		ans.push_back({R, free[0]});
		ans.push_back({R, par[R]});
		used[R] = true;
	}
	return true;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, M;
	cin >> N >> M;
	vector< vector<int> > G(N);
	for(int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		G[--u].push_back(--v);
		G[v].push_back(u);
	}
	vector<int> par(N, -1), used(N, 0), dep(N, 0);
	vector< pair<int, int> > ans;
	for(int i = 0; i < N; i++) if(par[i] == -1) {
		par[i] = i;
		if(!DFS(i, G, par, dep, used, ans)) {
			cout << "-1\n";
			return 0;
		}
	}
	for(int i = 0; i < M; i++) cout << ans[i].ff+1 << " " << ans[i].ss+1 << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define MP make_pair
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double EPS = 1e-9;
const double PI = acos(-1);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

ll addMod(ll a, ll b){
	return (a+b) % MOD;
}

ll mulMod(ll a, ll b){
	return (a*b) % MOD;
}

/////////////////////////////////////////////////////////

const int N = 100;

int w,h,n;
int x[N + 5], y[N + 5], a[N + 5];
bool flag[N + 5][N + 5];

int solve(){
	int mxx = 0, mxy = 0, mnx = w, mny = h;
	FOR(i,n){
		if(a[i] == 1){
			mxx = max(mxx, x[i]);
		}
		else if(a[i] == 2){
			mnx = min(mnx, x[i]);
		}
		else if(a[i] == 3){
			mxy = max(mxy, y[i]);
		}
		else{
			mny = min(mny, y[i]);
		}
	}
	if(mnx < mxx) mnx = mxx;
	if(mny < mxy) mny = mxy;
	int ret = 0;
	ret += max(0,h - mny) * w;
	ret += mxy * w;
	ret += mxx * h;
	ret += max(0,w - mnx) * h;
	ret -= mxx * max(0,h-mny);
	ret -= mxx * mxy;
	ret -= max(0,w-mnx) * max(0,h-mny);
	ret -= max(0,w-mnx) * mxy;
	return w*h-ret;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> w >> h >> n;
	FOR(i,n) cin >> x[i] >> y[i] >> a[i];
	cout << solve() << endl;
	return 0;
}

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

H,W,N = map(int,input().split())
sr,sc = map(int,input().split())
S = input().rstrip()
T = input().rstrip()

sr = H+1-sr

# ここに居たら後手の価値
L,R = 1,W
D,U = 1,H
for s,t in zip(S[::-1],T[::-1]):
    if t == 'L': R += 1
    elif t == 'D': U += 1
    elif t == 'R': L -= 1
    elif t == 'U': D -= 1
    
    if L == 0: L = 1
    if D == 0: D = 1
    if R > W: R = W
    if U > H: U = H

    if s == 'L': L += 1
    elif s == 'R': R -= 1
    elif s == 'D': D += 1
    elif s == 'U': U -= 1
    
    if L>R or D>U:
        # 後手の勝てる場所が存在せず
        break

bl = (L <= sc <= R) and (D <= sr <= U)
answer = 'YES' if bl else 'NO'
print(answer)

Measured memory_bytes: 4024
from string import ascii_lowercase

s = input()
t = input()
dic = {}
used = {}
for c in ascii_lowercase:
    dic[c] = None
    used[c] = False

for ss, tt in zip(s, t):
    if dic[tt] is None:
        if used[ss]:
            print('No')
            exit()
        else:
            dic[tt] = ss
            used[ss] = True
    elif dic[tt] != ss:
        print('No')
        exit()
else:
    print('Yes')


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;
  vi a(n);
  rep(i,n) cin >> a[i];
  int sum = 0;
  rep(i,n) sum += a[i];
  sort(rall(a));
  int bor = (sum + (4*m) - 1) / (4*m);
  YesorNo(a[m-1] > bor - 1);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  int N, M, X;
  cin >> N >> M >> X;
  int A[M];
  int ans = 0, ans1 = 0;
  for(int i=0;i<M;i++){
    cin >> A[i];
    if(A[i] < X){
    ans++;
    }
    else ans1++;
  }
  cout << min(ans, ans1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int a=0, cnt=0;
  for(int i=0; i<s.size(); i++) {
    if(s.at(i)=='R') {
      cnt++;
      a=cnt;
    }
    else {
      cnt=0;
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3592
def input_li():
    return list(map(int, input().split()))


def input_int():
    return int(input())


N = input_int()
S = input()
ans = 0
for i in range(1000):
    str_i = str(i)
    s = '0' * (3 - len(str_i)) + str_i
    idx = 0
    for j in range(N):
        if S[j] == s[idx]:
            idx += 1
            if idx == 3:
                ans += 1
                break
print(ans)


Measured memory_bytes: 68236
#include <bits/stdc++.h>
using namespace std;
int i, j, k;
int N;
char C[4000];
int A[4000];
int rev_b[2001];
int rev_w[2001];
int before_b[4000][2001];
int before_w[4000][2001];
int dp[2001][2001];

int main(){
    cin >> N;
    for(i=0; i<2*N; i++){
        cin >> C[i] >> A[i];
        if(C[i] == 'B'){
            rev_b[A[i]] = i;
            before_b[i][A[i]] += 1;
        }else{
            rev_w[A[i]] = i;
            before_w[i][A[i]] += 1;
        }
    }
    for(i=0; i<2*N; i++){
        for(j=2; j<=N; j++){
            before_b[i][j] += before_b[i][j-1];
            before_w[i][j] += before_w[i][j-1];
        }
    }
    for(i=1; i<2*N; i++){
        for(j=1; j<=N; j++){
            before_b[i][j] += before_b[i-1][j];
            before_w[i][j] += before_w[i-1][j];
        }
    }
    int sum;
    for(sum=1; sum<=2*N; sum++){
        int lb = max(0, sum - N);
        int ub = min(sum, N);
        int b, w;
        for(b=lb; b<=ub; b++){
            w = sum - b;
            int cand = 1<<30;
            if(b>0){
                int pos = rev_b[b];
                int d = dp[b-1][w] + pos - before_b[pos][b-1] - before_w[pos][w];
                cand = min(cand, d);
            }
            if(w>0){
                int pos = rev_w[w];
                int d = dp[b][w-1] + pos - before_b[pos][b] - before_w[pos][w-1];
                cand = min(cand, d);
            }
            dp[b][w] = cand;
        }
    }
    cout << dp[N][N] << endl;
    return 0;
}

Measured memory_bytes: 78464
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

void main()
{
	auto N = RD!long;
	auto M = RD!long;
	auto A = RDR.split.to!(long[]);
	auto cnt = [2, 5, 5, 4, 5, 6, 3, 7, 6];
	long[2][] use;
	foreach (e; A)
	{
		use ~= [cnt[e-1], e];
	}
	use.sort!"a[1] > b[1]"();
	
	auto dp = new long[][](N+1);
	dp[0] = [0];
	foreach (i; 0..N+1)
	{
		long[][] tmp;
		foreach (e; use)
		{
			auto di = i - e[0];
			if (di < 0) continue;
			if (dp[di].length == 0) continue;
			tmp ~= dp[di] ~ e[1];
		}
		long len;
		foreach (e; tmp)
		{
			len = max(len, e.length);
		}
		foreach (e; tmp)
		{
			if (e.length != len) continue;
			dp[i] = e;
			break;
		}
	}
	stderr.writeln(dp[N]);

	dp[N].sort();
	foreach_reverse (e; dp[N][1..$])
	{
		write(e);
	}

	writeln();
	stdout.flush();
}

Measured memory_bytes: 487420
s = list(input())

cnt = 0

for i in range(int(len(s))):
    if i == int(len(s)):
        break
    elif i == 0:
        continue
    else:
        if s[i] == s[i-1]:
            cnt += 1
            if s[i] == '0':
                s[i] = '1'
            else:
                s[i] = '0'

print(cnt)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 3000005;
int fac[MAX], inv[MAX], finv[MAX];
int mod = 1e9+7;

signed main(){
  //pre();
  int n,k;
  cin >> n >> k;
  
  int c = 0,d = 0, ans = 0;
  
  if(k%2){
    c = n/k;
    //cout << c << endl;
    ans = c*c*c;
  }
  else{
    d = n/(k/2);
    c = n/k; 
    //cout << d << endl;
    ans = pow(d-c, 3) + pow(c,3);
  }
  
  cout << ans << endl;
  return 0;
}
    


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,cnt,ans=0,i,j;
    cin>>n;
    for (i=4;i<=n;i++)
    {
        cnt=2;
        for (j=2;j<=sqrt(i);j++)
        {
            if (i%j==0)
            {
                if (i==j*j)
                    cnt++;
                else
                    cnt+=2;
            }
        }
        if (cnt==8 and i&1)
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;

    vector<string> s(n);
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      vector<char>vc;
      for (size_t j = 0; j < 10; j++) {
        vc.push_back(s[i][j]);
      }
      sort(vc.begin(), vc.end());
      s[i]=string(vc.begin(), vc.end());
      //cout<<s[i]<<endl;
    }

    sort(s.begin(), s.end());

    long long o=0;
    long c=1;
    for (int i = 1; i < n; i++) {
      if(s[i-1]==s[i]) {
        c++;
      }
      else {
        o += c*(c-1)/2;
        c=1;
      }
    }
    o += c*(c-1)/2;

    cout<<o<<endl;
    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ll long long int
#define sd(x) scanf("%d",&x)
#define F first
#define S second
#define sd2(x,y) scanf("%d%d",&x,&y);
#define mp make_pair
#define pb push_back
#define pi pair <int, int > 
#define pl pair <ll, int >
#define infl (1ll << 60)
#define inf (1 << 30)
#define nax  1100000
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
multiset  < int > bg;
multiset <int, greater< int > > sm;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int q;
    sd(q);
    int a, b, c;
    ll s1,s2;
    s1 = s2 = 0;
    ll rsum = 0;
    int cnt = 0;
    while(q--)
    {
        sd(a);
        //cout << a << "d\n";
        if(a == 1)
        {
            cnt++;
            sd2(b, c);
            rsum += c;
            int siz1 = sm.size();
            int siz2 = bg.size();
            if(siz1 != siz2)
            {
                int c_big = *bg.begin();
                s2 -= c_big;
                bg.erase(bg.find(c_big));
                if(b > c_big)
                    swap(b, c_big);
                bg.insert(c_big);
                s2 += c_big;
                sm.insert(b);
                s1 += b;
            }
            else
            {
                if(siz1 != 0)
                {
                    int c_sml = *sm.begin();
                    sm.erase(sm.find(c_sml));
                    s1 -= c_sml;
                    if(c_sml > b)
                        swap(c_sml, b);
                    sm.insert(c_sml);
                    s1 += c_sml;
                }
                bg.insert(b);
                s2 += b;
            }
           // cout << s1 << " " << s2 << '\n';
        }
        else
        {
            int med = 0; ll cans;
            if(cnt % 2 == 1)
                med = *bg.begin();
            else
                med = *sm.begin();

            cans = s2 - s1 - (cnt % 2 == 1 ? *bg.begin() : 0) + rsum;
            //cout << rsum << "dd\n";
            printf("%d %lld\n", med, cans);
        }
    }
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct Dice {
  int face[6];
  Dice() {}
  int& operator [] (int i) { return face[i]; }
  bool operator == (const Dice& other) {
    for (int i = 0; i < 6; i++) if (face[i] != other.face[i]) return false;
    return true;
  }
  bool operator != (const Dice& other) {
    return !(*this == other);
  }
  void roll(int a, int b, int c, int d) {
    int tmp = face[a];
    face[a] = face[b];
    face[b] = face[c];
    face[c] = face[d];
    face[d] = tmp;
  }
  void roll(char c) {
    switch (c) {
      case 'N' : roll(0, 1, 5, 4); break;
      case 'S' : roll(0, 4, 5, 1); break;
      case 'E' : roll(0, 3, 5, 2); break;
      case 'W' : roll(0, 2, 5, 3); break;
      case 'R' : roll(1, 2, 4, 3); break;
      case 'L' : roll(1, 3, 4, 2); break;
    }
  }
  bool identical(Dice other) {
    for (int i = 0; i < 6; i++) {
      other.roll(i & 1 ? 'E' : 'N');
      for (int j = 0; j < 4; j++) {
        other.roll('R');
        if (*this == other) return true;
      }
    }
    return false;
  }
};

vector<string> ord = {"Red", "Yellow", "Blue", "Magenta", "Green", "Cyan"};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<Dice> D(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 6; j++) {
        string s;
        cin >> s;
        D[i][j] = find(ord.begin(), ord.end(), s) - ord.begin();
      }
    }
    int ans = n;
    for (int i = 0; i < n; i++) {
      bool no = false;
      for (int j = 0; j < i; j++) {
        no |= D[i].identical(D[j]);
      }
      if (no) continue;
      ans--;
    }
    cout << ans << endl;
  }

  return 0;
}


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

#define ll long long 
#define dou  double 
#define endl "\n"

const int MOD=1e9+7;

int main()
{
	int n;
	cin >> n;
	int d1[n],d2[n];
	for(int i=0;i<n;i++)
		cin >> d1[i] >> d2[i];
	int count=0,flag=0,ur=0;
	for(int i=0;i<n;i++){
		if(d1[i]==d2[i])
			count++;
		else
			count=0;
		if(count==3){
			flag=1;
			break;
		}
	}
	if(flag==1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class Program{
  public static void Main(){

    var input = Console.ReadLine().Split();
    int h = int.Parse(input[0]);
    int w = int.Parse(input[1]);
    

    for(int i=0;i<h+2;i++){
      if(i==0 || i==h+1){
        for(int j=0; j<w+2; j++){
          Console.Write("#");
        }
        Console.WriteLine("");
      }
      else{
        Console.Write("#");
        string s = Console.ReadLine().Replace(" ","");
        Console.Write(s);
        Console.WriteLine("#");
      }
    }
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    
    int A;
    int B;
    int T;
    
    cin >> A;
    cin >> B;
    cin >> T;
    
    int remainder = T % A;
    
    cout << ( T - remainder ) * B / A << endl;
    
    return 0;
 
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i,j,values[3];
	scanf("%d\n",&i);

	for(j=0;j<i;j++)
	{
		scanf("%d %d %d",&values[0],&values[1],&values[2]);
		sort_aoj_volume0003(values);
		if(values[0]*values[0] + values[1]*values[1] == values[2]*values[2])
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

void sort_aoj_volume0003(int values[])
{
	int i,count=3;
	while(count > 1)
	{
		for(i=1;i<count;i++)
		{
			if(values[i] < values[i-1])
			{
				int value_2 = values[i-1];
				values[i-1] = values[i];
				values[i] = value_2;
			}
		}
		count--;
	}
	return;
}

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

static const int MAX = 200;
static const int INF = 1e9;

// 隣接行列を用いた幅優先探索 O(|V|^2)
int n, M[MAX][MAX];
vector<int> d(MAX, INF); // 始点sから頂点iまでの最短距離をd[i]に記録
// main関数からこれらを削除すること

bool bfs(int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int v = 0; v < n; v++){
      if(M[u][v] == 0) continue;
      if(d[v] != INF){
        if(d[v] % 2 != (d[u] + 1) % 2) return false;
        else continue;
      }
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  return true;
}

// 隣接行列を用いた幅優先探索 O(|V|^2)
void bfs2(int s) {
  queue<int> q;
  q.push(s);
  d[s] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int v = 0; v < n; v++){
      if(M[u][v] == 0) continue;
      if(d[v] != INF) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
}

int main() {
// 無向(有向)グラフの隣接行列
  int u, v;
  cin >> n;
  
  char s;
  string t;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> s;
      t = s;
      M[i][j] = stoi(t);
    }
  }
  
  if(!(bfs(0))){
    cout << -1 << endl;
    return 0;
  }
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      d[j] = INF;
    }
    
    bfs2(i);
    for(int j = 0; j < n; j++){
      ans = max(ans, d[j] + 1);
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
program geonowe
implicit none
integer :: a,b,c,i

read(*,*) a,b,c

do i = 1, b
	if ( mod(a*i,b) == c ) then
		write(*,'(a)') 'YES'
        stop
    end if
end do
write(*,'(a)') 'NO'
stop

end program geonowe

Measured memory_bytes: 2928
n = int(input())
l = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += min(l[i], a[i])
    a[i] -= min(l[i], a[i])
    ans += min(l[i + 1], a[i])
    l[i + 1] -= min(l[i + 1], a[i])
print(ans)

Measured memory_bytes: 18476
/* 
 * Author: aps
 * Time: 29-06-2019 18:10:18
**/
#include<bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int,int> pii;

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

inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x;}
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += mod; return x;}
inline ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod;}
inline ll power(ll a, ll b) {
    ll x = 1;
    while (b) {
        if (b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline ll inv(ll a) { return power(a, mod - 2);}

const int N = 2005;

ll fact[N],ifact[N];

void init(){
    fact[0] = ifact[0] = 1;
    for(int i=1;i<N;i++) {
        fact[i] = mul(fact[i-1],(ll)i);
    }

    ifact[N-1] = inv(fact[N-1]);
    for(int i=N-2;i>=1;i--){
        ifact[i] = mul(ifact[i+1],(ll)(i+1));
    }
}

ll C(ll n,ll r){
    if(n < r) return 0LL;
    if(r == 0) return 1LL;
    return mul(fact[n], mul(ifact[r],ifact[n-r]));
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    init();
    ll n,k; cin >> n >> k;
    ll x = n-k+1, y = k-1;
    for(ll i=1;i<=k;i++){
        cout << mul(C(x,i),C(y,i-1)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(){
	int x, y, n, t, aux1=1000, i, u=0;
	scanf("%i %i", &x, &y);
	i=x;
	while(i--){
		scanf("%i %i", &n, &t);
		if(t<=y){
			if(n<=aux1&&t){
				//aux=t;
				aux1=n;
				u=1;
			}		
		}
	}
	if(u==1)
		printf("%i\n", aux1);
	else
		printf("TLE\n");


}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int A,B,C;cin>>A>>B>>C;
	cout<<max(0,C-A+B)<<endl;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
string a,b,c;

int main() {
    cin >> a >> b >> c;
    if (a.back() == b[0] && b.back() == c[0]) {
        cout << "YES" << '\n';
    } else {
        cout << "NO" << '\n';
    }

    return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    int mn=999999;
    vector<int> A(5),B={0,1,2,3,4};

    for(auto &i: A)
        cin >> i;

    do{
        int cc=0;

        FOR(i,0,5){
            while(cc%10!=0)
                cc++;
            cc+=A[B[i]];
        }

        mn=min(mn,cc);
    }while(next_permutation(B.begin(),B.end()));


    cout << mn << endl;

    return 0;
}


Measured memory_bytes: 256
# あえてややこしいコードにします。　いろいろ使ってみたい
bell1, bell2, bell3 = map(int, input().split())

bell_list = [bell1, bell2, bell3]
min_price_bell = []

bell_list.sort()

for i in range(0, 2):
    min_price_bell.append(bell_list[i])

print(sum(min_price_bell))


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int N = 50;
ll op[N + 100];

int main() {
	ll K;
	cin >> K;
	for(int i = 0; i < N; i++)
		op[i] = K / N;
	for(int i = 0; i < K % N; i++)
		op[i]++;
	printf("%d\n", N);
	for(int i = 0; i < N; i++) {
		debug("op[%d]: %lld\n", i, op[i]);
		ll a = N - 1 + op[i] * N - (K - op[i]);
		assert(0 <= a && a <= (ll)1e16 + 1000);
		printf("%lld%c", a, " \n"[i == N - 1]);
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int isFirst = 0;
    rep(i, N) {
        if(A[i] % 2)
            isFirst = 1;
    }
    if(isFirst)
        cout << "first" << endl;
    else
        cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}

int main(){
  fastIO();
  ll x;
  cin>>x;
  for(int i=-1000;i<=1000;i++){
    for(int j=-1000;j<=1000;j++){
      ll ans = pow(i,5)-pow(j,5);
      if(ans==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
  return 0;
}


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

vector<vector<int>> edges;
vector<int> visited;
void dfs(int v, vector<int>& dist, vector<int>& indegree) {
    visited[v] = 1;
    for(int nei: edges[v]) {
        dist[nei] = max(dist[nei], dist[v]+1);
        indegree[nei]--;
        if(indegree[nei] == 0) {
            dfs(nei, dist, indegree);
        }
    }
}

int main()
{
    int N, M;
    cin >> N >> M;
    edges.resize(N+1);
    visited.resize(N+1);
    vector<int> indegree(N+1);
    vector<int> dist(N+1);
    for(int m = 0; m < M; m++) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        indegree[b]++;
    }

    for(int i = 1; i <= N; i++) {
        if(!visited[i] && indegree[i] == 0) {
            dfs(i, dist, indegree);
        }
    }

    int ans = 0;
    for(int i = 1; i <= N; i++) {
        ans = max(ans, dist[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11520
K,N  =list(map(int,input().split()))
A = list(map(int,input().split()))
C = list()
ans = int()
B = list(sorted(A))
for i in range(len(B)-1):
    C.append(B[i+1]-B[i])
C.append((K-B[-1])+(B[0]))
C = sorted(C)
for i in range(N-1):
    ans += C[i]
print(ans)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
 
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
 
const ll big=998244353;
int exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    string s,t;cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t)cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 10000;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int cost; };

signed main() {
	int n, a, b; cin >> n >> a >> b;
	vector<int>V;
	int flg = 0;
	if (a + b > n + 1)flg++;
	int mb = (n+a-1) / a;
	if (mb > b)flg++;
	for(int i=n-1;i>=0;i--) {
		int cnt = i + 1 + (n - 1 - i) / a;
		if (cnt == b) {//cout << i << endl;
			V.push_back(a);
			rep(j, i)V.push_back(1);
			rep(j, (n - i - 1) / a) {
				if ((!j)&&(n-i)%a)V.push_back((n - i) % a);
				else V.push_back(a);
			}
			break;
		}
	}
	if (flg) {
		cout << -1 << endl; return 0;
	}

	int mn = 1;
	stack<int>S;
	for (int i = V.size() - 1; i >= 0; i--) {
		rep(j, V[i]) {
			S.push(mn + V[i] - 1 - j);
		}
		mn += V[i];
	}
	while (S.size()) {
		cout << S.top();
		S.pop();
		if (S.size())cout << ' ';
	}cout << endl;
}

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

typedef long long ll;

int main()
{

    ll n,a,b,i,c=0;
    string st;
    cin >> st >> n;
    for(i=0; i<st.size(); i++)
    {
        char ch=st[i];
        c++;
        if(ch=='1')
        {
            if(c==n)
            {
                cout << ch << "\n";
                return 0;
            }
            continue;
        }
        cout << ch << "\n";
        return 0;
    }


    return 0;
}



Measured memory_bytes: 256
// aren't we just terrified?

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
 
bool codejam = 0;
 
typedef long long li;
typedef long double ld;
 
void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	string lol = "";
	for (int i = 0; i < a; i += 1) 
		lol += '1';
	while ((int) lol.size() < m)
		lol += '0';
	for (int i = 0; i < b; i += 1) {
		cout << lol << '\n';
	}
	for (auto &i : lol)
		i = ('0' ^ ('1' ^ i));
	for (int i = b; i < n; i += 1)
		cout << lol << '\n';
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main()
{
    int n,m=0,k=0,a[100],b[100],i;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=0;i<n;i++)
        cin>>b[i];
    for(i=0;i<n;i++)
        {
            k=a[i]-b[i];
            if(k>0)
                m+=k;
        }
        cout<<m<<endl;
    return 0;
}


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

using namespace std;

int main()
{
	priority_queue<int> pq;
	while(true)
	{
		char s[10];
		scanf("%s",s);
		if(s[2]=='s')
		{
			int t;
			scanf("%d",&t);
			pq.push(t);
		}
		else if(s[2]=='t')
		{
			printf("%d\n",pq.top());
			pq.pop();
		}
		else break;
	}
	return 0;
}

Measured memory_bytes: 6944
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int H,W;
char f[51][51];
bool reach[51][51] = {0};
int vx[4] = {1,0,-1,0};
int vy[4] = {0,1,0,-1};
int white = 0;
int check = -1;

struct corr{
    int x;
    int y;
    int d;
};

queue<corr> Q;

int bfs()
{
    while (!(Q.empty())){
        corr now = Q.front();
        Q.pop();
        int nowx = now.x;
        int nowy = now.y;
        int nowd = now.d;
        
        if (nowx == H-1 && nowy == W-1){
            check = nowd;
            break;
        }
        else {
            for (int i = 0;i < 4;i++){
                corr next;
                next.x = nowx+vx[i];
                next.y = nowy+vy[i];
                next.d = nowd+1;
                if (0 <= next.x && next.x < H && 0 <= next.y && next.y < W && f[next.x][next.y] == '.' && reach[next.x][next.y] == 0){
                    reach[next.x][next.y] = 1;
                    Q.push(next);
                }
            }
        }
    }
    if (check == -1){
        return -1;
    }
    else {
        return check;
    }
}


int main()
{
    cin >> H >> W;
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            cin >> f[i][j];
            if (f[i][j] == '.'){
                white++;
            }
        }
    }
    
    corr start = {0,0,0};
    Q.push(start);
    reach[0][0] = 1;
    
    if (bfs() == -1){
        cout << -1 << endl;
    }
    else {
        cout << white - 1 - bfs() << endl;
    }
}
 


Measured memory_bytes: 3576
#include <stdio.h>

//?????§????´¢
int search(int A[],int n,int key){
	int i=0;
	A[n] = key;
	while(A[i]!=key){
		i++;
	}
	return i!=n;
} 

int main(){
	int i,n,A[100001],q,key,sum=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",&key);
		if(search(A,n,key))
		sum++;
			}
			
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 644
def main():
	n, q = map(int, input().split())
	s = "."+input()+"."
	pm = [input().split() for _ in range(q)]

	def is_outside(x:int) -> int:
		for point, move in pm:
			if s[x] == point:
				if move == "L":
					x -= 1
				else:
					x += 1
			if x == 0:
				return -1
			if x == n+1:
				return 1
		return 0

	ok, ng = 0, n+1
	while ng - ok > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == -1:
			ok = mid
		else:
			ng = mid
	l = ok

	ng, ok = 0, n+1
	while ok - ng > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == 1:
			ok = mid
		else:
			ng = mid
	r = ng

	print(max(r-l, 0))

if __name__ == '__main__':
    main()

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

int main() {
  int n,m;cin>>n>>m;
  vector<int> h(n),vec(n);
  rep(i,n)cin>>h[i];
  rep(i,m){
    int a,b;cin>>a>>b;
    a--;b--;
    if(h[a]<=h[b])vec[a]++;
    if(h[b]<=h[a])vec[b]++;
  }
  int cnt=0;
  rep(i,n){
    if(vec[i]==0)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 4044
require "set"
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)

hash = {}
max = 0
set = Set.new
a_arr.each do |a|
  hash[a] ||= 0
  hash[a] += 1
  max = a if a > max
  set << a
end

hash.each do |k, v|
  i = v > 1 ? 1 : 2
  tmp = k * i
  while tmp <= max do
    hash.delete(tmp)
    i += 1
    tmp = k * i
  end
end

puts hash.size

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

using namespace std;

int main() {
	long long int N;
	cin >> N;
	vector<long long int>A( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	if( A[0] < 0 ) {
		for( size_t i = 0; i < N; i++ ) {
			A[i] *= -1;
		}
	}
	long long int sum = A[0], ans = 0;
	if( sum == 0 ) {
		sum++;
		ans++;
	}
	for( size_t i = 1; i < N; i++ ) {
		if(! (i % 2) ) {
			sum += A[i];
			if( sum <= 0 ) {
				ans += 1 - sum;
				sum = 1;
			}
		} else {
			sum += A[i];
			if( sum >= 0 ) {
				ans += sum + 1;
				sum = -1;
			}
		}
	}
	long long int memo = ans;
	ans = A[0] + 1;
	sum = -1;

	for( size_t i = 1; i < N; i++ ) {
		if( ( i % 2 ) ) {
			sum += A[i];
			if( sum <= 0 ) {
				ans += 1 - sum;
				sum = 1;
			}
		} else {
			sum += A[i];
			if( sum >= 0 ) {
				ans += sum + 1;
				sum = -1;
			}
		}
	}
	
	cout << min( ans, memo ) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;

struct RollingHash {
    int n;
    long long base1, base2, mod1, mod2;
    vector<long long> hash1, hash2, pow1, pow2;
    RollingHash(const string &s) : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) {
        n = s.size();
        hash1.assign(n + 1, 0);
        hash2.assign(n + 1, 0);
        pow1.assign(n + 1, 1);
        pow2.assign(n + 1, 1);
        for(int i = 0; i < n; i++) {
            hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
            hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    //[l, r)
    pair<long long, long long> get(int l, int r) {
        long long t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
        long long t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
        return {t1, t2};
    }
    // LCP of S[l, ..] and S[r, ..]
    int LCP(int l, int r){
        int len = n - r;
        int low = -1, high = len + 1;
        while(high - low > 1){
            int mid = (low + high) / 2;
            if(get(l, l + mid) == get(r, r + mid)) low = mid;
            else high = mid;
        }
        return low;
    }
};

signed main(){
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    string ss = s;
    string tt = t;
    while(ss.size() < t.size()) ss += s;
    int len = ss.size();
    ss += ss + ss;
    while(tt.size() < ss.size()) tt += t;
    string r = ss + "$" + tt;
    int tidx = ss.size() + 1; 
    RollingHash rh(r);
    int MAX = 0;
    for(int i = 0; i < len; i++){
        int tmp = rh.LCP(i, tidx);
        MAX = max(MAX, tmp);
    }
    if(MAX >= len * 2) cout << -1 << endl;
    else cout << MAX / m << endl;
}

Measured memory_bytes: 206480
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

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

	int len = 1; ll base = 26;
	while (N - base > 0) {
		N -= base;
		base *= 26;
		len++;
	}
	N--;

//	cout << base << ' ' << N << ' ' << len << '\n';
	string s = "";
	for (int i = 0; i < len; i++) {
		s += ('a' + (N % 26));
		N /= 26;
	}
	reverse(all(s));
	cout << s << '\n';
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <class T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
bool chmin(T &a, const T &b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体

ll nm[214514] = {};
ll pm[214514] = {};
int main() {
	IOS();
	map<string, ll> mp;
	ll n;
	cin >> n;
	for (int i = 0; i < n;i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << "AC x " << mp["AC"] << endl;
	cout << "WA x " << mp["WA"] << endl;
	cout << "TLE x " << mp["TLE"] << endl;
	cout << "RE x " << mp["RE"] << endl;
}


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

using namespace std;

const int N = 100005;
int n, a[N], dp[N];
bool solved[N];

int calc(int i)
{
    if (i == n - 1)
    {
        return 0;
    }
    
    if (solved[i])
        return dp[i];
        
    int ret = abs(a[i] - a[i + 1]) + calc(i + 1);
    if (i < n - 2)
    {
        ret = min(ret, abs(a[i] - a[i + 2]) + calc(i + 2));
    }
    
    solved[i] = 1;
    dp[i] = ret;
    return dp[i];
}

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


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

Measured memory_bytes: 3632