akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h, w;
	cin >> h >> w;
    vector<vector<int>> s(h,vector<int>(w));
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            char tmp; cin >> tmp;
            s[i][j]=(tmp=='.' ? 1 : 0);
        }
    }

    int ans=0;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(s[i][j]==0) continue;
            
            vector<vector<int>> v=s;
            v[i][j]=0;
            queue<pair<pair<int,int>,int>> q;
            q.push(make_pair(make_pair(i,j),0));
            while(!q.empty()){
                auto tmp=q.front();
                int x=tmp.first.first, y=tmp.first.second, z=tmp.second;
                q.pop();
                ans = max(ans,z);

                if(x>0 && v[x-1][y]==1){
                    q.push(make_pair(make_pair(x-1,y),z+1));
                    v[x-1][y]=0;
                }
                if(x<h-1 && v[x+1][y]==1){
                    q.push(make_pair(make_pair(x+1,y),z+1));
                    v[x+1][y]=0;
                }
                if(y>0 && v[x][y-1]==1){
                    q.push(make_pair(make_pair(x,y-1),z+1));
                    v[x][y-1]=0;
                }
                if(y<w-1 && v[x][y+1]==1){
                    q.push(make_pair(make_pair(x,y+1),z+1));
                    v[x][y+1]=0;
                }

            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
//
// Created by PIIMUU on 8/22/2020.
//
#include <bits/stdc++.h>
using namespace std;
int D[1010][1010];
using p = pair<int, pair<int, int>>;
int main() {
    int n, m;
    cin >> n >> m;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    sx--, sy--, ex--, ey--;
    string s[1010];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    priority_queue<p, vector<p>, greater<p>> q;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            D[i][j] = 2e9;
        }
    }
    q.push({0, {sx, sy}});
    D[sx][sy] = 0;
    while (q.empty() == false) {
        int x = q.top().second.first;
        int y = q.top().second.second;
        int d = q.top().first;
        //cout << x << " " << y << " " << d[x][y] << '\n';
        q.pop();
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                if (x + i >= 0 and x + i < n and y + j >= 0 and y + j < m
                    and d + (abs(i) + abs(j) >= 2) < D[x + i][y + j]
                    and s[x + i][y + j] == '.') {
                    D[x + i][y + j] = d + (abs(i) + abs(j) >= 2);
                    q.push({D[x + i][y + j], {x + i, y + j}});
                }
            }
        }
    }
    if (D[ex][ey] == 2e9) {
        cout << -1;
    } else
        cout << D[ex][ey];
}



Measured memory_bytes: 9556
import copy

class UNION:
    def __init__(self):
        return
    def find(self, x):
        if par[x] < 0:
            return x
        else:
            par[x] = self.find(par[x])
            return par[x]

    # 同一の集合の判定
    def same(self, x, y):
        if self.self.find(x) == self.find(y):
            return True
        else:
            return False
    # 集合の併合
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x

# 集合の数
def uCnt(self,x):
    return -par[self.find(x)]

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
cpar = [-1 for i in range(N)]
jiko = []
for i in range(M):
    par = copy.deepcopy(cpar)
    u = UNION()
    for j in range(M):
        if j == i:continue
        a = ab[j][0] - 1
        b = ab[j][1] - 1
        u.unite(a, b)
    tmp = min(par)
    if tmp == -N:
        jiko.append(i)

par = copy.deepcopy(cpar)
u = UNION()
for i in range(M):
    if jiko.count(i) == 0:
        a = ab[i][0] - 1
        b = ab[i][1] - 1
        u.unite(a, b)
ans = 0
for i in par:
    if i < -1:
        ans += abs(i) - 1

print(ans)

Measured memory_bytes: 3528
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
#include<math.h>
using namespace std;

