akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,A,B,C;
    int MP=10000;
    cin>>N>>A>>B>>C;
    vector<int>L;
    int l;
    for(int i=0;i<N;i++){
        cin>>l;
        L.push_back(l);
    }
    int n=pow(4,N);
    for(int i=0;i<n;i++){
        int num=i;
        int L_A=0,L_B=0,L_C=0;
        int n_A=0,n_B=0,n_C=0;
        for(int j=0;j<N;j++){
            int b=pow(4,N-j-1);
            switch(num/b){
                case 1:
                    L_A+=L[j];
                    n_A++;
                    break;
                case 2:
                    L_B+=L[j];
                    n_B++;
                    break;
                case 3:
                    L_C+=L[j];
                    n_C++;
                    break;
            }
            num%=b;
        }
        if(n_A==0||n_B==0||n_C==0){continue;}
        int m=10*(n_A-1)+10*(n_B-1)+10*(n_C-1)+abs(A-L_A)+abs(B-L_B)+abs(C-L_C);
        if(m<MP){MP=m;}
    }
    cout<<MP<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int count = 0;
    for (int i = 1; i < N + 1; i++)
    {
        int p;
        cin >> p;
        if (p != i)
        {
            ++count;
        }
    }
    if (count <= 2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B, C, D = map(int, input().split())

while A > 0 and C > 0:
    C -= B
    A -= D

print("Yes" if C <= 0 else "No")

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

using namespace std;

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

int A[200];
int main(){
    int N;
    cin >> N;
    REP(i,N){
        int a;
        cin >> a;
        A[i] = a;
    }

    double ave = 0.0;
    REP(i,N){
        ave += A[i];
    }
    ave /= N;

    int uave = ceil(ave);
    int lave = floor(ave);

    ll ans = 0;
    ll unum = 0;
    ll lnum = 0;
    REP(i,N){
        unum += (A[i] - uave)*(A[i] - uave);
    }
    REP(i,N){
        lnum += (A[i] - lave)*(A[i] - lave);
    }

    ans = min(unum, lnum);
    cout << ans << endl;
    return 0;
}


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

long long N, P;
string S;

long long memo[200005];
map<long long, long long>pcount;
long long kaidan[10000000];

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= P;
		}
		ori *= ori;
		ori %= P;
		po >>= 1;
	}
	return res;
}


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

	if(P == 2 || P == 5){
		long long num = 0;
		for(long long i = 0; i < N; i++) {
			if((S[i] - '0') % P == 0) {
				num +=  i + 1;
			}
		}
		cout << num << endl;

		return 0;
	}

	for(long long i = 0; i < N; i++) {
		memo[i+1] = memo[i] + (S[N-1-i] - '0') * modpow(10, i);
		memo[i+1] %= P;
		pcount[memo[i+1]]++;
	}
	//for(long long i = 0; i <= N; i++) {
	//	cout << "memo[" << i << "] = " << memo[i] << endl;
	//}


	long long ans = 0;
	for(auto item: pcount) {
		//cout << item.first << ", " << item.second << endl;
		if(item.first == 0) {
			ans += (item.second * (item.second - 1))/2 + item.second;
		} else {
			ans += (item.second * (item.second - 1))/2;
		}
	}
	cout << ans << endl;
}



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

