akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];

        for(int i = 0; i<N; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int alice = 0;
        int bob = 0;
        boolean f = false;
        for(int i = N-1; i>=0; i--) {
            if(f) bob += a[i];
            else alice += a[i];
            f = !f;
        }
        System.out.println(alice-bob);


    }
}

Measured memory_bytes: 23764
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

d,t,s = ip()
if t*s >= d:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61680
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; string s;
	cin >> n >> s;
	map< char, ll > mp;
	for( char c = 'a'; c <= 'z'; ++c ) mp[c] = 1;
	for( char c : s ){
		++mp[c];
	}
	ll ans = 1;
	for( char c = 'a'; c <= 'z'; ++c ){
		ans *= mp[c];
		ans %= MOD;
	}
	cout << ( ans-1+MOD ) % MOD << endl;
	return 0;
}

Measured memory_bytes: 512
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
string s;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes";
	else 
		cout<<"No";
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort()
F.sort(reverse = True)

ng = -1
ok = 10 ** 12

while ok - ng > 1:
	mid = (ok + ng) // 2
	ctr = 0
	for i in range(N):
		ctr += max(0, A[i] - mid // F[i])
	if ctr <= K:
		ok = mid
	else:
		ng = mid

print(ok)

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

int main() {

  int N, M, K;
  cin >> N >> M >> K;

  vector<int> A(N);
  vector<int> B(M);

  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  for(int i = 0; i < M; i++){
    cin >> B[i];
  }

  vector<long> sumA(N + 1);
  vector<long> sumB(M + 1);

  int maxA = N;
  int maxB = M;

  for(int i = 0; i <= N; i ++){
    if(i == 0){
      sumA[i] = 0;
    }else{
      sumA[i] = sumA[i - 1] + A[i - 1];
    }
    if(sumA[i] > K){
      maxA = i - 1;
      break;
    }
  }

  for(int i = 0; i <= M; i ++){
    if(i == 0){
      sumB[i] = 0;
    }else{
      sumB[i] = sumB[i - 1] + B[i - 1];
    }
    if(sumB[i] > K){
      maxB = i - 1;
      break;
    }
  }

  int max = 0;

  for(int i = 0; i <= maxA; i++){
    for(int j = maxB; i >= 0; j--){
      if(sumA[i] + sumB[j] <= K){
        maxB = j;
        if(i + j > max){
          max = i + j;
        }
        break;
      }else{
        continue;
      }
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 8008
#include <stdio.h>
#include <string>
#include <cmath>
#include <list>
#include <algorithm>

using namespace std;

int main(void)
{
    int n, m, x;
    int c[12];
    int a[12][12];

    scanf("%d %d %d", &n, &m, &x);
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        for (int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }

    int scores[12];
    int prices[4096];
    std::list<int> costs;

    for (int i = 0; i < pow(2, n); i++) {
        int digits[12];
        for (int j = 0; j < n; j++) {
            digits[j] = i & (int) pow(2, j);
        }

        // for (int j = 0; j < n; j++) {
        //     printf("%d ", digits[j]);
        // }
        // printf("\n");

        for (int k = 0; k < m; k++) {
            scores[k] = 0;
        }

        int cost = 0;

        for (int j = 0; j < n; j++) {
            if (digits[j] != 0) {
                for (int k = 0; k < m; k++) {
                    scores[k] += a[j][k];
                }
                cost += c[j];
            }
        }

        // for (int k = 0; k < m; k++) {
        //     printf("%d ", scores[k]);
        // }
        // printf("\n");
        // printf("%d\n", cost);

        bool flag = true;
        for (int k = 0; k < m; k++) {
            if (scores[k] < x) {
                flag = false;
                break;
            }
        }
        if (flag) {
            costs.push_back(cost);
        }
    }

    // for (std::list<int>::iterator itr = costs.begin(); itr != costs.end(); itr++) {
    //     printf("%d\n", *itr);
    // }

    if (costs.size() == 0) {
        printf("%d", -1);
    } else {
        printf("%d", *std::min_element(costs.begin(), costs.end()));
    }

    return 0;
}


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

int main() {
	int t;
	cin>>t;
	while(t--) {
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		if(d>c && b<a)
			cout<<-1<<"\n";
		else if(a<=b) {
			cout<<b<<"\n";
		}
		else {

			
			
			
				ll rem = a - b;
				//time = b;
				ll pp = (rem)%(c-d);
				ll pro = 0;
				if(pp != 0) {
					pro = (rem/(c-d)) + 1;
				}
				else {
					pro = rem/(c-d);
				}
				ll ans = b + pro*c;
				cout<<ans<<"\n";
			

		}
	}
	return 0;
}*/

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

int main() {

	int n;
	cin>>n;
	n = n%10;
	if(n == 3)
		cout<<"bon";
	else if(n==0 || n==1 || n==6 || n==8)
		cout<<"pon";
	else
		cout<<"hon"; 
	
	return 0;
}


/*
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	ll t;
	cin>>t;
	while(t--) {
		ll n;
		cin>>n;
		n = 2*n;
		//cout<<M_PI<<" ";

		double ans = 1/(tan(3.141592653589/n));
		
		cout<<setprecision(20)<<ans<<"\n";
	}
	return 0;
}*/

Measured memory_bytes: 3624
n,m,c=map(int,input().split())
b=list(map(int,input().split()))

cnt=0

for i in range(n):
  total = 0
  #配列aを取得
  a = list(map(int,input().split()))
  #totalにaとbの計算結果を格納
  for j in range(m):
    total += a[j] * b[j]

  if total > -c:
    cnt += 1

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  a-=k;
  if(a>=0){ cout << a << " " << b << endl; return 0; }
  b+=a;
  if(b>=0){ cout << 0 << " " << b << endl; return 0;}
  cout << 0 << " " << 0 << endl;
  return 0;
}


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

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

    V<ll> v(n);
    for(int i = 0; i < n; i++){
        ll a; cin >> a;
        v[i] = a - (i + 1);
    }
    sort(all(v));
    ll b = v[n / 2];

    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += abs(v[i] - b);
    }
    cout << ans << endl;

}


Measured memory_bytes: 4768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double

int32_t main()
{
    cout << fixed << setprecision(15);
    int n;
    cin >> n;
    vector<pair<double, pair<double, double>>> a;
    for (int i = 0; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        a.push_back({arg(complex<double>({x, y})), {x, y}});
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i)
        a.push_back(a[i]);

    double ans = 0;
    for (int i = 0; i < n; ++i)
    {
        double x = 0, y = 0;
        for (int j = i; j < n + i; ++j)
        {
            x += a[j].second.first;
            y += a[j].second.second;
            ans = max<double>(ans, sqrt(x * x + y * y));
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
    int a,b = 0,n[50];

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

    for(int i = 0;i < a;++i){
        for(int j = i+1; j < a;++j){
            b += (n[i] * n[j]);
        }
    }

    cout << b << endl;
}


Measured memory_bytes: 256
n=int(input())
d,x=map(int,input().split())
s=0
for i in range(n):
  k=0
  a=int(input())
  c=0
  while True:
    y=k*a+1
    if y<=d:
      c+=1
      k+=1
    else:
      s+=c
      break
print(s+x)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  unsigned long long X; cin >>X;
  unsigned long long yokin=100;
  int Ans=0;
  while (true) {
    Ans++;
    yokin*=1.01;
    if (X<=yokin) break;
  }
  cout <<Ans <<endl;
  return 0;
}


Measured memory_bytes: 3624
n,m,c = map(int,input().split())
b_list = list(map(int,input().split()))
a_list = [list(map(int,input().split())) for nesya in range(n)]
ans = 0
for hoge in a_list:
  t = 0
  d = 0
  while t < m:
    d += b_list[t]*hoge[t]
    t += 1
  if d+c > 0:
    ans += 1
print(ans)

Measured memory_bytes: 3064
n = int(input())
a = input()
b = input()
c = input()

ans = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        pass
    elif (a[i] != b[i]) and (b[i] != c[i]) and (c[i] != a[i]):
        ans += 2
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    n,X = LI()
    x = LI()
    for i in range(n-1):
        x[i+1] += x[i]
    x.insert(0,0)
    ans = float("inf")
    f = [5,5]
    for i in range(n):
        f.append(f[-1]+2)
    for k in range(1,n+1):
        i = 0
        a = n
        d = (k+n)*X
        while a > 0:
            d += f[i]*(x[a]-x[max(0,a-k)])
            a -= k
            i += 1
        ans = min(ans,d)
    print(ans)
#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 26604
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
data.append(0)

ans=0
memo=0
cnt=0
for i in data:
    if i == memo:
        cnt+=1
    else:
        ans+=(cnt//2)
        cnt=1
    memo=i
print(ans)

Measured memory_bytes: 3060
#ifdef LOCAL_EXEC
#include "include.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define trace(...)
#endif

using LL = long long;

const int mod = 1e9 + 7;
int modpow(int a, int n) {
	int res = 1;
	for (; n > 0; n >>= 1) {
		if (n & 1) res = (res * 1ll * a) % mod;
		a = (a * 1ll * a) % mod;
	}
	return res;
}

int modinv(int a) {
	return modpow(a, mod - 2);
}

int fact(int n) {
	int res = 1;
	for (int i = 1; i <= n; i++) {
		res = (res * 1ll * i) % mod;
	}
	return res;
}

int solve(int x, int y) {
	if ((x + y) % 3 != 0) return 0;
	int m = (x + y) / 3;
	x -= m, y -= m;
	if (x < 0 || y < 0) return 0;

	int num = fact(x + y);
	int den = (fact(x) * 1ll * fact(y)) % mod;
	return (num * 1ll * modinv(den)) % mod;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int x, y; cin >> x >> y;
	cout << solve(x, y) << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC128
{
    class C
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();
            int N = a[0], M = a[1];
            List<int[]> list = new List<int[]>();
            for (int i = 0; i < M; i++)
            {
                int[] b = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();
                list.Add(b);
            }
            int[] p = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();

            int counter = 0;
            int ns = (int)Math.Pow(2, N);
            for (int i = 0; i < ns; i++)
            {
                int x = i;
                bool[] onoff = new bool[N];
                for (int j = 0; j < N;j++)
                {
                    onoff[j] = x % 2 == 1;
                    x /= 2;
                }

                for (int j = 0; j < M; j++)
                {
                    int[] s = list[j];
                    {
                        int numOn = 0;
                        for (int k = 0; k < s[0]; k++)
                        {
                            int sw = s[k + 1];
                            if (onoff[sw-1]) numOn++; ;
                        }
                        if (numOn % 2 != p[j])
                        {
                            goto label1;
                        }
                    }
                }
                counter++;
            label1:;
            }

            Console.WriteLine(counter);

        }
    }
}


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

int main(){
	int a, l;
	while(1){
		cin >> a >> l;
		if(a == 0 && l == 0) break;

		vector<int> an;
		an.push_back(a);
		int i = 1;
		int flag = 0;
		while(1){
			vector<int>::iterator ite = an.end() -1;
			int ai = *ite;

			vector<int> digit;
			for(int k = 0; k < l; k++){
				digit.push_back(ai % 10);
				ai /= 10;
			}

			sort(digit.begin(), digit.end());
			int aimax = 0;
			int di = 1;
			ite = digit.begin();
			while(ite != digit.end()){
				aimax += (*ite) * di;
				di *= 10;
				ite++;
			}
			int aimin = 0;
			di /= 10;
			ite = digit.begin();
			while(ite != digit.end()){
				aimin += (*ite) * di;
				di /= 10;
				ite++;
			}

			ai = aimax - aimin;
			ite = an.begin();
			int j = 0;
			while(ite != an.end()){
				if(ai == *ite){
					flag = 1;
					break;
				}
				ite++;
				j++;
			}
			an.push_back(ai);

			if(flag){
				cout << j << ' ' << ai << ' ' << i-j << endl;
				break;
			}
			i++;

		}
	}

	return 0;
}

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

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

    int count=0;
        
    
    for (int i=1; i<=N; i++) {
        string buta=to_string(i);
        if (buta.size()%2==1) {
            count++;
        }
    }
    cout << count << endl;
}
        
        


Measured memory_bytes: 3728
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  int r,d,i,res;
  cin >> r >> d >> res;
  for(i=0;i<10;i++){
    res=r*res-d;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

#define int LL

int n, m;
int p[101010];
int a[101010], b[101010], c[101010];
int C[101010];

signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> p[i];
		p[i]--;
		if (i != 0) {
			if (p[i - 1] < p[i]) {
				C[p[i - 1]]++;
				C[p[i]]--;
			}
			else {
				C[p[i]]++;
				C[p[i - 1]]--;
			}
		}
	}
	for (int i = 0; i < 100100; i++) {
		if (i != 0)C[i] += C[i - 1];
	}
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		ans += min(a[i] * C[i], c[i] + b[i] * C[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 7012
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H = scan.nextInt();
		int W = scan.nextInt();
		int[][]G = new int[H][W];
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				G[i][j] = scan.nextInt();
			}
		}
		scan.close();
		if(H == 1) {
			for(int i = 0; i < W; i++) {
				if(G[0][i] == 0) {
					System.out.println(1);
					System.exit(0);
				}
			}
			System.out.println(0);
		}else if(W == 1) {
			for(int i = 0; i < H; i++) {
				if(G[i][0] == 0) {
					System.out.println(1);
					System.exit(0);
				}
			}
			System.out.println(0);
		}else {
			System.out.println(getLargestSquare(H, W, G));
		}

	}
	static int getLargestSquare(int H, int W, int[][]G) {
		int maxWidth = 0;
		int[][]dp = new int[H][W];
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				// 1と0を入れ替える
				dp[i][j] = (G[i][j] + 1) % 2;
			}
		}
		for(int i = 1; i < H; i++) {
			for(int j = 1; j < W; j++) {
				if(G[i][j] == 1) {
					dp[i][j] = 0;
				}else {
					dp[i][j] = Math.min(dp[i - 1][j - 1], Math.min(dp[i - 1][j], dp[i][j - 1])) + 1;
					maxWidth = Math.max(maxWidth, dp[i][j]);
				}
			}
		}
		return maxWidth * maxWidth;
	}
}



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

