akhauriyash/Code-Regression huggingface dataset:
#pragma GCC Optimize("Ofast")
#pragma GCC Optimize "trapv"
#pragma comment(linker, "/STACK: 2000000")

#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 

using namespace std;
//using namespace boost::multiprecision; 

#define FAST ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define TC int t; cin >> t; while(t--)
#define li long int
#define ll long long
#define ull unsigned long long 
#define Vec(x) vector <x>
#define Pai(x,y) pair <x,y>
#define Map(x,y) map <x,y>
#define UMap(x,y) unordered_map <x,y>
#define Set(x) set <x>
#define Sta(x) stack <x>
#define Qu(x) queue <x>https://discuss.codechef.com/t/bytelandian-gold-coins/76721
#define DQ(x) deque(x)
#define PriorQ(x)	priority_queue <x>
#define bg begin()
#define ed end()
#define sz size()
#define ct(x) count(x)
#define len length()
#define F first
#define S second
#define Makep make_pair
#define ins(x) insert(x)
#define ers(x) erase(x)
#define endl "\n";
#define MOD 1000000007
#define PI 2*acos(0.0)
#define clr() clear()
#define fori0(n) for(int i=0;i<n;i++)
#define foriab(a,b) for(int i=a;i<b;i++)
#define mem0(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,1,sizeof(x))
#define autoit(x) for(auto it=x.bg;it!=x.ed;it++)
#define count0(x) __builtin_popcount(x)
#define ret return 
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

const ll Inf=1e9+5;
const ll m = 1e9 + 7;

namespace funset{
bool checkvow(char x){
	return ((0x208222)>>(x&(0x1f)))&1;
	}
ll highpow2(ll x){
	return (x&~(x-1));
	}
bool chk2(ll x){
		return (x&(x-1));
	}	
}

const ll Mxn = 2 * 1e5;


using namespace funset;


ll strhash(string s){
	const ll p = 31;
	const ll m = 1e9 + 7;
	ll hashval = 0;
	ll powe = 1;
	for (char c: s){
		hashval = (hashval + (c - 'a' + 1) * powe) % m;
		powe = (powe * p) % m;
	}
	return hashval;
}

ll fact(ll n){
	if(n <= 1)
		return 1;
	return n*fact(n-1);
}


ll a[1000], dp[1000], n;

ll foo(ll a, ll b, ll x, ll y, ll n){
	ll t=min(a-x,n);
	a-=t;
	n-=t;
	t = min(b-y, n);
	b-=t;
	return a*b;
}

void solve(){
	ll n;
	cin >> n;
	ll a[n];
	for(ll &i:a)
		cin >> i;
	ll m;
	cin >> m;
	ll ans  =0, k= accumulate(a,a+n, 0);
	while(m--){
		ll pi, xi;
		cin >> pi >> xi;
		--pi;
		ans = (k-a[pi])+xi;
		cout << ans << endl;
	}
}