int main()
{
	string s;
	cin >> s;
	if(s.size()==2)
	{
		if(s[0]==s[1])
		{
			cout<<1<<' '<<2<<endl;
		}
		else
		{
			cout<<-1<<' '<<-1<<endl;
		}
		
		return 0;
	}
	rep(i,s.size()-2)
	{
		if(s[i]==s[i+1])
		{
			cout<<i+1<<' '<<i+2<<endl;
			return 0;
		}
		else if(s[i]==s[i+2])
		{
			cout<<i+1<<' '<<i+3<<endl;
			return 0;
		}
		else if(s[i+1]==s[i+2])
		{
			cout<<i+2<<' '<<i+3<<endl;
			return 0;
		}
	}
	cout<<-1<<' '<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null)
    for{
      in <- inputs
      val Array(h, w, _*) = in.split(" ").map(_.toInt)
      }{
        if(h != 0 && w != 0){
          println((List.tabulate(h,  w){(i,  j) =>
            if(j == w-1) "#\n"
            else if(i == 0 || i == h-1 || j == 0 || j == w-1) "#"
            else "."
          }).flatten.mkString)
        }
      }
  }
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    ll n, sum=0, k;
    cin >> n >> k;
    vector<ll> v;
    for(ll i = 0; i < n; i++)
    {

        ll x;
        cin >> x;
        v.pb(x);
    }

    ll ans = 1;
    for(ll i = 0; i < v.size(); i++)
    {
        sum+=v[i];
        if(sum <= k) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
l.reverse()
a=b=c=d=0
for i in l:
  if a==0:
    a=i
  elif b==0:
    b=i
    if a!=b:
      a=b
      b=0
  elif c==0:
    c=i
  elif d==0:
    d=i
    if c!=d:
      c=d
      d=0
  else:
    break
print(b*d)

Measured memory_bytes: 14252
#include <stdio.h>

int main(){
   int i, x, n;
   scanf("%d",&n);
   for(i=1;i<=n;i++){
      x=i;
      if(x%3==0){
         printf(" %d",x);
      } else {
         do {
            if(x%10==3){
               printf(" %d",i);
               break;
            }
            x/=10;
         } while(x!=0);
      }
   }
   printf("\n");
   return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<map>
#include<cmath>
typedef long long lint;
using namespace std;

template<typename T> 
void factP(map<T,T> &m,T n)
{
	T x=n;
	for(T i=2;i*i<=n;i++)
	{
		while(x%i==0)
		{
			m[i]++;
			x/=i;
		}
	}
	return;
}

int main()
{
	lint N,P;
	map<lint,lint> m;
	lint ans=1;
	
	cin >> N >> P;

	if(N==1)
	{
		cout << P << endl;
		return 0;
	}
	if(P==1)
	{
		cout << 1 << endl;
		return 0;
	}
	
	factP(m,P);
	
	for(auto&& i:m)
	{
		if(i.second<N)continue;
		ans*=pow(i.first,i.second/N);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>

using namespace std;

int n,q;
int edge[100001];
vector<int> G[100001];
int par[100001];
bool flag[100001];
int fm[100001];
char s[100001];
int v[100001];

void init(){
	for(int i=1;i<=n;i++){
		par[i]=i;
		G[i].clear();
	}
	memset(flag,false,sizeof(flag));
	memset(fm,-1,sizeof(fm));
}

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

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x!=y){
		par[x]=y;
	}

}

void unite_dfs(int v,int p){
	if(!flag[v])unite(v,p);
	else p=v;
	for(int i=0;i<G[v].size();i++){
		unite_dfs(G[v][i],p);
	}
}

int main(void){
	while(1){
		scanf("%d %d",&n,&q);
		if(n+q==0)break;
		init();
		for(int i=2;i<=n;i++){
			scanf("%d",&edge[i]);
			G[edge[i]].push_back(i);
		}
		flag[1]++;
		fm[1]=-2;
		for(int i=0;i<q;i++){
			cin >> s[i] >> v[i];
			if(s[i]=='M'){
				flag[v[i]]=true;
				if(fm[v[i]]==-1)fm[v[i]]=i;
			}
		}
		unite_dfs(1,1);
		long long res=0;
		for(int i=q-1;i>=0;i--){
			if(s[i]=='Q'){
				res+=(long long)find(v[i]);
			}
			if(s[i]=='M' && fm[v[i]]==i){
				unite(v[i],edge[v[i]]);
			}
		}
		printf("%lld\n",res);

	}
	return 0;
}

Measured memory_bytes: 12168
def getSpecies(sw, ox, swAdj):
    if (sw == 'S' and ox == 'o') or (sw == 'W' and ox == 'x'):
        return swAdj
    else:
        return 'SW'[swAdj == 'S']

N = int(input())
ss = input()

for pat in ['SS', 'SW', 'WS', 'WW']:
    anss = list(pat) + [''] * (N - 2)
    for i in range(1, N - 1):
        anss[i + 1] = getSpecies(anss[i], ss[i], anss[i - 1])

    if (getSpecies(anss[-1], ss[-1], anss[-2]) == anss[0]) \
        and (getSpecies(anss[0], ss[0], anss[-1]) == anss[1]):
        print(''.join(anss))
        break
else:
    print(-1)

Measured memory_bytes: 7276
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001

int main(void) {
	int h,w; cin >> h >> w;
	vector<string> s(h);
	rep(i,h) cin >> s[i];
	vvi cnt(h,vi(w,0));
	rep(i,h){
		vector<bool> done(w,false);
		rep(j,w){
			if( s[i][j]=='#' || done[j] ) continue;
			int l = 0;
			while( j+l<w && s[i][j+l]!='#' )l++;
			rep(k,l){
				cnt[i][j+k] += l;
				done[j+k] = true;
			}
			j+=l-1;
		}
	}
	rep(j,w){
		vector<bool> done(h,false);
		rep(i,h){
			if( s[i][j]=='#' || done[i] ) continue;
			int l = 0;
			while( i+l<h && s[i+l][j]!='#' )l++;
			rep(k,l){
				cnt[i+k][j] += l;
				cnt[i+k][j]--;
				done[i+k] = true;
			}
			i+=l-1;
		}
	}
	int ans = 0;
	rep(i,h)rep(j,w) ans = max(ans,cnt[i][j]);
	cout << ans << endl;
}




Measured memory_bytes: 20096
# D - Blue and Red Balls

N, K = map(int, input().split())

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod

mod = 10 ** 9 + 7
n = 10 ** 4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

for i in range(1, K + 1):
    B = cmb(K - 1, i - 1, mod)
    R = cmb(N - K + 1, N - K - i + 1, mod)
    print(B * R % mod)


Measured memory_bytes: 4584
using System;
using System.Collections.Generic;
using System.Linq;

class Program {

    static int Main(string[] args) {
        Dictionary<int, Dictionary<int, Dictionary<int, int>>> list = new Dictionary<int, Dictionary<int, Dictionary<int, int>>>();

        list.Add(1, InitTou());
        list.Add(2, InitTou());
        list.Add(3, InitTou());
        list.Add(4, InitTou());

        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++) {
            string[] wk = Console.ReadLine().Split(' ');
            
            int[] v = new int[wk.Length];
            for (int k = 0; k < wk.Length; k++) {
                v[k] = int.Parse(wk[k]);
            }

            list[v[0]][v[1]][v[2]] += v[3];
        }

        for (int tou = 1; tou <= 4; tou++) {
            for (int kai = 1; kai <= 3; kai++) {
                for (int heya = 1; heya <= 10; heya++) {
                    Console.Write(" ");
                    Console.Write(list[tou][kai][heya]);
                }

                Console.WriteLine(string.Empty);
            }
            if (tou < 4) {
                Console.WriteLine(new string('#', 20));
            }
        }

        return 0;
    }

    static Dictionary<int, Dictionary<int, int>> InitTou() {
        Dictionary<int, Dictionary<int, int>> list = new Dictionary<int, Dictionary<int, int>>();

        for (int k = 1; k <= 3; k++) {
            list.Add(k, new Dictionary<int, int>());

            for (int i = 1; i <= 10; i++) {
                list[k].Add(i, 0);
            }
        }

        return list;
    }
}


Measured memory_bytes: 18052
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main(){
    int h,m;
    string n,cpy;
    while(1){
        cin >> n;
        if(n == "-")break;
        cin >> m;
        for (int i = 0; i < m; i++)
        {
            cin >> h;
            cpy = n.substr(0,h);
            n = n.erase(0,h);
            n = n + cpy;
        }
        cout << n << endl;
    }

return 0;
}


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


int N;
ll cnt, cntx, cnty;
vector<bool> used(200000, 0);
vector<vector<int> > G(200000 + 10);

void dfs(int idx, int par){
    used[idx] = true;
    if(idx < 100000) cntx++;
    else cnty++;

    for(auto& to: G[idx]){
        if(to == par) continue;
        cnt++;
        if(used[to]) continue;
        dfs(to, idx);
    }
    return;
}

int main(){
    cin >> N;
    rep(i, 0, N){
        int x, y; cin >> x >> y; x--, y--;
        G[x].push_back(y + 100000);
        G[y + 100000].push_back(x);
    }
    ll ans = 0;
    rep(i, 0, 200000) if(!used[i]){
        cnt = 0;
        cnty =0;
        cntx = 0;
        dfs(i, -1);
        ans += cntx * cnty;
    }
    cout << ans - N << endl;

    return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  
  UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i  = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z; x--; y--;
    uf.unite(x, y);
  }
  
  set<int> s;
  for (int i = 0; i < n; i++) {
    s.insert(uf.root(i));
  }
  
  cout << s.size() << endl;
  return 0;
}


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

