akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;
int ans;
int pr[maxx];
int cnt[maxx];
int x3, x5, x15, x25, x75;

int main() {
	// 分解质因子 X = p1^x1 * p2^x2 * ... * pn^xn
	// X的因子个数 = (x1 + 1) * (x2 + 1) * ... * (xn + 1)
	// 75 --> 3 * 5 * 5 = 3 * 25 = 5 * 15 = 75
	int num = 0;
	for(int i = 2; i <= 100; i++) {
		bool chk = 1;
		for(int j = 2; j <= sqrt(i); j++) {
			if(i % j == 0) {
				chk = 0;
				break;
			}
		}
		if(chk) pr[++num] = i;
	}
	cin >> n;
	for(int i = 1; i <= n; i++) {
		int tmp = i;
		for(int j = 1; j <= num; j++) {
			while(tmp % pr[j] == 0) {
				cnt[j]++; // 质因子指数
				tmp /= pr[j];
			}
		}
	}
	for(int i = 1; i <= num; i++) {
		if(cnt[i] >= 2) x3++;
		if(cnt[i] >= 4) x5++;
		if(cnt[i] >= 14) x15++;
		if(cnt[i] >= 24) x25++;
		if(cnt[i] >= 74) x75++;
	}
	// 3 * 5 * 5
	ans += (x5 * (x5 - 1) / 2) * (x3 - 2); // Cx5\2 * C(x3 - 2)\1
	// 3 * 25
	ans += x25 * (x3 - 1); // Cx25\1 * C(x3 - 1)\1
	// 5 * 15
	ans += x15 * (x5 - 1); // Cx15\1 * C(x5 - 1)\1
	// 75
	ans += x75; //Cx75\1
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    int n,a,b; cin >> n >> a >> b;
    string s; cin >> s;
    int sum = 0, ab = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'a'){
            if(sum < a+b){
                cout << "Yes" << endl;
                sum++;
            }else{
                cout << "No" << endl;
            }
        }else if(s[i] == 'b'){
            if(sum < a+b && ab < b){
                cout << "Yes" << endl;
                sum++; ab++;
            }else{
                cout << "No" << endl;
            }

        }else if(s[i] == 'c'){
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int C = int.Parse(str[1]);
		int[,]D = new int[C,C];
		int[,]CC = new int[N,N];
		for(var i=0;i<C;i++){
			string[] str2 = Console.ReadLine().Split();
			for(var j=0;j<C;j++){
				D[i,j] = int.Parse(str2[j]);
			}
		}
		for(var i=0;i<N;i++){
			string[] str3 = Console.ReadLine().Split();
			for(var j=0;j<N;j++){
				CC[i,j] = int.Parse(str3[j]);
			}
		}
		int[,] Dis = new int[3,C];
		int count = 0;
		for(var h=0;h<3;h++){
			for(var i=0;i<C;i++){
				count = 0;
				for(var j=0;j<N;j++){
					for(var k=0;k<N;k++){
						if((j+k)%3 == h){
							count += D[CC[j,k]-1,i];
						}
					}
				}
				Dis[h,i] = count;
			}
		}
		int[,] mina = new int[3,3];
		int[,] minc = new int[3,3];
		for(var i=0;i<3;i++){
			for(var j=0;j<3;j++){
				mina[i,j] = 999999999;
				minc[i,j] = 99;
			}
		}
		for(var h=0;h<3;h++){
			for(var i=0;i<C;i++){
				if(Dis[h,i] < mina[h,0]){
					mina[h,2] = mina[h,1];
					minc[h,2] = minc[h,1];
					mina[h,1] = mina[h,0];
					minc[h,1] = minc[h,0];
					mina[h,0] = Dis[h,i];
					minc[h,0] = i;
				} else if(Dis[h,i] < mina[h,1]){
					mina[h,2] = mina[h,1];
					minc[h,2] = minc[h,1];
					mina[h,1] = Dis[h,i];
					minc[h,1] = i;
				} else if(Dis[h,i] < mina[h,2]){
					mina[h,2] = Dis[h,i];
					minc[h,2] = i;
				}
			}
		}
		int min = 999999999;
		for(var h=0;h<3;h++){
			for(var i=0;i<3;i++){
				if(minc[0,h] != minc[1,i]){
					for(var j=0;j<3;j++){
						if(minc[0,h] != minc[2,j] && minc[1,i] != minc[2,j]){
							min = Math.Min(min,mina[0,h]+mina[1,i]+mina[2,j]);
						}							
					}
				}
			}
		}
		Console.WriteLine(min);
	}
}

