akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M = inpl()
lines = defaultdict(set)

for _ in range(M):
	a,b,c = inpl()
	a,b = a-1,b-1
	lines[a].add((b,-c))

def BellmanFord(Start,Goal):
	Costs=[INF]*N
	Costs[Start] = 0
	upd8s = [True]*N
	for i in range(N): #N回ループ(高々N-1回で収束する)
		will_upd8s = [False]*N
		upd8 = False
		for s in range(N):
			if not upd8s[s]: continue	#前回更新してないので見ない
			for t,c in lines[s]:
				if c + Costs[s] < Costs[t]:
					Costs[t] = Costs[s]+c
					upd8 = True
					will_upd8s[t] = True #更新した点だけ次に見る

		upd8s = will_upd8s[:]
		if not upd8:
			return Costs[Goal] #なにも更新しなかったら終わり
	else: #負回路の検出(もうN回)
		pc = Costs[Goal]
		for i in range(N):
			upd8 = True
			for s in range(N):
				for t,c in lines[s]:
					if c + Costs[s] < Costs[t]:
						Costs[t] = Costs[s]+c
						upd8 = True
			if not upd8: break

		if pc != Costs[Goal]:
			return -INF
		else:
			return Costs[Goal]

print(-BellmanFord(0,N-1))


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(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, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int n, m;
 
int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	cin >> n >> m;
	cout << (n == m ? "Yes" : "No") << endl;
		
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $M);
$H = array_map('intval', explode(' ', trim(fgets(STDIN))));
$p = array_pad(array(), $N, 1);
for ($i = 0; $i < $M; $i++) {
    fscanf(STDIN, "%d %d", $A, $B);
    if ($H[$A - 1] > $H[$B - 1]) {
        $p[$B - 1] = 0;
    } else if ($H[$A - 1] < $H[$B - 1]) {
        $p[$A - 1] = 0;
    } else if ($H[$A - 1] === $H[$B - 1]) {
        $p[$A - 1] = 0;
        $p[$B - 1] = 0;
    }
    
}
printf("%d", array_sum($p));


Measured memory_bytes: 27104
#include <bits/stdc++.h>
#define dout if(debug) cout
const int maxn = 1e5+1;
typedef long long ll;
using namespace std;
const ll MOD =1e9+7;
int a[1000];
ll dp[19][19];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin>>t;
    while(t--){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        if (a<b){
            cout<<"No\n";
            continue;
        }
        if (b>d){
            cout<<"No\n";
            continue;
        }
        if (c>=b){
            cout<<"Yes\n";
            continue;
        }
        ll k=(a-c)/b;
        if ((a-c)%b==0)
            --k;
        k=max(k,0ll);
        ll z=a-k*b;
        if (z<b){
            cout<<"No\n";
            continue;
        }
        if (d%b==0){
            cout<<"Yes\n";
            continue;
        }
        ll i=(z-c)%b;
        ll j=(d%b);
        ll x=__gcd(j,b);
        ll r=i/x;
        if (i%x==0)
            --r;
        r=max(r,0ll);
        ll mn=i-r*x;
        if (mn<(b-c)%b){
            cout<<"No\n";
        }
        else
            cout<<"Yes\n";

    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int h,w;
  int i,j;

  while(1)
    {

      scanf("%d %d", &h, &w);
      if(h + w == 0)break;

      for(i=1;i<=h;i++)
	{
	  for(j=1;j<=w;j++)
	    {
	      if(i % 2 != 0)
		{
		  if(j % 2 != 0)
		    {
		      printf("#");
		    }
		  else
		    {
		      printf(".");
		    }
		}
	      else
		{
		  if(j % 2 != 0)
		    {
		      printf(".");
		    }
		  else
		    {
		      printf("#");
		    }
		}
	    }   
	  printf("\n");
	}
      printf("\n");
    }
}



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

int main(){
  string s,t;
  cin >>s;
  cin >>t;
  int a,b;
  cin >>a;
  cin >>b;
  
  string u;
  cin >>u;
  
  if(s==u){
  cout << (a-1)<<" "<<b<<endl;
  }
  else{cout<<a<<" "<<b-1<<endl;}
  
  return(0);

}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
cnt = 0
cnt_list = []
for i in range(len(H)-1):
    if H[i] >= H[i+1]:
        cnt += 1
    elif H[i] < H[i+1]:
        cnt_list.append(cnt)
        cnt = 0

cnt_list.append(cnt)

print(max(cnt_list))