int main() {
    int N;
    while(cin >> N) {
        int count = 0;
        for (int a = 0; a < 10; a++) {
            for (int b = 0; b < 10; b++) {
                for (int c = 0; c < 10; c++) {
                    for (int d = 0; d < 10; d++) {
                        if (a + b + c + d == N) {
                            count++;
                        }
                    }
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	int person = 0;
	for(int i = 0;i < N;i++){
		int a, b;
		cin >> a >> b;
		person += b - a + 1;
	}
	cout << person << endl;
}

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

int main(){
    int n, k, q, in;
    cin >> n >> k >> q;
    vector<int> sa(n);
    rep(i, n) sa.at(i) = 0;
    rep(i, q){
        cin >> in;
        sa.at(in-1)++;
    }
    rep(i, n){
        if(k + sa.at(i) - q > 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int n;
    cin >> n;
    vi(l,n);
    int sum = 0;
    rep(i,n){
        cin >> l[i];
        sum += l[i];
    }
    srt(l);
    string ans;
    if(sum > l[n-1] * 2) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void)
{
  int n;
  scanf("%d",&n);
  double x[n+1],y[n+1];
  for(int i=1;i<=n;i++){
    scanf("%lf%lf",&x[i],&y[i]);
  }
  double length_sum=0.0;
  for(int i=1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      length_sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  int length_number=0;
  for(int i=1;i<n;i++) length_number+=i;
  double ans;
  ans=length_sum*(double)(n-1)/(double)length_number;
  printf("%lf",ans);
  return 0;
}

Measured memory_bytes: 128
N=input()
if int(N[-1])==2 or int(N[-1])==4 or int(N[-1])==5 or int(N[-1])==7 or int(N[-1])==9:
    print('hon')
elif int(N[-1])==0 or int(N[-1])==1 or int(N[-1])==6 or int(N[-1])==8:
    print('pon')
elif int(N[-1])==3:
    print('bon') 

Measured memory_bytes: 9200
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
    }
    
    Scanner sc;
    int N;
    int[] H;
    int max = 0;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        N = sc.nextInt();
        H = new int[N];
        for (int i=0; i<N; ++i){
            H[i] = sc.nextInt();
        }
    }
    
    //解答処理
    int solve() {
        int count = 0;
        for (int i=0; i<N-1; i++){
            if (H[i] >= H[i+1]){    //右隣のマスが今のマスの高さ以下であれば回数をカウント
                ++count;
            } else {
                count = 0;
            }
            max = Math.max(count,max);  //大きい方をmaxに代入
        }

        return max;
    }
    
    //出力
    void show(int answer) {
        System.out.println(answer);
    }
}

Measured memory_bytes: 59300
N, K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = -float("inf")
for i in range(N):
    hoge = []
    p = i
    s = 0
    for j in range(K):
        p = P[p]-1
        s += C[p]
        hoge.append(s)
        ans = max(ans,s)
        if p == i:
            s *= (K-1)//len(hoge)
            s += max(hoge[0:(K-1)%len(hoge)+1])
            ans = max(ans,s)
            break
print(ans)
        

Measured memory_bytes: 79820
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using namespace std;
ll x[110000],y[110000];
ll a[110000],d[110000],amax[110000],dmax[110000];
main(){
  ll n,c;
  cin>>n>>c;
  rep(i,0,n)cin>>x[i]>>y[i];

  a[0]=y[0];
  d[n-1]=y[n-1];

  rep(i,1,n) a[i]=a[i-1]+y[i];
  irep(i,n-2,0)d[i]=d[i+1]+y[i];

  // 0 to n
  ll ans1=0;
  amax[0]=max((ll)0,y[0]-x[0]);
  rep(i,1,n)amax[i]=max(a[i]-x[i],amax[i-1]);
  ans1=amax[n-1];

  // n to 0
  ll ans2=0;
  dmax[n-1]=max((ll)0,y[n-1]-(c-x[n-1]));
  irep(i,n-2,0)dmax[i]=max(d[i]-(c-x[i]),dmax[i+1]);
  ans2=dmax[0];

  //  clockwise to anticlockwise
  ll ans3=0;
  rep(i,0,n){
    ll tmp=a[i]-x[i]*2+dmax[i+1];
    ans3=max(ans3,tmp);
  }

  // anticlockwise to clockwise
  ll ans4=0;
  irep(i,n-1,0){
    ll tmp2=d[i]-(c-x[i])*2+amax[i-1];
    ans4=max(ans4,tmp2);
  }
  ll ans5=max(max(ans1,ans2),max(ans3,ans4));
  cout<<ans5<<endl;
}

Measured memory_bytes: 5120
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const ll MOD = 1000000007;
double PI = 4*atan(1);

int X,Y,Z;
ll tmp = 0, ans = -1e18;
ll mxA[100000], mxB[100000];
vector<pii> todo;

bool comp(pii p, pii q) {
    return p.f-p.s > q.f-q.s;
}

void computeA() {
    ll csum = -MOD, cnum = 1; 
    pii cur = {-MOD,-MOD};
    
    set<pii> c; c.insert(cur);
    F0R(i,X+Y+Z) {
        c.insert({todo[i].f,i});
        if (mp(todo[i].f,(ll)i) > cur) cnum ++, csum += todo[i].f;
        while (cnum > X) {
            csum -= cur.f, cnum --;
            cur = *next(c.find(cur));
        }
        while (cnum < X && c.find(cur) != c.begin()) {
            cur = *prev(c.find(cur));
            csum += cur.f, cnum ++;
        }
        if (cur == mp(-MOD,-MOD)) mxA[i] = -1e18;
        else mxA[i] = csum;
        //cout << i << " " << mxA[i] << "\n";
    }
}

void computeB() {
    ll csum = -MOD, cnum = 1; 
    pii cur = {-MOD,-MOD};
    
    set<pii> c; c.insert(cur);
    F0Rd(i,X+Y+Z) {
        c.insert({todo[i].s,i});
        if (mp(todo[i].s,(ll)i) > cur) cnum ++, csum += todo[i].s;
        while (cnum > Y) {
            csum -= cur.f, cnum --;
            cur = *next(c.find(cur));
        }
        while (cnum < Y && c.find(cur) != c.begin()) {
            cur = *prev(c.find(cur));
            csum += cur.f, cnum ++;
        }
        if (cur == mp(-MOD,-MOD)) mxB[i] = -1e18;
        else mxB[i] = csum;
    }
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> X >> Y >> Z;
	F0R(i,X+Y+Z) {
	    int A,B,C; cin >> A >> B >> C;
	    tmp += C;
	    A -= C, B -= C;
	    todo.pb({A,B});
	}
	sort(todo.begin(),todo.end(),comp);
	computeA();
	computeB();
	F0R(i,X+Y+Z-1) ans = max(ans,tmp+mxA[i]+mxB[i+1]);
	cout << ans;
}

Measured memory_bytes: 9584
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    bool x = true;
    if(w >= v) x = false;
    ll jj = (v-w) * t;
    if(jj < abs(a-b)) x = false;
    cout << (x?"YES":"NO") << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	int arr[n + 1][3];
	for (int i = 1;i <= n;i++)
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	int dp[n + 1][3];
	dp[0][0] = dp[0][1] = dp[0][2] = 0; // base condition
	for (int i = 1;i <= n;i++) {
		dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]); // take last from A
		dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]); // take last from B
		dp[i][2] = arr[i][2] + max(dp[i-1][0], dp[i-1][1]); // take last from C
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;

int main(void) {
    ll n,k;
    cin>>k>>n;
    vl a(n);
    rep(i,n) cin>>a[i];
    ll r = a[0]+k-a[n-1];
    rep(i,n-1) r = max(r,a[i+1]-a[i]);
    cout<<k-r<<endl;
	return 0;
}


Measured memory_bytes: 4796
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
src = [SI() for _ in range(3)]

ans = 0
for i in range(n):
    tmp = set()
    for c in src:
        tmp.add(c[i])
    if len(tmp) == 3:
        ans += 2
    elif len(tmp) == 2:
        ans += 1

print(ans)


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

int main(){
  int n; cin >> n;
  string ans = "No";
  for(int i =1; i < 10; i++){
    for(int j = 1; j < 10; j++){
      if(i * j == n){
        ans = "Yes";
      }
    }
  }
  
  cout << ans << endl;
  
}





Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main (){
    ll a,b;
    cin >> a >> b;

    cout << lcm(a,b);

}

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

int main() {
    int n, k;
    while(cin >> n >> k, n) {

    vector <int> a(k);
    rep (i, k) cin >> a[i];
    sort(a.begin(), a.end());

    bool existBlank = a.front() == 0;
    if (existBlank) a.erase(a.begin());

    vector <pair <int, int>> sted;
    bool cont = false;
    int st = 0;
    rep (i, k - 1) {
        if (a[i] + 1 == a[i + 1]) {
            if (!cont) st = a[i];
            cont = true;
        }
        else {
            if (cont) {
                cont = false;
                sted.emplace_back(st, a[i] + 1);
            }
            else {
                sted.emplace_back(a[i], a[i] + 1);
            }
        }
    }
    if (cont) sted.emplace_back(st, a[k - 1]);

    int ans = 0;
    if (existBlank) {
        rep (i, sted.size() - 1) if (sted[i].second + 1 == sted[i + 1].first) {
            ans = max(ans, sted[i + 1].second - sted[i].first);
        }
    }
    else {
        for (auto & i : sted) ans = max(ans, i.second - i.first);
    }

    cout << ans << endl;

    }
    return 0;
}


Measured memory_bytes: 3440
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
 double x1,x2,y1,y2,d;

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

 d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));

 printf("%lf\n", d);

 return 0;
}

