akhauriyash/Code-Regression huggingface dataset:
# C
# Peaks

import numpy as np

N, M = map(int, input().split())
H_list = [int(x) for x in input().split()]
N_list = np.arange(1,N+1,1)
Max_list = np.zeros(N)
for i in range(M):
    A, B = map(int, input().split())
    Max_list[A-1] = max(Max_list[A-1],H_list[B-1])
    Max_list[B-1] = max(Max_list[B-1],H_list[A-1])
    
ans = 0
for i in range(len(Max_list)):
    ans += H_list[i] > Max_list[i]

print(ans)

Measured memory_bytes: 38556
#include<bits/stdc++.h>
using namespace std;
long long a[111111];
long long big=1000000000000000000;
int main()
{
	int  n;
	cin>>n;
	bool p=0;
	long long res=1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			cout<<0;return 0;
		}
		if(big/a[i]<res)
		{
			p=1;
		}
		else
		{
			res*=a[i];
		}
		
	}
	if(res>big||p==1)
		cout<<-1;
	else
		cout<<res;
	return 0;
 } 

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

namespace ConsoleApp
{
    class Program
    {

        static void Main(string[] args)
        {
            var ar = ReadLine().Split().Select(long.Parse).ToArray();

            var a = ar[0];
            var b = ar[1];

            var mina = (a ) / 0.08;
            var maxa = (a + 0.9) / 0.08;
            for (int i = (int)Math.Ceiling(mina); i <= maxa;i++)
            {
                if (Math.Floor(i * 0.1) == b)
                {
                    WriteLine(i);
                    return;
                }
            }

            WriteLine("-1");

        }



    }

}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main()
{
  int n;
  int max, min, score;
  int s;
  
  while (1) {
    cin >> n;
    if (n == 0) break;

    max = 0;
    min = 1000;
    score = 0;
    for (int i = 0; i < n; i++) {
      cin >> s;
      score += s;
      if (s > max) max = s;
      if (s < min) min = s;
    }
    cout << (score - max - min) / (n - 2) << endl;
  }
}



Measured memory_bytes: 3080
#include<iostream>
using namespace std;
	int main(){
	int n,a,b,c,d;
	cin >> n >> a;
	if(a<0)a=a*-1;
	b=a;c=a;
	for (int i=1;i<n;i++){
		cin >> d;
	if(d<0)d=d*-1;
	if(d>b)b=d;
	if(d<c)c=d;}
	cout << b-c <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	int AB = C * 2;
	int ans = 0;
	while (X > 0 || Y > 0)
	{
		if ((X > 0 && Y > 0) && AB < A+B)
		{
			ans += AB;
			X--;
			Y--;
		}
		else if (X > 0 && Y > 0)
		{
			ans += min(A, AB);
			ans += min(B, AB);
			X--;
			Y--;
		}
		else if (X > 0)
		{
			ans += min(A, AB);
			X--;
		}
		else
		{
			ans += min(B, AB);
			Y--;
		}
	}
	cout << ans << endl;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

int bs_upper_bound(int a[], int n, int x) {
    int l = 0;
    int h = n; // Not n - 1
    while (l < h) {
        int mid =  l + (h - l) / 2;
        if (x >= a[mid]) {
            l = mid + 1;
        } else {
            h = mid;
        }
    }
    return l;
}

int bs_lower_bound(int a[], int n, int x) {
    int l = 0;
    int h = n; // Not n - 1
    while (l < h) {
        int mid =  l + (h - l) / 2;
        if (x <= a[mid]) {
            h = mid;
        } else {
            l = mid + 1;
        }
    }
    return l;
}

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

ll mod=1e9+7;

int main()
{
    IOS;
    int n;
    cin>>n;
    int a[n][n];
    map<int,vector<int>> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
            if(a[i][j]==1){
                m[i].push_back(j);
            }
        }
    }
    ll mask=1LL<<n;
    ll dp[mask];
    for(int j=0;j<mask;j++)
        dp[j]=0;
    dp[0]=1;
    for(int j=0;j<mask;j++){
        int i=__builtin_popcount(j);
        for(int x=0;x<m[i].size();x++){
            int k=m[i][x];
            if((j&(1<<k))==0){
                dp[j|(1<<k)]=(dp[j|(1<<k)]+dp[j])%mod;
            }
        }
    }
    cout<<dp[mask-1];
}


