akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

int main(void){
	
	char str[26][(int)'Z'][6];
	int H,W;
	int i,j;

	scanf("%d %d",&H,&W);

	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			scanf("%s",str[i][j]);
		}
	}
	

	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(strcmp("snuke",str[i][j])==0){break;}
		}
			if(strcmp("snuke",str[i][j])==0){break;}
	}

	printf("%c%d\n",(char)(j+(int)'A'),i+1);
	return 0;

}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	static class Tuple {
		int l, r;

		Tuple(String line) {
			String[] tokens = line.split(" ");
			this.l = Integer.parseInt(tokens[0]);
			this.r = Integer.parseInt(tokens[1]);
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int Q = Integer.parseInt(in.readLine());
		Tuple[] tuples = new Tuple[Q];
		for (int i = 0; i < Q; ++i) {
			tuples[i] = new Tuple(in.readLine());
		}
		// rの最大を求める
		int max = Integer.MIN_VALUE;
		for (Tuple tuple : tuples) {
			max = Math.max(max, tuple.r);
		}
		// ふるいでprimesを求める
		List<Integer> primes = getPrimes(max);
		Set<Integer> set = new HashSet<>();
		set.addAll(primes);
		// 条件を満たす数を求める
		List<Integer> valids = getValids(primes, set);

		for (int i = 0; i < tuples.length; ++i) {
			System.out.println(calc(tuples[i], valids));
		}

	}

	static int calc(Tuple tuple, List<Integer> valids) {
		int left = Collections.binarySearch(valids, tuple.l);
		int right = Collections.binarySearch(valids, tuple.r+1);
		if (left < 0) {
			left = -1 * (left + 1);
		}
		if (right < 0) {
			right = -1 * (right + 1);
		}
		return right - left ;
	}

	static List<Integer> getValids(List<Integer> primes, Set<Integer> primeSet) {
		List<Integer> valids = new ArrayList<>();
		for (Integer prime : primes) {
			if (primeSet.contains((prime + 1) / 2)) {
				valids.add(prime);
			}
		}
		Collections.sort(valids);
		return valids;
	}

	static List<Integer> getPrimes(int max) {
		boolean[] conds = new boolean[max + 1];
		Arrays.fill(conds, true);
		conds[0] = false;
		conds[1] = false;
		List<Integer> primes = new ArrayList<>();
		for (int i = 2; i <= max; ++i) {
			if (!conds[i]) {
				continue;
			}
			primes.add(i);
			// ふるい
			for (int j = i + i; j <= max; j += i) {
				conds[j] = false;
			}
		}
		return primes;
	}
}


Measured memory_bytes: 58372
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c)
	fmt.Scan(&k)

	max := Max(a, b, c)
	total := a + b + c - max + max*Pow(2, k)

	fmt.Println(total)
}

func Max(as ...int) int {
	max := as[0]
	for _, a := range as {
		if max < a {
			max = a
		}
	}
	return max
}