Measured memory_bytes: 1232
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef complex<double> P;
typedef pair<P, double> Circle;

#define EPS 1e-8
#define EQ(a, b) (abs((a)-(b)) < EPS)

inline int signum(double x) { return abs(x) < EPS ? 0 : x > 0 ? 1 : -1; }

pair<P, P> inter_circles(Circle c1, Circle c2) {
    P p1 = c1.first;
    P p2 = c2.first;
    double r1 = c1.second;
    double r2 = c2.second;
    double d = abs(p1 - p2);
    double rc = (r1 * r1 + d * d - r2 * r2) / (2 * d);
    double rs = sqrt(r1 * r1 - rc * rc);
    P ans1 = p1 + (p2 - p1) / d * P(rc, rs);
    P ans2 = p1 + (p2 - p1) / d * P(rc, -rs);
    return make_pair(ans1, ans2);
}

int main() {

    double c1x, c1y, c1r, c2x, c2y, c2r;
    cin >> c1x >> c1y >> c1r >> c2x >> c2y >> c2r;

    Circle c1(P(c1x, c1y), c1r);
    Circle c2(P(c2x, c2y), c2r);

    auto ret = inter_circles(c1, c2);

    P p1 = ret.first;
    P p2 = ret.second;

    if (p1.real() > p2.real()) swap(p1, p2);
    else if (p1.real() == p2.real() && p1.imag() > p2.imag()) swap(p1, p2);

    cout << fixed << setprecision(20) << p1.real() << " " << p1.imag() << " " << p2.real() << " " << p2.imag() << endl;

}














































