akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
#include<queue>

using namespace std;

int main(){
    long long n;
    cin >> n;
    multiset<long long> a;
    for(long long i = 0; i < n; i++){
        long long ai;
        cin >> ai;
        a.insert(ai);
    }

    long long ans = 0;
    queue<long long> q;
    multiset<long long>::reverse_iterator ritr = a.rbegin();
    q.push(*ritr);
    for(ritr++; ritr != a.rend(); ritr++){
        ans += q.front();
        q.pop();
        q.push(*ritr);
        q.push(*ritr);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14352
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		/*
		 * ワーシャルフロイド
		 */
		int H=sc.nextInt();
		int W=sc.nextInt();
		long[][] cost=new long[10][10];
		for(int i=0; i<10; i++) {
			for(int j=0; j<10; j++) {
				cost[i][j]=sc.nextLong();
			}
		}
		for(int k=0; k<10; k++) {
			for(int i=0; i<10; i++) {
				for(int j=0; j<10; j++) {
					cost[i][j]=Math.min(cost[i][j], cost[i][k]+cost[k][j]);
				}
			}
		}
		int[][] moji=new int[H][W];
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				moji[i][j]=sc.nextInt();
			}
		}
		long sum=0;
		for(int i=0; i<H; i++) {
			for(int j=0; j<W; j++) {
				if(moji[i][j]!=-1) {
					sum+=cost[moji[i][j]][1];
				}
			}
		}
		pl(sum);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int,int>> ba(n);
    for(int i = 0; i < n; i++) {
        cin >> ba[i].second >> ba[i].first;
    }
    sort(ba.begin(),ba.end());
    int now=0;
    bool jud=true;
    for(int i = 0; i < n; i++) {
        now+=ba[i].second;
        if(now>ba[i].first) jud=false;
    }
    if(jud) cout << "Yes" << "\n";
    else    cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define m 1000000007
using namespace std;
#define ll long long
#define maxi 500001