Measured memory_bytes: 16084
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000;
const double PI = acos(-1);
const int mod = 1000000007;


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

    int ans = 0;
    rep(i, 1000) {
        int first = i / 100;
        int second = (i%100) / 10;
        int third = i % 10;
        // 1桁目
        bool is_ok = false;
        int now = -1;
        rep(j, n) {
            if (first == s[j] - '0') {
                is_ok = true;
                now = j;
                break;
            }
        }
        if (!is_ok) continue;
        // 2桁目
        is_ok = false;
        for (int j = now + 1; j < n; j++) {
            if (second == s[j] - '0') {
                is_ok = true;
                now = j;
                break;
            }
        }
        if (!is_ok) continue;
        // 3桁目
        is_ok = false;
        for (int j = now + 1; j < n; j++) {
            if (third == s[j] - '0') {
                is_ok = true;
                now = j;
                break;
            }
        }
        if (!is_ok) continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define INF (1<<30)
#define INFLL (1L<<63)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  ll x; cin >> x;
  if (x % 11 == 0) cout << x / 11 * 2 << endl;
  else if (x % 11 > 6) cout << x / 11 * 2 + 2 << endl;
  else cout << x / 11 * 2 + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int h,n;
  cin >> h >> n;
  ll sum = 0;
  rep(i,n) {
    ll a;
    cin >> a;
    sum += a;
  }
  if(sum>=h) cout << "Yes" << endl;
  else cout << "No" << endl;
  
    
  
}


Measured memory_bytes: 256
def main() :
	x = int(input())
	if 400 <= x <= 599 : k = 8
	if 600 <= x <= 799 : k = 7
	if 800 <= x <= 999 : k = 6
	if 1000 <= x <= 1199 : k = 5
	if 1200 <= x <= 1399 : k = 4
	if 1400 <= x <= 1599 : k = 3
	if 1600 <= x <= 1799 : k = 2
	if 1800 <= x <= 1999 : k = 1
	print(k)

if __name__ == '__main__' :
	main()

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

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

    int maxp = 0;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        int temp;
        cin >> temp;

        sum += temp;
        maxp = max(maxp, temp);
    }

    sum -= maxp / 2;

    cout << sum << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

int n,a[N];

int main () {
	cin >> n;
	n = 2 * n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	ll ans = 0;
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i = 2; i <= n; i += 2) ans += a[i];
	cout << ans;
	

return 0;
}

Measured memory_bytes: 256
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
def d(x,y):
    kyori=0
    for a,b in zip(x,y):
        kyori+=abs(a-b)**2
    return kyori
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if math.sqrt(d(X[i],X[j])).is_integer():
            ans+=1
print(ans)

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

