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

vector<ll> lucas(100, -1);

ll luca(ll num) {
  if (num == 0) {
    return lucas[0] = 2;
  }

  if (num == 1) {
    return lucas[1] = 1;
  }

  if (lucas[num] != -1) {
    return lucas[num];
  }

  return lucas[num] = luca(num - 1) + luca(num - 2);
}

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

  int n;
  cin >> n;

  cout << luca(n) << endl;

  return 0;
}

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

using namespace std;
typedef long long ll;

const int N=2e5+100;
typedef pair<int,int>pa;
map<pa,int>mp;
ll ans[10];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    string s;
    cin>>s;
    int win=0,lose=0;
    int g=0,p=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='g'){
            if(p<g) p++,win++;
            else g++;
        }
        else {
            if(p<g) p++;
            else g++,lose++;
        }
    }
    cout<<win-lose<<endl;
    return 0;
}


Measured memory_bytes: 3788
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int n,k;
bool ok[10];
int main(void){
	scanf("%d%d",&n,&k);
	memset(ok,false,sizeof(ok));
	for(int i=0;i<k;i++){
		int a;
		scanf("%d",&a);
		ok[a]=true;
	}
	while(1){
		int g=n;
		while(g>0){
			if(ok[g%10])break;
			g/=10;
		}
		if(g==0){
			printf("%d\n",n);
			break;
		}
		n++;
	}
	return 0;
}

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

int main()
{
    int r, D, x;
    cin >> r >> D >> x;

    rep(i, 10) {
        x = r * x - D;
        cout << x << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int a, b;
    cin >> a >> b;

    cout << max(0LL, a - b * 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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





// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);

    int cntAC=0;int cntWA=0;int cntTLE=0;int cntRE=0;

    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
        if(S[i]=="AC"){
            cntAC++;
        }else if(S[i]=="WA"){
            cntWA++;
        }else if(S[i]=="TLE"){
            cntTLE++;
        }else if(S[i]=="RE"){
            cntRE++;
        }
    }
    cout<<"AC x "<<cntAC<<endl;
    cout<<"WA x "<<cntWA<<endl;
    cout<<"TLE x "<<cntTLE<<endl;
    cout<<"RE x "<<cntRE<<endl;;
    return 0;
}


Measured memory_bytes: 6328
#include <iostream>
#include <algorithm>
 
using namespace std;
 
main(){
  int n, m, p, sum, input[100];
  while(cin >> n >> m >> p && (n|m|p)){
    sum = 0;
    for(int i=0;i<n;i++){
      cin >> input[i];
      sum += input[i] * 100;
    }
    int ans = sum *(100-p) / 100;
    if(input[m-1]) ans /= input[m-1];
    else ans = 0;
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3052
# coding: utf-8
# Your code here!
a,b,c = map(int,input().split())

aa = [a,b,c]
aa = sorted(aa)

for i in range(len(aa)):
    if i == 0:
        p=0
    else:
        p=aa[i]-aa[i-1]+p
        #print(p)
print(p)    

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

using namespace std;

int g[200000];
int i,n,r,t;

int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
		scanf("%d",&g[i]);
	sort(g+1,g+n+1);
	for (i=1;i<=n;i++)
		if (min(g[i],g[n]-g[i])>t)
			t=min(g[i],g[n]-g[i]),r=g[i];
	printf("%d %d\n",g[n],r);
	return 0;
}

Measured memory_bytes: 512
n = int(input())
a = [int(i) for i in input().split()]

j_Aj = [0]

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
maxj=max(j_Aj)
i_Ai = [0] * (maxj+1)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=maxj:
        i_Ai[j + a[j - 1]] += 1
print(ans)

Measured memory_bytes: 106444
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
def f(x):
  return -(-x // 10) * 10
def g(x):
  return (x-1) % 10 + 1
ans = sum(f(i) for i in [a,b,c,d,e])
mi = min(g(i) for i in [a,b,c,d,e])
ans += mi - 10
print(ans)

Measured memory_bytes: 3064
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

/**
 * Euclidの互除法による最大公約数算出.
 *
 * 計算量: `O(log min(a, b))`
 */
tailrec fun gcd(a: Int, b: Int): Int {
  if (a == 0) return b
  var x = a
  var y = b
  if (y < x) {
    x = b
    y = a
  }
  return gcd(y % x, x)
}

/**
 * Eratosthenesの篩による素数列挙.
 *
 * 計算量：`O(n log log n)`
 */
fun sieve(n: Int): Collection<Int> {
  val primes = (2..n).toSortedSet()
  for (i in 2..sqrt(n.toDouble()).toInt()) {
    if (i !in primes) continue
    ((i + i)..n step i).forEach { primes.remove(it) }
  }
  return primes
}

fun main() {
  val n = readI()
  val aa = readIs()
  run {
    val at = BooleanArray(1_000_001)
    var maxa = 0
    aa.forEach {
      if (it != 1 && at[it]) return@run
      maxa = max(maxa, it)
      at[it] = true
    }
    val pr = sieve(maxa)
    for (p in pr) {
      var t = 0
      for (q in p..maxa step p) {
        if (at[q]) {
          t++
          if (t == 2) return@run
        }
      }
    }
    println("pairwise coprime")
    return
  }
  var t = gcd(aa[0], aa[1])
  for (i in 2 until n) {
    t = gcd(t, aa[i])
  }
  println(if (t == 1) "setwise coprime" else "not coprime")
}


Measured memory_bytes: 190648
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {
	static HashMap<String,Boolean> map;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String in = sc.nextLine();
			String[] a = in.split(" ");
			int n = Integer.parseInt(a[0]);
			int m = Integer.parseInt(a[1]);
			int[] C = new int[n];
			int[] V = new int[n];
			int[] D = new int[n];
			int[] L = new int[n];
			for(int i = 0; i < n; i++) {
				in = sc.nextLine();
				in = sc.nextLine();
				a = in.split(" ");
				C[i] = Integer.parseInt(a[0]);
				V[i] = Integer.parseInt(a[1]);
				D[i] = Integer.parseInt(a[2]);
				L[i] = Integer.parseInt(a[3]);
			}
			int MAX = 0;
			int[][] dp = new int[m+1][3];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j <= m; j++) {
					for(int k = 1; ; k++) {
						int tmp = j + C[i] * k;
						if(tmp > m) break;
						dp[tmp][0] = Math.max(dp[tmp][0], dp[j][0] + V[i] * k);
						dp[tmp][1] = Math.max(dp[tmp][1], dp[j][1] + D[i] * k);
						dp[tmp][2] = Math.max(dp[tmp][2], dp[j][2] + L[i] * k);
					}
				}
			}
			for(int i = 0; i <= m; i++) {
				MAX = Math.max(dp[i][0], MAX);
				MAX = Math.max(dp[i][1], MAX);
				MAX = Math.max(dp[i][2], MAX);
			}
			System.out.println(MAX);
			
			
			
			
		}
		
	}
 }

