akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int x1,x2,y1,y2;

	cin >> x1 >> y1 >> x2 >> y2;

	int dx = x2 - x1;
	int dy = y2 - y1;

	int x = x2;
	int y = y2;

	rep(i, 0, 2) {

		int _dx = -dy;
		int _dy = dx;

		dx = _dx;
		dy = _dy;

		x = x + dx;
		y = y + dy;

		cout << x << " " << y << " ";

	}
	
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;

    double x[n+10];
    string myu[n+10];
    double sum = 0.;
    for (int i=0; i<n; i++) {
        cin >> x[i] >> myu[i];
        if (myu[i] == "JPY") {
            sum += x[i];
        }
        else sum += 380000.*x[i];
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;


#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}



int main() {
	IOS;
	int k, l;
	cin >> k;
	l = k / 2;
	cout << l * (k - l) << endl;
}




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

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

K, X = map(int, raw_input().split())

if K * 500 >= X:
    print "Yes"
else:
    print "No"

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S, T; cin >> S >> T;
    int same = 0;
    rep(i, S.length()){
        int res = 0;
        int st = i;
        rep(j, T.length()){
            if(st+j >= S.length()){res = 0; break;}
            if(S[st+j] == T[j]) res++;
        }
        same = max(same, res);
    }

    cout << T.length()-same << endl;
    return 0;
}

Measured memory_bytes: 3664
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef double db;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
const int N=2e5+5,mo=1e9+7,rt=3;
ll Log[N],le,ri,l,r,i,j,n,m,mid;
ll len,f[20][N],a[N],xs[N],inc[N],prt[N],sum;
void rmq()
{
	fo(i,0,m) f[0][i]=a[i];
	fo(i,1,m+1) Log[i]=trunc(log(i)/log(2));
	fo(j,1,Log[m+1])
		fo(i,0,m-(1<<j)+1)
			f[j][i]=min(f[j-1][i],f[j-1][i+(1<<j-1)]);
}
ll getmn(ll x,ll y)
{
	ll z=Log[y-x+1];
	return min(f[z][x],f[z][y-(1<<z)+1]);
}
ll find(ll v)
{
	le=0;
	ri=r;
	while (le<ri)
	{
		mid=(le+ri+1)/2;
		if (getmn(mid,r)<=v) le=mid;
		else ri=mid-1;
	}
	return le;
}
int main()
{
	scanf("%lld %lld",&n,&m);
	a[0]=n;
	fo(i,1,m)
	{
		scanf("%lld",a+i);
	}
	rmq();
	xs[m]=1;
	fd(i,m,1)
	{
		r=i-1;
		len=a[i];
		while (r>=0)
		{
			l=find(len);// pos<=r && a[pos]<=len
			xs[l]+=xs[i]*(len/a[l]);
			len%=a[l];
			r=l-1;
		}
		inc[len]+=xs[i];
	}
	fd(i,n,1)
	{
		sum+=inc[i];
		prt[i]=sum+xs[0];
	}
	fo(i,1,n) printf("%lld\n",prt[i]);
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==0&b==0)break;
        for(int i=0;i<a;i++){
            if(i==0||i==a-1){
                for(int o=0;o<b;o++){
                    cout<<"#";
                }
                cout<<endl;
                continue;
            }
            for(int o=0;o<b;o++){
              if(o==0||o==b-1){
                cout<<"#";
                                continue;
              }
                cout<<".";
            }
            cout<<endl;
        }
      cout<<endl;
    }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll MOD=1000000007;
const ll LINF=1ll<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};




