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

int main() {
	int N,A,m,n = 29;
  cin >> N;
  for(int i;i < N;i++){
    cin >> A;
    m = 0;
    while(A % 2 == 0){
      A /= 2;
      m++;
    }
    if(n > m){
      n = m;
    }
  }
  cout << n <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

char s[15];
int n,m;

int main(){
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n;i++) if(s[i]=='o') m++;
	m+=15-n;
	if(m>=8) puts("YES");
	else puts("NO");
	return 0;
}

/*
数据不清空，爆零两行泪
读题不认真，爆零两行泪
分析不仔细，爆零两行泪
建树不构造，爆零两行泪
变量不统一，爆零两行泪
边界不算清，爆零两行泪
数组不开大，爆零两行泪
*/

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int n,t;
	cin>>n>>t;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	
	vector<int> mv = v;
	rep(i,n-1){
		mv[i+1] = min(mv[i],mv[i+1]);
	}
	
	vector<int> dv(n);
	rep(i,n){
		dv[i] = v[i]-mv[i];
	}
	
	int maxi = -1;
	rep(i,n){
		maxi = max(dv[i],maxi);
	}
	
	int c=0;
	rep(i,n){
		if(dv[i]==maxi)c++;
	}
	cout<<c<<endl;
	
}

Measured memory_bytes: 1536
#include <iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<int,pint> edge;
typedef long long ll;
const int inf   = 1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

edge e[200001];
int ans,par[100001];

int find(int x){
  if(par[x]==x)return x;
  return par[x]=find(par[x]);
  }

void unite(edge e){
  int x=find(e.second.first);
  int y=find(e.second.second);
  if(x!=y){
    par[x]=y;
    ans+=e.first;
    }
  }
 

int main(){
  int n;cin>>n;
  rep(i,n)par[i]=i;
  pint x[n],y[n];
  rep(i,n){
    int a,b;
    cin>>a>>b;
    x[i]=pint(a,i);
    y[i]=pint(b,i);
    }
  sort(x,x+n);sort(y,y+n);
  rep(i,n-1){
    e[i]=make_pair(x[i+1].first-x[i].first,pint(x[i].second,x[i+1].second));
    e[n-1+i]=make_pair(y[i+1].first-y[i].first,pint(y[i].second,y[i+1].second));
    }
  sort(e,e+2*n-2);
  ans=0;
  rep(i,2*n-2)unite(e[i]);
  cout<<ans<<endl;
  return 0;
  }

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

long long a, b, k;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> a >> b >> k;
    if(k >= a) k -= a, a = 0;
    else a -= k, k = 0;
    b = max((long long)0, b - k);
    cout << a << " " << b << "\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
input()
s = input()
c = 0
for i in s:
    if i == "(":
        c += 1
    else:
        if c > 0:
            c -= 1
d = 0
for i in s[::-1]:
    if i ==")":
        d += 1
    else:
        if d > 0:
            d -= 1
print("("*d+s+")"*c)




Measured memory_bytes: 8924
#include "iostream"
#include "vector"
#include "algorithm"
#include "map"
#define N_MAX  200005

using namespace std;

typedef long long llint;

int N;
llint A[N_MAX];
llint A_sum[N_MAX];