int main(){
    
    size_t h, w;

    std::cin >> h >> w;

    std::vector<std::vector<char>> c(h, std::vector<char>(w));

    for(auto&& v : c){
        for(auto&& e : v){
            std::cin >> e;
        }
    }

    std::vector<std::vector<char>> out(2 * h, std::vector<char>(w));

    for(size_t i = 0; i < h; i++){
        for(size_t j = 0; j < w; j++){
            out[2 * i][j] = c[i][j];
            out[2 * i + 1][j] = c[i][j];
        }
    }

    for(const auto& v : out){
        for(const auto& e : v){
            std::cout << e;
        }
        std::cout << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(a: int, b: int):
    n = int(str(a) + str(b))
    if math.sqrt(n) == math.sqrt(n) // 1:
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 62340
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 105;
int n, W;
int w[maxn], v[maxn];

int dp[maxn][maxn][maxn * 3];

void read_input()
{
    cin >> n >> W;
    for(int i = 1; i <= n; ++i)
        cin >> w[i] >> v[i];
}

void solve()
{
    fill_n(&dp[0][0][0], sizeof(dp) / sizeof(dp[0][0][0]), -1);
    dp[0][0][0] = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            for(int k = 0; k < 3 * n; ++k)
            {
                if(dp[i][j][k] == -1) continue;
                dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
                dp[i + 1][j + 1][k + w[i + 1] - w[1]] = max(dp[i + 1][j + 1][k + w[i + 1] - w[1]],
                                                            dp[i][j][k] + v[i + 1]);
            }
    int ans = 0;
    for(int j = 1; j <= n; ++j)
        for(int k = 0; k <= 3 * n; ++k)
            if(w[1] * 1LL * j + k <= W) ans = max(ans, dp[n][j][k]);
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 13824
A, B, C = map(int, input().split())
k = int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

a = A
b = B
c = C
ans = 0
if a < b < c:
    ans = 1

for i in range(3**k):
    a = A
    b = B
    c = C
    i3 = Base_10_to_n(i, 3).zfill(k)
    mem = 0
    Pick = []
    for j in range(k):
        if i3[j] == '0':
            a *= 2
        elif i3[j] == '1':
            b *= 2
        elif i3[j] == '2':
            c *= 2
#        print(a, b, c)
    if a < b < c:
        ans = 1
#        print('!!')
if ans:
    print('Yes')
else:
    print('No')

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

const int md = 1e9+7;
int n, x, y, z, sm, g;
long long a[2][1<<20] = {1}, ans;

int main(){
  scanf("%d%d%d%d", &n, &x, &y, &z);
  sm = x + y + z;
  g = (((1<<y)+1)<<z)+1;
  for(int i = 0; i <= n; i++){
    (ans *= 10) %= md;
    for(int j = 0; j < 1<<sm; j++){
      if((j & g) == g) (ans += a[i&1][j]) %= md;
      else for(int k = 1; k <= 10; k++) (a[i&1^1][(j+(1<<sm))>>k] += a[i&1][j]) %= md;
      a[i&1][j] = 0;
    }
  }
  printf("%lld\n", ans);
}

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

using namespace std;


int main() {
    int A, B;
    cin>>A>>B;

    int tmp = A+B;
    if(tmp%2==1){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }else{
        cout << tmp/2 << endl;
        return 0;
    }

}

Measured memory_bytes: 256
/*input
5
3 3 3 3 3
*/
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 9000000000000000001
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--) 
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define sz(x)  ((ll)x.size())
#define DEBUG
#ifdef DEBUG
#define dbg(x) cout << (#x) << " is " << (x) << endl
#else 
#define dbg(x)
#endif
#define N 200002

using namespace std;
int main()
{
	fastio
	ll T=1,n,m;string str;
	// cin>>T;
	// cin.ignore(); put after cin, just b4 a getline(cin, s) to avoid getline() directly getting \n
	while(T--)
	{
		ll p=0,q=0,tmp=0,sum=0,count=0; //tmp variable
		int flag=0;
		
		cin>>n;
		ll a[n];
		for(ll i=0;i < n;i++)
			cin>>a[i];

		ll mx = 0;

		for (int i = 0; i < n; ++i)
		{
			if(a[i]>mx) mx = a[i];
			else sum += mx-a[i];
		}
		cout << sum << endl;
		
	}
	return 0;
}

Measured memory_bytes: 5212
def abc175_c_2():
    x, k, d = map(int, input().split())

    def solve(x, k, d):
        # Xを絶対値でプラスの値にし、0に近づける問題に置き換える
        x = abs(x)

        # (x // d)は0の手前まで移動するのに必要な回数。kの方が小さい場合はk回移動してしまえばよい
        if k < (x // d):
            return x - (k * d)
        # kのほうが大きい場合はそこから数回移動が必要
        else:
            # xからとりあえずx//d回は移動してOK
            current_x = x - d * (x // d)
            k = k - (x // d)

            # 結局ここをfor文で探索すると時間がかかるので終わらない。(10**30回とか探索しちゃう。)
            if (k % 2) == 0:
                # 残りの移動回数が偶数回なら移動を繰り返してその場所に戻ってくる
                return current_x
            else:
                # 奇数回の場合、偶数回移動を繰り返した後、もう一回だけ移動する。
                # この時、current_xは0以上なので、マイナス方向に動けばOK
                return abs(current_x - d)

    ans = solve(x, k, d)
    print(ans)

if __name__ == '__main__':
    abc175_c_2()

Measured memory_bytes: 9204
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	a := readInt()
	b := readInt()

	d := []struct {
		p int
		q int
		r int
	}{
		{1, 2, 3},
		{2, 3, 1},
		{1, 3, 2},
	}

	x := min(a, b)
	y := max(a, b)
	for _, v := range d {
		if v.p == x && v.q == y {
			fmt.Println(v.r)
		}
	}
}

var stdin *bufio.Scanner

func read() string {
	if stdin == nil {
		stdin = bufio.NewScanner(os.Stdin)
		stdin.Split(bufio.ScanWords)
		stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	}
	stdin.Scan()
	return stdin.Text()
}

func readInt() int {
	n, _ := strconv.Atoi(read())
	return n
}

func readFloat64() float64 {
	n, _ := strconv.ParseFloat(read(), 64)
	return n
}

func min(a ...int) int {
	v := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] < v {
			v = a[i]
		}
	}
	return v
}

func max(a ...int) int {
	v := a[0]
	for i := 1; i < len(a); i++ {
		if v < a[i] {
			v = a[i]
		}
	}
	return v
}


Measured memory_bytes: 640
def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod

def uf_find(n,p):

    ufl = []

    while p[n] != n:
        ufl.append(n)
        n = p[n]

    for i in ufl:
        p[i] = n

    return n


def uf_union(a,b,p,rank,tsize):

    ap = uf_find(a,p)
    bp = uf_find(b,p)

    if ap == bp:
        return True
    else:

        if rank[ap] > rank[bp]:
            p[bp] = ap
            tsize[ap] += tsize[bp]
        elif rank[ap] < rank[bp]:
            p[ap] = bp
            tsize[bp] += tsize[ap]
        else:
            p[bp] = ap
            rank[ap] += 1
            tsize[ap] += tsize[bp]

        return False

mod = 10**9+7
N = int(input())
P = list(map(int,input().split()))
fac,inv = modfac(N+10,mod)

ans = 0

p = [i for i in range(N)]
rank = [1] * N
tsize = [1] * N

for i in range(N):

    if P[i] == -1:
        continue
    nex = P[i] - 1
    uf_union(i,nex,p,rank,tsize)

able = [True] * N
c = []
d = []

for i in range(N):

    if P[i] == -1:
        nowp = uf_find(i,p)
        c.append(tsize[nowp])
        able[nowp] = False

for i in range(N):

    if uf_find(i,p) == i and able[i]:
        d.append(tsize[i])


ans = 0
for i in c:
    ans += i
for i in d:
    ans += i-1
ans *= pow(N-1,len(c),mod)
ans %= mod

#print (ans)

#自分を選んで減る場合
for i in c:
    ans -= (i-1) * pow(N-1,len(c)-1,mod)
    ans %= mod

#互いに選んで減る場合

dp = [0] * (len(c)+1)
dp[0] = 1

for i in c:
    for j in range(len(c)-1,-1,-1):
        dp[j+1] += dp[j] * i
        #dp[j+1] %= mod
#print (c,dp)

for i in range(2,len(c)+1):

    ans -= dp[i] * fac[i-1] * pow(N-1,len(c)-i,mod)
    ans %= mod

print (ans % mod)


"""
連結成分で考える
全ての街が -1 以外を選んだ時、
最小数 + -1の数
-1同士が選ぶことを考える
-1同士が選んだ時のみ答えが1減る
そうでなければ変化なし？

連結成分に-1は1つ以下しかない？
→正しい

-1を含まない連結成分は分けておく
-1の連結成分同士が求め合えば、答えは-1される

a個含む & bこ含む
場合

a*b * (N-1)^(K-2)
引けばいい

自分の連結成分を求めるときも1減る
ループを作ると1減るんだ！



"""


Measured memory_bytes: 178548
#include <iostream>
#include <cstdio>
#include <cctype>
#include <iomanip>
#include <vector>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int n = 0, c = gcu();
	// bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu())); *s = '\0';}
si void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
svo(string &s){for (char c: s) pcu(c);}
//template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

struct KMP {
	vector<int> pi;
	string T, P;

	KMP() {
		scan(T);
		scan(P);
		prifix_function();
	}

	void prifix_function() {
		pi.resize(P.size());
		int k = -1;
		pi[0] = k;
		for (size_t q = 1; q < P.size(); q++) {
			while (k >= 0 && P[k + 1] != P[q])
				k = pi[k];
			if (P[k + 1] == P[q])
				k++;
			pi[q] = k;
		}
	}

	void matcher() {
		int q = -1;
		int m = P.size();
		for (size_t i = 0; i < T.size(); i++) {
			while (q >= 0 && P[q + 1] != T[i])
				q = pi[q];
			if (P[q + 1] == T[i])
				q++;
			if (q == m - 1) {
				out(i - m + 1, '\n');
				q = pi[q];
			}
		}
	}
	void print() {
		for (char c: P)
			cerr << "  " << c << " ";
		cerr << endl;
		for (int i: pi)
			cerr << setw(3) << i << " ";
		cerr << endl;
	}
};

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

	kmp.matcher();
	//kmp.print();
}


Measured memory_bytes: 3948
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
string s[66],t[66];
int dy[]={-1,0,0,1};
int dx[]={0,1,-1,0};
int h,cnt,w,used[66][130],sum;
map<int,int>id_sum;
map<int,vector<int> >id_each;
void id_dfs(int y,int x,vector<vector<int> >&a,char X,vector<int>&id_x){
  a[y][x]=cnt;
  id_x.push_back(x);
  used[y][x]=1;
  sum++;
  r(i,4){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(ny<0||nx<0||ny>=h||nx>=w)continue;
    if(used[ny][nx])continue;
    if(s[ny][nx]==X)id_dfs(ny,nx,a,X,id_x);
  }
}
P get_lr(int y,int x,vector<vector<int> >&a){
  int id=a[y][x];
  int ny=y;
  int l_x=1e8,r_x=-1e8;
  for(;ny<h;ny++){
    int flag=0;
    r(j,w)if(a[ny][j]==id){
      if(ny+1==h||(a[ny+1][j]!=-1&&a[ny+1][j]!=id)){
        l_x=min(l_x,j);
        r_x=max(r_x,j);
      }
      flag++;
    }
    if(!flag)break;
  }
  return P(l_x,r_x);
}
vector<int> get_data(int y,int x,vector<vector<int> >&a){
  int used2[600]={};
  int oy=y,ox=x;
  vector<int>id_x;
  queue<P>q;
  q.push(P(y,x));
  used2[a[y][x]]=1;
  while(!q.empty()){
    P p=q.front();q.pop();
    y=p.first;
    x=p.second;
    r(i,h)r(j,w)if(a[i][j]==a[y][x]){
      if(a[i][j]==a[oy][ox])used[i][j]=1;
      id_x.push_back(j);
      r(k,1){
        int ny=i+dy[k];
        int nx=j+dx[k];
        if(ny<0||nx<0||ny>=h||nx>=w)continue;
        if(a[ny][nx]==-1)continue;
        if(used2[a[ny][nx]])continue;
        used2[a[ny][nx]]=1;
        q.push(P(ny,nx));
      }
    }
  }
  return id_x;
}
signed main(){
  while(cin>>w>>h,w){
    id_sum.clear();
    id_each.clear();
    cnt=0;
    memset(used,0,sizeof(used));
    r(i,h)cin>>s[i];
    vector<vector<int> >a(h,vector<int>(w));
    r(i,h)r(j,w)a[i][j]=-1;
    r(i,h)r(j,w)if(isdigit(s[i][j])){
      if(!used[i][j]){
        vector<int>id_x;
        sum=0;
        id_dfs(i,j,a,s[i][j],id_x);
        id_sum[cnt]=sum;
        id_each[cnt++]=id_x;
      }
    }
    int flag=0;
    memset(used,0,sizeof(used));
    r(i,h)r(j,w)if(isdigit(s[i][j])){
      if(used[i][j])continue;
      P x_lr=get_lr(i,j,a);
      vector<int>v=get_data(i,j,a);
      double X=0,L=x_lr.first,R=x_lr.second;
      r(i,v.size())X+=v[i];
      X/=(double)v.size();
      if(!(L-0.5<X&&X<R+0.5))flag++;
    }
    if(!flag)cout<<"STABLE"<<endl;
    else cout<<"UNSTABLE"<<endl;
  }
}


Measured memory_bytes: 3224
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

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

    int ans = min(b,d) - max(a,c);
    if(ans<0) ans = 0;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int N;
    cin >> N;
    double x[N], ans = 0;
    string u[N];
    rep(i, N) cin >> x[i] >> u[i];
    rep(i, N) {
        if (u[i] == "JPY") {
            ans += x[i];
        } else {
            ans += 380000.0 * x[i];
        }
    }
    printf("%f\n", ans);
    return 0;
}

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

