akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int cnt[200001] = {0};

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

    for (int i = 2; i <= N; i++)
    {
        int Ai;
        cin >> Ai;
        cnt[Ai]++;
    }

    for (int i = 1; i <= N; i++)
    {
        cout << cnt[i] << endl;
    }
}


Measured memory_bytes: 4304
#include <stdio.h>
#define M 100005
int a[M];
int find(int b,int n){
	int left=0;int right=n;
	int mid;
	while(left<right){
	mid=(left+right)/2;
	if(b==a[mid]) return 1;
	else if(b<a[mid]) right=mid;
	else  left=mid+1;
	}
	return 0;
}

int main(){
	int n;int cnt;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int q;cnt=0;
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int b;
		scanf("%d",&b);
		if(find(b,n)){
			cnt++;
		}
	}
	printf("%d\n",cnt);


}


Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>

using namespace std;

#define MAX 1000000

int main()
{
  int a, b, n;
  while (scanf("%d %d %d ", &a, &b, &n) == 3) {
    int sum = 0;
    
    for (int i = 0; i <= n; i++) {
      if (i > 0) sum += a / b;
      a = (a % b) * 10;
    }
    printf("%d\n", sum);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a,b) (((a)-(b))>0?((a)-(b)):((b)-(a)))

using namespace std;

int main(){
	char c[3];
	rep(i,0,3) cin >> c[i];
	int k;
	if( c[0]=='R' && c[1]=='R' && c[2]=='R' ) k = 3;
	else if( c[0]=='R' && c[1]=='R' ) k = 2;
	else if( c[1]=='R' && c[2]=='R' ) k = 2;
	else if( c[0]=='R' || c[1]=='R' || c[2]=='R' ) k = 1;
	else k = 0;
	
	cout << k;
	
	return 0;
}

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

using namespace std;
using LL = long long;

constexpr LL INF = 1e18;

int main() {
	LL N, K;
	cin >> N >> K;

	LL cnt0 = 0;
	vector< LL> pos, neg;
	for (int i = 0; i < N; i++) {
		LL v; cin >> v;
		if (v == 0) cnt0++;
		else if (v > 0) pos.push_back(v);
		else neg.push_back(v);
	}

	sort(begin(pos), end(pos));
	sort(begin(neg), end(neg));

	function< LL( LL)> check = [&](LL val) {
		LL rv = 0;
		if (val >= 0) {
			rv += cnt0 * (N - cnt0);
			rv += cnt0 * (cnt0 - 1) / 2;

		}
		for (int i = 0, j = pos.size() - 1; i < j; i++) {
			while (j > i && pos[i] * pos[j] > val) j--;
			rv += j - i;
		}
		for (int i = 0, j = 0; i < pos.size(); i++) {
			while (j < neg.size() && pos[i] * neg[j] <= val) j++;
			rv += j;
		}
		for (int i = neg.size() - 1, j = 0; i > j; i--) {
			while (i > j && neg[i] * neg[j] > val) j++;
			rv += i - j;
		}
		return rv;
	};

	LL l = -INF, r = INF, ans;
	while (l <= r) {
		LL val = (l + r) / 2;
		LL cnt = check(val);
		if (cnt >= K) {
			ans = val;
			r = val - 1;
		} else {
			l = val + 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a + b >= k){
    cout << min(a, k) << endl;
  } else {
    k -= a + b;
    cout << a - k << endl;
  }
  return 0;
}

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


int main(){
    ll n, a, b; cin >> n >> a >> b;
    ll ans = 0;
    if(a==b && n==1){ cout<< 1 <<endl; return 0;}
    if(a==b && n!=1){ cout << 1 <<endl; return 0;}
    if(a<b && n==1) { cout << 0 <<endl; return 0;}
    if(a>b){ cout << 0 <<endl; return 0;}
    
    ans = (b-a)*(n-2)+1;
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys
from collections import Counter, defaultdict
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline


class RollingHash():
    """
    Original code is https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
    """
    class RH():
        def __init__(self, s, base, mod):
            self.base = base
            self.mod = mod
            self.rev = pow(base, mod-2, mod)

            l = len(s)
            self.h = h = [0]*(l+1)
            tmp = 0
            for i in range(l):
                num = ord(s[i])
                tmp = (tmp*base + num) % mod
                h[i+1] = tmp

            self.pw = pw = [1]*(len(s)+1)
            v = 1
            for i in range(l):
                pw[i+1] = v = v * base % mod

        def calc(self, l, r):
            return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod

    @staticmethod
    def gen(a, b, num):
        result = set()
        while 1:
            import random
            import math
            random.seed()
            while 1:
                v = random.randint(a, b)//2*2+1
                if v not in result:
                    break
            for x in range(3, int(math.sqrt(v))+1, 2):
                if v % x == 0:
                    break
            else:
                result.add(v)
                if len(result) == num:
                    break
        return result

    def __init__(self, s, rand=False, num=5):
        if rand:
            bases = RollingHash.gen(2, 10**3, num)
        else:
            assert num <= 10
            bases = [641, 103, 661, 293, 547, 311, 29, 457, 613, 599][:num]

        MOD = 10**9+7
        self.rhs = [self.RH(s, b, MOD) for b in bases]

    def calc(self, l, r):
        return tuple(rh.calc(l, r) for rh in self.rhs)


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo


def slv(N, S):
    srh = RollingHash(S, rand=True, num=2)

    def f(m):
        h2i = defaultdict(list)
        for i in range(N-m+1):
            j = i + m
            h = srh.calc(i, j)
            h2i[h].append(i)

        for l in h2i.values():
            l0 = l[0]
            for i in range(1, len(l)):
                n = l[i] - l0
                if n >= m:
                    return 0
        return 1

    return Bisect(f).bisect_right(0, 1, N//2+1) - 1


def main():
    N = int(input())
    S = input()
    print(slv(N, S))


if __name__ == '__main__':
    main()


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

int main() {
    int d, n; cin >> d >> n;
    if (n == 100) n = 101;
    if (d == 0) cout << n;
    else if (d == 1) cout << (n * 100);
    else cout << (10000 * n);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main (void) {
	string s1, s2, s3; cin >> s1 >> s2 >> s3;
	cout << (char)(s1[0]-32)<< (char) (s2[0]-32) << (char) (s3[0]-32) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> b(N - 1);
    for(int i = 0; i < N - 1; i++) cin >> b[i];
    int sum = 0;
    for(int i = 0; i < N; i++){
        if(i == 0) sum+= b[i];
        else if(i == N - 1) sum += b[i - 1];
        else{
            sum += min(b[i], b[i  - 1]);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	int cnt = 1;
	for(int i = 0; i < n; i++){
		if(a[i] == cnt){
			cnt++;
		}
	}
	cnt--;
	if(cnt == 0){
		cout << -1;
	}
	else
		cout << n-cnt << endl;

	return 0;
}



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

using namespace std;

int x,y,z,ans;

int main(){
	scanf("%d%d%d",&x,&y,&z);
	if (x<y) swap(x,y);
	if (x<z) swap(x,z);
	if (y<z) swap(y,z);
	for (;y<x;++y,++z,++ans);
	for (;z+2<=y;z+=2,++ans);
	if (z<y) ans+=2;
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

const int MAX = 2e5;
ll x[MAX];

int main() {
	int n;
	ll a, b;
	cin >> n >> a >> b;
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	ll result = 0;
	for(int i = 1; i < n; i++) {
		result += min(a * (x[i] - x[i - 1]), b);
	}
	cout << result << "\n";
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    LL N;
    scanf("%lld", &N);
    if (N % 2) return !printf("0\n");
    LL base = 10, cnt = 1, ans = 0;
    while (base <= N) {
        ans += cnt * (N / base - N / (base * 5));
        base *= 5;
        cnt++;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Smart Calculator
public class Main {

        static char[] s;
        static int id;

        static int exp(){
                int r = term();
                while(true){
                        char c = s[id++];
                        if(c=='+')r+=term();
                        else if(c=='-')r-=term();
                        else break;
                }
                return r;
        }

        static int term(){
                int r = fact();
                while(true){
                        char c = s[id++];
                        if(c=='*') r*=fact();
                        else if(c=='/')r/=fact();
                        else break;
                }
                id--;
                return r;
        }

        static int fact(){
                char c = s[id++];
                if(c=='(')return exp();
                if(c=='-'){
                        return -fact();
                }
                if(c=='+'){
                        return fact();
                }
                int x = c-'0';
                while(true){
                        c = s[id++];
                        if(Character.isDigit(c)){
                                x *= 10;
                                x += c-'0';
                        }
                        else break;
                }
                id--;
                return x;
        }

        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int t = sc.nextInt();
                while(t--!=0){
                        s = sc.next().toCharArray();
                        id = 0;
                        System.out.println(exp());
                }
        }
}

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

using ll=long long; 

void solve(){
	int a,b;
	cin>>a>>b;
	if(a<0&&0<b){
		cout<<"Zero"<<endl;
	}
	else if(a==0||b==0){
		cout<<"Zero"<<endl;
	}
	else if(a<0&&b<0){
		if((b-a)%2==0){
			cout<<"Negative"<<endl;
		}
		else{
			cout<<"Positive"<<endl;
		}
	}
	else{
		cout<<"Positive"<<endl;
	}
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vll A(N);
    REP(i, N) cin >> A[i];

    map<ll, ll> m;
    REP(i, N) m[A[i]]++;

    int Q; cin >> Q;
    vi B(Q), C(Q);
    ll ans = accumulate(ALL(A), 0LL);
    REP(i, Q) {
        cin >> B[i] >> C[i];

        ans += m[B[i]] * C[i];
        ans -= m[B[i]] * B[i];

        print(ans);

        m[C[i]] += m[B[i]];
        m[B[i]] = 0;

    }
}


Measured memory_bytes: 10796
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include<vector>
#include <string>

using namespace std;

int main() {
	int K, N, max = 0, t, time = 0, tmp=0,dis=0;
	vector<int>input;
	cin >> K >> N;
	for (int i = 0; i < N; i++) {
		cin >> t;
		input.push_back(t);
	}
	for (auto it = input.rbegin(); it != input.rend()-1; it++) {
		dis = *it - *(it+1);
		if (dis > max) max = dis;
		tmp += dis;
		//cout << "dis" << " " << dis;
	}
	//cout << "dis" << " " << K - tmp<<'\n';
	if ((K - tmp) > max)max = K - tmp;
	cout << K - max;
	//cout << '\n' << time;

	return 0;
}

Measured memory_bytes: 1400
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut num = 1;
    for block in a {
        if block == num {
            num += 1;
        }
    }
    let blocks = n + 1 - num;
    if blocks == n {
        println!("-1");
    } else {
        println!("{}", blocks);
    }
}


Measured memory_bytes: 4984
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
using namespace std;
int a[200005]={0},b[200005]={0};
int main()
{
	int n,k,l,r,cnt=0;
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	for(int i=1;i<=k;i++){
		cnt=0;
		for(int j=1;j<=n;j++){
			if(a[j]==n)
				cnt++;
		}
		if(cnt==n)break;
		memset(b,0,sizeof(b));
		for(int j=1;j<=n;j++){
			l=j-a[j];
			r=j+a[j];
			if(l<1)l=1;
			if(r>n)r=n;
			b[l]++;
			if(r+1<=n)
				b[r+1]--;
		}
		for(int j=2;j<=n;j++){
			b[j]+=b[j-1];
		}
		for(int j=1;j<=n;j++){
			a[j]=b[j];
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d ",b[i]);
	}
	return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int N;
vector<int>len(3);
vector<pair<int, int>>now(4, pair<int, int>(0, 0));
int ans = INF;
void dfs(int k, vector<int>l) {
	if (k == N) {
		int cnt = 0;
		rep(i, 0, 3) {
			if (now[i].second == 0)return;
			cnt += abs(len[i] - now[i].first) + 10 * (now[i].second - 1);
		}
		chmin(ans, cnt);
	}
	else {
		rep(i, 0, 4) {
			now[i].first += l[k];
			now[i].second++;
			dfs(k + 1, l);
			now[i].first -= l[k];
			now[i].second--;
		}
	}
}

int main() {
	init();

	cin >> N;
	rep(i, 0, 3)cin >> len[i];
	vector<int>l(N);
	rep(i, 0, N)cin >> l[i];
	dfs(0, l);
	cout << ans << "\n";

	return 0;
}

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

a = []
c = []

for i in range(n):
    a.append(list(map(int, input().split())))
    c.append(a[i][0])
    del a[i][0]

INF = 100000000

ans = INF

for i in range(1 << n):
    cost = 0
    d = [0] * m
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for k in range(m):
                d[k] += a[j][k]
    ok = True
    for j in range(m):
        if d[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost)
if ans == INF:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 9192
<?php
$k = trim(fgets(STDIN));
$z = $k%50;
$i = 0;
while($i <= 50){
$a[] = $i;
++$i;
}
unset($a[(50 -$z)]);
sort($a);
echo 50 . PHP_EOL;
$d = ($k-$z)/50;
$i = 0;
while($i < 50){
$a[$i] += $d;
++$i;
}

echo join(" ",$a);

Measured memory_bytes: 3956
input()
x=list(map(int,input().split()))
z=[abs(x[i]-y) for i,y in enumerate(map(int, input().split()))]
print(sum(z),sum([u**2 for u in z])**(1/2),sum([u**3 for u in z])**(1/3),max(z),sep='\n')


Measured memory_bytes: 5652
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/

int main(){
    int a, b; cin >> a >> b;
    if(a % 2 != 0 && b % 2 != 0){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,t,sum=0,time=0;
    cin>>n>>x>>t;
    while(n>sum)
    {
        sum=sum+x;
        time=time+t;
    }
    cout<<time<<endl;
    return 0;
}




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

int main() {
  int N,K;
  int a;
  cin >> N >> K;
  a = 1;
  for (int i=0;i < N;i++){
    if (a >= K){
     a = a + K;
    }
    if (a < K){
     a = a * 2;
    }
   }
  cout << a << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

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

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100010;

int n;
struct edge{
	int x,nxt;
}e[N*2];
int tot,h[N];
bool f[N][2];

void inse(int x,int y){
	e[++tot].x=y;
	e[tot].nxt=h[x];
	h[x]=tot;
}

bool bz[N];
int fa[N];

void dfs(int x){
	bz[x]=1;
	f[x][0]=1;
	int cnt=0,s=0;
	for(int p=h[x];p;p=e[p].nxt)
	if (!bz[e[p].x]){
		fa[e[p].x]=x;
		dfs(e[p].x);
		f[x][0]&=f[e[p].x][1];
		s++;
		if (f[e[p].x][1])cnt++;
	}
	for(int p=h[x];p;p=e[p].nxt)
	if (fa[e[p].x]==x&&f[e[p].x][0]){
		if ((cnt-f[e[p].x][1])==s-1)f[x][1]=1;
	}
}

int main(){
	n=get();
	fo(i,1,n-1){
		int x=get(),y=get();
		inse(x,y);
		inse(y,x);
	}
	dfs(1);
	if (f[1][1])printf("Second\n");
	else printf("First\n");
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

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

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

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

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


Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int tourist = 0;
    map<int, int> m;
    rep(i, n) {
        cin >> a[i];
        if (a[i] >= 3200)
            tourist++;
        else
            m[a[i] / 400]++;
    }
    int min1 = m.size();
    int max1 = m.size();
    if (tourist == n) {
        cout << 1 << ' ' << n << endl;
        return 0;
    }
    if (tourist) {
        max1 += tourist;
    }
    cout << min1 << ' ' << max1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<=i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;
typedef pair<ll,ll> P;

int N,A,B,C;

int dfs(int cur,int a,int b,int c,vector<int> &L){
  if(cur==N){return min({a,b,c})>0?abs(a-A)+abs(b-B)+abs(c-C)-30:INF;}
  int ret0 = dfs(cur+1,a,b,c,L);
  int ret1 = dfs(cur+1,a+L[cur],b,c,L)+10;
  int ret2 = dfs(cur+1,a,b+L[cur],c,L)+10;
  int ret3 = dfs(cur+1,a,b,c+L[cur],L)+10;
  return min({ret0,ret1,ret2,ret3});
}

int main(){
  cin>>N>>A>>B>>C;
  vector<int> L(N);
  REP(i,0,N)cin>>L[i];
  int ans = dfs(0,0,0,0,L);
  print(ans)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
  
    return ans;
}
int main() {
    int N;
    cin>>N;
    vector<int>A(N);
    rep(i,N){
        cin>>A[i];
    }
    sort(A.rbegin(),A.rend());
    int a=0;
    int b=0;
    rep(i,N){
        if(i+1<N){
        a+=A[i];
        b+=A[i+1];
        i++;
        }
        else{
          a+=A[i];
        }
    }
  cout<<a-b<<endl;
}


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

int main(){
	int N;
	cin >> N;
	set<string> s;
	for(int i=0;i<N;i++){
		string S;
		cin >> S;
		s.insert(S);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 19260
if __name__ == '__main__':
    exp = list(map(str, input().split()))
    tmp = []
    for e in exp:
        if e == '+':
            tmp.append(tmp.pop() + tmp.pop())
        elif e == '-':
            tmp.append(-tmp.pop() + tmp.pop())
        elif e == '*':
            tmp.append(tmp.pop()*tmp.pop())
        else:
            tmp.append(int(e))
    print(tmp[0])


Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int s(int n) {
	int ret = 0;
	while(n){
		ret += n % 10;
		n /= 10;
	}
	return ret;
}

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

	lint n, a, b, sum, ans = 0;
	cin >> n >> a >> b;
	rep(i, n+1) {
		sum = s(i);
		if ((a <= sum) && (sum <= b))ans += i;
	}
	co(ans);
	gc();
}

Measured memory_bytes: 256
N = int(input())

if N >= 400 and N <= 599:
    print(8)
if N >= 600 and N <= 799:
    print(7)
if N >= 800 and N <= 999:
    print(6)
if N >= 1000 and N <= 1199:
    print(5)
if N >= 1200 and N <= 1399:
    print(4)
if N >= 1400 and N <= 1599:
    print(3)
if N >= 1600 and N <= 1799:
    print(2)
if N >= 1800 and N <= 1999:
    print(1)



Measured memory_bytes: 61644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sim template < class c
#define ris return *this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", ", d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; it++)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int N = 310;
vector<vector<vector<double>>> dp(N, vector<vector<double>> (N, vector<double> (N, -1)));
int a[4], n;

double solve(int x, int y, int z) {
	if (x < 0 || y < 0 || z < 0) {
		return 0;
	}
	if (x == 0 && y == 0 && z == 0) {
		return 0;
	}
	if (dp[x][y][z] != -1) {
		return dp[x][y][z];
	}
	int rem = x + y + z;
	double v1 = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1);
	return dp[x][y][z] = v1 / rem;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	int x;
	for (int i = 0; i < n; i++) {
		cin >> x;
		a[x]++;
	}
	double ans = solve(a[1], a[2], a[3]);
	cout << fixed << setprecision(12) << ans;
	
	return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    int N;
    cin >> N;
    FOR(i,1,N){
        int ans = 0;
        FOR(z,1,sqrt((double)i/6)){
            FOR(y,z,sqrt((double)(i-z*z)/3)){
                FOR(x,y,sqrt(i-z*z-y*y-y*z)){
                    if(x*x+y*y+z*z+x*y+y*z+z*x == i){
                        if(x == y && y == z) ans++;
                        else if(x == y || y == z || z == x) ans+=3;
                        else ans+=6;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll T[105];

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> T[i];
    }

    ll ans = T[0];
    REP(i, N) {
        ll g = gcd(ans, T[i]);
        ans = ans / g * T[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for _ in range(3)]
a = [0] * 3
b = [0] * 3
b[0] = c[0][0] - a[0]
b[1] = c[0][1] - a[0]
b[2] = c[0][2] - a[0]
a[1] = c[1][0] - b[0]
a[2] = c[2][0] - b[0]
#print(a)
#print(b)
flag = True
for i in range(3):
  for j in range(3):
    if a[i] + b[j] != c[i][j]:
      flag = False
if flag:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
card=['S','H','C','D']
num=[[False]*14 for i in range(4)]
N=int(input())
for i in range(N):
    s,m=input().split()
    m=int(m)
    if s=='S':
        num[0][m]=True
    elif s=='H':
        num[1][m]=True
    elif s=='C':
        num[2][m]=True
    else:
        num[3][m]=True
for i in range(4):
    for j in range(1,14):
        if num[i][j] == False:
            print("%s %d"%(card[i],j))


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

int main()
{
    int N, L;
    cin >> N >> L;

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

    sort(S.begin(), S.end());
    for (int i = 0; i < N; i++)
    {
        cout << S[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 1050;

struct box {
  int w, s, v;
};

int n;
vector <box> v;
long long dp[MAXN][10 * MAXN];

bool cmp(box &a, box &b) {
  return a.w + a.s < b.w + b.s;
}

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    box b;
    scanf("%d %d %d", &b.w, &b.s, &b.v);
    v.push_back(b);
  }

  sort(all(v), cmp);
  reverse(all(v));

  dp[0][v[0].s] = v[0].v;
  for (int i = 1; i < n; i++) {
    dp[i][v[i].s] = v[i].v;
    for (int j = 0; j <= 10000; j++) {
      if (dp[i - 1][j] == 0) {
        continue;
      }
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if (j >= v[i].w) {
        dp[i][min(j - v[i].w, v[i].s)] = max(dp[i][min(j - v[i].w, v[i].s)], dp[i - 1][j] + v[i].v);
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i <= 10000; i++) {
    ans = max(ans, dp[n - 1][i]);
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int X, N;
  cin >> X >> N;

  set<int> p_set;
  int p;
  for (int n = 1; n <= N; n++){
    cin >> p;
    p_set.insert(p);
  }

  if (N == 0){
    cout << X << endl;
    return 0;
  }

  int min_d = 1000;
  int min_p = 1000;
  for (int n = 0; n <= 101; n++){
    if (p_set.count(n)){
      continue;
    }
    int d = abs(X - n);
    //cout << n << " " << d << endl;
    if (d < min_d){
      min_d = d;
      //cout << "min_d: " << d << endl;
      min_p = n;
      //cout << "min_p: " << min_p << endl;
    }
  }
  cout << min_p << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

// (x, y)と(sx, sy)が同一直線上にあるか判定
inline bool sameline(int x, int y, int sx, int sy) {
    return x == sx || y == sy || abs(x - sx) == abs(y - sy);
}

// x行目にクイーンを置く
bool dfs(std::vector<int>& queen, int x) {
    if (x == 8) return true;

    if (queen[x] >= 0) {
        for (int sx = 0; sx < x; ++sx) {
            if (sameline(x, queen[x], sx, queen[sx])) return false;
        }
        return dfs(queen, x + 1);
    }

    for (int y = 0; y < 8; ++y) {
        bool judge = true;
        for (int sx = 0; sx < x; ++sx) {
            if (sameline(x, y, sx, queen[sx])) judge = false;
        }

        if (judge) {
            queen[x] = y;
            if (dfs(queen, x + 1)) return true;
            queen[x] = -1;
        }
    }
    return false;
}

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

    if (!dfs(queen, 0)) std::terminate();

    std::vector<std::string> ans(8, std::string(8, '.'));
    for (int x = 0; x < 8; ++x) ans[x][queen[x]] = 'Q';

    for (auto& s : ans) std::cout << s << std::endl;
    return 0;
}



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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

struct edge {
  int p;
  vi c;
};

edge es[100000];

int main() {
  string s;
  cin >> s;

  int n = s.size();

  REP(i, n) {
    if ((i == 0 and s[i] == '0') or (i == n - 1 and s[i] == '1') or
        (i != 0 and i != n - 1 and s[i] != s[n - i - 2])) {
      cout << "-1" << endl;
      return 0;
    }
  }

  int p = 0;

  FOR(i, 1, n - 1) {
    if (s[i] == '1') {
      cout << p + 1 << " " << i + 1 << endl;
      p = i;
    } else {
      cout << p + 1 << " " << i + 1 << endl;
    }
  }

  cout << 1 << " " << n << endl;

  return 0;
}


Measured memory_bytes: 4736
N = gets.to_i
as = gets.split.map(&:to_i)
as.sort!
ans = []
min = as.shift
max = as.pop
 
tmp1 = min
while as.size > 0 && as[-1].to_i >= 0
  plus = as.pop
  ans << [tmp1, plus]
  tmp1 -= plus
end
tmp2 = max
while as.size > 0 && as[-1].to_i < 0
  minus = as.pop
  ans << [tmp2, minus]
  tmp2 -= minus
end
ans << [tmp2, tmp1]
p tmp2 - tmp1

ans.map { |(x, y)| puts "#{x} #{y}" }

Measured memory_bytes: 19712
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//#include <iostream>
//#include <string>
//using namespace std;

int main(int argc, char* argv[]){
	int N;
	char buf[51]={0};

	scanf("%d", &N);
	scanf("%s", buf);

	char *p = buf;
	int ans=0;
	for(;;){
		int cmp = strncmp(p, "ABC", 3);
		if(cmp==0){
			ans++;
			p += 3;
		}
		else{
			p++;
		}
		if(*p=='\0'){
			break;
		}		
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

int main()
{
	int x, k;
	scanf("%d %d", &k, &x);
	
	for (int i = max(x - k + 1, -1000000); i <= min(x + k - 1, 1000000); i++)
		printf("%d ", i);
	puts("");
	
	return 0;
}

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

( n, m ) = map ( int, input ( ).split ( ) )
b = tuple ( map ( int, input ( ).split ( ) ) )
p = list ( map ( int, input ( ).split ( ) ) )

cs = 0
ss = { }
fs = [ ]
bs = [ b ]
while bs:
  ( fs, bs ) = ( bs, fs )
  while fs:
    b = fs.pop ( )
    if b not in ss:
      ss[ b ] = cs
      b = list ( b )
      for i in range ( n - 1 ):
        ( b[ i ], b[ i + 1 ] ) = ( b[ i + 1 ], b[ i ] )
        bs.append ( tuple ( b ) )
        ( b[ i + 1 ], b[ i ] ) = ( b[ i ], b[ i + 1 ] )
  cs = cs + 1

for ( k, v ) in ss.items ( ):
  res = [ ]
  co = 1
  for i in range ( 1, len ( k ) ):
    if k[ i - 1 ] == k[ i ]:
      co = co + 1
    else:
      res.append ( co )
      co = 1
  res.append ( co )
  if res == p and v < cs:
    cs = v

print ( cs )

Measured memory_bytes: 10176
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
 string a,b;
 cin>>a>>b;
 if(a=="H") cout<<b<<endl;
 else if(a=="D"&&b=="H") cout<<"D"<<endl;
 else cout<<"H"<<endl;
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
que = deque(maxlen=h * w)
next = deque(maxlen=h * w)

data = []

for ln in range(h):
    line = list(input().rstrip())
    data.append(line)
    for r, letter in enumerate(line):
        if letter == '#':
            que.append((ln, r))

count = 0

while len(que) > 0:
    count += 1
    while len(que) > 0:
        row, col = que.popleft()
        for r, c in ((row - 1, col), (row + 1, col), (row, col - 1), (row, col + 1)):
            if 0 <= r < h and 0 <= c < w and data[r][c] == '.':
                next.append((r, c))
                data[r][c] = '#'
    que, next = next, que
    next.clear()

print(count - 1)

Measured memory_bytes: 117164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        long ans = Long.MAX_VALUE;
        for(long i=1; i*i<=n; i++) {
            if(n % i == 0) {
                long digitsA = String.valueOf(i).length();
                long digitsB = String.valueOf(n/i).length();
                ans = Math.min(Math.max(digitsA,digitsB),ans);
            }
        }
        System.out.println(ans);
    }
}


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

int main() {
  int n;
  cin>>n;
  int ans=0;
  vector<int>vec(n);
  for(int i=0;i<n;i++) {
    cin>>vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for(int k=0;k<n;k++) {
    if(k%2==0) {
      ans+=vec.at(k);
    }
    else if(k%2==1) {
      ans-=vec.at(k);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
l=[]
import sys
sys.setrecursionlimit(20000000)
from collections import defaultdict
d=defaultdict(lambda:defaultdict(int))
l1=[[] for i in range(n+1)]
#d=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(n-1):
  a,b=map(int,input().split())
  l1[a].append(b)
  l1[b].append(a)
  l.append([a,b])
max1=0
for i in l1:
  if max1<len(i):
    max1=len(i)
def dfs(x,y):#xは頂点yは入ってくる色
  l2=l1[x]
  now=1
  for i in range(len(l2)):
    if d[x][l2[i]]!=0:
      pass
    else:                
      if now==y:
        now+=1
      d[x][l2[i]]=now
      d[l2[i]][x]=now
      dfs(l2[i],now)
      now+=1
print(max1)
dfs(1,0)
for i in range(len(l)):
  print(d[l[i][0]][l[i][1]])


Measured memory_bytes: 92640
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		for(int i=0;i<n;i++){
			String s = sc.next();
			String ans = s.substring(0,1);
			
			int now = 0;
			
			for(int j=1;j<s.length();j++){
				if(s.codePointAt(j)==60) now--;
				else if(s.codePointAt(j+1)==62) now++;
				if(now==-1){
					ans = (char)s.codePointAt(j+2) + ans;
					now++;
				}
				else if(now==ans.length()) ans = ans + (char)s.codePointAt(j+2);
				j += 2;
			}
			System.out.println(ans);
		}
	}	
}

Measured memory_bytes: 21260
N = int(input())
a = list(map(int, input().split()))
count = [0] * 100001
over = 0
ans = 0
for i in a:
    if i > 100000:
        over += 1
    else:
        count[i] += 1
for i in range(100001):
    if count[i] < i:
        ans += count[i]
    elif count[i] == i:
        continue
    else:
        ans += count[i] - i
print(ans + over)



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

int main(){
	int a,b,c,x,count=0;
  	cin >> a >> b >> c >> x;
  	for (int i=0;i<=a;i++){
    	for (int j=0;j<=b;j++){
        	for (int k=0;k<=c;k++){
             if (i*500+j*100+k*50==x) count++; 
            }
        }
    }
	cout << count << endl;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

const mod = 10^^9+7;

void main()
{
  int n; readV(n);

  auto ans = 1L;
  foreach (i; 1..n+1)
    (ans *= i) %= mod;

  writeln(ans);
}


Measured memory_bytes: 256
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
c = 0
for i in range(N-2):
  for j in range(i+1,(i+N+1)//2):
    k = j*2-i
    if len(set([S[i], S[j], S[k]]))==3:
      c += 1
print(r*g*b-c)

Measured memory_bytes: 9188
#include <cmath>
#include <iostream>

using namespace std;

const int INF = 1 << 30;

int main() {
    int N, K;
    cin >> N >> K;

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

    int cost[N + K];
    fill(cost, cost + N + K, INF);
    cost[0] = 0;

    for (int i = 0; i < N - 1; ++i) {
        for (int k = 1; k <= K; ++k) {
            cost[i + k] = min(cost[i + k], cost[i] + abs(h[i + k] - h[i]));
        }
    }

    cout << cost[N - 1] << endl;
    return 0;
}


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

using namespace std;

struct status{
    int cost,x,y,t;
    status(int cost,int x,int y,int t):
    cost(cost),x(x),y(y),t(t){}
};

queue<status>q;

int ans=-1;
int sx,sy,gx,gy,lx,ly;
int mx[7]={0,1,1,0,-1,-1,0};
int my0[7]={1,0,-1,-1,-1,0,0};
int my1[7]={1,1,0,-1,0,1,0};
bool memo[201][201][6];

void non_cost(status st){
    q.push(st);memo[st.x+100][st.y+100][st.t]=1;
    int tx=st.x,ty=st.y,tt=st.t;
    while(1){
        int f=abs(tx*ty*tt)%6;
        if(tx%2!=0)ty+=my1[f];
        else ty+=my0[f];
        tx+=mx[f];
        (++tt)%=6;
        if(abs(tx)>abs(lx) || abs(ty)>abs(ly))return;
        if(memo[tx+100][ty+100][tt])return;
        q.push(status(st.cost,tx,ty,tt));
        if(tx==gx && ty==gy){
            ans=st.cost;
            break;
        }
        memo[tx+100][ty+100][tt]=1;
    }
}

int main(){
    cin>>sx>>sy>>gx>>gy;
    int n;cin>>n;
    for(int i=0;i<n;++i){
        int x,y;
        cin>>x>>y;
        for(int j=0;j<6;++j)memo[x+100][y+100][j]=1;
    }
    cin>>lx>>ly;
    non_cost(status(0,sx,sy,0));
    if(ans!=-1){
        cout<<ans<<endl;
        return 0;
    }
    while(!q.empty()){
        status nst=q.front();q.pop();
        for(int i=0;i<7;++i){
            //if(abs(nst.x*nst.y*nst.t)%6 == i)continue;
            int tx=nst.x+mx[i],tt=(nst.t+1)%6,ty;
            if(nst.x%2!=0)ty=nst.y+my1[i];
            else ty=nst.y+my0[i];
            if(abs(tx)>abs(lx) || abs(ty)>abs(ly))continue;
            if(!memo[tx+100][ty+100][tt]){
                non_cost(status(nst.cost+1,tx,ty,tt));
                if(tx==gx && ty==gy){
                    ans=nst.cost+1;
                    break;
                }
                if(ans!=-1)break;
            }
        }
        if(ans!=-1)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
/*
	vec1.size();
	str1.length();
	vec1.pop_back;
*/
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef vector<pll> vplll;
#define rep(i,l,r) for (ll i = l; i < r; ++i)
#define reprev(i,l,r) for (ll i = r; i >= l; --i)
ll mod = 1e9+7;
ll expo_mod(ll x, ll y, ll p) 
{ 
	ll res = 1;
	x = x % p; 
	if (x == 0) 
		return 0; 
	while (y > 0) 
	{
		if (y%2==1) 
			res = (res*x) % p; 
		y = y>>1; // y = y/2 
		x = (x*x) % p; 
	} 
	return res; 
} 
ll gcd(ll a,ll b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m,x;
	ll crr[13];
	ll algo[13];
	ll arr[13][13];
	cin>>n>>m>>x;
	rep(i,0,n)
	{
		cin>>crr[i];
		rep(j,0,m)
		{
			cin>>arr[i][j];
		}
	}
	ll mini=1e9;
	ll money,fg;
	rep(i,1,1<<n)
	{
		money=0;
		rep(j,0,m)
		{
			algo[j]=0;
		}
		rep(j,0,n)
		{
			if(i&(1<<j))
			{
				money+=crr[j];
				rep(k,0,m)
				{
					algo[k]+=arr[j][k];
				}
			}
		}
		fg=1;
		rep(j,0,m)
		{
			if(algo[j]<x)
			{
				fg=0;
				break;
			}
		}
		if(fg)
		{
			mini=min(mini,money);
		}
	}
	if(mini==1e9)
		cout<<"-1\n";
	else
		cout<<mini<<"\n";
	return 0;
}

Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#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 ll long long 
#define all(v) v.begin(),v.end()
using namespace std; 
ll two(ll  k){
  ll ans=0;
  while(k%2==0){
    k/=2;
    ans++;
  }
  return ans;
}
int main(){
  ll n; cin >>n;
  vector<ll> a(n);
  ll ans  =0;
  rep(i,n){
    cin >>a[i];
     ans += two(a[i]);
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 384