int main(){
    priority_queue<int> q;
    for(int i=0; i<3; i++){
        int tmp;
        cin >> tmp;
        q.push(tmp);
    }
    int cnt=0,cnt2=0;
    int a=q.top();q.pop();
    int b=q.top();q.pop();
    int c=q.top();q.pop();
    cnt+=a-b;
    c+=a-b;
    if(a%2!=c%2){
        cnt++;
        a++;
        b++;
    }
    cnt+=(a-c)/2;
    
    cout << cnt << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#ABC142D
import sys
import math
import collections
#sys.setrecursionlimit(100000)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#n=int(input())
tmp = input().split()
a,b = list(map(lambda a: int(a), tmp))


tmp=gcd(a,b)
c = collections.Counter(prime_factorize(tmp))

#print(c.keys())
print(len(c.keys())+1)


Measured memory_bytes: 3316
#include<stdio.h>

int main()
{
  int a, b;
  int n;
  int i, j;

  //Read a and b
  scanf("%d%d", &a, &b);

  //if b>a, change a into b
  if(b>a)
    {
      i=a;
      a=b;
      b=i;
    }


  //This algorism is the Euclidean algorithm
  while(1)
    {
      //step 1
      n=a%b;

      //step2
      //if n=0, b is the greatest common divisor
      if(n==0)
	{
	  printf("%d\n", b);
	  break;
	}

      //When n not equal 0, new a is b and new b is n. Then return step1.
      else if(n!=0)
	{
	  a=b;
	  b=n;
	}
    }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define io  ios_base::sync_with_stdio(false);    cin.tie(NULL);
#define vec  vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define MOD 1000000007
using namespace std;
 
 void solve()
 {
          ll i,z,c,d,y=0,x,l=0,A[1000],B[5004],a,b,s,j,m,n,num,p,q,k,r;
         
    //     vec v(n),v1; 
          string S,S1;
          cin>>S;
          cin>>S1;
          for(i=0;i<S.length();i++)
          {
              if(S[i]!=S1[i])
              l++;
          }
          cout<<l;
          
          
 }
 
int main() 
{  io
    ll num;
num=1;
//cin>>num;
while(num--)
{ 
solve();

cout<<"\n";
}
return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#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 ALL(a) (a).begin(), (a).end()

int main() {
    int H, W;
    string A[100];
    cin >> H >> W;
    REP(i, H) cin >> A[i];

    vector<int> hv, wv;
    REP(i, H) {
        bool ok = true;
        REP(j, W) if (A[i][j] == '#') {
            ok = false;
            break;
        }
        if (!ok) hv.push_back(i);
    }
    REP(i, W) {
        bool ok = true;
        REP(j, H) if (A[j][i] == '#') {
            ok = false;
            break;
        }
        if (!ok) wv.push_back(i);
    }
    for (int i : hv) { for (int j : wv) cout << A[i][j]; cout << endl; }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
struct edge
{
	int u,v,w;
	edge(int a,int b,int c):u(a),v(b),w(c){}
	bool operator<(const edge &b)const{return w<b.w;}
};
int n,p[110000];
pair<int,int> x[110000],y[110000];
vector<edge> e;
int find(int x){return p[x]==x?x:p[x]=find(p[x]);}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i].first,&y[i].first);
		x[i].second=y[i].second=i;
	}
	sort(x+1,x+1+n);
	sort(y+1,y+1+n);
	for(int i=1;i<n;i++)e.push_back(edge(x[i].second,x[i+1].second,x[i+1].first-x[i].first));
	for(int i=1;i<n;i++)e.push_back(edge(y[i].second,y[i+1].second,y[i+1].first-y[i].first));
	for(int i=1;i<=n;i++)p[i]=i;
	sort(e.begin(),e.end());
	long long ans=0;
	for(int j=0;j<e.size();j++)
	{
		int u=find(e[j].u),v=find(e[j].v);
		if(u==v)continue;
		ans+=e[j].w;
		p[u]=v;
	}
	printf("%lld\n",ans);
	return 0;
}


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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) {
        cout << k << endl;
        return 0;
    } else if (k <= a + b) {
        cout << a << endl;
        return 0;
    } else {
        cout << a - (k - a - b) << endl;
    }
}

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

