akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)
import numpy as np
from collections import defaultdict
d = defaultdict(int)
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    # b_list = []
    # c_list = []
    n, m = map(int, input().split())
    d = defaultdict(int)
    a_list = list(map(int, input().split()))

    for a in a_list:
        d[a] += 1

    for j in range(m):
        b, c = map(int, input().split())
        d[c] += b
        # a_list += [c] * b
        # b_list.append(b)
        # c_list.append(c)

    #print(d)
    current_n = 0
    sum = 0
    for k in sorted(d.keys(), reverse=True):
        sum += min(d[k], n - current_n) * k
        current_n += d[k]
        if current_n >= n:
            break
    print(sum)
    # for j in range(m):
    #     a_list += [c_list[j]] * b_list[j]

    # a_list.sort(reverse=True)
    # print(sum(a_list[:n]))


    # a = np.array(a_list, dtype=np.int64)


    #
    # for j in range(m):
    #     a.sort()
    #     to_index = min(b_list[j], sum(a < c_list[j]))
    #     a[:to_index] = c_list[j]
    #
    # print(np.sum(a))
solve()

Measured memory_bytes: 41080
#include <iostream>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;

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

Measured memory_bytes: 3596
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n, x; cin >> n >> x;
    vector<int> m(n);
    rep(i, n) cin >> m.at(i);

    int res = 1001;
    int sum = 0;
    rep(i, n){
        res = min(res, m.at(i));
        sum += m.at(i);
    }

    sum = x - sum;
    ll ans = 0;
    ans = sum/res;
    ans += n;

    cout << ans << endl;

    return 0;
}


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

