akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
  int x,y,box;
  scanf("%d%d",&x,&y);
  if(x<y){
    box=x;
    x=y;
    y=box;
  }
  box=x%y;
  while(box!=0){
   x=y;
   y=box;
   box=x%y;
  }
  printf("%d\n",y);
  return 0;
}



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

int main()
{
    int n, k;
    cin >> n >> k;
    map<int,int> m;
    for(int i =0; i < k; i++)
    {
        int ki;
        cin >> ki;
        for(int i = 0; i <ki; i++)
        {
            int x;
            cin >> x;
            m[x]++;
        }
    }
    cout << n - m.size();


}



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

using namespace std;

int main()
{
  int n, m, l[200000], r[200000];
  vector< int > line[100001];

  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; i++) l[i] = r[i] = i;
  while(m--) {
    int x, y;
    scanf("%d %d", &x, &y);
    line[x].push_back(y);
  }
  for(int i = 0; i < 100000; i++) {
    for(auto &p : line[i]) {
      l[p] = l[p - 1];
      r[p - 1] = r[p];
    }
  }
  for(int i = 0; i < n; i++) {
    if(i > 0) putchar(' ');
    printf("%d", r[i] - l[i] + 1);
  }
  putchar('\n');
}

Measured memory_bytes: 10204
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n-1); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.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; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

const ll MOD = 1000000007, MAX = 500500;
ll fac[MAX], finv[MAX], inv[MAX];
// 前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数の計算
ll COM(int n, int k){
    if (n < 0 || k < 0 || n < k) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    vector<ll> ans(n+1); // m-i個からn-i個選ぶ
    ans[n] = 1;
    ans[n-1] = (m-n+1) % MOD; // m-n+1個から1個選ぶ
    rrep(i,n-1) ans[i] = ans[i+1] * (m-i) % MOD;

    COMinit();

    ll res = 0;
    rep(i,n+1){
        if(i%2 == 0) res += COM(n,i) * ans[i] % MOD, res %= MOD;
        else res -= COM(n,i) * ans[i] % MOD - MOD, res %= MOD;
    }
    cout << res * ans[0] % MOD << endl;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to;
    char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void){
    
    ll N;
    cin >> N;
    vector<ll> d(N);
    REP(i, N)cin >> d[i];

    sort(d.begin(), d.end());

    ll center = (d.size() / 2) - 1;
    // cout << center << endl;

    ll ans = d[center +1] - d[center];

    cout << ans << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, p;
    string s;
    cin >> n >> p >> s;

    vector<int> v(n);
    REP(i, n) v[i] = s[n-1-i] - '0';

    ll ans = 0;

    if(p == 2 || p == 5){
        REP(i, n){
            ans += (v[i]%p == 0) * (n - i);
        }
    }else{
        vector<ll> mod(p, 0);
        ll m = 0, pow10 = 1;
        REP(i, n){
            m += v[i] * pow10;
            m %= p;
            mod[m]++;
            pow10 *= 10;
            pow10 %= p;
        }
        REP(i, p){
            ans += max(0LL, mod[i] * (mod[i] - 1) / 2);
        }
        ans += mod[0];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1412
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    ll h, w, n; cin >> h >> w >> n;
    vector< vector<ll> > dots;

    rep(i, n){
        ll a, b; cin >> a >> b;
        rep(j, 3){
            rep(k, 3){
                if(1 < a+j-1 && a+j-1 <= h-1 && 1 < b+k-1 && b+k-1 <= w-1){
                    vector<ll> dot{a+j-1, b+k-1};
                    dots.push_back(dot);
                }
            }
        }
    }
    sort(all(dots));
    vector<ll> ans(10, 0);
    if( (int)dots.size() != 0 ){
        int count = 1;
        FOR(i, 1, (int)dots.size()){
            if(dots[i-1] == dots[i]){
                count++;
            }else{
                ans[count]++;
                count = 1;
            }
        }
        ans[count]++;
    }

    cout << (h-2)*(w-2)-accumulate(ans.begin()+1, ans.end(), 0) << endl;
    FOR(i, 1, (int)ans.size()){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 52516
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> gate(m, vector<int> (2));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> gate.at(i).at(j);
        }
    }
    int maxl = 0;
    int minr = 1000000;
    for (int i = 0; i < m; i++) {
        maxl = max(maxl, gate.at(i).at(0));
    }
    for (int i = 0; i < m; i++) {
        minr = min(minr, gate.at(i).at(1));
    }
    int ans = minr - maxl + 1;
    if (ans < 0) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 5760
def main():
    S = list(input())
    N = len(S) + 1
    a = [-1] * N
    for i in range(N):
        if a[i] == -1:
            calc(i, S, a)

    print(sum(a))

def calc(i, S, a):
    if i == 0:
        if S[i] == '<':
            a[i] = 0
        else:
            j = 0
            while j < len(S) and S[j] == '>':
                j += 1
            for k in range(j):
                a[k] = j - k
    elif i == len(S):
        if S[i - 1] == '>':
            a[i] = 0
        else:
            a[i] = a[i - 1] + 1
    else:
        if S[i - 1] == '<' and S[i] == '<':
            a[i] = a[i - 1] + 1
        elif S[i - 1] == '<' and S[i] == '>':
            j = 0
            while (i + j) < len(S) and S[i + j] == '>':
                j += 1
            for l in range(j):
                a[i + l] = j - l
            a[i] = max(a[i - 1] + 1, j)
        elif S[i - 1] == '>' and S[i] == '<':
            a[i] = 0
        elif S[i - 1] == '>' and S[i] == '>':
            a[i] = a[i - 1] - 1

main()


Measured memory_bytes: 26800
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  if(n%10==3){
    cout << "bon" << endl;
  }else if(n%10==0||n%10==1||n%10==6||n%10==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" <<endl;
  }

}