int main(){
    
    int K, A, B;
    int d;
    bool f=false;
    cin >> K;
    cin >> A >> B;
    for(int i=1; i<1000; i++){
        d=i*K;
        //cout << i << " " << d << endl;
        if(A<=d && d<=B){
            f=true;
            break;
        }
    }
    
    if(f){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3652
open Batteries

let solve lst =
  let rec solve_loop (a, b) = function
    | [] -> a + b
    | first :: xs ->
        let (x, y) = first in
        let ratio = max ((a-1)/x+1) ((b-1)/y+1) in
        solve_loop (x*ratio,y*ratio) xs
  in
  solve_loop (1,1) lst

let () =
  IO.lines_of stdin
  |> Enum.skip 1
  |> Enum.map (fun l -> Scanf.sscanf l "%d %d" (fun x y -> (x, y)))
  |> List.of_enum
  |> solve
  |> Int.print stdout


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli data[50][26];
lli ans[26];

signed main(){

    lli n;
    cin>>n;

    REP(i,0,n){
        string s;
        cin>>s;
        REP(j,0,s.size()){
            data[i][s.at(j)-'a']++;
        }
    }

    REP(i,0,26){
        lli cnt=INF;
        REP(j,0,n){
            cnt=min(cnt,data[j][i]);
        }
        ans[i]=cnt;
    }

    REP(i,0,26){
        REP(j,0,ans[i])cout<<(char)(i+'a');
    }
    cout<<endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main()  {
	var input1 int
	var input2 int


	_, _ = fmt.Scan(&input1, &input2)

	ans := input1 * (input1 - 1 ) /2 + input2 * (input2 - 1) / 2

	fmt.Println(ans)
}


Measured memory_bytes: 512
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    currentH = 0
    add = 0
    for i, a in enumerate(A):
        if a >= currentH:
            currentH = a
        else:
            add += currentH - a
    print(add)

    return 0

if __name__ == "__main__":
    solve()

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


int main() {
string S;
cin >> S;
ll K;
cin >> K;
//先頭の文字から順に、出来るならaに変えていく
//先頭の文字がaにできない場合、その後ろの文字がaにできるかを調べ、出来るならaに
//ある文字がaに出来ない場合、何も操作せず、その後ろの文字を見る
//どれもaに出来ないなら、末尾の文字に操作するのが最適
//最後に残ったKの値の回数だけ末尾の文字に操作する
for(int i  = 0;i<S.size();i++){
    if(S[i] == 'a') continue;
    else if('z'-S[i]+1<=K){
        K -= 'z'-S[i]+1;
        S[i] = 'a';
    }

}
if('z'-S[S.size()-1]<K){//末尾の文字をa以降に出来る時
S[S.size()-1] = 'a'+(K-('z'-S[S.size()-1]+1))%26;
}
else S[S.size()-1] += K; 
cout << S << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
 
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll a ,b, c, k;
        cin >>a >>b >> c >> k;
        bool flag = false;
        for(i = 0; i <= k; i++){
            for(j = 0; j <= k; j++){
                if(i + j > k){
                    break;
                }
                for(ll it = 0; it <= k; it++){
                    if(it + i + j > k){
                        break;
                    }
                    ll x, y, z;
                    x = (1 << i) * a;
                    y = (1 << j) * b;
                    z = (1 << it) * c;
                    if(z > y && y > x){
                        flag = true;
                        cout << "Yes";
                        return 0;
                    }
                }
            }
        }
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using i64 = long long;

int dp[300][301][301];

int main() {
    std::string s;
    int k;
    std::cin >> s >> k;

    for (int l = 0; l < s.size(); l++) for (int i = 0; i <= k; i++) {
        dp[l][l + 1][i] = 1;
    }
    for (int w = 2; w <= s.size(); w++) {
        for (int i = 0; i + w <= s.size(); i++) {
            int j = i + w - 1;
            for (int c = 0; c <= k; c++) dp[i][j + 1][c] = std::max(dp[i][j][c], dp[i + 1][j + 1][c]);
            if (s[i] == s[j]) for (int c = 0; c <= k; c++) dp[i][j + 1][c] = std::max(dp[i][j + 1][c], dp[i + 1][j][c] + 2);
            else for (int c = 0; c < k; c++) dp[i][j + 1][c + 1] = std::max(dp[i][j + 1][c + 1], dp[i + 1][j][c] + 2);
        }
    }

    int ret = 0;
    for (auto &v : dp) for (auto &w : v) for (auto e : w) ret = std::max(e, ret);
    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 104832
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int node[200005][2];
int used;
long l;

void add(const string &s, int index, int id){
  if(s.size() == index) return;
  int si = s[index] - '0';
  if(node[id][si] == -1){
    node[id][si] = used++;
  }
  add(s, ++index, node[id][si]);
}

long nim = 0;
void validate(int id, int dep){
  if(id==-1) return;
  if( (node[id][0]==-1) ^ (node[id][1]==-1) ){
    nim = nim^(1LL<<__builtin_ctzll(l-dep));
  }
  validate(node[id][0], dep+1);
  validate(node[id][1], dep+1);
}

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

  fill(node[0], node[200005], -1);
  used = 1;

  rep(i,n){
    string s;
    cin>>s;
    add(s,0,0);
  }

  validate(0,0);

  if(nim!=0) cout << "Alice" << endl;
  else cout << "Bob" << endl;

  return 0;
}


Measured memory_bytes: 4252
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]


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


def main():
    N = INT()
    A = LIST()
    A.sort(reverse=True)

    if N % 2 == 0:
        confort = 2*sum(A[:N//2])-A[0]
    else:
        confort = 2*sum(A[:N//2])+A[N//2]-A[0]
    print(confort)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 32084
import sys

def getpar(Edge, p):
    N = len(Edge)
    par = [0]*N
    par[0] = -1
    par[p]  -1
    stack = [p]
    visited = set([p])
    while stack:
        vn = stack.pop()
        for vf in Edge[vn]:
            if vf in visited:
                continue
            visited.add(vf)
            par[vf] = vn
            stack.append(vf)
    return par

def topological_sort_tree(E, r):
    Q = [r]
    L = []
    visited = set([r])
    while Q:
        vn = Q.pop()
        L.append(vn)
        for vf in E[vn]:
            if vf not in visited:
                visited.add(vf)
                Q.append(vf)
    return L

def getcld(p):
    res = [[] for _ in range(len(p))]
    for i, v in enumerate(p[1:], 1):
        res[v].append(i)
    return res

mod = 10**9+7
frac = [1]*114514
for i in range(2,114514):
    frac[i] = i * frac[i-1]%mod
fraci = [None]*114514
fraci[-1] = pow(frac[-1], mod -2, mod)
for i in range(-2, -114514-1, -1):
    fraci[i] = fraci[i+1] * (114514 + i + 1) % mod
def perm(a, b):
    if not a >= b >= 0:
        return 0
    return frac[a]*fraci[a-b]%mod

N, K = map(int, input().split())
Dim = [0]*N
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1
    b -= 1
    Edge[a].append(b)
    Edge[b].append(a)
    Dim[a] += 1
    Dim[b] += 1

P = getpar(Edge, 0)
L = topological_sort_tree(Edge, 0)
C = getcld(P)

dp = [0]*N
dp[0] = K
decided = [0]*N
for i in range(1, N):
    l = L[i]
    p = P[l]
    lcp = len(C[p])
    dp[l] = (K - lcp + decided[p] - (p != 0)) 
    decided[p] += 1
ans = 1
for d in dp:
    ans = ans * d % mod
print(ans)

Measured memory_bytes: 88992
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i += 2) {
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <climits>
#include <set>
#include <queue>
#include <unordered_set>
using namespace std;

#define ll long long

class Solver
{
public:
	int n;
	vector<string> strs;
	vector<map<char, int> > hash_array;
	Solver();

	void exec();
};

Solver::Solver(){
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string tmp;
		cin >> tmp;
		strs.push_back(tmp);
		map<char, int> tmp_hash;
		for (int j = 0; j < tmp.length(); ++j)
		{
			tmp_hash[tmp[j]]++;
		}
		hash_array.push_back(tmp_hash);
	}
}

void Solver::exec(){
	vector<int> char_nums = vector<int>(26, 100);
	for (char c = 'a'; c <= 'z'; ++c)
	{
		for (int i = 0; i < n; ++i)
		{
			char_nums[c-'a'] = min(hash_array[i][c], char_nums[c-'a']);
		}
	}
	string ans = "";
	for (char c = 'a'; c <= 'z'; ++c)
	{
		for (int i = 0; i < char_nums[c-'a']; ++i)
		{
			ans += c;
		}
	}
	cout << ans << endl;
}

int main(){
	Solver solution = Solver();
	solution.exec();
}


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

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

  if (X == 3 || X == 5 || X == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    int D; cin >> D;
    vector<int> c(27); for (int i = 1; i <= 26; ++i) cin >> c[i];
    vector<vector<int>> s(D + 1);
    for (int i = 1; i <= D; ++i) {
        vector<int> v(27);
        for (int j = 1; j <= 26; ++j) cin >> v[j];
        s[i] = v;
    }

    // output
    vector<int> last(27, 0);
    ll satisfy = 0;
    for (int i = 1; i <= D; ++i) {
        ll best_contest = 0;
        ll best_score = -999999999;
        vector<int> c_last = last;
        for (int j = 1; j <= 26; ++j) {
            ll tmp_satisfy = satisfy;
            int con = j;
            // add satisfy
            tmp_satisfy += s[i][j];
            // update last
            c_last[con] = i;
            // sub satisfy
            for (int j = 1; j <= 26; ++j) {
                tmp_satisfy -= c[j] * (i - c_last[j]);
            }
            if (tmp_satisfy > best_score) {
                best_contest = j;
                best_score = tmp_satisfy;
            }
        }
        // actual update
        int con = best_contest;
        last[con] = i;
        cout << con << endl;
    }
}

Measured memory_bytes: 3688
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll X, A, B;
    cin >> X >> A >> B;

    if(B <= A){
        p("delicious");
    }else{
        ll over = B - A;
        if(over <= X){
            p("safe");
        }else{
            p("dangerous");
        }
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np
N=int(input())
happines=[]
dp=[[0,0,0,0,0,0] for i in range(N+1)]
for i in range(N):
    happy=list(map(int,input().split()))
    happines.append(happy)
def dp_search():
    zenkai=-1
    for i in range(N):
        if i<=N-1:
            dp[i + 1][0] = max(dp[i][2],dp[i][3])+happines[i][0]
            dp[i + 1][1] = max(dp[i][4],dp[i][5])+happines[i][0]
            dp[i + 1][2] = max(dp[i][0],dp[i][1])+happines[i][1]
            dp[i + 1][3] = max(dp[i][4],dp[i][5])+happines[i][1]
            dp[i + 1][4] = max(dp[i][0],dp[i][1])+happines[i][2]
            dp[i + 1][5] = max(dp[i][2],dp[i][3])+happines[i][2]
    print(max(dp[-1]))
dp_search()

Measured memory_bytes: 71996
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int dp[1000][10001] = {};

int main()
{
    int h, n;
    cin >> h >> n;
    vector<pair<int, int>> magic(n);
    for (auto &&i : magic)
    {
        cin >> i.first >> i.second;
    }
    for (int i = 0; i < n; i++)
    {
        dp[i][0] = 0;
        for (int j = 1; j <= h; j++)
        {
            if (j <= magic[i].first)
            {
                if (i)
                {
                    dp[i][j] = min(dp[i - 1][j], magic[i].second);
                }
                else
                {
                    dp[i][j] = magic[i].second;
                }
            }
            else if (i)
            {
                dp[i][j] = min(dp[i - 1][j], dp[i][j - magic[i].first] + magic[i].second);
            }
            else
            {
                dp[i][j] = dp[i][j - magic[i].first] + magic[i].second;
            }
        }
    }
    cout << dp[n - 1][h] << "\n";
}

Measured memory_bytes: 39296
#include <bits/stdc++.h>
#define int long long

using namespace std;

int a[1000][1000];
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, h, w;
    cin >> h >> w >> n;
    int x = 0, y = 0;
    for (int i = 0; i < n; i++)
    {
        int now;
        cin >> now;
        while (now--)
        {
            a[x][y] = i + 1;
            if ((y == w - 1 && x % 2 == 0) || (x % 2 && y == 0))
            {
                x++;
            }
            else
            {
                if (x % 2) y--;
                else y++;
            }
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 768
program answer
  implicit none
  integer :: N, i, ans
  integer, allocatable :: B(:)
  read(*,*) N
  allocate(B(N-1))
  read(*,*) B
  ans=0
  do i = 1, N
     if(i==1) then
        ans=ans+B(i)
     else if(i==N) then
        ans=ans+B(i-1)
     else
        ans=ans+min(B(i-1),B(i))
     end if
  end do
  write(*,*) ans
  stop
 end program answer


Measured memory_bytes: 2796
from operator import itemgetter
N, K = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0))
cnt = 0
i = 0
while cnt < K:
    cnt += AB[i][1]
    i += 1
print(AB[i-1][0])


Measured memory_bytes: 29096
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf: VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf: VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn nextN<T>(&mut self, n: usize) -> Vec<T> where T: FromStr, T::Err: Debug {
            let mut vec: Vec<T> = Vec::with_capacity(n);
            for i in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

mod data {
    pub struct UnionFind {
        root : Vec<usize>
    }

    impl UnionFind {
        pub fn new(size : usize) -> UnionFind {
            UnionFind {root : (0..size).collect()}
        }

        pub fn find(&mut self, x : usize) -> usize {
            let xroot = self.root[x];
            if x != xroot {
                self.root[x] = self.find(xroot);
            }
            self.root[x]
        }

        pub fn unite(&mut self, x : usize, y : usize) {
            let xroot = self.find(x);
            self.root[xroot] = self.find(y);
        }

        pub fn same(&mut self, x : usize, y : usize) -> bool {
            self.find(x) == self.find(y)
        }
    }
}

fn with_large_stack(func : fn() -> ()) {
    use std::thread::Builder;
    let builder = Builder::new();
    let th = builder.stack_size(10000000);

    th.spawn(move || {
        func();
    }).unwrap().join();
}

fn main() {
    with_large_stack(_main);
}

fn f(h: &Vec<i64>, b:i64, x:i64, cnt: i64) -> bool {
    let mut c: i64 = 0;
    for a in h {
        let r = a - b * cnt;
        if (r > 0) {
            c += (r + x - 1) / x;
        }
    }
    c <= cnt
}

fn _main() {
    let mut reader = reader::Reader::new();

    let n: usize = reader.next();
    let a: i64 = reader.next();
    let b: i64 = reader.next();
    let x: i64 = a - b;

    let h: Vec<i64> = reader.nextN(n);

    let mut lb: i64 = 0;
    let mut ub: i64 = 1000000000;
    while ub - lb > 1 {
        let mid = (ub + lb) / 2;
        if f(&h, b, x, mid) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    println!("{}", ub);
}
 

Measured memory_bytes: 15864
n = int(input())
ans = []
for i in range(1,n+1):
    if i % 3 == 0 and i % 5 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        ans.append(i)
print(sum(ans))

Measured memory_bytes: 29852
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(), x.end()

const int N = 1.1e5;
const int M = 998244353;
int n, a[N];

signed main() {
#ifdef DEBUG
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int answer = a[0] == 0;
	sort(a, a + n);
	for (int i = 1; i < n; ++i) {
		answer *= upper_bound(a, a + n, a[i] - 1) - lower_bound(a, a + n, a[i] - 1);
		answer %= M;
	}
	
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;

int main()
{
    fio;
    ll t, a, n, q, k, i, l, m, c, u, f, j, p, x, y, b, d;
   
cin>>n;
vector<int>v(n,0),V(n,0);
for(auto& h : v)
cin>>h;
V[n-1]=0;
for(i=n-2;i>=0;i--)
V[i]=(v[i+1]+V[i+1])%MOD;

// for (auto &h : V)
//     cout<<h<<" ";
//     cout<<endl;

for(i=0;i<n;i++)
V[i]=((v[i]%MOD)*(V[i]%MOD))%MOD;
c=0;
for (i = 0; i < n; i++)
    c = (c + V[i] % MOD) % MOD;
cout<<c<<endl;
    return 0;
}


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

int main(){
    ll H, W;
    cin >> H >> W;
    ll s1 = ((H + 2) / 3) * W - (H / 3) * W;
    ll s2 = ((W + 2) / 3) * H - (W / 3) * H;
    ll s3 = 1e18, s4 = 1e18;
    rep(h, 0, H+1){
        ll c1 = (H - h) * W;
        ll c2 = h * (W / 2);
        ll c3 = h * ((W + 1) / 2);
        ll mx = max({c1, c2, c3});
        ll mn = min({c1, c2, c3});
        s3 = min(s3, mx - mn);
    }
    rep(w, 0, W+1){
        ll c1 = (W - w) * H;
        ll c2 = w * (H / 2);
        ll c3 = w * ((H + 1) / 2);
        ll mx = max({c1, c2, c3});
        ll mn = min({c1, c2, c3});
        s4 = min(s4, mx - mn);
    }
    cout << min({s1, s2, s3, s4}) << endl;
    return 0;
}

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

string A;
int Path[26][200010];
int From[200010];
string ans;

void dp(){
    A = "#" + A;
    int L = A.size();
    for(int i = 0; i < 26; i++){
        Path[i][L-1] = 200005;
        for(int j = L-1; j > 0; j--){
            if(A[j] - 'a' == i)Path[i][j-1] = j;
            else Path[i][j-1] = Path[i][j];
        }
    }
}

void bfs(){
    for(int i = 0; i < 200010; i++)From[i] = -1;
    queue<int>Q;
    Q.push(0);
    while(true){
        int pos = Q.front();
        Q.pop();
        if(pos == 200005)break;
        for(int i = 0; i < 26; i++){
            if(From[Path[i][pos]] != -1)continue;
            From[Path[i][pos]] = pos;
            Q.push(Path[i][pos]);
        }
    }
}

void backtrack(){
    ans = "";
    for(int pos = 200005; pos; pos = From[pos]){
        for(int i = 0; i < 26; i++){
            if(Path[i][From[pos]] == pos){
                ans += string(1, 'a'+i);
                break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
}

int main(){
    cin >> A;
    dp();
    bfs();
    backtrack();
    cout<<ans<<endl;
    return 0;
}

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

int main(void){
  int N,m=0;
  cin >> N;
  int a[N];
  int b[N][N]={};
  
  
  for(int i=0;i<N;i++)
    a[i]=i;
  
  if(N%2==1){
    
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(i+j+2!=N&&i<j){
          b[i][j]=1;
          m++;
        }
      }      
    }
  }else if(N%2==0){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(i+j+2!=N+1&&i<j){
          b[i][j]=1;
          m++;
        }
      }      
    }
  }
  
  cout << m << endl;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(b[i][j]==1&&i!=j){
        cout << i+1 << " " << j+1 << endl;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    H1, M1, H2, M2, K = [int(i) for i in input().strip().split()]
    return (H2*60 + M2) - (H1*60 + M1) - K


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9160
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=RD()
	k=II()

	dp=[[[0]*2 for _ in range(k+2)] for _ in range(len(n)+1)]
	#print(dp)

	dp[0][0][0]=1

	for i in range(len(n)):
		now=int(n[i])
		for j in range(k+1):
			#print(i,j,now)
			dp[i+1][j+(now!=0)][0]+=dp[i][j][0]
			dp[i+1][j][1]+=dp[i][j][1]+dp[i][j][0]*(now!=0)
			dp[i+1][j+1][1]+=dp[i][j][1]*9+dp[i][j][0]*(now-1 if now>0 else 0)
		#print(dp)
	print(dp[len(n)][k][0]+dp[len(n)][k][1])

















if __name__ == "__main__":
	main()


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int solve(int n) {
  int cnt = 0;
  while (true) {
    if (n % 2 == 0) {
      n /= 2;
      cnt++;
    } else {
      break;
    }
  }
  return cnt;
}

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

  int m = 0, res = 1;
  rep(i, N) {
    int cnt = solve(i + 1);
    if (cnt > m) {
      m = cnt;
      res = i + 1;
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}




int main(){
    int N, M; std::cin >> N >> M;
    std::vector<int> a(M), b(M);
    if(M % 2){
        for(int i(0); i < M / 2; ++i){
            a[i] = i + 1;
            b[i] = M-i;
        }
        for(int i(M / 2); i < M; ++i){
            int j(i - M/2);
            a[i] = j + 1 + M;
            b[i] = 2*M+1 - j;
        }
    }else{
        for(int i(0); i < M / 2; ++i){
            a[i] = i + 1;
            b[i] = M-i + 1;
        }
        for(int i(0); i < M / 2; ++i){
            a[i+M/2] = M + i + 2;
            b[i+M/2] = 2*M+1 - i;
        }
    }

    for(int i(0); i < M; ++i){
        std::cout << a[i] << " " << b[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 4052
#include<stdio.h>

int main(void)
{

    int W,H,x,y,r;
    
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    
    
    if(W<x+r || 0>x-r || H<y+r || 0>y-r)printf("No\n");
    else printf("Yes\n");
    

    return 0;
}


Measured memory_bytes: 2100
<?php
list($n,$x)=explode(" ",trim(fgets(STDIN)));
$a=explode(" ",trim(fgets(STDIN)));
if($x==(int)array_sum($a)){
  echo $n;
}elseif($x>(int)array_sum($a)){
  echo $n-1;
}else{
  sort($a);
  $ans=0;
  $i=0;
  while($i<$n){
    if($x>=$a[$i]){
      ++$ans;
      $x-=$a[$i];
    }else{
      echo $ans;
      exit;
    }
    ++$i;
  }
}

Measured memory_bytes: 4728
#include<stdio.h>

int main()
{
  int r,i,j,x,p=1,c;

  scanf("%d",&r);

  int A[r+1];

  for(i=1;i<=r;i++)
    {
      scanf("%d",&A[i]);
    }

  x=A[r];

  i=p-1;

  for(j=p;j<r;j++)
    {
      
      if(A[j]<=x)
	{
	  i=i+1;
	  c=A[i];
	  A[i]=A[j];
	  A[j]=c;
	}
    }

  c=A[i+1];
  A[i+1]=A[r];
  A[r]=c;

   for(j=1;j<=r;j++)
    {
      if(j==i+1)
	{
	  if(j==1) printf("[%d]",A[j]);
	  else printf(" [%d]",A[j]);
	}
      else
      {
	if(j==1) printf("%d",A[j]);
	  else printf(" %d",A[j]);
      }
      }

   printf("\n");

  return 0;
}



Measured memory_bytes: 2248
inf = float('inf')

N, M = map(int,input().split())
edges = []
for _ in range(M):
    a, b, c = map(int,input().split())
    a -= 1; b-= 1
    edges.append((a, b, -c))

dist = [inf] * N
dist[0] = 0
for _ in range(N-1):
    for v, nv, w in edges:
        if dist[nv] > dist[v] + w:
            dist[nv] = dist[v] + w

is_update = [False] * N
for _ in range(N):
    for v, nv, w in edges:
        if dist[nv] > dist[v] + w:
            dist[nv] = dist[v] + w
            is_update[nv] = True
        if is_update[v] is True:
            is_update[nv] = True

if is_update[N-1] is True:
    ans = "inf"
else:
    ans = -dist[N-1]

print(ans)

Measured memory_bytes: 3364
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, A, B = list(map(int, sys.stdin.buffer.readline().split()))

a = N // (B + A)
b = N % (B + A)
ans = a * A
ans += min(A, b)
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
#define N 200010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,d[N][2];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)d[i][0]=read(),d[i][1]=read();
	for(int i=1;i<=n-2;i++)
	{
		if(d[i][0]==d[i][1] && d[i+1][0]==d[i+1][1] && d[i+2][0]==d[i+2][1])printf("Yes"),exit(0);
	}
	printf("No\n");
	return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    int n, k;
    cin >> n >> k;
    using P = pair<i64, i64>;
    vector<P> td(n);
    for (int i = 0; i < n; ++i) {
        i64 t, d;
        cin >> t >> d;
        td[i] = {t, d};
    }
    sort(begin(td), end(td), [](P p, P q) { return p.second < q.second; });
    vector<bool> ct(n + 1);
    i64 del = 0;
    i64 kin = 0;
    priority_queue<i64, vector<i64>, greater<i64>> que;
    for (int i = 0; i < k; ++i) {
        i64 t, d;
        tie(t, d) = td.back();
        td.pop_back();
        del += d;
        if (!ct[t]) {
            ct[t] = true;
            kin++;
        } else {
            que.push(d);
        }
    }
    i64 ans = del + kin * kin;
    while (!td.empty() && !que.empty()) {
        i64 t, d;
        tie(t, d) = td.back();
        td.pop_back();
        if (!ct[t]) {
            ct[t] = true;
            kin++;
            del -= que.top();
            que.pop();
            del += d;
            ans = max(ans, del + kin * kin);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::unordered_set;
using std::map;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int n; cin >> n;

  pair<int, int> res{0, 0};
  for(int a = 0; a < 100; ++a)
    for(int b = 0; b < 100; ++b)
      if(a*4 + b*7 == n) res = {a, b};

  cout << (res.first || res.second ? "Yes" : "No") << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   string s;
   cin >> s;
   vector<int> w;
   bool we = 0;
   for (int i = 0; i < (int)(s.length()); i++) {
      if (s[i] == 'W') {
         w.emplace_back(i);
         we = 1;
      }
   }
   if (we == 0) {
      cout << 0 << '\n';
      return 0;
   }
   long long ans = w[0];
   for (int i = 1; i < (int) w.size(); i++) {
      ans += w[i] - i;
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 1552
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

bool check_encode(string str, char c, string sn) {
	string ss = "";
	for (int i = 0; i < str.length(); ++i) {
		if (str[i] == c) {
			ss += "ABC";
		}
		else {
			ss += str[i];
		}
	}
	cout << str << " " << ss << " " << sn << endl;
	if (ss == sn) {
		return false;
	}
	else {
		return true;
	}
}

int main(void) {
	string str;
	cin >> str;

	string sn = str;
	queue<string> gene;
	gene.push(str);
	bool find = false;

	while (sn.length() > 2 && !gene.empty()) {
		sn = gene.front();
		gene.pop();

		if (sn == "ABC") {
			find = true;
			break;
		}

		vector<bool> seq(sn.length(),false);
		bool cs = false;
		//ABCテ・ツ按、テ・ツョツ?
		for (int i = 0; i < sn.length()-2; ++i) {
			if (sn[i] == 'A' && sn[i+1] == 'B' && sn[i+2] == 'C') {
				seq[i] = true;
				cs = true;
			}
		}

		bool fa,fb,fc;
		fa = fb = fc = false;
		//テヲツ鳴?・ツュツ療・ツ按療、ツスツ愿ヲツ按?
		if (cs) {
			string astr,bstr,cstr;
			astr = bstr = cstr = "";
			for (int i = 0; i < sn.length(); ++i) {
				if (seq[i]) {
					astr += "A";
					bstr += "B";
					cstr += "C";
					i += 2;
				}
				else {
					astr += sn[i];
					bstr += sn[i];
					cstr += sn[i];
					if (sn[i] == 'A') {
						fa = true;
					}
					else if (sn[i] == 'B') {
						fb = true;
					}
					else if (sn[i] == 'C') {
						fc = true;
					}
				}
			}

			if (!fa) {
				gene.push(astr);
			}
			if (!fb) {
				gene.push(bstr);
			}
			if (!fc) {
				gene.push(cstr);
			}
			//cout << astr << " " << bstr << " " << cstr << endl;
		}
	}

	if (find) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin>>a>>b>>c;

if(a > b) swap(a, b);
if(b > c) swap(b, c);
if(a > b) swap(a, b);

cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}


Measured memory_bytes: 3056
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)));
#define Mx(a , b) ((a) > (b) ? (a) : (b))
#define Mn(a , b) ((a) < (b) ? (a) : (b))

const double EPS = 1e-10;
const int INF = 2147483647;

int H , W , N;
int x , y;
map<P2 , int> m;
LL ans[10];

int main(){
	scanf("%d%d%d" , &H , &W , &N);
	for(int i = 0 ; i < N ; ++i){
		scanf("%d%d" , &x , &y);
		for(int j = -1 ; j < 2 ; ++j){
			for(int k = -1 ; k < 2 ; ++k){
				if(x + j < 2 || x + j >= H || y + k < 2 || y + k >= W) continue;
				m[MP(x + j , y + k)]++;
			}
		}
	}
	ans[0] = (LL)(H - 2) * (W - 2) - m.size();
	for(map<P2 , int>::iterator it = m.begin() ; it != m.end() ; ++it){
		++ans[(*it).second];
	}
	for(int i = 0 ; i < 10 ; ++i) printf("%lld\n" , ans[i]);
	return 0;
}


Measured memory_bytes: 56448
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAX 2000200
#define MIN -2000000300
#define INF 1<<30
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];

void Init(int n){
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      A[i][j] = INF;
    }
  }
}

int prime(){
  for(int i=0;i<n;i++){
    d[i] = INF;
    used[i]=false;
  }
  int ans=0;
  d[0] = 0;

  while(true){
    int v = -1;
    for(int i=0;i<n;i++){
      if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
    }
    if(v == -1)break;
    ans+=d[v];
    used[v] = true;   

    for(int i=0;i<n;i++){
      d[i] = min(d[i],A[v][i]);
    }

  }
  return ans;
}

int main(){
  scanf("%d",&n);
  //  Init(n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      scanf("%d",&A[i][j]);
      if(A[i][j] == -1)A[i][j] = INF;
    }
  }
 
  printf("%d\n",prime());
 

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

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

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int[][] color = new int[H][W];
    int N = scanner.nextInt();
    int i = 0;
    for (int c = 1; c <= N; c++) {
      int a = scanner.nextInt();
      for (int j = 0; j < a; j++) {
        int y = i / W;
        int r = i % W;
        int x = y % 2 == 0 ? r : W - r - 1;
        color[y][x] = c;
        i++;
      }
    }

    StringBuilder sb = new StringBuilder();
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) {
        sb.append(color[y][x]);
        if (x < W - 1) sb.append(' ');
      }
      sb.append('\n');
    }
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 29864
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {

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

    int a, b, c; cin >> a >> b >> c;
    
    cout << max(0, c - (a - b)) << endl;

    return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
ans = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if i != j:
            uf.union(a[j][0]-1, a[j][1]-1)
    if uf.size(0) != n:
        ans += 1
print(ans)

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


int main() {
  int K;
  cin >> K;
  queue<ll> q;
  ll count = 0;
  ll tmp;
  rep(i, 9) q.push(i + 1);
  while (count < K) {
    tmp = q.front();
    q.pop();
    if (tmp % 10 != 0) q.push(10 * tmp + tmp % 10 - 1);
    q.push(10 * tmp + tmp % 10);
    if (tmp % 10 != 9) q.push(10 * tmp + tmp % 10 + 1);
    count++;
  }
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 1792
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, *P = map(int, read().split())
min = P[0] 
ans = 1
for i in range(1,N):
    if P[i] > min:
        continue
    else:
        ans += 1
        min = P[i]
print(ans)

Measured memory_bytes: 27848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		String string = sc.nextLine();
		String[] strings = string.split(" ");

		System.out.println(strings[0].substring(0, 1) + strings[1].substring(0, 1) + strings[2].substring(0, 1));
	}

}


Measured memory_bytes: 39312
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  ll W;
  cin >> W;

  vector<ll> w(N);
  vector<ll> v(N);
  for(int i = 0;i < N;i++)cin >> w[i] >> v[i];

  vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));

  for(int i = 1;i <= N;i++){
    for(int j = 0;j <= W;j++){
      if(j < w[i-1])dp[i][j] = dp[i-1][j];
      else dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i-1]] + v[i-1]);
    }
  }

  cout << dp[N][W] << endl;
}


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

int main() {
    ll a[4];rep(i,4)cin>>a[i];
    ll ans = a[0]*a[2];
    ans = max(ans,a[1]*a[3]);
    ans = max(ans,a[0]*a[3]);    
    ans = max(ans,a[1]*a[2]);    
    cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
ll pts[1000000][6]={0};

ll mnht(ll pt[1000000][6], int kth, int idx, int d)
{
    ll dist=0;

    for(int i=0;i<d;i++)
    {
        dist+=abs(pt[kth][i]-pt[idx][i]);
    }

    return dist;
}
   /*
   10
   -70 -64 -6 -56 64 61 -57 16 48 -98
   */
ll max_cmb(ll cmbn[6], ll pt[1000000][6], int n, int d)
{
    ll pk=0;ll idx=0;

   for(int i=0;i<n;i++)
   {
       ll val=0;

       for(int j=0;j<d;j++)
       {
           val+=(1-2*cmbn[j])*pt[i][j];
       }

       if(val>pk)
       {
           pk=val;
           idx=i;
       }
   }

   return idx;
}

int main()
{
   int n, d = 2;
   cin>>n;

   for(int i=0;i<n;i++)
   {
       for(int j=0;j<d;j++)
        cin>>pts[i][j];
   }

   ll pk[2<<d];

   for(int j=0;j< 1<<(d);j++)
   {
       ll cmbn[6]={0};
       for(int dig=0;dig< d; dig++)
       {
           if(j & 1<<dig)
             cmbn[dig]=1;
          // cout<<cmbn[dig]<<" ";
       }
//cout<<endl;
       pk[j]=max_cmb(cmbn, pts, n, d);
   }

   ll maxd=0;
   for(int i=0;i<n;i++)
   {
       for(int j=0;j< 1<<(d);j++)
       maxd=max(maxd, mnht(pts, i, pk[j], d));
   }

   cout<<maxd<<endl;
   return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int64_t> vec(N + 1);
    vec.at(0) = 2;
    vec.at(1) = 1;
    for (int i = 2; i <= N; i++)
    {
        vec.at(i) = vec.at(i - 1) + vec.at(i - 2);
    }
    cout << vec.at(N) << endl;
}


Measured memory_bytes: 256