Measured memory_bytes: 14252
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = zeros(Int,n)
	b = zeros(Int,n)
	for i in 1:n
		p,q = readline() |> split |> parseMap
		a[i] = p
		b[i] = q
	end
	a = sort(a)
	b = sort(b)
	if n%2==1
		l = a[(n+1)>>1]
		r = b[(n+1)>>1]
		println(r-l+1)
	else
		l = a[n>>1]+a[n>>1+1]
		r = b[n>>1]+b[n>>1+1]
		println(r-l+1)
	end
end

main()

Measured memory_bytes: 211836
#include<iostream>
using namespace std;
int main(){
	long long N,Y;
	cin>>N>>Y;
	if(Y%1000!=0){
		cout<<"-1"<<" "<<"-1"<<" "<<"-1"<<endl;
		return 0;
	}else{
		Y=Y/1000;
		for(int i=0;i<=2000;i++){
			for(int j=0;j<=1000;j++){
				if((5*j+i)>Y){
					continue;
				}
				if( ((Y - (i + j*5)) % 10 == 0 ) ) {
                    if(i + j + ((Y - (i + j*5))/10) == N) {
                        printf("%d %d %d\n",((Y - (i + j*5))/10),j,i);
                        return 0;
                    }
                }
			}
		}
	}
	cout<<"-1"<<" "<<"-1"<<" "<<"-1"<<endl;
	return 0;
}

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

#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
int mod = 24 * 60;

int gt(int t1 , int t2){
   if(t2 >= t1)
      return t2 - t1;
   return mod - t1 + t2;
}
void solve(){
   int h0 , m0 , h1 , m1 , time;
   cin >> h0 >> m0 >> h1 >> m1 >> time;
   int t1 = h0 * 60 + m0 , t2 = h1 * 60 + m1;

   int diff = gt(t1 , t2);
   cout << diff - time << "\n";
}

int main() {
#ifndef ONLINE_JUDGE
#endif
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int t = 1;
//   cin >> t;
   while(t--){
      solve();
   }
}

Measured memory_bytes: 3608
#include<cstdio>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{   int n,i,j,l,m,d;
 long long int s;
 char a[100];
 char b[2][100];
 char c[2][100];
	while(~scanf("%d%s",&m,a))
	{     l=1;
	      int p=2;
	      int k=0;
	    for(i=0;i<m/2;i++)
	    b[l][i]=a[i];
	 for(i=m/2;i<m;i++)
	    {
		c[l][k]=a[i];
		k++;} k--;
	    if(strcmp(b[l],c[1])==0)
	    printf("Yes\n");
	    else
	    printf("No\n");
	    
	}
}

Measured memory_bytes: 256
//Abhinav ---IIIT_A
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i,x,n) for(int i=x;i<(int)n;++i)
ld pie=3.141592653589793238462643383279;
int mod=1e9+7;

struct Edge {
    int a, b, cost;
};

int n, m;
vector<Edge> edges;
const int INF = 1000000000;