Measured memory_bytes: 3592
#include <stdio.h>
int main(){
    int n,ans[4]={0,0,0,0};
    char a[10]={'\0'};
    while(scanf("%d,%s",&n,a)!=EOF){
        if(a[0]=='B')ans[1]++;
        if(a[0]=='O')ans[3]++;
        if(a[0]=='A'){
            if(a[1]=='B')ans[2]++;
            else ans[0]++;
            a[1]='\0';
        }}
    for(int i=0;i<4;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 2660
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    int m,x;
    bool a[n+1][n+1];
    memset(a,false,sizeof(a));
    REP(i,1,n+1) {
      cin >> m;
      rep(j,m) {
	cin >> x;
	a[i][x]=true;
      }
    }
    cin >> m;
    bool b[n+1];
    memset(b,false,sizeof(b));
    rep(i,m) {
      cin >> x;
      b[x]=true;
    }
    int ans=-1;
    REP(i,1,n+1) {
      bool ck=true;
      REP(j,1,n+1) {
	if(b[j] && !a[i][j]) ck=false;
      }
      if(ck) {
	if(ans==-1) ans=i;
	else ans=-2;
      }
    }
    if(ans==-1 || ans==-2) pr(-1);
    else pr(ans);
  }
  return 0;
}


Measured memory_bytes: 1176
#include <cstdio>

typedef struct
{
	char szUd[3];
} UL;

#define	N	100

int main()
{
	UL	ul[N];

	while(1)
	{
		int l = 0;
		int r = 0;
		int lPrev = 0;
		int rPrev = 0;
		int stepped = 0;

		int count;

		::scanf("%i", &count);

		if(count == 0)	{	break;	}

		// Input info
		for(int i = 0; i < count; i ++)
		{
			::scanf("%s", ul[i].szUd);
		}

		for(int i = 0; i < count; i ++)
		{
			//printf(">%c\n", ul[i].szUd[1]);
			switch(ul[i].szUd[0])
			{
			case 'l':
				if(ul[i].szUd[1] == 'u')
				{	l ++;	}
				if(ul[i].szUd[1] == 'd')
				{	l --;	}
				break;
			
			case 'r':
				if(ul[i].szUd[1] == 'u')
				{	r ++;	}
				if(ul[i].szUd[1] == 'd')
				{	r --;	}
				break;
			}
			if(r != rPrev && l != lPrev && r == l)
			{
				stepped ++;
				rPrev = r, lPrev = l;
			}
		}
		
		::printf("%i\n", stepped);
	}
}

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

count = {}
for i in range(1, m + 1):
  count[i] = 0

for i in range(n):
  a = list(map(int, input().split()))
  for j in range(1, len(a)):
    count[a[j]] += 1

ans = 0
for k, v in count.items():
  if v == n:
    ans += 1

print(ans)




Measured memory_bytes: 3060
from fractions import gcd
from math import factorial, ceil, sqrt, atan2, log, pi, e, asin,acos, cos, sin
from itertools import *
from fractions import Fraction
import string
import copy
import random
import bisect
from decimal import *
def id_generator(size=20, chars=string.digits):
    return ''.join(random.choice(chars) for _ in range(size))
 
def mp():
    return map(int,str(raw_input()).split())
 
 
a,b=mp()
if a>=b:
    if a%b==0:
    	print -1
    else:
    	print a
else:
	if 0:
		print -1
	else:
		print a