int main()
{
  i64 a, b;
  cin >> a >> b;
  i64 tap = 1;
  for (i64 i = 0;; i++)
  {
    if (b <= tap)
    {
      cout << i << endl;
      return 0;
    }
    tap += a - 1;
  }
  return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;

  ll ans = (n * 2 - m) / (-4);
  if (ans < 0) ans = m / 2;
  else ans += n;

  print(ans);

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] rgb = str.split(" ");
		int g = Integer.parseInt(rgb[1]);
		int b = Integer.parseInt(rgb[2]);

		if((g*10+b)%4 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}


	}

}


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

int main() {
  int N;
  cin >> N;
  int v[N];
  for(int i=0;i<N;i++){
  cin>>v[i];
  }
  int a=v[0];
  if(a==2)cout<<1<<endl;
  int count=1;
  for(int i=0;i<N-1;i++){
    if(a!=2){
    cin>>v[a];
    a=v[a-1];
    count++;
    if(a==2){
      cout<<count<<endl;
      break;
  }
    else if(i==N-2&&a!=2)cout<<-1<<endl;
  }
    else break;
  }
  
  
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contest_01_Valeo_P2
{
    class Program
    {
        static void Main(string[] args)
        {
            //while (true)
            {
                //Console.WriteLine("start problem");
                string input = Console.ReadLine();
                int h = int.Parse(input.Split(' ')[0]);
                int n = int.Parse(input.Split(' ')[1]);
                input = Console.ReadLine();
                string[] a_string = input.Split(' ');
                List<int> a = new List<int>();
                a_string.ToList().ForEach(x => a.Add(int.Parse(x)));
                bool result = canWin(h, n, a);
                Console.WriteLine(result ? "Yes" : "No");
                //Console.Write("press y to exit : ");
                //if (Console.ReadLine() == "y")
                //    return;
            }
        }

        private static bool canWin(int h, int n, List<int> a)
        {
            int health = h;
            for (int i = 0; i < n; i++)
            {
                health -= a[i];
                if (health <= 0)
                    return true;
            }
            if (health <= 0)
                return true;
            return false;
        }
    }
}


Measured memory_bytes: 20064
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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)*}
    };
}

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!{
        a: i64,
        b: i64,
        c: i64,
    };
    if c <= a + b {
        println!("No");
    } else if 4 * a * b < (c  - a - b).pow(2){
        println!("Yes");
    }else {
        println!("No");
    }

}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
int x, y, a, b, c;
V<P<int, int>> v;
struct prime{
  static const int N = 1e6;
  vector<ll> pr;
  int z[N+1];
  prime(){
    for (int i=2; i<=N; ++i) {
      if(!z[i]) z[i] = i, pr.push_back(i);
      for (int j=0; j<(int)pr.size() && pr[j]<=z[i] && i*pr[j]<=N; ++j) z[i*pr[j]] = pr[j];
    }
  }
  vector<pair<ll, int>> division(ll a){
    vector<pair<ll, int>> v;
    for(ll b:pr){
      if(a<=N) goto fast;
      if(b*b > a) break;
      if(a%b) continue;
      v.emplace_back(b, 0);
      while(a%b==0) a/=b, v.back().second++;
    }
    if(a>1) v.emplace_back(a, 1);
    return v;
fast:
    int p = -1;
    while(a>1){
      if(z[a] != p) v.emplace_back(z[a], 0);
      p = z[a];
      a /= z[a];
      v.back().second++;
    }
    return v;
  }
  vector<ll> divisor(ll m){
    vector<ll> v{1};
    for(auto &a:division(m)){
      int s=v.size();
      ll b=1;
      for(int i=0; i<a.second; i++){
        b *= a.first;
        for(int j=0; j<s; j++) v.push_back(v[j]*b);
      }
    }
    sort(v.begin(), v.end());
    return v;
  }
} pr;
ll n;
bool simulate(ll n, ll k){
  if(k==1) return false;
  while(n%k == 0) n /= k;
  return n%k == 1;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int ans = 0;
  for(ll a:pr.divisor(n  )) ans += simulate(n, a);
  for(ll a:pr.divisor(n-1)) ans += simulate(n, a);
  cout << ans << endl;
}