int main()
{
    string s;
    getline(cin,s);
    int sum=0;
    for(char x:s)
    {
        sum+=(x-'0');
    }
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <iomanip>
#include <vector>
 
uint64_t W, H, x, y;
 
int main(int argc, char const* argv[])
{
    std::cin >> W >> H >> x >> y;
    
    std::cout << double(W*H)/2 << " ";
 
    if (W == x + x && H == y + y) {
        std::cout << 1 << std::endl;
    }
    else {
        std::cout << 0 << std::endl;
    }
 
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

struct edge{
	ll to,cost;
};
vector<edge> G[100000];
ll N,M,X,H[100000];
ll A[300000],B[300000],T[300000];
ll maxh[100000];
ll d[100000];
const ll INF = 0xfffffffffffffff;
priority_queue< P,vector<P>,greater<P> > q;
ll dist;
int main()
{
	cin>>N>>M>>X;
	memset(maxh,-1,sizeof(maxh));
	rep(i,N) scanf("%lld",&H[i]);
	rep(i,M){
		scanf("%lld%lld%lld",&A[i],&B[i],&T[i]);
		A[i]--;
		B[i]--;
		if(H[A[i]]>=T[i]){
			G[A[i]].pb(edge{B[i],T[i]});
		}
		if(H[B[i]]>=T[i]){	
			G[B[i]].pb(edge{A[i],T[i]});
		}
	}
	priority_queue<P> q1;
	q1.push(P(X,0));
	fill(d,d+N,INF);
	while(!q1.empty()){
		P p=q1.top();
		q1.pop();
		ll x=p.sc;
		if(maxh[x]!=-1) continue;
		maxh[x]=p.fr;
		d[x]=X;
		q.push(P(d[x],x));
		rep(i,G[x].size()){
			edge e=G[x][i];
			if(maxh[e.to]==-1&&p.fr>=e.cost) q1.push(P(min(H[e.to],p.fr-e.cost),e.to));
		}
	}
	ll ans=INF;
	if(maxh[N-1]!=-1){
		ans=X-maxh[N-1]+H[N-1]-maxh[N-1];
	}
	while(!q.empty()){
		P p=q.top();
		q.pop();
		ll x=p.sc;
		if(d[x]<p.fr) continue;
		if(x==N-1){
			ans=min(ans,d[N-1]+H[N-1]);
			continue;
		}
		rep(i,G[x].size()){
			edge e=G[x][i];
			if(maxh[x]!=-1&&maxh[e.to]==-1) dist=min( d[x]+(e.cost*2) , X + (e.cost - maxh[x])*2 );
			else dist=d[x]+e.cost*2;
			if(d[e.to]> dist) {
				d[e.to]=dist;
				q.push(P(d[e.to],e.to));
			}
		}
	}
	if(ans>0xfffffffffffff) ans=-1;
	cout<<ans<<endl;
	//rep(i,N) cout<<d[i]<<" "<<maxh[i]<<endl;
}

Measured memory_bytes: 33400
#include <stdio.h>
#define M 100
#define inf 1000000

int p,tree[M][M];

void SSSP(){
  int a,cost,i,j;
  int g[M],now[M];

  for(i=0;i<p;i++){
    g[i]=inf;
    now[i]=0;
  }

  g[0]=0;
  now[0]=1;

  while(1){
    cost=inf;
    a=-1;
    for(i=0;i<p;i++){
      	if(cost>g[i]&&now[i]!=2){
	  a=i;
	  cost=g[i];
	}
    }
    if(a==-1) break;
    now[a]=2;
    for(j=0;j<p;j++){
      if(now[j]!=2 && tree[a][j]!=inf){
	if(g[a]+tree[a][j]<g[j]){
	  g[j]=g[a]+tree[a][j];
	  now[j]=1;
	}
      }
    }
  }

  for(i=0;i<p;i++){
    printf("%d %d\n",i,g[i]);
  }
}
      

int main(){
  int i,j,nu1,nu2,out,weight;

  scanf("%d",&p);

  for(i=0;i<p;i++){
    for(j=0;j<p;j++){
	tree[i][j]=inf;
      }
  }

  for(i=0;i<p;i++){
    scanf("%d%d",&nu1,&out);
    for(j=0;j<out;j++){
      scanf("%d%d",&nu2,&weight);
      tree[nu1][nu2]=weight;
    }
  }
  
  SSSP();

  return 0;
}



Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> list(n+1);
  for (int i=1; i<=n; i++) {
    cin >> list.at(i);
  }
  int m;
  cin >> m;
  int a,b,t;
  for (int i=0; i<m; i++) {
    int ans = 0;
    cin >> a >> b;
    t = list.at(a);
    list.at(a) = b;
    for (int i=1; i<list.size(); i++) {
      ans += list.at(i);
    }
    cout << ans << endl;
    list.at(a) = t;
  }
}

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

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

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

  ll n, W; cin >> n >> W;
  ll w[110] = {}, v[110] = {};
  rep(i, n) cin >> w[i] >> v[i] ;

  // dp[i][j] := i まで見た時に重さが j となる価値の最大値
  ll dp[110][100010] = {};
  rep(i, n) {
    for(int j = 0; j <= W; j++) {
      if(j-w[i] >= 0) {
        dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
      }
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }

  cout << dp[n][W] << '\n';
  return 0;
}


Measured memory_bytes: 86272
import numpy as np
import copy
import sys

h,w,k = map(int, input().split())
C = np.array([[int(elm=="#") for elm in sys.stdin.readline().strip()] for i in range(h)])

ans = 0
for i in range(2**h):
    for ii in range(2**w):
        g = copy.deepcopy(C)
        for j in range(h):
            if i>>j &1: g[j,:] = 0
        for jj in range(w):
            if ii>>jj &1: g[:,jj] = 0
        cnt = np.count_nonzero(g)
        if cnt == k: ans += 1
print(ans)

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

void Main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<char> c(n);
    int r = 0;
    for (int i = 0; i < n; i++)
    {
        c[i] = s[i]=='R' ? 1 : 0;
        r += c[i];
    }
    int m = 0;
    for (int i = 0; i < r; i++)
    {
        if (c[i] == 0) {
            m++;
        }
    }
    
    cout << m << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3860
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
  a, b = map(int, input().split())
  g[a - 1].append(b - 1)
  g[b - 1].append(a - 1)

def go(curr, used, count):
  if count == 1:
    return 1
  tmp = used + [curr]
  return sum(go(node, tmp, count - 1) for node in g[curr] if node not in used)

print(go(0, [], n))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a*b;
	return 0;
}