void solve()
{
    cin>>n>>m;
    for(int i=0;i<m;++i){
      int A,B,C; cin>>A>>B>>C;
      --A; --B;
      Edge lp; lp.a=A; lp.b=B; lp.cost=C;
      edges.pb(lp);
    }
    vector<int> d(n);
    vector<int> p(n, -1);
    int x;
    for (int i = 0; i < n; ++i) {
        x = -1;
        for (Edge e : edges) {
            if (d[e.a] + e.cost < d[e.b]) {
                d[e.b] = d[e.a] + e.cost;
                p[e.b] = e.a;
                x = e.b;
            }
        }
    }

    if (x == -1) {
        cout << "NO";
    } else {
        for (int i = 0; i < n; ++i)
            x = p[x];

        vector<int> cycle;
        for (int v = x;; v = p[v]) {
            cycle.push_back(v);
            if (v == x && cycle.size() > 1)
                break;
        }
        reverse(cycle.begin(), cycle.end());

        cout << "YES\n";
        for (int v : cycle)
            cout << v << ' ';
        cout << endl;
    }
}
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x,n; cin>>x>>n;
  int a[n]; f(i,0,n) cin>>a[i];
  sort(a,a+n);
  int pos=-1;
  f(i,0,n){
    if(a[i]==x){
      pos=i; break;
    }
  }
  if(pos==-1) cout<<x;
  else{
    int th=x;
    int lp=-1;
    bool fg=0;
    f(i,pos+1,n){
      if((a[i]-a[i-1])>1) {
        fg=1;
        lp=a[i-1]+1;
        break;
      }
    }
    int lp1=-1;
    bool fg1=0;
    for(int i=pos-1;i>=0;--i){
      if((a[i+1]-a[i])>1){
        fg1=1;
        lp1=a[i+1]-1;
        break;
      }
    }
    if(!fg) lp=a[n-1]+1;
    if(!fg1) lp1=a[0]-1;
    if(abs(x-lp1)<=abs(lp-x)) cout<<lp1;
    else cout<<lp; 
  }
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int n,h[105],ans,tmp;
int main(){
	cin>>n>>h[1];
	ans=tmp=h[1];
	for(int i=2;i<=n;i++)
	   {
	   	  cin>>h[i];
	   	  if(h[i]>=tmp)ans+=h[i]-tmp,tmp=h[i];
	   	  else  
	   	  {
	   	  	 
	   	  	 tmp=h[i];
	   	  }
	   }
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
for i in range(N):
    A[i] *= - 1

heapq.heapify(A)

for i in range(M):
    big = (heapq.heappop(A) * -1) // 2
    heapq.heappush(A, big * -1)

print(-sum(A))


Measured memory_bytes: 14180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
int main() {
	ll n,cnt=0;
	cin >> n;
	map<pair<ll, ll>, ll>mp;
	pair<ll, ll>p,pp;
	for (ll i = 1; i <= n; i++) {
		ll head = i / pow(10, getDigit(i)-1);
		ll tail = i % 10;
		p = make_pair(head,tail);
		mp[p]++;
	}
	for (ll i = 1; i <= n; i++) {
		ll head = i / pow(10, getDigit(i)-1);
		ll tail = i % 10;
		pp = make_pair(tail,head);
		cnt += mp[pp];
	}
	cout << cnt << endl;
}

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

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


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int H, A; cin >> H >> A;
    cout << (H + A - 1) / A << 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)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> v(26);
	rep(i,n) v[s[i] - 'a']++;
	ll ans = 0;
	rep(i,n) {
		int c = s[i] - 'a';
		ll temp = 1;
		rep(j, 26) {
			if (j == c) v[j]--;
			else {
				temp = temp * (v[j] + 1);
				temp %= MOD;
			}
		}
		ans += temp;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>


using namespace std;

string s;
int dt[30], j=0;

pair<char, int> dfs(){
	// printf("j: %d\n", j);
	int v1, v2;
	char a1, a2;
	
	j++;
	
	if (s[j]=='['){
		pair<char, int> ret;
		ret = dfs();
		a1 = ret.first;
		v1 = ret.second;
		if (v1<0){
			return make_pair('0', -1);
		} 
	}else{
		a1 = s[j];
		v1 = dt[a1-'a'];
	}
	
	j++;
	j++;
	
	if (s[j]=='['){
		pair<char, int> ret;
		ret = dfs();
		a2 = ret.first;
		v2 = ret.second;
		if (v2<0){
			return make_pair('0', -1);
		}
	}else{
		a2 = s[j];
		v2 = dt[a2-'a'];
	}
	
	j++;
	
	// printf("1: (%c, %d) 2: (%c, %d)\n", a1, v1, a2, v2);
	
	if (v1==0){
		return make_pair(a2, v2-1);
	}else if (v2==0){
		return make_pair(a1, v1-1);
	}else{
		return make_pair('0', -1);
	}
}

int main(){
	char letter;
	int v;
	cin >> s;
	scanf("%*c");
	while(1){
		if (scanf("%c%*c%d%*c", &letter, &v)==EOF){
			break;
		}
		dt[letter - 'a'] = v;
		// printf("letter[%d] = %d\n", letter - 'a', v);
	}
	pair<char, int> ret;
	ret = dfs();
	cout << (ret.second==0 ? "Yes" : "No") << endl;
	
	
	return 0;
}


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

int main(){
  int h,w,m,b,bb;
  cin >> h >> w >> m;
  map<pair<int,int>,bool>a;
  map<int,int>tate;
  map<int,int>yoko;
  for(int i=0;i<m;i++){
    cin >> b >> bb;
    a[make_pair(b-1,bb-1)]=true;
    tate[b-1]++;
    yoko[bb-1]++;
  }
  b=0,bb=0;
  set<int>mh;
  set<int>mw;
  for(auto x:tate)
    b=max(b,x.second);
  for(auto x:tate)
    if(x.second==b)
      mh.insert(x.first);
  for(auto x:yoko)
    bb=max(bb,x.second);
  for(auto x:yoko)
    if(x.second==bb)
      mw.insert(x.first);
  bool ok=false;
  for(auto x:mh){
    for(auto y:mw){
      if(!a[make_pair(x,y)]){
        ok=true;
        break;
      }
    }
    if(ok)
      break;
  }
  cout << b+bb-(ok?0:1) << endl;
  return 0;
}

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

int N;
long long int A[10010];

long long int max(){
    long long int max = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] > max){
            max = A[i];
        }
    }
    return max;
}