Measured memory_bytes: 5240
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, T: int, c: "List[int]", t: "List[int]"):
    ret = float('inf')
    for cc, tt in zip(c, t):
        if tt <= T:
            ret = min(ret, cc)
    return 'TLE' if ret == float('inf') else ret



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    c = [int()] * (N)  # type: "List[int]" 
    t = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        c[i] = int(next(tokens))
        t[i] = int(next(tokens))
    result = solve(N, T, c, t)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5248
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int main()
{
  int N;
  string s, t;
  cin >> N >> s >> t;
  rep(i, N){
    if(s == t){
      cout << N + i << endl;
      return 0;
    }
    s.erase(s.begin());
    t.erase(t.begin()+t.size()-1);
  }
  cout << 2*N << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a(n,0),b(n,0),c(n,0);
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
    
    for(int i=1;i<n;i++)
    {
       a[i]=a[i]+max(b[i-1],c[i-1]); 
       b[i]=b[i]+max(a[i-1],c[i-1]);
       c[i]=c[i]+max(b[i-1],a[i-1]);
    }

    cout<<max(max(a[n-1],b[n-1]),c[n-1])<<endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int k,n;
	cin>>k>>n;
	for(int i=0;i<n;i++)
	cin>>ar[i];
	int mx = k;
	for(int i=0;i<n;i++)
	{
		int n1 = i;
		int n2 = (i-1+n)%n;
		int dst = 0;
		if(!i)
		dst = (k - ar[n2] + ar[n1]);
		else dst = (ar[n1] - ar[n2]);
		mx = min(mx, k - dst);
	}	
	cout<<mx<<"\n";
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 1024
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n-2):
  if p[i]<p[i+1] and p[i+1]<p[i+2]:
    cnt+=1
  elif p[i]>p[i+1] and p[i+1]>p[i+2]:
    cnt+=1
