akhauriyash/Code-Regression huggingface dataset:
N,M = (int(i) for i in input().split())

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)
    divisors.sort()
    return divisors
M_div = make_divisors(M)

for i in range(len(M_div)):
	if N <= M_div[i]:
		break

a = len(M_div)-i
print(M_div[a-1])

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	String S;
	int N;
	int count = 0;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		S = in.readLine();
	}

	void calc() {
		for (int i = 0; i + 2 < N; ++i) {
			if (S.substring(i).startsWith("ABC")) {
				++count;
			}
		}
	}

	void showResult() {
		System.out.println(count);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 1e5 + 5;
typedef long long ll;
 
ll xL[MAXN], xR[MAXN], C, preL[MAXN], preR[MAXN], mxL[MAXN], mxR[MAXN];
int vL[MAXN], vR[MAXN], N;
 
int main(){
	scanf("%d %lld", &N, &C);
	for(int i=1; i<=N; ++i){
		scanf("%lld %d", &xL[i], &vL[i]);
		xR[N - i + 1] = C - xL[i];
		vR[N - i + 1] = vL[i];
	}
	for(int i=1; i<=N; ++i) preL[i] = preL[i - 1] - xL[i] + xL[i - 1] + vL[i];
	for(int i=1; i<=N; ++i) preR[i] = preR[i - 1] - xR[i] + xR[i - 1] + vR[i];
	for(int i=1; i<=N; ++i) mxR[i] = max(mxR[i - 1], preR[i]);
	for(int i=1; i<=N; ++i) mxL[i] = max(mxL[i - 1], preL[i]);
	ll best = 0;
	for(int L=0; L<=N; ++L){
		ll cur = preL[L];
		if(cur > best) best = cur;
		cur = cur - xL[L] + mxR[N - L];
		if(cur > best) best = cur;
	}
	for(int R=0; R<=N; ++R){
		ll cur = preR[R];
		if(cur > best) best = cur;
		cur = cur - xR[R] + mxL[N - R];
		if(cur > best) best = cur;
	}
	printf("%lld\n", best);
	return 0;
}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;

vcL color( 100000+99, 0 );
bool vis[ 100000+99 ];

void DFS(vPL *adj, int now) {
	for (auto x : adj[now]) {
		if ( vis[x.first] ) continue;
		else vis[x.first] = true;
		
		DFS( adj, x.first );
	}
}

void solve() {
	MEM( vis, false );
	
	lli n, m, cnt = 0;
	cin >> n >> m;
	
	vPL adj[ n+1 ];
	
	for (int i = 0; i < m; ++i) {
		int from, to, dis;
		cin >> from >> to >> dis;
		adj[from].Push( Pair( to, dis%2 ) );
		adj[to].Push( Pair( from, dis%2 ) );
	}
	
	for (int i = 1; i <= n; ++i) {
		if ( !vis[i] ) {
			cnt++ ;
			DFS( adj, i );
		}
	}
	
	cout << cnt << '\n';
}

int main() {
	int t = 1;
	#ifdef LOCAL
		t = 1 << 10;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 11776
#include<iostream>
using namespace std;
int main(){
    int n;
    int jud=1;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
      if(a[i]%2 == 0 && a[i]%3 != 0 && a[i]%5 != 0){
          jud = 0;
      }
    }
    if(jud == 0){
        cout << "DENIED" << endl;
    }else{
        cout << "APPROVED" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 20:53:06 2019

@author: Yamazaki Kenichi
"""

n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(1,n-1):
    if (p[i] - p[i-1]) * (p[i] - p[i+1]) < 0:
        ans += 1

print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, M, K; cin >> N >> M >> K;
  string result = "No";
  rep(i,N+1) rep(j,M+1) {
    if (i*j+(N-i)*(M-j)==K) result = "Yes";
  }
  cout << result << endl;
  return 0;
}

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

using namespace std;

int main() {
  string n;
  cin >> n;
  string ans = "";
  for (int i = 0; i < n.size(); ++i) {
    if (n[i] == '1') {
      ans += '9';
    }
    else {
      ans += '1';
    }
  }
  cout << ans << endl;
  return 0;
}



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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll sum = accumulate(a.begin(), a.end(), 0LL);
  int cnt = 0;
  rep(i,n) {
    if (4*m*a[i] < sum) continue;
    cnt++;
  }
  if (cnt >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<limits>
#include<stack>

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;

int INF = std::numeric_limits<int>::max();
int NINF = std::numeric_limits<int>::min();
int MOD = 1e9+7;

int col[] = {0,-1,0,1,1,1,-1,-1};
int row[] = {-1,0,1,0,1,-1,1,-1};

//knight moves
int cc[] = {1,2,2,1,-1,-1,-2,-2};
int rr[] = {-2,-1,1,2,-2,2,1,-1};

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

    int n, w;
    cin >> n >> w;

    vi wts(n), vals(n);
    vvll dp(n,vll(w+1,0));

    for(int i = 0; i < n ; ++i)
        cin >> wts[i] >> vals[i];

    //initialize dp table
    for(int i = wts[0]; i <= w ; ++i)
        dp[0][i] = vals[0];

    for(int i = 1 ; i < n; ++i)
    {
        for(int j = 0; j < wts[i] ; ++j)
            dp[i][j] = dp[i-1][j];

        for(int j = wts[i]; j <= w ; ++j)
        {
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-wts[i]] +vals[i]);
        }
    }

     /*for(int i = 0 ; i < n; ++i)
    {
        for(int j = 0; j <= w ; ++j)
        {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/

    cout << dp[n-1][w];
    return 0;
}


Measured memory_bytes: 82248
n, x, y = map(int, input().split())

x -= 1
y -= 1
ans = [0] * n

for i in range(n):
    for j in range(i+1, n):
        dist = min(j - i, abs(i-x) + abs(j-y) + 1)
        ans[dist] += 1

for i in range(1,n):
    print(ans[i])


Measured memory_bytes: 3444
import sys
import numpy as np
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import defaultdict

N = int(input())
lines = readlines()
graph = defaultdict(list)
for line in lines[:N-1]:
  a,b,c = map(int,line.split())
  graph[a].append((b,c))
  graph[b].append((a,c))
Q, K = map(int,lines[N-1].split())
XY = np.array([line.split() for line in lines[N:]],np.int64)

def degreesOfSeparation(graph,start):
    if start not in graph:
        return -1
    visited = set()
    frontier = set()
    table = [0] * (len(graph) + 1)
    degrees = 0
    visited.add(start)
    frontier.add(start)
    while len(frontier) > 0:
        #print(frontier,":",degrees)
        #degrees += 1
        newfront = set()
        for g in frontier:
            for next in graph[g]:
                if next[0] not in visited:
                    visited.add(next[0])
                    newfront.add(next[0])
                    table[next[0]] += next[1] + table[g]
        frontier = newfront
    return table
table = degreesOfSeparation(graph,K)
for q in range(Q):
  print(table[XY[q][0]] + table[XY[q][1]])

Measured memory_bytes: 102748
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>

#define REP(i,k,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

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

	int a[21];
	memset(a,0,sizeof(a));

	bool b[21];
	rep(i,21) b[i] = true;

	vector<vector<int> > v(21);

	rep(i,m)
	{
		int x,y;
		cin >> x >> y;

		x--;
		y--;
		a[y]++;
		v[x].pb(y);
	}

	int count = 0;
	while(count != n)
	{
		rep(i,n)
		{
			if(a[i] == 0 && b[i])
			{
				cout << i+1 << endl;
				b[i] = false;
				count++;

				rep(j,v[i].size()) a[v[i][j]]--;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) {
  v = vector<T>(n, x);
}
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i];
}
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  lli a, b; cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> card(n);
    for (int i = 0; i < n;i++){
        cin >> card.at(i);
    }
    sort(card.begin(), card.end(), greater<int>());
    int sum_A = 0, sum_B = 0;

        for (int i = 0; i < n;i++){
            if(i%2 ==0){
            sum_A += card.at(i);
            }
            else {
                sum_B += card.at(i);
            }
    }
    cout << sum_A - sum_B << endl;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
xyc=[list(map(int,input().split())) for i in range(M)]

noti=min(a)+min(b)
ans=noti
c=0

for i in range(M):
    c=a[xyc[i][0]-1] + b[xyc[i][1]-1] -xyc[i][2]
    ans=min(ans,c)
print(ans)

Measured memory_bytes: 38568
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
for i in range(D):
  SC+=S[i][P[i][0]]
YY=[]
Y=[]
for k in range(25):
  for i in range(D):
    SC2=SC
    YY=XX[:]
    Y=X[:]
    SC2-=S[i][P[i][0]]
    SC2+=S[i][P[i][k+1]]
    for j in range(26):
      Y[j]=0
    YY[P[i][0]],YY[P[i][k+1]]=0,0
    for j in range(D):
      if j==i:
        Z=P[j][k+1]
      else:
        Z=P[j][0]
      Y[P[i][0]]+=C[P[i][0]]
      Y[P[i][k+1]]+=C[P[i][k+1]]
      Y[Z]=0
      YY[P[i][0]]+=Y[P[i][0]]
      YY[P[i][k+1]]+=Y[P[i][k+1]]
    if SC2-sum(YY)>SC-sum(XX):
      P[i].insert(0,P[i][k+1])
      del P[i][k+2]
      XX=YY[:]
      SC=SC2
for i in range(D):
  print(P[i][0]+1)

Measured memory_bytes: 84848
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int cal(vector<string> board,int high,int wide,int k){
  int p = 0;
  for(int i = 0;i<high;i++){
    for(int j = 0;j<wide;j++){
      if(board[i][j]=='#'){
        p++;
      }
    }
  }
  if(p==k){
    return 1;
  }else{
    return 0;
  }
}

int yokobo(vector<string> board,int loc,int high,int wide,int k){
  if(loc==wide){
    return cal(board,high,wide,k);
  }
  int p = yokobo(board,loc+1,high,wide,k);
  for(int i = 0;i<high;i++){
    board[i][loc]='.';
  }
  return p+yokobo(board,loc+1,high,wide,k);
}

int tatebo(vector<string> board,int loc,int high,int wide,int k){
  if(loc == high){
    return yokobo(board,0,high,wide,k);
  }
  long long p =  tatebo(board,loc+1,high,wide,k);
  for(int i = 0;i<wide;i++){
    board[loc][i]= '.';
  }
  return tatebo(board,loc+1,high,wide,k)+p;
}

int main(void){
  int high,wide,k;
  cin >> high >> wide >> k;
  vector<string> board(high);
  for(int i = 0;i<high;i++){
    cin >> board[i];
  }
  long long ans = 0;
  for(int i = 0;i < 64;i++){
    ans = ans + tatebo(board,0,high,wide,k);
  }
  ans = ans/64;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;

namespace A
{

    class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLineIntSpilit();

            //true 高橋くんたーん
            bool flag = true;
            while(s[0] > 0 || s[2] > 0) {
                if (flag) {
                    // c - b
                    s[2] = s[2] - s[1];
                    flag = false;
                }
                else {
                    // a - d
                    s[0] = s[0] - s[3];
                    flag = true;
                }
            }

            Console.WriteLine((flag) ? "Yes" : "No");
            ReadLine();
        }

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 19000
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
using namespace std;

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

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>

#define N 200000
int arr[N];

int cmp(const void *a, const void *b) {
	return *(const int *) b - *(const int *) a;
}

int main(void) {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	qsort(arr, n, sizeof arr[0], cmp);

	long long int ans = arr[0];
	int ci = 1, cc = 0;
	for (int i = 2; i < n; i++) {
		ans += arr[ci];
		if (cc) {
			cc = 0;
			ci++;
		} else cc = 1;
	}

	printf("%lld\n", ans);
}


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1 && f==-1 && r==-1){
            break;
        }
        if(m==-1 || f==-1){
             cout<<"F"<<endl;
        }
        else{
        int sum=m+f;
        if(sum>=80){
            cout<<"A"<<endl;
        }
        else if(65<=sum && sum<80){
            cout<<"B"<<endl;
        }
        else if(50<=sum && sum<65){
            cout<<"C"<<endl;
        }
        else if(30<=sum && sum<50){
            if(r>=50){
                cout<<"C"<<endl;
            }
            else{
                cout<<"D"<<endl;
            }
        }
        else{
            cout<<"F"<<endl;
        }
        sum=0;
        }
    }
    return 0;
}


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

signed main() {
    int n;
    cin >> n;
    long long int sum = 0;
    for( int i = 1 ; i <= n ; i++ ) {
        if( i % 3 == 0 || i % 5 == 0 )
            continue;
        else
            sum += i;
    }
    cout << sum << "\n";
}


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

int main(){
    
    string sent, sub;
    int m, h;
    
    while(1){
        cin >> sent;
        if ( sent == "-") break;
        cin >> m;
        for ( int i = 0; i < m; i++){
            cin >> h;
            sub = sent.substr(0,h);
            sent.erase(0,h);
            sent = sent + sub;
        }
        cout << sent << endl;
    }
    return 0;
}



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

int main() {
  int N, x, a;
  cin >> N >> x;
  int ans = 0;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> a;
    vec.at(i) = a;
  }
  sort(vec.begin(), vec.end());

  for(int i = 0; i < N; i++){
    x -= vec.at(i);
    if(x < 0) break; // xがマイナスなら終了
    else if(i != N-1 && x >= 0) ans++; // iがN-1でない時（3なら2の時で）xが0以上なら足す
    else if(x == 0) ans++; // xが0と同じでも足す
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long[] a = new long[5];
    for(int i = 0; i < 5; i++ ){
      a[i] = sc.nextLong();
    }
    Main abc123C = new Main();
    System.out.println(abc123C.solve(n, a));
  }

  public long solve(long n, long[] a) {
    long min = a[0];
    for(int i = 1; i < 5; i++ ) {
      if(a[i] < min){
        min = a[i];
      }
    }
    return (long)Math.ceil((double)n/min) + 4;
  }
}


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

using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;
using str = string;
using bl = bool;
using ch = char;

template<class T> using v = vector<T>;
template<class T> using uset = unordered_set<T>;
template<class T1, class T2> using umap = unordered_map<T1, T2>;

#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define sz(x) ((int)(x).size())
#define ph push_back
#define pp pop_back
#define mp make_pair
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define fore(i, a) for(auto& i : a)
#define FORE(i, a) for(auto i : a) 

template<class T> void pd(T x)
{
    cout << x << " ";
}
template<class T> void pl(T x)
{
    cout << x << endl;
}

// -----



int main()
// 引退するレベルのくそをやらかしたのでくそいかになりました
{
    ll a, b, n;
    cin >> a >> b >> n;
    
    ll x = min(b - 1, n);
    ll ans = ((a * (ll)x) / b) - a * ((ll)x / b);
    pl(ans);
}

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

template<typename T>
using Matrix = vector<vector<T>>;

template<typename T>
struct Edge { int src, to; T cost; };

template<typename T>
using Edges = vector<Edge<T>>;

// g: 隣接行列。自分から自分への距離は0。到達できない場合はINF
// INF: gのINF値
template<typename T>
void warshall_floyd(Matrix<T>& g, const T INF) {
    for (int k = 0; k < g.size(); ++k) {
        for (int i = 0; i < g.size(); ++i) {
            for (int j = 0; j < g.size(); ++j) {
                if (g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

void Main()
{
    // 頂点数, 辺の数
    int V, E;
    cin >> V >> E;
    // 隣接行列構築
    const int INF = 1e9;
    Matrix<int> g(V, vector<int>(V, INF));
    Edges<int> edges;
    for (int i = 0; i < E; ++i) {
        int from, to, cost; cin >> from >> to >> cost;
        // if 1-indexed
        --from, --to;
        edges.push_back(Edge<int>{from,to,cost});
        g[from][to] = cost;
        // 無向
        g[to][from] = cost;
    }
    for (int i = 0; i < V; ++i) {
        g[i][i] = 0;
    }
    // ワーシャルフロイド
    warshall_floyd(g, INF);
    int res = 0;
    for (auto edge : edges) {
        if (g[edge.src][edge.to] < edge.cost) ++res;
    }
    cout << res;
}

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


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> L(10, vector<int>(10));
    rep(i, 10) rep(j, 10) cin >> L[i][j];

    vector<vector<int>> A(N, vector<int>(M));
    rep(i, N) rep(j, M) cin >> A[i][j];

    rep(k, 10) rep(i, 10) rep(j, 10) {
        L[i][j] = min(L[i][j], L[i][k] + L[k][j]);
    }

    int64 ans = 0;
    rep(i, N) rep(j, M) {
        if (A[i][j] == -1) continue;
        ans += L[A[i][j]][1];
    }

    cout << ans << endl;

    // rep(i, 10) cout << L[i] << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#define true 1
#define false 0

int judge(int, int);
int A[25], Q[205];
int n, q, sum = 0, flag = 0;

int main()
{

    int i, j;

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

    scanf("%d", &q);
    for (i = 0; i < q; i++)
    {
        scanf("%d", &Q[i]);
    }

    for (j = 0; j < q; j++)
    {
        if (judge(0, Q[j]) == true)
            printf("yes\n");
        else
            printf("no\n");
    }

    return 0;
}

int judge(int i, int m)
{
    //printf("%d %d\n",i,m);
    int res = false;

    if (m == 0)
        return true;

    if (i >= n)
        return false;

    if (judge(i + 1, m - A[i]) == true)
        res = true;
    if (judge(i + 1, m) == true)
        res = true;

    return res;
}



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

void swap(int &a, int &b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int a, b;
	while(cin >> a >> b, a|b) {
		if(a > b) {
			swap(a, b);
		}
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e15+7;
const ll N = 200003;
ll n,a[N],y=0,x=0,ans=INF;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
		y+=a[i];
	}
	FOR(i,0,n-1){
		y-=a[i];
		x+=a[i];
		ans=min(abs(y-x),ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
import operator
import functools
import itertools
import math


def sum_of_vector(vec1, vec2):
    return list(map(operator.add, vec1, vec2))


def powerset(iterable):
    s = list(iterable)
    return itertools.chain.from_iterable(itertools.combinations(s, r) for r in range(len(s) + 1))


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

min_value = float("inf")
for x in powerset(books):
    if x:
        vec_sum = functools.reduce(sum_of_vector, x)
        cost, *achieves = vec_sum
        if all(map(lambda achieve: achieve >= X, achieves)):
            if min_value > cost:
                min_value = cost

if math.isinf(min_value):
    print(-1)
else:
    print(min_value)


Measured memory_bytes: 9644
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int p, q, m;
    cin >> p >> q >> m;
    VI a(p), b(q);
    REP(i,p) a[i] = in();
    REP(i,q) b[i] = in();
    int ans = *min_element(ALL(a)) + *min_element(ALL(b));
    REP(i,m){
        int u = in() - 1, v = in() - 1, c = in();
        chmin(ans, a[u] + b[v] - c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n, d;
    cin >> n >> d;
    
    cout << ((n-1) / (2*d+1) + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define li long long int
#define FOR(i, a, b) for (li (i) = (a) ; (i) < (b) ; ++(i))
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    li M;
    cin >> M;

    li ans = 48 - M;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
'use strict';

function main(stdin) {
  const input = stdin.split(' ').map(v => parseInt(v, 10));
  const A = input[0];
  const B = input[1];
  let ans;

  if (A < 6) {
    ans = 0;
  } else if (A <= 12) {
    ans = B / 2;
  } else {
    ans = B;
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
#include <iomanip>
using namespace std;
typedef long long ll;

int Tmax, V, E, u, v, d, Nnew, new_id, dst, order[11111], check[444], par[444], sum = 0;
vector<vector<pair<int, int>>> li(444);
queue<pair<int, int>> route;
queue<int> store;
queue<int> car;

void dfs(int now, int distance) {
	route.push(make_pair(now, distance));
	sum += distance * 2;
	for (auto &e : li[now]) {
		if (par[e.first] == now) {
			dfs(e.first, e.second);
			route.push(make_pair(now, e.second));
		}
	}
}

int main() {
	cin >> V >> E;
	for (int i = 0; i < E; i++) {
		cin >> u >> v >> d;
		li[u].push_back(make_pair(v, d));
		li[v].push_back(make_pair(u, d));
	}
	cin >> Tmax;
	for (int i = 0; i < Tmax; i++) {
		cin >> Nnew;
		if (Nnew)
			cin >> new_id >> order[i];
		else
			order[i] = -1;
	}
	for (int i = 1; i <= V; i++)
		check[i] = 0;
	priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, greater<pair<pair<int, int>, int >>> que;
	que.push(make_pair(make_pair(0, 1), -1));
	while (!que.empty()) {
		int now = que.top().first.second, npar = que.top().second;
		que.pop();
		if (!check[now]) {
			check[now]++;
			par[now] = npar;
			for (auto &e : li[now]) {
				int next = e.first, dnext = e.second;
				if (!check[next])
					que.push(make_pair(make_pair(dnext, next), now));
			}
		}
	}
	dfs(1, 0);
	route.pop();
	int count = 0, ndst = 1, check_store = 1;
	queue<int> keep;
	queue<pair<int, int>> keep2;
	for (int i = 0; i < Tmax; i++) {
		if (order[i] > 0)
			store.push(order[i]);
		if (ndst == 1 && !count)
			check_store = 1;
		if (check_store) {
			while (!store.empty()) {
				car.push(store.front());
				store.pop();
			}
		}
		if (check_store&&car.size() < 1)
			cout << "-1" << endl;
		else {
			check_store = 0;
			if (!count) {
				while (!car.empty()) {
					if (car.front() != ndst)
						keep.push(car.front());
					car.pop();
				}
				while (!keep.empty()) {
					car.push(keep.front());
					keep.pop();
				}
				int nowp = ndst,flag=0;
				while (1) {
					int checkp = route.front().first;
					if (checkp == par[nowp])
						break;
					keep2.push(route.front());
					route.pop();
					while (!car.empty()) {
						if (car.front() == checkp) {
							flag = 1;
							break;
						}
						keep.push(car.front());
						car.pop();
					}
					while (!keep.empty()) {
						car.push(keep.front());
						keep.pop();
					}
					if (checkp == nowp) {
						if (flag) {
							while (!route.empty()) {
								keep2.push(route.front());
								route.pop();
							}
							while (!keep2.empty()) {
								route.push(keep2.front());
								keep2.pop();
							}
							break;
						}
						else {
							while (!keep2.empty()) {
								route.push(keep2.front());
								keep2.pop();
							}
						}
					}
				}
				ndst = route.front().first;
				count = route.front().second;
				route.pop();
				route.push(make_pair(ndst, count));
			}
			cout << ndst << endl;
			count--;
		}
	}
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int x,y,amari,z;


  //input
  scanf("%d %d",&x,&y);


  if(x<y){
		z=x;
		x=y;
		y=z;
	}

		while(y>0){
      amari=x%y;
      x=y;
      y=amari;
    }

    //output
    printf("%d\n",x);

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>

using namespace std;

int main()
{
	int n;
	
	while( cin >> n, n)
	{
		int hit  = 0;
		
		for( int i = 1; i*4 <= n; i++)
		{
			int j;
			cin >> j;
			hit += j;
		}
		
		cout << hit << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(){
  int p[50],N;
  cin >> N;
  for(int i=0;i<N;i++)cin >> p[i];
  int cnt=0;
  for(int i=0;i<N;i++){
    if(p[i]!=i+1) cnt++;
  }
  
  if(cnt<=2)cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vpr){
    if(!vpr.empty()){
        auto x = vpr.front();
        ostr << x.first << " " << x.second;
        for(auto itr = ++vpr.begin(); itr != vpr.end(); itr++){
            x = *itr;
            ostr << endl << x.first << " " << x.second;
        }
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
// vll x(n); x[i]=a;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;
typedef vector<vector<ll>> vvll;
// vvll x(m,vi(n)); x[i][j]=a;

#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    string s;
    cin >> s;

    ll n = s.size();
    ll a = 1, t = 0;
    REP(i,n-2){
        if(t < 1){
            t = 1;
            a++;
        }
        else if(t > 1){
            t--;
            a++;
        }
        else if(s[i] == s[i-1]){
            t = 3;
        }
        else{
            a++;
        }
    }
    if(t == 3) a++;
    else if(t == 2 && s[n-2] != s[n-1]) a++;
    else if(t == 0 && s[n-2] != s[n-1]) a++;
    else if(s[n-3] != s[n-2] && s[n-2] != s[n-1]) a++;

    cout << a << endl;
    return 0;
}

Measured memory_bytes: 640
import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.List (transpose, group)

main :: IO ()
main = do
  [n, m, d] <- map read <$> words <$> getLine
  solve d <$> replicateM n getLine >>= print

solve :: Int -> [String] -> Int
solve d ss = cnt xs + cnt ys
  where f = map length . filter ((=='.') . head) . group
        xs = concatMap f ss
        ys = concatMap f . transpose $ ss
        cnt = sum . map (\x -> max 0 (x-d+1))



Measured memory_bytes: 5024
#include <cstdio>
#include <utility>
using namespace std;

typedef pair<int, int> MD;
typedef pair<int, MD> YMD;

const char *msgs[] = {"meiji", "taisho", "showa", "heisei"};
YMD comp[] = {
  YMD(1868, MD(9, 8)),
  YMD(1912, MD(7, 30)),
  YMD(1926, MD(12, 25)),
  YMD(1989, MD(1, 8)),
};

int main() {
  while (1) {
    int y, m, d;
    if (scanf("%d%d%d", &y, &m, &d) != 3) return 0;

    YMD p = YMD(y, MD(m, d));
    bool found = false;
    for (int i=3; i>=0; i--) {
      if (p >= comp[i]) {
        printf("%s %d %d %d\n", msgs[i], y-comp[i].first+1, m, d);
        found = true;
        break;
      }
    }

    if (!found) puts("pre-meiji");
  }
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;
int ans;

const int mod = 1000000007;

int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int cost = min({4*a,2*b,c});
    int n;
    cin >> n;

    if(n%2 == 0)
    {
      cout << min(n/2*d,n*cost);
    }
    else
    {
      cout << min(n*cost,n/2*d + cost);
    }
    return 0; 
}


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

typedef long long int ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define sz(a) (int)(a).size()
const int lt=100005;
ll mod=1000000007;

void printv(vector <ll> a){
	for(int i=0;i<a.size();i++)
		cout << a[i] << " ";
	cout << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string n;
	cin >> n;
	ll sum = 0;
	for(int i=0;i<sz(n);i++)
		sum=(sum+(n[i]-'0'))%9;
	
	if(sum==0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

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

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

        if x == y:
            return

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

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

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

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = map(int, input().split())
uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)

print(uf.group_count() - 1)

Measured memory_bytes: 12772
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int main()
{
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (0 <= x - r && x + r <= w && 0 <= y - r && y + r <= h)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int count = 0;
            int PjMin = Integer.MAX_VALUE;

            for (int i = 0; i < N; i++) {
                int Pi = in.nextInt();
                if (Pi <= PjMin) {
                    count++;
                }
                if (PjMin >= Pi) {
                    PjMin = Pi;
                }
            }
            out.println(count);
        }
    }
}

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

int main(){
	int k, n;
	cin >> n >> k;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	
	sort(p.begin(), p.end());
	int ans = 0;
	rep(i, k) {
		ans += p[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>

const double EPS=1e-10;

#define equals(a, b) (fabs((a)-b(b))<EPS)
#define X real()
#define Y imag()

using namespace std;

typedef complex<double> Point;
typedef complex<double> Vector;

struct Segment {
    Point p1, p2;
};
typedef Segment Line;

struct Circle {
    Point c;
    double r;
    Circle(Point c=Point(), double r=0.0) :
        c(c),r(r){}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Vector a,Vector b) {
    return a.X*b.Y - a.Y*b.X;
}

Point project(Segment s, Point p) {
    Vector base = s.p2-s.p1;
    double r=dot(p-s.p1,base) / norm(base);
    return s.p1+base*r;
}

Point reflect(Segment s, Point p) {
    return p+(project(s,p)-p)*2.0;
}

enum CCW {
    COUNTER_CLOCKWISE=1,
    CLOCKWISE=-1,
    ONLINE_BACK=2,
    ONLINE_FRONT=-2,
    ON_SEGMENT=0,
};

int ccw(Point p0, Point p1, Point p2) {
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return CCW::COUNTER_CLOCKWISE;
    if(cross(a,b)<-EPS) return CCW::CLOCKWISE;
    if(dot(a,b)<-EPS) return CCW::ONLINE_BACK;
    if(norm(a)<norm(b)) return CCW::ONLINE_FRONT;

    return CCW::ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4) {
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2) {
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPoint(Segment s1,Segment s2) {
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}
int main() {
    int q;
    cin>>q;
    while(q-->0) {
        double x1,y1;
        double x2,y2;
        double x3,y3;
        double x4,y4;
        cin>>x1>>y1>>x2>>y2;
        cin>>x3>>y3>>x4>>y4;
        Segment s1=Segment({Point(x1,y1),Point(x2,y2)});
        Segment s2=Segment({Point(x3,y3),Point(x4,y4)});

        Point p=getCrossPoint(s1,s2);
        printf("%.10f %.10f\n",p.X,p.Y);
    }
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
int main(int argc, char** argv) {
	int n;
	cin>>n;
	ll ans=0,v=0;
	rep(i,1,n)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		ans+=x*y;
		v+=y;
	}
	ll k=0;
	while(ans/10)
	{
		k+=ans/10;
		ans=ans/10+ans%10;
	};
	cout<<v-1+k;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll brr[1009],sum,cnt=0,mx=0,f=0,n;
    //int f=0,n;
    scanf("%lld",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%lld",&brr[i]);
    }
    for(int i=0; i<n-1; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            f=0;
            sum=brr[i]*brr[j];
           // cout<<sum<<" 11"<<endl;
           ll sum1=sum;
           ll val1=sum%10;

           sum=sum/10;
            while(sum!=0)
            {
                ll val=sum%10;
                if(val+1!=val1)
                {
                    f=1;
                    break;
                }
                val1=val;
                //cout<<val<<endl;
                //in[cnt++]=val;
                sum=sum/10;
            }
            if(f==0)
            {
                mx=max(mx,sum1);
            }
        }
    }
    if(mx==0)
        printf("-1\n");
    else
        printf("%lld\n",mx);

    return 0;
}

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

int main()
{
    std::string s;
    bool table[26]{};
    std::cin >> s;
    for (const auto& e : s)
    {
        table[e - 'a'] = true;
    }
    for (int i = 0; i < 26; i++)
    {
        if (table[i]) continue;
        printf("%c\n", i + 'a');
        return 0;
    }
    printf("None\n");

    return 0;
}

Measured memory_bytes: 512
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [i for i in range(n)] # parents
        self.rank = [1] * n # height of tree
        self.size = [1] * n # size[i] -> iをrootとするgroupのサイズ

    # 木の根を返す
    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # xとyの属する集合を併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parents[x] = y
            self.size[y] += self.size[x] 
        else:
            self.parents[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # xとyが同じグループに属しているかを判定する
    def same(self, x, y):
        return self.find(x) == self.find(y)

N, Q = map(int, input().split())
uf = UnionFind(N)
for x in range(Q):
    t, u, v = map(int, input().split())
    if t == 0:
        uf.union(u, v)
    elif t == 1:
        if uf.same(u, v):
            print(1)
        else:
            print(0)


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl

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

int main() {
  int N; cin >> N;
  int ans = N;
  FOR(i,ans,1000) {
    if (i % 111 == 0) {
      cout << i;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
typedef long long ll;
ll n,a,b;
ll ans;
int main(){
	cin>>n>>a>>b;
	if((a&1)==(b&1))
		ans=(b-a)>>1;
	else{
		ans=min(n-b,a-1);
		ans+=(b-a)>>1;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import math
import sys

x,y,a,b,c = list(map(int,sys.stdin.readline().split()))
p = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
q = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
r = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
eat=[]

if x<len(p):
    [eat.append(red) for red in p[:x]]
else:
    [eat.append(red) for red in p]
if y<len(q):
    [eat.append(green) for green in q[:y]]
else:
    [eat.append(green) for green in q]
[eat.append(apple) for apple in r]
eat = sorted(eat, reverse=True)
#print(sum(eat[:x + y]))
ans = 0
for taste in eat[:x + y]:
    ans += taste 
print(ans)


Measured memory_bytes: 23768