int main(){
  int r, g, b, n;
  cin >> r >> g >> b;
  n = 100 * r + g * 10 + b;
  if (n % 4 == 0)
    cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
 
using namespace std;
 
typedef long long ll;
 
ll n, s;
 
ll f(ll p, ll q)
{
    ll cnt = 0;
    while(p != 0)
    {
        cnt += p % q;
        p /= q;
    }
    return cnt;
}
 
int main()
{
    scanf("%lld%lld", &n, &s);
    ll i;
    if(n < s)
    {
        printf("-1");
        return 0;
    }
    if(n == s)
    {
        printf("%lld", n + 1);
        return 0;
    }
    for(i = 2; i * i <= n; i++)
    {
        if(f(n, i) == s)
        {
            printf("%lld", i);
            return 0;
        }
    }
    for(; i >= 1; i--)
    {
        if((n - s) % i == 0 && f(n, (n - s) / i + 1) == s)
        {
            printf("%lld", (n - s) / i + 1);
            return 0;
        }
    }
    if(s == 1)
    {
        printf("%lld", n);
        return 0;
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;



int ret_num(int n, int m, int cheak[1000], int *num){
    if(m==1&&cheak[*num]==0)return *num;
    if(m==1||cheak[*num]==1){
        *num=(*num+1)%n;
        return ret_num(n, m, cheak, num);
    }
    *num=(*num+1)%n;
    return ret_num(n, m-1, cheak, num);
}


int main(void)
{
    int n,m;
    
    while(cin>>n>>m){
        int counter = n;
        int num = 0;
        int cheak[1000]={0};
        if(n==0&&m==0)break;
        while(counter!=1){
            counter--;
            cheak[ret_num(n, m, cheak, &num)]=1;
            /*for(int i=0; i<n; i++){
                cout<<setw(3)<<i+1;
            }cout<<endl;
            for(int i=0; i<n; i++){
                cout<<setw(3)<<cheak[i];
            }cout<<endl;*/
        }
        for(int i=0; i<n; i++){
            if(cheak[i]==0){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    
    
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;


vector<ll> g[200005];
ll subtree[200005],a[200005],ans[200005];
bool blocked[200005];

void dfs1(ll root,ll par)
{
	int cnt=0;
	for(auto x:g[root])
	{
		if(x!=par && !blocked[x])
			{
				cnt++;
				dfs1(x,root);
				subtree[root]+=subtree[x];
			}
	}
	if(cnt==0) subtree[root]=1;
	else
	subtree[root]++;
}

ll best;
void dfs2(ll &root,ll cur,ll par,ll &res)
{
	for(auto x:g[cur])
	{
		if(x!=par && !blocked[x])
		{
			dfs2(root,x,cur,res);
			ll mx=max(subtree[x],subtree[root]-subtree[cur]);
			if(mx<best)
			{
				best=mx;
				res=cur;
			}
		}
	}
}

ll find_centroid(ll root)
{
	subtree[0]=-1;
	subtree[root]=0;
	dfs1(root,0);
	ll res=root;
	best=INT_MAX;
	dfs2(root,root,0,res);
	return res;
}

ll dfs3(ll cur,ll par,ll val,vector<ll>&vv)
{

	vv.pb(val);

	for(auto x:g[cur])
	{
		if(x!=par && !blocked[x])
			dfs3(x,cur,(val^a[x]),vv);
	}
}

ll dp[3001][3001];

int main()
{
    int tests=1;
    // cin>>tests;
    while(tests--)
    {
    	ll i,j,n,m;
    	string s,t;
    	cin>>s>>t;
    	n=s.length();
    	m=t.length();
    	rep(i,1,n)
    	{
    		rep(j,1,m)
    		{
    			if(s[i-1]==t[j-1])
    			{
    				dp[i][j]=1+dp[i-1][j-1];
    			}
    			else
    			{
    				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    			}
    		}
    	}
    	string ans;
    	i=n,j=m;
    	while(i>0 && j>0)
    	{
    		if(s[i-1]==t[j-1])
    		{
    			ans.pb(s[i-1]);
    			i--;
    			j--;
    		}
    		else
    		{
    			if(dp[i-1][j]>=dp[i][j-1])
    				i--;
    			else
    				j--;
    		}
    	}
    	reverse(all(ans));
    	cout<<ans;

    }

    return 0;
}
    

Measured memory_bytes: 78628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		int K = scanner.nextInt();

		int[] cumulant = new int[N+1];

		for (int i = 0; i < N; i++) {
			cumulant[i+1] = cumulant[i] + scanner.nextInt();
		}

		scanner.close();

		int max = 0;

		for (int i = 0; i + K <= N; i++) {
			if (cumulant[i + K] - cumulant[i] > max)
				max = cumulant[i + K] - cumulant[i];
		}

		System.out.println((double) (max + K) / 2);
	}

}


Measured memory_bytes: 64956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="Sunny"){cout<<"Cloudy"<<endl;}
    else if(s=="Cloudy"){cout<<"Rainy"<<endl;}
    else if(s=="Rainy") {cout<<"Sunny"<<endl;}
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << (b - 1) / (a - 1) + ((b - 1) % (a - 1) > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 256
s=int(input())
ls=[s]
for i in range(1000000):
  if s%2==0:
    s=s/2
    if s in ls:
      print(len(ls)+1)
      break
    else:ls.append(s)
  else:
    s=3*s+1
    if s in ls:
      print(len(ls)+1)
      break
    else:ls.append(s)

Measured memory_bytes: 3060
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end
require 'complex'
def eratosthenes(n)
	is_p = Array.new(n+1){true}
	is_p[0] = false
	is_p[1] = false
	2.upto(N){|i|
		if(is_p[i])
			j = i+i
			while(j<=N)
				is_p[j]=false
				j+=i
			end
		end
	}
	is_p
end
def prime_decomp(n,is_p)
	h = {}
	if(is_p[n])
		h[n] = 1
		return h
	end
	q = n
	for d in 2..(Math.sqrt(n).to_i)
		if(is_p[d])
			dcnt = 0
			while(q%d==0)
				q /= d
				dcnt += 1
			end
			dcnt != 0 ? h[d] = dcnt : 1
		end
	end
	q != 1 ? h[q] = 1 : 1
	dpp h
	h
end
def comb(n,a)
	return $fact[n] * $finv[a] % $mod * $finv[n-a] % $mod;
end
def pow(a,n)
	prd = 1;
	exp = a;
	while(n > 0)
		if((n&1)==1)
			prd *= exp;
			prd %= $mod;
		end
		exp *= exp;
		exp %= $mod;
		n >>= 1;
	end
	return prd;
end
# constant
NMAX = 100100;
$mod = 998244353;
$mod = 10**9+7;
$fact = Array.new(NMAX);
$finv = Array.new(NMAX);
# read
# preprocess
$fact[0] = 1;
$finv[0] = 1;
for i in 1..(NMAX)
	$fact[i] = $fact[i-1] * i % $mod;
	$finv[i] = pow($fact[i], $mod-2);
end
# main
N,M=gets.chomp.split(' ').map{|n| n.to_i}
num = 1
is_p = eratosthenes(Math.sqrt(M))
prime_decomp(M,is_p).each{|k,v|
	num = num * comb(v+N-1,v) % $mod
}
puts num


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

int main() {
  map<char, queue<char>> cards;
  string a, b, c;
  cin >> a >> b >> c;
  for (auto& ch : a) cards['a'].push(ch);
  for (auto& ch : b) cards['b'].push(ch);
  for (auto& ch : c) cards['c'].push(ch);

  char turn = 'a';
  while (!cards[turn].empty()) {
    char new_turn = cards[turn].front();
    cards[turn].pop();
    turn = new_turn;
  }
  cout << (char)toupper(turn) << endl;
}


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

using namespace std;

int main(void){
    int N,Q;
    cin>>N>>Q;
    string S;
    cin>>S;
    vector<int> l(Q);
    vector<int> r(Q);
    int ans=0;
    

    for (int i = 0; i < Q; i++){
        cin>>l[i]>>r[i];
    }
    
    vector<int>  AC(N);
    for (int i=0;i<N-1;i++){
        if(S[i]=='A'&&S[i+1]=='C') i!=0?AC[i]=AC[i-1]+1:AC[i]=1;
        else i!=0?AC[i]=AC[i-1]:AC[i]=0;
        //cout<<i<<":"<<AC[i]<<endl;
    }

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

        cout<<AC[r[i]-2]-AC[l[i]-2]<<endl;
        
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 2176
#-*-coding:utf-8-*-

def main():
    n = int(input())
    ans = 0
    for i in range(1, n+1, 2):
        temp = 0
        for j in range(1, i+1):
            if i % j == 0:
                temp += 1
        if temp == 8:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
    int i,n;
    map<int,int> m;
    cin>>n;
    int a[n-1];
    for(i=0;i<n-1;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        m[i+1];
    }
    for(int i=0;i<n-1;i++){
        m[a[i]]++;
    }
    for(auto it=m.begin();it!=m.end();it++){
        cout<<it->second<<endl;
    }
    return 0;
}


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

#define pb push_back
#define F first
#define S second
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define SET(x, val) memset(x, val, sizeof(x))
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 5, MOD1 = 1e9 + 7, MOD2 = 998244353;
const lint INF = 1e18;

int a[N], b[N], n;
priority_queue<int, vector<int>, greater<int>> st;
priority_queue<int> st2;

bool solve()
{
    while(st.size()) st.pop();
    for(int i = 1; i <= n; i++)
    {
        st.push(i+a[i]);
        b[i] = st.size();
        while(st.size() && st.top()==i) st.pop();
    }
   /* for(int i = 1; i <= n; i++)
    {
        cout << b[i] << " ";
    }
    cout << endl;*/
    while(st2.size()) st2.pop();
    for(int i = n; i >= 1; i--)
    {
        st2.push(i-a[i]);
        b[i]+=st2.size()-1;
        while(st2.size() && st2.top()==i) st2.pop();
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        a[i]=b[i];
        if(a[i]==n) cnt++;
    }
    if(cnt==n) return true;
    return false;
}
signed main()
{
    fastio;
    int k;
    cin >> n >> k;
    //n = 200000, k = 100;
    //a[1]=1;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for(int i = 1; i <= k; i++)
    {
        //cout << i << endl;
        bool comp = solve();
        if(comp) break;
    }
    for(int i = 1; i <= n; i++)
    {
        cout << a[i] << " ";
    }
}

Measured memory_bytes: 7004
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }
        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);
            int[] B = new int[N];
            Array.Copy(A, B, N);
            Array.Sort(B);
            for(int i = 0; i < N; i++)
            {
                if(B[N-1] == A[i])
                {
                    WriteLine(B[N-2]);
                    continue;
                }
                WriteLine(B[N-1]);
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 18812
# -*- coding: utf-8 -*-
S = int(input())

hour = int(S / (60 * 60))
minutes = int((S % (60 * 60)) / 60)
seconds = int((S % (60 * 60)) % 60)

watch = str(hour) + ":" + str(minutes) + ":" + str(seconds)

print(watch)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int s,w;
    cin>>s>>w;
    string ans ="safe";
    if(s<=w) ans="unsafe";
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int s1s2s3;
  cin >> s1s2s3;
  cout << s1s2s3 / 100 + s1s2s3 % 100 / 10 + s1s2s3 % 100 % 10 << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
//#include <cstdlib>

using namespace std;


int main(){
	long long a,b,v,w,t;
	cin >> a >> v >> b >> w >> t;
	if (w - v == 0){
	 cout << "NO";
	 return 0;
	}
    if (a < b){
		if ((double)(a-b)/(w-v) <= t && (double)(a-b)/(w-v) >= 0) 
			cout << "YES";
		else cout<< "NO";
    }else{
    	if ((double)(a-b)/(v-w) <= t && (double)(a-b)/(v-w) >= 0) 
			cout << "YES";
		else cout<< "NO";
    }
	//system("PAUSE");
	return 0;
}

Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

bool comp(ll x, ll y){
	ll x1=x, y1=y;
	ll d1=0, d2=0;
	while(x1>0){
		d1+=(x1%10);
		x1/=10;
	}
	while(y1>0){
		d2+=(y1%10);
		y1/=10;		
	}
	if(x*d2!=y*d1){
		return x*d2<y*d1;
	}else{
		return x<y;
	}
}

int main()
{
	int k;
	scanf("%d", &k);
	vector<ll> v;
	ll p10=1;
	set<ll> st;
	for(ll d=1; d<=13; d++){
		for(ll i=1; i<1000; i++){
			st.insert((i+1)*p10-1);
		}
		p10*=10;
	}
	for(auto itr=st.begin(); itr!=st.end(); itr++){
		v.push_back(*itr);
	}
	bool e[200000]={};
  	ll m=v.back();
	for(int i=v.size()-2; i>=0; i--){
		if(!comp(v[i], m)){
          e[i]=1;
        }else{
          m=v[i];
        }
	}
	int t=0, i0=0;
	while(t<k){
		if(e[i0]==1){
			i0++;
			continue;
		}else{
			printf("%lld\n", v[i0]);
          i0++;
          t++;
        }
    }
	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;


public class Main{
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int w=Integer.valueOf(scan.nextLine());
	int n=Integer.valueOf(scan.nextLine());
	int[] a=new int[n];
	int[] b=new int[n];
	int[] lots=new int[w+1];
	int temp;

	for(int i=1;i<lots.length;i++){
		lots[i]=i;
	}
	for(int i=0;i<n;i++){
		String str=scan.nextLine();
		String[] s=str.split(",");
		a[i]=Integer.valueOf(s[0]);
		b[i]=Integer.valueOf(s[1]);

		temp=lots[a[i]];
		lots[a[i]]=lots[b[i]];
		lots[b[i]]=temp;
	}
	for(int i=1;i<lots.length;i++){
		System.out.println(lots[i]);
	}


	}

}

Measured memory_bytes: 17184
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int N; cin>>N;
  int a = 0;
  int b = 0;
  REP(count,N){
    string s,t; cin>>s>>t;
    if(s>t){ a += 3; }
    else if(s<t){ b += 3; }
    else{ ++a; ++b; }
  }
  printf("%d %d\n",a,b);
}


Measured memory_bytes: 3260
import numpy as np
H, W = map(int, input().split())

c = []
for _ in range(10):
    tmp = list(map(int, input().split()))
    c.append(tmp)
c = np.array(c)
# print(c)

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for _ in range(H):
    for i in map(int, input().split()):
        if i not in [-1, 1]:
            ans += c[i][1]
print(ans)


Measured memory_bytes: 17860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n, c, k;
    cin >> n >> c >> k;

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

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

    int r = 0, t1, c1 = c;
    for (int i = 0; i < n; i++) {
        c1++;
        if (c1 > c || t[i] > t1) {
            c1 = 1;
            t1 = t[i] + k;
            r++;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;


int main()
{ 
	int arr [300000][60];
	int arr2 [300000][60];
	int MOD=1000000007;
	long long arr3[60];
	long long cnt;
	cnt=0;
	for(int i=0;i<60;i++)arr3[i]=0;
	arr3[0]=1;
	for(int i=1;i<60;i++){
		arr3[i]=(arr3[i-1]*2)%MOD;
//      	cout<<arr3[i]<<endl;
	}
	for(int i=0;i<300000;i++)for(int j=0;j<60;j++){arr[i][j]=0;arr2[i][j]=0;}
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		long long cur;
		cin>>cur;
		for(int j=0;j<60&&cur!=0;j++){
			arr[i][j]=cur%2;
//          	cout<<i<<" "<<j<<" "<<arr[i][j]<<endl;
			cur=cur/2;
		}
	}
	for(int i=0;i<60;i++){
		arr2[n-1][i]=arr[n-1][i];
	}
	for(int i=n-2;i>=0;i--)
		for(int j=0;j<60;j++){
			arr2[i][j]=arr2[i+1][j]+arr[i][j];
//          cout<<i<<" "<<j<<" "<<arr2[i][j]<<endl;
		}
	for(int i=0;i<n-1;i++){
		for(int j=0;j<60;j++){
			if(arr[i][j])cnt+=(arr3[j]*(n-i-1-arr2[i+1][j]))%MOD;
			else cnt+=(arr3[j]*arr2[i+1][j])%MOD;
			cnt=cnt%MOD;
//          	cout<<cnt<<endl;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


	


Measured memory_bytes: 140928
//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define se second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;


int main()
{
	fast;
	
	ll n;
	cin>>n;
	ll a[n];
	ll b[n];
	
	ll x,y;
	
	ll i;
	for(i=0;i<n;i++)
	{
		cin>>x>>y;
		a[i]=x+y;
		b[i]=x-y;
	}
	sort(a,a+n);
	sort(b,b+n);
	
	ll ans=max(abs(b[n-1]-b[0]),abs(a[n-1]-a[0]));
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 6676
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;


map<ll,ll> mm;

int main()
{
    idfc;
    ll n;
    cin>>n;
    ll i;
    for(i=2;i*i<=n;i++)
    {
        while(!(n%i))
        {
         //   cout<<n<<endl;
            mm[i]+=1;
            n/=i;
        }
       // cout<<i<<endl;
    }
    if(n>1)mm[n]+=1;


    int x;
    int ans=0;
    for(auto it:mm)
    {
        x=it.second; i=1;
        while(x>=i)
        {
            ans++;
            x-=i;
            i++;
        }
    }
    cout<<ans;

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, k;
vector<int> g[112345];
int num[112345];

int main() {
	cin >> n;
	REP(i, n - 1) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	priority_queue<pii, vector<pii>, greater<pii> > pq;
	
	cin >> k;
	REP(i, k) {
		int v, p;
		scanf("%d %d", &v, &p);
		v--;
		num[v] = p;
		
		pq.push(pii(p, v));
	}
	
	fill(num, num + n, -1);
	
	while (!pq.empty()) {
		pii now = pq.top(); pq.pop();
		
		int p = now.first;
		int u = now.second;
		
		num[u] = p;
		
		REP(i, g[u].size()) {
			int v = g[u][i];
			if (~num[v]) continue;
			pq.push(pii(p + 1, v));
			num[v] = p + 1;
		}
	}
	
	bool ng = false;
	REP(u, n) if (num[u] == -1) ng = true;
	
	REP(u, n) REP(i, g[u].size()) {
		int v = g[u][i];
		if (abs(num[u] - num[v]) != 1) ng = true;
	}
	
	if (ng) puts("No");
	else {
		puts("Yes");
		REP(i, n) printf("%d\n", num[i]);
	}
	
	return 0;
}

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

int  main(){
    int n;
    cin >> n;
    int min = n;
    for(int i =0; i <= n; i++){
        int count = 0;
        int tmp = i;
        while(tmp > 0){
            count += tmp%6;
            tmp /= 6;
        }
        tmp = n-i;
        while(tmp > 0){
            count += tmp%9;
            tmp /= 9;
        }
        if(count < min)
            min = count;
    }
    cout << min;
}

Measured memory_bytes: 256
/*
    author:ujwalll
*/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std; 
#define rep(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1<<29;
const int MOD=1073741824;
#define pp pair<ll,ll>
#define ppi pair<int,int>
typedef long long int ll;
bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
////////////////////////////////////////////////////////////////////

int main(){
    int tc=1;
    // cin>>tc;
    while(tc--){
        double d,t,s;
        cin>>d>>t>>s;
        if((d/s)<=t)cout<<"Yes";
        else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  cout<<a.back()-a.front();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

int main(){
    fastio;
    int s,w;
  cin>>s>>w;
  if(w>=s) cout<<"unsafe\n";
  else cout<<"safe\n";
}




Measured memory_bytes: 3636
#include <iostream>

int main() {
  int an, bn, mn;
  int min;
  int min_a = 999999;
  int min_b = 999999;
  int a[100000];
  int b[100000];
  for (int i = 0; i < 100000; i++) a[i] = b[i] = 0;
  std::cin >> an >> bn >> mn;
  for (int i = 0; i < an; i++) {
    std::cin >> a[i];
    if (min_a > a[i]) min_a = a[i];
  }
  
  for (int i = 0; i < bn; i++) {
    std::cin >> b[i];
    if (min_b > b[i]) min_b = b[i];
  }
  min = min_a + min_b;
  
  for (int i = 0; i < mn; ++i) {
    int xi, yi, c;
    std::cin >> xi >> yi >> c;
    int temp = a[xi-1] + b[yi-1] - c;
    if (min > temp) min = temp;
  }
  std::cout << min << std::endl;
}

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

int solve(int n, int x) {
    int res = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int k = j + 1; k <= n; k++) {
                if (i + j + k == x) {
                    res++;
                }
            }
        }
    }

    return res;
}

int main() {
    int n, x;
    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }
        cout << solve(n, x) << "\n";
    }
}



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

int n;
int a[101][101];
int flag[101];
int t[101];
int sum = 0;

void prim(){
  int ima = 0;
  int mine = 100000000;
  
  
  for(int k=0;k<n-1;k++) {
    mine = 10000000;
    for(int i=0;i<n;i++) {
      if(flag[i] == 0 && mine > t[i]) {
	mine = t[i];
	ima = i;
      }
    }
    sum += mine;
    flag[ima] = 1;
    
    for(int i=0;i<n;i++) 
      if(a[ima][i] != -1) 
	if(t[i] > a[ima][i] ) t[i] = a[ima][i];
    
    
  }
}

int main() {

  cin >> n;

  for(int i=0;i<n;i++) 
    for(int j=0;j<n;j++) 
      cin >> a[i][j];
  
  for(int i=0;i<n;i++) {
    flag[i] = 0;
    t[i] = 100000000;
  }
  
  t[0] = 0;
  flag[0] = 1;
  for(int i=0;i<n;i++) 
    if(a[0][i] != -1) t[i] = a[0][i];

  prim();

  cout << sum << endl;
 
  return 0; 
  
}



Measured memory_bytes: 3124
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]
w1 = wv[0][0]

w_to_idx = {0:0}
idx_to_w = {0:0}
idx_W = 0
def calc():
  global w_to_idx, idx_to_w, idx_W
  idx = 1
  w_max = 0
  for i in range(1, N+1):
    w = w1*i
    for j in range(3*i + 1):
      ww = w + j
      if ww in w_to_idx:
        continue
      w_to_idx[ww] = idx
      idx_to_w[idx] = ww
      if w_max < ww <= W:
        w_max = ww
        idx_W = idx
      idx += 1

calc()
n = len(w_to_idx)
dp = [[0]*n for i in range(N+1)]
for i, (w, v) in enumerate(wv, 1):
  for j in range(n):
    dp[i][j] = dp[i-1][j]
    ww = idx_to_w[j]
    if ww >= w and ww-w in w_to_idx:
      jj = w_to_idx[ww - w]
      dp[i][j] = max(dp[i][j], dp[i-1][jj] + v)

print(max(dp[-1][:idx_W+1]))

Measured memory_bytes: 53648
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
    ll n, sum = 0;
    scanf("%lld", &n);
    for (size_t i = 1; i <= n; i++)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }
    printf("%lld", sum);
}

Measured memory_bytes: 1716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_NMX 100000

using namespace std;
typedef pair<llong, llong> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, M, X[MAX_NMX];

int numbers[MAX_NMX + 1];
int not_paired[MAX_NMX];
int pairs[MAX_NMX];


int solve() {
    for(int i = 0; i < N; ++i)
        numbers[X[i]]++;

    for(int i = 0; i <= MAX_NMX; ++i) {
        pairs[i % M] += numbers[i] / 2;
        if(numbers[i] % 2 == 1)
            not_paired[i % M]++;
    }

    int res = 0;
    for(int i = 0; i * 2 <= M; ++i)
        if(i == 0 || i * 2 == M) {
            res += not_paired[i] / 2;
        } else {
            
            if(not_paired[i] > not_paired[M - i]) { 
                int carry = min(not_paired[i] - not_paired[M - i], 2 * pairs[M - i]);
                res += not_paired[M - i] + carry;
                pairs[M - i] = (2 * pairs[M - i] - carry) / 2;

            } else if(not_paired[i] < not_paired[M - i]) { 
                int carry = min(not_paired[M - i] - not_paired[i], 2 * pairs[i]);
                res += not_paired[i] + carry;
                pairs[i] = (2 * pairs[i] - carry) / 2;

            } else {
                res += not_paired[i];
            }
        }

    for(int i = 0; i < M; ++i)
        res += pairs[i];

    return res;
}

int main(int argc, char **argv) {
    cin >> N >> M;
    for(int i = 0; i < N; ++i)
        cin >> X[i];

    cout << solve() << endl;   
}

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll D, std::vector<ll> X, std::vector<ll> Y) {
  ll ans = 0;
  ll d2 = D * D;

  rep(i, N) {
    if (d2 >= X.at(i) * X.at(i) + Y.at(i) * Y.at(i)) {
      ans++;
    }
  }

  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  ll D;
  scanf("%lld", &D);
  std::vector<ll> X(N);
  std::vector<ll> Y(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
    scanf("%lld", &Y[i]);
  }
  solve(N, D, std::move(X), std::move(Y));
  return 0;
}


Measured memory_bytes: 6444
#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--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
ll mod= 1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[210000];
main(){
    ll n,k,ans=0;
    cin>>n>>k;
    ll s=0;
    rep(i,0,n)cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll st=k;
    rep(i,k,n)ans+=a[i];
    if(n<=k)cout<<0;
    else cout<<ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (long long i = 0; i < (n); ++i)
#define rep(i, a, b) for (long long i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

typedef long long ll;

int main(void)
{
    // priority_queue<int, vector<int>, greater<int>> pq[3];
    priority_queue<int> pq[3];
    int a, b, c;
    int x[2];
    cin >> x[0] >> x[1] >> a >> b >> c;
    int musyoku = 0;

    REP(i, a)
    {
        int t;
        cin >> t;
        pq[0].push(t);
    }
    REP(i, b)
    {
        int t;
        cin >> t;
        pq[1].push(t);
    }
    REP(i, c)
    {
        int t;
        cin >> t;
        pq[2].push(t);
    }
    long long ans = 0;
    while (x[0] > 0 or x[1] > 0)
    {
        int max = -1;
        int maxpos;
        if (x[0] + x[1] <= musyoku)
        {
            break;
        }
        REP(i, 3)
        {
            if (x[i] == 0)
                continue;
            if (pq[i].size() == 0)
                continue;
            if (max < pq[i].top())
            {
                max = pq[i].top();
                maxpos = i;
            }
        }
        if (maxpos == 0 or maxpos == 1)
        {
            x[maxpos]--;
        }
        else
        {
            musyoku++;
        }
        ans += max;
        pq[maxpos].pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1784
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

int n , l;
int tmp;
char s[1200];
int ans , a , b;
void work () {
	int i , j;
	scanf ( "%d" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%s" , s + 1 );
		l = strlen ( s + 1 );
		for ( j = 1 ; j < l ; j++ ) {
			if ( s[j] == 'A' && s[j+1] == 'B' ) {
				ans++;
			}
		}
		if ( s[1] == 'B' ) b++;
		if ( s[l] == 'A' ) a++;
		if ( s[1] == 'B' && s[l] != 'A' ) tmp = 1;
		if ( s[1] != 'B' && s[l] == 'A' ) tmp = 1;
	}
	if ( (a || b) && tmp == 0 ) ans--;
	ans += min ( a , b );
	printf ( "%d\n" , ans );
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, k) = [int(e) for e in lines[0].split(" ")]

    return (n, k)


def solve(n, k):

    tmp = math.log(n, k)
    if tmp.is_integer():
        result = math.ceil(tmp) + 1
    else:
        result = math.ceil(tmp)

    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

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

int gcd(int A,int B){
  if(B>A)swap(A,B);
  if(B==0)return A;
  return gcd(B,A%B);
}

int main(){
 	string s;
	cin >> s;
	int a0 = 0;
	int a1 = 0;
	for(int i=0;i<s.size();i++) {
		if(s[i] - '0' == i % 2) {
			a0++;
		}
		else {
			a1++;
		}
	}
	cout << min(a0, a1) << endl;
} 

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

int main()
{
  int h, w;
  cin >> h >> w;
  char grid[h][w];
  int m_distance[h][w];

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cin >> grid[y][x];
      m_distance[y][x] = 2000;
    }
  }

  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (grid[y][x] == '#') {
        m_distance[y][x] = 0;
        continue;
      }
      if (x == 0) continue;
      m_distance[y][x] = min(m_distance[y][x], m_distance[y][x - 1] + 1);
    }
    for (int x = w - 2; x >= 0; x--) {
      m_distance[y][x] = min(m_distance[y][x], m_distance[y][x + 1] + 1);
    }
  }

  for (int x = 0; x < w; x++) {
    for (int y = 1; y < h; y++) {
      m_distance[y][x] = min(m_distance[y][x], m_distance[y - 1][x] + 1);
    }
    for (int y = h - 2; y >= 0; y--) {
      m_distance[y][x] = min(m_distance[y][x], m_distance[y + 1][x] + 1);
    }
  }

  int ans(0);
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      ans = max(ans, m_distance[y][x]);
    }
  }
  cout << ans << endl;
}


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