Measured memory_bytes: 20040
from collections import deque

n = int(input())
a = list(map(int, input().split()))
if 1 in a:
    d = deque(a)
    count = 0
    num = 1
    pick = 0
    while d:
        pick = d.popleft()
        count += 1
        if pick == num:
            count -= 1
            num += 1

    print(count)
else:
    print(-1)


Measured memory_bytes: 26772
N = input()
A = list(map(int, input().split(' ')))
finish = False
can = 0
A_len = len(A)

while not finish:
    for num, soe in zip(A, range(A_len)):
        if num % 2 == 0:
            A[soe] = num / 2
        else:
            finish = True
    if finish:
        break
    can += 1

print(can)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dp[100005];
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i >= 1) {
            dp[i] = min(dp[i],dp[i-1]+abs(A[i-1]-A[i]));
        }
        if(i >= 2) {
            dp[i] = min(dp[i],dp[i-2]+abs(A[i-2]-A[i]));
        }
    }
    cout << dp[N-1] << endl;
}



Measured memory_bytes: 4828
MOD = 10**9 + 7


def main():
    L = input()
    N = len(L)
    dp = [[0]*2 for i in range(N+1)]
    dp[0][0] = 1

    for i in range(N):
        # smaller: 1 -> 1
        if L[i] == "1":
            dp[i+1][1] += dp[i][1] * 3
            dp[i+1][1] %= MOD
        else:
            dp[i+1][1] += dp[i][1] * 3
            dp[i+1][1] %= MOD
        # smaller: 0 -> 1
        if L[i] == "1":
            dp[i+1][1] += dp[i][0] * 1
            dp[i+1][1] %= MOD
        # smaller: 0 -> 0
        if L[i] == "1":
            dp[i+1][0] += dp[i][0] * 2
            dp[i+1][0] %= MOD
        else:
            dp[i+1][0] += dp[i][0] * 1
            dp[i+1][0] %= MOD

    print((dp[N][0]+dp[N][1]) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 54236
import sys
def f(c):
 if sum(c)in c:return 1
 if 5 in c or sum(c)==2:return 0
 if 4 in c:
     k=c.index(4);c[k]-=3
     if f(c):return 1
     c[k]+=3
 if 3 in c:
     k=c.index(3);c[k]-=3
     if f(c):return 1
     c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
      c[i]-=1;c[i+1]-=1;c[i+2]-=1
      if f(c):return 1
      c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 e=list(e)
 a=[i for i in n if f([(e+[i]).count(j)for j in n])]
 if a:print(*a)
 else:print(0)


Measured memory_bytes: 5584
local mmi, mma = math.min, math.max
local n, x = io.read("*n", "*n")
local a = {}
local t = {}
for i = 1, n do
  a[i] = io.read("*n")
  t[i] = {a[i]}
end
for i = 1, n do
  for j = 1, n - 1 do
    local use = i - j
    if use <= 0 then use = use + n end
    t[i][j + 1] = mmi(t[i][j], a[use])
  end
end
local ret = 0
for i = 1, n do
  ret = ret + t[i][1]
end
for j = 2, n do
  local v = 0
  for i = 1, n do
    v = v + t[i][j]
  end
  ret = mmi(ret, x * (j - 1) + v)
end
print(ret)


Measured memory_bytes: 64504
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define crap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mx5 100005
#define MOD 1000000007

int main() {
	crap;
	ll h,w;
	cin >> h >> w;
	char val;
	ll dp[h][w];
	for( int i=0; i<h; i++ ){
	    for( int j=0; j<w; j++ ){
	        cin >> val;
	        if( val == '#')
	            dp[i][j] = -1;
	        else
	            dp[i][j] = 0;
	    }
	}
	dp[0][0] = 1;
	for( int i=0; i<h; i++ ){
	    for( int j=0; j<w; j++ ){
	        if( dp[i][j] == -1  ){
				continue;
			}
			if( dp[i][j-1]!= -1 && j!=0){
				dp[i][j] = dp[i][j-1]%MOD;
			}
			if( dp[i-1][j] != -1 && i!=0 ){
				dp[i][j] = (dp[i][j]+dp[i-1][j])%MOD;
			}
			else{
				continue;
			}
	    }
	}
 	cout << dp[h-1][w-1];

	
	return 0;
}

Measured memory_bytes: 11280
#include <stdio.h>

int main(void){


int n, i;
		int array[1000];
		double sum = 0;
		double average;

		while (1) {

			scanf("%d", &n);
			sum = 0;
			average = 0;

			if (n == 0)break;

			for (i = 1; i <= n; i++) {
				scanf("%d", &array[i]);
				sum += array[i];
			}
			average = sum / n;
			double a = 0;

			for (i = 1; i <= n; i++) {
				a += pow(array[i] - average, 2);

			}
			printf("%.8lf\n", pow(a / n, 0.5));

		}

return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

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 (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<ll> a(N); rep(i,N) std::cin >> a[i];

  ll ans = 0;
  ll s = 0, x = 0, r = 0;
  for (int l = 0; l < N; l++) {
    while ( r < N && ( (s+a[r]) == (x^a[r]) ) ) {
      s += a[r];
      x ^= a[r];
      r++;
    }
    ans += (r-l);

    if (l == r) { r++; }
    else {
      s -= a[l];
      x ^= a[l];
    }
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
     
    public class Main {
     
    	public static void main(String[] args) {
    		// TODO 自動生成されたメソッド・スタブ
    		Scanner scan = new Scanner(System.in);
    		
    		int n = scan.nextInt();
    		int m = scan.nextInt();
    		if( n == m) {
    			System.out.print("Yes");
    		}
    		else {
    			System.out.print("No");
    		}
    		
    		
    	}
     
    }

Measured memory_bytes: 35656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		if(r<=x && x<=w-r && r<=y && y<=h-r){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		sc.close();

	}

}

Measured memory_bytes: 26244
#include <stdio.h>

int main()
{
	char S[4];
	int J = 0;

	scanf("%s", &S);

	for (int i = 0; i < 3; ++i) {
		if (S[i] == S[i+1]) {
			J = 1;
			break;
		}
	}
	if (J == 1) printf("Bad");
	else printf("Good");	
}

	


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int a[2];

int main()
{
	cin>>a[0]>>a[1];
	sort(a,a+2);
	for(int i=1;;i++)
		if(not binary_search(a,a+2,i))
			return 0 * printf("%d",i);
}

Measured memory_bytes: 256
N = int(input())
m = 10**9 + 7

a, b = 10, 9
for i in range(N - 1):
    a = (a * 10) % m
    b = (b * 9) % m

A = B = (a - b) % m


a, b = 10, 8
for i in range(N - 1):
    a = (a * 10) % m
    b = (b * 8) % m

C = (a - b) % m

print((A + B - C) % m)


Measured memory_bytes: 9208
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a=n/100,b=n%100,c=0,d=0;
  if (a!=0&&a<13) c++;
  if (b!=0&&b<13)d++;
  if(c+d==2)cout<<"AMBIGUOUS"<<endl;
  else if(c+d==1){
    if(c==1)cout<<"MMYY"<<endl;
    else cout<<"YYMM"<<endl;
  }
  else cout<<"NA"<<endl;
}


Measured memory_bytes: 256
D,N = map(int,input().split())
ans = 1
if N != 100:
    if D == 0:
        print(ans * N)
    elif D == 1:
        print(ans * N * 100)
    else:
        print(ans * N * 10000)

elif N == 100:
    if D == 0:
        print(ans * N +1)
    elif D == 1:
        print(ans * N * 100 +100)
    else:
        print(ans * N * 10000 +10000)

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

using namespace std;

int sum_digits(int n)
{
	if (n == 0) {
		return 0;
	}
	return (n % 10) + sum_digits(n / 10);
}

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

	int ans = 1 << 30;
	for (int A = 1; N - A >= 1; ++A) {
		int B = N - A;
		ans = min(ans, sum_digits(A) + sum_digits(B));
	}
	cout << ans << endl;
}


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

int main(){
    int t1, t2 = 0, t, n, i, s = 0;
    cin >> n >> t;
    for(i=0; i<n; i++){
        cin >> t1;
        s += min(t, t1-t2);
        t2 = t1;
    }
    s += t;
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            if len(datasets[dataset][rgb_key]) > 1:
                nums = sorted(datasets[dataset][rgb_key])
            else:
                continue

            for hand in WINNING_HANDS:
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                if match_count == 3:
                    results.append(1)
                    break

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7764
#include <iostream>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
  int N;
  cin >> N;
  string ans = "No";
  if(N % 10 == 7){
    ans = "Yes";
  }
  else{
    N = N / 10;
    if(N % 10 == 7){
      ans = "Yes";
    }
    else{
      N = N / 10;
      if(N == 7){
        ans = "Yes";
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  sort(begin(p),end(p));
  cout << accumulate(begin(p),begin(p)+K,0) << endl;
}


Measured memory_bytes: 3556
import collections
import copy
s = int(input())
same = 0
List = []
List.append(s)
while same == 0:
    if s % 2 == 0:
        s = s / 2
        List.append(s)
        unique = set(copy.copy(List))
        _List = collections.Counter(List)
        for v in unique:
            if _List[v] == 2:
                same += 1
    else :
        s = 3 * s + 1
        List.append(s)
        _List = collections.Counter(List)
        unique = set(copy.copy(List))
        for v in unique:
            if _List[v] == 2:
                same += 1
print(len(List))

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int graph[9][9]={0};
    for(int i=0; i<M; ++i){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a][b]++; graph[b][a]++;
    }
    vector<int> v;
    for(int i=0; i<N; ++i) v.push_back(i);
    
    int res=0;
    
    do{
        bool ok = true;
        for(int i=0; i<N-1; ++i){
            if(v[0]!=0){
                ok = false;
                break;
            }
            if(graph[v[i]][v[i+1]]==0) ok = false;
        }
        if(ok) res++;
    }while(next_permutation(v.begin(), v.end()) );
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
n,m=map(int,input().split())
x=[int(i) for i in input().split()]
v=[[] for i in range(m)]
for i in x:v[i%m].append(i)
a=0
for i in range(1,m//2+1*(m%2==1)):
  x,y=v[i],v[m-i]
  d=len(x)-len(y)
  if d<0:
    d=-d
    x,y=y,x
  c=sorted(Counter(x).items(),key=lambda x:x[1])
  p=0
  for t in c:
    p+=(t[1]//2)
  a+=len(y)+min(p,(d//2))
a+=len(v[0])//2+(len(v[m//2])//2 if m%2==0 else 0)
print(a)

Measured memory_bytes: 81388
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int lli;

int main() {
    int a;
    cin >> a;
    int temp;
    temp = a + a * a + a * a * a;
    cout << temp << endl;
    return 0;
}

Measured memory_bytes: 3592
def base_changer(number,base):
    buff=97+abs(base-10)
    dic={};buff2='';buff3=10
    for i in range(97,buff+1):
        dic[buff3]=chr(i)
        buff3+=1   
    while(number>=base):
        mod=int(number%base)
        number=int(number//base)
        if (mod) in dic.keys():
            buff2+=dic[mod]
            continue
        buff2+=str(mod)
    if (number) in dic.keys():
        buff2+=dic[number]
    else:
        buff2+=str(number)

    return buff2[::-1]  
N,K = map(int, input().split())
print(len(base_changer(N,K)))



Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int h, w;

int main() {

	cin >> h >> w;

	vector<vector<char>> tb(h, vector<char>(w));

	int cntw = 0;
	queue<pair<int,int>> que;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> tb[i][j];
			if (tb[i][j] == '.') {
				cntw++;
			}
			else {
				que.push({i,j});
			}
		}
	}

	int ans = 0;
	while (cntw != 0) {
		ans++;
		queue<pair<int, int>> next;
		while (!que.empty()) {
			auto p = que.front(); que.pop();
			int dy[] = { -1,0,1,0 }; int dx[] = { 0,1,0,-1 };
			for (int d = 0; d < 4; d++) {
				int ny = p.first + dy[d]; int nx = p.second + dx[d];
				if (ny < 0 || nx < 0 || ny >= h || nx >= w)continue;
				if (tb[ny][nx] == '.') {
					tb[ny][nx] = '#';
					next.push({ ny,nx });
					cntw--;
				}
			}
		}
		que = next;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9600
N, M = map(int, input().split())
nums = list(map(int, input().split()))
ids = [0] * (N+1)
for i, n in enumerate(nums):
  ids[n] = i+1

class UnionFind():
  
  def __init__(self, n):
    self.par = list(range(n+1))
    self.rank = [0] * (n+1)

  def root(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.root(self.par[x])
      return self.par[x]

  def unite(self, x, y):
    xr = self.root(x)
    yr = self.root(y)
    if xr == yr:
      return
    if self.rank[xr] < self.rank[y]:
      self.par[xr] = yr
    else:
      self.par[yr] = xr
      if self.rank[xr] == self.rank[y]:
        self.rank[xr] += 1

  def same(self, x, y):
    return self.root(x) == self.root(y)

i_tree = UnionFind(N)
  
for _ in range(M):
  x, y = map(int, input().split())
  i_tree.unite(x, y)
cnt = 0
for i in range(1, N+1):
  if i_tree.same(i, ids[i]):
    cnt += 1
print(cnt)

Measured memory_bytes: 16228
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

K=gets.to_i
S=get_nsp
N=S.size
if N<=K
    puts S.join("")
else
    puts S[0..K-1].join("")+"..."
end

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

using namespace std;

int main()
{
	int n;
	cin>>n;
	if(n==25){
		cout<<"Christmas";
	} 
	else if(n==24){
		cout<<"Christmas Eve";
	}else if(n==23){
		cout<<"Christmas Eve Eve";
	}else{
		cout<<"Christmas Eve Eve Eve";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define INF 1e9
#define pb push_back
using namespace std;
typedef long long ll;
using pii = pair<ll, ll>;

int main() {
    string s;
    cin >> s;
    int n;
    n = s.size();
    cout << s[0] + to_string(n-2) +s[n-1];
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n;
  cin >> n;
  for(int j=1;j<=9;j++){
    if(n%j==0){
      int i = n/j;
      if(1<=i&&i<=9){
      	cout << "Yes" << endl;
      	return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3684
import math

N = int(input())
a = list(map(int, input().split()))

prod = a[0]
lcm = a[0]
for i in range(1,N):
    x = math.gcd(lcm, a[i])
    lcm = (lcm*a[i])//x

m = lcm-1
ans = 0
for i in a:
    ans += m%i
print(ans)


Measured memory_bytes: 9388
/**
*   author:  akifpathan
*   created: Sunday 13.09.2020 03:47:09 PM
**/

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());	

void solve()
{
	int n,m;
	cin>>n>>m;
	
	priority_queue<int>pq;
	
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		
		pq.push(x);
	}
	
	while(m--)
	{
		int u=pq.top();
		pq.pop();
		
		u/=2;
		pq.push(u);
	}
	
	ll ans=0;
	
	while(!pq.empty())
	{
		ans+=pq.top();
		pq.pop();
	}
	
	cout<<ans;
}		

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}



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

int main()
{
    std::string deq;
    std::cin >> deq;
    bool res = true;
    int cnt = 0;
    auto l_itr = deq.begin(), r_itr = (deq.end() - 1);

    while(l_itr - deq.begin() < r_itr - deq.begin()){
        if(*l_itr == *r_itr){
            l_itr++;
            r_itr--;
        }else if(*l_itr == 'x'){
            l_itr++;
            cnt++;
        }else if(*r_itr == 'x'){
            r_itr--;
            cnt++;
        }else{
            res = false;
            break;
        }
    }
    std::cout << (res ? cnt : -1) << std::endl;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
	NodePointer i;
	for(i = nil;i->next!=nil;i=i->next){
		
		if(i->next->key==key){return i->next;}
		
	}
	return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
	t->next->prev = t->prev;
	t->prev->next = t->next;
	free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
	NodePointer i;
	i = nil->prev;
	deleteNode(i);
}

void delete(int key){
  /* your code */
	NodePointer i;
 	 i=listSearch(key);
	if(i!=NULL)deleteNode(i);
	
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
	x->next = nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;
    vector<int> a;
    if (s[0] == '0') {
        a.push_back(0);  
    }
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        ++cnt;
        if (i < n - 1 && s[i] != s[i + 1]) {
            a.push_back(cnt);
            cnt = 0;            
        }
    }
    if (cnt) {
        a.push_back(cnt);  
    }
    //cout << "division: " << endl;
    /*for (int i = 0; i < a.size(); ++i) {
        cout << a[i] << ' ';
    }
    cout << endl;*/
    vector<int> suma(a.size() + 1, 0);
    for (int i = 1; i <= a.size(); ++i) {
        suma[i] = suma[i - 1] + a[i - 1];  
    }
      
    int ans = 0;
    for (int i = 0; i < a.size(); i += 2) {
        int r = i + 2 * k;        
        int cursum;
        if (r >= a.size()) {
            r = a.size() - 1;  
        }
        ans = max(ans, suma[r + 1] - suma[i]);
        //cout << "sum of interval [" << i << ", "<< r << "] -> " << suma[r + 1] - suma[i] << endl;
    }
    //cout << "ans = ";
    cout << ans;
    return 0;
}


Measured memory_bytes: 1272
def A():
    a = int(input())
    s = str(input())
    if a<3200:
        print('red')
    else:
        print(s)

def B():
    n = int(input())
    a = input().split()
    s = 0
    for i in range(n):
        s += (1/int(a[i]))
    print(1/s)

B()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
struct Vec{
    double x, y;
};
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;
}

using namespace std;
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(c - (a - b), 0) << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;long long sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0&&i%5==0)
        {
            continue;
        }
        if(i%3==0)
        {
            continue;
        }
        if(i%5==0)
        {
            continue;
        }
        sum+=i;
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

typedef long long ll;

#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789

using namespace std;
 

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

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

int MAX;
int N;

int d[260];
bool flag[260];
bool ans[260];
vector< int >r[260];
int idx;
int ch;
int jdg;
queue< int >q;


int main(){
	
	while( cin>>MAX, MAX ){
		cin>>N;
		
		jdg = 1;
		fill( ans, ans+260, 1 );
		fill( d, d+260, 0 );
		fill( flag, flag+260, 1 );
		REP(i, 260) r[i].clear();
		
		REP(i, N) scanf("%d", d+i+1);
		q.push(0);
		flag[0] = 0;
		flag[N+1] = 0;	
		
		while( !q.empty() ){
			idx = q.front();
			q.pop();
			FOR(i, 1, MAX+1){
				ch = idx+i;
				if( ch > N ) ch = N+1;
				ch += d[ch];
				if( ch > N ) ch = N+1;
				if( ch < 0 ) ch = 0;
				r[ch].push_back(idx);
				if( flag[ch] ){
					q.push(ch);
					flag[ch] = 0;
				}
			}
		}
		
		q.push(N+1);
		ans[N+1] = 0;
		while( !q.empty() ){
			ch = q.front();
			q.pop();
			REP(i, r[ch].size() ){
				idx = r[ch][i];
				if( ans[idx] ){
					ans[idx] = 0;
					q.push(idx);
				}
				
			}
		}
		
		REP( i, N+2 ){
			if( ans[i] && !flag[i] ) jdg = 0;
			//printf("%d-%d ", ans[i], flag[i]);
		}
		
		if( jdg ) puts("OK");
		else{     puts("NG");}
		
	}
	
	return 0;

}

Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long LL;
int main() {
    LL n; cin >> n;
    string s = to_string(n);
    LL ret = (s.size()-1) * 9;
    LL cur = 0;
    n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') continue;
        ret = max(ret, cur+s[i]-'0'-1 + (n-i-1)*9);
        cur += s[i] - '0';
    }
    ret = max(ret, cur);
    cout << ret << endl;


    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $n, $m);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));

$M = [2, 5, 5, 4, 5, 6, 3, 7, 6, ];
$RM = [
    2 => [1],
    3 => [7],
    4 => [4],
    5 => [2, 3, 5],
    6 => [6, 9],
    7 => [8],
];

// プラスするマッチの本数の配列
$AM = [];
foreach ($A as $v) {
    $AM[] = $M[$v - 1];
}
sort($AM);
$AM = array_unique($AM);
// マッチの本数から数字を逆算する配列
$ARM = [];
foreach ($AM as $v) {
        $ARM[$v] = max(array_intersect($RM[$v], $A));
}

const N_MAX = 10005;
$dp = array_fill(0, N_MAX, '');
// 初期化
foreach ($AM as $v) {
    $dp[$v] = $ARM[$v];
}
for ($i = 0; $i < N_MAX; ++$i) {
    foreach ($AM as $v) {
        if ($i - $v >= 0 && $dp[$i - $v] !== '') {
            chmax($dp[$i], $dp[$i - $v], $ARM[$v]);
        }
    }
}

function chmax(&$a, $b, $c) {
    if (strlen($a) > strlen($b) + 1) {
        // 何もしない
    } else if (strlen($a) === strlen($b) + 1) {
        // 比較して大きい方にする
        if ($a < ($b . $c)) $a = $b . $c;
    } else {
        // b + $cで置き換え
        $a = $b . $c;
    }
}

/* echo implode(', ', $dp), PHP_EOL; */

echo $dp[$n];


Measured memory_bytes: 37496
#include<stdio.h>

int main(void)
{
   int n, i;
   char s[101], t[101], v[201];

   scanf("%d%s%s",&n,s,t);

   for(i=0;i<n;i++){
      v[i*2]=s[i];
      v[i*2+1]=t[i];
   }
   v[n*2]='\0';

   printf("%s\n",v);
   return 0;
}

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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
    ll N;
    cin>>N;
    vector<P> v(N);
    rep(i,N) {
        ll x,y;
        cin>>x>>y;
        v[i].first = x-y;
        v[i].second = x + y;
    }
    ll Xmin = INF,Xmax = -INF,Ymin = INF,Ymax = -INF;
    rep(i,N){
        chmin(Xmin,v[i].first);
        chmin(Ymin,v[i].second);
        chmax(Xmax,v[i].first);
        chmax(Ymax,v[i].second);
    }
    cout<<max(Xmax-Xmin,Ymax-Ymin)<<endl;
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll int, ll int>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define debug4(n, m, x, y) cout << "DEBUG4 " << n << ' ' << m << ' ' << x << ' ' << y << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) if (n < 0) n = 0
#define alive(n) cout << "Alive here: checkpoint " << n << endl
#pragma GCC optimize("Ofast")
using namespace std;
void yes() {
	cout << "YES\n";
	return;
}
void no() {
	cout << "NO\n";
	return;
}
void init() {
	// initialize
	
}
void solve(int case_no) {
    // implementation
    // input using array
    int n;
    cin >> n;
    // There is a way without array
    int cnt = 0;
    for (int i = 0;i < n;i++) {
    	int a, b;
    	cin >> a >> b;
    	if (a == b) {
    		cnt++;
    		if (cnt == 3) {
    			cout << "Yes\n";
    			return;
			}
		} else {
			cnt = 0;
		}
	}
	cout << "No\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(NULL));
    init();
    int t = 1;
//    cin >> t;
    for (int i = 1;i <= t;i++) solve(i);
}
/*

*/

Measured memory_bytes: 3572
// Print Test Cases
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B
//
// Accepted

use std::io::{BufRead, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    for i in 1.. {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        
        let x: i32 = buf.trim().parse().unwrap();
        
        if x == 0 {
            break;
        }
        
        println!("Case {}: {}", i, x);
    }
}


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

int main(){
 int N;
 cin>>N;
 
 vector<int>d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
 
  int i=0,j=100,k=0;
  while(j>0){
    
   while(i<N){
     if(d.at(i)==j){
       k++;
       break;
     }
     else{
       i++;
     }
   }
    i=0;
    j--;
  }
  cout<<k<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
long int pow107 = (int)pow(10, 9) + 7;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}


int main(){
    long int a,b,c;
    cin >> a >> b >> c;
    cout << (b-a == c-b ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main()
{
	//clock_t start, end;
	//start = clock();

	while (true) {
		int n, x, ans = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		for (int a = 1; a <= n; a++) {
			for (int b = a + 1; b <= n; b++) {
				for (int c = b + 1; c <= n; c++) {
					if (a + b + c == x) ans++;
				}
			}
		}
		cout << ans << endl;
	}

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



Measured memory_bytes: 3084
import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	}
}

Measured memory_bytes: 59476
func main() {
let s = readLine()!.split(separator: " ").map{ Int($0)! }
let h = s[0]
let w = s[1]
let k = s[2]

var map = Array(repeating: Array(repeating: false, count: w), count: h)

for i in 0..<h {
	let sts = readLine()!
	var m = 0
	for st in sts {
		if st == "#" {
			map[i][m] = true
		}
		m += 1
	}
}

let maxrow = pow(2, h)
let maxcol = pow(2, w)
var c = 0
for ri in 0..<maxrow {
	let rtf = gentf(ri, h)
	for ci in 0..<maxcol {
		let ctf = gentf(ci, w)
		var cou = 0
		for ai in 0..<h {
			for bi in 0..<w {
				if map[ai][bi] == true && rtf[ai] && ctf[bi] {
					cou += 1
				}
			}
		}
		if cou == k { c += 1 }
	}
}
print(c)
}

main()
func pow(_ source: Int, _ count: Int) -> Int {
	var n = 1
	for _ in 0..<count {
		n *= source
	}
	return n
}
func gentf(_ n: Int, _ len: Int) -> [Bool] {
	let bin = String(n, radix: 2)
	var tf = Array(repeating: false, count: len)
	var i = len - bin.count
	for b in bin {
		if b == "1" { tf[i] = true }
		i += 1
	}
	return tf
}


Measured memory_bytes: 8264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> cnt(N);
	REP(i, K) {
		int d;
		cin >> d;
		REP(j, d) {
			int a;
			cin >> a; --a;
			cnt[a]++;
		}
	}
	int ans = 0;
	REP(i, N) ans += cnt[i] == 0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(){
    int a,b,c,k;
    scanf("%d%d%d%d", &a,&b,&c,&k);

    int ans;
    if( k <= a ) ans = k;
    if( a < k && k <= a+b ) ans = a;
    if( a+b < k ) ans = a-(k-(a+b));

    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 1724
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    
	  Scanner sc = new Scanner(System.in);
	  
	  int a = sc.nextInt();
	  int b = sc.nextInt();
	  int c = sc.nextInt();
	  int sum = 0;
	  for(int i = a; i <= b; i++) {
		  if(c % i == 0){
			  sum++;
			  //System.out.println(i);
		  }
		  
	  }
	  System.out.println(sum);
  }
}

Measured memory_bytes: 26352
#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>

#define all(x) x.begin(),x.end()
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define pr(x) printf("%d",x)
#define prl(x) printf("%lld",x)
#define LL long long
#define pb push_back
#define PB pop_back
#define PF pop_front
#define F first
#define S second
#define inrow(vec)    for(int i=0;i<vec.size();i++)cout<<vec[i]<<" ";
#define incoloum(vec) for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;

const double PI=3.1415926;
const int KL=1e6;

using namespace std;

LL q,x,y,z,n,m,p[KL],mn=1e9,mx=-1e9,ans;
string t;
vector <int> vec;
set <int> s;
map <int,int> M;

int main()
{
    char t;
    cin>>t;
    t++;
    cout<<t;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> unsafe(n+1,0);
    for(ll i=0;i<m;i++){
        ll a;
        cin>>a;
        unsafe[a]++;
    }
    vector<ll> dp(n+1,0);    
    dp[0]=1;
    
    if(unsafe[1]<1){
        dp[1]=1;
    }else{
        dp[1]=0;
    }
    
    for(ll i=2;i<n+1;i++){        
        if(unsafe[i-1]<1){
            dp[i]+=dp[i-1];
        }
        if(unsafe[i-2]<1){
            dp[i]+=dp[i-2];
        }
        dp[i]%=1000000007;
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 4792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <cstdio>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int n;
const int MAX_N = 100001;
const int MAX_A = 10;
double dp[MAX_N + 1][MAX_A + 1] = {0};//日にち、連続
double ans[MAX_N] = {0};

int main(void)
{
	dp[0][0] = 1;
	double sum = 0;
	for (int i = 0; i < MAX_N; i++)
	{
		for (int j = 0; j < MAX_A; j++)
		{
			if(!dp[i][j]) continue;
			sum += dp[i][j] * 1.0 / (1 << j);//??

			dp[i+1][j+1] = dp[i][j] * 1.0 / (1 << j);
			dp[i+1][0] += dp[i][j] * (1.0 - 1.0 / (1 << j));
		}
		ans[i] = sum;
	}
	while(cin >> n && n)
	{
		printf("%.8f\n", ans[n-1]);
	}
	return 0;
}

Measured memory_bytes: 10568