akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int h[ 100010 ];

int main()
{
int i;
int j;
int K;
int N;
int iMin;
int X;

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

	cin >> N;
	cin >> K;

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

	sort( h, h + N );

	iMin = 1000000000;
	for( i = 0; ; i++ )
	{
		j = i + K - 1;
		if( j >= N ) break;

		X = h[ j ] - h[ i ];
		if( iMin > X ) iMin = X;
	}

	cout << iMin << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
int n, h[100] = {};
int nn(int hh)
{
  int ans = 0;
  bool is = false, be = false;
  for(int i = 0; i != n; i++){
    if(h[i] >= hh){
      if(!is){
        ans++;
        is = true;
      }
      if(be) be = false;
    }else{
      if(is) be = true;
      is = false;
    }
  }
  return ans;
}
int main(void)
{
  int maxh = 0, ans = 0;
  std::cin >> n;
  for(int i = 0; i != n; i++){
    std::cin >> h[i];
    maxh = std::max(maxh, h[i]);
  }
  for(int hh = 1; hh <= maxh; hh++) ans += nn(hh);
  std::cout << ans << std::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 rep2(i, a, b) for(int i = (a); i < (b); i++)
typedef long long ll;

int main() {
   int a, b, c, k;
   cin >> a >> b >> c >> k;

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

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		ll n, ans = 0;
		cin >> n;
		for (ll i = 1; i <= n; i++) {
			ans += (n / i);
			if (n % i == 0) ans--;
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define st first
#define nd second
 
string a,b;
char sonuc[3005];
int p[3005][3005];//[hangiurun][value] = minweight

int dp(int i, int j){
    if(p[i][j] != -1) return p[i][j];
    if(i == 0 || j == 0) {
        return 0;
    }
    if(a[i-1] == b[j-1]) {
        p[i][j] = 1+dp(i-1, j-1);
        return p[i][j];
    }
    p[i][j] = max(dp(i,j-1), dp(i-1, j));
    return p[i][j];
}   

int32_t main() {
	ios_base::sync_with_stdio(0);
    memset(p, -1, sizeof(p));
    cin >> a >> b;
    int k = dp(a.length(), b.length());
    int u = k;
    int i = a.length();
    int j = b.length();
    while(j > 0 && i > 0){
        if(a[i-1] == b[j-1]){
            sonuc[k-1] = a[i-1];
            i--;
            j--;
            k--;
        }
        else if(p[i][j] == p[i][j-1]){
            j--;
        }
        else{
            i--;
        }
    }
    for (int i = 0; i < u; i++)
    {
        cout << sonuc[i];
    }
    cout << endl;
}

Measured memory_bytes: 74452
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }

ll MOD = 1000000007;

int main(void){
  int n; 
  double d;
  cin >> n >> d;
  double x[n],y[n],dis[n];
  int count = 0;
  rep(i,n){
    cin >> x[i] >> y[i];
    dis[i] = sqrt(x[i]*x[i]+y[i]*y[i]);
    if(dis[i] <= d) count++;
  }
  cout << count << endl;
  return 0; 
}


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

int main(){
  char X,Y;
  int x,y;
  cin>>X>>Y;
  if(X=='A') x=10;
  if(X=='B') x=11;
  if(X=='C') x=12;
  if(X=='D') x=13;
  if(X=='E') x=14;
  if(X=='F') x=15;
  if(Y=='A') y=10;
  if(Y=='B') y=11;
  if(Y=='C') y=12;
  if(Y=='D') y=13;
  if(Y=='E') y=14;
  if(Y=='F') y=15;
  if(x>y)cout<<">"<<endl;
  else if(x<y)cout<<"<"<<endl;
  else cout<<"="<<endl;
}


Measured memory_bytes: 256
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);


using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 1000001;
const int mod = 1e9 + 7;


int main(){
    int n, m;
    cin>>n>>m;
    int verdict[n+1];
    fill(verdict, verdict+n+1, 0);

    int penality = 0, ac = 0;

    fr(i,m){
        int p;
        string s;
        cin>>p>>s;
        if(verdict[p] != -1){
            if(s == "AC")penality += verdict[p], verdict[p] = -1, ++ac;
            else ++verdict[p];
        }
    }
    cout<< ac <<' '<<penality << endl;
}


Measured memory_bytes: 640
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad (replicateM)
import           Data.List     (nub)
main :: IO ()
main = print =<< solve <$> getInput

getInput :: IO [Int]
getInput = do
  n <- readLn
  replicateM n readLn

solve :: [Int] -> Int
solve = length . nub


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

using namespace std;

int main()
{
	int n,fib[45];
	fib[0]=fib[1]=1;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		fib[i]=fib[i-1]+fib[i-2];
	printf("%d\n",fib[n]);
	return 0; 
}

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

using namespace std;

int ans[100009][2];
int main() {
    int n, x;
    cin >> n;

    ans[1][0] = 1;
    ans[1][1] = 1;
    cin >> x;
    int prev = x;

    for (int i = 2; i <= n; i ++) {
        cin >> x;
        if (prev > x) {
            ans[i][1] = min(ans[i - 1][1], ans[i - 1][0] + 1);
            ans[i][0] = min(ans[i - 1][0], ans[i - 1][1]) + 1;
        }
        else if (prev < x) {
            ans[i][0] = min(ans[i - 1][1] + 1, ans[i - 1][0]);
            ans[i][1] = min(ans[i - 1][0], ans[i - 1][1]) + 1;
        } else {
            ans[i][0] = ans[i - 1][0];
            ans[i][1] = ans[i - 1][1];
        }
        prev = x;
    }
    cout << min(ans[n][0], ans[n][1]) << endl;
}


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

int main (){
    int N, total = 0, flag = 0;

    cin >> N;

    int A[N];

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

    while(1){

        for(int i = 0; i < N; i++){
            if(A[i] % 2 == 1){
                flag = 1;
            }
            else{
                A[i] /= 2;
            }
        }

        if(flag == 1){
            break;
        }
        total++;
    }

    cout << total <<endl;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int a, b, c;
	cin >> a >> b >>c;
	cout << max(0, b + c - a);
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const long long INF = 1001001001;
const long long MOD = 1000000007;
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    int cnt=0;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')cnt=3;
    else if(s[0]=='R'&&s[1]=='R'||s[1]=='R'&&s[2]=='R')cnt=2;
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R')cnt=1;
    cout<<cnt<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	string tmp[4] = { "dream", "dreamer", "erase", "eraser" };
	reverse(s.begin(), s.end());
	for (int i = 0; i < 4; i++) reverse(tmp[i].begin(), tmp[i].end());
	bool ok = true;
	for (int i = 0; i < s.size();) {
		bool can = false;
		for (int j = 0; j < 4; j++) {
			string d = tmp[j];
			if (s.substr(i, d.size()) == d) {
				can = true;
				i += d.size();
			}
		}
		if (!can) {
			ok = false;
			break;
		}
	}
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import itertools

N = int(input())

# 各index i と n に対して、左側にn以下のblack/whiteがいくつあるかを数える
# とりあえず1を入れて、あとでcumsum

B_pos = [0] * (N+1)
W_pos = [0] * (N+1)
B_cnt = [[0] * (N+1) for _ in range(2*N)]
W_cnt = [[0] * (N+1) for _ in range(2*N)]

for i in range(2*N):
    c,a = input().split()
    a = int(a) # 0-index化
    if c == 'B':
        B_pos[a] = i
    else:
        W_pos[a] = i
for i in range(1,N+1):
    B_cnt[B_pos[i]][i] += 1
    W_cnt[W_pos[i]][i] += 1
# cumsum
for i in range(1,2*N):
    for j in range(N+1):
        B_cnt[i][j] += B_cnt[i-1][j]
        W_cnt[i][j] += W_cnt[i-1][j]
for i in range(2*N):
    for j in range(1,N+1):
        B_cnt[i][j] += B_cnt[i][j-1]
        W_cnt[i][j] += W_cnt[i][j-1]

B_cnt

W_cnt

# Bi,Wj まで並べるためのコスト
dp = [[0] * (N+1) for _ in range(N+1)]

INF = 1 << 50
for b in range(N+1):
    rng_w = range(N+1) if b else range(1,N+1)
    for w in rng_w:
        p = B_pos[b]
        q = W_pos[w]
        x1,x2 = INF,INF
        if b >= 1:
            x1 = dp[b-1][w] + (p - B_cnt[p][b-1] - W_cnt[p][w])
        if w >= 1:
            x2 = dp[b][w-1] + (q - W_cnt[q][w-1] - B_cnt[q][b])
        dp[b][w] = x1 if x1 < x2 else x2

answer = dp[N][N]
print(answer)

Measured memory_bytes: 194056
#include <stdio.h>
typedef long long int ll;
const int N=1e5+10;
int n,a[N];
ll find(ll x){
    ll ans=0,now=0;
    int last=0;
    for(int i=0;i<n;i++){
        now+=a[i];
        while(now>x)now-=a[last++];
        ans+=i-last+1;
    }
    return ans;
}
int main(){
    int q;
    ll x;
    scanf("%d%d",&n,&q);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    while(q--){
        scanf("%lld",&x);
        printf("%lld\n",find(x));
    }
}


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

using namespace std;


int main(void) {
	string S,T;
	cin >> S;
	cin >> T;
	int ans = 0;
	for (int i = 0; i < S.size();i++) {
		if (S[i] != T[i]) ans++;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3464
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

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


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

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MOD = 998244353;

int mul(int a , int b) {
    return a * 1ll * b % MOD;
}

int add (int a , int b) {
    a += b;
    while (a >= MOD) a -= MOD;
    while (a < 0) a += MOD;
    return a;
}

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

    int n;
    cin >> n;

    vector<int> r(n) , c(n) , power(n + 1);
    vector<array<int , 2> > p(n);
    vector<array<int , 4> > ans(n);

    power[0] = 1;
    for (int i = 0 ;i < n ;i++) {
        cin >> r[i] >> c[i];
        p[i] = {r[i] , c[i]};
        power[i + 1] = mul(power[i] , 2);
    }

    vector<int> ind(n);
    iota(ind.begin() , ind.end() , 0);

    sort(ind.begin() , ind.end() , [&](int i , int j) {
       return p[i][0] < p[j][0];
    });


    sort(r.begin() , r.end());
    r.resize(unique(r.begin() , r.end()) - r.begin());

    Tree<int> os;
    int j = 0;
    for (int i = 0 ;i < r.size() ;i++) {
        int st = j;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            os.insert(p[ind[j]][1]);
            j++;
        }

        j = st;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            int lf = os.order_of_key(p[ind[j]][1] + 1);
            int rt = os.size() - os.order_of_key(p[ind[j]][1]);
            ans[ind[j]][2] = lf - 1;
            ans[ind[j]][0] = rt - 1;
            j++;
        }
    }


    sort(ind.begin() , ind.end() , [&](int i , int j) {
        return p[i][0] > p[j][0];
    });


    reverse(r.begin() , r.end());
    os.clear();

    j = 0;
    for (int i = 0 ;i < r.size() ;i++) {
        int st = j;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            os.insert(p[ind[j]][1]);
            j++;
        }

        j = st;
        while (j < ind.size() && p[ind[j]][0] == r[i]) {
            int lf = os.order_of_key(p[ind[j]][1] + 1);
            int rt = os.size() - os.order_of_key(p[ind[j]][1]);
            ans[ind[j]][3] = lf - 1;
            ans[ind[j]][1] = rt - 1;
            j++;
        }
    }

    int res = mul(n , power[n - 1]);
    for (int i = 0 ;i < n ;i++) {
        int a = ans[i][0] , b = ans[i][1];
        int c = ans[i][2] , d = ans[i][3];

        int f = mul(power[a] - 1 , power[d] - 1);
        f = mul(f , power[n - a - d - 1]);
        int s = mul(power[b] - 1 , power[c] - 1);
        s = mul(s , power[n - b - c - 1]);
        int sub = mul(power[a] - 1 , power[b] - 1);
        sub = mul(sub , mul(power[c] - 1 , power[d] - 1));
        res = add(res , add(add(f , s) , -sub));
    }

    cout << res;
}

Measured memory_bytes: 17408
//Bokann ga bokka--nn!!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
map<P,int>ma;
int f[15][15];
int linkk[15][15];
//int dp[(1<<23)][24]={};
P za[25];
int n,m;
int val;
int calc(int mask,int cur)
{
	int ret=0;
	//if(dp[mask][cur]) return dp[mask][cur];
	int x=za[cur].first;
	int y=za[cur].second;
	if(mask==(1<<val)-1)
	{
		if(x==za[23].first || y==za[23].second) return 1;
		else return 0;
	}
	for(int i=x-1;i>=0;i--)
	{
		int s=linkk[i][y];
		if(f[i][y]==1 && !((mask>>s)&1))
		{
			ret+=calc(mask | (1<<s),s);
			break;
		}
	}
	for(int i=x+1;i<m;i++)
	{
		int s=linkk[i][y];
		if(f[i][y]==1 && !((mask>>s)&1))
		{
			ret+=calc(mask | (1<<s),s);
			break;
		}
	}
	
	for(int i=y-1;i>=0;i--)
	{
		int s=linkk[x][i];
		if(f[x][i]==1 && !((mask>>s)&1))
		{
			ret+=calc(mask | (1<<s),s);
			break;
		}
	}
	for(int i=y+1;i<n;i++)
	{
		int s=linkk[x][i];
		if(f[x][i]==1 && !((mask>>s)&1))
		{
			ret+=calc(mask | (1<<s),s);
			break;
		}
	}
	//if(ret) dp[mask][cur]=ret;
	return ret;
}
int main(){
	while(1)
	{
		cin >> n >> m;
	//	ma.clear();
		if(!n) return 0;
		int num=0; val=0;
		for(int i=0;i<15;i++)for(int j=0;j<15;j++) { f[i][j]=INF; linkk[i][j]=-1;}
		
		for(int i=0;i<m;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin >> f[i][j];
				if(f[i][j]==1) { linkk[i][j]=num; za[num++]=mp(i,j); val++;}
				if(f[i][j]==2) za[23]=mp(i,j);
			}
		
		}
		cout << calc(0,23) << endl;
	}
}