print(cnt)

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

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

  int H, W;
  cin >> H >> W;
  VS vs(H);
  cin >> vs;

  int ws = 0;
  REP(y,H) REP(x,W) if(vs[y][x] == '.') ++ws;

  queue<PII> q;
  VVI dist(H, VI(W, INF));
  q.push(MP(0,0));
  dist[0][0] = 0;
  while(!q.empty()){
	auto p = q.front();
	q.pop();

	REP(d,4){
	  PII np(p.FF+dx[d], p.SS+dy[d]);
	  if(np.FF < 0 || H <= np.FF || np.SS < 0 || W <= np.SS || vs[np.FF][np.SS] == '#' || dist[np.FF][np.SS] < INF)
		continue;
	  q.push(np);
	  dist[np.FF][np.SS] = dist[p.FF][p.SS] + 1;
	}
  }

  if(dist[H-1][W-1] == INF) cout << -1 << endl;
  else cout << ws - dist[H-1][W-1] - 1 << endl;

  return 0;
}


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


using namespace std;

int gcd(int a, int b) {
  if(a < b) gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
  int N;
  cin >> N;
  vector<int>A(N);

  for( int i=0;i<N;i++ )
    cin >> A[i];
  
  vector<int>l(N);
  vector<int>r(N);

  int tmp = A[0];
  for( int i=0;i<N;i++ )
    {
      tmp = gcd(tmp, A[i]);
      l[i] = tmp;
    }
  tmp = A[N-1];
  for( int i=N-1;i>-1;i-- )
    {
      tmp = gcd(tmp, A[i]);
      r[i] = tmp;
    }
  
  int ans = 0;
  for( int i=0;i<N;i++ )
    {
      if(i==0)
	tmp = r[1];
      else if(i==N-1)
	tmp = l[N-2];
      else
	tmp = gcd(l[i-1], r[i+1]);
      //      cout << tmp << " " << l[i-1] << " " <<  r[i+1] << endl;
      
      ans = max(ans, tmp);
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
/*
              *******
When winter comes,You'll hear no lions roar,
no stags grazing the fields,
no roses growing in the meadows,
no snakes in the sand.
The krakens will freeze where they swim.
The flayed men will rot and wither.
No trouts swimming in the river and no falcons flying in the air.
Not even the dragons breath will warm you in your halls.
Only the wolfs howl in the night.
            WINTER IS COMING
*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define si(x) scanf("%d",&x)
#define pi(x) printf("%d\n",x)
#define s(x) scanf("%lld",&x)
#define p(x) printf("%lld\n",x)
#define sc(x) scanf("%s",x)
#define pc(x) printf("%s",x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define inf 1e18
#define prec(x) fixed<<setprecision(15)<<x
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define mem(x,y) memset(x,y,sizeof(x))
#define PQG priority_queue< int,std::vector<int>,std::greater<int> >
#define PQL priority_queue< int,std::vector<int>,std::less<int> >
#define PQPL priority_queue<pii ,vector< pii >, less< pii > >
#define PQPG priority_queue<pii ,vector< pii >, greater< pii > >
#define PQPGB priority_queue<pii ,vector< pll >, greater< pll > >
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

using namespace std;

const int N = 2e5+7;
int a[N];
int sum[N],bt[N][25];

bool ok(int lt,int rt) {
    for(int i=0;i<20;i++) {
        if((bt[rt][i]-bt[lt-1][i])>1) return false;
    }
    return true;
}

int main() {
    fast_io;
    int n; cin>>n;
    mem(bt,0); mem(sum,0);
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
        for(int j=0;j<20;j++) {
            bt[i][j]=bt[i-1][j];
            if((1<<j)&a[i]) bt[i][j]++;
        }
    }
    ll cnt=0;
    for(int i=1;i<=n;i++) {
        int l=i+1,r=n; int idx=-1;
        while(l<=r) {
            int mid=(l+r)/2;
            if(ok(i,mid)) idx=mid,l=mid+1;
            else r=mid-1;
        }
        if(idx!=-1) cnt+=(ll)(idx-i);
    }
    cout<<cnt+n<<endl;


    return 0;
}

Measured memory_bytes: 21376
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>

using namespace std;

int main() {
	int a, b, c, n;
	cin >> a >> b >> c;
	if (a > b) {
		n = b;
		b = a;
		a = n;
	}
	if (b > c) {
		n = c;
		c = b;
		b = n;
	}
	if (a > b) {
		n = b;
		b = a;
		a = n;
	}
	cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned int ui;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
#define All(v) (v).begin(),(v).end()
#define Rep(i,n) for(int i = 0; i < (int)n; i++)
#define Reps(i,n) for(int i = 1; i <= (int)n; i++)
#define For(i,m,n) for(int i = m; i < n; i++)
#define Fors(i,m,n) for(int i = m; i <= n; i++)
#define Inf 2e9
#define F first
#define S second
#define pb push_back
#define mp make_pair
struct speed{speed(){cin.tie(); ios::sync_with_stdio(false); cout << fixed << setprecision(18);}}speed;

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

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

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


int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    a = a-1;
    cout << b-(b/c+b/d-b/lcm(c,d)) - (a-(a/c+a/d-a/lcm(c,d))) << "\n";
}

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

using namespace std;

int main(){
    unsigned long long a=1, minn=1;
    cin>>a;
    for(unsigned long long i=2; i*i<=a; ++i){
        if(a%i==0) minn=i;
    }
    if(minn==1) cout<<a-1;
    else cout<<(minn+a/minn-2);
    return 0;
}


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

int main(){
  string s;
  ll k;
  cin >> s;
  cin >> k;
  ll i = 0;
  ll count = 0;
  while(s[i] == '1'){
    if(s[i] == '1'){
      ++count;
      ++i;
    }
    else break;
  }
  if(count > 0 && count >= k){
    cout << "1" << endl;
  }
  else{
    cout << s[count] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll a, b, c, d, p;
  cin >> a >> b >> c >> d >> p;
  ll res1 = p*a, res2;
  if (p <= c) {
    res2 = b;
  } else {
    res2 = b + (p-c)*d;
  }
  cout << min(res1, res2) << endl;
}


Measured memory_bytes: 3108
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String wk = sc.next();
    String[] ballArray = wk.split("");
    int ballNum = 0;
    for (int i = 0;i < ballArray.length;i++){
      if (ballArray[i].equals("1")) {
        ballNum = ballNum + 1;
      }
    }
	System.out.println(ballNum);
  }
}

Measured memory_bytes: 21844
//
// Created on 2020/06/27.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    string s;
    string t;
    cin>>s;
    cin>>t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define interval pair<ll, ll>

const int N = (1e5) + 5;
interval I[N];
int n;

bool comp_right(const interval &i, const interval &j) {
	return i.second < j.second;
}

int activitySelection(interval I[], int n) {
	sort(I, I + n, comp_right);
	int mx = 0;
	ll last = LLONG_MIN;
	for (int i = 0; i < n; ++i) {
		if (last <= I[i].first) {
			++mx;
			last = I[i].second;
		}
	}
	return mx;
}

int main() { // claudio van
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, l; cin >> x >> l;
    I[i] = make_pair(x - l, x + l);
  }
  int mx = activitySelection(I, n);
  cout << mx << "\n";
  return 0;
}

Measured memory_bytes: 1792
main :: IO ()
main = do
  args <- fmap (map (map toInt . words) . lines) getContents
  presentation args

presentation :: [[Int]] -> IO ()
presentation [[a, b], [0, 0]] = mapM_ print $ solve a b
presentation ([a, b]:t) = do
  case res of
    [] -> putStrLn "NA"
    otherwise -> mapM_ print res
  putStrLn ""
  presentation t
  where
    res = solve a b
presentation _ = return ()

toInt :: String -> Int
toInt = read

upperbound :: Int -> Int
upperbound n = ((n + 3) `div` 4) * 4

lowerbound :: Int -> Int
lowerbound n = (n `div` 4) * 4

solve :: Int -> Int -> [Int]
solve from to = [x | x <- [upperbound from, upperbound from + 4 .. lowerbound to], (x `mod` 16) == 0 || (x `mod` 25) /= 0 ]

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

int main() {
  int n;
  cin>>n;
  int k=0;
  std::vector<int> a(n),b(n,0);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i!=1;k++){
    i=a[i]-1;
    b[i]++;
    if(b[i]>1){k=-1;break;}
  }
  cout<<k<<endl;
}


Measured memory_bytes: 1024