int main(){
    int K; cin >> K;
    long long sum1=0, sum2=0, sum3=0;
    sum1=K*(K+1)/2;
    for(int i=1; i<=K-1; i++){
        for(int j=i+1; j<=K; j++){
            sum2+=__gcd(i,j);
        }
    }
    sum2*=6;
    for(int i=1; i<=K-2; i++){
        for(int j=i+1; j<=K-1; j++){
            for(int k=j+1; k<=K; k++){
                sum3+=__gcd(i,__gcd(j,k));
            }
        }
    }
    sum3*=6;
    long long ans=sum1+sum2+sum3;
    cout << ans << endl;
    return 0;
}

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

int main()
{
    long n, k, m = 1000000007, result = 0;
    cin >> n >> k;
    n++;
    for (long i = k; i <= n; i++) {
        result += n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2 - i * (i - 1) / 2 + 1;
        result %= m;
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 3196
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
 	int low = max(a,c);
  	int high = min(b,d);
	cout << max(0, high - low) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    public static void Main()
    {
        int N = NextInt();
        int x = NextInt();
        if (x != 1 && x != 2 * N - 1)
        {
            Console.WriteLine("Yes");
            int[] ans = new int[2 * N - 1];
            for (int i = 0; i < 2 * N - 1; i++) ans[i] = 0;
            ans[N - 2] = 1;
            ans[N - 1] = x;
            ans[N] = 2 * N - 1;
            int y = 2;
            for (int i = 0; i < 2 * N - 1; i++)
            {
                if (ans[i] != 0) { continue; }
                if (y == x) { i -= 1;y += 1; continue; }
                ans[i] = y;
                y++;
            }
            for (int i = 0; i < 2 * N - 1; i++) Console.WriteLine(ans[i]);
        }
        else Console.WriteLine("No");
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 17116
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  ll dp[60][60][3000]; //i番目までの中からj個選んで総和になりうるか
  int N,A;
  cin>>N>>A;
  int x[N+1];
  for(int i=0; i<N; i++){
    cin>>x[i];
  }
  dp[0][0][0]=1;
  for(int i=0; i<N; i++){
    for(int j=0; j<=N; j++){
      for(int k=0; k<=A*N; k++){
        dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
        dp[i+1][j][k]+=dp[i][j][k];
      }
    }
  }
 	ll sum = 0;
	for (int i = 0; i <= N; i++){
      sum += dp[N][i][A*i];
    }
	cout << sum-1 << endl;
}

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

A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

XYC = [tuple(map(int, input().split())) for _ in range(M)]

ans = min(A) + min(B)
for x, y, c in XYC:
    cost = A[x - 1] + B[y - 1] - c
    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 28432
import itertools

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

for k in itertools.combinations_with_replacement(["", "A", "B", "C"], K):
  if A*2**k.count("A") < B*2**k.count("B") and B*2**k.count("B") < C*2**k.count("C"):
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
//a<=bとする。gcd(a,b)<=aが成り立つ。
//a=p*qとすると，最大公約数の候補は1,p,q,r。

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    long long N, K;
    cin >> N >> K;
    long long ans = 0;
    vector<long long>u(K + 1);
    for (size_t i = K; i >= 1; i--)
    {
         u.at(i)=modpow((K / i), N , mod);
         for (size_t j = 2; i*j <= K; j++)
         {
             u.at(i) -= u.at(i * j);
             if (u.at(i) < 0)u.at(i)+=mod;
         }
    }
    for (size_t i = 1; i <= K; i++)
    {
        ans += u.at(i) * i;
        ans %= mod;
    }
    cout << ans;
}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e3 + 10;

void solve() {
   int x, y, k;
   while(cin >> x) {
        cin >> y >> k;
        bool f = 0;
        for (int i = 0; i <= x; i++) {
            for (int j = 0; j <= y; j++) {
                if(i * j + (x - i) * (y - j) == k || i * (y - j) + (x - i) * j == k) {
                    f = 1; break;
                }
            }
            if(f) break;
        }
        puts(f ? "Yes" : "No");
   }
}

int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}