Measured memory_bytes: 3360
function Main(input) {
	input = input.split("\n");
    const s = input[0].split(" ");
    const t = input[1].split(" ");
  
    const ss = String(s).split("");
    const tt = String(t).split("");

    const n = ss.length;
  
    let e = 0;
  
    for(let i = 0 ; i < n ; i++){
        if(ss[i] !== tt[i]){
            e++;
          
        }

    }

    console.log( '%d', e);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36472
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include <iomanip>

using namespace std;
struct Point
{
  double x;
  double y;
}; 
struct Edge{
  Point start;
  Point end;

  void make(Point start,Point end)
  {
    this->start=start;
    this->end=end;
  }
};

Point rot60(Point a,Point b)
{
  Point rot;
  rot.x=b.x-a.x; rot.y=b.y-a.y;
  double length=sqrt(rot.x*rot.x+rot.y*rot.y);
  double slope=(rot.y)/(rot.x);
  double deg=atan(slope)+M_PI/3;
  if(a.x>=b.x){
    deg+=M_PI;
  }
  rot.x=length*cos(deg)+a.x;
  rot.y=length*sin(deg)+a.y;
  return rot;
}

vector<Edge> KochCurve(vector<Edge>& edges,int& count)
{
  if(count==0){
    return edges;
  }else{
    int n=edges.size();
    vector<Edge> results(n*4);
    Point s,t,u;
    for(int i=0;i<n;i++){
      Point s,t,u;
      s.x=(edges[i].end.x+2*edges[i].start.x)/3;
      s.y=(edges[i].end.y+2*edges[i].start.y)/3;
      t.x=(2*edges[i].end.x+edges[i].start.x)/3;
      t.y=(2*edges[i].end.y+edges[i].start.y)/3;
      u=rot60(s,t);
      results[i*4].make(edges[i].start,s);
      results[i*4+1].make(s,u);
      results[i*4+2].make(u,t);
      results[i*4+3].make(t,edges[i].end);
    }
    count--;
    results=KochCurve(results,count);
    return results;
  }
}

int main()
{
  int n;
  cin>>n;
  int count=n;
  vector<Edge> edges(1);
  edges[0].start.x=0; edges[0].start.y=0;
  edges[0].end.x=100; edges[0].end.y=0;
  edges=KochCurve(edges,count);
  
  for(int i=0;i<edges.size();i++){
    cout<<fixed;
    cout<<setprecision(8)<< edges[i].start.x<<" "<<edges[i].start.y<<endl;
  }
  cout<<fixed;
  cout<<setprecision(8)<<edges[edges.size()-1].end.x<<" "<<edges[edges.size()-1].end.y<<endl;
  return 0;
}



Measured memory_bytes: 3744
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

/*int main() {
    int a;
    cin >> a;

    int x, y, z;
    x = a % 10;
    y = ((a - x) / 10) % 10;
    z = ((a - x - y * 10) / 100);

    if (x == 7 || y == 7 || z == 7) {
        cout << "Yes";
    } else {
        cout << "No";
    }



    return 0;
}*/

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

    long long int ans = 0;

    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }

    cout << ans;




    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>