Measured memory_bytes: 3568
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=1e5+10;
int n,p[N],res;
//
inline void add(int &x,int y){
	x+=y;
	if(x>=MOD)x-=MOD;
}
inline int mul(int x,int y){
	ll ans=1ll*x*y;
	return ans%MOD;
}
inline int modpow(int x,int y){
	int ans=1;
	while(y>0){
		if(y&1)ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
inline int modinv(int x){
	return modpow(x,MOD-2);
}
int main(){
	n=getint();
	for(int i=1;i<=n;i++){
		add(p[i],p[i-1]);
		add(p[i],modinv(i+1));
	}
	rep(i,n){
		int x=getint();
		add(res,mul(p[i],x));
		add(res,x);
		add(res,mul(p[n-i-1],x));
	}
	rep(i,n)res=mul(res,i+1);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  string s;
  cin >> s;
  rep(i, 3) {
    if (s[i] == s[i+1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
}


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

bool solve(){
    int n;
    cin >> n;
    if(n == 0) return true;
    vector<pair<double,string> > ls;
    for(int i=0;i<n;i++){
        string l;
        int p, a, b, c, d, e, f, s, m;
        cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
        int X = f*s*m - p, Y = a+b+c+(d+e)*m;
        ls.emplace_back(make_pair(double(-X)/Y,l));
    }
    sort(ls.begin(), ls.end());
    for(int i=0;i<n;i++){
        cout << ls[i].second << endl;
    }
    cout << '#' << endl;
    return false;
}

int main(){
    while(!solve());
    return 0;
}


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

template <class... Args>
void gin(Args&&... args) { (cin >> ... >> args); }
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long

void solve(){
 int n,d; gin(n,d); 
 int cnt = 0,x,y;
 fr(_,n){
 	gin(x,y);
 	cnt += x*x + y*y <= d*d;
 }
 cout << cnt;

}
int32_t main()
{
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   // int tst; cin >> tst; while(tst--)
   {
   	solve();
   }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
#define DEBUG(x) cout << x << '\n'

int n, a[MAXN], vis[MAXN], pos[MAXN];
ll k;
int dfs(int u){
    if(~vis[a[u]]) return a[u];
    vis[a[u]] = vis[u] + 1;
    pos[vis[a[u]]] = a[u];
    return dfs(a[u]);
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios::sync_with_stdio(false);

    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i], vis[i] = -1;
    vis[1] = 0, pos[0] = 1;
    int x = dfs(1);
    int mx = *max_element(vis + 1, vis + n + 1) + 1;
    int ans;
    if(k < mx) ans = pos[k];
    else{
        int cycle = mx - vis[x];
        k -= vis[x];
        k %= cycle;
        ans = pos[vis[x]+k];
    }
    cout << ans;
}


Measured memory_bytes: 5880
#include <stdio.h>

int n;
int p[25];
int ans;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", p + i);
    }

    for (int i = 1; i < n - 1; i++) {
        if (p[i] > p[i - 1] && p[i] < p[i + 1]) {
            ans++;
        }
        else if (p[i] < p[i - 1] && p[i] > p[i + 1]) {
            ans++;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
N = int(input())
 
s=k=kn=0;n=N
while k<n:
	k += 1
	n = N//k
	kn = k*n*(n+1)
	s += 4*kn
s -= (k+1)*kn
if n<k:
	s -= 2*kn 
print(s//4)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	string o,e;
	cin>>o;
	cin>>e;

	for(int i=0;i<e.size();i++)
		cout<<o[i]<<e[i];
	if(o.size()>e.size())cout<<o[e.size()]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i, n-1)if(s[i] == s[i+1]){
        printf("%d %d\n", i+1, i+2);
        return 0;
    }
    rep(i, n-2)if(s[i] == s[i+2]){
        printf("%d %d\n", i+1, i+3);
            return 0;
    }
    puts("-1 -1");
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

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

  string s;
  cin >> s;
  int k;
  cin >> k;

  vector<vector<int>> pos(26, vector<int>());
  rep(i, s.size()) {
    pos[s[i] - 'a'].push_back(i);
  }

  set<string> ss;
  rep(c, 26) {
    for (int& i : pos[c]) {
      for (int j = 1; i+j <= s.size(); j++) {
        ss.insert(s.substr(i, j));
        if (j >= k) break;
      }
    }
    if (ss.size() >= k) break;
  }

  auto itr = ss.begin();
  rep(i, k-1) itr++;

  cout << *itr << endl;

  return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    int a[n + 2];
    int b[n + 1];
    FOR(i, 1, n + 1) cin >> a[i];
    FOR(i, 1, n)    cin >> b[i];
    ll res = 0;
    FOR(i, 1, n)
    {
       res += min(a[i] + a[i + 1], b[i]);
       if(b[i] >= a[i])
            a[i + 1] -= min(a[i + 1], b[i] - a[i]);
    }
    cout << res;
    return 0;
}


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

string s, t;

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

  int len = s.length();
  string sub = t.substr(0, len);

  if ((sub == s) & (t.length() == len + 1)) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 3720
n,m,x =map(int,input().split())

a = []
c = []
for _ in range(n):
    a.append(list(map(int,input().split())))
    c.append(a[-1].pop(0))

#print(a,c)

ans = 10 ** 8

for i in range(1 << n):
    cost = 0
    check = True
    d = [0 for i in range(m)]
    for j in range(n):
        if i >> j & 1:
            cost += c[j]
            for i2 in range(m):
                d[i2] += a[j][i2]
            #print(i >> j,d)
    for k in range(m):
        if d[k] < x:
            check = False
    if check:
        ans = min(ans, cost)
    #print(d,cost,check)
    
if ans == 10 ** 8:
    print(-1)
else:
    print(ans)

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

#define ll long long


int main()
{
    ll h,i,n;

    cin>>h>>n;

    vector<ll> v(n);

    ll s=0;
    for(int i=0;i<n;i++){
        cin>>v[i];

        s+=v[i];
    }


    if(s>=h)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;




    return 0;
}









Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  for(int n,a[100];cin>>n;){
    int sum=0,p=0;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);for(int i=0;i<n;i++)sum+=a[i],p+=sum;
    cout<<p<<endl;
  }
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>


using namespace std;
  
int main(){
  string s;
  cin >> s;
  int k = 15 - s.size();
  for(auto z : s){
    if (z == 'o') k++;

  }
  if(k > 7){
  	cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main
 
import (
  "fmt"
  "os"
  "bufio"
)
 
func main() {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  str := scanner.Text()
  
  switch str {
    case "SAT": fmt.Println(1)
    case "FRI": fmt.Println(2)
    case "THU": fmt.Println(3)
    case "WED": fmt.Println(4)
    case "TUE": fmt.Println(5)
    case "MON": fmt.Println(6)
    case "SUN": fmt.Println(7)
  }
}


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

const int mod = 1000000007;

// dp[i][j] : 先頭からi桁目まで見たときの組み合わせ数。
//            j = 0 : i桁目まで一致
//            j = 1 : s未満であることが確定している
ll dp[100100][2]; 
int main() 
{
    string s;
    cin >> s;
    int n = s.size();

    rep(i,100100)rep(j,2) dp[i][j] = 0;
    dp[0][0] = 1;

    for (int i=1; i<=n; i++) {
        if (s[i-1] == '0') {
            // 合計が0
            (dp[i][0] += dp[i-1][0]) %= mod;
            (dp[i][1] += dp[i-1][1]) %= mod;
            // 合計が1
            (dp[i][1] += dp[i-1][1] * 2 % mod) %= mod;
        } else { // == '1'
            // 合計が0
            (dp[i][1] += dp[i-1][0] + dp[i-1][1]) %= mod;
            // 合計が1
            (dp[i][0] += dp[i-1][0] * 2 % mod) %= mod;
            (dp[i][1] += dp[i-1][1] * 2 % mod) %= mod;
        }
    }

    ll ans = dp[n][0] + dp[n][1];
    ans %= mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

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

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int K = in.nextInt();
			int[] x = new int[N];
			int ans = 0;
			for(int i = 0; i < N; i++) {
				x[i] = in.nextInt();
				if(Math.abs(x[i]) < Math.abs(x[i] - K)) {
					ans += Math.abs(x[i]) * 2;
				} else {
					ans += Math.abs(x[i] - K) * 2;
				}
			}
			out.println(ans);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

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

	}
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int> 
#define all(a) a.begin(), a.end()
// #define int long long
#define ll long long
#define vi vector<int>
#define mod 998244353
#define mod1 1000000007
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)
#define testcase  int t; cin>>t; while(t--) 
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;

int max(int a, int b) { return (a > b)? a : b; } 

int min(int a, int b) { return (a < b)? a : b; }


   
 /*************************************************************************/

vi ar[100010];
int vis[100010],dist[10001];
/*
vi a;
int n,m;
*/
int solve()
{
    
    return 0;
}

int cc;
/*
void dfs(int node )
{
	vis[node]=1;
	cc++;
	for(int child : ar[node])
	{
		if(vis[child]==0)
		{
			dfs(child);			
		}		
	}
}
*/

int32_t main()
{
	FIO
    // testcase
	{
        int n;
        cin>>n;
        vi a(n),b(n),c(n);
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i]>>c[i];
        }
        vector< vector<int>>dp(n,vector<int>(3));
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];
        for(int i=1;i<n;i++)
        {
            dp[i][0] =  a[i] + max(dp[i-1][1] , dp[i-1][2]);
            dp[i][1] =  b[i] + max(dp[i-1][0] , dp[i-1][2]);
            dp[i][2] =  c[i] + max(dp[i-1][1] , dp[i-1][0]);
        }
        
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    }
    return 0;
}




Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

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

  if(N==M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}



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

int main() {
    string S,T;
    cin >> S >> T;
    int max = 0;
    for (int i = 0; i < S.size()-T.size()+1; i++) {
        int count = 0;
        for (int j = 0; j < T.size(); j++) {
            if (S.at(i+j)==T.at(j)) {
                count++;
            }
            if (count > max) {
                max = count;
            }
        }
    }
    cout << T.size() - max << endl;
}



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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll a, b, n;
    cin >> a >> b >> n;
    ll rem;
    if(n >= b-1)
    {
        rem = b-1;
    }
    else
    {
        rem = n;
    }
    cout << a*(rem) / b;
    return 0;
}


Measured memory_bytes: 3640
from itertools import combinations
n,m,x=[int(i) for i in input().split()]
a=[]
for i in range(n):
    a.append([int(i) for i in input().split()])
cost=[]
for i in range(1,n+1):
    c=list(combinations(a,i))
    b=[[0]*(m+1) for i in range(len(c))]
    for k in range(len(c)):
        for j in range(len(c[k])):
            for i in range(m+1):
                b[k][i]+=c[k][j][i]
    for i in range(len(b)):
        s=0 ; flag=0
        for j in range(1,len(b[i])):
            if b[i][j]<x:
                flag=1
                break
        if flag==0: 
            cost.append(b[i][0])
if not cost: print(-1)
else: print(min(cost))

        
            
            
        


Measured memory_bytes: 68644
N, total = map(int, input().split())
li = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    diff = li[i] + li[i+1] - total
    if diff > 0:
        if li[i+1] > diff:
            li[i+1] -= diff
        else:
            li[i] -= (diff - li[i+1])
            li[i+1] = 0
        ans += diff
print(ans)

Measured memory_bytes: 14132
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#ifdef ONLINE_JUDGE
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define dbg(v)
#else
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
#endif

// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

template<typename T> T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template<typename T> T lcm(const T a, const T b) {
    return a / gcd(a, b) * b;
}

template<typename T> bool chmin(T& a, const T& b) {
    if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
    if (a < b) return a = b, true; else return false;
}

// End of template.

int main() {
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    int x;
    cin >> x;
    if (x >= 30) print("Yes"); else print("No");

    return 0;
}

/*
  __ _   ___ _ __  _ __
 / _` | / __| '_ \| '_ \
| (_| || (__| |_) | |_) |
 \__,_(_)___| .__/| .__/
            |_|   |_|
*/


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

int n,l;
int a[100000];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n>>l;
	for (int i=0; i<n; i++) cin>>a[i];
	
	vector<int> v;
	
	int t=-1;
	for (int i=1; i<n; i++)
		if (a[i-1]+a[i] >=l ) t = i;
		
	if (t==-1)
		return cout<<"Impossible",0;

	v.push_back(t);
	for (int i=t-1; i; i--) v.push_back(i);
	for (int i=t+1; i<n; i++) v.push_back(i);

	reverse(v.begin(),v.end());
	cout<<"Possible\n";
	for (int i:v) cout<<i<<'\n';	
	
	return 0;
}