int main(){
	//sieve();
	auto beg=clock();
	FAST
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	
    solve();
	auto ted=clock();
	#ifndef ONLINE_JUDGE
	cout << (double)(ted-beg)/CLOCKS_PER_SEC << endl;
	#endif
	ret 0;
}

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

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

	ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') cnt1++;
		if (S[i] == 'G') cnt2++;
		if (S[i] == 'B') cnt3++;
	}

	ll ans = cnt1 * cnt2 * cnt3;

	for (int d = 1; d <= N; d++) {
		for (int m = d; m < N; m++) {
			if (m - d < 0 || m + d >= N) continue;
			if ((S[m - d] != S[m + d]) && (S[m] != S[m + d]) && S[m - d] != S[m]) ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> x(M);
    vector<int> a(M);
    for(int i=0;i<M;i++){
      cin>>x[i];
    }
    sort(x.begin(),x.end());
    for(int i=1;i<M;i++){
      a[i-1]=x[i]-x[i-1];
    }
    int w=0;
    sort(a.rbegin(),a.rend());
    for(int i=N-1;i<M-1;i++){
      w+=a[i];
    }
      cout<<w<<endl;
    return 0;
}




Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    int n=10*a+b,m=10*c+d;
    string ans;
    if(n>12||n==0)
    {
        if(m>0&&m<13)
        ans="YYMM";
        else
        ans="NA";
    }
    else
    {
        if(m>0&&m<13)
        ans="AMBIGUOUS";
        else
        ans="MMYY";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            String s = reader.readLine();

            int N = Integer.parseInt(s);

            s = reader.readLine();
            String[] sl = s.split(" ");

            boolean flg = false;
            for (int i = 0; i < N; i++) {
                char x = sl[i].charAt(0);
                if (x == 'Y') {
                    flg = true;
                    break;
                }
            }

            System.out.println(flg ? "Four" : "Three");
        }
    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	int ct=0;
	for (char ch : s)
		if (ch=='2') ct++;
	cout<<ct<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

ll a[100001] = {};
ll b[100001] = {};
ll maxA = 0;
int main() {
	ll N, H; cin >> N >> H;
	rep(i, 0, N) {
		cin >> a[i] >> b[i];
		maxA = max(a[i], maxA);
	}

	sort(b, b + N);
	reverse(b, b + N);
	ll cnt = 0;
	rep(i, 0, N) {
		if (maxA >= b[i]) {
			break;
		}
		H -= b[i];
		cnt++;

		if (H <= 0) {
			cout << cnt << endl;
			return 0;
		}
	}

	if (H % maxA == 0)cnt += H / maxA;
	else cnt += H / maxA + 1;

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

#define CAP 3

#define ZIGEN (CAP + 1)

int R, C, K;
int r[212345], c[212345], k[212345];

int main(void) {
	int i, j, x;
	uint64_t* values;
	uint64_t** dp;
	uint64_t* buf;
	if (scanf("%d%d%d", &R, &C, &K) != 3) return 1;
	for (i = 0; i < K; i++) {
		if (scanf("%d%d%d", &r[i], &c[i], &k[i]) != 3) return 1;
	}
	values = calloc(R * C, sizeof(*values));
	buf = malloc(sizeof(*buf) * R * C * ZIGEN);
	dp = malloc(sizeof(*dp) * R);
	if(values == NULL || buf == NULL || dp == NULL) return 2;
	for (i = 0; i < K; i++) {
		values[(r[i] - 1) * C + (c[i] - 1)] = k[i];
	}
	for (i = 0; i < R; i++) {
		dp[i] = buf + (i * C * ZIGEN);
	}
	dp[0][0 * ZIGEN + 0] = 0;
	for (i = 1; i <= CAP; i++) dp[0][0 * ZIGEN + i] = values[0 * C + 0];

	for (i = 0; i < R; i++) {
		for (j = 0; j < C; j++) {
			if (i == 0 && j == 0) continue;

			for (x = 0; x <= CAP; x++) {
				uint64_t res = 0;
				/* 横移動 → 拾った数を引き継ぐ */
				if (j > 0 && dp[i][(j - 1) * ZIGEN + x] > res) res = dp[i][(j - 1) * ZIGEN + x];
				/* 横移動 + 拾う */
				if (j > 0 && x > 0 && dp[i][(j - 1) * ZIGEN + (x - 1)] + values[i * C + j] > res) {
					res = dp[i][(j - 1) * ZIGEN + (x - 1)] + values[i * C + j];
				}
				/* 縦移動 → 拾った数を引き継がない */
				if (i > 0 && dp[i - 1][j * ZIGEN + CAP] > res) res = dp[i - 1][j * ZIGEN + CAP];
				/* 縦移動 + 拾う */
				if (i > 0 && x > 0 && dp[i - 1][j * ZIGEN + CAP] + values[i * C + j] > res) {
					res = dp[i - 1][j * ZIGEN + CAP] + values[i * C + j];
				}
				/* 拾える数を投げ捨てる */
				if (x > 0 && dp[i][j * ZIGEN + (x - 1)] > res) res = dp[i][j * ZIGEN + (x - 1)];

				dp[i][j * ZIGEN + x] = res;
			}
		}
	}
	printf("%" PRIu64 "\n", dp[R - 1][(C - 1) * ZIGEN + CAP]);
	free(values);
	free(dp);
	free(buf);
	return 0;
}


Measured memory_bytes: 355484
#include <iostream>
#include <cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x == 2) {
			ans++;
			continue;
		}
		if (x < 2 || x % 2 == 0)
			continue;
		int j = 3;
		bool cont = 0;
		while (j <= sqrt(x)) {
			if (x % j == 0) {
				cont = 1;
				break;
			}
			j = j + 2;
		}
		if (cont)
			continue;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3092
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			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++;
							}
						}
					}
				}
			}
			System.out.println(count);
		}
	}

}

Measured memory_bytes: 18852
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
map<string,int>mp;
int main(){
	int n;
	cin>>n;
	int maxnum=0;
	string tmp;
	for(int i=1;i<=n;i++){
		cin>>tmp;
		maxnum=max(++mp[tmp],maxnum);
	}
	for(auto p:mp){
		if(p.second==maxnum)cout<<p.first<<endl;
	}
}


Measured memory_bytes: 25344
import java.io.*;
import java.util.StringTokenizer;

class Main{

static final PrintWriter out=new PrintWriter(System.out);

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringTokenizer st=new StringTokenizer(line);
int h=Integer.parseInt(st.nextToken());
int w=Integer.parseInt(st.nextToken());
int[][] wf=new int[h][w];
for(int i=0;i<h;i++){
boolean flag=false;
char[] map=br.readLine().toCharArray();
for(int j=0;j<w;j++){
if(map[j]=='c'){
wf[i][j]=0;
flag=true;
}
else{
if(!flag) wf[i][j]=-1;
else wf[i][j]=wf[i][j-1]+1;
}
if(j==w-1) out.println(wf[i][j]);
else out.print(wf[i][j]+" ");
}
}
out.flush();
}
}
}

Measured memory_bytes: 25000
#include<stdio.h>
long long int a,s,d[99][21],f,g,h,i,j;
int main(void)
{
	for(i=0;i<99;i++){
		for(j=0;j<=20;j++){
			d[i][j]=0;
		}
	}
	scanf("%ld",&a);
	for(i=1;i<=a;i++){
		scanf("%ld",&s);
		if(i==1){
			d[1][s]=1;
		}
		if(i>=a){
			break;
		}
		else{
		for(j=0;j<=20;j++){
			if(j+s<=20){
				f=j+s;
				d[i][f]+=d[i-1][j];
			}
			if(j-s>=0){
				g=j-s;
				d[i][g]+=d[i-1][j];
			}
		}
		}
	}
	/*for(i=0;i<a;i++){
		for(j=0;j<=20;j++){
			printf("%ld ",d[i][j]);
		}
		printf("\n");
	}*/
	printf("%ld\n",d[a-1][s]);
	return 0;
}