fn solve() {
    input! {
        h: usize, w: usize, m: usize,
        hwv: [(Usize1, Usize1); m]
    };

    let mut sum_h = vec![0_i64; h];
    let mut sum_w = vec![0_i64; w];
    for &(i, j) in &hwv {
        sum_h[i] += 1;
        sum_w[j] += 1;
    }

    let max_h = *sum_h.iter().max().unwrap();
    let max_w = *sum_w.iter().max().unwrap();
    let max_hc = sum_h.iter().filter(|&s| s == &max_h).count();
    let max_wc = sum_w.iter().filter(|&s| s == &max_w).count();
    let sum = max_h + max_w;
    let on_bomb = hwv
        .into_iter()
        .filter(|&(h, w)| sum_h[h] + sum_w[w] == sum)
        .count()
        == max_hc * max_wc;
    let res = if on_bomb { sum - 1 } else { sum };
    println!("{}", res);
}

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


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N) {
  set<LL> data;
  LL ans = 0;
  for (LL i = 1; i * (i - 1) <= N; i++) {
    if (N % i == 0) {
      LL k = i;
      LL m = N / i - 1;
      if (k < m && data.find(m) == data.end()) {
        data.insert(m);
        ans += m;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef std::vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	string s;
	cin >> s;
	int ans = 0;
	FOR(i, s.length() - 1)if (s[i] != s[i + 1])ans++;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int minv;
int INF=1<<27;
int cost[10][10];

int dfs(int now,int ncost){
  if(now==1)
    return minv=min(minv,ncost);
  else if(minv<ncost)
    return minv;
  int rec=0;
  for(int i=0;i<10;i++){
    if(i!=now)
      rec=dfs(i,ncost+cost[now][i]);
  }
  return rec;
}
int main(){
  int min_cost[10];
  int h,w;
  int mp[200][200];
  int ans=0;
  
  cin >> h >> w;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin >> cost[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> mp[i][j];
    }
  }

  for(int i=0;i<10;i++){
    minv=INF;
    min_cost[i]=dfs(i,0);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(mp[i][j]!=1&&mp[i][j]!=-1)
        ans+=min_cost[mp[i][j]];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
 
int run_test(){
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n + 1], b[m + 1];
    a[0] = b[0] = 0;
    ll sum = 0;
    for(int i=1; i<=n; i++){
        ll t;
        cin >> t;
        sum += t;
        a[i] = sum;
    }    
    sum = 0;
    for(int i=1; i<=m; i++){
        ll t;
        cin >> t;
        sum += t;
        b[i] = sum;
    }
    int ans  = 0;
    for(int i=0; i<=n; i++){
        if(k - a[i] >= 0){
            int  j = lower_bound(b,b + m, k - a[i]) - b;
            if(j > m || b[j] > k - a[i]){
                j--;
            }
            ans = max(ans, i + j);
        }
    }
    cout << ans;
    return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 6792
import re
s = list(input())
match_MMYY = re.match(r'0[1-9]|1[0-2]', "".join(s[:2]))
match_YYMM = re.match(r'0[1-9]|1[0-2]', "".join(s[2:]))
if (match_YYMM and match_MMYY):
    answer = 'AMBIGUOUS'
elif(match_YYMM):
    answer = 'YYMM'
elif(match_MMYY):
    answer = 'MMYY'
else:
    answer = 'NA'

print(answer)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5+5;
const int mod = 1e9+7;

ll n, m, ans = 0;


int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	//#ifndef OJ
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//#endif

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> m;
		ans += m-1;
	}

	cout << ans;

	return 0;
}


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

int main() {
    int n;  cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    sort(a.begin(), a.end());
    ll sum=0;
    for(int i=0; i<n-1; i++)
        sum += a.at(i);
    if(sum>a.at(n-1))
        cout << "Yes" << endl;
    else    cout << "No" << endl;
}


Measured memory_bytes: 256