Measured memory_bytes: 180068
#include <stdio.h>
#define abs(a) ((a)<0 ? -(a) : (a))

int a = 0, b = 0, count = 0;
int ansa, ansb;

void dfs(int num, int n, int flag){
  if(flag == ((1<<n) - 1)){
    ++count;
    if(num == a){
      ansa = count;
    }
    if(num == b){
      ansb = count;
    }
    return;
  }
  for(int i=1; i<=n; i++){
    if(flag & (1<<(i-1)))  continue;
    num = num * 10 + i;
    dfs(num, n, (flag | (1<<(i-1))));
    num = num / 10;
  }
}

int main(){
  int n;  scanf("%d", &n);
  //  printf("%d\n", ((1<<n) -1));return 0;
  int t;
  for(int i=0; i<n; i++){
    scanf("%d", &t);
    a = a * 10 + t;
  }
  for(int i=0; i<n; i++){
    scanf("%d", &t);
    b = b * 10 + t;
  }
  dfs(0, n, 0);
  printf("%d\n", abs(ansb - ansa));
  return 0;
}


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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...) 
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<array<int, 3>> a(n);
    for (auto& it : a)
        cin >> it[0] >> it[1] >> it[2];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            int curr = a[i][j];
            a[i][j] = 0;
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    a[i][j] = max(a[i][j], a[i - 1][k] + curr);
                }
            }
        }
    }
    cout << *max_element(a[n - 1].begin(), a[n - 1].end());
    return 0;
}

Measured memory_bytes: 4520
N, K = map(int, input().split())
S = list(map(int, input()))
 
Z = [j for j, s in enumerate(S) if (j > 0 and s == 0 and S[j] != S[j-1]) or (j == 0 and s == 0)] + [N]
Y = [j for j, s in enumerate(S) if (j > 0 and s == 1 and S[j] != S[j-1]) or (j == 0 and s == 1)]
result = 0
if len(Z) <= K:
    print(N)
else:
    for i in range(len(Z)-K):
        if i == 0:
            result = Z[i+K]
        else:
            result = max(result, Z[i+K] - Y[i if Y[0] < Z[0] else i-1])
    print(result)

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