int main(){
    bool f;cin >> f;
    cout << (not f) << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<stdio.h>
#include<iostream>
#include<vector>
using namespace std;

int main(){
    string s;
    cin >>  s ; 
    if (s == "SUN"){
        cout << 7 ;
    }
    else if (s == "MON"){
        cout << 6 ;
    }
    else if (s == "TUE"){
        cout << 5 ;
    }
    else if (s == "WED"){
        cout << 4 ;
    }
    else if (s == "THU"){
        cout << 3 ;
    }
    else if (s == "FRI"){
        cout << 2 ;
    }
    else if (s == "SAT"){
        cout << 1 ;
    }
}   

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;
int N,K;
vector<ll> h;
int main(){
  cin >> N >> K;
  h.resize(N);
  for(int i = 0;i<N;i++){
    cin >> h[i];
  }

  sort(h.begin(),h.end());
  ll ans = 1000000000;
  for(int i = 0;i<N;i++){
    int l = i;
    int r = i + (K-1);
    if(r >= N){
      break;
    }
    ans = min(ans,h[r] - h[l]);
  }
  cout << ans << endl;
}


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

int main(void)
{
    int K;
    cin >> K;

    vector<int> num(32);
    num = {
        1,
        1,
        1,
        2,
        1,
        2,
        1,
        5,
        2,
        2,
        1,
        5,
        1,
        2,
        1,
        14,
        1,
        5,
        1,
        5,
        2,
        2,
        1,
        15,
        2,
        2,
        5,
        4,
        1,
        4,
        1,
        51};
    cout << num.at(K - 1) << endl;

    return (0);
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**7)
def LPP():
    n, m = map(int, readline().split())
    edges = [[] for _ in range(n)]
    for _ in range(m):
        s, t = map(int, readline().split())
        s -= 1
        t -= 1
        edges[s].append(t)
    dp = [-1]*n
    def dfs(s):
        if dp[s] != -1:
            return dp[s]
        if len(edges[s]) == 0:
            dp[s] = 0
            return 0
        res = 0
        for t in edges[s]:
            res = max(res, dfs(t)+1)
        dp[s] = res
        return res
    for i in range(n):
        dfs(i)
    print(max(dp),end="")

LPP()



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

int main() {
  char c;
  cin >> c;
  
  if(c == 'a' ){
    cout << "vowel" << endl;
    }
  else if (c == 'i'){
    cout << "vowel" << endl;
  }
  else if (c == 'u'){
    cout << "vowel" << endl;
  }
  else if (c == 'e'){
    cout << "vowel" << endl;
  }
  else if (c == 'o'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
    }
}


Measured memory_bytes: 764
import sys

def sieve(n):
    if n < 2:
        is_prime = [False for _ in range(n+1)]
        return is_prime

    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False

    return is_prime


def main():
    input = sys.stdin.readline
    Q = int(input())
    is_prime = sieve(10**5)
    A = [0 for _ in range(10**5 + 1)]
    for i in range(3, 10**5 + 1):
        if is_prime[i] and is_prime[(i+1)//2]:
            A[i] = A[i-1] + 1
        else:
            A[i] = A[i-1]

    for _ in range(Q):
        l, r = map(int, input().split())
        print(A[r] - A[l-1])


if __name__ == '__main__':
    main()


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

int main() {
	long n,m,i,j,k,ans,cur;
	cin >> n;
	vector<pair<long,long>> a(n);
	for(i=0; i<n; i++){
		cin >> a[i].first;
		a[i].second=i;
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	vector<vector<long>> dp(n+1,vector<long>(n+1,0));
	for(i=0; i<n; i++){
		for(j=0; j<=i; j++){
			cur=a[i].first*(a[i].second-j);
			dp[j+1][i-j]=max(dp[j+1][i-j],dp[j][i-j]+abs(cur));
			cur=a[i].first*((n-1-i+j)-a[i].second);
			dp[j][i-j+1]=max(dp[j][i-j+1],dp[j][i-j]+abs(cur));
		}
	}
	ans=0;
	for(i=0; i<=n; i++){
		ans=max(ans,dp[i][n-i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 34672
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#include <random>
#include <chrono>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

class simulator{
public:
    const int L=26;
    int D;
    vector<int> C;
    vector<vector<int>> S;

    vector<int> bestAnswer;
    int bestScore;

    simulator(){}

    void solve(){
        input();
        output();
    }

    void input(){
        cin>>D;
        C.resize(L);
        S.resize(D);
        rep(i,L) cin>>C[i];
        rep(i,D){
            S[i].resize(L);
            rep(j,L) cin>>S[i][j];
        }
        bestAnswer.resize(D);
        rep(i,D) cin>>bestAnswer[i];
        rep(i,D) bestAnswer[i]--;
    }

    int evaluate(vector<int> &t){
        int result=0;
        vector<int> last(L,0);
        for(int i=0;i<D;i++){
            int tar=t[i];
            result+=S[i][tar];
            last[tar]=i+1;
            for(int j=0;j<L;j++) result-=C[j]*(i+1-last[j]);
            cout<<result<<endl;
        }
        return result;
    }

    void output(){
        //cout<<evaluate(bestAnswer)<<endl;
        evaluate(bestAnswer);
        return;
    }

};

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

  simulator sim;
  sim.solve();

  return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll d;cin >>d;
   string c="Christmas";
   string e="Eve";
   if(d==25)cout <<c<<endl;
   if(d==24)cout <<c<<" "<<e<<endl;
   if(d==23)cout <<c<<" "<<e<<" "<<e<<endl;
   if(d==22)cout <<c<<" "<<e<<" "<<e<<" "<<e<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static long[] pow5;
	static{
		pow5 = new long[26];
		long p = 1;
		for(int i = 0; i < 26; i++){
			pow5[i] = p;
			p *= 5;
		}
	}
	public static void main(String[] args) {
		final int maxNum = 18;
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long ans = 0;
		for(int i = 1; i < 26; i++){
			ans += n / 2 / pow5[i];
		}
		System.out.println(n % 2 == 0 ? ans : 0);
	}
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+1;
vector<int> G[mx];
vector<bool> visited(mx,false);
vector<int> dist(mx);
vector<int> in_degree(mx);

void dfs(int u){
    assert(!visited[u]);
    visited[u]=true;
    for(int v : G[u]){
        dist[v] = max(dist[v],dist[u]+1);
        --in_degree[v];
        if(in_degree[v]==0) dfs(v);
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0; i<m; ++i){
        int x, y;
        cin>>x>>y;
        --x;--y;
        G[x].push_back(y);
        in_degree[y]++;
    }

    for(int i=0; i<n; ++i){
        if(!visited[i] && in_degree[i]==0) dfs(i);
    }
    int ans=0;
    for(int i=0; i<n; ++i) ans=max(ans, dist[i]);
    cout<<ans<<"\n";
}


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

int main() {
  long N,M;
  cin >> N>>M;
  vector<int> a(M);
  long mod=1e9+7;

  int tmp=-11;
  for(int i=0;i<M;i++) {
    int x;
    cin>>x;
    a[i]=x;
    if(x==tmp+1){
      cout<<0<<endl;
      return 0;
    }
    tmp=x;

  }

  vector<long> dp(100005);
  dp[0]=1;
  dp[1]=1;
  for(int i=2;i<100005;i++) {
    dp[i] = dp[i-1]+dp[i-2];
  	dp[i] %=mod;
  }
  //cout<<dp[100]<<endl;
    long ans=1;
    int now = 0;
    int next = 0;
  for(int i=0;i<M;i++){
    next = a[i]-1;
    ans *= dp[next-now];
    now = next+2;
    ans%=mod;
  }
  //cout<<ans<<endl;
  next = N;
  ans *= dp[next-now];
  //now = next+1;
  ans%=mod;
cout<<ans<<endl;
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
	long long int x,a,b;
	scanf("%lld%lld%lld",&x,&a,&b);
	if(abs(a-b)<=x){
		if(a-b>=0){
			printf("delicious\n");
		}
		if(a-b<0){
			printf("safe\n");
		}
	}
	else if(abs(a-b)>x){
		printf("dangerous\n");
	}
}

Measured memory_bytes: 128
h,w=map(int,input().split());r=[list('#'+'#.'[i%2]*(w-2)+'.')for i in range(h)];b=[list('.'+'.#'[i%2]*(w-2)+'#')for i in range(h)]
for i in range(h):
  t=input()
  for j in range(w):
    if t[j]=='#':r[i][j]=b[i][j]='#'
for t in r:print(''.join(t))
print()
for t in b:print(''.join(t))

Measured memory_bytes: 9460
import sys
sys.setrecursionlimit(10**6)

mod=10**9+7
N,K=map(int,input().split())

tree=[]
for i in range(N+1):
  tree.append([])

for i in range(N-1):
  a,b=map(int,input().split())
  tree[a].append(b)
  tree[b].append(a)
#print(tree)

answer=1
visited=[False]*(N+1)
def dfs(node,depth,cind):
  #print(node,depth,cind)
  global answer
  visited[node]=True
  
  if depth==0:
    answer*=K
    answer%=mod
  elif depth==1:
    answer*=K-1-cind
    answer%=mod
  else:
    answer*=K-2-cind
    answer%=mod
  
  next_nodes=tree[node]
  i=0
  for nn in next_nodes:
    if not visited[nn]:
      dfs(nn,depth+1,i)
      i+=1

node=N//2
dfs(node,0,0)
print(answer)


Measured memory_bytes: 109232
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;//998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,m;
  cin >> n >> m;

  auto g=dsu(n);

  for(ll i=0;i<m;i++){
    ll a,b;
    cin >> a >> b;
    g.merge(a-1,b-1);
  }

  auto p=g.groups();
  
  cout << p.size()-1 << endl;

  return 0;
}

Measured memory_bytes: 9000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  sort(all(b));
  int g=1;
  rep(i,a-1){
  if(b[i]!=b[i+1])
    g++;
  }
  out(g);
}

Measured memory_bytes: 384
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main2():
	#a = int(input())
	#b , c = IN()
	s =  input()
	#s='1'*3000
	s=[int(c) for c in s]
	ll=len(s)
	ret_count=0
	for i in range(1):#ll-2):
		v = s[i]
		vs=[v]
		for c in s[i+1:]:
			v = (v * 10 + c) % 2019
			vs.append(v)
			if v == 0:
				ret_count += 1
		else:
			pa(vs)	
	print(ret_count)
				
def main():
	#a = int(input())
	#b , c = IN()
	s =  input()
	#s='1'*3000
	s=[int(c) for c in s]
	s=s[::-1]
	ll=len(s)
	cc=[0]*2019
	p=0
	tt=1
	cc[0]=1
	for i, v in enumerate(s):
		tt *= 10
		tt %= 2019
		p += tt*v
		p %= 2019
		cc[p] += 1
	
	ret = 0
	for v in cc:
		ret += v *(v-1)//2
	print(ret)	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 77116
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5],rfact[fact_table + 5];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

string s, t;
ll dp[3005][3005];

void solve() {
    cin >> a >> b >> c >> d;
    dp[a][b] = 1ll;
    for(ll i=a;i<=c;i++){
        for(ll j=b;j<=d;j++){
            if (i == a && j == b) continue;
            // 真ん中を塗らない場合
            dp[i][j] += dp[i][j-1] * i % mod;
            dp[i][j] %= mod;

            dp[i][j] += dp[i-1][j] * j % mod;
            dp[i][j] %= mod;

            ll tmp = ((dp[i-1][j-1] * (i - 1)) % mod) * (j - 1) % mod;
            tmp = mod - tmp;

            dp[i][j] += tmp;
            dp[i][j] %= mod;
        }
    }
    ll ans = dp[c][d];
    p(ans);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



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

//関数


    
    
    
//main関数
int main() {
    
    
    //入力
    long N,X;
    cin>>N>>X;
    
    
    //計算
    bool dai=true;
    long x=X,y=N-X;
    long ans=x;
    
    while(x>0&&y>0){
        if(dai){
            ans+=y;
            dai=false;
        }else{
            long m=min(x,y),M=max(x,y);
            long path=((2*M)/m);
            path-=path%2;
            path--;
            ans+=m*path;
            dai=true;
            x=M-((path+1)/2)*m;
            y=m;
        }
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<deque>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
	int f1, f2, f3, dp[11][2001], N, K, C, G, sum, temp, se, out = 0;

	deque<int> List[11];
	scanf("%d %d",&N, &K);
	for(f2 = 0; f2 <= K; f2++){
			dp[0][f2] = 0;
	}
	for(f1 = 0; f1 < N; f1++){
		scanf("%d %d",&C, &G);
		List[G].push_back(C);
	}
	for(f1 = 1; f1 <= 10; f1++){
		temp = 0;
		if(List[f1].size()){
			sort(List[f1].begin(), List[f1].end(), greater<int>());
		}
		for(f2 = 0; f2 <= K; f2++)
			dp[f1][f2] = dp[f1 - 1][f2];
		se = min((int)List[f1].size(), K);
		for(f2 = 1; f2 <= se; f2++){
			temp += List[f1].front();
			sum = temp + f2 * (f2 - 1);
			for(f3 = 0; f3 <= K - f2; f3++){
				dp[f1][f2 + f3] = max(dp[f1 - 1][f3] + sum,dp[f1][f2 + f3]);
			}
			List[f1].pop_front();
		}
	}
	for(f1 = 0; f1 <= K; f1++){
		if(dp[10][f1] > out)
			out = dp[10][f1];
	}
	printf("%d\n",out);
	return 0;
}

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

int main(){
	int n, ans = 0, fbra = 0, fbna = 0, nbra = 0;
	string in;
	cin >> n;
	rep(i, n){
		cin >> in;
		rep(j, in.size()){
			if(j != 0 && in[j] == 'B' && in[j-1] == 'A') ans++;
		}
		if(in[0] == 'B' && in.back() == 'A') fbra++;
		else if(in[0] == 'B') fbna++;
		else if(in.back() == 'A') nbra++;
	}
	if(fbra == 0) ans += min(fbna, nbra);
	else{
		if(fbna != 0 || nbra != 0){
			ans += min(fbra + fbna, fbra + nbra);
		}else{
			ans += fbra - 1;
		}
	}
	
	cout << ans << endl;
	
}

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

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

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

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

ll L[2005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> L[i];
    }
    sort(L, L + N);
    ll ans = 0;
    REP(i, N)
    {
        FOR(j, N, i + 1)
        {
            ll a = L[i];
            ll b = L[j];
            ll ok = j, ng = N;
            while (abs(ok - ng) > 1)
            {
                ll mid = (ok + ng) / 2;
                if (L[mid] < a + b)
                    ok = mid;
                else
                    ng = mid;
            }
            ans += ok - j;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int a,b,c,d;
    while(cin >> a >> b){
        d=a+b;
        c=1;
        while(d/10){
            c++;
            d=d/10;
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
n = int(input())

li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))

ans = 0
res = 0

for i in range(n):
    res = sum(li1[:i+1]) + sum(li2[i:])
    ans = max(ans,res)
    
print(ans)
    

Measured memory_bytes: 3060
#include <stdio.h>
#define LIMIT 10000
#define N_MAX 100

int main(void)
{
    int n, a, b, c, x, y[N_MAX], frame, i;

    while(scanf("%d %d %d %d %d", &n, &a, &b, &c, &x), n + a + b + c + x)
    {
        for(i = 0; i < n; i++)
            scanf("%d", y + i);

        frame = i = 0;
        while(1)
        {
            if(x == y[i]) i++;
            if(i == n || frame == LIMIT) break;
            frame++, x = (x * a + b) % c;
        }

        printf("%d\n", i == n ? frame : -1);
    }

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    n--;
    cout << n * (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc176/tasks/abc176_e
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> X(M), Y(M), row(H), col(W);
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        row[x]++;
        col[y]++;
        X[i] = x;
        Y[i] = y;
    }
    vector<int> R, C;
    int maxr = -1, maxc = -1;
    REP(i, H) {
        if (row[i] > maxr)
            maxr = row[i], R.clear(), R.push_back(i);
        else if (row[i] == maxr)
            R.push_back(i);
    }
    REP(i, W) {
        if (col[i] > maxc)
            maxc = col[i], C.clear(), C.push_back(i);
        else if (col[i] == maxc)
            C.push_back(i);
    }
    bitset<300010> vr, vc;
    for (auto &x : R)
        vr.set(x);
    for (auto &x : C)
        vc.set(x);

    int cnt = 0;
    REP(i, M) {
        if (vr[X[i]] && vc[Y[i]])
            cnt++;
    }
    if (cnt == R.size() * C.size()) {
        cout << maxr + maxc - 1 << endl;
    } else {
        cout << maxr + maxc << endl;
    }
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    long long sum = accumulate(begin(A), end(A), 0LL);
    long long cur = 0, mn = sum;
    for (int i = 0; i + 1 < N; ++i) {
        cur += A[i];
        mn = min(mn, abs(sum - 2 * cur));
    }
    cout << mn << "\n";
    
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        String s = sc.next(), t = sc.next();
        char[] s1 = s.toCharArray(), t1 = t.toCharArray();
        int[][] f = new int[s1.length + 1][t1.length + 1];
        for(int i = 1; i <= s1.length; i ++){
            for(int j = 1; j <= t1.length; j ++){
                if(s1[i - 1] == t1[j - 1])f[i][j] = f[i - 1][j - 1] + 1;
                else f[i][j] = Math.max(f[i][j - 1],f[i - 1][j]);
            }
        }
        StringBuilder sb = new StringBuilder();
        int x = s1.length - 1, y = t1.length - 1;
        while(f[x + 1][y + 1] > 0){
            if(s1[x] == t1[y]){
                sb.append(s1[x]);
                x--;y--;
            }
            else{
                if(f[x + 1][y + 1] == f[x + 1][y])y--;
                else x--;
            }
        }

//        for(int i = 0; i <= s1.length; i ++){
//            for(int j = 0; j <= t1.length; j ++){
//                System.out.print(f[i][j] + " ");
//            }
//            System.out.println();
//        }
        System.out.println(sb.reverse().toString());
    }
}

Measured memory_bytes: 81360
#include <cstdio>

using namespace std;

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a <= 5) {
    puts("0");
  } else
  if (a <= 12) {
    printf("%d\n", b / 2);
  } else {
    printf("%d\n", b);
  }
}


Measured memory_bytes: 128
<?php

$k = trim(fgets(STDIN));

$divisors = [];
for ($i=1;$i<=$k;++$i) {
    for ($j=1;$j<=$i;++$j) {
        if ($i%$j === 0) $divisors[$i][] = $j;
    }
}

$count = 0;
for($i=1;$i<=$k;++$i) {
    for($j=$i;$j<=$k;++$j) {
        for($l=$j;$l<=$k;++$l) {
            $common_divisors = array_intersect(
                $divisors[$i],
                $divisors[$j],
                $divisors[$l]
            );

            if ($i === $j || $j === $l || $i === $l) {
                if ($i === $j && $j === $l) {
                    $count += end($common_divisors);
                } else {
                    $count += end($common_divisors) * 3;
                }
            } else {
                $count += end($common_divisors) * 6;
            }
        }
    }
}

echo $count . PHP_EOL;


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

int main()
{
    int  abc[3];
    for (int i = 0; i < 3; i++){
        cin >> abc[i];
    }
    sort(abc, abc+3);
    cout << abc[0] << " "<< abc[1] << " "<< abc[2] << endl;
}


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

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;
    std::vector<int> a(N);
    for(int i = 0; i < N; i++){
        std::cin >> a.at(i);
    }
    int btn = 1;
    std::vector<bool> loop(N, false);
    int ans = 0;
    for(;;){
        btn = a.at(btn-1);
        ans++;
        if(btn == 2){
            std::cout << ans << std::endl;
            return 0;
        }
        if(loop.at(btn-1)){
            std::cout << -1 << std::endl;
            return 0;
        }
        loop.at(btn-1) = true;
    }
    
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int n, A[50];

int solve(int i, int m) {
	if (m == 0)return 1;
	if (i >= n)return 0;
	int res = solve(i + 1,m) || solve(i + 1, m - A[i]);
	return res;
}

int main() {
	int q, M, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%d", &A[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &M);
		if (solve(0, M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 2660
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
using namespace std;
vector <string> ans;
void f(string S, int c){
    vector <int> left_inds;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == '.'){
            left_inds.push_back(i);
        }
    }

    if(left_inds.size() == 0){
        ans.push_back(S);
        return;
    }

    S[left_inds[0]] = c;
    left_inds.erase(left_inds.begin());

    for(int bit_set = 0; bit_set < (1 << left_inds.size()); bit_set++){
        for(int i = 0; i < left_inds.size(); i++){
            if(((bit_set >> i) & 1) == 1){
                S[left_inds[i]] = c;
            }
        }
        f(S, c + 1);
        for(int i = 0; i < left_inds.size(); i++){
            if(((bit_set >> i) & 1) == 1){
                S[left_inds[i]] = '.';
            }
        }
    }
}
int main(void){
    int N;
    cin >> N;

    string S;
    for(int i = 0; i < N; i++){
        S.push_back('.');
    }

    f(S, 'a');

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

Measured memory_bytes: 7796
package main

import (
	"fmt"
)

func main() {
	var m, f, r int
	for {
		fmt.Scan(&m, &f, &r)
		if m == f && f == r && r == -1 {
			break
		}
		if m == -1 || f == -1 {
			fmt.Println("F")
            continue
		}
		sum := m + f
		var g string
		switch {
		case 80 <= sum:
			g = "A"
		case 65 <= sum && sum < 80:
			g = "B"
		case 50 <= sum && sum < 65:
			g = "C"
		case 30 <= sum && sum < 50:
			g = "D"
			if 50 <= r {
				g = "C"
			}
		case sum < 30:
			g = "F"
		}
		fmt.Println(g)
	}
}



Measured memory_bytes: 1120
function Main(input) {
		input = input.split(" ");
		const num = parseInt(input[0], 10);
		const rate = parseInt(input[1], 10);
		if(num > 10) {
				console.log(rate);
		} else {
				console.log(rate+(100 * (10 - num)));
		}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22080
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[200] = {0};
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int cnt = 0, cnt2 = 0;
    while (1) {
        for (int i = 0; i < n; i++) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
            } else {
                cnt++;
                break;
            }
        }
        if (cnt) {
            break;
        }
        cnt2++;
    }
    cout << cnt2 << endl;
    return 0;
}


Measured memory_bytes: 256
x,k,d=map(int, input().split())
if x-k*d>0:
    print(x-k*d)
elif x+k*d<0:
    print(-x-k*d)
else:
    if (k-x//d)%2==0:
        print(abs(x-(x//d)*d))
    else:
        print(abs(x-(x//d+1)*d))

Measured memory_bytes: 9212
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int n, m;
	while (cin >> n >> m, n) {
		vector<int> map(n),list(m);
		for (int i = 0; i < n; i++) {
			cin >> map[i];
		}
		for (int i = 0; i < m; i++) {
			cin >> list[i];
		}
		int i = 0;
		int pos = 0;
		for (;; i++) {
			pos += list[i];
			if (pos +1>= n)break;
			pos += map[pos];
			if (pos + 1 >= n)break;
		}
		cout << i + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3016
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, n; cin >> h >> w >> n;
    map<P, ll> m;
    rep (i, n) {
        ll a, b; cin >> a >> b; a--; b--;
        rep (y, max(0LL, a - 2), min(h - 2, a + 1)) {
            rep (x, max(0LL, b - 2), min(w - 2, b + 1)) {
                m[P{y, x}]++;
            }
        }
    }
    vector<ll> ans(10);
    for (auto p : m) ans[p.second]++;
    ans[0] = (h - 2) * (w - 2);
    rep (i, 1, 10) ans[0] -= ans[i];
    rep (i, 10) cout << ans[i] << "\n";
    return 0;
}

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

int main()
{
    int count = 0;

    int N, tmp;

    string list;
    cin >> N >> list;

    //一番右がリーダーのときの人数
    for (int i = 1; i < N; i++)
    {
        if(list.at(i)=='E')
            count++;
    }

    tmp = count;
    
    for (int i = 1; i < N;i++)
    {
        

        if(list.at(i)=='E')
            tmp--;
        if (list.at(i - 1) == 'W')
            tmp++;

        count = min(count,tmp);
    }

    cout << count;
}

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

int main() {
  int d;
  uint64_t g;
  std::cin >> d >> g;

  std::vector<uint64_t> p(d);
  std::vector<uint64_t> c(d);

  for (int i = 0; i < d; i++) {
    std::cin >> p[i] >> c[i];
  }

  uint64_t count = 1000;

  for (int i = 0; i < (1 << d); i++) {
    std::vector<bool> bit(d);
    for (int j = 0; j < d; j++) {
      bit[j] = (i & (1 << j)) != 0;
    }
    uint64_t cur_cou = 0;
    uint64_t point = 0;

    for (int j = 0; j < d; j++) {
      if (bit[j]) {
        cur_cou += p[j];
        point += 100 * (1 + j) * p[j] + c[j];
      }
    }

    for (int j = d - 1; 0 <= j; j--) {
      if (!bit[j] && point < g) {
        const auto num = std::min(p[j] - 1,
          static_cast<uint64_t>(std::ceil(static_cast<double>(g - point) / (100 * (1 + j)))));
        cur_cou += num;
        point += 100 * (1 + j) * num;
      }
    }

    if (g <= point) {
      count = std::min(count, cur_cou);
    }
  }

  std::cout << count << std::endl;
  return 0;
}

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

int main() {
  ll H,W,h,w; cin>>H>>W>>h>>w;
  ll max=1000000000/(h*w);
  
  ll hu=(H/h)*(W/w);
    ll sei=H*W-hu;
  
  if(max*sei-(max*(h*w-1)+1)*hu<=0){cout<<"No"<<endl;
                    return 0;}
 cout<<"Yes"<<endl;
  rep(i, H){
    rep(j, W){
      if((i+1)%h==0 && (j+1)%w==0) cout<<(-max*(h*w-1)-1);
      else cout<<max;
      if(j==W-1)cout<<endl;
      else cout<<" ";
    }
  }
  
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;
ll gcd(ll a, ll b){
    if (a % b == 0)
    {  return(b);}
    else{return(gcd(b, a % b));}
}
ll lcm(ll a, ll b)
{return a * b / gcd(a, b);}

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<int>x(3);
  x[0]=a,x[1]=b,x[2]=c;
  sort(x.begin(),x.end());
  a=x[0];b=x[1];c=x[2];
  int count=0;
  int p=a,q=b,r=c;
  count+=(c-b);
  a=a+(c-b);
  b=c;
  rep(i,30){
    if(a==c){break;}
    if(a>c){count++;break;}
        a+=2;count++;
  }
  cout<<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
}

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll a,b,c,d,e,ans;
ll z[500005],y[500005],x[500005];

bool used[500005];
string s,t;

int main(){
	cin>>n;
	bool dame=false;
	for(i=0;i<n;i++){
		cin>>z[i];
		x[z[i]]++;
	}
	sort(z,z+n);
	num = INF;
	for(i=0;i<=z[n-1];i++){
		a=max(i,z[n-1]-i);
		num = min(num,a);
		y[a]++;
	}
	for(i=0;i<=z[n-1];i++){
		if(i<=num && x[i]>y[i])dame=true;
		if(i>num && y[i]>x[i])dame=true;
	}
	if(dame)p("Impossible");
	if(!dame)p("Possible");
	

	return 0;
}

Measured memory_bytes: 11008
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
#define MAX 300000
int main(){
	bool sosu[MAX]={1,1};
	for(int i=2;i*i<=MAX;i++)if(sosu[i]==0)
	for(int j=i*2;j<MAX;j+=i)sosu[j]=1;
	//sosu[i]=0 -> i is sosu
	
	int a,b;
	while(cin>>a>>b,a+1){
		vi sos;
		int t=a+1;
		while(sos.size()!=b){
			if(sosu[t]==0)sos.pb(t);
			t++;
		}
		vi sum;
		rep(i,b)loop(j,i,b)sum.pb(sos[i]+sos[j]);
		sort(all(sum));
		cout<<sum[b-1]<<endl;
	}
	
}
 
 

Measured memory_bytes: 1568
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int A, B, K;
  while (cin >> A >> B >> K) {
    vector<int> cand;
    for (int d = 1; d <= A && d <= B; d++) {
      if (A % d == 0 && B % d == 0) {
        cand.push_back(d);
      }
    }
    sort(cand.rbegin(), cand.rend());
    cout << cand[K - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 2e5+10;
ll n;
ll h[N];
ll b[N];

ll query(ll i)
{
	ll ans = 0;
	for(ll j = i ; j>0 ; j-=j&(-j))
		ans = max(ans , b[j]);
	return ans;
}

void update(ll i , ll val)
{
	for(ll j = i ; j<N ; j+=j&(-j))
		b[j] = max(b[j],val);
}

signed main()
{

	fast;
	memset(b , 0 , sizeof b);
////////////////////////////////////////////////////////////////////////////////////////////
	cin >> n;

	rep(i,1,n+1)
	{
		cin >> h[i];
	}

	ll ans = 0;
	rep(i,1,n+1)
	{
		ll e;
		cin >> e;
		ll tmp = query(h[i]) + e;
		update(h[i] , tmp);
		// ans = max(ans , tmp);
	}
	ans = query(n+1);
	cout<<ans<<endl;


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

	return 0;
}


Measured memory_bytes: 3328