#define N 10000

int isPrime(int);

int main(){
  int A[N],n,i,num=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<n;i++){
    if(isPrime(A[i])) num++;
  }
  printf("%d\n",num);

  return 0;
}

int isPrime(int x){
  int i;

  if(x==2) return 1;
  if(x<2 || x%2==0) return 0;
  
  i=3;
  while(i <= (int)sqrt(x)){
    if(x%i==0) return 0;
    i += 2;
  }

  return 1;
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int A, B, C;
  cin >> A >> B >> C;
  if (A == B) {
    cout << C << endl;
  } else if (B == C) {
    cout << A << endl;
  } else {
    cout << B << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#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;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll s,c;
	cin >> s >>c;
	ll ans;
	if(s < c/2){
		ans = s + (c - 2*s)/4;
	}
	else{
		ans = c/2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
h_list=list(map(int,input().split()))
for i in range(n-1):
    if h_list[i+1] == h_list[i]:
        continue
    elif h_list[i + 1] - h_list[i] > 0:
        h_list[i+1]=h_list[i+1]-1
    else:
        print('No')
        exit(0)
print(('Yes'))

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

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((A%2+B%2+C%2)%3==0)
    cout<<(max({A,B,C})*3-(A+B+C))/2<<endl;
  else if(A%2+B%2+C%2==1)
    cout<<((max({A,B,C})/2*2+1)*3-(A+B+C))/2<<endl;
  else if(A%2+B%2+C%2==2)
    cout<<(((max({A,B,C})+1)/2*2)*3-(A+B+C))/2<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for m in range(M)]
AB = sorted(AB, key=lambda x: x[1])
ans = 0
prev = 0
for a, b in AB:
    if ans > 0 and a <= prev:
        pass
    else:
        ans += 1
        prev = b-1
print(ans)


Measured memory_bytes: 62296
package main
import (
  "fmt"
  "math"
)
func main() {
  var n,p,k int64
  fmt.Scan(&n,&p)
  m := map[int64]int64{}
  f := primes(p)
  j := 0
  for {
    k = p
    for i:=j;i<len(f);i++ {
      if p%f[i] == 0 {
        m[f[i]]++
        p /= f[i]
        j = i
        break
      }
    }
    if p == 1 { break }
    if p == k {
      m[p]++
      break
    }
  }
  k = 1
  for key,val := range m {
    k *= pow(key,val/n)
  }
  fmt.Println(k)
}
func pow(base int64,power int64) int64 {
  if power == 0 { return 1 }
  if power%2 == 0 {
    var h int64 = pow(base,power/2)
    return h*h
  } else {
    return base*pow(base,power-1)
  }
}
func primes(n int64) []int64 {
  var r int = int(math.Sqrt(float64(n)))
  var m []int = make([]int,r)
  for i:=0;i<r;i++ {
    m[i] = i+1
  }
  m[0] = -1
  for i:=1;i<r;i++ {
    if m[i] < 0 { continue }
    for j:=i+m[i];j<r;j+=m[i] {
      m[j] = -1
    }
  }
  var p []int64 = []int64{}
  for i:=1;i<r;i++ {
    if m[i] < 0 { continue }
    p = append(p,int64(m[i]))
  }
  return p
}

Measured memory_bytes: 11776
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    char  s[n+1];
    scanf("%s",s);
    if(n%2==0){
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    if(s[i]>s[j]){
                        char tmp=s[i];
                        s[i]=s[j];
                        s[j]=tmp;
                    }
                }
            }
            int l=1;
        for(int i=0;i<n-1;i+=2){
            if(s[i]!=s[i+1]){ l=0; break;}
        }
        if(l==1) printf("Yes");
        if(l==0) printf("No");
    }
    else printf("No");

    return 0;
}


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

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

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

    if(a < b){
        cout << "a < b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }else{
        cout << "a > b" << endl;
    }

    return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<stdlib.h>
