akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(10) << num << endl;
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    string s; cin >> s;
    int res=0;
    int sai=0;
    rep(i,n){
        if(s[i]=='(') res++;
        else if(res==0) sai++;
        else res--;
    }
    rep(i,sai)cout<<'(';
    cout<<s;
    rep(i,res)cout<<')';
  cout << endl;
}



Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {
	
	char a, b;

	cin >> a >> b;

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

	return 0;
}


Measured memory_bytes: 256
import sys
import math
     
     
def main():
    """
    2 <= K <= N <= 10^5
    1 <= ai <= N
    1 <= i <= N
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())
 
    #ans = f_K(N, K, A)
    ans = editorial(N, K, A)
    print(ans)
     
     
def test_examples():
    nka_ans = [
        (4, 3, [2, 3, 1, 4], 2),
        (3, 3, [1, 2, 3], 1),
        (8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
    ]
 
    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans
     
     
def test_ans():
    nka_ans = [
        (5, 2, [1, 2, 3, 4, 5], 4),
        (5, 3, [1, 2, 3, 4, 5], 2),
        (5, 2, [5, 4, 3, 2, 1], 4),
        (5, 3, [5, 4, 3, 2, 1], 2),
    ]
     
    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans
     
     
def f_K(N, K, A):
    """
    最初に置く範囲は、 1_idx - K + 1 から 1_idx
    """
    idx = [i for i, a in enumerate(A) if a == 1][0]
    left_idx = max(0, idx - K)
    ans = float("inf")
    for i in range(left_idx, idx + 1):
        left = i
        right = max(0, N - left - K)
        tmp = (left + (K - 1) - 1) // (K - 1)
        tmp += 1
        tmp += (right + (K - 1) - 1) // (K - 1)
        ans = min(ans, tmp)
     
    return ans
     
     
def editorial(N, K, A):
    """
    端から端までカバーしていく
    K + (K - 1) * N (N >= 0)
    これは仮に１番左に1があったとき
    結果的には順番は気にしなくて良い
    上記でカバーしていくと、いつかは最初の1をカバーする
        カバーした順番を1をカバーしたことを最初に行えば変わらない
     
    TODO: editorial pdfの意味
        1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g
    """
    return ((N-1) + (K-1) - 1) // (K-1)
     
     
     
if __name__ == '__main__':
    main()

Measured memory_bytes: 13940
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
using namespace std;
typedef long long ll;

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

  sort(a, a+n, greater<int>());
  int ali=0;
  int bob=0;
  for(int i=0; i<n; i++){
    if(i%2==0) ali+= a[i];
    else bob+=a[i];
  }
  cout << ali - bob << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0

for a_i in range(min(k, len(v))+1):
    for b_i in range(min(k, len(v))-a_i+1):
        juwel = v[:a_i:] + v[len(v)-b_i::]
        juwel.sort()
        c = min(k - a_i - b_i, len(juwel))
        for i in range(c):
            if juwel[0] < 0:
                del juwel[0]
            else:
                break
        ans = max(ans, sum(juwel))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> ap(0),am(0),aall(N);
    rep(j,N){
        int num;
        cin >> num;
        aall[j] = num;
        if (num < 0) am.push_back(num);
        else ap.push_back(num);
    }
    int p = ap.size();
    int m = am.size();
    int nowp,nowm;
    nowp = nowm = 0;
    sort(all(am));
    sort(all(ap));
    reverse(all(ap));
    ll ans = 1;

    int l = 0;
    if(K==N){
        rep(j,N){
            ans *= aall[j];
            ans %= MOD;
        }
        if (ans < 0){
            ans = MOD + ans;
        }
        cout << ans << endl;
        return 0;
    }
    if(p == 0 && K%2 == 1){
        reverse(all(am));
        rep(j,K){
            ans *= am[j]*-1;
            ans %= MOD;
        }
        cout << MOD - ans << endl;
        return 0;
    }

    while(l < K){
        if(l == K - 1){
            ans *= ap[nowp];
            ans %= MOD;
            break;
        }
        if(p-nowp < 2){
            ans *= am[nowm] * am[nowm + 1] % MOD;
            ans %= MOD;
            l += 2;
            nowm += 2;
            continue;
        }else if(m - nowm < 2){
            ans *= ap[nowp];
            ans %= MOD;
            l++;
            nowp++;
            continue;
        }

        //通常時
        if(ap[nowp] * ap[nowp + 1] > am[nowm] * am[nowm + 1]){
            ans *= ap[nowp];
            ans %= MOD;
            l++;
            nowp++;
        }else{
            ans *= am[nowm] * am[nowm + 1] % MOD;
            ans %= MOD;
            l += 2;
            nowm += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6924
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<int> g[100005];
int main() {
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int u,v;
    cin >> u >> v;
    --u; --v;
    g[u].emplace_back(v);
  }
  int s,t;
  cin >> s >> t;
  --s; --t;

  vector<vector<int>> dist(n,vector<int>(3,-3));
  queue<P> q;
  auto push = [&](int v, int d){
    if(0<=dist[v][d%3] && dist[v][d%3]<=d) return;
    dist[v][d%3] = d;
    q.emplace(v,d);
  };
  push(s,0);
  while(!q.empty()){
    P p = q.front(); q.pop();
    for(int v:g[p.first]){
      push(v,p.second+1);
    }
  }
  cout << dist[t][0]/3 << endl;
}


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

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();  // input Integer
    int b = sc.nextInt();  // input Integer
//    String a = sc.next();  // input String
    int p = a*3+b;
    System.out.println(p/2);
  }
}

Measured memory_bytes: 21844
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

def main():
    N = int(input())
    d = make_divisors(N)
    d.reverse()
    ans = float('inf')
    for i in range(N):
        if len(d) == 1:
            a = d.pop()
            ans = min(ans, 2*(a-1))
            break
        if len(d) == 0:
            break
        a = d.pop()-1
        b = d.pop()-1
        ans = min(ans, a+b)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9440
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N,K,S;
	cin>>N>>K>>S;
	for(int i=0;i<N;i++)
	{
		cout<<(i<K?S:(S==1000000000?S-1:S+1));
		if(i==N-1)cout<<endl;
		else cout<<" ";
	}
}

Measured memory_bytes: 1280
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
# 勇者1...1番目・2番目の街で、B_1体まで
# 勇者2...2番目・3番目の街で、B_2体まで
# 勇者N...N番目・(N+1)番目の街で、B_N体まで
 
ans = sum(A)
for i in range(N):
  if A[i] >= B[i]: A[i] -= B[i]
  else:
    # A[i] < B[i]
    B[i] -= A[i]
    A[i] = 0
    A[i+1] = max(A[i+1]-B[i], 0) 

ans -= sum(A)
print(ans)

Measured memory_bytes: 24280
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            final String inputA = inputReader.readLine();
            final String inputB = inputReader.readLine();
            if (inputA == null || inputB == null) {
                break;
            }
            final String[] splitA = inputA.split(" ");
            final String[] splitB = inputB.split(" ");

            int hit = 0;
            int blow = 0;
            for (int i = 0; i < splitA.length; i++) {
                if (splitA[i].equals(splitB[i])) {
                    hit++;
                    splitA[i] = "";
                    splitB[i] = "";
                }
            }
            for (int i = 0; i < splitA.length; i++) {
                if (splitA[i].length() == 0) {
                    continue;
                }
                for (int j = 0; j < splitB.length; j++) {
                    if (splitA[i].equals(splitB[j])) {
                        blow++;
                        splitA[i] = "";
                        splitB[j] = "";
                        break;
                    }
                }
            }
            System.out.printf("%d %d\n", hit, blow);
        }
    }
}

Measured memory_bytes: 12000
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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

int main()
{
  ll d, n;
  cin >> d >> n;
  int p[3] = {1, 100, 10000};


  if (n == 100)
    n++;

  cout << p[d] * n << endl;
  return 0;
}


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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;





int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	vi v({1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
});
	int k;
	cin >> k;

	cout << v[k - 1] << '\n';



	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


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

using namespace std;

vector<pair<string,pair<int, int> > > v;

int main(){
   // freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        string s;
        int x;
        cin>>s>>x;
        v.push_back({s,{-x,i}});
    }
    sort(v.begin(),v.end());

    for(int i=0;i<n;i++){
        cout<<v[i].second.second<<"\n";
    }
}

Measured memory_bytes: 256
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

L, R = [int(x) for x in input().split()]

if R - L >= 3000:
    print(0)
    sys.exit()

ans = INF
for i in range(L, R):
    for j in range(i + 1, R + 1):
        ans = min(ans, (i * j) % 2019)

print(ans)


Measured memory_bytes: 3696
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>

#include <vector>
#include <queue>

using namespace std;


const int N = 210, M = 40010;

const int INF = 1e9;


struct edge
{
	int from, to, flow, cap;
	edge() { }
	edge(int _1, int _2, int _3, int _4) : from(_1), to(_2), flow(_3), cap(_4) { }
};


struct Dinic
{
	edge edges[M];
	int head[N], nxt[M], tot;

	inline void init()
	{
		memset(head, -1, sizeof(head));
		tot = 0;
	}

	inline void add_edge(int x, int y, int z)
	{
		edges[tot] = edge(x, y, 0, z);
		nxt[tot] = head[x];
		head[x] = tot++;
		edges[tot] = edge(y, x, 0, 0);
		nxt[tot] = head[y];
		head[y] = tot++;
	}

	int s, t, L, R;

	int cur[N];

	int d[N];

	bool bfs()
	{
		memset(d + L, -1, sizeof(int) * (R-L+1));
		
		queue <int> q;
		q.push(s);
		d[s] = 0;
		
		while (!q.empty())
		{
			int x = q.front(); q.pop();
			cur[x] = head[x];
			for (int i = head[x]; ~i; i = nxt[i])
			{
				edge & e = edges[i];
				if (d[e.to] == -1 && e.flow < e.cap)
				{
					d[e.to] = d[x] + 1;
					q.push(e.to);
				}
			}
		}
		
		return d[t] != -1;
	}

	int dfs(int x, int a)
	{
		if (x == t || a == 0) return a;
		
		int flow = 0, f = 0;
		for (int &i = cur[x]; ~i; i = nxt[i])
		{
			edge & e = edges[i];
			if (d[e.to] == d[x] + 1 && (f = dfs(e.to, min(a, e.cap - e.flow))) > 0)
			{
				e.flow += f;
				edges[i^1].flow -= f;
				a -= f;
				flow += f;
				if (!a) break;
			}
		}
		
		return flow;
	}

	inline int maxflow(int s, int t)
	{
		this->s = s;
		this->t = t;
		int flow = 0;
		while (bfs()) flow += dfs(s, INF);
		return flow;
	}
} dinic;


int n, m;

int a[110][110], b[110][110], c[110][110];
int val[110][110];


vector <int> vec[110][110];


inline int get(int x) { return (x-1) / m + 1; }


int main()
{
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			scanf("%d", &a[i][j]);
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			vec[i][get(a[i][j])].push_back(a[i][j]);
	
	for (int i = 1; i <= m; i++)
	{
		dinic.init();
		
		dinic.L = 0, dinic.R = 2 * n + 2;
		int S = 2 * n + 1, T = 2 * n + 2;
		
		for (int j = 1; j <= n; j++)
			dinic.add_edge(S, j, 1);
		for (int j = 1; j <= n; j++)
			dinic.add_edge(j + n, T, 1);
		for (int j = 1; j <= n; j++)
			for (int k = 1; k <= n; k++)
				if (!vec[j][k].empty()) dinic.add_edge(j, k + n, 1);
		dinic.maxflow(S, T);
		for (int j = 1; j <= n; j++)
			for (int k = dinic.head[j]; ~k; k = dinic.nxt[k])
			{
				edge & e = dinic.edges[k];
				if (e.to != S && e.to != T && e.to > n && e.cap == e.flow)
				{
					b[j][i] = vec[j][e.to - n].back();
					vec[j][e.to - n].pop_back();
				}
			}
	}
	
	for (int i = 1; i <= m; i++)
	{
		static int tmp[110];
		for (int j = 1; j <= n; j++) tmp[j] = b[j][i];
		sort(tmp + 1, tmp + 1 + n, [](int a, int b) { return get(a) < get(b); });
		for (int j = 1; j <= n; j++) c[j][i] = tmp[j];
	}
	
	for (int i = 1; i <= n; i++, puts(""))
		for (int j = 1; j <= m; j++)
			printf("%d ", b[i][j]);
	for (int i = 1; i <= n; i++, puts(""))
		for (int j = 1; j <= m; j++)
			printf("%d ", c[i][j]);
	
	return 0;
}

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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long
#define vi vector<int>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())

int main(){
	int a=0,buf;

	REP(i,4){
		cin>>buf;
		a+=buf;
	}
	cout<<a/60<<"\n"<<a%60<<"\n";
	return 0;
}

Measured memory_bytes: 3080
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  (_, k) <- getIntPair
  ns <- getIntList
  print $ ceiling $ solve k ns

solve k ns = bisearchD check (0, fromIntegral (maximum ns))
  where
    check d = k < (sum $ map (subtract 1 . ceiling . (/d)) ds)
    ds = map fromIntegral ns

-- Input

getInt :: IO Int
getInt = readLn
second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine
 
getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntegerList :: IO [Integer]
getIntegerList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2
        
bisearchD :: (Double -> Bool) -> (Double, Double) -> Double
bisearchD check = bis 0
  where
    bis count (l, r)
      | count > 100 = l
      | check mid  = bis (count + 1) (mid, r)
      | otherwise  = bis (count + 1) (l, mid)
      where
        mid = l + (r - l) / 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

-- 組み合わせ
powerset :: [a] -> [[a]]  
powerset xs = filterM (\x -> [True, False]) xs


Measured memory_bytes: 29220
N, M = map(int, input().split())
birth_list = []
for i in range(M):
    Pi, Yi = map(int, input().split())
    birth_list.append([Pi, Yi])

counter = -1
prev_pref = -1
for city in sorted(birth_list, key=lambda x: (x[0], x[1])):
    # print(city)
    if city[0] != prev_pref:
        counter = 1
    else:
        counter += 1
    identity_number = str(city[0]).zfill(6) + str(counter).zfill(6)
    city.append(identity_number)
    prev_pref = city[0]

for city in birth_list:
    print(city[2])

Measured memory_bytes: 31052
from bisect import *
A,B,Q=map(int,input().split())
s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]
st = [] # (z, 0or1)0ならs, 1ならt
for i in range(A):
    st.append((s[i], 0))
for i in range(B):
    st.append((t[i], 1))

st.sort(key=lambda x: x[0])
INF = float("inf")

for _ in range(Q):
    x = int(input())
    b_left = bisect_left(st, (x, 0))
    ids = [b_left-1, b_left, b_left+1]
    dists = []
    for idx in ids:
        if 0 <= idx <= A+B-1:
            dists.append((abs(x - st[idx][0]), idx))

    ans = INF
    for start in dists:
        tmp = start[0]
        s_idx = start[1]
        now = st[s_idx][0]
        if st[s_idx][1] == 0: #s
            t_left = bisect_left(t, now)
            additional = []
            for nxt in [t_left-1, t_left, t_left+1]:
                if 0<=nxt<=B-1:
                    additional.append(abs(now - t[nxt]))
            delta = min(additional)
            ans = min(ans, tmp+delta)
        else:
            s_left = bisect_left(s, now)
            additional = []
            for nxt in [s_left-1, s_left, s_left+1]:
                if 0 <= nxt <= A-1:
                    additional.append(abs(now - s[nxt]))
            delta = min(additional)
            ans = min(ans, tmp+delta)
    print(ans)

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int d, g; cin >> d >> g;
    vector<int> p(d), c(d);
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];

    int ans = inf;
    for (int bits = 0; bits < (1 << d); bits++) {
        int num = 0;
        int score = 0;
        for (int i = 0; i < d; i++) {
            if (bits & (1 << i)) num += p[i], score += 100 * (i + 1) * p[i] + c[i];
        }
        int b = d - 1;
        while (score < g && b >= 0) {
            if (!(bits & (1 << b))) {
                int n = min(p[b], (g - score + (100 * b)) / (100 * (b + 1)));
                num += n, score += 100 * (b + 1) * n;
            }
            b--;
        }
        if (score >= g) ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <list>
#include <cmath>
#include <iomanip>

int main()
{
    while(1){
        int n;
        std::cin >> n;

        if(n==0) break;

        std::vector<int> score;
        for (int i = 0; i < n; ++i) {
            int a;
            std::cin >> a;
            score.push_back(a);
        }

        int sum = 0;
        for(auto s : score){
            sum += s;
        }
        double average = (double)sum / n;

        double sig = 0;
        for(auto s : score){
            sig += std::pow(s-average,2);
        }

        std::cout << std::setprecision(8) << std::sqrt(sig/n) << std::endl;

    }
    return 0;
}



Measured memory_bytes: 3244
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
//END OF TEMPLATE

void main(){
    ulong n;
    ulong m;
    scan(n,m);
        
    auto h=scanarr!ulong;
    ulong[][] j;
    j.length=n;

    ulong a,b;
    foreach(i;0..m){
        scan(a,b);
        j[a-1]~=
            h[b-1];
        j[b-1]~=
            h[a-1];
    }   

    ulong ans;
    foreach(i;0..n){

        if(j[i].filter!(hi=>h[i]<=hi).array.length==0)
            ans++;
    }
    ans.writeln;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const ll INF = 1e15;
int N, W;
int v[111], w[111];
ll dp[111][111111];

void print() {
   for (int i = 0; i <= N; i++) { // i個選ぶ
      for (int j = 0; j <= W; j++) { // 重さjまで
         printf(" %3lld", dp[i][j]);
      }
      puts("");
   }
}

int main() {
   // fill(dp[0], dp[111], -1);
   cin >> N >> W;
   rep (i, N) {
      cin >> v[i] >> w[i];
   }

   for (int j = 0; j <= W; j++) {
      dp[0][0] = 0;
   }
   for (int i = 0; i < N; i++) { // i個選ぶ
      for (int j = 0; j <= W; j++) { // 重さjの時
      if (j >= w[i]) dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
      else dp[i+1][j] = dp[i][j];
         // if (j + w[i] > W) dp[i+1][j] = dp[i][j];
         // debug2(i, j);
         // dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
      }
   }

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

   // print();

   return 0;
}


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

using namespace std;

#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> ii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n, a, ans = 0;
  cin >> n;
  forn(i, n) {
    cin >> a;
    ans = (ans ^ a);
  }
  if (ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
    

    
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<unordered_map>
using namespace std;

int main(void){
    int i, N;
    string s, S;
    unordered_map<string, int> hash;
    cin >> N;
    cin >> S;
    for(i=0;i<N; i++){
        s = S.substr(i, 1);
        if(hash[s]==false){
            hash[s] = 2;
        }else{
            hash[s] += 1;
        }
    }
    unsigned long ans;
    ans = 1;
    unordered_map<string, int>::iterator iter;
    for(iter=hash.begin(); iter!=hash.end(); iter++){
        ans *= iter->second;
        if(ans>pow(10, 9)+7){
            ans = ans % (unsigned long)(pow(10,9)+7);
        }
    }
    cout << ans-1<< endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
vector<pair<int ,int> >s;
queue<char>que;
int main()
{
    string str;
    int n,k;
    cin>>n>>k;
    cin>>str;
    int ans=0;
    int j=0;
    int flag=1;
   int  couts=0;
    for(int i=0; i<n; i++)
    {
          if(str[i]=='0')
          {
              if(str[i+1]!='0')
                {
                  s.push_back(make_pair(i,i-couts));
                     couts=0;
                   continue;
                }
                couts++;
          }
    }
    int maxs=0;
    if(s.size()<=k)
     ans=n;
    else
    {
         s.push_back(make_pair(n,n));
         int temp=0;
        for(int i=k;i<s.size();i++)
        {
           maxs=s[i].second-temp;

         ans=max(ans,maxs);
           temp=s[i-k].first+1;
        }
    }
       cout<<ans<<endl;
       return 0;
}




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

int main(){
    string S;
    cin >> S;
    int len = S.size();
    int ret = 0;
    REP(i,len-1){
        if(S[i] != S[i+1]){
            ret++;
        }
    }
    cout << ret << endl;
}

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

int main(){
    int a,b,c,x = 0,y = 0;
    cin >> a >> b >> c;
    
    x = b - a;
    y = c - b;
    
    if(x == y){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];
    P.push_back(-1);
    
    int tmp = 0, ans = 0;
    for (int i=0; i<=N; i++) {
        if (P[i] == i+1) {
            tmp++;
        } else {
            ans += (tmp + 1)/2;
            tmp = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	m := scanInt(sc)

	sumMods := make([]int, n+1)
	sumMods[0] = 0
	for i := 0; i < n; i++ {
		a := scanInt(sc)
		sumMods[i+1] = (sumMods[i] + a) % m
	}

	answer := int64(0)
	sameMods := make(map[int]int64, 0)
	for i := 0; i < len(sumMods); i++ {
		answer += sameMods[sumMods[i]]
		sameMods[sumMods[i]] += 1
	}

	fmt.Println(answer)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    long long int n;
    long long int count=0;

    cin>>n;
    FOR(i,1,n-1){
        count+=i;
    }
    cout<<count<<endl;
}


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

int main ()
{
   ll n;cin>>n;ll h[n];
   ll dp[n];
    fr(i,n)cin>>h[i];
   dp[0]=0;
   dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2] + abs(h[i]-h[i-2])); 
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int ufr[100100],ufp[100100],ans[100100];

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufr[i] = 1;
		ufp[i] = i;
	}
}

int ufind(int x){
	if(ufp[x] == x){
		return x;
	}
	return ufp[x] = ufind(ufp[x]);
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return;
	}
	if(ufr[x]<ufr[y]){
		swap(x,y);
	}
	ufr[x] += ufr[y];
	ufp[y] = x;
}

int main(void){
	int n,m,k,a,b,i;
	cin >> n >> m >> k;
	ufinit(n);
	for(i=0; i<m; ++i){
		cin >> a >> b;
		--a; --b;
		--ans[a];
		--ans[b];
		unionf(a,b);
	}
	for(i=0; i<k; ++i){
		cin >> a >> b;
		--a; --b;
		if(ufind(a)==ufind(b)){
			--ans[a];
			--ans[b];
		}
	}
	for(i=0; i<n; ++i){
		ans[i] += ufr[ufind(i)];
		--ans[i];
		cout << (i?" ":"") << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 2048
/*
*  Author: windystreet
*  Date  : 2019-08-05 20:51:35
*  Motto : Think twice, code once.
*/
#include<bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

void solve(){
    int n,ans = 0;
    cin>>n;
    if(n==100000) ans = 90909;
    else if(n>=10000) ans = 909 + n - 10000 + 1;
    else if(n > 999) ans = 909;
    else if(n >=100) ans = 9 + n - 100+1;
    else if(n >9 ) ans = 9;
    else ans = n;
    cout<<ans<<endl;
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
   // freopen("F:/in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
#ifndef ONLINE_JUDGE
    //printf("%.10f\n",1.0*clock()/CLOCKS_PER_SEC);
#endif
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    if s in ["KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA"]:
        print("YES")
    else:print("NO")

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
using ll = long long;

int main()
{

  int N;
  cin >> N;
  string ans = "";

  if (N == 0)
    cout << '0';

  while (N != 0)
  {
    if (N % (-2) == 0)
    {
      ans = '0' + ans;
    }
    else if (abs(N % (-2)) == 1)
    {
      ans = '1' + ans;
      N -= 1;
    }

    if (N == 0)
      break;
    N /= -2;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
while True:
    N = int(input())
    if N == 0:
        break

    table = [[0 for i in range(N+1)] for j in range(N+1)]

    for i in range(N):
        n = [int(i) for i in input().split()]
        for j in range(N):
            table[i][j] = n[j]

    for i in range(N):
        for j in range(N):
            table[i][N] += table[i][j]
            table[N][j] += table[i][j]

    for i in range(N):
        table[N][N] += table[i][N]

    for i in range(N+1):
        for j in range(N+1):
            print(str(table[i][j]).rjust(5), end="")
        print("")



Measured memory_bytes: 5628
n=int(input())
h=list(map(int,input().split()))
ans=0
tmp=0

for i in range(n-1):
  if h[i]>=h[i+1]:
    tmp+=1
  else:
    if tmp>ans:
      ans=tmp
    tmp=0
if tmp>ans:
      ans=tmp
print(ans)

Measured memory_bytes: 14224
from math import ceil, sqrt
n,d=map(int,input().split())
pw=[]
for i in range(n):
    inp=tuple(map(int,input().split()))
    pw.append(inp)

ans=0
for i in range(n-1):
    for j in range(i+1, n):
        dis=sqrt(sum([(a-b)**2 for a,b in zip(pw[i],pw[j])]))
        if ceil(dis)==int(dis):
            ans+=1
print(ans)

        

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

using namespace std;

char s[20];
int mini = 10000;

int main(){
    scanf("%s", s);
    int len = strlen(s);
    for(int i=0; i<len-2; i++){
        int num = 0;
        num += (s[i+2] - '0');
        num += (s[i+1] - '0') *10;
        num += (s[i] -'0') * 100;
        if(abs(num - 753) < mini)
            mini = abs(num-753);
    }
    printf("%d\n", mini);
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
#include <string>

using namespace std; using ll=long long; const int INF=1e9; using P=pair<ll,ll>;

int main() {
  int s,q; cin>>s>>q;
  if (s<=q) cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
}


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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)
#else
#define show(...) 42
#endif

#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define two pair<int,int>
#define ll long long int
#define int long long int
#define mod(x,m) ((x%m+m)%m)
#define oo 1e15
#define all(v) v.begin(),v.end()
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define rep(a1,b1,c1) for(int a1=b1;a1<c1;a1++)
#define repb(a2,b2,c2) for(int a2=b2;a2>=c2;a2--)
#define speedforces std::ios::sync_with_stdio(false)
#define watch(x) cerr << (#x) << " is " << (x) << "\n"
#define input_from_file  freopen("input.txt", "r", stdin);
#define output_to_file  freopen("output.txt", "w", stdout);

int ans;
int len[100005];
int deg[100005];
vector<vector<int>> g;

void dfs(int root){
   for(auto i : g[root])
    if(len[i] == 0) dfs(i);
   for(auto i : g[root]) len[root] = max(len[i]+1,len[root]);
   ans = max(ans,len[root]); 
}

signed main(){
//input_from_file;
speedforces;
int n,m; cin>>n>>m;
g.clear();
g.resize(n+1);
memset(len,0,sizeof len);
memset(deg,0,sizeof deg);
for(int i=0;i<m;i++){
  int x,y; cin>>x>>y;
  g[x].pb(y);
  deg[y]++;
}
ans = 0;
for(int i=1;i<=n;i++) 
if(deg[i] == 0) dfs(i);
cout<<ans<<endl;
}

Measured memory_bytes: 12032
#include<stdio.h>
#include<string.h>
int a;
int q;

typedef struct{
  char name[100];
  int time;
} Queue;

Queue Q[10000000];
int n;
int head = 0, tail = 0;

void enqueue(Queue x) {
  Q[head] = x;
  head++;
}

Queue dequeue() {
  tail++;
  return Q[tail-1];
}

int main(void){
  int i,j;
  int cnt;
  int SumOfTime = 0;
  Queue x;
  scanf("%d %d", &n, &q);

  for(i = 0; i < n; i++) {
    scanf("%s",x.name);
    scanf("%d",&x.time);
    enqueue(x);
  }

  while(1) {
    x = dequeue();
    if(x.time <= q) {
      SumOfTime += x.time;
      printf("%s %d\n", x.name, SumOfTime);
    } else {
      x.time -= q;
      SumOfTime += q;
      enqueue(x);
    }
    if(head == tail)break;
  }
  return 0;
}

Measured memory_bytes: 21072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> cnt(3);
    for (int i = 0; i < n; i++) {
        cnt[s[i] - 'a']++;
    }
    string ans = "YES";
    if (abs(cnt[0] - cnt[1]) > 1) ans = "NO";
    if (abs(cnt[1] - cnt[2]) > 1) ans = "NO";
    if (abs(cnt[2] - cnt[0]) > 1) ans = "NO";
    cout << ans << endl;
}

Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef int64_t I;
typedef vector<I> vI;
typedef pair<I, I> II;
typedef vector<II> vII;
typedef vector<vII> vvII;

template<typename T>
ostream& operator<<(ostream& os, vector<T> const& v) {
  os << "[";
  for (size_t i = 0; i < v.size(); i++) {
    os << (i == 0 ? "" : ",") << v[i];
  }
  return os << "]";
}

template<typename S, typename T>
ostream& operator<<(ostream& os, tuple<S, T> const& v) {
  return os << "<" << get<0>(v) << "," << get<1>(v) << ">";
}

template<typename S, typename T, typename U>
  ostream& operator<<(ostream& os, tuple<S, T, U> const& v) {
  return os << "<" << get<0>(v) << "," << get<1>(v) << "," << get<2>(v) << ">";
}

int main() {
  I n; cin >> n;
  vI a;
  for (I i = 0; i < n; i++) {
    I x; cin >> x;
    a.push_back(x);
  }
  vI sums(n);
  sums[0] = a[0];
  sums[1] = a[1];
  for (I i = 2; i < n; i+=2) {
    sums[i] = sums[i - 2] + a[i];
  }
  for (I i = 3; i < n; i+=2) {
    sums[i] = max(sums[i - 2] + a[i], sums[i - 3] + a[i]);
  }
  if (n % 2 == 0) {
    cout << max(sums[n - 2], sums[n - 1]) << endl;
  } else {
    I m = sums[n - 2];
    for (I i = 0; i < n; i += 2) {
      m = max(m, sums[n - 1] - a[i]);
    }
    for (I i = 1; i < n; i += 2) {
      m = max(m, sums[n - 1] - sums[i - 1] + sums[i] - a[i]);
    }
    cout << m << endl;
  }
}



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

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

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

  bool flag = true;
  int cnt = 0;
  int dummy;
  
  while(flag){
    
    flag = false;

    for(int i = n-1; i > 0; i--){
      if(a[i] < a[i-1]){
	dummy = a[i];
	a[i]  = a[i-1];
	a[i-1]  = dummy;
	cnt++;
	flag = true;
      }
    }
  }

  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    cout << a[i]; 
  }

  cout << endl;
  cout << cnt << endl;

  return 0;

}



Measured memory_bytes: 3096
#include<iostream>
#include<queue>
using namespace std;
struct P{
  int tax, tay;
  int kax, kay;
  int c;

  P(int _tax, int _tay, int _kax, int _kay, int _c) : tax(_tax), tay(_tay), kax(_kax), kay(_kay), c(_c) {};
};

int x, y;
int m[51][51];
int tx, ty, kx, ky;

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

int bfs(void){
  queue<P> que;
  que.push(P(tx, ty, kx, ky, 0));

  bool a[51][51][51][51];

  for(int i = 0;i < x; i++)
    for(int j = 0;j < y; j++)
      for(int k = 0;k < x; k++)
	for(int l = 0;l < y; l++) a[i][j][k][l] = false;

  int ans = 100;

  while(que.size()){
    P p = que.front(); que.pop();
    if(p.tax == p.kax && p.tay == p.kay || p.c > 100){
      ans = p.c;
      break;
    }

    for(int i = 0;i < 4; i++){
      int nx1 = p.tax + dx[i], ny1 = p.tay + dy[i];
      int nx2 = p.kax - dx[i], ny2 = p.kay - dy[i];

      if((0 > nx1 || 0 > ny1 || nx1 >= x || ny1 >= y || m[ny1][nx1] == 1) && (0 > nx2 || 0 > ny2 || nx2 >= x || ny2 >= y || m[ny2][nx2] == 1)) continue;

      if(0 > nx1 || 0 > ny1 || nx1 >= x || ny1 >= y || m[ny1][nx1] == 1)      nx1 = p.tax, ny1 = p.tay;
      else if(0 > nx2 || 0 > ny2 || nx2 >= x || ny2 >= y || m[ny2][nx2] == 1) nx2 = p.kax, ny2 = p.kay;
 
      if(a[nx1][ny1][nx2][ny2]) continue;

      a[nx1][ny1][nx2][ny2] = true;

      que.push(P(nx1, ny1, nx2, ny2, p.c + 1));
    }
  }
  return ans;
}

int main(void){

  for( ; ; ){
    cin >> x >> y;

    if(!x && !y) break;

    cin >> tx >> ty >> kx >> ky;
    tx--; ty--; kx--; ky--;

    for(int i = 0;i < y; i++){
      for(int j = 0;j < x; j++){
	cin >> m[i][j];
      }
    }

    int ans = bfs();
    if(ans >= 100) cout << "NA" << endl;
    else cout << ans << endl;
  }
}


Measured memory_bytes: 7944