void calc() {

	Int N, M, Q; std::cin >> N >> M >> Q;
	std::vector<Int> a(Q), b(Q), c(Q), d(Q);
	rep(i, Q)std::cin >> a[i] >> b[i] >> c[i] >> d[i];
	//ここまで入力受け取り

	Int ans = -1;

	auto check = [&](std::vector<Int>& vec) {
		Int res = 0;
		rep(i, Q) {
			if (vec[b[i] - 1] - vec[a[i] - 1] == c[i])res += d[i];
		}
		ans = std::max(ans, res);
	};

	std::vector<Int> A(N, -1);
	std::stack<std::pair<std::vector<Int>, Int>> s;
	s.push({ A, 0 });

	while (!s.empty()) {
		auto [vec, cur] = s.top(); s.pop();
		Int prev = -1;
		if (cur != 0)prev = vec[cur - 1];

		rep(i, M) {
			if (prev > i + 1)continue;
			vec[cur] = i + 1;
			if (cur + 1 == N) {
				check(vec);
				continue;
			}
			s.push({ vec, cur + 1 });
		}
		
	}

	std::cout << ans;


}


int main() {

	init();
	calc();

	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>

int main(){
  int L,A,B,C,D,i,count=0;

  scanf("%d %d %d %d %d",&L,&A,&B,&C,&D);

  for(i = 0; i <= L; i++){
    A-=C;
    B-=D;
    count++;
    if(A <= 0 && B <= 0){
      break;
    }
  }
  L-=count;

  printf("%d\n",L);
  return 0;
}

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

using namespace std;

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

    string s;
    cin >> s;

    int comparison_position = 0;
    char comparison_character = s[0];
    int count = 1;

    for (int i = 1; i < s.size(); i++){
        if (s[i] == comparison_character) continue;
        else{
            count++;
            comparison_position = i;
            comparison_character = s[i];
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 512
import numpy as np


card = np.array([list(map(int, input().split())) for _ in range(3)], dtype=np.int64)
n = int(input())
for _ in range(n):
    num = int(input())
    card[card == num] = 0
card = card == 0


def check_vertical(card):
    return np.all(card, axis=0).sum() >= 1


def check_horizon(card):
    return np.all(card, axis=1).sum() >= 1


def check_diagonal(card):
    check1 = np.diag(card).sum()
    check2 = np.diag(np.fliplr(card)).sum()
    return check1 == 3 or check2 == 3


if check_vertical(card) or check_horizon(card) or check_diagonal(card):
    print('Yes')
else:
    print('No')


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];
bool U[100005];

int main()
{
    int N;
    cin >> N;
    ll xr = 0;
    REP(i, N)
    {
        cin >> A[i];
        xr ^= A[i];
    }

    int sum = 0;
    for (int i = 30; i >= 0; --i)
    {
        int n = ((xr >> i) & 1);
        if ((n + sum) % 2 == 0)
            continue;

        bool find = false;
        REP(j, N)
        {
            if (A[j] % (1 << i) == 0 && ((A[j] >> i) & 1 == 1) && !U[j])
            {
                U[j] = true;
                find = true;
                sum++;
                break;
            }
        }
        if (!find)
        {
            sum = -1;
            break;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
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;}
using Int = long long;
const char newl = '\n';


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;

  int sum=0;
  int op=0,cl=0;

  using P = pair<int, int>;
  vector<P> vp;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(char c:s){
      if(c=='(') sum++;
      if(c==')') sum--;
    }

    int cnt=0,res=0;
    for(char c:s){
      if(c=='(') cnt++;
      if(c==')') cnt--;
      if(cnt<0) res++,cnt++;
    }
    if(cnt==0) cl+=res;
    else if(res==0) op+=cnt;
    else vp.emplace_back(res,cnt);
  }
  if(sum) drop("No");

  vector<P> xs,ys;
  for(auto p:vp){
    if(p.first<=p.second) xs.emplace_back(p);
    else ys.emplace_back(p.second,p.first);
  }
  sort(xs.begin(),xs.end());
  sort(ys.begin(),ys.end());
  for(auto p:xs){
    if(op-p.first<0) drop("No");
    op-=p.first;
    op+=p.second;
  }
  for(auto p:ys){
    if(cl-p.first<0) drop("No");
    cl-=p.first;
    cl+=p.second;
  }
  assert(op==cl);
  drop("Yes");
  return 0;
}


Measured memory_bytes: 7808
import java.util.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1237();
	}
	
	class AOJ1237{
		AOJ1237(){
			while(true){
				target = sc.nextInt();
				seq = sc.next();
				if(target==0)	break;
				solve();
			}
		}
		int target,ans;
		int[] alist;
		boolean valid;
		String seq;
		void solve(){
			
			valid=true;
			ans=-1;
			alist=new int[seq.length()];
			for(int i=0; i<alist.length; ++i)	alist[i]=-1;
			
			dfs(new int[seq.length()], seq, 0, 0);
			if(ans<0)	System.out.println("error");
			else if(!valid)	System.out.println("rejected");
			else{
				System.out.print(ans);
				for(int i=0; i<alist.length; ++i)if(alist[i]>=0)	System.out.print(" "+alist[i]);
				System.out.println();
			}
		}
		void dfs(int[] list,String remain,int sum,int depth){
			int cur=Integer.parseInt(remain);
			if(sum+cur <= target){
				if(sum+cur == ans)	valid=false;
				if(sum+cur > ans){
					valid = true;
					ans = sum+cur;
					for(int i=0; i<depth; ++i)	alist[i]=list[i];
					alist[depth]=cur;
					for(int i=depth+1; i<list.length; ++i)	alist[i]=-1;
				}
			}
			
			
			for(int i=1; i<=remain.length(); ++i){
				String	l=remain.substring(0, i),
						r=remain.substring(i);
				if(r.isEmpty())	continue;
				cur = Integer.parseInt(l);
				if(sum+cur > target)	continue;
				list[depth] = cur;
				dfs(list, r, sum+cur, depth+1);
			}
		}
	}
}