int main(){
  int unused __attribute__((unused));
  int i, N;
  int *A, *k;

  unused = scanf("%d", &N);
  A = (int *)malloc(sizeof(int)*N);
  k = (int *)malloc(sizeof(int)*N);
  for(i=0; i<N; i++) k[i] = 0;
  for(i=0; i<N-1; i++){
    unused = scanf("%d", &A[i]);
    k[(A[i]-1)]++;
  }

  for(i=0; i<N; i++) printf("%d\n", k[i]);
  return 0;
}

Measured memory_bytes: 3280
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}
int h,w;
int dy[] = {0,-1,0,1};
int dx[] = {1,0,-1,0};

bool inside(int y,int x){
	return (y < h && x < w && y >= 0 && x >= 0);
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w;
	vector<string> mas(h);
	vector<vector<int> > dist(h,vector<int>(w,INF));
	queue<pii> que;
	rep(i,h){
		cin >> mas[i];
		rep(j,w){
			if(mas[i][j] == '#'){
				que.emplace(i,j);
				dist[i][j] = 0;
			}
		}
	}
	while(!que.empty()){
		int y = que.front().first;
		int x = que.front().second;
		que.pop();
		rep(i,4){
			int ny = y + dy[i];
			int nx = x + dx[i];
			if(inside(ny,nx) && chmin(dist[ny][nx],dist[y][x] + 1)){
				que.emplace(ny,nx);
			}
		}
	}
	int maxv = 0;
	rep(i,h){
		rep(j,w){
			chmax(maxv,dist[i][j]);
		}
	}
	cout << maxv << '\n';

	return 0;
}


Measured memory_bytes: 25524
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <sstream>
#include <cctype>
using namespace std;

#define PQ priority_queue
#define P pair<int,int>
#define CLA(array) memset(array,0,sizeof array)
#define CLINF(array) memset(array,0x3f,sizeof array)
#define CLF(array) memset(array,-1,sizeof array)
#define DB(a) cout << "DEBUG " << a << endl;
typedef long long LL;
typedef unsigned long long ULL;
const int MAXN = 100000 + 50;
const int INF = 1 << 30;