int main() {
	int X;
	cin >> X;
  for(int i = X;i<=X+10000;i++){
		bool flag = true;
		for(int tmp=2;tmp*tmp<=i;tmp++){
			if(i%tmp == 0) flag = false;
		}
		if(flag){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#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 <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;
// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



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

Measured memory_bytes: 256
a,b,c,x,y=map(int,input().split())
cost=[]
cm=0
while cm<=2*max(x,y):
    am=x-cm//2    
    bm=y-cm//2
    if am>=0 and bm>=0: cost.append(am*a+bm*b+cm*c)
    elif am>=0 and bm<=0: cost.append(am*a+cm*c)
    elif am<=0 and bm>=0: cost.append(bm*b+cm*c)
    elif am<=0 and bm<=0: cost.append(cm*c)
    cm+=2
print(min(cost))

Measured memory_bytes: 44912
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        String s = sc.next();
        char[] arr = s.toCharArray();

        for (int i=0; i<s.length()/2; i++) {
            if (arr[i]!=arr[s.length()-1-i]) {
                out.print("No");
                out.flush();
                return;
            }
        }

        for (int i=0; i<s.length()/2-1; i++) {
            if (arr[i]!=arr[(s.length()/2)-1-i]) {
                out.print("No");
                out.flush();
                return;
            }
     
        }

        out.print("Yes");
        out.flush();
    }

}


Measured memory_bytes: 23764
k = int(input())
a = list(map(int,input().split()))
x = sorted(a)
m = x[k//2-1]
n = x[k//2]

if m == n:
    for i in range(k):
        print(m)
        
else:
    for i in a:
        if i <= m:
            print(n)
        else:
            print(m)

Measured memory_bytes: 25224
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0517
// ???????????????????????¨????????????????????????????????????????????£????????§?????????????????§???????£???????????????????
// ????????????????????????????????£?????°????????????????????????????????????

#include <iostream>
using namespace std;

bool paper[100100];

int main() {
  int n, k;
  while (cin >> n >> k && n && k) {
    fill(paper, paper+n+100, false);
    int x;
    for (auto i=0; i<k; i++) {
      cin >> x;
      paper[x] = true;
    }
    int white = (paper[0] ? 1 : 0);
    int f = 0, l = 0;
    int cnt = 0;
    int ans = 0;
    while (l <= n) {
      if (cnt <= white) {
        if (!paper[++f]) {
          cnt++;
        }
      } else {
        // cerr << f << " " << l << endl;
        ans = max(ans, f-l-1);
        if (!paper[++l]) cnt--;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1256
#include<stdio.h>
int main() {
	int L = 0;
	int R = 0;
	int d = 0;
	int count = 0;
	int i = 0;
	scanf("%d %d %d", &L, &R, &d);

	for (i = L; i <= R; i++) {
		if (i % d == 0) {
			count++;
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 1728
from collections import deque
s=deque(input().split())
f=False
for i in range(int(input())):
  _=input().split()
  if _[0]=='1':
    f=not f
  else:
    if f:
      [s.append(_[2]) if _[1]=='1'
       else s.appendleft(_[2])]
    else:
      [s.appendleft(_[2]) if _[1]=='1'
       else s.append(_[2])]
print("".join(s)[::-1] if f else "".join(s))

Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  int K,N; cin>>K>>N;
  int A[N]; rep(i,N) cin>>A[i];
  ll ans=A[N-1]-A[0];
  rep(i,N){
    ll tmp=1e15;
    if(i) tmp=K-(A[i]-A[i-1]);
    ans=min(ans,tmp);
    if(i!=N-1) tmp=K-(A[i+1]-A[i]);
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
long long l,r,mid;
long long e(long long x)
{
    long long ans=1;
    for(int i=1;i<x;++i)
        ans*=10;
    return ans;
}
bool check(long long x)
{
    char ch='0';
    cout<<'?'<<' '<<x<<endl;
    while(ch!='Y'&&ch!='N') cin>>ch;
    if(ch=='Y') return true;
    else return false;
   /*
    const long long ans=369;
    const string s=to_string(ans);
   string xs=to_string(x);
   if(ans<=x&&s<=xs) return true;
   if(ans>x&&s>xs) return true;
   return false;
   */
}
int main()
{
    ios::sync_with_stdio(false);
    for(int i=1;i<=11;i++)
    {
        if(!check(e(i)))
        {
            l=e(i-1);r=e(i)-1;
            break;
        }
    }
    if(l==0)
    {
        for(int i=1;i<=11;i++)
        if(check(e(i+1)-1))
        {
            cout<<"! "<<e(i)<<endl;
            return 0;
        }
    }
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(10*mid))
            r=mid-1;
        else
            l=mid+1;
    }
    cout<<"! "<<l<<endl;
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 数値
		int k = sc.nextInt();
		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;

		for (int i = 0; i < n - 1; i++) {
			if (a[i + 1] - a[i] > max) {
				max = a[i + 1] - a[i];
			}
		}

		a[n - 1] = k - a[n - 1];
		if (a[n - 1] + a[0] > max) {
			max = a[n - 1] + a[0];
		}

		out(k - max);

	}

	/*
	 * 以下メソッド集
	 */
	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}
}


Measured memory_bytes: 80912
//2020 2.16 バブルソート

#include <stdio.h>
#define MAX 100

int main()
{
    int a,temp,cnt=0,cnt1=0;
    int i,j;
    int A[MAX];

    scanf("%d",&a);
    for(i=0;i<a;i++)
    {
        scanf("%d",&A[i]);
    }
    while(1)
    {
        j=a-1;
        if(cnt1==j) break;
        while(j>=1)
        {
        if(A[j]<A[j-1])
        {
            cnt++;
            temp = A[j];
            A[j] = A[j-1];
            A[j-1] = temp;
        }
        j--;
        }
        cnt1++;
    }
    for(i=0;i<a;i++)
    {
        if(i==0) printf("%d",A[i]);
        else printf(" %d",A[i]);
    }
    printf("\n%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#define MAX 100000000
using namespace std;

int main (void) {
  long long n,N;
  cin >> N;
  n=sqrt(N);
  long long ans=MAX;
  long long b=0;
  long long  size1=0, size2=0, size3=0;
  long s,t=0;
  for (long i=1; i<=n; i++) {
    if (N%i==0) {
      b=N/i;
      string s =to_string(i);
      string t =to_string(b);
      size1=s.size();
      size2=t.size();
      size3=max(size1,size2);
      ans=min(ans, size3);
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b,c,cub,rec,per;
   while(scanf("%d%d%d",&a,&b,&c)!=EOF)
   {
     if(a<b && b<c)
     {
         cout<<"Yes"<<endl;
     }
     else
     {
         cout<<"No"<<endl;
     }

   }
}




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

typedef long long ll;

int main() {
        ll n;
        cin >> n;
        ll c = 1, len = 0;
        while (true) {
                if (n < c)
                        break;
                n -= c;
                len++;
                c *= 26;
        }
        string ans = "";
        for (int i = 0; i < len; i++) {
                ans += char(n % 26 + 'a');
                n /= 26;
        }
        reverse(ans.begin(), ans.end());
        return cout << ans << "\n", 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int H = nextInt();
		int W = nextInt();

		String[][] S = new String[H+2][W+2];
		Arrays.fill(S[0], ".");
		Arrays.fill(S[S.length-1], ".");
		for(int i=1;i<S.length-1;i++){
			Arrays.fill(S[i], ".");
			String[] tmp = toStringArray(nextString());
			for(int x=0;x<tmp.length;x++){
				S[i][x+1]=tmp[x];
			}
		}

		//4方向の場合は0～5,8方向は0～9でループ
		int[] around = { -1, 0, 1, 0, -1, 1, 1, -1, -1 };
		for(int h=1;h<S.length-1;h++){
			for(int w=1;w<S[h].length-1;w++){
				if(S[h][w].equals(".")){
					int cnt=0;
					for(int x=0;x<around.length-1;x++){
						if(S[h+around[x]][w+around[x+1]].equals("#")){
							cnt++;
						}
					}
					S[h][w]=String.valueOf(cnt);
				}
				System.out.print(S[h][w]);
			}
			System.out.println();
		}



	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
		int m=sc.nextInt();

  		int[] a1=new int[a];
		for(int c=0;c<a;c++){
    		a1[c]=sc.nextInt();
    	}
  	  int[] b1=new int[b];
		for(int c=0;c<b;c++){
    		b1[c]=sc.nextInt();
    	}
  		int min=100000000;
  
		for(int c=0;c<m;c++){
    		int x=sc.nextInt();
          	int y=sc.nextInt();
          	int d=sc.nextInt();
            int g=a1[x-1]+b1[y-1]-d;
            min=Math.min(g,min);
    	}
  		
  		Arrays.sort(a1);
  		Arrays.sort(b1);
  		int min1=a1[0]+b1[0];
    
  
 	if(min1>=min){
    		System.out.println(min);
    	}else{
     		System.out.println(min1);
   	 }

    }
}

Measured memory_bytes: 136252
#include<iostream>
using namespace std;
int main() {
  int k,cnta,cntb;
  cnta=0;
  cntb=0;
  cin >> k;
  
  for (int i=1; i<k+1; i++){
    if(i%2==0){
    cnta++;
    }else if(i%2 !=0){
      cntb++;
    }
  }
  cout << cnta*cntb << endl;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  for (int i = 0; i < N; i++) cin >> C.at(i);

  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  long long ans = 0, X, Y;

  for (int i = 0; i < N; i++) {
    X = lower_bound(A.begin(), A.end(), B.at(i)) - A.begin();
    Y = upper_bound(C.begin(), C.end(), B.at(i)) - C.begin();
    ans += X * (N - Y);
  }

  cout << ans << "\n";
}

Measured memory_bytes: 1408
def f;gets.split.map &:to_i;end
while 0<n=gets.to_i
b={};(1..n).map{i,*z=f;b[i]=z}
f[0].times{s,g=f
c={s=>[0,[s]]}
(t=c.flat_map{|k,(v,l)|b.map{|i,(x,y)|c[i]||(d=Math.hypot x-b[k][0],y-b[k][1])>50?nil:[d+v,l+[i]]}}.compact.min)?(c[t[1][-1]]=t):break until c[g]
puts c[g]?c[g][1]*" ":"NA"}end

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

int main(){
    queue <int> Q[3];
    for(int i = 0; i < 3; ++i){
        string tmp;
        cin >> tmp;
        for(int j = 0; j< tmp.size(); ++j){
            Q[i].push(tmp[j]-'a');
        }
    }
    char won = '@';
    int flg = 0;
    while(true){
       if(Q[flg].size() == 0){
            won = flg + 'A';
            break; 
       }
       int nxt = Q[flg].front();Q[flg].pop();
       flg = nxt;
    }
    cout << won << endl;

    return 0;
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
typedef pair<ll, ll> P;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}


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

    if (n == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }

    if (n == 4) {
        cout << "2 5 63 20" << endl;
        return 0;
    }

    if (n == 5) {
        cout << "2 5 20 30 63" << endl;
        return 0;
    }

    vector<ll> a;
    map<ll, vector<ll>> unused;

    rep(i, 30000 + 1) {
        if (i == 0) continue;
        if (i % 6 == 1 || i % 6 == 5) continue;
        if (a.size() < n) {
            a.push_back(i);
            continue;
        }
        unused[i % 6].push_back(i);
    }
    ll sum_v = accumulate(a.begin(), a.end(), 0ll);
    if (sum_v % 6 == 2) {
        a.erase(find(a.begin(), a.end(), 8));
        a.push_back(unused[0].front());
    }
    if (sum_v % 6 == 3) {
        a.erase(find(a.begin(), a.end(), 9));
        a.push_back(unused[0].front());
    }
    if (sum_v % 6 == 5) {
        a.erase(find(a.begin(), a.end(), 9));
        a.push_back(unused[4].front());
    }

    for (ll i : a) cout << i << ' ';
    cout << endl;
}





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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 1050000000;
constexpr auto MOD = 1000000007;

int main() {
	int n;
	cin >> n;
	vi c(n-1), s(n-1), f(n-1);
	rep(i, n-1)cin >> c[i] >> s[i] >> f[i];

	rep(i, n) {
		int t = 0;
		rep(j, n - 1 - i) {
			if (t < s[i + j])t = s[i + j];
			else if (t % f[i + j])t += (f[i + j] - (t % f[i + j]));
			t += c[i + j];
		}
		cout << t << endl;
	}
}

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


int main() {
  int a, b;
  cin >> a >> b;
  if (b%a == 0) cout << a+b << endl;
  else cout << b-a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld double
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
int main()
{
	boost;
	int a, b;
	cin >> a >> b;
	if(a > 9 || b > 9)
	cout << -1;
	else
	cout << a * b;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [0] + list(map(int, input().split()))
    B = [0] * (n + 1)
    res = []

    for i in reversed(range(1, n + 1)):
        if B[i] % 2 != A[i]:
            res.append(i)
            for j in range(1, int(pow(i, 0.5)) + 1):
                if i % j == 0:
                    B[j] += 1
                    if j != i // j:
                        B[i // j] += 1

    print(len(res))
    if len(res) != 0:
        print(*res[::-1])


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 19336
#include<iostream>
#include<iomanip>
#define MAX 10000000
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) Rep(i,0,a)
using namespace std;
int sum,u[70][70][4],v[70][70];
int w,h;
int dx[]={0,0,-1,1},dy[]={1,-1,0,0},d[70][70];
void func(int x,int y,int now){
	d[y][x]=now;
	if(x!=w-1||y!=h-1){
		rep(i,4)
			if(u[y][x][i]==1)
				if(d[y+dy[i]][x+dx[i]]>now+1)
					func(x+dx[i],y+dy[i],now+1);
	}
}
int main(){
	int box[70][70];
	while(cin>>w>>h,w||h){
		rep(i,2*h-1)
		rep(j,w-1+i%2)
		cin>>box[i][j];
		//1
	   //2 3
		//0
		rep(i,h)
		rep(j,w){
			d[i][j]=MAX;
			if(j==0)
				u[i][0][2]=0;
			else {
				if(box[2*i][j-1]==1)
					u[i][j][2]=0;
				else u[i][j][2]=1;
			}
			if(i==0)
				u[0][j][1]=0;
			else {
				if(box[2*i-1][j]==1)
					u[i][j][1]=0;
				else u[i][j][1]=1;
			}
			if(i==h-1)
				u[h-1][j][0]=0;
			else {
				if(box[2*i+1][j]==1)
					u[i][j][0]=0;
				else u[i][j][0]=1;
			}
			if(j==w-1)
				u[i][w-1][3]=0;
			else {
				if(box[2*i][j]==1)
					u[i][j][3]=0;
				else u[i][j][3]=1;
			}
		}
		func(0,0,1);
		if(d[h-1][w-1]==MAX)
			cout<<'0';
		else {
			cout<<d[h-1][w-1];
		}
cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(int i =a; i < n; i++)
#define fi first
#define se second
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef long long int lli;

int main(){__
    int n;
    cin >> n;
    vi a(n);
    forn(i,0,n) cin >> a[i];
    vi pre(n),suf(n);
    pre[0] = a[0];
    forn(i,1,n) pre[i] = __gcd(a[i],pre[i-1]);
    suf[n-1] = a[n-1];
    for(int i =n-2; i >=0; i--){
    	suf[i] = __gcd(a[i],suf[i+1]);
    }
    int ans = -1;
    forn(i,0,n){
    	int p = (i-1 >= 0) ? pre[i-1] : 0;
    	int s = (i+1 < n) ? suf[i+1] : 0;
    	//cout << "para i " << i << " tenemos a " << __gcd(p,s) << endl;
    	ans = max(ans,__gcd(p,s));
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int a[1025],z=0;
int main()
{
	int flag=1,s,s1,i;
	scanf("%d",&s);
	if(s==0)
	{
		printf("0");
		return 0;
	}
	while(s!=0)
	{
		s1=fabs(s%2);
		a[++z]=s1;
		if(s1==1)
		{
			if(flag==1)
				s--;
			else
				s++;
		}
		s/=2;
		flag=!flag;
	}
	for(i=z;i>=1;i--)
		printf("%d",a[i]);
	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    l1 = length = 0
    l2 = 1

    while (l2 + length < N):
        if S[l1:l2] in S[l2:]:
            length = l2 - l1
            l2 += 1
        else:
            l1 += 1
            l2 = l1 + length + 1
    print(length)

main()


Measured memory_bytes: 40300
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	vector<vector<int>> v=vector<vector<int>>(n+2,vector<int>());
	int db[101010]={};
	int dw[101010]={};
	FOR(i,1,n){
		int a,b;
		cin>>a>>b;
		v[a].PB(b);
		v[b].PB(a);
	}
	db[1]=dw[n]=1;
	queue<int> b;
	queue<int> w;
	b.push(1);
	w.push(n);
	while(b.size()){
		int t=b.front();
		b.pop();
		int l=v[t].size();
		FOR(i,0,l){
			if(db[v[t][i]]==0){
				db[v[t][i]]=db[t]+1;
				b.push(v[t][i]);
			}
		}
	}
	while(w.size()){
		int t=w.front();
		w.pop();
		int l=v[t].size();
		FOR(i,0,l){
			if(dw[v[t][i]]==0){
				dw[v[t][i]]=dw[t]+1;
				w.push(v[t][i]);
			}
		}
	}
	int cb=0,cw=0;
	FORQ(i,1,n){
		if(db[i]<=dw[i]){
			cb++;
		}else{
			cw++;
		}
	}
	if(cb<=cw){
		cout<<"Snuke"<<endl;
	}else{
		cout<<"Fennec"<<endl;
	}

    return 0;
}


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

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


def solve(X: int, Y: int):
    # a + b = X
    # 2a+4b = Y
    ret = Y - 2 * X
    if ret >= 0 and ret % 2 ==0:
        b = ret // 2
        a = X - b
        if a >= 0:
            print(YES)
        else:
            print(NO)
    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()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9144
num = int(input())
input_num = input()
num_list = [int(i) for i in input_num.split(" ")]
num_list.sort()
min = num_list[0]
max = num_list[num-1]
if min== max:
    print(0)
    exit()
min_sum = 100**3
for i in range(min,max):
    temp_sum = 0
    for j in range(0,num):
        temp_sum += (num_list[j] - i)**2
    if min_sum>temp_sum:
        min_sum = temp_sum
print(min_sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second

int main() {
	LL n, k;
	cin >> n >> k;
	vector<LL> h(n);
	REP(i, n) cin >> h[i];
	sort(ALL(h));
	LL ans = INF;
	REP(i, n - k + 1) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int fibonacci(int);
int main(void)
{
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}
int fibonacci(int n)
{
  int i;//counter
  int *F=(int*)malloc(sizeof(int)*(n+1));
  F[0]=F[1]=1;
  for(i=2;i<=n;i++) F[i]=F[i-2]+F[i-1];
  return F[n];
}



Measured memory_bytes: 2048
from collections import defaultdict
from math import factorial

s = input()

rs = list()
r = 0
dr = 1
for i in range(len(s)):
    rt = (dr * int(s[-(i + 1)])) % 2019
    r = (r + rt) % 2019
    dr = (dr * 10) % 2019
    rs.append(r)

d = defaultdict(lambda: 0)

d[0] = 1
for r in rs:
    d[r] += 1

res = 0
for x in d.values():
    res += x * (x - 1) / 2

a = 0
for ss in s + 'x':
    if ss == '0':
        a += 1
        res -= 1
    else:
        if a >= 2:
            res -= a * (a - 1) / 2
        a = 0

print(int(res))


Measured memory_bytes: 16896
/**
*    created: 25.07.2020 08:19:39
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8]={0, 1, 0, -1, 1, 1,-1, -1};
const int dy2[8]={1, 0,-1, 0, 1, -1, 1, -1};
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    int ans = 1;
    for (int i = 1; i * i <= m; i++) {
        if (m % i == 0) {
            int p = m / i;
            if (m >= n * i) chmax(ans,i);
            if (m >= n * p) chmax(ans,p);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int solve(int d, string s) {
	if (d == n) return 0;
	if (s[d] == 48) return solve(d + 1, s);
	int ret = n;
	int e = s[d] - 48;
	for (int i = d + 1; i <= n; i++) {
		s[i - 1] = (s[i - 1] - 38 - e) % 10 + 48;
		ret = min(ret, solve(d + 1, s) + 1);
	}
	return ret;
}
int main() {
	string s, t;
	while (cin >> n, n) {
		cin >> s >> t;
		for (int i = 0; i < n; i++) s[i] = (t[i] - s[i] + 10) % 10 + 48;
		cout << solve(0, s) << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
/**
 * 	matrix chain multiplication
 * 	f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
 * 	f(n,n) = 1
 * 	r(n)=c(n-1)
 * 	f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
 * 	f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
 * 	f(n,m) = min(f(n,k,m)
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int r[100] = {0};
int a[100][100] = {0};

int f(int n, int m);
int f(int n, int k, int m);


int f(int n, int k, int m)
{
	return f(n,k) + f(k+1,m) + (r[n] * r[k+1] * r[m+1]);
}

int f(int n, int m)
{
	if (n==m) return 0;
	int & ra = a[n][m];
	if (ra) return ra;
	ra = INT_MAX;
	for (int k=n;k<m;k++)
	{
		int ans = f(n,k,m);
		if (ans < ra) ra = ans;
	}
	return ra;
}

int main()
{
	int rr = 0;
	int cc = 0;
	int n = 0;
	cin >> n;
	for (int i=0;i<n;i++)
	{
		cin >> rr >> cc;
		r[i]=rr;
		r[i+1]=cc;
	}
	for (int i=0;i<n-1;i++)
	{
		a[i][i+1] = r[i] * r[i+1] * r[i+2];
	}
	int ans = f(0,n-1);
	cout << ans << endl;
}

Measured memory_bytes: 3116
#include <iostream>
#include <fstream>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <iterator>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=1e5+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int a[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int l=-1,cnt=0,ans=0,x;
    for(int i=1;i<=n;i++){
        cin>>x;
        if(x!=l){
            ans+=cnt/2;
            cnt=0;
            l=x;
        }
        cnt++;
    }
    ans+=cnt/2;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,T; cin >> N >> T;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    ll maxv = 0;
    ll minv = A[0];
    for(int i = 1; i < N;i++){
        maxv = max(maxv,A[i]-minv);
        minv = min(minv,A[i]);
    }
    
    ll V = maxv;
    maxv = 0;
    minv = A[0];
    for(int i = 1; i < N;i++){
        if(A[i] - minv == V) res++;
        maxv = max(maxv,A[i]-minv);
        minv = min(minv,A[i]);
    }

    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		boolean[] c = new boolean[n];
		long ac = 0 , wa = 0;
		int[] q = new int[n];
		Arrays.fill(q , 0);
		Arrays.fill(c , true);
		int p;
		String s;
		for(int i = 0 ; i < m ; i++){
			p = Integer.parseInt(sc.next()) - 1;
			s = sc.next();
			if(s.equals("WA") && c[p]) q[p]++;
			if(s.equals("AC") && c[p]){
				c[p] = false;
				wa += q[p];
				ac++;
			}
		}
		sc.close();
		ou.print(ac + " " + wa + "\n");
		ou.flush();
    }
}

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

const int N = 2e5 + 69;

int n, ans;
int a[N], b[N];

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

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		a[i] *= 2;
		b[i] *= 2;
	}
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	if(n & 1) {
		int med1 = a[(n + 1) / 2];
		int med2 = b[(n + 1) / 2];
		if(med1 < med2)
			swap(med1, med2);
		ans = (med1 - med2 + 2) / 2;
	} else {
		int med1 = (a[n / 2] / 2) + (a[(n / 2) + 1] / 2);
		int med2 = (b[n / 2] / 2) + (b[(n / 2) + 1] / 2);
		if(med1 < med2)
			swap(med1, med2);
		ans = (med1 - med2 + 1);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    double r;
    cin >> r;
    cout << precise(6) << (r * r * M_PI) << " ";
    cout << precise(6) << (2 * M_PI * r) << endl;
}



Measured memory_bytes: 3300
fn main() {
    /* 標準入力を開いて */
    let scan = std::io::stdin();

    let mut line = String::new();

    /* 読み込んで  */
    let _ = scan.read_line(&mut line);
    /* 空白で分割してからベクタにまとめる */
    let vec: Vec<&str> = line.split_whitespace().collect();

    /* それぞれを変換 */
    let n: u32 = vec[0].parse().unwrap_or(0);
    let m: u32 = vec[1].parse().unwrap_or(0);
    println!("{}", n+m/2);
}

Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector< vector < int> > vee;
typedef pair<int, int> pa;
typedef vector<pair<ll,ll> > vepa;
typedef set<int>se;
typedef map<string,int> mp;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N];
bool visited[N]={};
ll cnt[N],freq[N];
bool f,ff;
int main()
{
  ll n,k,sum(0);
  cin>>n>>k;
  ve v(k);
   for(ll& i:v)
    cin>>i;
   ve vf(k);
    vf[0]=v[0]+n-v[k-1];
    REP(i,k)
     {
       vf[i]= v[i]-v[i-1];;
     }
     sort(all(vf));
     vf.pop_back();
     sum=accumulate(all(vf),0);
   cout<<sum;
go;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;

const int MAXN = 2e5 + 5;



int main(){
	ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie();
    int n; cin >> n;
    map<ll, ll> sums;
    ll ans = 0;
    for(int i = 1; i <= n; i ++){
        int x; cin >> x;
        ans += sums[i - x];
        ++ sums[x + i];
    }
    cout << ans << endl;
}
/**

*/



Measured memory_bytes: 26364
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;
 
 
int main()
{
  int t;
  scf(t);

    set<string>s;

    while(t--)
    {
      string a;
      cin>>a;

      s.insert(a);
    }

    cout<<s.size()<<endl;

}
 


Measured memory_bytes: 19312
#include<bits/stdc++.h>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    long long ans=0;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i=0;i<n;i++){
        auto small=lower_bound(a.begin(),a.end(),b[i]);
        auto large=upper_bound(c.begin(),c.end(),b[i]);

        ans+=(small-a.begin())*(c.end()-large);
    }
    cout<<ans;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define bigrep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define reps(i, n, s) for (int i = s; i < (int)(n); i++)
#define twopo(k)  1 << k

typedef vector<int> vec1;
typedef vector<vector<int>> vec2;
typedef vector<vector<char>> cvec2;
typedef pair<int, int> pairi;
typedef map<int, int> mapii;

vec1 vecplus(const vec1 &first, const vec1 &second){
  int len = first.size();
  vec1 answer(len);
  rep(i,len){
    answer.at(i) = first.at(i) + second.at(i);
  }
  return answer;
}

vec2 listmake(const int &row, const int &col){
  vec2 list;
  rep(i,row){
    vec1 v(col);
    rep(j,col){
      cin >> v.at(j);
    }
    list.push_back(v);
  }
  return list;
}

int main(){
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  const double PI=3.14159265358979323846264338327950288;
  double shorta = PI * H /6 + PI * M /360;
  double longa = PI * M / 30;
  double angle = 0;
  if (shorta > longa){
    angle = shorta - longa;
  }else{
    angle = longa - shorta;
  }
  const double cosang = cos(angle);
  const double ans2 = A * A + B * B - 2 * A * B * cosang;
  const double ans = sqrt(ans2);
  
  printf("%.20f",ans);
  
}

Measured memory_bytes: 4264