Measured memory_bytes: 1044
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
//#define int  long long 
using namespace std;
double a;
double x = sqrt(2.0);
signed main()
{
	scanf("%lf", &a);
	if (a >= 1 && a <= x)	printf("%.12lf\n", 2.0);
	else if (a >= 2 && a <= 3 / x)	printf("%.12lf\n", 3.0);
	else	printf("%.12lf\n", x * a);
}



Measured memory_bytes: 3216
class BIT:
    def __init__(self, n):
        self.n = n
        self.array = [0 for i in range(n + 1)]

    def sum(self, i):
        result = 0
        while(i > 0):
            result = result + self.array[i]
            i -= i & (-i)
        return result

    def range_sum(self, i, j):
        tmp_i = self.sum(i - 1)
        tmp_j = self.sum(j)
        return tmp_j - tmp_i

    def add(self, i, x):
        while (i <= self.n):
            self.array[i] += x
            i += i & (-i)


init = [int(n) for n in input().split()]
a = []

bit = BIT(init[0])

for i in range(init[1]):
    line = [int(n) for n in input().split()]
    if line[0] == 0:
        bit.add(line[1], line[2])
    else:
        print(bit.range_sum(line[1], line[2]))



Measured memory_bytes: 8044
#include<stdio.h>

int main(void)
{
  char str[101];
  int i=0;
  scanf("%s",str);
  while(str[i] != '\0')
    {
      i++;
    }
  printf("%c%d%c\n",str[0],i-2,str[i-1]);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int prim(void);
int n;
int A[100][100];
int main(){
  int i,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&A[i][j]);
      if(A[i][j]==-1){
	A[i][j]=2001;
      }
    }
  }
  printf("%d\n",prim());
  return 0;
}
int prim(void){
  int i;
  int u,v,minv,sum=0;
  int d[100],p[100],c[100];
  for(i=0;i<n;i++){
    d[i]=2001;
    p[i]=-1;
    c[i]=0;
  }
  d[0]=0;
  while(1){
    minv=2001;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && c[i]!=2){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    c[u]=2;
    for(v=0;v<n;v++){
      if(c[v]!=2 && A[u][v]!=2001){
	if(d[v]>A[u][v]){
	  d[v]=A[u][v];
	  p[v]=u;
	  c[v]=1;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1){
      sum+=A[i][p[i]];
    }
  }
  return sum;
}



Measured memory_bytes: 2108
a,b = map(int,input().split())
AC = [0]*(a+1)
WA = [0]*(a+1)
ac = 0
wa = 0
wat = 0

for i in range(b):
  x,y = map(str,input().split())
  if y == "WA":
    WA[int(x)] += 1
  elif AC[int(x)] == 0 and y == "AC":
    wa += WA[int(x)]
    ac += 1
    AC[int(x)] = 1

print(ac,wa)

Measured memory_bytes: 4724
n=int(input())
edge=[[] for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
ans=[0 for i in range(n+1)]
od=[1]
ev=[]
q=[1]
c=[1 for i in range(n+1)]
c[1]=0
t=0
while q:
    tl=q[:]
    q=[]
    for i in tl:
        for j in edge[i]:
            if c[j]:
                q.append(j)
                c[j]=0
                if t:
                    od.append(j)
                else:
                    ev.append(j)
    t^=1
if len(od)>len(ev):
    od,ev=ev,od
if len(od)<=n//3:
    t=3
    for i in od:
        ans[i]=t
        t+=3
    x=0
    for i,j in enumerate(ans):
        if j==0:
            ans[i]=x
            x+=1
            if x%3==0 and x<t:
                x+=1
else:
    t=0
    for i in range(1,n+1,3):
        ans[ev[t]]=i
        t+=1
    t=0
    for i in range(2,n+1,3):
        ans[od[t]]=i
        t+=1
    t=0
    for i,j in enumerate(ans):
        if j==0:
            ans[i]=t
            t+=3
print(" ".join(map(str,ans[1:])))

Measured memory_bytes: 123468
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod


def main():
    MOD = 10 ** 9 + 7

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

    calc = Calc(max_value=N * M - 2, mod=MOD)

    xsum = 0
    for d in range(1, N):
        xsum = (xsum + d * (N - d)) % MOD
    xsum = (xsum * M * M) % MOD

    ysum = 0
    for d in range(1, M):
        ysum = (ysum + d * (M - d)) % MOD
    ysum = (ysum * N * N) % MOD

    ans = (xsum + ysum) * calc.combination(N * M - 2, K - 2) % MOD

    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 18804
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
int n, m;
map<string, int> items;
map<string, vector<string> > alc;

map<string, int> memo;
int minPrice(const string& t) {
	vector<string>& mats = alc[t];
	if (!mats.size()) return items[t];
	map<string, int>::iterator it = memo.find(t);
	if (it != memo.end()) return it->second;
	int ap = 0;
	for (unsigned i = 0; i < mats.size(); i++) {
		ap += minPrice(mats[i]);
	}
	return memo[t] = min(items[t], ap);
}

int main () {
	while (cin >> n, n) {
		items.clear();
		alc.clear();
		memo.clear();
		for (int i = 0; i < n; i++) {
			string name;
			int value;
			cin >> name >> value;
			items[name] = value;
		}
		cin >> m;
		for (int i = 0; i < m; i++) {
			string name;
			int k;
			cin >> name >> k;
			vector<string> mats;
			for (int j = 0; j < k; j++) {
				string mat;
				cin >> mat;
				mats.push_back(mat);
			}
			alc[name] = mats;
		}
		string target;
		cin >> target;
		cout << minPrice(target) << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>

using namespace std;

int a,b;
int ac[6001],bc[6001];

int main(void){
	scanf("%d%d",&a,&b);
	memset(ac,-1,sizeof(ac));
	memset(bc,-1,sizeof(bc));
	for(int i=0;i<a;i++)scanf("%d",&ac[i]);
	for(int i=0;i<b;i++)scanf("%d",&bc[i]);
	int res=0;
	for(int i=0;i<b;i++){
		int cnt=0,np=i;
		for(int j=0;j<a;j++){
			if(ac[j]==bc[np]){
				np++;
				cnt++;
			}
		}
		res=max(res,cnt);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 1244
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0, sum = 0;
	//new
	ll n, m;
	cin >> n >> m;
	if (n == 1 && m == 1)cout << 1 << endl;
	else if (n == 1) {
		cout << max((ll)0,m - 2) << endl;
	}
	else if (m == 1) {
		cout << max((ll)0,n - 2) << endl;
	}
	else {
		cout << (n - 2) * (m - 2) << endl;
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;


typedef long long ll;

int main(void) {
  ll n;
  cin >> n;
  vector<int> res;
  for(; n; ) {
    int b = (n % -2 != 0);
    res.push_back(b);
    n -= b;
    n /= -2;
  }
  if(res.empty()) {
    res.push_back(0);
  }
  reverse(res.begin(), res.end());
  REP(i, res.size()) {
    printf("%d", res[i]);
  }
  puts("");
  
  return 0;
}


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

int main() {
  int A, B;
  string S;
  bool aBool=true;
  cin >> A >> B >> S ;
 if( S[A] == '-' && S.size()==A+B+1){
   S.erase(A,1);
   for(int count=0;
       count<A+B;
       count++){
   aBool=S[count]!='-'&&aBool;
   } 
 }
  else{
aBool=false;
}
   if(aBool){
   cout << "Yes" << endl;
   }
  else{
  cout << "No" << endl;
  }
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
unordered_map<int,list<int> > adj;
void dfs(vector<bool> &visited, int vertex, vector<int> &dp)
{
    visited[vertex] = true;
    
    for(auto itr : adj[vertex])
    {
        if(visited[itr] == false)
            dfs(visited, itr, dp );
        dp[vertex] = max(dp[vertex], 1 + dp[itr]);
    }
    return ;
}
void dfsUtil(int vertices)
{
    vector<int> dp(vertices + 1, 0);
    
    vector<bool> visited(vertices + 1, 0);
    for(int i = 1; i <= vertices; i++)
    {
        if(visited[i] == false)
            dfs(visited, i, dp );
       
    }
    
    cout << *max_element(dp.begin(), dp.end()) ;
}
int main() {
    int vertices,edges;
    cin >> vertices >> edges;
    
    for(int i = 0; i < edges; i++)
    {
        int st, end;
        cin >> st >> end;
        adj[st].push_back(end);
    }
    
    dfsUtil(vertices);
    return 0;
}

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

int main() {
  string a, b;
  string c;
  cin >> a >> b;
  size_t d = b.length();
  int e;
  e = d - 1;
  c = b.substr(0, e);
  if(c == a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  //cout << c << endl;
  //if(b == 0, 3)
}


Measured memory_bytes: 3628
s = int(input())
ans = [s]
i = 1
if s == 1 or s == 2:
    ans = 4
else:
    while ans[i-1] != 4:
        if ans[i-1] % 2 ==0:
            ans.append(ans[i-1]//2)
        else:
            ans.append(ans[i-1]*3 + 1 )
        i += 1
    ans = i + 3
print(ans)

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int N;
    cin >> N;
    vll As(N);
    // ll sum = 0;
    rep(i, N) {
        cin >> As[i];
        // sum += As[i];
    }
    std::sort(As.begin(), As.end());
    ll sum = 0;
    sum += As[N-1];
    for (int i = 0; i < (N-2)/2; i++) {
        sum += As[N-2-i]*2;
        // cout << (N-2)/2 << " " << sum << endl;
    }
    if ((N-2) % 2 == 1) {
        sum += As[N-2-(N-2)/2];
    }
    cout << sum << endl;
}

Measured memory_bytes: 4796
#pragma GCC optimize ("Ofast")

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING

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



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);


	int x; cin >> x;
	cout << (x >= 30?"Yes": "No");
	
	return 0;
}

Measured memory_bytes: 3532
N = gets.to_i
t = 1
a = 1
N.times{|n|
    tn, an = gets.split.map{|i|i.to_i}
    #warn "#{tn}:#{an}"
    ft = Rational(t, tn).ceil
    fa = Rational(a, an).ceil
    f = [ft, fa].max
    t = f * tn
    a = f * an
    #warn "=>#{t}:#{a}"
}
puts t + a


Measured memory_bytes: 1788
use proconio::*;
use std::*;

fn main() {
    input! {
        n: usize,
    }
    let mut cnt = 0;
    for _ in 0..n {
        input! { d1: i8, d2: i8}
        if d1 == d2 {
            cnt += 1;
        } else {
            cnt = 0;
        }
        if cnt == 3 {
            println!("Yes"); return
        }
    }
    println!("No");
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int num=1;
    int n,m;cin>>n>>m;
    int idx[m],c[m];
    rep(i,m) cin>>idx[i]>>c[i];
    rep(i,n-1) num*=10;
    if(n==1) num=0;
    for(int x=num;x<(num==0?10:num*10);x++){
        string s=to_string(x);
        // cout<<s<<endl;
        bool f=true;
        rep(i,m){
            if(s[idx[i]-1]==(char)('0'+c[i])) continue;
            f=false;
        }
        if(f){
            cout<<x<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static int abs(int x){
        return (x > 0)? x : -x;
    }

    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        List<Integer> list_a = new ArrayList<Integer>();
        List<Integer> list_b = new ArrayList<Integer>();
        List<Integer> list_c = new ArrayList<Integer>();
        List<Integer> list_d = new ArrayList<Integer>();
        
        for(int i = 0; i < n; i++){
            int p = scan.nextInt();
            int q = scan.nextInt();
            list_a.add(p);
            list_b.add(q);
        }

        for(int i = 0; i < m; i++){
            int p = scan.nextInt();
            int q = scan.nextInt();
            list_c.add(p);
            list_d.add(q);
        }

        for(int i = 0; i < n; i++){
            int minIndex = 0, minDiff = 1234567890;
            for(int j = 0; j < m; j++){
                int diff = abs(list_a.get(i) - list_c.get(j)) + abs(list_b.get(i) - list_d.get(j));

                if(diff < minDiff){
                    minIndex = j + 1;
                    minDiff = diff;
                }
            }
            System.out.println(minIndex);
        }
    }
}

Measured memory_bytes: 21588
while True:
    n,l,r = map(int, input().split())
    if n==0 and l==0 and r==0:
        break
    a = [0]*n
    cnt = 0
    for i in range(n):
        a[i]=int(input())
        # aのリスト完成
    for x in range(l,r+1):
        for i in range(1,n+1):
            if x%a[i-1]==0:
                if i%2==1:
                    cnt += 1
                break
            if i==n and n%2==0:
                cnt += 1
    print(cnt)
            


Measured memory_bytes: 5604
program main
  implicit none
  integer i, mae, ushiro
  character(4) S
  read(*, *) S
  mae = 0
  ushiro = 0
  if (S(1:1) == '0') then
    if (S(2:2) /= '0') then
      mae = 1
    endif
  else if (S(1:1) == '1') then
    if (S(2:2) == '0' .or. S(2:2) == '1' .or. S(2:2) == '2') then
      mae = 1
    endif
  end if
  
  if (S(3:3) == '0') then
    if (S(4:4) /= '0') then
      ushiro = 1
    endif
  else if (S(3:3) == '1') then
    if (S(4:4) == '0' .or. S(4:4) == '1' .or. S(4:4) == '2') then
      ushiro = 1
    endif
  end if

   
  if (mae == 1) then
    if (ushiro == 1) then
      write(*,'(A)') 'AMBIGUOUS'
    else
      write(*,'(A)') 'MMYY'
    end if
  else
    if (ushiro == 1) then
      write(*,'(A)') 'YYMM'
    else
      write(*,'(A)') 'NA'
    end if
  end if
          


end program main


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


def solve(N: int, H: "List[int]"):
    cur = H[0]
    counter = 0
    res = 0
    for h in H[1:]:
        if h <= cur:
            counter += 1
        else:
            res = max(res, counter)
            counter = 0
        cur = h
    res = max(res, counter)
    print(res)
    return


# Generated by 1.1.5 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()
    N = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16152
def countnumber(l):
  for i in range(l):
    p,s=input().split()
    p=int(p)
    if x[p-1]==0:
      if s=="WA":
        y[p-1]+=1
      else:
        x[p-1]+=1
  X=sum(x)
  Y=0
  for i in range(n):
    if x[i]==1:
      Y+=y[i]
  return X,Y

n,m=map(int,input().split())
x=[0]*n
y=[0]*n
result1,result2=countnumber(m)

print(result1,result2)
    

Measured memory_bytes: 45784
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));



int main(){
    int a, b;
    cin >> a >> b;
    cout << a / b << ' ';
    cout << a % b << ' ';
    cout << fixed << setprecision(10) << (a * 1.0) / (b * 1.0) << endl;
}


Measured memory_bytes: 3280
def main():
    N,M=map(int,input().split())
    str=list(map(int,input().split()))
    cal=sum(str)
    str.sort(reverse=True)

    for i in range(M):
        if str[i]<cal*(1/(4*M)):
            print("No")
            return

    print("Yes")
    return

main()


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
 
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
 
MOD = 10 ** 9 + 7
s = input().strip()
n = len(s)
if s[-1] == "?":
    tmp = [1 for i in range(10)] + [0 for i in range(3+13*(n-1))]
 
else:
    tmp = [0 for i in range(13*n)]
    # print("-------------------")
    # print(s[-1])
    # print(int(s[-1]))
    tmp[int(s[-1])] = 1
# print(len(tmp))
keta = 1
for kt, c in enumerate(s[::-1][1:]):
    keta = (keta * 10) % 13
    
    if c != "?":
        seni = int(c) * keta
        for j in range(13):
            tmp[(j + seni) % 13 + (kt + 1) * 13] += tmp[kt * 13 + j] % MOD
    else:
        for isure in range(10):
            seni = isure * keta
            for j in range(13):
                tmp[(j + seni) % 13 + (kt + 1) * 13] += tmp[kt * 13 + j] % MOD
                # print(nw)
 
    # print(tmp[(13*kt):13*(kt+1)])
    # tmp = [num % MOD for num in nw]
    # tmp = nw
print(tmp[-8] % MOD)
 

Measured memory_bytes: 115820
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define INF 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
//dp[i桁目まで見た時][現時点の数を13で割ったあまり] <- 0埋めしてから足していく
ll dp[1000000][20];
int main(){
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i,n)rep(j,13){
    if(s[i] == '?'){
      rep(k,10)dp[i + 1][(j * 10 + k) % 13] += dp[i][j] % INF;
    }
    else{
      int k = s[i] - '0';
      dp[i + 1][(j * 10 + k) % 13] += dp[i][j] % INF;
    }
  }
  cout << dp[n][5] % INF << endl;
  return 0;
}


Measured memory_bytes: 16896
#include<stdio.h>

int main(){
	int N, K, X, Y, i;
	i = scanf("%d %d %d %d", &N, &K, &X, &Y);
	if(N <= K){
		printf("%d\n", N * X);
		return 0;
	}
	else printf("%d\n", K * X + (N - K) * Y);
	return 0;
}

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

int main(){

    int  h,n,a;
    cin >> h >> n ;
    int total = 0;
    rep(i,n){
        int tt = 0;
         cin >> tt;
         total += tt;
    }

    if(h <= total) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Katana = Tuple!(long, "swing", long, "throwing");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, h;
    scan(n, h);
    auto k = new Katana[](n);
    long throw_sum;
    foreach (i; iota(n))
    {
        long a, b;
        scan(a, b);
        k[i] = Katana(a, b);
        throw_sum += k[i].throwing;
    }

    long cnt1 = INF, cnt2 = INF;
    if (h <= throw_sum)
    {
        k.sort!"a.throwing > b.throwing"();
        cnt1 = 0;
        auto tmp = h;
        while (tmp > 0)
            tmp -= k[cnt1++].throwing;
    }

    k.sort!"a.swing < b.swing"();
    cnt2 = 0;
    foreach (i; iota(n - 1))
    {
        if (k[i].throwing > k[$ - 1].swing)
        {
            h -= k[i].throwing;
            cnt2++;
        }
    }

    while (h > k[$ - 1].throwing)
    {
        h -= k[$ - 1].swing;
        cnt2++;
    }

    if (h)
        writeln(min(cnt1, cnt2 + 1));
    else
        writeln(min(cnt1, cnt2));
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
 cin>>s;
 set<char> t;
 for(int i=0;i<4; i++){
     t.insert(s.at(i));
 }
 if(t.size()==2) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a[10][10] = {0}, x, y, s, i, j, n1 = 0, n2 = 0;

  while (scanf("%d,%d,%d", &x, &y, &s) != EOF) {
    a[y][x]++;
    if (s >= 1) {
      if (x - 1 >= 0) a[y][x-1]++;
      if (x + 1 < 10) a[y][x+1]++;
      if (y - 1 >= 0) a[y-1][x]++;
      if (y + 1 < 10) a[y+1][x]++;
    }
    if (s >= 2) {
      if (x - 1 >= 0 && y - 1 >= 0) a[y-1][x-1]++;
      if (x + 1 < 10 && y - 1 >= 0) a[y-1][x+1]++;
      if (x - 1 >= 0 && y + 1 < 10) a[y+1][x-1]++;
      if (x + 1 < 10 && y + 1 < 10) a[y+1][x+1]++;
    }
    if (s == 3) {
      if (x - 2 >= 0) a[y][x-2]++;
      if (x + 2 < 10) a[y][x+2]++;
      if (y - 2 >= 0) a[y-2][x]++;
      if (y + 2 < 10) a[y+2][x]++;
    }
  }
  
  for (i = 0; i < 10; i++)
    for (j = 0; j < 10; j++)
      if (a[i][j] == 0) n1++;

  for (i = 0; i < 10; i++)
    for (j = 0; j < 10; j++)
      if (a[i][j] > n2) n2 = a[i][j];

  printf("%d\n", n1);
  printf("%d\n", n2);

  return 0;
}

Measured memory_bytes: 600
from math import sqrt

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

result = 0
for i in range(N):
    for j in range(N):
        if i != j:
            result += sqrt((xy[i][0] - xy[j][0]) * (xy[i][0] - xy[j][0]) + (xy[i][1] - xy[j][1]) * (xy[i][1] - xy[j][1]))
print(result / N)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint H, W, N;
	cin >> H >> W >> N;

	vector<pair<int, int>> blk(N);
	for (int i = 0; i < N; i++) cin >> blk[i].first >> blk[i].second;

	map<lint, lint> sqmap;
	vector<int> dxdy{-1, 0, 1};

	for (int i = 0; i < N; i++) {

		for (const auto &dx : dxdy) {
			for (const auto &dy : dxdy) {

				lint x = blk[i].second + dx;
				lint y = blk[i].first + dy;

				if (1 < x && x < W && 1 < y && y < H) {
					sqmap[(y - 1) * W + x - 1]++;
				}

			}
		}

	}

	vector<lint> ans(10);
	for (const auto &elem : sqmap) ans[elem.second]++;

	ans[0] = (H - 2) * (W - 2) - (lint)(sqmap.size());

	for (const auto &elem : ans) cout << elem << "\n";

	return 0;
}

Measured memory_bytes: 57344
N,D,A=map(int,input().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,input().split()))

X=sorted(X,key=lambda x:x[0])
lastX=X[-1][0] # 最後のモンスターの場所
from collections import defaultdict
damage=defaultdict(int)
ans=0
for i in range(len(X)):
  x=X[i][0]
  h=X[i][1]
  if h>0:
    dele=set()
    for d in damage.items():
      if d[0]<x:
        dele.add(d[0])
      else:
        h-=d[1]
    for p in dele:
      del damage[p]
  if h>0:
    turn=(h+A-1)//A
    if x+D>lastX:
      damage[lastX]+=turn*A
    else:
      damage[x+D]=turn*A
    ans+=turn
print(ans)

Measured memory_bytes: 80320
// SeeAlso: https://atcoder.jp/contests/abc120/tasks/abc120_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int A,B,K;
int main() {
    cin >> A >> B >> K;

    int m = min(A,B);

    int counter=0;
    
    for(int i=m;i>0;i--) {
        if((A%i)==0 && (B%i)==0) {
            counter++;
        }
        if(counter==K) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    int a,b,base,base_max;
    scanf("%d%d", &a ,&b);

    base = ceil((double)(a*100)/(double)8);
    base_max = ceil((double)((a+1)*100)/(double)8);

    int output=-1;

    while(base < base_max){
        if(floor((double)base/(double)10)==b){
            output = base;
            break;
        }
        base++;
    }
    cout << output << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int dp[31];

int main() {
	dp[0] = 1;
	dp[1] = 1;
	dp[2] = 2;
	FOR(i, 3, 31) {
		dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
	}
	int N;
	while(scanf("%d", &N), N) {
		printf("%d\n", dp[N]/10/365 + 1);
	}
	return 0;
}

Measured memory_bytes: 3108
n=int(input())
d,x=map(int,input().split())
a=[int(input()) for i in range(n)]

s=0
k=0
j=0

for i in range(1,n+1):
    k=a[i-1]
    while k*j+1<=d:
        s+=1
        j+=1     
    j=0        
    k=0
ans=s+x
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <time.h>
#include <algorithm>
using namespace std;
#define INF 2147483647 

int dp[100001];
int main() {
	ios_base::sync_with_stdio(false);

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

	cout << max << "\n";
}


Measured memory_bytes: 1024
//こんなプログラムを組んではいけない(戒め
//マージの仕様が複雑だし、空白マスを引く処理忘れやすいし、ひどいコードだ。
#include<iostream>
#include<queue>
using namespace std;

const int h = 12;
const int w = 12;
const int dy[4] = {-1, 0, 1, 0};
const int dx[4] = {0, 1, 0, -1};

char data[h][w+2];

//データ構造をマージする一般的なテクなし。
class UnionFind {
public:
	int oya[2521], size;
	void ini(int size) { this->size = size; for( int i = 0;i < size; i++ ) oya[i] = i; }
	int root(int x) { if( oya[x] == x ) return x; return (oya[x] = root(oya[x]) ); }
	void marge(int x, int y) { x = root(x); y = root(y); if ( x != y ) { size--; oya[x] = y; } }
}uf;

void bfs(int sy, int sx) {
	queue<int> que;
	que.push(sy*w + sx);
	
	while( !que.empty() ) {
		int now = que.front();
		que.pop();
		
		if ( data[now/w][now%w] == '0' )
			continue;
		if ( uf.root(now) != now ) 	//すでに調べている(マージされている)ならcontinue
			continue;
		
		uf.marge(now, sy*w + sx);	//nowをsy*w + sxにくっつける(逆にしたら無限ループするかも)
		
		for(int i = 0; i < 4; i++ ) {
			int ny = now/w + dy[i];
			int nx = now%w + dx[i];
			if ( 0 <= ny && ny < h && 0 <= nx && nx < w )
				que.push(ny * w + nx);
		}
	}
}

int main() {
	int i, j;
	while( cin >> data[0] ) {
		for( i = 1; i < h; i++ )
			cin >> data[i];
		
		uf.ini(h*w);
		
		int minus = 0;
		for( i = 0; i < h; i++ ) {
			for( j = 0; j < w; j++ ) {
				minus += (data[i][j] == '0');
				bfs(i, j);
			}
		}
		cout << uf.size - minus << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

//bugged 18278,702
int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll n;
    cin >> n;
    n--;
    //first find how many characters the dogs name is
    ll count = 26;
    ll chars = 1;
    ll ithstring = n;
    while(count<=ithstring) {
        chars++;
        ithstring-=count;
        count*=26;
    }
    string name(chars, '0');
    //reset count so that 0 points to the first string of that size aaa
    //start with right most character
    //power of count
    ll div = 26;
    for(ll digit=0; digit<chars; digit++) {
        //see modulo of ith/count
        char d = 'a'+(ithstring%div);
        name[digit] = d;
        ithstring/=26;
    }
    //reverse
    reverse(name.begin(), name.end());
    cout << name << "\n";
    return 0;
}


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

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i <= _##i poi  i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i < _##i poi  i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i >= _##i poi  i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i > _##i poi  i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

/*#define do {*/
/*#define end }*/

#define val const auto
#define var auto

#define zenbu(c) c.begin(), c.end()

#define fuwafuwa(n, c) dokidoki((n) + (c) - 1, c)
#define dokidoki(n, c) ((n) / (c) * (c))

template<class T> bool read(T& t){
    return cin >> t poi
}
template<class T, class...U> bool read(T& t, U&... u){
    unless(cin >> t) return false poi
    return read(u...) poi
}

template<class T> T lov_yet(T t){
    if(t) return t poi
    else return 0 poi
}

template<class T> T gcd(T a, T b){
    if(b) return gcd(b, a % b) poi
    else return a poi
}

pair<double, double> solve_linear(double a1, double b1, double c1, double a2, double b2, double c2){
    return make_pair(lov_yet((b1 * c2 - b2 * c1) / (b1 * a2 - b2 * a1)), lov_yet((a1 * c2 - a2 * c1) / (a1 * b2 - b1 * a2))) poi
}

const long double PI = 3.141592653589793238462643383279502884L poi

double distance(const pair<double, double>& p){
    return lov_yet(sqrt(p.first * p.first + p.second * p.second)) poi
}
double distance(const pair<double, double>& a, const pair<double, double>& b){
    return distance(make_pair(a.first - b.first, a.second - b.second)) poi
}

double inner_product(const pair<double, double>& a, const pair<double, double>& b){
    return lov_yet(a.first * b.first + a.second * b.second) poi
}

double outer_product_z(const pair<double, double>& a, const pair<double, double>& b){
    return lov_yet(a.first * b.second - b.first * a.second) poi
}

template<class T> T toppo(stack<T>& stick){
    T choco = stick.top() poi
    stick.pop() poi
    return choco poi
}

bool include_word(const string& s, const string& find){
    if(s.size() < find.size()) return false poi
    if(s == find) return true poi
    if(s.substr(0, find.size() + 1) == find + " " || s.substr(s.size() - find.size() - 1) == " " + find) return true poi
    times(s.size() - find.size() - 2, i)
        if(s.substr(i, find.size() + 2) == " " + find + " ") return true poi
    return false poi
}

int main(){
    vector<int> pyon(5) poi
    times(5, i) cin >> pyon[i] poi
    sort(zenbu(pyon), greater<int>()) poi
    times(5, i) cout << (i ? " " : "") << pyon[i] poi
    cout poipoi poi

    return 0 poi
}

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

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

const double PI = 3.14159265358979323846;
const int mod = 1e9+7;
// int 1e9+7 double 1e-12 long long 1e18

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll n, m, d;
  cin >> n >> m >> d;
  // ll ans = 0;
  // rep(i,1,n){
  //   rep(j,1,n){
  //     rep(k,1,n){
  //       rep(l,1,n){
  //         rep(o,1,n){
  //           rep(p,1,n){
  //           // cout << i << "," << j << "," << k << endl;
  //           ans += (abs(i - j) == 3) + (abs(j - k) == 3) + (abs(k - l) == 3) + (abs(l - o) == 3) + (abs(p - o) == 3); 
  //         }}
  //       }
  //     }
  //   }
  // }
  double ans = (m-1) * (n-d);
  if (d != 0){
    ans *= 2;
  }
  ans = ans / (n * n);
  cout << fixed;
  cout << setprecision(10) << ans << endl;
  return 0;
}


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

int main(){
 
  int A,B,C,D;
  string ans;
  cin >> A >> B >> C >> D;
 
  while(true){
    C -= B;
    if(C <= 0){
      ans = "Yes";
      break;
    }
    A -= D;
    if(A <= 0){
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3628
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
from collections import deque
#from decimal import Decimal

INF = 1 << 50

def run():
    K, T, *A = map(int, read().split())
    max_a = max(A)
    print(max(max_a-1-K+max_a, 0))

if __name__ == "__main__":
    run()

Measured memory_bytes: 9364
use std::io::Read;
fn main(){
 let mut s=String::new();
 std::io::stdin().read_to_string(&mut s).unwrap();
 s=s.trim().to_lowercase();
 let a=(b'a'..b'z'+1).map(|c|c as char);
 let n=a.map(|x|(x,s.chars().filter(|&c|c==x).count()));
 for i in n{
  println!("{} : {}",i.0,i.1);
 }
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1000000007ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int gcc(int n, int m) {
    int a = max({n, m});
    int b = min({n, m});
    if(b == 0) return a;
    int c;
    while(a % b != 0){
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}

int main() {
    vector<int> a(55556, 1);
    a.at(0) = 0;
    a.at(1) = 0;
    vector<int> ans;
    rp(i, 0, 55556){
        if(a.at(i) == 1){
            if(i % 5 == 1) ans.push_back(i);
            int j = 1;
            while(i * j <= 55555){
                a.at(i*j) = 0;
                j ++;
            }
        }
    }
    int N;
    scanf("%d", &N);
    rp(i, 0, N) printf("%d ", ans.at(i));
    return 0;

}

Measured memory_bytes: 512