Measured memory_bytes: 20212
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,0,n - 1) cin >> a[i];
  rep(i,0,n - 1) a[i]--;
  int ans = 0;
  for(int i = 0;i < n;i++){
    if(i < a[i] && a[a[i]] == i) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
int main()
{
	int N;
	scanf("%d", &N);
	char s = 'Q';
	int sum = 0;
  	getchar();
	for(int i = 0; i < N; i++)
	{
		char temp = getchar();
		if(temp != s)
		{
			sum++;
			s = temp;
		}
	}
	printf("%d", sum);
}

Measured memory_bytes: 128
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  out(floor((nin()+nin())*nin()/2))
}
main()

Measured memory_bytes: 7372
#include<stdio.h>

int main(void)
{
        int n, m, k, a[1000]={0}, r, b=0;
        int i, j;

        scanf("%d%d", &n,&m);

        for(i = 0; i < n; i++) {
                scanf("%d", &k);
                for(j = 0; j < k; j++) {
                        scanf("%d", &r);
                        a[r]++;
                }
        }

        for(i = 0; i <= m; i++) {
                if(a[i] == n) {
                        b++;
                }
        }
        printf("%d\n", b);
        return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if(n % 2 == 1) cout << "No" << endl;
  else{
    bool b = 1;
    for(int i = 0; i < n/2; ++i){
      if(s.at(i) != s.at(i+n/2)){
        b = 0;
        break;
      }
    }
    if(b) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int h,w; cin >> h >> w;
    vector<vector<int> > a(h, vector<int>(w, 0));
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }

    vector<tuple<int,int,int,int>> ans;

    rep(i,h){
        rep(j,w){
            int ni,nj;
            if(i == h-1 && j == w-1) break;
            else if(j == w-1) {ni = i+1; nj = j;}
            if(j < w-1) {ni = i; nj = j+1;}

            if(a[i][j] % 2 == 1){
                ans.push_back(make_tuple(i,j,ni,nj));
                a[i][j]--; a[ni][nj]++;
            }
        }
    }

    int n = ans.size();
    cout << n << endl;
    for(auto p : ans){
        cout << get<0>(p)+1 << " " << get<1>(p)+1 << " " << get<2>(p)+1 << " " <<get<3>(p)+1 << endl;
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	unordered_map<int,int>m;
	for(int i=0;i<n;++i){
		int A; cin>>A;
		++m[A];
	}
	int64_t ans=0;
	for(auto&&i:m){
		if(i.first!=i.second){
			ans+=i.second>i.first?i.second-i.first:i.second;
		}
	}
	cout<<ans<<"\n"s;
}

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

int N;
vector<vector<pair<int, int>>> G;
vector<int> C;

void dfs(int cur, int prev, int color) {
  int c = 1;
  for (auto p : G.at(cur)) {
    if (p.first == prev) continue;
    if (c == color) c++;
    C.at(p.second) = c;
    dfs(p.first, cur, c);
    c++;
  }
}

int main() {
  cin >> N;
  G.resize(N);
  C.resize(N-1);
  for (int i = 0; i < N-1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G.at(a).push_back(make_pair(b, i));
    G.at(b).push_back(make_pair(a, i));
  }
  dfs(0, -1, -1);
  int K = 0;
  for (int i = 0; i < N-1; i++) K = max(K, C.at(i));
  cout << K << endl;
  for (int i = 0; i < N-1; i++) cout << C.at(i) << endl;
}

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

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
    static modint H(ll a,ll b){
        return C(a+b, a);
    }
};
vector<modint> modint::factorial;
#define C(n,r) modint::C(n,r)
#define H(a,b) modint::H(a,b)