Measured memory_bytes: 6028
#include <iostream>
using namespace std;
typedef long long ll;

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

int main(void){
    // Your code here!
    int N;
    ll X;
    cin >> N >> X;
    ll x[N];
    ll dp[N];
    for(int i = 0; i < N; i++) cin >> x[i];
    
    dp[0] = abs(X- x[0]);
    for(int i = 1; i < N; i++){
        dp[i] = gcd(dp[i-1], abs(X-x[i]));
    }
    
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
fun main(args: Array<String>) = println(run {
    val (n,m)= readLine()!!.split(" ").map { it.toInt() }
    val ps = (1..m).map { readLine()!!.split(" ") }
    val result = ps.groupBy { it[0] }.mapValues {
        it.value.map { it[1] }
    }

    val ac = result.filter { "AC" in it.value }.count()
    val wa = result.filter { "AC" in it.value }.map { it.value.takeWhile { it == "WA" }.count() }.sum()

    "$ac $wa"
})

Measured memory_bytes: 101656
n,m = map(int,input().split())
a = list(map(int,input().split()))

e = sum(a)
f = e/4/m
c = 0
a.sort()

for i in range (n):
    if a[i] >= f:
        c = c + 1
    else:
        c = c

if c >= m:
    print ('Yes')
else:
    print ('No')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

int main()
{
	ll l,r;
	ll ans=2020;
	bool f=true;
	cin>>l>>r;
	for(int i=0;i<2020;i++)
	{
		if(l+i>r)
			break;
		if((l+i)%2019==0)
		{
			f=false;
			break;
		}
	}
	for(int i=0;i<2020;i++)
	{
		if(r-i<l)
			break;
		if((r-i)%2019==0)
		{
			f=false;
			break;
		}
	}
	if(f){
		for(ll i=l;i<r;i++)
		{
			for(ll j=i+1;j<=r;j++)
			{
				if(ans>(i*j)%2019)
					ans=(i*j)%2019;
			}
		}
	}else
		ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int a,b,c;
	while(~getIII(a,b,c)){
		printf("%s\n",a+b>=c?"Yes":"No");
	}
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a+b >= 10){
		    System.out.println("error");
		}else{
		    System.out.println(a+b);
		}
	}
}

Measured memory_bytes: 21716
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int h,w,k;
	cin>>h>>w>>k;
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	char c[h+5][w+5];
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>c[i][j];
		}
	}
	int vis[h+5][w+5];
	memset(vis,-1,sizeof(vis));
	queue<pair<int,int>> q;
	q.push(mk(x1,y1));
	vis[x1][y1]=0;
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int i=1;i<=k;i++)
		{
			if(y+i<=w)
			{	
				if(c[x][y+i]=='.'&&(vis[x][y+i]==-1\
				||vis[x][y+i]==vis[x][y]+1))
				{
					if (vis[x][y+i]==-1) 
					{
						vis[x][y+i]=vis[x][y]+1;
						q.push(make_pair(x,y+i));
					}	
				}
				else
				{
					break;
				}
			}
		}
		for(int i=1;i<=k;i++)
		{
			if(y-i>=1)
			{	
				if(c[x][y-i]=='.'&&(vis[x][y-i]==-1\
				||vis[x][y-i]==vis[x][y]+1))
				{
					if (vis[x][y-i]==-1) 
					{
						vis[x][y-i]=vis[x][y]+1;
						q.push(make_pair(x,y-i));
					}	
				}
				else
				{
					break;
				}
			}
		}
		for(int i=1;i<=k;i++)
		{
			if(x+i<=h)
			{	
				if(c[x+i][y]=='.'&&(vis[x+i][y]==-1\
				||vis[x+i][y]==vis[x][y]+1))
				{
					if (vis[x+i][y]==-1) 
					{
						vis[x+i][y]=vis[x][y]+1;
						q.push(make_pair(x+i,y));
					}	
				}
				else
				{
					break;
				}
			}
		}
		for(int i=1;i<=k;i++)
		{
			if(x-i>=1)
			{	
				if(c[x-i][y]=='.'&&(vis[x-i][y]==-1\
				||vis[x-i][y]==vis[x][y]+1))
				{
					if (vis[x-i][y]==-1) 
					{
						vis[x-i][y]=vis[x][y]+1;
						q.push(make_pair(x-i,y));
					}	
				}
				else
				{
					break;
				}
			}
		}
	}
	cout<<vis[x2][y2]<<endl; 
	return 0;
}