int main() {

    cin >> N;

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

    A_sum[0] = 0;
    for (int i = 1; i <= N; i++) {
        A_sum[i] = A_sum[i - 1] + A[i];
    }

    llint ans = 0;
    map <llint, llint> mp;
    for (int i = 0; i <= N; i++) {
       ans += mp[A_sum[i]];
       mp[A_sum[i]]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 15872
import java.util.Scanner;
 
class Main{
 
    public static void main(String[] args){
 
        Scanner scanner = new Scanner(System.in);
        int s = scanner.nextInt();
        int w = scanner.nextInt();
        scanner.close();
        if(w>=s){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
        
    }
 
}

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

long fs(long n, long a, long b, long m) {
    long r = 0;
    while(m) {
        r += a / m * n * (n - 1) / 2 + b / m * n;
        a %= m;
        b %= m;
        b += a * n;
        n = b / m;
        b -= m * n;
        swap(a, m);
    }
    return r;
}
int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
        int n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << fs(n, a, b, m) << '\n';
    }
    return 0;
}


Measured memory_bytes: 3560
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
main=print.solve.map((\[a,b]->(a,b)).unfoldr(B.readInt.B.dropWhile isSpace)).B.lines=<<B.getContents
solve((n,m):ab)=fst.foldr f(0,maxBound).sort$ab
f(a,b)(k,i)=if i<b then (k,i) else (k+1,a)

Measured memory_bytes: 31364
#include <iostream>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std; 
typedef long long int ll;

int main(){
    /*input*/
    int x,y,z;	cin >> x >> y >> z; 
    /*calculation*/
    x -= z;
    /*output*/
    cout << x/(y+z) << endl;
}


Measured memory_bytes: 256
N, M = map( int, input().split())
now = [1]*N
ans = [0]*N
ans[0] = 1
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    if ans[x] == 1:
        if now[x] >= 2:
            ans[y] = 1
        else:
            ans[x] = 0
            ans[y] = 1
    now[y] += 1
    now[x] -= 1
print( sum( ans))


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 998244353;
const int maxn = 2e5+5;
ll c[maxn<<2][2];
ll inv[maxn<<2];
ll tg[maxn<<2];
void pull(int x) {
    inv[x] = inv[x<<1] + inv[x<<1|1] + c[x<<1][1] * c[x<<1|1][0];
    c[x][0] = c[x<<1][0] + c[x<<1|1][0];
    c[x][1] = c[x<<1][1] + c[x<<1|1][1];
}
pair<pair<int,int>,ll> pull(pair<pair<int,int>,ll>x,pair<pair<int,int>,ll>y) {
    return {{x.F.F+y.F.F,x.F.S+y.F.S},x.S+y.S + (ll)x.F.S * y.F.F};
}

void push(int x,int l,int r,int mid) {
    if (!tg[x]) {
        return;
    }
    swap(c[x<<1][0],c[x<<1][1]);
    tg[x<<1] ^= 1;
    inv[x<<1] = c[x<<1][0] * c[x<<1][1] - inv[x<<1];
    swap(c[x<<1|1][0],c[x<<1|1][1]);
    tg[x<<1|1] ^= 1;
    inv[x<<1|1] = c[x<<1|1][0] * c[x<<1|1][1] - inv[x<<1|1];
    tg[x] = 0;
}
void update(int x,int l,int r,int ql,int qr) {
    if (ql <= l && qr >= r) {
        swap(c[x][0],c[x][1]);
        tg[x] ^= 1;
        inv[x] = (ll)(c[x][0]) * (c[x][1])- inv[x];
        return;
    }
    int mid = (l + r) >> 1;
    push(x,l,r,mid);
    if (ql <= mid) {
        update(x<<1,l,mid,ql,qr);
    }
    if (qr > mid) {
        update(x<<1|1,mid+1,r,ql,qr);
    }
    pull(x);
}
pair<pair<int,int>,ll> query(int x,int l,int r,int ql,int qr) {
    if (ql <= l && qr >= r) {
        return {{c[x][0],c[x][1]},inv[x]};
    }
    int mid = (l + r) >> 1;
    push(x,l,r,mid);
    if (qr <= mid) {
        return query(x<<1,l,mid,ql,qr);
    }
    if (ql > mid) {
        return query(x<<1|1,mid+1,r,ql,qr);
    }
    return pull(query(x<<1,l,mid,ql,qr),query(x<<1|1,mid+1,r,ql,qr));
}
void build(int x,int l,int r) {
    if (l == r) {
        int val;
        cin >> val;
        c[x][val]++;
        return;
    }
    int mid = (l + r) >> 1;
    build(x<<1,l,mid);
    build(x<<1|1,mid+1,r);
    pull(x);
}
void solve() {
    int n, q;
    cin >> n >> q;
    build(1,1,n);
    while (q--) {
        int op,l,r;
        cin >> op >> l >> r;
        if (op == 1) {
            update(1,1,n,l,r);
        }
        else {
            cout << query(1,1,n,l,r).S << '\n';
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


Measured memory_bytes: 20024
n, m = map (int, input().split(" "))
datalist = [-1 for i in range(n)]
result = 99999
for i in range(m):
    keta, value = map (int, input().split(" "))
    if(datalist[keta-1] == -1 or datalist[keta-1] == value):
        datalist[keta-1] = value
    else:
        result = -1

for i in range(n):
    if datalist[i] == -1:
        if(i == 0 and n > 1):
            datalist[i] = 1
        else:
            datalist[i] = 0
if n > 1 and datalist[0] == 0:
    result = -1

if(result == -1):
    print(-1)
else:
    result = 0
    for i in range(n):
        result = result + datalist[n-i-1]*(10**i)
    print(result)

Measured memory_bytes: 3064
import Data.List

main = do
  str <- getLine
  let n = read str ::Int
  str <- getLine
  let a = take n $ map read (words str) ::[Int]
  let ans = and $ map (isOne . length) $ (group . sort) a
  if ans == True
    then putStrLn "YES"
    else putStrLn "NO"


isOne :: Int -> Bool
isOne 1 = True
isOne x = False

Measured memory_bytes: 79228
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;

        long num = long.Parse(Reader.ReadLine());


        int ans = 0;
        long tmp = GetNum(1, num, num);
        for (long i = tmp; i >= 1; i--)
        {
            if (num % i == 0)
            {
                ans = Math.Max(i.ToString().Length, (num / i).ToString().Length);
                break;
            }
        }
        Console.WriteLine(ans);

    }


    private long GetNum(decimal min, decimal max, decimal target)
    {
        if (max - min <= 1)
        {
            if (max * max <= target)
            {
                return (long)max;
            }
            return (long)min;
        }
        decimal mid = Math.Floor((max + min) / 2);

        if (mid * mid <= target)
        {
            return GetNum(mid, max, target);
        }
        else
        {
            return GetNum(min, mid, target);
        }
    }





    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"

10000000002


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
 int main(){
   int H,W;
 cin >> H >> W;
   vector<char> vec1(W+2,'#');
   for(int i=0;i<W+2;i++){
    cout << vec1.at(i);
   } cout << endl;
  for (int i=0;i<H;i++){
      vector<char> veci(W);
        for (int j=0; j<W;j++){
          cin >> veci.at(j) ;   }    
      cout <<'#';
          int k=0;
          while(k<W){
           cout << veci.at(k);
            k++;
          }
          cout<<"#"<<endl;
        }
 for(int i=0;i<W+2;i++){
    cout << vec1.at(i);
   } cout << endl;
 }

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

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

from copy import deepcopy

c = deepcopy(b)

ans = 0

if sum(a) < sum(b):
    print(-1)
    sys.exit()

diff = 0
ad = []

for i, j in zip(a, b):
    if i == j:
        pass
    elif i > j:
        ad.append(i - j)
    else:
        diff += (j - i)
        ans += 1

ad.sort()

while diff > 0:
    diff -= ad.pop()
    ans += 1

print(ans)
        


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

using namespace std;

using ll = long long;

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

    ll n, k;
    cin >> n >> k;

    ll num = k;
    for (int i = 1; i < n; ++i)
        num *= (k - 1);

    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
start = []
goal = []
for i in range(m):
    a, b = map(int,input().split())
    if a == 1:
        start.append(b)
    if b == n:
        goal.append(a)
if set(start) & set(goal):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 21852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    map<int, int> mp;
    map<int,bool> solved;
    int acnt = 0;
    int wcnt = 0;
    rep(i,m){
        int p;
        string s;
        cin>>p>>s;
        if(s=="AC" && !solved[p]){
            solved[p] = true;
            wcnt += mp[p];
            acnt++;
        } else {
            mp[p] += 1;
        }
    }
    cout<<acnt<<" "<<wcnt<<endl;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
template <typename T>
T gcd(T m, T n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  string S,T;
  ll A,B;
  string U;
  cin>>S>>T>>A>>B>>U;
  if(S==U){
    A--;
  }else{
    B--;
  }
  printf("%d %d\n",A,B);
  return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  
  int x = 0;
  
  if (A >= B){
    x += A;
    A--;
      if ( A >= B){
        x += A;
      }
        else {
          x += B;
        }
  }
  else {
    x += B;
    B--;
    if ( A >= B) {
      x += A;
    }
    else {
      x += B;
    }
  }

  cout << x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 10000000;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

vector <pii> conn[100050];
vector <int> son[100050];
int par[100050][2];
bool dchk[100050];
void DFS(int n) {
	dchk[n] = true;
	for (auto it : conn[n]) {
		if (dchk[it.second]) continue;
		par[it.second][0] = n, par[it.second][1] = it.first;
		son[n].push_back(it.second);
		DFS(it.second);
	}
}

int cnt[16];
vector <int> Vu;
int dp[32768];
int sum[32768];
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i < N; i++) {
		int t1, t2, t3;
		scanf("%d %d %d", &t1, &t2, &t3);
		t1++, t2++;
		conn[t1].emplace_back(t3, t2);
		conn[t2].emplace_back(t3, t1);
	}
	DFS(1);

	for (i = 2; i <= N; i++) {
		int v = par[i][1];
		for (auto it : son[i]) v ^= par[it][1];
		cnt[v]++;
	}

	int ans = cnt[0];
	for (i = 1; i <= 15; i++) {
		ans += cnt[i] / 2;
		if (cnt[i] % 2) Vu.push_back(i);
	}

	dp[0] = 0;
	int X = Vu.size();
	int mx = 0;
	for (i = 1; i < (1 << X); i++) for (j = 0; j < X; j++) if (i & (1 << j)) sum[i] ^= Vu[j];
	for (i = 1; i < (1 << X); i++) {
		dp[i] = 0;
		for (j = i; j; j = (j - 1)&i) {
			if (sum[j]) continue;
			dp[i] = max(dp[i], dp[i^j] + 1);
		}
		mx = max(mx, dp[i]);
	}
	return !printf("%d\n", N - 1 - ans - mx);
}
//*/

Measured memory_bytes: 18048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int sE[1000000],sW[1000000];
int S=0,W=0;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ret = s.size()-1;
    for (int i=s.size()-1;i>=0;i--) {
        sE[i]=sE[i+1]+(s[i]=='E');
        sW[i]=sW[i+1]+(s[i]=='W');
    }
    for (int i=0;i<s.size();i++) {
        ret=min(ret, W + sE[i+1]);
        W+=(s[i]=='W');
    }
    cout<<ret<<endl;
}

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

int main(){
    int N,M,sum=0;
    int A[10001];
    cin >> N >> M;
    for(int i=0; i<M; i++){
        cin >> A[i];
        sum += A[i];
    }

    if(sum <= N){
        cout << N-sum << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
import numpy as np
 
n = int(input())
a = np.array(list(map(int, input().split())))
ans_count = 0
 
while(1):
  count = len(np.where(a % 2 == 1)[0])
  if count > 0:
    break
  a = a / 2
  ans_count += 1
print(ans_count)

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


struct State {
  int i, j, t;
};

const int INF = 1<<28;
const int MAXN = 1001;
int H, W;
char C[MAXN][MAXN];
int G[MAXN][MAXN];

int main() {
  while(cin >> H >> W) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> C[i][j];
      }
    }
    memset(G, 0, sizeof(G));
    queue<State> que;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(!isdigit(C[i][j])) {
          G[i][j] = INF;
          continue;
        }
        for(int di = -1; di <= 1; ++di) {
          for(int dj = -1; dj <= 1; ++dj) {
            if(di == 0 && dj == 0) continue;
            int ni = i + di;
            int nj = j + dj;
            if(C[ni][nj] == '.') ++G[i][j];
          }
        }
        if(G[i][j] >= C[i][j]-'0') {
          que.push((State){i, j, 1});
        }
      }
    }
    int res = 0;
    while(que.size()) {
      const State s = que.front();
      que.pop();
      res = s.t;
      for(int di = -1; di <= 1; ++di) {
        for(int dj = -1; dj <= 1; ++dj) {
          if(di == 0 && dj == 0) continue;
          int ni = s.i + di;
          int nj = s.j + dj;
          if(G[ni][nj] >= C[ni][nj]-'0') continue;
          if(++G[ni][nj] >= C[ni][nj]-'0') {
            que.push((State){ni, nj, s.t + 1});
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 6132
package main

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

func main() {
	N, X := ReadInt(), ReadInt()
	cnt := 1
	v := 0
	for i := 0; i < N; i++ {
		v += ReadInt()
		if v <= X {
			cnt++
		} else {
			break
		}
	}
	fmt.Println(cnt)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 1840
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct P{
  int h;
  int w;
  int s;
};

bool comp(const P& p1, const P& p2)
{
  return p1.s < p2.s;
}

int main()
{
  int n, w, d, s, t;
  P p, q;

  while(cin>>n>>w>>d && (n+w+d)){
    vector<P> vec;
    p.w = w;
    p.h = d;
    p.s = w*d;
    vec.push_back(p);
    while(n--){
      cin >> t >> s;
      p = vec[t-1];
      vec.erase(vec.begin()+(t-1));
      s %= (p.h*2 + p.w*2);
      if(0 < s && s < p.w){
	q.h = p.h;
	q.w = p.w - s;
	p.w = s;
      } else if(p.w < s && s < p.w+p.h){
	q.w = p.w;
	s -= p.w;
	q.h = p.h - s;
	p.h = s;
      } else if(p.w+p.h < s && s < 2*p.w+p.h){
	q.h = p.h;
	s -= (p.w+p.h);
	q.w = p.w - s;
	p.w = s;
      } else {
	q.w = p.w;
	s -= (2*p.w + p.h);
	q.h = p.h - s;
	p.h = s;
      }
      q.s = q.h*q.w;
      p.s = p.w*p.h;
      
      if(p.s < q.s){
	vec.push_back(p);
	vec.push_back(q);
      } else {
	vec.push_back(q);
	vec.push_back(p);
      }
    }
    sort(vec.begin(), vec.end(), comp);

    cout << vec[0].s;
    for(int i = 1; i < vec.size(); i++){
      cout << " " << vec[i].s;
    }
    cout << endl;
  }

  return 0;
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

ll const mod = 1e9+7;

int up(int i,int k) {
  return (i+k-1)/k;
}

int main() {
  string S;
  cin >> S;
  int cnt = 0;
  rep(i,S.size()){
    if (S[i]=='g') cnt++;
    else cnt--;
  }
  cout << cnt/2 << endl;
}

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

using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back

int main(){
	fast;
	lli n,x;
	cin>>n;
	vector <lli> vec(n+1,0);
	for (int i=0;i<n-1;i++){
		cin>>x;
		vec[x]++;
	}
	for (int i=1;i<=n;i++) cout<<vec[i]<<endl;
}

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

// DPテーブル
const int MAX_W = 110000;
int dp[MAX_W];

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

	// 品物を列挙 (価値はすべて 1)
	vector<int> weight;
	for (int i = 1; i <= W; i *= 6) weight.push_back(i);
	for (int i = 9; i <= W; i *= 9) weight.push_back(i); // 1 が重複しないように (しても問題はない)
	int n = (int)weight.size();

	// DP初期条件: dp[i][0] = 0
	for (int w = 0; w < MAX_W; ++w) dp[w] = 1 << 29; // INF
	dp[0] = 0;

	// DPループ
	for (int i = 0; i < n; ++i) {
		for (int w = weight[i]; w <= W; ++w) {
			dp[w] = min(dp[w], dp[w - weight[i]] + 1);
		}
	}

	cout << dp[W] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)
    cout<<"1"<<endl;
  if(b==0)
    cout<<"2"<<endl;
  if(c==0)
    cout<<"3"<<endl;
  if(d==0)
    cout<<"4"<<endl;
  if(e==0)
    cout<<"5"<<endl;
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    map<ll, ll> A;
    ll ans = 1;
    cin >> N;
    rep(i, N) {
        ll temp;
        cin >> temp;
        A[temp]++;
    }
    iter(i, A) {
        if((i.first != 0 && i.second != 2) || (N % 2 == 0 && i.first == 0) || (N % 2 && i.first == 0 && i.second != 1)) {
            cout << 0 << endl;
            return 0;
        }
        ans *= i.second;
        ans %= MOD;
    }
    if(N % 2 && !A[0]) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll,ll>;
ll modpow(ll x, ll y);
const ll mod = pow(10, 9) + 7;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    ans += modpow(10, n)%mod;
    ans %= mod;
    ans -= modpow(9, n)%mod;
    ans %= mod;
    ans -= modpow(9, n)%mod;
    ans %= mod;
    ans += modpow(8, n)%mod;
    ans %= mod;
    ans = (ans + mod)%mod;
    cout << ans << endl;
}

ll modpow(ll x, ll y){
    ll r = 1;
    for(ll i = 0; i < y; i++){
        r *= x%mod;
        r %= mod;
    }
    return r%mod;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>

int main() {
  int N;
  std::cin >> N;
  std::vector<int> t(N + 1, 0);
  std::vector<int> x(N + 1, 0);
  std::vector<int> y(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    std::cin >> t[i+1] >> x[i+1] >> y[i+1];
  }

  bool can = true;
  for (int i = 0; i < N; ++i) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;
  }

  if (can) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int A,B,C,D;
cin >> A >> B >> C >> D;
if(A*B<C*D) {
  cout << C*D << endl;
} else {
  cout << A*B << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <iterator>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    if (n%(2*d + 1) == 0) {
        cout << n/(2*d + 1) << endl;
    } else {
         cout << n/(2*d + 1) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)

using namespace std;

int main()
{
	int num[3];
	int count=0;
	cin >> num[0] >> num[1] >> num[2];
	for (int i= 0; i < 3; i++) {
		if (num[i] == 7) {
			count++;
		}
	}
	if (count == 1) {
		cout << "YES"<<endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

int main() {
	string A;
	cin >> A;
	long long N = A.length();
	map<char, long long> Nums;
	for (char c : A) Nums[c]++;
	long long ans = N * (N - 1) / 2 + 1;
	for (auto& p : Nums) ans -= p.second * (p.second - 1) / 2;
	cout << ans << endl;
}

Measured memory_bytes: 640
<?php 
 
list($n, $m) = explode(' ', fgets(STDIN));
$a = explode(' ', fgets(STDIN));
rsort($a);
$count = 0;
$t = array_sum($a)/(4*$m);

 
for ($i=0; $i<$n ; $i++) {
  // code...
  if ($a[$i] >= $t) {
    // code...
    $count ++;
    
  }
}
if($count >= $m){
  echo 'Yes';
}else{
  echo 'No';
}


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

#define ll long long

int main()
{
	long long  n;
	
	
	
	cin>>n;
	
	long long  a[3*n];
	
	for(long long  i=0;i<3*n;i++)
	{
		cin>>a[i];
	}
	
	sort(a,a+3*n);
	
	long long  count1=0;
	long long count=0;
	for(long long  i=3*n-2;i>=0;i-=2)
	{
		count1+=a[i];
		count++;
		if(count==n)
		break;
	}
	
	cout<<count1;
}

Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main() {
    int a,b;
    cin >>a>>b;
    if(a<=b)cout << a<<endl;
    else cout <<a-1<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int b=sc.nextInt();
		int time=sc.nextInt();
		int temp = (int) (time+0.5)/x;
		int number=temp*b;
      if(time<x) number=0;
		System.out.println(number);

	}
}


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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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;
}

int main(){
    int N; cin >> N;
    string S; cin >> S;
    set<string> password;

    // Brute Force
    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < i; j++) {
    //         for (int k = 0; k < j; k++) {
    //             string cand;
    //             cand = string{S[i]} + string{S[j]} + string{S[k]};
    //             password.insert(cand);
    //         }
    //     }
    // }

    // map<char, int> digits;
    // for (int i = 0; i < S.size(); i++) {
    //     if (!digits.count(S[i])) digits[S[i]] = 1;
    //     else if (digits[S[i]] <= 2) digits[S[i]]++;
    // }
    // for (auto itr = digits.begin(); itr != digits.end(); itr++) {
    //     cout << itr->first << ", " << itr->second << endl;
    // }
    // cout << password.size() << endl;
    int cnt = 0;
    for (int i = 0; i < 1000; i++) {
        int c[3] = {i / 100, (i / 10) % 10, i % 10};
        int f = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] == ('0' + c[f])) f++;
            if (f == 3) break;
        }
        if (f == 3) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#define int long long int
int function2(int memo[],int turn[],int n,map<int,int> &sticks)
{
	if(n<0)
	{
		return -1000000000;
	}
	if(n==0)
	{
		return 0;
	}
	if(memo[n]!=-1)
	{
		return memo[n];
	}
	else
	{
		map<int,set<int>> mp;
		int here=-1000000000;
		mp[here].insert(-1);
		for(auto &p:sticks)
		{
			int val=1+function2(memo,turn,n-p.second,sticks);
			mp[val].insert(p.first);
		}
		auto it=mp.end();
		it--;
		int answer=*it->second.rbegin();
		turn[n]=answer;
		memo[n]=it->first;
		return it->first;
	}
}
int32_t main()
{
	int n,m;
	cin>>n>>m;
	int value[10]={0,2,5,5,4,5,6,3,7,6};
	map<int,int> sticks;
	int j;
	for(j=0;j<m;j++)
	{
		int x;
		cin>>x;
	    sticks.insert({x,value[x]});
	}
	int memo[n+1],turn[n+1];
	for(j=0;j<=n;j++)
	{
		memo[j]=-1;
		turn[j]=-1;
	}
	int val=function2(memo,turn,n,sticks);
	while(n!=0)
	{
		int here=turn[n];
		cout<<here;
		n-=value[here];
	}
	cout<<endl;
}


Measured memory_bytes: 5548
# -*- coding: utf-8 -*-
"""
A - STring
https://atcoder.jp/contests/agc005/tasks/agc005_a

"""
import sys


def solve(X):
    stat = 0
    ans = 0
    for x in X:
        if x == 'T':
            stat += 1
            ans = max(ans, stat*2)
        else:
            stat -= 1
    return ans


def main(args):
    X = input()
    ans = solve(X)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

/*inline void fastRead_int(int &x)
{
	register int c = getchar_unlocked();
	x=0;
	int neg = 0;
	for(;((c<48 || c>57) && c!='-'); c=getchar_unlocked());
	
	if(c=='-'){
		neg = 1;
		c = getchar_unlocked();
	}
	for(; c>47 && c<58;c=getchar_unlocked())
		x = (x<<1)+(x<<3)+c-48;
	if(neg)	x = -x;
	
}
*/
int min_cost(int a[], int n, int k)
{
	int cost[n];
	cost[n-1] = 0;
	cost[n-2] =abs(a[n-2]-a[n-1]);
	for(int i=n-3;i>=0;i--){
		cost[i] = (abs(a[i]-a[i+1]))+cost[i+1];
		for(int j = i+2;j<n && j<=i+k ;j++)
			cost[i] = min(abs(a[i]-a[j])+cost[j],cost[i]);
	}
	return cost[0];
}

int main()
{
	int n,k; cin>>n>>k;
	//fastRead_int(n);	fastRead_int(k);
	int a[n];for(int i=0;i<n;i++)	cin>>a[i];//fastRead_int(a[i]);
	cout<<min_cost(a,n,k)<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  string si;
  int result;
  result = 0;
  for (int i = 0; i < N; i++)
  {
      cin >> si;
      if (si=="Y")
      {
          cout << "Four" << endl;
          result = 1;
          break;
      }
      
      
  }
if (result==0)
{
    cout << "Three" << endl;
}

  
  // ここにプログラムを追記

}

Measured memory_bytes: 3604
#include <iostream>
#include <set>
#include <vector>

using namespace std;

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

  vector<string> pasts(N);
  for (int i = 0; i < N; ++i) {
    cin >> pasts[i];
  }

  set<string> search;
  for (int i = 0; i < N; ++i) {
    string s = pasts[i];

    if (i == 0) {
      search.insert(s);
      continue;
    }

    // check tail
    if (pasts[i - 1].back() != s[0]) {
      cout << "No" << endl;
      return 0;
    }

    // check pasts
    if (search.find(s) != search.end()) {
      cout << "No" << endl;
      return 0;
    }

    search.insert(s);
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;

point_t operator+(const point_t &lhs, const point_t &rhs)
{
	point_t p = { lhs.first + rhs.first, lhs.second + rhs.second };
	return p;
}

bool operator==(const point_t &lhs, const point_t &rhs)
{
	return (lhs.first == rhs.first) && (lhs.second == rhs.second);
}

bool is_in_field(int col, int row, const point_t &point)
{
	const int c = point.second;
	const int r = point.first;
	return (0 <= c && c < col) && (0 <= r && r < row);
}

int solve(int col, int row, field_t &field, const point_t &start, const point_t &goal)
{
	// 2. 各マスの訪問履歴(memo)を作成する
	//    memoにはスタートからそのマスまでの歩数を格納する(初期値は0)
	vector<vector<int>> memo;
	for (int i = 0; i < row; ++i) {
		vector<int> v(col, 0);
		memo.push_back(v);
	}

	// 移動方向(上下左右)
	const point_t points[] = {
		{ -1, 0 },{ 1, 0 },{ 0, -1 },{ 0, 1 },
	};

	// 3. スタートのマスをキューに格納する
	queue<point_t> q;
	q.push(start);

	// 11. 4から10をキューが空になるまで繰り返す
	while (!q.empty()) {
		// 4. キューの先頭から一マス取得する
		point_t cur = q.front(); q.pop();

		// 5. 取り出したマスがゴールなら終了
		if (cur == goal) {
			return memo[cur.first][cur.second];
		}

		for (const auto &point : points) {
			// 6. 手順4で取り出したマス(cur)から上下左右の何れかに移動する
			point_t next = cur + point;
			// 7. 移動先のマス(next)が迷路外でないことを確認する(迷路外の場合は手順6に戻る)
			if (is_in_field(col, row, next)) {
				const char s = field[next.first][next.second];
				// 8. 移動先のマス(next)が道またはゴールであることを確認する(道でもゴールでもない場合は手順6に戻る)
				if (s == '.' || s == 'g') {
					// 9. 移動先のマス(next)が未訪問であることを確認する(訪問済みの場合は手順6に戻る)
					if (memo[next.first][next.second] == 0) {
						// 10. 移動先のマス(next)をキューに格納し、訪問履歴を更新する
						q.push(next);
						memo[next.first][next.second] = memo[cur.first][cur.second] + 1;
					}
				}
			}
		}
	}
	return -1;
}

int main()
{
	int col, row;
	cin >> row >> col;

	point_t start, goal;
	field_t field;

	start.first = 0;
	start.second = 0;
	goal.first = row-1;
	goal.second = col-1;

	int numBlock = 0;

	// 1. 迷路(field)を作成する
	for (int i = 0; i < row; ++i) {
		vector<char> v;
		for (int j = 0; j < col; ++j) {
			char c;
			cin >> c;

			if (c == '#') {
				numBlock++;
			}
			if (i == 0 && j == 0) {
				c == 's';
			}
			else if (i == (row - 1) && j == (col - 1)) {
				c == 'g';
			}
			v.push_back(c);
		}
		field.push_back(v);
	}

	// 最短歩数はsolveで計算する
	int result = solve(col, row, field, start, goal);
	if (result != -1) {
		cout << (col*row - result - 1 - numBlock) << endl;
	}
	else {
		cout << "-1";
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define print(x) cout << x << endl;
typedef long long ll;

int main() {
	int n, m; cin >> n >> m;
	vector<int> fav(m, 0);
	rep(i, n) {
		int k; cin >> k;
		rep(j, k) {
			int a;
			cin >> a;
			fav[a-1]++;
		}
	}
	int ans = 0;
	rep(i, m) {
		if (fav[i] == n) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

bool match(string s, string t) {
	if (s.length() != t.length()) return false;
	for (int i = 0; i < s.length(); i++) {
		if (!(s[i] == t[i] || s[i] == '?')) return false;
	}
	return true;
}
int main() {
	string s;
	string t;
	cin >> s >> t;
	vector<string> ansAll;
	bool rep = false;
	for (int i = s.length()-1; i >= 0; i--) {
		string sub = s.substr(i, t.length());
		if (match(sub, t)) {
			string ans = s;
			for (int j = 0; j < s.length(); j++) {
				if (j < i) {
					if (s[j] == '?') ans[j] = 'a';
					else ans[j] = s[j];
				}
				else if (j < i + t.length()) {
					ans[j] = t[j-i];
				}
				else {
					if (s[j] == '?') ans[j] = 'a';
				}
			}
			ansAll.push_back(ans);
			rep = true;
		}
	
	
	}
	if (rep) {
		string r = *min_element(ansAll.begin(), ansAll.end());
		cout << r;
	}
	else cout << "UNRESTORABLE";
	return 0;
}





Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <functional>
using namespace std;
const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { 1, 0, -1, 0 };
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	vector<vector<bool> > used(H, vector<bool>(W, false));
	function<pair<int, int>(int, int)> dfs = [&](int r, int c) {
		pair<int, int> ans = make_pair(0, 0);
		if (S[r][c] == '#') ans.first = 1;
		else ans.second = 1;
		used[r][c] = true;
		for (int i = 0; i < 4; ++i) {
			int tr = r + dx[i], tc = c + dy[i];
			if (0 <= tr && tr < H && 0 <= tc && tc < W && !used[tr][tc] && S[r][c] != S[tr][tc]) {
				pair<int, int> res = dfs(tr, tc);
				ans.first += res.first;
				ans.second += res.second;
			}
		}
		return ans;
	};
	long long ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (!used[i][j]) {
				pair<int, int> res = dfs(i, j);
				ans += (long long)(res.first) * res.second;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

int N, M;
int T[100];
int P[100], X[100]; 

int main() {
    cin >> N;
    rep(i, N) cin >> T[i];

    cin >> M;
    rep(i, M) cin >> P[i] >> X[i];

    int sum = accumulate(T, T + N, 0);

    rep(i, M) {
        int ans = sum - T[P[i] - 1] + X[i];
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;

 
int main(){
	while(1) {
		int N;
		cin >> N;
		if(N == 0) break;
		int a[401][401];
		for(int j = 0; j < 401; j++) {
				for(int k = 0; k < 401; k++) {
					a[j][k] = -1;
				}
		}
		int y = 200, x = 200;
		a[200][200] = 0;
		for(int i = 0; i < N-1; i++) {
			int n, d;
			cin >> n >> d;
			for(int j = 0; j < 401; j++) {
				for(int k = 0; k < 401; k++) {
					if(a[j][k] == n) {
						y = j;
						x = k;
						break;
					}
				}
			}
			if(d == 0) a[y][x - 1] = i+1;
			if(d == 1) a[y + 1][x] = i+1;
			if(d == 2) a[y][x + 1] = i+1;
			if(d == 3) a[y - 1][x] = i+1;
		}

		int maxW = 0, maxH = 0, minW = 401, minH = 401;
		for(int j = 0; j < 401; j++) {
			for(int k = 0; k < 401; k++) {
				if(a[j][k] >= 0) {
					x = k;
					if(x > maxW) maxW = x;
					if(x < minW) minW = x;
				}
				if(a[k][j] >= 0) {
					y = k;
					if(y > maxH) maxH = y;
					if(y < minH) minH = y;
				}
			}
		}
		int W = maxW - minW + 1, H = maxH - minH + 1;;
		cout << W << " " << H <<endl;
	}
				


	return 0;
}

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

int main() {
  int M, D;
  cin >> M >> D;
  int cnt = 0;
  for(int i=1; i<=M; i++){
    for(int j=10; j<=D; j++){
      if((j/10) * (j%10) == i && (j/10)>=2 && (j%10)>=2){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import heapq

n, m, s = [int(x) for x in input().split()]
adj = [[] for u in range(n + 1)]
for e in range(m):
    u, v, a, b = [int(x) for x in input().split()]
    adj[u].append((v, a, b))
    adj[v].append((u, a, b))
exchange = [[int(x) for x in input().split()] if u else [] for u in range(n + 1)]
def bound(s):
    return min(s, n * 50)
pq, done, d = [(0, 1, bound(s))], set(), {(1, bound(s)): 0}
ans = [float('inf') for u in range(n + 1)]
while len(pq) > 0:
    dist, u, s = heapq.heappop(pq)
    ans[u] = min(ans[u], dist)
    if (u, s) not in done:
        for v, a, b in adj[u]:
            if s >= a and d.get((v, bound(s - a)), float('inf')) > d[u, s] + b:
                d[v, bound(s - a)] = d[u, s] + b
                heapq.heappush(pq, (d[v, bound(s - a)], v, bound(s - a)))
        c, t = exchange[u]
        if d.get((u, bound(s + c)), float('inf')) > d[u, s] + t:
            d[u, bound(s + c)] = d[u, s] + t
            heapq.heappush(pq, (d[u, bound(s + c)], u, bound(s + c)))
        done.add((u, s))

print(*(ans[u] for u in range(2, n + 1)), sep='\n')


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

#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

ll n,a[200010],ans = 0;
map<ll,int> Mp;
int main() {
	read(n);
	ll csu = 0;
	Mp[0] = 1;
	for(int i=0;i<n;i++){
		read(a[i]);
		csu+=a[i];
		ans+=Mp[csu];
		Mp[csu]+=1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14336
s = gets.strip

f = s[0, 2].to_i
b = s[2, 2].to_i

if f == 0
  if b >= 1 && b <= 12
    puts 'YYMM'
  else
    puts 'NA'
  end
  exit
elsif b == 0
  if f >= 1 && f <= 12
    puts 'MMYY'
  else
    puts 'NA'
  end
  exit
end

if f >= 13
  if b >= 1 && b <=12 
    puts 'YYMM'
  else
    puts 'NA'
  end
elsif f >= 1 && f <= 12
  if b >= 13
    puts 'MMYY'
  else
    puts 'AMBIGUOUS'
  end
end


Measured memory_bytes: 1788
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_favorite(ll N, ll x) {
    if (x == 0) return false;
    if (N / x == N %x) return true;
    return false;
}

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    REP(x, 1, int(sqrt(N) + 1)) {
        if ((N % x) == 0) {
            ll y = N / x;
            if(is_favorite(N, x - 1) == true)
                ans += x - 1;
            if (is_favorite(N, y - 1) == true)
                ans += y - 1;
        }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p[1000005];
int main()
{
   ll a,b,c,d;
   cin>>a;
   ll k=7;
   ll ans=1;
   while(1)
   {


       if(k<a)
       {
           ans++;
           k*=10;
           k+=7;
       }
       else
       {
           k=k%a;
           if(k==0)
           {
               cout<<ans<<endl;
               return 0;
           }
           if(p[k]==1&&k!=0)
           {
               cout<<"-1"<<endl;
               return 0;
           }
               p[k]=1;

       }


   }

    return 0;
}


Measured memory_bytes: 11324
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

string s;

int main() {
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int solve(int a,int b){
	if(b-a<=1)return 2*a-2;
	int c=(int)sqrt(a*b);
	if(c*c==a*b)c--;
	if(c*(c+1)>=a*b)return 2*c-2;
	else return 2*c-1;
}
signed main(){
	int Q;
	cin>>Q;
	rep(i,Q){
		int A,B;
		cin>>A>>B;
		if(A>B)swap(A,B);
		cout<<solve(A,B)<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
function compare(a, b) {
  if (a == b) {
    return 'a == b';
  } else if (a < b) {
    return 'a < b';
  } else {
    return 'a > b';
  }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  console.log(chunk.split(' ').map(Number).reduce(compare));
});

Measured memory_bytes: 15644