int main(void){
    ll H,W,h,w;
    cin >> H >> W >> h >> w;
    modint res = H(W-1,H-1);
    rep(x,w-1){
        res -= H(H-h,x) * H(h-2,W-x-1);
    }
    res -= H(H-h,w-1) * H(h-1,W-w);
    cout << res << endl;
    return 0;
}


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

struct Main {
  map<string, vector<string> > m;
  set<string> num, vis;

  int rec(const string &s) {
    vis.insert(s);
    if(!m.count(s)) return 1;
    int res = 0;
    for(int i = 0; i < m[s].size(); ++i) {
      if(vis.count(m[s][i])) continue;
      res += rec(m[s][i]);
    }
    return res;
  }

  Main() {
    int n; cin >> n;
    if(n == 0) exit(0);
    string first;
    for(int i = 0; i < n; ++i) {
      string s; cin >> s;
      replace(s.begin(), s.end(), ':', ' ');
      replace(s.begin(), s.end(), ',', ' ');
      replace(s.begin(), s.end(), '.', ' ');
      stringstream ss(s);
      string group;
      ss >> group;
      if(first.empty()) first = group;
      string name;
      while(ss >> name) {
        m[group].push_back(name);
      }
    }
    cout << rec(first) << endl;
  }
};

int main() {
  while(Main(), 1);
  return 0;
}