Measured memory_bytes: 28084
N = int(input())
hill = list(map(int, input().split()))
view = 0
f = False
highest = hill[0]
for i in range(N):
    if hill[i] >= highest:
        f = True
        highest = hill[i]
    else:
        f = False
    if f:
        view += 1
print(view)

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

#define PRICE 700
#define TOPPING 100

string s;
int p = PRICE;

int main(){
  cin >> s;
  for (int i; i<3; i++)
    s[i] == 'o' ? p += TOPPING : 0;
  cout << p << endl;
  return 0;
}

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

int main(void)
{
	char letter;
	cin >> letter;
	if (letter >= 'a' && letter <= 'z')
	{
		cout << 'a' << endl;
	}
	else
	{
		cout << 'A' << endl;
	}
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}
template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(all(v),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
int dx2[] = {1,1,1,-1,-1,-1,0,0};
int dy2[] = {1,0,-1,-1,0,1,1,-1};
int m[10][10];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char c;
  int x,y,s,a1 = 100,a2 = 0;
  while(cin>>x>>c>>y>>c>>s){
    if(s == 1){
      if(m[x][y] == 0)
        --a1;
      m[x][y]++;
      rep(i,4){
        int X = x+dx[i],Y=y+dy[i];
        if(value(x+dx[i],y+dy[i],10,10)){
          if(m[X][Y] == 0)
            --a1;
          m[x+dx[i]][y+dy[i]]++;
          if(m[X][Y] > a2){
            a2 = m[X][Y];
          }
        }
      }
    }
    else if(s == 2){
      if(m[x][y] == 0)
        --a1;
      m[x][y]++;
      rep(i,8){
        int X = x+dx2[i],Y=y+dy2[i];
        if(value(x+dx2[i],y+dy2[i],10,10)){
          if(m[X][Y] == 0)
            --a1;
          m[x+dx2[i]][y+dy2[i]]++;
          if(m[X][Y] > a2){
            a2 = m[X][Y];
          }
        }
      }
    }
    else{
      if(m[x][y] == 0)
        --a1;
      m[x][y]++;
      rep(i,8){
        int X = x+dx2[i],Y=y+dy2[i];
        if(value(X,Y,10,10)){
          if(m[X][Y] == 0)
            --a1;
          m[X][Y]++;
          if(m[X][Y] > a2){
            a2 = m[X][Y];
          }
        }
      }
      rep(i,4){
        int X = x+dx[i]*2,Y=y+dy[i]*2;
        if(value(X,Y,10,10)){
          if(m[x+dx[i]*2][y+dy[i]*2] == 0)
            --a1;
          m[x+dx[i]*2][y+dy[i]*2]++;
          if(m[X][Y] > a2){
            a2 = m[X][Y];
          }
        }
      }
    }
  }
  cout << a1 << endl;
  cout << a2 <<endl;
  return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<int> v(n); cin >> v;
  int ans = 0;
  int minv = 1001001001;
  for(auto e:v){
    if(ChangeMin(minv,e)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4056
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int N = intRead();
        for (int i = N; N <= 999; i++) {
            string s = i.ToString();
            if (s[0] == s[1] && s[1] == s[2]) { Console.WriteLine(s); break; }
        }
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = strReverce(ret);
        return ret;
    }

}


Measured memory_bytes: 11092
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split('\n');
  var N = inp[0];
  var tmp = inp[1].split(' ');
  var tmp2 = inp[2].split(' ');

  // 二次元配列
  var A = [];
  A[0] = [];
  A[1] = [];

  for (var j = 0; j < N; j++) {
    A[0][j] = parseInt(tmp[j]);
    A[1][j] = parseInt(tmp2[j]);
  }


  var maxVal = 0;
  for (var tmp = 0; tmp <= N - 1; tmp++) {
    var sum = 0;
    for (var l = 0; l <= N - 1 - tmp; l++) {
      sum += A[0][l];
    }
    for (var m = N - 1 - tmp; m <= N - 1; m++) {
      sum += A[1][m];
    }
    if (sum > maxVal) maxVal = sum;
  }
  console.log('%d', maxVal);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int dice(int a) {
    if (0 < a && a< 7) return 1;
    else if (a == 0) return 0;
    else return 2;
}
int main() {
    ll x; cin >> x;
    int a = x % 11;
    ll b = (x - a) / 11;

    cout << dice(a) + 2 * b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define y1 y123123123
#define int ll

using namespace std;

const int N = 2e5 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;

int n;
string s;

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

    cin >> s;
    if(s.size() % 2 != 0) {
        cout << "No";
        return 0;
    }
    for(int i = 0; i < s.size(); i += 2) {
        if(s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

}


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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	vector<int> freq(26);
	for(char c : s) freq[c-'A']++;
	int y = 0;
    for (int v : freq) {
		if (v == 1 || v == 3 || v == 4) {
			cout << "No\n";
			exit(0);
		}
		else if (v == 2) y++;
	}
	if (y == 2) cout << "Yes\n";
}



Measured memory_bytes: 256
n,k=map(int,input().split())
l=[int(input()) for i in range(n)]
l.sort(reverse=True)
#print(l,n,k)
ans=float('inf')
for i in range(n-k+1):
    a=l[i]-l[i+k-1]
    ans=min(ans,a)
print(ans)

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

template<typename Monoid>
struct SlidingWindowAggregation{
    typedef function<Monoid(Monoid,Monoid)> F;
    stack<pair<Monoid,Monoid>> front_stack,back_stack;
    F f;
    Monoid id;
    SlidingWindowAggregation(F f,Monoid id):
        f(f),id(id),front_stack(),back_stack(){
        front_stack.emplace(id,id);
        back_stack.emplace(id,id);
    }
    void push(const Monoid &x){
        back_stack.emplace(x,f(back_stack.top().second,x));
    }
    void pop(){
        if (front_stack.size()==1){
            while(1<back_stack.size()){
                Monoid t=back_stack.top().first;
                Monoid calc=f(t,front_stack.top().second);
                front_stack.emplace(t,calc);
                back_stack.pop();
            }
        }
        front_stack.pop();
    }
    Monoid fold(){
        return f(front_stack.top().second,back_stack.top().second);
    }
};

int DSL_3_D(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,L; cin >> N >> L;
    vector<int> a(N);
    for (int i=0;i<N;++i) cin >> a[i];
    SlidingWindowAggregation<int> SWAG([](int a,int b){return min(a,b);},INT_MAX);
    for (int i=0;i<L-1;++i) SWAG.push(a[i]);
    for (int i=L-1;i<N;++i){
        SWAG.push(a[i]);
        cout << SWAG.fold() << (i+1==N?'\n':' ');
        SWAG.pop();
    }
    return 0;
}

int main(){
    DSL_3_D();
}


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

public class Main{
	public static void main(String[] args){
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s;
		int n;
		int box;
		String[] HIGH;
		int[] h;
		try{
			while((s=r.readLine()) !=null){
				n=Integer.parseInt(s);
				for(int i=0;i<n;i++){
					String kosuu=r.readLine();
					String highdata=r.readLine();
					box=Integer.parseInt(kosuu);
					HIGH=highdata.split(" ");
					h=new int[HIGH.length];
					for(int a=0;a<HIGH.length;a++){
						h[a]=Integer.parseInt(HIGH[a]);
					}
					int[] highdifup=new int[box-1];
					int[] highdifdown=new int[box-1];
					for(int b=0;b<box-1;b++){
						highdifup[b]=h[b+1]-h[b];
					}
					for(int c=0;c<box-1;c++){
						highdifdown[c]=h[c]-h[c+1];
					}
					Arrays.sort(highdifup);
					Arrays.sort(highdifdown);
					if(highdifup[box-2]<0){highdifup[box-2]=0;}
					if(highdifdown[box-2]<0){highdifdown[box-2]=0;}
					System.out.println(highdifup[box-2]+" "+highdifdown[box-2]);
					for(int w=0;w<box-1;w++){
						highdifup[w]=0;
						highdifdown[w]=0;
					}
				}
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 22640
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub fn divisors(n: u64) -> Vec<u64> {
    let mut res = Vec::new();
    let mut x = 1;
    while x * x <= n {
        if n % x == 0 {
            res.push(x);
            let y = n / x;
            if y != x {
                res.push(y);
            }
        }
        x += 1;
    }
    res
}

fn solve() {
    input! {
        n: usize, k: u64,
        av: [u64; n]
    };

    let sum = av.iter().sum::<u64>();
    let mut divisors = divisors(sum);
    divisors.sort_by_key(|&x| -(x as i64));
    for d in divisors {
        let mut dv = av.iter().map(|x| x % d).collect::<Vec<_>>();
        dv.sort();
        let mcusum = dv
            .iter()
            .scan(0, |acc, &x| {
                *acc += x;
                Some(*acc)
            })
            .collect::<Vec<_>>();
        let pcusum = dv
            .iter()
            .scan(0, |acc, &x| {
                *acc += d - x;
                Some(*acc)
            })
            .collect::<Vec<_>>();
        for i in 0..n {
            let msum = mcusum[i];
            let psum = pcusum[n - 1] - pcusum[i];
            let c = std::cmp::max(msum, psum);
            let diff = (msum as i64 - psum as i64).abs() as u64;
            if diff % d == 0 && c <= k {
                println!("{}", d);
                return;
            }
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2252
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>                                    
#include <deque>                                    
#include <queue>
#include <iomanip>
#include <ctime>
#include <random>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;

 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll a[N], ans, mx;
 
inline void boost () {
   ios_base :: sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
}

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   for (int i = 1; i <= n; i ++) {
      mx = max (mx, a[i]);
      ans += mx - a[i];
   }
   cout << ans;
}               
 
signed main () {                                       
  // #ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                 


Measured memory_bytes: 5216
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> joushi(n);
  for(int i=0; i<n-1; i++){
	cin >> joushi.at(i);
  }
	vector<int> answer(n,0);
  for(int i=0; i<n-1; i++){
    answer.at(joushi.at(i)-1)++;
  }
  for(int i=0; i<n; i++){
    cout << answer.at(i);
    if(i == n-1){cout << " ";}
    else{cout << endl;}
  }
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// chctxdy
int main(){
	string s; cin >> s;
	for (ll i = 0; i < s.length(); i++){
		if (i % 2 == 0){
			if (s[i] != 'h'){
				cout << "No\n"; return 0;
			}
		}
		else{
			if (s[i] != 'i'){
				cout << "No\n"; return 0;
			}
		}
	}
	if (s.length() % 2 != 0){
		cout << "No\n"; return 0;
	}
	cout << "Yes\n";
}

Measured memory_bytes: 256
import collections
n = int(input())
x = list(map(int, input().split()))
tmp = sorted(x)
xl = tmp[n // 2 - 1]
xr = tmp[n // 2]
if xl == xr:
    for i in range(n):
        print(xl)
    exit()
for i in x:
    if i > xl:
        print(xl)
    elif i < xr:
        print(xr)


Measured memory_bytes: 26540
# 01 -> 3
# 02 -> 6
# 11 -> 2
# 12 -> 2
# 21 -> 1
# 22 -> 3
n=int(input())
s1 = list(input())
s2 = list(input())
s1p="!"
s2p="!"
arr=[]
for i in range(n):
    if s1[i]==s2[i]:
        arr.append(1)
    elif s1[i]==s1p:
        arr.append(2)
    s1p=s1[i]
    s2p=s2[i]
#print(arr)
prv=0
ans=1
for a in arr:
    if prv==0 and a==1:
        ans*=3
        ans%=1000000007
    elif prv==0 and a==2:
        ans*=6
        ans%=1000000007
    elif prv==1:
        ans*=2
        ans%=1000000007
    elif prv==2 and a==2:
        ans*=3
        ans%=1000000007
    prv=a
print(ans)


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

int main()
{
    long long n, q;
    cin >> n;
    vector<long long> a(n);
    
    for(int i=0;i<n;i++)
        cin >> a[i];

    cin >> q;
    for (int i = 0; i < q; i++)
    {
        long long com,b,e;
        cin >> com >> b >> e;
        if(com == 0)
            cout << *minmax_element(a.begin()+b,a.begin()+e).first << endl;
        else if (com == 1)
            cout << *minmax_element(a.begin() + b, a.begin() + e).second << endl;
    }

    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int n , a , b , c , d , len , space , pos;
bool tuker;
string s;
int main(){
	cin >> n >> a >> b >> c >> d , pos;
	cin >> s;
    a--; b--; c--; d--;
  
	for(int i = 0 ; i < s.size() ; i++){
		if(s[i] == '#' && s[i+1] == '#' && ((a <= i && i <= c) || (b <= i && i <= d))){
      cout << "No" << endl;
      return 0;
		}
	}

  for(int i = b ; i <= d; i++){
		if(s[i] == '.' && s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
				tuker = true;
		}
	}
  
	if(a < b && c < d )cout << "Yes" << endl;
	else if(tuker)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3720
#include<iostream>
#include<cstdint>
#include<algorithm>
using namespace std;

const int MAX = 200000;

int main() {
	int N;
	static int A[MAX];
	cin >> N;
	for (int i = 0;i < N;i ++) {
		cin >> A[i];
		A[i] -= i + 1;
	}
	sort(A, A+N);
	
	int64_t ans = 0;
	for (int i = 0;i < N;i ++) ans += abs(A[i] - A[N >> 1]);
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、B_i = A_i-iについて考えてみる(iは定数なので)
この時、bを動かした時を考えると、悲しさはB_i<=bの個数だけ増えてb<B_iの個数だけ減る
ということはソートして中央値でおｋ
*/

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define eps (1>>25)
#define INF (1<<25)
#define MOD 1000000007
int main(){
  int n,ans=0;
  cin>>n;
  ans+=n/25;
  n=n%25;
  ans+=n/10;
  n=n%10;
  ans+=n/5;
  n=n%5;
  ans+=n;
  cout<<ans<<endl;
  return 0;
}



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

int main() {
  int N, M;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s.at(i);
  cin >> M;
  vector<string> t(M);
  rep(i, M) cin >> t.at(i);

  int max = (N > M) ? N : M;
  vector<string> words(max);
  int X = 0;
  rep(i, N) {
    const string& target = s.at(i);
    int cnt = 0;
    rep(j, N) if (target == s.at(j)) cnt++;
    rep(k, M) if (target == t.at(k)) cnt--;
    X = (cnt > X) ? cnt : X;
  }
  cout << X << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a+b==15)
	{
		printf("+");
	}
	else if(a*b==15)
	{
		printf("*");
	}
	else
	{
		printf("x");
	}
	return 0;
}

Measured memory_bytes: 256
n=int(input())
c=list(map(float,input().split()))
c.sort()
k=n
for i in range(n-2):
  v=(c[0]+c[1])/2
  c=c[2:]
  if c[k-3]<v:
    c.append(v)
    break
  for j in range(k-2):
    if c[j]>=v:
      c.insert(j,v)
      break
  k=k-1
print((c[0]+c[1])/2)

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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  for(int i=0;i<n;i++){
    if(i<(n+1)/2)
      cout << a.at(n-1-i*2);
    else
      cout << a.at((i-(n+1)/2)*2+n%2);
    if(i!=n-1)
      cout << " ";
  }
  cout << endl;
  return 0;
}

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

const int maxn = 310;
int n, m, cnt[maxn], a[maxn][maxn];

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    function<int(int, int)> solve = [&](int n, int m) {
        if (!m) return INT_MAX;
        memset(cnt, 0, sizeof(cnt));
        for (int i = 1; i <= n; i++) {
            cnt[a[i][1]]++;
        }
        int mx = 1;
        for (int i = 1; i <= 300; i++) {
            if (cnt[i] > cnt[mx]) mx = i;
        }
        int tmp = cnt[mx];
        for (int i = 1; i <= n; i++) {
            for (int j = 1, k = 0; j <= m; j++) {
                if (mx == a[i][j]) continue;
                a[i][++k] = a[i][j];
            }
        }
        return min(tmp, solve(n, m - 1));
    };
    printf("%d\n", solve(n, m));
    return 0;
}

Measured memory_bytes: 4136
#include<stdio.h>
int main(){
  int data[10000][2]={};
  int i=0,j=0,k=0,l=0;
  int x,n;
  int count=0;
  int counts=0;

  while(1){
    scanf("%d %d",&n,&x);
    if(n==0 && x==0) break;
    data[i][0]=n;
    data[i][1]=x;
    i++;
    count +=1;
  }

  for(l=0;l<count;l++){
    counts=0;
  
    for(i=1;i<=data[l][0];i++){
      for(j=1;j<=data[l][0];j++){
	for(k=1;k<=data[l][0];k++){
	 
	  if((i+j+k)==data[l][1] && i!=j && j!=k && k!=i) counts+=1;
	}
      }
    }
    printf("%d\n",counts / 6);
  }


  return 0;
}



Measured memory_bytes: 2060
using System;
using System.Linq;

namespace ABC064
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int max = a.Max();
            int min = a.Min();

            Console.WriteLine(max - min);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

const int N = 501;
int a[N][N], d[N][N], tr[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}, n;

void dfs(int x, int y) {
    rep(i, 4) {
        int cx = x + tr[i][0], cy = y + tr[i][1];
        if (cx < 0 || cy < 0 || cx >= n || cy >= n)
            continue;
        if (a[cx][cy] > a[x][y] + 1 - d[cx][cy]) {
            a[cx][cy] = a[x][y] + 1 - d[cx][cy];
            dfs(cx, cy);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	int x, y, q, ans = 0;
    cin >> n;
    rep(i, n)
        rep(j, n)
            a[i][j] = min(min(i, j) + 1, n - max(i, j));
    rep(i, n * n) {
        cin >> q;
        q--;
        x = q / n;
        y = q % n;
        ans += a[x][y] - 1;
        d[x][y] = 1;
        a[x][y]--;
        dfs(x, y);
    }
    cout << ans;
}



Measured memory_bytes: 17076
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main() {
  int h,w,n;
  cin >> h >>w >>n;
  int a[n];
  rep(i,n)cin >> a[i];
  int k=0;
  int ans[h][w];

  rep(i,h){
    if((i+2)%2==0){
      rep(j,w){
        if(a[k]==0)k++;
        if(a[k]>=0){ans[i][j]=k+1;a[k]--;}
      }
    }else{
      for(int j=w-1;j>=0;j--){
        if(a[k]==0)k++;
        if(a[k]>=0){ans[i][j]=k+1;a[k]--;}
      }
    }
  }

  rep(i,h){
    rep(j,w)cout << ans[i][j] << " ";
    cout << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N = 110;
const ll INFLL = 1e18;
int _w;

int n;

namespace Tree {
	int head[N], nxt[N*2], to[N*2], eid;
	void init() {
		eid = 0;
		memset(head, -1, sizeof head);
	}
	void link( int u, int v ) {
		to[eid] = v, nxt[eid] = head[u], head[u] = eid++;
		to[eid] = u, nxt[eid] = head[v], head[v] = eid++;
	}
}

int maxd, leaf[N];

void dfs( int u, int fa, int d ) {
	using namespace Tree;
	maxd = max( maxd, d );
	int ch = 0;
	for( int i = head[u]; ~i; i = nxt[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		dfs(v, u, d+1), ++ch;
	}
	leaf[d] = max( leaf[d], ch );
}

pll solve1( int u ) {
	maxd = 0;
	memset(leaf, 0, sizeof leaf);
	dfs(u, 0, 1);
	ll ans = 1;
	for( int i = 1; i < maxd; ++i )
		ans *= leaf[i];
	return pll(maxd, ans);
}

pll solve2( int e ) {
	maxd = 0;
	memset(leaf, 0, sizeof leaf);
	int u = Tree::to[e];
	int v = Tree::to[e^1];
	dfs(u, v, 1);
	dfs(v, u, 1);
	ll ans = 2;
	for( int i = 1; i < maxd; ++i )
		ans *= leaf[i];
	return pll(maxd, ans);
}

pll mymin( pll a, pll b ) {
	if( a.first < b.first )
		return a;
	else if( a.first > b.first )
		return b;
	else {
		return a.second < b.second ? a : b;
	}
}

int main() {
	cin >> n;
	Tree::init();
	for( int i = 0; i < n-1; ++i ) {
		int u, v;
		cin >> u >> v;
		Tree::link(u, v);
	}
	pll ans(INFLL, INFLL);
	for( int i = 1; i <= n; ++i )
		ans = mymin( ans, solve1(i) );
	for( int i = 0; i < Tree::eid; i += 2 )
		ans = mymin( ans, solve2(i) );
	printf( "%lld %lld\n", ans.first, ans.second );
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  double n, m, d;
  cin >> n >> m >> d;
  double ans;
  if(d == 0) {
    ans = (m - 1) * n / pow(n, 2);
  } else {
    ans = (m - 1) * 2 * (n - d) / pow(n, 2);
  }
  printf("%.9f\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>



const int MAX_V = 1000000;
int prime[1000001];
int sum[1000002];



int main(){
    int i,k,n;
    int num;
    sum[0] = 0;
    
    for(i = 2; i <= MAX_V; i++){
        prime[i] = 1;
    }
    
    for(i = 2; i*i <= MAX_V; i++){
        if(prime[i]){
            for(k = 2*i; k <= MAX_V; k += i){
                prime[k] = 0;
            }
        }
    }
    
    
    for(i = 0; i <= MAX_V; i++){
        sum[i+1] = sum[i] + prime[i];
    }
    
    
    while(scanf("%d", &num) != EOF){
        int cnt = sum[num+1];
        printf("%d\n", cnt);
    }
    return 0;
}

Measured memory_bytes: 8408
#!/usr/bin/env python3
import sys
from itertools import accumulate
from collections import Counter
from math import factorial
def combinations_count(n, r):
    if n<r:
        return 0
    return factorial(n) // (factorial(n - r) * factorial(r))

def solve(N: int, A: "List[int]"):
    accum = accumulate(A)
    counter = dict(Counter(accum))

    answer = 0
    for key,value in counter.items():
        if key == 0:
            answer += value + combinations_count(value,2)
        else:
            answer += combinations_count(value,2)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 59668
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

int main(){
	int N;
	cin >> N;
	std::vector<int> d(N);
	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}
	sort(d.begin(),d.end());

	int m = N/2;
	cout << d[m]-d[m-1] << endl;

	return 0;
}

Measured memory_bytes: 640
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

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

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

	int N;
	
	cin >> N;

	int remainder = N / 15;

	cout << 800 * N - remainder * 200 << endl;

	
	return 0;
}


Measured memory_bytes: 256