long long int sum(){
    long long int sum = 0;
    for (int i = 0; i < N; i++){
        sum += A[i];
    }
    return sum;
}

long long int min(){
    long long int min = A[0];
    for (int i = 1; i < N; i++){
        if (A[i] < min){
            min = A[i];
        }
    }
    return min;
}

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    cout << min() << ' ' << max() << ' ' << sum() << endl;
}

Measured memory_bytes: 3152
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}
	if n <= k {
		fmt.Println("0")
		return
	}
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))
	sum := 0
	for j := k; j < n; j++ {
		sum += nums[j]
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5504
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn = 2e5+55;
#define LL long long
LL a[maxn];
int n;
LL f(LL x)
{
	LL ans=0;
	for(int i=1;i<=n;i++){
		ans+=1LL*abs(a[i]-x);
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]-=i;
	}
	sort(a+1,a+1+n);
	LL ans=1e16;
	ans=min(ans,f(a[n/2+1]));
	printf("%lld\n",ans);

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> cmp(n);
  rep(i, n) {
    cin >> p[i];
    cmp[i] = p[i];
  }
  sort(p.begin(), p.end());
  int cnt = 0;
  rep(i, n) {
    if(cmp[i] != p[i]) cnt++;
  }
  bool flag = false;
  if(cnt <= 2) flag = true;
  
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
}
  

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> g(n,0);
    vector<ll> p(n,0);
    g.at(0) = 1;
    for(i = 1;i < n;++i){
        if(s.at(i) == 'g'){
            g.at(i) = g.at(i-1)+1;
            p.at(i) = p.at(i-1);
        }else{
            g.at(i) = g.at(i-1);
            p.at(i) = p.at(i-1)+1;
        }
    }
    ll tmp = 1e9;
    ll ans = 0;
    for(i = n-1;i >= 0;--i){
        tmp = min(tmp, (g.at(i) - p.at(i))/2);
        if(tmp > 0 && s.at(i) == 'g'){
            ++ans;  --tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int a, b;
  cin >> a >> b;
  int d = max(a,b);
  int c = min(a,b);
  int e = c;
  for (int i = 0; i < d-1; i++){
    e = e * 10 + c;
  }
  cout << e;
}

Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
 
int main(){
    long long int a,b,c;
    cin >> a >> b >> c;
    long long d = c - a - b;
    if(d > 0 and d * d > 4 * a * b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            int n = ReadAndParseInt();
            int[] arr = { 64, 32, 16, 8, 4, 2, 1 };
            for(int i=0;i<arr.Length;++i)
            {
                int d = arr[i];
                if( d <= n)
                {
                    Console.WriteLine(d);
                    return;
                }
            }
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<math.h>
int main()
{
	double  n,m;
	scanf("%lf %lf",&n,&m);
	if(2*n<=m){
	n=(2*n+m)/4;
	printf("%.0lf\n",floor(n));
	}
	else
	printf("%.0lf\n",floor(m/2));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
const int MAXN = 1024;

//OPERATORS


//GLOBALS


//FUNCTIONS

ll arr[100000];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,w; cin >> n >> w;
	memset(arr,0,sizeof(arr));
	vector<ll> pesos(n,0);
	vector<ll> costo(n,0);
	for(int i = 0; i < n; i++){
		cin >> pesos[i] >> costo[i];
	}
	
	
	for(int j = 0; j < n; j++){
			for(int i = w; i >= 0 ; i--){
			if(pesos[j] <= i){
				arr[i] = max(arr[i], arr[i-pesos[j]] + costo[j]);
			}
		}
	}
	
	
	cout << arr[w]  << endl;


	return 0;
}


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

using namespace std;

using ll = long long;

struct UnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;

    UnionFind(int sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -data[find(x)];
    }
};

struct Edge {
    int u;
    int v;
    ll w;

    bool operator<(const Edge& e) const {
        return w < e.w;
    }
};

void merge(int a, int b, UnionFind& uf, vector<int>& v) {
    int r1 = uf.find(a), r2 = uf.find(b);
    uf.unite(a, b);
    int r = uf.find(a);
    if (r == r1) {
        v[r] += v[r2];
        v[r2] = 0;
    } else {
        v[r] += v[r1];
        v[r1] = 0;
    }
}

void merge2(int a, int b, UnionFind& uf, vector<int>& v, vector<int>& vv) {
    int r1 = uf.find(a), r2 = uf.find(b);
    uf.unite(a, b);
    int r = uf.find(a);
    if (r == r1) {
        v[r] += v[r2];
        vv[r] += vv[r2];
        v[r2] = 0;
        vv[r2] = 0;
    } else {
        v[r] += v[r1];
        vv[r] += vv[r1];
        v[r1] = 0;
        vv[r1] = 0;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, K;
    cin >> n >> m >> K;
    vector<int> c(n);
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }

    vector<Edge> es;
    for (int i = 0; i < m; i++) {
        int a, b;
        ll w;
        cin >> a >> b >> w;
        a--; b--;
        es.push_back((Edge){a, b, w});
    }
    sort(es.begin(), es.end());

    UnionFind uf(n + K);
    for (int i = 0; i < n; i++) {
        if (c[i] == -1) continue;
        uf.unite(i, n + c[i]);
    }
    int comp_num = K;
    ll ans = 0;
    bool ok = false;
    for (Edge& e : es) {
        if (uf.same(e.u, e.v)) continue;
        if (c[e.u] == -1 || c[e.v] == -1) {
            comp_num--;
            uf.unite(e.u, e.v);
        } else {
            if (uf.same(c[e.u] + n, c[e.v] + n)) continue;
            comp_num--;
            uf.unite(c[e.u] + n, c[e.v] + n);
        }
        ans += e.w;
        if (comp_num == 1) {
            ok = true;
            break;
        }
    }
    cout << (ok ? ans : -1) << endl;
    return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
int a[105];
int n,ans;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    cin>>a[i];
    
    sort(a,a+n+1);
    for (int i=1;i<=n;i++)
    if (a[i]!=a[i-1])
    ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    n = ii()
    d = [[0] * 10 for _ in range(10)]
    for i in range(1, n+1):
        a_str = str(i)
        d[int(a_str[0])][int(a_str[-1])] += 1
    cnt = 0
    for i in range(1, n+1):
        b_str = str(i)
        cnt += d[int(b_str[-1])][int(b_str[0])]
    print(cnt)
        


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {

    let op: String = read();
    let num: i32 = op.parse::<i32>().unwrap();;
    let iter = op.chars();

    let mut div : i32 = 0;

    for c in iter {
        div += c.to_string().parse::<i32>().unwrap();
    }

    if num % div == 0 {
        println!("Yes");
    } else {
        println!("No");
    }

}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const int DAY   = 86400;
const int EARLY = 10800;

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

    int t = 0;
    vector<int> cnt(DAY, 0);
    for(int i=0; i<n; ++i){
        t += a[i];
        t %= DAY;
        ++ cnt[t];
        t += b[i];
        t %= DAY;
    }

    int sum = accumulate(cnt.begin(), cnt.begin() + EARLY, 0);
    int ans = 0;
    for(int i=0; i<DAY; ++i){
        sum += cnt[(EARLY+i)%DAY];
        ans = max(ans, sum);
        sum -= cnt[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9

int main()
{
    int r;
    cin >> r;
    float ans=6.283*r;
    cout <<ans<< endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    bool flag = true;
    rep(i,s.size()) {
        if (s[i] != t[i]) flag = false;
    }
    if (flag) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3628
import Control.Applicative
import Control.Monad

diff :: [Int] -> Int
diff xs = last xs - head xs


solver :: [[Int]] -> Int -> Int
solver xs t = t - sum (map diff xs)


main :: IO()
main = do
  t <- (read :: String -> Int) <$> getLine
  unless (t == 0) $ do
    n <- (read :: String -> Int) <$> getLine
    s <- map (map (read :: String -> Int) . words) <$> replicateM n getLine
    let y = solver s t
    if y <= 0
      then putStrLn "OK"
      else print y
    main

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;


int n,a;
int x[51];
ll dp[51][3000][51]; //dp[i][j][k]=a i番目までの数でkこ使って合計jにする通りが何通りか
int main(){
  cin>>n>>a;
  rep(i,n)cin>>x[i];

  //初めの一個
  dp[0][x[0]][1]=1;
  dp[0][0][0]=1;

  for(int i=1;i<n;i++){
    for(int j=0;j<3000;j++){

      for(int k=0;k<51;k++){
        dp[i][j][k]+=dp[i-1][j][k];
        dp[i][j+x[i]][k+1]+=dp[i-1][j][k];
      }


    }
  }

  ll ans=0;
  rep(k,n+1)rep(j,3000){

    if(k!=0&&j/k==a&&j%k==0){
      // dump(k);
      // dump(dp[n-1][j][k]);
      ans+=dp[n-1][j][k];
    }
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 58880
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * https://abc046.contest.atcoder.jp/tasks/abc046_a
 */
public class Main {

	public static void main(String[] args) {
		
		Set<Integer> set = new HashSet<>();
		Scanner sc = new Scanner(System.in);
		set.add(sc.nextInt());
		set.add(sc.nextInt());
		set.add(sc.nextInt());
		sc.close();
		
		System.out.println(set.size());

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	ll a,b;
   	cin >> a >> b;
   	if(a%b) cout << a;
   	else cout << -1;
   	cout << "\n";
    return 0;
}



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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < max(a, b); i++) cout << min(a, b);
    return 0;
}

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

int main()
{
	int n, m; cin >> n >> m;
	vector<int> x(m); for (int i = 0; i < m; i++) cin >> x[i];

	if (m <= n) {
		cout << 0 << endl;
		return 0;
	}

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

	int allLength = x[m - 1] - x[0];

	vector<int> l(m); 
	for (int i = 0; i < m - 1; i++) {
		l[i] = x[i + 1] - x[i];
	}

	sort(l.begin(), l.end(), greater<int>());

	int sum = 0;
	for (int i = 0; i < n - 1; i++) sum += l[i];

	cout << allLength - sum << endl;

	return 0;
}

Measured memory_bytes: 1024
class Solver(object):
    def __init__(self):
        self.n = int(input())
        self.a_s = list(map(int, input().split(" ")))
        self._sadness = {}

    def solve(self):
        array = self.a_s.copy()
        for i in range(self.n):
            array[i] -= i + 1
        array.sort()
        b = array[len(array) // 2]
        print(self.sadness(b))
        
    def sadness(self, b):
        if b not in self._sadness:
            self._sadness[b] = sum(abs(self.a_s[i] - (b+i+1)) for i in range(self.n))
        return self._sadness[b]


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 25708
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#define pb push_back

using namespace std;
int hako[6][6][6];
int tmp[6][6][6];
int m1,m2;
vector<int> a,b;

int cal(int x,int y,int z){
  int i,j,k;
  int num=0;
  for(k=1;k>=-1;k--){
    for(i=1;i>=-1;i--){
      for(j=1;j>=-1;j--){
        if(x+i<0||x+i>4||y+j<0||y+j>4||(i==0&&j==0&&k==0))continue;
        if(hako[x+i][y+j][z+k]==1) num++;
      }
    }
  }
  return num;
}

void sim(int n){
  int i,j,k,l,r;
  int num=0;
  for(l=0;l<n;l++){
    for(k=0;k<5;k++){
      for(i=0;i<5;i++){
        for(j=0;j<5;j++){
          num=cal(i,j,k);
          if(hako[i][j][k]==0){
            tmp[i][j][k]=0;
            for(r=0;r<a.size();r++){
              if(num==a[r]) tmp[i][j][k]=1;
            }
          }
          else{
            tmp[i][j][k]=0;
            for(r=0;r<b.size();r++){
              if(num==b[r]) tmp[i][j][k]=1;
            }
          }
        }
      }
    }
    for(k=0;k<5;k++) for(i=0;i<5;i++) for(j=0;j<5;j++) hako[i][j][k]=tmp[i][j][k];
  }
}

int main(){
  int i,j,k,n,t;
  string s;
  int c=1;
  while(cin>>n,n){
    for(i=0;i<5;i++){
      for(j=0;j<5;j++){
        for(k=0;k<5;k++){
          hako[i][j][k]=0;
        }
      }
    }
    for(k=0;k<5;k++){
      for(i=0;i<5;i++){
        cin>>s;
        for(j=0;j<s.size();j++){
          if(s[j]=='1') hako[i][j][k]=1;
        }
      }
    }
    a.clear();
    b.clear();

    cin>>m1;                   
    for(i=0;i<m1;i++){
      cin>>t;
      a.pb(t);
    }
    cin>>m2;
    for(i=0;i<m2;i++){
      cin>>t;
      b.pb(t);
    }
    
    sim(n);
    /* cout<<"Case "<<c<<":"<<endl; */
    if(c!=1) printf("\n");
    printf("Case %d:\n",c);
    for(k=0;k<5;k++){
      for(i=0;i<5;i++){
        for(j=0;j<5;j++){
          printf("%d",hako[i][j][k]);
          /* cout<<hako[i][j][k]; */
        }
        printf("\n");
      }
      if(k!=4) printf("\n");
    }    
    c++;
  }
  return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define MAX 100000

struct Queue {
    char name[10];
    int time;
};

Queue Q[MAX];
int n; // nunber of queue
int t; // time for subtracting
int head, tail;

void enqueue(Queue q) {
    Q[tail] = q;
    tail = (tail + 1) % MAX;
}

Queue dequeue() {
    Queue x = Q[head];
    head = (head + 1) % MAX;
    return x;
}

int main() {
    int elapsed = 0; int c = 0;
    scanf("%d %d", &n, &t);
    
    for (int i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].time);
    }
    
    // simulation starts from here
    head = 1;
    tail = n+1;
    while (head != tail) {
        Queue tmp_q = dequeue(); // ??????Q????????????????????????
        c = std::min(tmp_q.time, t);
        tmp_q.time -= c;
        elapsed += c;
        if (tmp_q.time > 0) enqueue(tmp_q);
        else {
            printf("%s %d\n", tmp_q.name, elapsed);
        }
    }
    
    return 0;
}

Measured memory_bytes: 4704
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
if(b >= 100 ) a *= 1000;
else if (b >= 10 ) a *= 100;
else a *= 10;
a = a + b;
for(int i=1; i<320 ; i++){
  if(i*i == a) {
    a = -1;
    break;
   }
}//for
if (a == -1) System.out.print("Yes");
else         System.out.print("No");
}//main
}//Main

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

int main()
{
    string str;
    string STR;
    int i, len;
    char ch;
 
        getline(cin, str);

        STR = "";

        if ((len = str.length()) < 1200) {
           for (i = 0; i < len; i++) {
               ch = str.at(i);
               if (isalpha(static_cast<unsigned char>(ch))) {
                   if(isupper(ch)) {
                   STR += tolower(ch);
                   } else {
                    STR += toupper(ch);
                   } 
               } else {
                   STR += ch;
               }
           }
        }

        cout << STR << endl;
    
     return 0;
}


Measured memory_bytes: 3164
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int d[] = new int[N];
        for (int i=0; i<N; i++) {
            d[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        long sum = 0L;

        for (int i=0; i<N-1; i++) {
            for(int j=i+1; j<N; j++) {
                sum += d[i] * d[j];
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(sum);
        out.flush();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int d,n;
  cin>>d>>n;
  if(d==0){
    if(n==100)cout<<101<<endl;
    else cout<<n<<endl;
  }else if(d==1){
    if(n==100)cout<<(n+1)*100<<endl;
    else cout<<n*100<<endl;
  }else {
    if(n==100)cout<<(n+1)*10000<<endl;
    else cout<<n*10000<<endl;
  }
  return 0;
}

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


#define ll unsigned long long
#define ALL(x) x.begin(),x.end()

#define FASTIO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
const int MOD = 1e9+7;
const int maxn = static_cast<int>(1e5+3);


ll power(ll x, ll int y){
    int res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x + MOD)%MOD;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%MOD; // Change x to x^2
    }
    return res;
}
int arr[maxn];

int main(){

    int k,s;cin >> k >> s;
    ll ans = 0;
    for(int i=0;i<=k;i++){
        
        for(int j=0;j<=k;j++){
        
            if(s - i - j >= 0 && s - i - j <= k) ++ans;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    static long MOD = 1000000007;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] ok = new boolean[n + 1];
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            ok[x] = true;
        }
        long[] s = new long[n + 1];
        s[0] = 1;
        s[1] = 1;
        for (int i = 1; i <= n; i++) {
            if (i == 1) {
                if (ok[i]) {
                    s[i] = 0;
                }
                continue;
            }
            if (ok[i]) {
                s[i] = 0;
                continue;
            }
            s[i] = s[i - 2] + s[i - 1];
            s[i] %= MOD;
        }
        System.out.println(s[n]);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    int n = S.size();
    int ans = n;
    for (int k = 0; k+1 < n; ++k)
    {
        if (S[k] != S[k+1])
            ans = min(ans, max(k+1, n - (k+1)));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

int main() {
  //freopen("input.txt", "r", stdin);

  int D, G;
  cin >> D >> G;
  ll problems[D];
  ll bonuses[D];

  for (int i = 0; i < D; i++) {
    cin >> problems[i];
    cin >> bonuses[i];
  }

  // まずどの問題のボーナスポイントをとるか決める
  // 2^D通りある
  ll ans = 1<<29;
  for (int bit = 0; bit < (1 << D); bit++) {
    ll sum = 0, num = 0;
    for (int i = 0; i < D; i++) {
      // bitがたっていたら全部解く
      if (bit & (1 << i)) {
        sum += problems[i] * 100 * (i + 1) + bonuses[i];
        num += problems[i];
      }
    }

    if (sum >= G) {
      ans = min(ans, num);
    } else {
      // まだ目標に届いていない場合は貪欲に
      for (int i = D - 1; i >= 0; i--) {
        if (bit & (1 << i)) continue;
        for (int j = 0; j < problems[i]; j++) {
          if (sum >= G) {
            break;
          }
          sum += (i + 1) * 100;
          num++;
        }
      }

      ans = min(ans, num);
    }
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 256
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

ma = max(a for a, b in ab)
dp = [0] * (h+ma)

for i in range(1, h+ma):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(min(dp[h:h+ma]))

Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<queue>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;

int cnt[100][300];
int main() {
  int n;
  cin >> n;
  rep(i,n) {
    string s;
    cin >> s;
    rep(j,(int)s.size()) ++cnt[i][s[j]];
  }
  string ans = "";
  vector<int> vec(26,INT_MAX);
  rep(i,n) {
    rep(j,26) vec[j] = min(vec[j],cnt[i]['a'+j]);
  }
  rep(i,26) {
    if( vec[i] == INT_MAX ) continue;
    ans += string(vec[i],'a'+i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  ll n,k; cin >> n >> k;
  vector<ll> M, P;
  ll zero = 0;
  loop(i,0,n) {
    ll a; cin >> a;
    if (a == 0) zero++;
    else if (a < 0) M.push_back(a);
    else P.push_back(a);
  }
  sort(M.begin(), M.end());
  sort(P.begin(), P.end());
  ll m = M.size(), p = P.size();

  if (k <= m*p) {
    auto f = [&](ll x) {
      ll num = 0;
      // ある正整数P[i]に対して、積がx以下となるような相方の数を見つける
      // Mは昇順なので、左の方が積が大きい.
      // 満たさない箇所が一度出ればそれ以降はすべて満たさない
      // i.e. 2で満たさないとする
      // 1  1  2  2  3
      //   ok ng
      // 2個
      loop(i,0,p) {
        ll ok = -1, ng = m;
        while (ok + 1 < ng) {
          ll mid = (ok+ng)>>1;
          if (P[i]*M[mid]<=x) ok = mid;
          else ng = mid;
        }
        num += ng;
      }
      return num < k;
    };

    // f(x) := ペアの積がx以下であるペアの個数がk未満
    ll ng = -1000000000000000001, ok = 1000000000000000001;
    while (ng+1<ok) {
      ll mid = (ng+ok)>>1;
      if (f(mid)) ng = mid; // k未満の場合足りないので緩める
      else ok = mid; // k以上なので余裕があるかもしれないので厳しく
    }
    // okは、あと1でも引いたらk個未満になってしまうような最小のペアの積の値
    // 1引いてngになってしまうということはok自身ペアの積としてありうる整数ということ
    // つまり、解として有効
    cout << ok << endl;
    return 0;
  }

  k -= m*p;

  ll numZero = zero ? zero*(zero-1)/2 : 0;
  numZero += zero * (m+p);
  if (k <= numZero) {
    cout << 0 << endl;
    return 0;
  }

  k -= numZero;

  // 初めて満たさないインデックス = 満たす個数 としたい
  // これがないと個数=M.size()-i-1みたいになる
  reverse(M.begin(), M.end());

  auto f = [&](ll x) {
    ll num = 0;
    // 各正整数に対して、ペアに出来る正整数の数を求める.
    // ただし、自分自身とは組めないので範囲に自身も含まれる場合は-1
    // (i,j) (j,i)の両方をカウントしているので最後に2で割る.
    loop(i,0,p) {
      ll ok = -1, ng = p;
      while (ok + 1 < ng) {
        ll mid = (ok+ng)>>1;
        if (P[i]*P[mid]<=x) ok = mid;
        else ng = mid;
      }
      if (i < ng) ng--;
      num += ng;
    }
    loop(i,0,m) {
      ll ok = -1, ng = m;
      while (ok + 1 < ng) {
        ll mid = (ok+ng)>>1;
        if (M[i]*M[mid]<=x) ok = mid;
        else ng = mid;
      }
      if (i < ng) ng--;
      num += ng;
    }
    return (num>>1) < k;
  };

  ll ng = -1000000000000000001, ok = 1000000000000000001;
  while (ng+1<ok) {
    ll mid = (ng+ok)>>1;
    if (f(mid)) ng = mid;
    else ok = mid;
  }
  cout << ok << endl;
  return 0;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mp ;

int main()
{
    ll n, x, q, a, b, val, sum = 0, cnt ;
    cin >> n ;
    for (int i = 0; i < n; i++) {
        cin >> x ;
        mp[x]++ ;
        sum += x ;
    }
    cin >> q ;
    for (int i = 0; i < q; i++) {
        cin >> a >> b ;
        cnt = mp[a] ;
        val = a * cnt ;
        mp[a] = 0 ;
        sum -= val ;
        val = b * cnt ;
        sum += val ;
        mp[b] += cnt ;
        printf("%lld\n", sum) ;
    }

    return 0 ;
}


Measured memory_bytes: 9648