Measured memory_bytes: 1392
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n;
	cin>>n;
	int a;
	cin>>a;
	int count=1,ma=a;
	for(int i=1;i<n;i++){
		int b;
		cin>>b;
		ma=max(ma,b);
		if(b==ma){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int A = cin.nextint;
        int B = cin.nextint;
        WriteLine(new[] { A + B, A - B, A * B }.Max());
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
use std::collections::BTreeSet;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn main() {
    let n = reads()[0];

    let mut rs: Vec<(i32, i32)> = (0..n)
        .map(|_| {
            let v = reads();
            (v[0], v[1])
        })
        .collect();

    let mut bs: Vec<(i32, i32)> = (0..n)
        .map(|_| {
            let v = reads();
            (v[0], v[1])
        })
        .collect();

    rs.sort();
    bs.sort();

    let mut ys = BTreeSet::<i32>::new();
    let mut ri = 0;
    let mut ans = 0;

    for &(bx, by) in bs.iter() {
        while ri < rs.len() && rs[ri].0 < bx {
            ys.insert(rs[ri].1);
            ri += 1;
        }

        let mut cand = -1;
        for &y in ys.iter() {
            if y < by && y > cand {
                cand = y;
            }
        }

        if cand >= 0 {
            ans += 1;
            ys.remove(&cand);
        }
    }

    println!("{}", ans);
}


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


def solve(S: str):
    print(min(abs(int(S[i:i + 3]) - 753) for i in range(len(S) - 2)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060