Measured memory_bytes: 1160
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, m;
    while(cin >> n >> m) {
        if(n == 0 && m == 0) break;
        vector<int> ma(m + 1, 0);
        rep(i, n) {
            int d, v; cin >> d >> v;
            chmax(ma[d], v);
        }
        int ans = 0;
        for(int i = 1; i <= m; ++ i) {
            ans += ma[i];
        }
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


Measured memory_bytes: 3136
/*

Convex Polygon - Convex Hull(https://onlinejudge.u-aizu.ac.jp/problems/0068)

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef pair<double, double> dP;
typedef complex<ll> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

//外積を計算する関数
double gaiseki(comp a, comp b)
{
	return (conj(a)*b).imag();
}

//凸包

void solve(void){

	int N;
	cin >> N;

	vector <dP> pps(N);

	rep(N, i)
	{
		cin >> pps[i].snd >> pps[i].fst;
	}

	sort(all(pps));

	int k = 0;

	vector <comp> ps(N), qs(2*N);

	rep(N, i)
	{
		ps[i] = comp(pps[i].snd, pps[i].fst);
	}

	//上側
	rep(N, i)
	{
		while(k > 1 && gaiseki(qs[k-1] - qs[k-2], ps[i]-qs[k-1]) < 0)
		{
			k--;
		}
		qs[k++] = ps[i];
	}

	int t = k;

	//下側
	repr(N-1, i)
	{
		while(k > t && gaiseki(qs[k-1] - qs[k-2], ps[i]-qs[k-1]) < 0)
		{
			k--;
		}
		qs[k++] = ps[i];
	}

	cout << k-1 << endl;

	rep(k-1, i)
	{
		cout << qs[i].real() << ' ' << qs[i].imag() << endl;
	}



}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> a;
  int c[n];
  for(int i=0;i<n;i++){
    int b;
    cin >> b;
    a.push_back(make_pair(b,i));
  }
  sort(a.begin(),a.end());
  int j=0;
  for(auto i:a){
    if(j<a.size()/2) c[i.second] = a.at(a.size()/2).first;
    else c[i.second] = a.at(a.size()/2-1).first;
    j++;
  }
  for(int i=0;i<n;i++) cout << c[i] << endl;
}


Measured memory_bytes: 4720
#include<bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  string input;
  cin>>input;
  for(auto c:input){
    if(c=='7'){
      cout<<"Yes"<<"\n";  
      return 0;
    }
  }
  cout<<"No"<<"\n";  
 
  
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==3){
    cout<<3<<endl;
  }
  if(a+b==4){
    cout<<2<<endl;
  }
  if(a+b==5){
    cout<<1<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<bitset>
#include<bits/stdc++.h>

#define ll long long int
#define N 1000000
using namespace std;

main()
{
	ll n;
	cin>>n;
	ll a[n];
	ll s=0;
	map<ll,ll> m;
	for(ll i=0;i<n;i++)
		{
		cin>>a[i];
		s+=a[i];
		m[a[i]]++;	
	}
	ll q;
	cin>>q;
	while(q--)
	{
		
		ll a,b;
		cin>>a>>b;
			s = s + (b-a)*(m[a]);
		m[b]+=m[a];

		m[a]=0;
		cout<<s<<endl;
	}
		
	
	
	
}

Measured memory_bytes: 10148
eval'N,M,A,*B='+`dd`.split*?,
s=[d=x=0]*9*M
B.map{|b|e=b
A>b&&b+=M
x+=t=b-A
[0,M].map{|m|s[m-~A]+=1
s[m+b]-=t
s[m-~b]+=t-1}
A=e}
p x-s.map{d+=$.+=_1}.max

Measured memory_bytes: 46284
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<int>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int N;
    string S;
    cin >> N >> S;
    vvl dp(N+1, vl(N+1, 0));
    per(i,N) per(j,N) {
        if (S[i] == S[j]) dp[i][j] = dp[i+1][j+1] + 1;
    }
    int ans = 0;
    rep(i,N) rep(j,N) {
        dp[i][j] = min(dp[i][j], abs(i - j));
        ans = max(ans, dp[i][j]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 101156
N = int(input())
nameList = []
for i in range(N):
    nameList.append(input())

nameCount = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in nameList:
    a = list(i)
    try:
        nameCount[a[0]]+=1
    except:
        pass

nameCountList = []
for i in ["M","A","R","C","H"]:
    nameCountList.append(nameCount[i])


x = 0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            x += nameCountList[i] * nameCountList[j] * nameCountList[k]

print(x)

Measured memory_bytes: 9812
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
 
int main(void){
  int a,b,t;
  cin >> a>> b>>t;
  int sum = 0;int c = a;
  while(a <=t){
    sum += b;
    a += c;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n;
    cin>>n;
    vector<int> vec1(n),vec2(n);
    for(i=0;i<n;i++){
        cin>>vec1[i];
    }
    for(i=0;i<n;i++){
        cin>>vec2[i];
    }
    long long int ans=0,maxv=0;
    for(i=0;i<n;i++){
        ans=0;
        for(j=0;j<n;j++){
            if(j<=i)ans+=vec1[j];
            if(j>=i)ans+=vec2[j];
        }
        maxv=max(maxv,ans);
    }
    cout<<maxv<<endl;
}

Measured memory_bytes: 256
#include <iostream>
 #include<algorithm>
#include<vector>

 using namespace std;

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

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

 int count=1;
 for(int i=1; i<n; i++){
     if(a[i] !=a[i-1]){
         count++;
     }
 }

cout<<count<<endl;
 }


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

#define FOR(i,s,e) for(int i = (s);i <= (e);i++)
int A;
int B;
int C;
int D;
int E;
int F;
double res = -1;
int waterRes;
int sugerRes;
int main()
{
	cin >> A>> B>> C>> D>> E>> F;
	for(int a = 0;a <= F;a+= 100 * A)
	{
		for(int b = 0;b <= F;b+= 100* B)
		{
			int water = a + b;
			if(water == 0 || water > F) continue;
			int sugerMax = water / 100 * E;
			for(int c = 0;c <= sugerMax;c+=C)
			{
				for(int d = 0;d <= sugerMax;d+=D)
				{
					int suger = c + d;
					if(suger > sugerMax || suger + water > F) break;
					double per = static_cast<double>(100.0 * suger / (suger + water));
					if(res < per)
					{
						res = per;
						waterRes = water + suger;
						sugerRes = suger;
					}
				}
			}
		}
	}

	cout << waterRes << " " << sugerRes << endl;
	return 0;


}


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

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

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var n = sc.nextInt();
		var d = sc.nextLong();
		var cnt = 0;
		for(int i=0;i<n;i++) {
			var p = sc.nextLong();
			var q = sc.nextLong();
			if(Math.sqrt(p*p+q*q)<=d) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


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

int main() {
    
    ll n,m;
    cin >> n >> m;
    ve<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll l = -1,r = 2*a[n-1]+1;
    while(r-l>1){
        ll mid = (l+r)/2;
        bool ok = [&]{
            ll cnt = 0;
            rep(i,n){
                ll k = lower_bound(a.begin(),a.end(), mid-a[i]) - a.begin();
                cnt += n-k;
            }
            if(cnt <= m)return true;
            else return false;
        }();
        if(ok)r = mid;
        else l = mid;
    }
    ll ans = 0;
    ve<ll> su(n+1);
    rep(i,n)su[i+1] = su[i] + a[i];
    ll z=0;
    rep(i,n){
        ll k = lower_bound(a.begin(), a.end(), r-a[i]) - a.begin();
        ans += a[i] * (n-k) + su[n] - su[k];
        z += n-k;
    }
    if(z<m){
        ans += l * (m-z);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

ll cnt_true = 0;

void dpf_w(int i, int h, int w, int k, string s[]){
    if(i==w){
        int cnt = 0;
        rep(m, h)
        {
            rep(n,w){
                //cout << s[m][n];
                if (s[m][n] == '#')
                    cnt++;
                    
            }
            //cout << endl;
        }
        if(cnt == k)
            cnt_true++;
        return;
    }
    // 選択しない場合
    dpf_w(i + 1, h, w, k, s);

    // 選択する場合
    rep(j, h)
    {
        if(s[j][i] == '#')
            s[j][i] = 'b';
    }
    dpf_w(i + 1, h, w, k, s);
    rep(j, h)
    {
        if (s[j][i] == 'b')
            s[j][i] = '#';
    }
}

    void dpf_h(int i, int h, int w, int k, string s[])
{
    if(i==h){
        dpf_w(0,h, w, k, s);
        return;
    }
    // 選択しない場合
    dpf_h(i + 1, h, w, k, s);
    
    // 選択する場合
    rep(j,w){
        if(s[i][j] == '#')
            s[i][j] = 'r';
    }
    dpf_h(i + 1, h, w, k, s);
    rep(j, w)
    {
        if (s[i][j] == 'r')
            s[i][j] = '#';
    }
}

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    rep(i,h){
        cin >> s[i];
    }
    dpf_h(0, h, w, k, s);
    cout << cnt_true << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
    int n, i, j, k;
    while (scanf("%d",&n)!=EOF) {
        for(j = n + 1; ; j++) {
            int counter = 0;
            for (i = 2; i * i <= j; i++) {
                if (j % i == 0) {
                    counter = 1;
                    break;
                }
            }
            if (counter == 0) {
                break;
            }
        }
        for (k = n - 1; ; k--) {
             int counter = 0;
            for (i = 2; i * i <= k; i++) {
                if (k % i == 0) {
                    counter = 1;
                    break;
                }
            }
            if (counter == 0) {
                break;
            }
        }
        printf("%d %d\n", k, j);
    }
    return 0;
}

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


def solve(
    A: int,
    B: int,
    M: int,
    a: "List[int]",
    b: "List[int]",
    x: "List[int]",
    y: "List[int]",
    c: "List[int]",
):
    # 引数大杉ぃ
    min_refrigerator = min(a)
    min_microwave = min(b)
    not_use_coupon = min_refrigerator + min_microwave

    max_sale = max(c)
    use_coupon = 2000000
    for xi, yi, ci in zip(x, y, c):
        use_coupon = min(use_coupon, a[xi - 1] + b[yi - 1] - ci)

    ans = min(use_coupon, not_use_coupon)
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(A)]  # type: "List[int]"
    b = [int(next(tokens)) for _ in range(B)]  # type: "List[int]"
    x = [int()] * (M)  # type: "List[int]"
    y = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(A, B, M, a, b, x, y, c)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24612
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)

for i in range(n-1):
	if a[i]+1==a[i+1]:
		ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 38256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int N=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		pw.println(Math.min(A*N, B));
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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 int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 21204
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    while(1){
        cin>>a>>op>>b;
        if(op=='?')break;
        if(op=='+')cout << a+b << endl;
        else if(op=='-')cout<<a-b<<endl;
        else if(op=='*')cout<<a*b<<endl;
        else if(op=='/')cout<<a/b<<endl;
    }
    return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
  }
  if(s=="Rainy"){
    cout<<"Sunny"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int b[],int a,int n,int p,int q,int s,int t,double u){
  int i;
  int sm=0,ct=0;
  if(t==n-1){
    for(i=1;i<n;i++)
      sm+=s/b[i];
    if(p*s-q*sm&&q*s%(p*s-q*sm)==0){
      b[n]=q*s/(p*s-q*sm);
      if(s*b[n]<=a){
	if(n==1||b[n-1]<=b[n])
	  ct++;
      }
    }
  }else if(u<(double)p/q){
    for(i=b[t];s*(int)pow(i,n-t)<=a;i++){
      if(u+(double)(n-t)/i+0.125<(double)p/q)
	break;
      if(s*i<=a){
	b[t+1]=i;
	ct+=f(b,a,n,p,q,s*i,t+1,u+1.0/i);
      }
    }
  }
  return ct;
}
int main(){
  int i;
  int b[8],a,n,p,q;
  int ct;
  b[0]=1;
  while(cin>>p>>q>>a>>n&&p+q+a+n){
    ct=0;
    for(i=1;i<n+1;i++)
      ct+=f(b,a,i,p,q,1,0,0.0);
    cout<<ct<<endl;
  }
  return 0;
}

Measured memory_bytes: 884
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    string s, t;
    cin >> s >> t;
    vector<char> S(s.size()), T(t.size());

    SORT(s);
    SORT(t);
    reverse(t.begin(), t.end());
    
    if(s < t){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]

    g = [set() for _ in [0]*n]
    for a, b in ab:
        g[a-1].add(b-1)
        g[b-1].add(a-1)

    mod = 10**9+7
    fact = [1, 1]
    inv = [pow(i, mod-2, mod) for i in range(n+1)]
    for i in range(2, n+1):
        fact.append(fact[-1]*i % mod)

    class rerooting():
        # addは頂点iに頂点jを根とする部分木（DPの値：x）をくっつけるときの補正
        def __init__(self, tree, ini):
            # merge:頂点aにbをマージするときのモノイド
            # adj_bu:ボトムアップ時の調整（a:値,i:頂点）
            # adj_td:トップダウン時の調整（a:値,i:頂点,p:親）
            # adj_fin:最終調整（a:値,i:頂点）
            def merge(a, b): return a * b % mod
            def adj_bu(a, i): return a * inv[size[i]] % mod
            def adj_td(a, i, p): return a * inv[n-size[i]] % mod
            def adj_fin(a, i): return a * fact[n-1] % mod

            # トポロジカルソートをする
            # T:木の隣接グラフ表現をset化
            # P:親
            # q:キュー
            # order:トポソしたもの
            T = g
            P = [-1]*n
            q = [0]
            order = []
            while q:
                i = q.pop()
                order.append(i)
                for a in T[i]:
                    if a != P[i]:
                        P[a] = i
                        T[a].remove(i)
                        q.append(a)

            # Tをリストに変換
            T = [list(i) for i in T]

            # サイズの処理を先に行う
            # size[i]:0を根とする根付き木における、iを根とする部分木の大きさ
            size = [1]*n
            for i in order[1:][::-1]:
                size[P[i]] += size[i]

            # ボトムアップ処理をする
            # ME:マージした値を一時保存
            # DP:DP値、MEを調整したもの
            ME = [ini]*n
            DP = [0]*n
            for i in order[1:][::-1]:
                DP[i] = adj_bu(ME[i], i)
                p = P[i]
                ME[p] = merge(ME[p], DP[i])
            DP[order[0]] = adj_fin(ME[order[0]], order[0])
            TD = [ini]*n

            # トップダウン処理をする
            for i in order:
                # 左からDP（結果はTDに入れている）
                ac = TD[i]
                for j in T[i]:
                    TD[j] = ac
                    ac = merge(ac, DP[j])
                # 右からDP（結果はacに入れている、一度しか使わないのでacで問題ない）
                ac = ini
                for j in T[i][::-1]:
                    TD[j] = adj_td(merge(TD[j], ac), j, i)
                    ac = merge(ac, DP[j])
                    DP[j] = adj_fin(merge(ME[j], TD[j]), j)
            for i in DP:
                print(i)

    rerooting(g, 1)


main()


Measured memory_bytes: 169824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
const int MAX_V = 15;
const int INF = 1e9;
 
int V,E;
int d[MAX_V][MAX_V];
int dp[MAX_V][1<<MAX_V];

int dfs(int v, int mask){
    if(mask==(1<<V)-1) return d[v][0];
    if(dp[v][mask]!=-1) return dp[v][mask];
    int res = INF;
    rep(u,V){
        if(v==u || d[v][u]==INF || (mask&(1<<u))) continue;
        res = min(res, dfs(u, mask|(1<<u))+d[v][u]);
    }
    return dp[v][mask] = res;
}

int main() {
    cin>>V>>E;
    rep(i,V)rep(j,V) d[i][j]=INF;
    rep(i,V) d[i][i]=0;
    rep(i,E){
        int s,t;
        cin>>s>>t;
        cin>>d[s][t];
    }
    memset(dp, -1, sizeof(dp));
    int res=dfs(0,1);
    cout<<(res==INF ? -1 : res)<<endl;
    return 0;
}

Measured memory_bytes: 5040
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		int min;
		int max;
		int a = in.nextInt();
		min = a;
		max = a;
		for(int i=0; i<N-1; i++){
			a = in.nextInt();
			if(min > a){
				min = a;
			}
			if(max < a){
				max = a;
			}
		}
			System.out.print(max - min);
		
	}
}


Measured memory_bytes: 21844
n,k = map(int,input().split())
R,S,P =map(int,input().split())
T = list(input())
value= {'r':P,'s':R,'p':S}
ans = 0
#k個ごとのグループで考える
for i in range(k):
    num = i
    pre = ''
    while num<n:
        if pre == T[num]:#同じ手だったら負けかあいこ．つまり0点カウント
            pre = ''
        else:
            pre = T[num]
            ans += value[pre]
        num += k
print(ans)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int h, w;
	cin >> h >> w;
	int a[h][w];
	rep(i, h) {
		rep(j, w) cin >> a[i][j];
	}

	vector< vector<int> > ans;

	rep(i, h-1) {
		rep(j, w) {
			if(a[i][j] % 2 == 1) {
				ans.push_back({i, j, i+1, j});
				a[i+1][j]++;
			}
		}
	}
	rep(i, w-1) {
		if(a[h-1][i] % 2 == 1) {
			ans.push_back({h-1, i, h-1, i+1});
			a[h-1][i+1]++;
		}
	}
	int n = ans.size();
	cout << n << endl;
	rep(i, n) {
		cout << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][2]+1 << " " <<  ans[i][3]+1 << endl;
	}
	return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int t;
    string s;
    while (cin >> t >> s, t) {
        int n = s.size();
        map<int, int> mp;   // sum, num
        map<int, V> mp2;    // sum, sep
        rep2(state, 1 << (n - 1), 1 << n) {
            int x = 0;
            int temp = 0;
            V v;
            rep(i, n) {
                temp *= 10;
                temp += s[i] - '0';
                if ((state >> i) & 1) {
                    x += temp;
                    v.emplace_back(temp);
                    temp = 0;
                }
            }
            mp[x]++;
            mp2[x] = v;
        }

        int ma_val = -1;
        int ma_num = -1;
        V v;
        for (auto p : mp) {
            if (p.first <= t) {
                ma_val = p.first;
                ma_num = p.second;
                v = mp2[p.first];
            }
        }

        if (ma_val == -1) {
            cout << "error" << endl;
        } else if (ma_num > 1) {
            cout << "rejected" << endl;
        } else {
            cout << ma_val;
            for (auto x : v) cout << " " << x;
            cout << endl;
        }
    }
}

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int N, K;
    cin >> N >> K;
    vint prices(N);
    rep(i, N) {
        cin >> prices[i];
    }
    std::sort(prices.begin(), prices.end());
    ll sum = 0;
    rep(i, K) {
        sum += prices[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int a[999];
int main(){
int i,u=0,v=0,n=read(),m=read();
for (i=1;i<=m;++i){
  a[i]=read();
  if (a[i]&1){
    if (!u) u=i;
    else if (!v) v=i;
    else return puts("Impossible"),0;
    }
  }
if (u) swap(a[1],a[u]);
if (v) swap(a[v],a[m]);
for (i=1;i<=m;++i) write(a[i]),p32;pl;
if (m<2) ++m;
a[1]--,a[m]++;
int j=a[1]?1:2;
cout<<m-j+1<<endl;
for (i=j;i<=m;++i) cout<<a[i]<<" ";
}

Measured memory_bytes: 256
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)             \
    do {                         \
        cout << #args << " -> "; \
        err(args);               \
    } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
    std::cout << a << ' ';
    err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &... args) {
    for (auto &v : arg)
        std::cout << v << ' ';
    err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII   = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD   = 1000000007;
const int MAXN  = 200005;
const int M     = 1000005;

multiset<int> m[MAXN], ma;
set<int> s;
int r[MAXN], in[MAXN];

void run() {
    char c;
    cin >> c;
    cout << ((c>='a' && c<='z')?'a':'A') << endl;
}

// Debug Input Redirection
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    run();
}



Measured memory_bytes: 13032