int main(){
    //ios_base::sync_with_stdio(false);
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int t1 = max(a,c);
	int t2 = min(b, d);
	if(b <= c) printf("%d\n", 0);
	else if(d <= a) printf("0\n");
	else printf("%d\n", t2 - t1);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
 
class dice {
  private:
    int f[6];
  public:
    dice(int *a){
      int i;
      rep(i, 6) f[i] = a[i];
    }
    void n(){
      int t;
      t = f[0];
      f[0] = f[1];
      f[1] = f[5];
      f[5] = f[4];
      f[4] = t;
    }
    void s() {
      int t;
      t = f[0];
      f[0] = f[4];
      f[4] = f[5];
      f[5] = f[1];
      f[1] = t;
    }
    void w() {
      int t;
      t = f[0];
      f[0] = f[2];
      f[2] = f[5];
      f[5] = f[3];
      f[3] = t;
    }
    void e() {
      int t;
      t = f[0];
      f[0] = f[3];
      f[3] = f[5];
      f[5] = f[2];
      f[2] = t;
    }
    void r() {
      int t;
      t = f[1];
      f[1] = f[2];
      f[2] = f[4];
      f[4] = f[3];
      f[3] = t;
    }
    void l() {
      int t;
      t = f[1];
      f[1] = f[3];
      f[3] = f[4];
      f[4] = f[2];
      f[2] = t;
    }
    int print(int num) {
      return f[num];
    }
};
 
int main(void) {
  int a[6], i, j, b[6];
  rep(i, 6) scanf("%d", &a[i]);
  rep(i, 6) scanf("%d", &b[i]);
  dice d1(a), d2(b);
  if(d1.print(1) == d2.print(0)) d1.n();
  else if(d1.print(2) == d2.print(0)) d1.w();
  else if(d1.print(3) == d2.print(0)) d1.e();
  else if(d1.print(4) == d2.print(0)) d1.s();
  else if(d1.print(5) == d2.print(0)) d1.n(), d1.n();
  if(d1.print(2) == d2.print(1)) d1.r();
  else if(d1.print(3) == d2.print(1)) d1.l();
  else if(d1.print(4) == d2.print(1)) d1.r(), d1.r();
  int s = 0;
  rep(i, 6) if(d1.print(i) != d2.print(i)) s = 1;
  if(s) printf("No\n");
  else printf("Yes\n");
  return 0;
}


Measured memory_bytes: 2684
package main

import (
	"fmt"
	"math"
)

const MaxN = 300005

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	var i int
	var s string
	fmt.Scanf("%d", &i)
	fmt.Scanf("%s", &s)
	// prefix sum, @see https://en.wikipedia.org/wiki/Prefix_sum
	// i -> how many 'W' of s[0:i+1].
	var prefixes [MaxN]int
	if s[0] == 'W' {
		prefixes[0] = 1
	} else {
		prefixes[0] = 0
	}
	for i := 1; i < len(s); i++ {
		if s[i] == 'W' {
			prefixes[i] = prefixes[i-1] + 1
		} else {
			prefixes[i] = prefixes[i-1]
		}
	}
	n := math.MaxInt64
	for i := 0; i < len(s); i++ {
		// The altered s must be 'EEEEEEOWWWWWWW'.
		// Sum of 'W' in left and 'E' in the right;
		if s[i] == 'W' {
			n = min(n, prefixes[i]-1+(len(s)-(i+1))-(prefixes[len(s)-1]-prefixes[i]))
		} else {
			n = min(n, prefixes[i]+(len(s)-(i+1))-(prefixes[len(s)-1]-prefixes[i]))
		}
	}
	fmt.Println(n)
}

Measured memory_bytes: 4736
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
	int x;

	rep(i, 3){
		int tmp;
		cin >> tmp;
		x = x*10 + tmp;
	}

	cout << (x%4 == 0 ? "YES" : "NO") << endl;		
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

bool is_prime[60000];
int prime[60000];
void eratos(int n){
    for(int i=0; i<=n; i++) is_prime[i]=true;
    is_prime[0]=false, is_prime[1]=false;

    for(int i=2; i*i<=n; i++){
        if(is_prime[i]){
            for(int j=2; i*j<=n; j++){
                is_prime[i*j]=false;
            }
        }
    }

    int cnt=0;
    for(int i=2; i<=55555; i++){
        if(is_prime[i] && i%5==1){
            prime[cnt]=i;
            cnt++;
        }
    }
}

int main(){
    int n; cin>>n;
    eratos(55550);
    for(int i=0; i<n; i++){
        cout << prime[i] << " ";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e16;
typedef long long ll;
ll mod = 1e9+7;
ll fast_exp(ll a, ll b)
{
    if(b == 0)
        return 1;
    else
    {
        ll res = 1;
        res = fast_exp(a,b/2);
        res = (res*res)%mod;
        if(b%2 == 1)
            res = (res*a)%mod;
        return res;
 
    }
}

 
int main()
{
   // ios_base::sync_with_stdio(false);
   // cin.tie(NULL);
   
  int r;
  cin>>r;
  cout<<r*r<<endl;


 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <fstream>
#include <iomanip>
#include <complex>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int N = 1e3 + 5, inf = 1e9, mod = 998244353;
using namespace std;

int main()
{
    IO
    int n, a, mn = inf;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        int tmp = 0;
        while(a % 2 == 0)
            a /= 2, tmp++;
        mn = min(mn, tmp);
    }
    cout << mn << '\n';
    return 0;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    map<int, int> m;
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        if (m.find(a) == m.end()) {
            m.insert(make_pair(a, 1));
        } else {
            m[a]++;
        }
        if (m.find(b) == m.end()) {
            m.insert(make_pair(b, 1));
        } else {
            m[b]++;
        }
    }

    for (int i = 1; i <= N; ++i) {
        if (m.find(i) != m.end()) {
            cout << m[i] << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256