func Pow(a, b int) int {
	pow := 1
	for i := 0; i < b; i++ {
		pow *= a
	}
	return pow
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = 1e9+7;

map<int,int> par;
vector<vector<int>> e;
void rec(int now,int p){
	par[now] = p;
	for(int v:e[now]){
		if(v != p)rec(v,now);
	}
}

int main(){
	int n;
	cin >> n;
	ll k;
	cin >> k;
	e.resize(n);
	for(int i = 0;i < n-1;i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	rec(0,-1);
	par[0] = 0;
	map<P,ll> mp;
	for(int i = 1;i < n;i++){
		mp[P(par[par[i]],par[i])]++;
	}

	ll ans = k;
	for(ll i = 1;i <= mp[P(0,0)];i++){
		ans *= (k - i);
		if(ans <= 0){
			cout << 0 << endl;
			return 0;
		}
		ans %= MOD;
	}

	for(auto p:mp){
		if(p.first != P(0,0)){
			for(ll i = 1;i <= p.second;i++){
				ans *= (k - 1 - i);
				if(ans <= 0){
					cout << 0 << endl;
					return 0;
				}
				ans %= MOD;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 22528
#include<stdio.h>
int main(void)
{
	int a[10000],r,c,b,d=0,e,f=0;
	scanf("%d%d",&r,&c);
	for(b=0;b<r*c;b++){
		scanf("%d",&a[b]);
	}
	for(b=0;b<r*c;b++){
		printf("%d ",a[b]);
		d+=a[b];
		if((b+1)%c==0){
			printf("%d\n",d);
			f+=d;
			d=0;
		}
	}
	for(b=0;b<c;b++){
		for(e=b;e<r*c;e=e+=c){
			d+=a[e];
		}
		printf("%d ",d);
		d=0;
	}
	printf("%d\n",f);
	return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  string s;
  int ans[32]={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<<ans[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i = a;i<=b;++i)
#define For_(i,a,b) for(int i = a;i>=b;--i)
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
inline int read(){
    register int r = 0,f = 1;
    register char c = getchar();
    while(c<'0' || c >'9'){
        if(c =='-') f = -1;
        c = getchar();
    }
    while(c>='0' && c<='9'){
        r = (r<<1) + (r<<3) + c - '0';
        c = getchar();
    }
    return r * f;
}
const int N = 100 + 2 , INF = 0x3f3f3f3f;


int main(){
    string s;
    cin>>s;
    if(s[s.size()-1] == 's') cout<<s+"es"<<endl;
    else cout<<s+"s"<<endl;
    system("pause");
    return 0;
}


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


int main()
{

    long long n;

    cin >> n;


    long long a[n] , b[n];


    for(int i=0; i<n; i++)
    {
        cin >> a[i];

        b[i] = a[i];
    }

    long long count = 1;


    int flag = 0;

    for(int i=0; i<n; i++)
    {
        if(count==a[i])
        {
            count++;
            flag = 1;
        }
    }

    if(flag==1)
    {
        cout << n-count+1 << endl;
    }
    else
    {
        cout << -1 << endl;

    }




    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>
int main(void){
char data[10000000];
int sum = 0;

scanf("%s", &data);

int length = strlen(data);

for(int i = 0; i < length; i++) {
    sum = sum + (data[i] - '0');
   }

if((sum % 9) == 0) {
    printf("Yes");
  }    

else if((sum % 9) != 0) {
    printf("No");
  }
    
}



Measured memory_bytes: 2320
#include <iostream>
#include <string>

const int N = 101;
const int INF = (int) (2e9);

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

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    int n, nums[N];
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> nums[i];
    }
    int res = INF;
    for (int y = -100; y <= 100; ++y) {
        int cost = 0;
        for (int i = 0; i < n; ++i) {
            cost += (nums[i] - y) * (nums[i] - y);
        }
        res = cost < res ? cost : res;
    }
    std::cout << res << '\n';
    return 0;
}

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

int main() {
  string S;
  int w;
  cin >> S >> w;

  string ans = "";
  for (int i = 0; i < S.size(); i++) {
    if (i % w == 0) ans += S[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N;
    set<ll> s;
    rep(i,N) {
        cin>>A;
        s.insert(A);
    }
    cout<<(s.size() == N ? "YES" : "NO")<<endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
#define IOS  cin.tie(0),cout.tie(0); ios::sync_with_stdio(false);
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
 
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main() {
  IOS
  ll n, k;
  cin >> n >> k;
  
  int exp_num = 0;
  while(true) {
    if(pow(k,exp_num) > n) {
      break;
    }
    exp_num += 1;
  }
  cout << exp_num;

  return 0;
}

Measured memory_bytes: 384
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::max;
use std::fs::read;

fn main() {
    let mut a:usize = read!();
    let mut b:usize = read!();
    println!("{}",(a+b*2)/(b*2+1));
}

Measured memory_bytes: 2168
a = int(input())

if 1 <= a <= 1000:
    print(1000-a)
elif 1001 <= a <= 2000:
    print(2000 - a)
elif 2001 <= a <= 3000:
    print(3000 - a)
elif 3001 <= a <= 4000:
    print(4000 - a)
elif 4001 <= a <= 5000:
    print(5000 - a)
elif 5001 <= a <= 6000:
    print(6000 - a)
elif 6001 <= a <= 7000:
    print(7000 - a)
elif 7001 <= a <= 8000:
    print(8000 - a)
elif 8001 <= a <= 9000:
    print(9000 - a)
elif 9001 <= a <= 10000:
    print(10000 - a)


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
ll A[int(1e5+5)], ans[int(1e5+5)];
Pli P[int(1e5+5)];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> A[i]; P[i] = {A[i], i};
  }
  sort(P, P + N, greater<Pli>());

  int m = N; ll sum = 0, sum2 = 0;
  for (ll i = 0; i < N; i++){
    if (m > P[i].se){
      ans[m] = sum - (P[i].fi * i + sum2);
      m = P[i].se;
      sum2 = sum - P[i].fi * i;
    }
    sum += P[i].fi;
  }
  ans[m] += sum - sum2;

  for (int i = 0; i < N; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 6700
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   ll x,y,z,K;
           cin>>x>>y>>z>>K;
           vll a(x),b(y),c(z);
           rep(i,0,x)cin>>a[i];rep(i,0,y)cin>>b[i];rep(i,0,z)cin>>c[i];
           sort(all(a)); sort(all(b)); sort(all(c));
           reverse(all(a));reverse(all(b));reverse(all(c));
           priority_queue<ll, vector<ll>, greater<ll>> pq;
           ll mn=inf;
           ll cnt=0;
           rep(i,0,x){
			rep(j,0,y){
             rep(k,0,z){
               cnt++;
               if(cnt<=3000){
                pq.push(a[i]+b[j]+c[k]);
                mn=pq.top();
               }
               else{
                if(a[i]+b[j]+c[k]>mn){
                  pq.push(a[i]+b[j]+c[k]);
                  pq.pop();
                  mn=pq.top();
                }
                 else{
                  break; 
                 }
               }
             }
            }
           }
           while(pq.size()>K)pq.pop();
           vll ans(K);
           rep(i,0,K){
            ans[K-i-1]=pq.top();
             pq.pop();
             
           }
           rep(i,0,K){
            cout<<ans[i]<<endl; 
           }
}

Measured memory_bytes: 3712
# Aizu Problem ITP_1_7_C: Spreadsheet
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


n, m = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for __ in range(n)]

for row in range(n):
    A[row].append(sum(A[row]))

for row in A:
    print(' '.join([str(r) for r in row]))

last = []
for col in range(m):
    last.append(sum([A[row][col] for row in range(n)]))
last.append(sum(last))
print(' '.join([str(l) for l in last]))

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

using namespace std;

int digits (long x);

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

    long a;
    for (long i = 1L; i * i <= n; i++) {
        if (n % i == 0) {
            a = i;
        }
    }

    long b = n / a;
    cout << max(digits(a), digits(b)) << endl;

    return 0;
}

int digits (long x)
{
    int digit = 0;
    while (x != 0) {
        digit++;
        x /= 10;
    }

    return digit;
}

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

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

const ll mod = 1000000007;

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

    // 圧縮
    int cnt[n];
    rep(i,n) cnt[i] = 0;
    int idx = 0;
    int c = 1;
    if (s[0] == '0') {
        cnt[0] = 0;
        idx++;
    }
    rep(i,n-1) {
        if (s[i] != s[i+1]) {
            cnt[idx] = c;
            c = 1;
            idx++;
        } else {
            c++;
        }
    }
    cnt[idx] = c;
    idx++;
    if (s[n-1] == '0') {
        cnt[idx] = 0;
        idx++;
    }

    // 尺取り
    int ans = 0;
    int nsum = 0;
    if (2*k+1 >= idx) {
        for (int c:cnt) nsum += c;
        cout << nsum << endl;
        return 0;
    }
    rep(i,2*k+1) nsum += cnt[i];
    ans = nsum;
    for (int i = 2*k+1; i < idx; i += 2) {
        nsum = nsum - cnt[i-2*k-1] - cnt[i-2*k] + cnt[i] + cnt[i+1];
        ans = max(ans, nsum);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4076
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

int main() {

char *array[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};

char test[3];
int idx = 0;
scanf("%s",&test);
for (int i=0;i<7;i++){
    if (strcmp(test,array[i])==0){
            idx=i;
            break;}
}
if (idx+1==7){printf("7");}
else {
printf("%d",7-(idx+1));
}

return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define bl bool
#define INF 1e+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int main(){
	ll n,k;
	read(n),read(k);
	ll ans=0;
	for(ll i=22;i<=k;i++)
	{
		ll first=i%10;
		ll second=i/10;
		if(first<2 || second<2){
			continue;
		}
		if(first*second<=n){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int gcd(int a,int b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}
int main(){
    int n,ans,a;
    scanf("%d %d",&n,&ans);
    for(int i=1;i<n;i++){
        scanf("%d",&a);
        ans=gcd(a,ans);
    }
    printf("%d\n",ans);
}

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

int main()
{   
    int n;
    string s;
    cin>>n>>s;
    int sum=0;
    
    for(int i=1;i<n;i++){
        if(s[i]=='E') sum++;
    }
    int ans=sum;
    for(int i=1;i<n;i++){
        if(s[i]=='E') sum--;
        if(s[i-1]=='W') sum++;
        if(ans>sum) ans=sum;
    }
    cout<<ans<<endl;


    
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int getint() {
	char C;
	while (!isdigit(C = getchar()));
	int A = C - '0';
	while (isdigit(C = getchar())) A = A * 10 + C - '0';
	return A;
}

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


	int N;
	N = getint();
	int A[200001] = {};

	int mae = 0;
	ll kotae = 1;
	ll mod = 1e9 + 7;
	rep(i, N) {
		int C;
		C = getint();
		if (mae != C) kotae = (kotae + A[C]) % mod;
		A[C] = kotae;
		mae = C;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n;
	scanf("%d",&n);
	int t,a,b,now_a=0,now_b=0,now_t=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d%d",&t,&a,&b);
		int x=fabs(a-now_a),y=fabs(b-now_b);
		int sum=x+y;
		if((sum%2)&&!((t-now_t)%2)){
			puts("No");
			return 0;
		}
		if(!(sum%2)&&((t-now_t)%2)){
			puts("No");
			return 0;
		}
		if(sum>t-now_t) {
			puts("No");
			return 0;
		}
		now_a=a,now_b=b,now_t=t;
	}
	puts("Yes");
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int ans,count,key;
    
    for(int i=1;i<=N;i++){
        key = i;
        while (key > 0)
        {
            key /= 10;
            count++;
        }
        if(count %2 != 0)ans++;
        count = 0;
    }
    cout << ans << endl;



}

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

int main(){
        int n, m;
        while (cin >> n >> m && n != 0 || m != 0){
                int money = 0;
                vector<int> a(n);
                for (int i = 0; i < n; i++) cin >> a[i];
                for (int i = 0; i < n - 1; i++){
                        for (int j = i + 1; j < n; j++){
                                if (a[i] + a[j] <= m) money = max(money, a[i] + a[j]);
                        }
                }
                if (money == 0) cout << "NONE" << endl;
                else cout << money << endl;
        }
        return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;

int h, w, k;
string s[800];
int minCost[800][800];

int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
bool is_range(int r, int c) {
	return (0 <= r && r < h && 0 <= c && c < w);
}

int main() {
	int i, j;
	int sy, sx;
	
	cin >> h >> w >> k;
	for (i = 0; i < h; i++) {
		cin >> s[i];
		for (j = 0; j < w; j++) {
			if (s[i][j] == 'S') {
				sy = i;
				sx = j;
			}
			minCost[i][j] = 11451419;
		}
	}
	
	typedef pair<int, int> P;
	queue<P> que;
	que.push(P(sy, sx)); minCost[sy][sx] = 0;
	
	while (!que.empty()) {
		int y = que.front().first;
		int x = que.front().second;
		que.pop();
		
		for (int dir = 0; dir < 4; dir++) {
			int ny = y + dy[dir];
			int nx = x + dx[dir];
			if (is_range(ny, nx) && s[ny][nx] != '#' && minCost[ny][nx] > minCost[y][x] + 1) {
				minCost[ny][nx] = minCost[y][x] + 1;
				que.push(P(ny, nx));
			}
		}
	}
	
	int ans = 11451419;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (minCost[i][j] > k) continue;
			//cout << i << " " << j << endl;
			
			int dist_r = min(i, h - 1 - i);
			int dist_c = min(j, w - 1 - j);
			
			ans = min(ans, 1 + (min(dist_r, dist_c) + k - 1) / k);
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int p, q, a, n;

int dfs(int x, int y, int pre_y, int cnt){
    if(x * q == y * p) return 1;
    if(cnt == n) return 0;
    if(x * q > y * p) return 0;

    int ret = 0;
    for(int yy = pre_y; y * yy <= a; yy++){
        ret += dfs(x * yy + y, y * yy, yy, cnt + 1);
    }

    return ret;
}

int main(void){
    for(; cin >> p >> q >> a >> n, p;){
        cout << dfs(0, 1, 1, 0) << endl;
    }

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n,i,j,nr;
char sir[100010];
int main()
{
    cin>>n;
    cin>>sir;
    for(i=0;i<n;i++)
    {
        while(sir[i]==sir[i+1])
            i++;
        nr++;
    }
    cout<<nr;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	int n, k;
	int ans;
	
	cin >> n >> k;
	
	ans = k;
	
	for (int i = 1; i < n; i++) {
		ans *= k - 1;
	}
	
	cout << ans << endl;
	
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
	int xx,yy;
	cin >> xx >> yy;
	
	
	int ta,tb;
	ta = yy - 2 * xx;
	tb = 4 * xx - yy;
	
	if( ta%2 == 0 && ta >=0 && tb >=0 && tb%2==0) cout <<"Yes" <<endl;
	else cout << "No" << endl;
	
	
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s1;
string s2;
int n;
const int inf = 1000000007;
long long ans;
int same(int prev)
{
    if(prev == 1){
        ans = ans * 2;
    }
    if(prev == 0){
        ans = ans * 3;
    }
    s1.erase(s1.size() - 1, 1);
    s2.erase(s2.size() - 1, 1);
    ans = ans % inf;
    return 1;
}

int dif(int prev)
{
    if(prev == 2){
        ans = ans * 3;
    }
    if(prev == 1){
        ans = ans * 2;
    }
    if(prev == 0){
        ans = ans * 6;
    }
    s1.erase(s1.size() - 1, 1);
    s1.erase(s1.size() - 1, 1);
    s2.erase(s2.size() - 1, 1);
    s2.erase(s2.size() - 1, 1);
    ans = ans % inf;
    return 2;
}
    

int main()
{
    int prev = 0;
    ans = 1;
    cin >> n >> s1 >> s2;
    while(s1.size() > 0){
        if(s1[s1.size() - 1] == s2[s2.size() - 1])
        {
            prev = same(prev);
        } else {
            prev = dif(prev);
        }
    }
    cout << ans << endl;
    return 0;
}

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


int x,cnt1[100005],cnt2[100005],mx1,mx2,x1,x2;
int main(){
  ll n;
  cin >> n;
  vector<ll> v(n);
  for(ll i=0;i<n;++i){
    cin >> x;
    if(i%2==0){
      cnt1[x]++;
      if(mx1<cnt1[x]){
        mx1=cnt1[x];
        x1=x;
      }
    }
    else{
      cnt2[x]++;
      if(mx2<cnt2[x]){
        mx2=cnt2[x];
        x2=x;
      }
    }
  }
  sort(cnt1,cnt1+100005,greater<int>());  
  sort(cnt2,cnt2+100005,greater<int>());
  if(x1!=x2) cout << n-mx1-mx2 << endl;
  else cout << n-max(mx1+cnt2[1],mx2+cnt1[1]) << endl;
  }

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)

vector<pair<ll,int>> factorization(ll N){
    vector<pair<ll,int>> ans;
    ll i=2;
    int counter;
    while(true){
        if(N==1) break;
        if(N%i!=0) i++;
        else{
            counter=0;
            while(N%i==0){
                N=N/i;
                counter++;
            }
            ans.push_back(make_pair(i,counter));
            i++;
        }
    }
    return ans;
}

int main(){
    vector<pair<ll,int>> vec;
    int N;
    ll M;
    cin>>N>>M;
    vec=factorization(M);  
    int dp[100][100000];
    rep(i,100) rep(j,N) dp[i][j]=0;
    rep(i,100) dp[i][0]=1;
    Rep(j,N-1){
        rep(i,100){
            rep(k,i+1) dp[i][j]=(dp[i][j]+dp[i-k][j-1])%mod;
        }
    }
    ll ans=1;
    pair<ll,int> p;
    while(!vec.empty()){
        p=vec.back();
        vec.pop_back();
        ans=(ans*dp[p.second][N-1])%mod;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 39296
#include <stdio.h>

int main(){
  
  int i, j, k,n,m,l;
  int a[101][101], b[101][101];
  long c[101][101];
  
  scanf ("%d%d%d",&n,&m,&l);
    
  for (i = 0;i < n;i++){
    for (j = 0;j < m;j++){
      scanf ("%d",&a[i][j]);	
    }
  }
  
  for (i = 0;i < m;i++){
    for (j = 0;j < l;j++){
      scanf ("%d",&b[i][j]);
    }
  }
  
  
  for(i = 0;i < n;i++){
    for(j = 0;j < l;j++){
      
      c[i][j] = 0;
      
      for (k = 0;k < m;k++){
	c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  
  for(i = 0;i < n;i++){
    for(j = 0;j < l-1;j++){
      printf("%ld ",c[i][j]);
    }
    printf ("%ld\n",c[i][j]);
  }
  
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    ll n, a, b; cin >> n >> a >> b;
    vector<ll> x(n);
    for(ll i=0; i<n; i++) cin >> x.at(i);

    ll sum=0;
    for(int i=0; i<n-1; i++)    sum += min(b, (x[i+1]-x[i])*a);

    cout << sum << endl;
       
}



Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let (_n, a, b): (usize, usize, usize) = util::get3();
    let xs: Vec<usize> = util::gets();

    println!(
        "{}",
        xs.windows(2).map(|v| min(a * (v[1] - v[0]), b)).fold(
            0,
            |x, y| x + y,
        )
    );
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

ll n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n >> m;
  // half num of squares
  if (n == 1 || m == 1)
    cout << 1;
  else
    cout << (n * m + 1) / 2;
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>;
#include <vector>;
using namespace std;
int main() {
 int a,b,c,i,k; string name;
 cin >> a >> b >> k;
 i = 0;
 while (2 * k > 1) {
  if (i == 0) {
   a = (a - (a % 2)) / 2;
   b = b + a;
  }
  else {
   b = (b - (b % 2)) / 2;
   a = a + b;
  }
  i = (i + 1) % 2;
  k = k - 1;
 }
 cout << a << " " << b;
 return 0; 
} 

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  vi32 v = {a, b, c};
  sort(all(v));
  if (v[0] == v[1] && v[1] != v[2]) {
    yes();
  }
  if (v[0] != v[1] && v[1] == v[2]) {
    yes();
  }
  no();
}


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


def solve(S: str):
    if datetime.strptime(S, "%Y/%m/%d") <= datetime.strptime("2019/4/30", "%Y/%m/%d"):
        print("Heisei")
    else:
        print("TBD")


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,n) for(i=0;i<n;i++)in(v[i]);
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define cf(n) printf("%I64d\n",n)
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
typedef long long int ll;
#define N 2000005
int main()
{
    int a,b,t;
    in3(a,b,t);
    t/=a;
    cout << b*t << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

                int e = a*b;
                int f = c*d;

                System.out.println(Math.max(e,f));
        }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int A = 0;
  
  for(int i = 0; i < N; i++){
      int x;
      cin >> x;
      if(x * 2 < K){
          A += x * 2;
      }
      else{
          A += ( K - x ) * 2;
      }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  N = int(readline())
  H = np.array(readline().split(), dtype = np.int32)
  
  def F(L,R):
    if R<L:
      return 0
    idx = L + H[L:R+1].argmin()
    x = H[idx]
    H[L:R+1] -= x
    return x + F(L, idx-1) + F(idx+1,R)
  
  answer = F(0,N-1)
  print(answer)
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 15336
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  pair<int,int> a[6];
  rep(i,6){
    cin>>a[i].fst>>a[i].scd;
    if(a[i].fst<a[i].scd) swap(a[i].fst,a[i].scd);
  }
  sort(a,a+6);
  if(a[0]==a[1] && a[2]==a[3] && a[4]==a[5]){
    int x=a[0].fst,y=a[0].scd;
    int x2[2]={a[2].fst,a[2].scd},y2[2]={a[4].fst,a[4].scd};
    rep(i,2){
      rep(j,2){
	if(x==x2[i] && y==y2[j] && x2[1-i]==y2[1-j]){
	  cout<<"yes"<<endl;
	  return 0;
	}
	if(y==x2[i] && x==y2[j] && x2[1-i]==y2[1-j]){
	  cout<<"yes"<<endl;
	  return 0;
	}
      }
    }
  }
	
  cout<<"no"<<endl;
  

  return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  int cnt = 1;
  while (cnt < b) {
    cnt = cnt-1+a;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	var cnt, both, head, tail int
	for i := 0; i < N; i++ {
		s := ReadString()
		for j := 0; j < len(s)-1; j++ {
			if s[j] == 'A' && s[j+1] == 'B' {
				cnt++
			}
		}
		h := s[0] == 'B'
		t := s[len(s)-1] == 'A'
		if h && t {
			both++
		} else if h {
			head++
		} else if t {
			tail++
		}
	}

	if head+tail == 0 && both > 0 {
		fmt.Println(cnt + both - 1)
	} else {
		fmt.Println(cnt + both + Min(head, tail))
	}
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

typedef long long ll;
typedef long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = ll(b)-1; i >= (a); i--)
#define MAPIT(i,c,k) for (auto i = (c).equal_range((k)).first; i!= (c).equal_range((k)).second; i++)

#define sz(c) ll((c).size())
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second
#define has(c, i) ((c).find(i) != (c).end())
#define DBG(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })


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

	ll H, W, N;

	cin >> H >> W >> N;

	map<pll, ll> colored;

	FOR(i, 0, N){
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		FOR(j, -1, 2) FOR(k, -1, 2){
			int na = a + j;
			int nb = b + k;

			if(na < 0 || nb < 0 || na >= H || nb >= W) continue;

			colored[mp(na, nb)]++;
		}
	}

	vector<ll> erg(10);
	erg[0] = (H-2) * (W-2);

	for(auto& e : colored){
		if(e.xx.xx == 0 || e.xx.yy == 0 || e.xx.xx == H-1 || e.xx.yy == W-1) continue;

		erg[e.yy]++;
	}

	FOR(i, 1, 10) erg[0] -= erg[i];

	FOR(i, 0, 10) cout << erg[i] << endl;
}

Measured memory_bytes: 56576
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

int main(int argc, char *argv[]) {
	LL n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	LL g = gcd(n, m);
	bool ok = true;
	for (LL i = 0; i < g; ++i) {
		if (s[(s.length() / g) * i] != t[(t.length() / g) * i]) {
			ok = false;
		}
	}
	LL len = lcm(n, m);
	cout << (ok ? len : -1) << endl;
	return 0;
}


Measured memory_bytes: 888
#include <climits>
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN = 1E5 + 10;

int n;
int val[MAXN];
int dep[MAXN];
vector<int> E[MAXN];

int level;
int ansFlag = true;
int l[MAXN], r[MAXN];
int ans[MAXN];

void DFS1(int u, int pre){
	if (val[u] >= 0){
		ansFlag &= ((dep[u] ^ val[u]) & 1) == level;
		l[u] = val[u], r[u] = val[u];
	}
	else
		l[u] = -1E7, r[u] = 1E7;
	for (int v, i = 0; i < E[u].size(); ++i){
		if ((v = E[u][i]) == pre)
			continue;
		dep[v] = dep[u] + 1;
		DFS1(v, u);

		l[u] = max(l[u], l[v] - 1);
		r[u] = min(r[u], r[v] + 1);
	}
	if (l[u] > r[u])
		ansFlag = false;
}

void DFS2(int u, int pre){
//	printf("%d %d %d, %d\n", u, l[u], r[u], ans[u]);
	for (int v, i = 0; i < E[u].size(); ++i){
		if ((v = E[u][i]) == pre)
			continue;
		ans[v] = ans[u] + 1 <= r[v] ? ans[u] + 1 : ans[u] - 1;
		DFS2(v, u);
	}
}

int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		val[i] = -1;
	for (int u, v, i = 1; i < n; ++i){
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	int K;
	scanf("%d", &K);
	int root = -1;
	for (int v, p, i = 0; i < K; ++i){
		scanf("%d%d", &v, &p);
		val[v] = p;
		root = v;
	}
	level = val[root] & 1;
	DFS1(root, 0);
	if (ansFlag){
		ans[root] = val[root];
		DFS2(root, 0);
		puts("Yes");
		for (int i = 1; i <= n; ++i)
			printf("%d\n", ans[i]);
	}
	else
		puts("No");
	return 0;
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double


using namespace std;
const int N = 1e5 + 5;


int main(){
    ll n, x, t; cin >> n >> x >> t;
    ll nm = (n / x);
    if(n % x)nm++;
    cout << nm * t ;
    return 0;
}


Measured memory_bytes: 3628
S = str(input())

R = 0
L = 0
R_i = 0
L_i = 0
R_line = 0
L_line = 0
hoge = [0] * len(S)

for i in range(len(S) - 1):
    if S[i] == "R" and S[i + 1] == "L":
        R_i = i
        L_i = i + 1
    if (S[i] == "L" and S[i + 1] == "R"):
        L_line = i
        hoge[R_i] = ((R_i - R_line) // 2) + ((L_line - L_i + 1) // 2) + 1
        hoge[L_i] = ((R_i - R_line + 1) // 2) + ((L_line - L_i) // 2) + 1
        R_line = i+1
    elif i == len(S)-2:
        L_line = i+1
        hoge[R_i] = ((R_i - R_line) // 2) + ((L_line - L_i + 1) // 2) + 1
        hoge[L_i] = ((R_i - R_line + 1) // 2) + ((L_line - L_i) // 2) + 1
        R_line = i

for i in range(len(hoge)):
    print(hoge[i],end = " ")



Measured memory_bytes: 51544
import java.util.Scanner;
 
 
public class Main {
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[][][] data = new int[4][3][10];
         
        for(int i = 0; i < n; i++) {
            int b = stdIn.nextInt();
            int f = stdIn.nextInt();
            int r = stdIn.nextInt();
            int v = stdIn.nextInt();
             
            data[b-1][f-1][r-1] += v;
        }
         
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 3; j++) {
                for(int k = 0; k < 10; k++) {
                    System.out.print(" " + data[i][j][k]);
                }
                System.out.println();
            }
            if(i != 3) {
            System.out.println("####################");
            }
        }
    }
 
}


Measured memory_bytes: 29892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,K;

  cin >> N >> K;

  vector<int> A(N);

  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }

  map<int,int> bv;

  for(int i=0;i<N;i++) {
    if(bv[A.at(i)]) bv[A.at(i)]++;
    else bv[A.at(i)] = 1;
  }
  //各数値のボールの数を記録

  if(bv.size()<=K){
    cout << 0 << endl;
    return 0;   
  }//最初から条件を満たしていた場合

  priority_queue<int> bvp;

    for(pair<int,int> p : bv) {
      int key = p.first;
      int value = p.second;

      bvp.push(value);
      
    }//各種のボール数を優先キューに格納

    int res=0;//残るボールの数

    for(int i=0;i<K;i++){
      res+=bvp.top();
      bvp.pop();
    }//種類あたりの個数が多いものからK種類、残すボールに加える
  
  cout << N-res << endl;//全ボール-残すボール
 
  return 0;
}

Measured memory_bytes: 11516
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
typedef long long ll;
const ll INF=1ll<<60;
template<class T>inline bool chmin (T& a,T b){if(a>b){a=b;return 1;} return 0;}
template<class T>inline bool chmax(T& a, T b){if(a<b){a=b;return 1;} return 0;}

int N;
ll W,w[110],v[110];
ll dp[110][1000010]={0};
int main(){
  cin >> N >> W;
  FOR(i,0,N) cin >> w[i] >> v[i];
  FOR(i,0,N){
    FOR(sumw,0,W+1){
      if(sumw-w[i]>=0)
        chmax(dp[i+1][sumw],dp[i][sumw-w[i]]+v[i]);
      
      chmax(dp[i+1][sumw],dp[i][sumw]);
    }
  }
  
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 286976
fun main(args : Array<String>) {
    val (h, w) = readLine()!!.split(" ").map{it.toInt()}

    for (i in 0 until h) {
        val row = readLine()!!.split(" ")
        for (j in 0 until w) {
            if (row[j] == "snuke") {
                println("${(j+65).toChar()}${i+1}")
                return
            }
        }
    }
}

Measured memory_bytes: 37884
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int n;
string s;
ll dp[111111][4];

ll solve(int p, int a)
{
	if (p == n)
	{
		if (a == 3) return 1;
		else return 0;
	}
	if (dp[p][a] >= 0) return dp[p][a];
	ll res = 0;
	if (s[p] == '?')
	{
		if (a == 3)
		{
			res = solve(p + 1, a) * 3;
		}
		else
		{
			res += solve(p + 1, a + 1);
			res += solve(p + 1, a) * 3;
		}
	}
	else if (a == 3)
	{
		res = solve(p + 1, a);
	}
	else if (s[p] == "ABC"[a])
	{
		res += solve(p + 1, a + 1);
		res += solve(p + 1, a);
	}
	else
	{
		res += solve(p + 1, a);
	}
	return dp[p][a] = res % MOD;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	MS(dp, -1);
	cin >> s;
	n = s.size();
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 8656
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input()
s = s.replace("BC", "D")
n = len(s)
for i in range (n):
  if s[i] == "A":
    count += 1
  elif s[i] == "D":
    ans += count
  else:
    count = 0
print(ans)



Measured memory_bytes: 43504
import math
 
a,b,x = map(int, input().split())
 
def over_flag(a,b,x):
    return math.atan( 2*b/a-2*x/a**3 )*180/math.pi
 
def below_flag(a,b,x):
    return 90-math.atan(2*x/(a*b**2))/math.pi*180
 
def main(a,b,x):
    if x>a**2*b:
        print(0)
        return 0
    if x>a**2*b/2:
        print(over_flag(a,b,x))
    else:
        print(below_flag(a,b,x))
    return 0
main(a,b,x)

Measured memory_bytes: 3060
n = int(input())
K=[]
P=[]
while len(K)<n:
  k,p = map(int, input().split())
  K.append(k)
  P.append(p)

for i in range(n):
  a = K[i]
  b = P[i]
  if a%b !=0:
    print(a%b)
  else:
    print(b)




Measured memory_bytes: 5604