Measured memory_bytes: 1784
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    int a, b, c, k, cnt = 0;
    cin >> a >> b >> c >> k;
    if (b <= a) {
        while (b <= a) {
            b *= 2;
            cnt++;
            debug(a, b, c, cnt);
        }
    }
    if (c <= b) {
        while (b >= c) {
            c *= 2;
            cnt++;
            debug(a, b, c, cnt);
        }
    }
    if (cnt <= k)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, X);
  print((X / 500) * 1000 + ((X % 500) / 5) * 5);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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;
}



int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    ll cnt=0;
    for (ll i = 0; i < N; i++){
        for (ll j = i + 1; j < N; j++){
            for (ll k = j + 1; k < N; k++){
                if(L[i]+L[j]>L[k] && L[i]+L[k]>L[j] && L[j]+L[k]>L[i] && L[i]!=L[j] && L[j]!=L[k] && L[k]!=L[i]) {
                    cnt++;
                    // if(N==5){
                    //     debg(i)
                    //     debg(j)
                    //     debg(k)
                    // }
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
 
public class Main {
    public void exec() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        while(true) {
            String line = br.readLine();
            if ("-".equals(line))
            	break;
            int len = line.length();
            int m = Integer.parseInt(br.readLine());
            int h = 0;
            for (int i=0; i<m; i++) {
            	h += Integer.parseInt(br.readLine());
            }
            h %= len;
            if(h == 0)
            	out.println(line);
            else {
            	out.print(line.substring(h, len));
            	out.println(line.substring(0, h));
            }
            out.flush();
        }
    }
  
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}

Measured memory_bytes: 24164
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
bool compare(pair<ll,string> p1,pair<ll,string> p2){
return p2.fi>p1.fi;
}
void solve(){
 ll k,a,b;
 cin>>k>>a>>b;
 ll z=a/k;
 if((k*z>=a &&k*z<=b )||(k*(z+1)>=a &&k*(z+1)<=b)) cout<<"OK"<<endl;
 else cout<<"NG"<<endl;

}
int main()
{   fast;
    ll t=1;
    //cin>>t;
    fr(zz,1,t+1){
    solve();
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
    
 
int main (){
  	int N;
    string S;
    cin>>N>>S;
    bool a=true;
  	if(N%2>0){
            a=false;
        }
    for(int i=0; i<N/2; i++){
        if(N%2>0){
            break;
        }
        if(S.at(i)==S.at(N/2+i)){
            continue;
        }
        else{
            a=false;
            break;
        }
    }
    if(a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
            int N = sc.nextInt();

            String[][] S = new String[N][3];

            for(int i = 0 ; i < N ; i++){
                S[i][0] = sc.next();
                S[i][1] = sc.next();
                S[i][2] = String.valueOf(i+1);
            }
            sc.close();


            Arrays.sort(S, new Comparator<String[]>() {
                @Override
                public int compare(String[] o1, String[] o2) {

                    if (o1[0].equals(o2[0])) {
                        return Integer.parseInt(o2[1]) - Integer.parseInt(o1[1]); 
                    } else {
                        return o1[0].compareTo(o2[0]); 
                    }
                }
            });
/*
            for(int i = 0 ; i < N ; i++){
                System.out.print(S[i][0] + " ");
                System.out.print(S[i][1]+ " ");
                System.out.print(S[i][2]+ " ");
                System.out.println("");
            } 
*/

            for(int i = 0 ; i < N ; i++){
                System.out.println(S[i][2]);
            }
        }
   }



Measured memory_bytes: 21460
import           Control.Monad (replicateM)
import           Data.Function (on)
import           Data.List     (groupBy, sortOn)

main :: IO ()
main = do
  [_n, m] <- map read . words <$> getLine
  pys <- replicateM m $ (\[p, y] -> (p, y)) . map read . words <$> getLine
  mapM_ putStrLn $ f pys

type Prefecture = Int
type Year = Int

f :: [(Prefecture, Year)] -> [String]
f =
  map (\(_i, p, j) -> pad6' (show p) ++ pad6' (show j)) .
  sortOn (\(i, _p, _j) -> i) .
  concatMap (zipWith (\j (i, (p, _y)) -> (i, p, j)) [1 :: Int ..]) .
  groupBy ((==) `on` (\(_i, (p, _y)) -> p)) .
  sortOn snd .
  zip [1 :: Int ..]
-- sortOn ではなく sortBy comparing を使ってしまうと C022_scrambled 以降 TLE

pad6 :: String -> String
pad6 = reverse . take 6 . (++ repeat '0') . reverse

pad6' :: String -> String
pad6' s = replicate (6 - length s) '0' ++ s


Measured memory_bytes: 126332
N = int(input())
L = list(map(int, input().split()))
L.sort()
import bisect
num = 0
for i in range(N):
  for j in range(i+1,N):
    num += bisect.bisect_left(L,L[i]+L[j])-j-1
    #print(i,j,num)
print(num)

Measured memory_bytes: 3316
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
  int u, t, b;
  S(int u, int t, int b) : u(u), t(t), b(b) {}
  bool operator < (const S& s) const {
    if(t != s.t) return t > s.t;
    if(b != s.b) return b < s.b;
    return u < s.u;
  }
};

int main(){
  int N, M, L, K, A, H;
  while(cin>>N>>M>>L>>K>>A>>H && N){
    bool recover[100] = {};
    REP(i, L){
      int t; cin>>t;
      recover[t] = true;
    }
    int dist[100][100];
    memset(dist, -1, sizeof(dist));
    REP(i, K){
      int a, b, c;
      cin>>a>>b>>c;
      dist[a][b] = c;
      dist[b][a] = c;
    }
    priority_queue<S> que;
    que.push(S(A, 0, M));
    bool used[100][101] = {};
    bool help = true;
    while(!que.empty()){
      S s = que.top(); que.pop();
      if(s.u == H){
        cout<<s.t<<endl;
        help = false;
        break;
      }
      if(used[s.u][s.b]) continue;
      used[s.u][s.b] = true;
      if(s.b > 0){
        REP(i, N) if(dist[s.u][i] >= 0 && s.b - dist[s.u][i] >= 0 && !used[i][s.b - dist[s.u][i]]){
          que.push(S(i, s.t + dist[s.u][i], s.b - dist[s.u][i]));
        }
      }
      if(recover[s.u] && s.b < M && !used[s.u][s.b + 1]){
        que.push(S(s.u, s.t + 1, s.b + 1));
      }
    }
    if(help){
      cout<<"Help!"<<endl;
    }
  }
  return 0;
}

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

vector<ll> C;
vector<vector<int>> G;
vector<bool> isvisit;

void dfs(int k) {
  for (auto ne : G[k]) {
    if (isvisit[ne]) continue;
    C[ne] += C[k];
    isvisit[ne] = true;
    dfs(ne);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  G.resize(n);
  C.resize(n, 0);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,q) {
    int p, x;
    cin >> p >> x;
    p--;
    C[p] += x;
  }
  isvisit.resize(n, false);
  isvisit[0] = true;
  dfs(0);
  rep(i,n) cout << C[i] << endl;
  return 0;
}

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

int main(){
  vector<int>vec(5);
  for(int i=0;i<5;i++) cin>>vec[i];
  int k;
  cin>>k;
  int df=0;
  for(int i=0;i<5;i++){
    for(int a=0;a<5;a++){
      if(vec[i]-vec[a]>k){
        df=1;
      }
    }
  }
  if(df==0){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  } 
}


Measured memory_bytes: 256
card = [[list(map(int, input().split())) for _ in range(3)],
        [[0 for _ in range(3)] for _ in range(3)]]
N = int(input())
B = [int(input()) for _ in range(N)]

sc = 1
DEB = False

def check_vertical(card):
    V = [sum(card[sc][i]) for i in range(3)]
    if DEB: print(V)
    return (3 in V)

def check_horizen(card):
    H = [sum([card[sc][j][i] for j in range(3)]) for i in range(3)]
    if DEB: print(H)
    return (3 in H)
def check_diag(card):
    D = [card[sc][0][0]+card[sc][1][1]+card[sc][2][2],
         card[sc][0][2]+card[sc][1][1]+card[sc][2][0]]
    if DEB: print(D)
    return(3 in D)

def check_card(card):
    return (check_diag(card) or check_horizen(card) or check_vertical(card))

for b in B:
    for i in range(3):
        for j in range(3):
            if card[0][i][j] == b: card[1][i][j] = 1
            tf = check_card(card)
            if tf:
                print('Yes')
                break
        else:
            continue
        break
    else:
        continue
    break
else:
    if tf is False:
        print('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	
	int n;
	scanf("%d", &n);
	int poin = 0;
	
	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			if( i * j == n){
				poin = 1;
			}
		}
	}
	
	if(poin == 1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1632
i,j,s,a,b;t['   '];c(int*x){i=x[1]-1[&x][1];}main(n){for(;i=scanf("%d",&n)*n;qsort(t,n,8,c),printf("%d\n%d\n%d\n",*t,t[2],t[n*2-4]))for(;i--;t[i*2+1]=s)for(s=!scanf("%d",t+i*2),j=4;j--;s+=a*60+b)scanf("%d%d",&a,&b);}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define M 10000
#define MAX 10*10*10*10*10*10*10*10

int isprime(int x);

int main(){
  int i,n;
  int A[M];
  int P=0;
  scanf("%d",&n);
  if(n < 1 || n > M) exit(1);
  for(i=0;i<n;i++){
     scanf("%d",&A[i]);
     if(A[i] < 2 || A[i] > MAX) exit(2);
     if(1 == isprime(A[i])) P++;
  }
  printf("%d\n",P);
  return 0;
}

int isprime(int x){
  int i;
  if(x == 2) return 1;
  else if(x < 2 || x%2==0) return 0;
  i = 3;
  while(i<=sqrt(x)){
    if(x%i == 0) return 0;
    i = i + 2;
  }
  return 1;
  
}



Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T>
struct Kruskal{
  
  struct edge{
    int from,to;
    T cost;
    int used;
    edge(){}
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<int> p,r;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(int n):n(n){}

  void init(int n){
    r.assign(n,1);
    p.resize(n);
    iota(p.begin(),p.end(),0);
  }
  
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

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

  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(int u,int v,T c){
    edges.emplace_back(u,v,c);
  }
  
  T build(){
    sort(edges.begin(),edges.end());
    init(n);
    T res=0;
    for(auto &e:edges){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};
//END CUT HERE
int main(){
  int V,E;
  scanf("%d %d",&V,&E);
  Kruskal<int> ksk(V);
  for(int i=0;i<E;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    ksk.add_edge(a,b,c);
  }
  printf("%d\n",ksk.build());
  return 0;
}

/*
  verified on 2018/10/22
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp
*/



Measured memory_bytes: 4916