akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
typedef long long int ll;
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];


int main(){
  ll q,h,s,d,n; cin >> q>>h>>s>>d>>n;
  if(n%2==1){
    ll ans=min({8*q,4*h,2*s,d})*(n-1)/2+min({4*q,2*h,s});
    cout<<ans<<endl;
  }
  else{
    ll ans= min({8*q,4*h,2*s,d})*n/2;
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stdio.h>
using namespace std;
struct node{
	int num,id;
}student[100010];

bool cmp(node a,node b){
	return a.num<b.num;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>student[i].num;
		student[i].id=i+1;
	}
	sort(student,student+n,cmp);
	for(int i=0;i<n-1;i++)
		cout<<student[i].id<<" ";
	cout<<student[n-1].id<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(ll i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
class state {
public:
    int idx;
    string a;
    int b;
    state(){}
    state(int idx,string a, int b){
        this->a = a;
        this->b = b;
        this->idx = idx;
    }
    bool operator<(const state &x)const{
        if(a == x.a){
            return b>x.b;
        }
        return a<x.a;
    }
};
int main() {
    int N;
    cin >> N;
    vector<state> X;
    rep(i,N){
        string a;
        int b;
        cin >> a>> b;
        X.pb(state(i+1,a,b));
    }
    sort(all(X));
    rep(i,N){
        cout << X[i].idx << endl;
    }
}

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

int main() 
{
    int n,T;
    cin >> n >> T;
    int m = INT_MAX;
    for (int i=0; i<n; i++)
    {
        int c,t;
        cin >> c >> t;
        if (t<=T)
            m=min(m,c);
    }
    cout << (m!=INT_MAX?to_string(m):"TLE");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;



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

    vector<pair<int,int> > z;   // a[i],i
    vector<int> b(n);
    int i;
    for(i=0; i<n; i++) {
        int a;
        scanf("%d%d", &a, &b[i]);
        z.push_back(make_pair(a,i));
    }
    sort(z.begin(), z.end());

    ll ans=0;
    set<pair<int,int> > z0;   // b[i],i
    int curr=0;
    for(i=1; i<=m; i++) {
        while(curr<n && z[curr].first<=i) {
            int id=z[curr].second;
            z0.insert(make_pair(b[id],id));
            curr++;
        }
        if(z0.empty()) {
            
        }
        else {
            auto it=z0.rbegin();
            ans+=(it->first);
            z0.erase(*it);
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 6004
import java.util.Scanner;

public class Main {
  public static void main(String arg[]) {
    Scanner sc = new Scanner(System.in);
    int valuesCount = sc.nextInt(); // 価格の個数
    // 時刻tにおける価格を配列に格納
    int values[] = new int[valuesCount];
    for (int i = 0; i < valuesCount; i++) {
      values[i] = sc.nextInt();
    }
    sc.close();

    System.out.println(getMaxProfit(values));
  }

  private static int getMaxProfit(int[] values) {
    int maxProfit = Integer.MIN_VALUE;
    int min = Integer.MAX_VALUE;
    for (int value : values) {
      if (value - min > maxProfit) {
        maxProfit = value - min;
      }
      if (value < min) {
        min = value;
      }
    }
    return maxProfit;
  }
}


Measured memory_bytes: 100904
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    for (auto e: v) os << e << ",";
    os << "]";
    return os;
}

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// print floating-point number
// cout << fixed << setprecision(12) <<

// }}}

int H, W;
char s[20][20];
bool visited[20][20];

int bfs(P start, P destination)
{
    REP (i, H) REP (j, W) visited[i][j] = false;
    queue<pair<P, int> > q;
    q.emplace(start, 0);
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        if (visited[p.fi.fi][p.fi.se]) continue;
        visited[p.fi.fi][p.fi.se] = true;
        if (s[p.fi.fi][p.fi.se] == '#') continue;
        if (p.fi == destination) return p.se;
        REP (i, 4) {
            int ni = p.fi.fi + dx[i];
            int nj = p.fi.se + dy[i];
            if (ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
            if (s[ni][nj] == '#' || visited[ni][nj]) continue;
            P np = mp(ni, nj);
            q.emplace(np, p.se+1);
        }
    }
    return -1;
}

void solve()
{
    int ans = 0;
    REP (si, H) {
        REP (sj, W) {
            if (s[si][sj] == '#') continue;
            REP (ti, H) {
                REP (tj, W) {
                    if (s[ti][tj] == '#') continue;
                    if (si == ti && sj == tj)
                        ans = max(ans, 0);
                    else
                        ans = max(ans, bfs(mp(si, sj), mp(ti, tj)));
                }
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    REP (i, H) REP (j, W) cin >> s[i][j];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

using namespace std;

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

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {

	int a, b;
	cin >> a >> b;
	string str;
	cin >> str;
	str[b - 1] += 0x20;
	cout << str << endl;



}



Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

int main() {
	string s, t;
	cin >> s >> t;
	bool tmp = true;
	if (s.size() != t.size() - 1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			tmp = false;
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


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

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

	int a, n;
	cin >> n;
	cin >> a;

	if (n % 500 <= a){
		cout << "Yes" << "\n";
	}else{
		cout << "No" << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair



int main() {
    int n; cin >> n;
    int k = 2;
    vector<int> factor(100000, 0);
    int m = n;
    while (k * k <= n) {
        if (m % k == 0) {
            factor[k]++;
            m /= k;
        }
        else k++;
    }
    printf("%d:", n);
    REP(i, factor.size()) {
        REP(j, factor[i]) printf(" %d", i);
    }
    if (m != 1) printf(" %d", m);
    printf("\n");
    return 0;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    ll before = -1;

    ll ans = 0;
    REP(i,N) {
        if(i == 0) {
            before = A[i];
            continue;
        }
        if (before > A[i]) {
            ans += before - A[i];
            A[i] = before;
        }
        before = A[i];
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 200010 , LOG = 19;

int n , a , pre = 0 , tmp;
long long ans = 0;

int main(){
	scanf("%d",&n);
	for(int i = 0 ;i < n;i++){
		scanf("%d",&a);
		tmp = min(a , pre);
		ans += tmp;
		a -= tmp;
		ans += a / 2;
		pre = a % 2;
	}
	cout << ans << endl;   	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string S;
int64_t K;
int64_t DP[105][4][2]; // i桁目まで決めて、j個の非0を使って、N以下であることが確定している個数

int main()
{
  cin >> S >> K;
  int N = S.size();
  DP[0][0][0] = 1;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 4; j++)
    {
      for (int k = 0; k < 2; k++)
      {
        int si = S[i] - '0'; // 今の桁
        for (int d = 0; d < 10; d++)
        {
          int ni = i + 1, nj = j, nk = k;
          if (d != 0)
            nj++;
          if (nj > K)
            continue;
          if (k == 0)
          {
            if (d > si)
              continue;
            else if (d < si)
              nk = 1;
          }
          DP[ni][nj][nk] += DP[i][j][k];
        }
      }
    }
  }
  int64_t ans = DP[N][K][0] + DP[N][K][1];
  cout << ans << endl;
}


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

using namespace std;
const int MAXN=1e5+10;
int n,l,q,a,b,dat[MAXN],nxt[MAXN][25];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&dat[i]);
	scanf("%d",&l);
	for(int i=1;i<=n;i++)
	{
		int pos=lower_bound(dat+1,dat+n+1,dat[i]+l)-dat;
		if(dat[pos]==dat[i]+l) nxt[i][0]=pos;
		else nxt[i][0]=pos-1;
	}
	
	for(int i=n;i;i--)
		for(int j=1;j<=20;j++)
			nxt[i][j]=nxt[nxt[i][j-1]][j-1];
	
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&a,&b);
		if(a>b) swap(a,b);
		
		int res=0;
		for(int i=20;i>=0;i--)
			if(nxt[a][i]&&nxt[a][i]<b) a=nxt[a][i],res+=(1<<i);
		if(a<b) a=nxt[a][0],res++;
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 11008
N, M = [int(nm) for nm in input().split()]
L = []
for n in range(N):
  KA = [int(ka) for ka in input().split()]
  for ka in range(len(KA)-1):
    L.append(KA[ka+1])
like = 0
for m in range(M):
  if L.count(m+1) == N:
    like += 1
print(like)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
int main(){
  long long N, M;
  scanf("%lld %lld", &N, &M)+1;
  printf("%lld\n", ((N != 1) ? (N - 2) : 1) * ((M != 1) ? (M - 2) : 1));
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int k;
int main()
{
	cin>>k;
	if(k&1) printf("%d\n",(k/2)*(k/2+1));
	else printf("%d\n",(k/2)*(k/2));
	return 0;
}

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

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, X);
    CINS(int, L, N);

    int d = 0;
    int count = 1;
    for (int i = 0; i < N; i++) {
        d += L[i];
        if ( d <= X ) {
            count++;
        } else {
            break;
        }
    }
    
    cout << count << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

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

int main() {
  int n,p;
  while(cin>>n>>p,n+p) {
    int i=0;
    int wan = p;
    vector<int> a(n);
    
    while(true) {
//      cout << i << " " << a[i] << " "<<wan << endl;
      if (wan) {
        wan--;
        a[i]++;
        if (wan==0&&a[i]==p)
          break;
      } else {
        wan = a[i];
        a[i]=0;
      }
      i++;
      if (i>=n) i=0;
    }
    cout << i << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	char s1[100],s2[100],s3[100];
	cin>>s1>>s2>>s3;
	if(s1[0]>='a'&&s1[0]<='z')
	s1[0]-=32;
	if(s2[0]>='a'&&s2[0]<='z')
	s2[0]-=32;
	if(s3[0]>='a'&&s3[0]<='z')
	s3[0]-=32;
	cout<<s1[0]<<s2[0]<<s3[0];
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    if(x == 1 || x == 2*N-1){
        cout << "No" << endl;
        return 0;
    }

    if(N == 2){
        cout << "Yes" << endl;
        for(int i=1; i<=3; i++) cout << i << endl;
        return 0;
    }

    vector<int> ans(2*N+1, 0);
    if(x != 2){
        ans[N-1] = x-1;
        ans[N]   = x;
        ans[N+1] = x+1;
        ans[N+2] = x-2;

        int id = 0;
        for(int i=1; i<=2*N-1; i++){
            if(i == N-1 || i == N || i == N+1 || i == N+2) continue;

            id++;
            if(id == x-2) id = x+2;
            ans[i] = id;
        }

        cout << "Yes" << endl;
        for(int i=1; i<=2*N-1; i++) cout << ans[i] << endl;
    }
    else{
        ans[N-1] = x+2;
        ans[N]   = x;
        ans[N+1] = x-1;
        ans[N+2] = x+1;

        int id = 0;
        for(int i=1; i<=2*N-1; i++){
            if(i == N-1 || i == N || i == N+1 || i == N+2) continue;

            id++;
            if(id == x-1) id = x+3;
            ans[i] = id;
        }

        cout << "Yes" << endl;
        for(int i=1; i<=2*N-1; i++) cout << ans[i] << endl;
    }
}


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

int main()
{
    int a, b, c, k;
    int aa, bb, cc;
    cin >> a >> b >> c >> k;
    bool ans = false;
    rep(x, k+1) {
        aa = a << x;
        rep(y, (k+1-x)) {
            bb = b << y;
            rep(z, (k+1-x-y)) {
                cc = c << z;
                if ((aa < bb) && (bb < cc)) {
                    ans = true;
                }
            }
        }
    }

    if (ans == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 3564
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double max = -1;
		double min = 999999;
		while(sc.hasNext()){
			double num = sc.nextDouble();
			if(max < num) max = num;
			if(min > num) min = num;
		}
		System.out.println(max - min);
	}
}

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

int main()
{
	int a[3];
	while(cin>>a[0]>>a[1]>>a[2])
	{
		sort(a,a+3);
		if(a[0]==a[1])
		{
			if(a[2]!=a[1])
			cout<<"Yes"<<endl;
			else
			cout<<"No"<<endl;
		}else if(a[1]==a[2])
		{
			if(a[0]!=a[1])
			cout<<"Yes"<<endl;
			else
			cout<<"No"<<endl;
		}else
		{
			cout<<"No"<<endl;
		}
	}



return 0;	
} 

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

int main () {
	int N, D;
	int X[10][10];
	scanf ("%d %d", &N, &D);
	for (int p=0; p<N; p++)
		for (int d=0; d<D; d++)
			scanf ("%d", &X[p][d]);
	int sum = 0;
	for (int p1=0; p1<N; p1++) {
		for (int p2=p1+1; p2<N; p2++) {
			int tmp = 0;
			for (int d=0; d<D; d++)
				tmp += (X[p1][d] - X[p2][d]) * (X[p1][d] - X[p2][d]);
			int rt = (int) sqrt (tmp);
			if (rt*rt==tmp)
				sum ++;
		}
	}
	printf ("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_V 101
#define MAX_E 1001
#define INF 1e9
 
struct Edge{
    int to,cost;
    Edge(int to,int cost) : to(to),cost(cost) {}
};
 
struct P{
    int d,v,c;
    P(int d,int v,int c) : d(d),v(v),c(c) {}
    bool operator < (const P &p)const{
	if(c != p.c){
	    return c > p.c;
	}else{
	    return d > p.d;
	}
    }
};
 
int V,E,C;
int d[MAX_V][MAX_E];
vector<Edge> G[MAX_V];
 
void init(){
    for(int i = 0 ; i < MAX_V ; i++){
	G[i].clear();
    }
}
 
int dijkstra(){
    fill(d[0],d[0]+MAX_V*MAX_E,INF);
    d[0][0] = 0;
    priority_queue<P> Q;
    Q.push(P(0,0,0));
    while(!Q.empty()){
	P p = Q.top(); Q.pop();
	int v = p.v, c = p.c;
	if(d[v][c] < p.d) continue;
	if(v == V-1 && p.d <= C) return c;
	for(int i = 0 ; i < (int)G[v].size() ; i++){
	    Edge e = G[v][i];
	    if(d[v][c]+e.cost < d[e.to][c]){
		d[e.to][c] = d[v][c]+e.cost;
		Q.push(P(d[e.to][c],e.to,c));
	    }
	    if(d[v][c] < d[e.to][c+1]){
		d[e.to][c+1] = d[v][c];
		Q.push(P(d[e.to][c+1],e.to,c+1));
	    }
	}
    }
    return -1;
}
 
int main(){
    int f,t,c;
    while(cin >> V >> E >> C,V){
	init();
	for(int i = 0 ; i < E ; i++){
	    cin >> f >> t >> c;
	    f--; t--;
	    G[f].push_back(Edge(t,c));
	}
	cout << dijkstra() << endl;
    }
    return 0;
}

Measured memory_bytes: 3508
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC153E();

#if 1
int main()
{
	ABC153E();
	fflush(stdout);
	return 0;
}
#endif

static void ABC153E()
{
	int H, N;
	getint(H, N);

	std::vector<std::pair<int, int>> magics(N);
	for (int i = 0; i < N; i++) {
		getint(magics[i].first, magics[i].second);
	}

	std::vector<int> cost(H + 1, (int)MOD_NUM);
	cost[0] = 0;
	for (int h = 1; h <= H; h++) {
		for (int m = 0; m < N; m++) {
			if ((h < magics[m].first) && (cost[h] > magics[m].second)) {
				cost[h] = magics[m].second;
			}
			if (h >= magics[m].first) {
				cost[h] = std::min(cost[h], (cost[h - magics[m].first] + magics[m].second));
			}
		}
	}

	printf("%d\n", cost[H]);
}


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

int main() {
	// your code goes here
	int X,Y;
	
	while(cin >> X >> Y && X){
	int maps[20][20]={};
	int DP[20][20]={};
	for(int j=1;j<=X;j++)
		DP[1][j]=1;
	for(int i=1;i<=Y;i++)
		for(int j=1;j<=X;j++)
			cin >> maps[i][j];
	for(int i=1;i<=Y-1;i++)
		for(int j=1;j<=X;j++)
			if(maps[i][j]==0){
				for(int k=-1;k<=1;k++)
					if(maps[i+1][j+k]!=2 || k==0)
					DP[i+1][j+k]+=DP[i][j];
			}
			else if(maps[i][j]==2)
					DP[i+2][j]+=DP[i][j];
	int sum=0;
	
	for(int i=Y;i<Y+2;i++)
		for(int j=1;j<=X;j++)
			if(maps[i][j]!=1)
				sum+=DP[i][j];
	cout << sum << endl;
}
	
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
	int n,t,a[100000];
	scanf("%d %d",&n,&t);
	int mi = 1000000001;
	int val = 0,cnt = 0;
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		mi = min(mi,a[i]);
		if(a[i]-mi>val){
			cnt = 1;
			val = a[i] - mi;
		}else if(a[i]-mi==val){
			cnt++;
		}
	}
	printf("%d\n",cnt);
}


Measured memory_bytes: 512
n = gets.to_i
a = gets.split.map(&:to_i).map!{|a| a / 400}.sort!

temp = n
for i in 0..(a.length - 1) do
  if a[i] >= 8
    temp = i
    break
  end
end

if temp != 0
  puts a[0..(temp-1)].uniq.sort.length.to_s + ' ' + (a[0..(temp-1)].uniq.sort.length + (n - temp)).to_s
else
  puts '1 ' + n.to_s
end

Measured memory_bytes: 1788
X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
list.sort(r, reverse=True)

p = p[(A-X):]
q = q[(B-Y):]

i_p = 0
i_q = 0
for i_r in range(C):
    if i_p >= len(p):
        if q[i_q] < r[i_r]:
            q[i_q] = r[i_r]
            i_q += 1
    elif i_q >= len(q):
        if p[i_p] < r[i_r]:
            p[i_p] = r[i_r]
            i_p += 1
    elif p[i_p] <= q[i_q]:
        if p[i_p] < r[i_r]:
            p[i_p] = r[i_r]
            i_p += 1
    else:
        if q[i_q] < r[i_r]:
            q[i_q] = r[i_r]
            i_q += 1

    if i_p >= len(p) and i_q >= len(q):
        break

res = 0

for i in range(len(p)):
    res += p[i]

for i in range(len(q)):
    res += q[i]

print(res)

Measured memory_bytes: 105396
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    hist=[0]*(10**5+1)
    for i in range(n):
        hist[a[i]]+=1
    
    max3=0
    for i in range(10**5-1):
        max3=max(max3,hist[i]+hist[i+1]+hist[i+2])
    return max3

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)



Measured memory_bytes: 20828
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <iostream>
#include <chrono>

using namespace std;

const int DIV = 1000000007;

int main(int argc, char* argv[]) {
#ifdef VLAD_LOCAL
    ifstream in("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &in = cin;
#endif
    int n, k;
    in >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        in >> a[i];
    }
    int l = 0, r = 1e9;
    while (l + 1 < r) {
        int cur = (l + r) / 2;
        int count = 0;
        for (int i = 0; i < n; i++) {
            count += (a[i] - 1) / cur;
        }
        if (count <= k)
            r = cur;
        else
            l = cur;
    }
    printf("%d\n", r);
    
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf\n", seconds);
#endif
	return 0;
}


Measured memory_bytes: 4044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x = br.readLine();
		String[] cut = x.split(" ");
		int a = Integer.parseInt(cut[0]);
		int b = Integer.parseInt(cut[1]);
		int c = Integer.parseInt(cut[2]);
		int d = Integer.parseInt(cut[3]);

		System.out.println(a * b > c * d ? a * b : c * d);

	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <math.h>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  string s, t;
  int a,b;
  cin >> a >> b;

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

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

/* // Ordered Set
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define os_find(k) find_by_order(k)
#define os_order(k) order_of_key(k)
*/

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector<int> vi;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)
// int ncr(int n,int r) {return (fact[n]*modInv(fact[r]))%mod*modInv(fact[n-r])%mod;}
// int modInv(int i) {return binExp(i,mod-2);}

signed main()
{
    fast

    #ifndef ONLINE_JUDGE
        freopen("inputf.in","r",stdin);
        freopen("outputf.in","w",stdout);
    #endif

    // test
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;

        bool zero = 0;
        if(a <= 0 && b >= 0) zero = 1;
        if(c <= 0 && d >= 0) zero = 1;

        int ans = LLONG_MIN;
        if(zero) ans = 0;

        ans = max(ans, b*d);
        ans = max(ans, b*c);
        ans = max(ans, a*d);
        ans = max(ans, a*c);

        cout<<ans;
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <cmath>

bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

    int prev = 11;
    for (int i = 0; i < N; i++)
    {
        while (true)
        {
            if (isPrime(prev))
            {
                std::cout << prev << " ";
                prev += 10;
                break;
            }
            else
            {
                prev += 10;
            }
        }
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <cstring>

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

#define INF (int)1e9+7

static const int dy[4] = {0,1,0,-1};
static const int dx[4] = {1,0,-1,0};

typedef long long ll;

using namespace std;

int main(){
    int a,b;

    cin >> a >> b;

    if(a == b) cout << a + b << endl;
    else{
        int ans = max(a, b);
        cout << ans + ans-1 << endl;
    }
    return 0;
}


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

int main(){
    int n,m,l,r,Min=0,Max=100001;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        Min=max(Min,l);
        Max=min(Max,r);
    }
    cout<<max(0,Max-Min+1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=61;
lli tot[N], s, x, ans;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,a[n];
    
    for(i=0;i<n;i++) cin>>a[i];
    
    s=a[0]+a[1];
    for(i=2;i<n;i++) x^=a[i];
    
    s-=x;
    if(s<0) return cout<<-1, 0;
    for(i=N-1;i>=0;i--)
    {
        if(x & (1LL<<i)) continue;
        
        if(2*(1LL<<i) <= s)
        {
            tot[i]=1;
            s -= (2*(1LL<<i)); 
            ans+=(1LL<<i);
        }
    }
    
    if(ans>a[0] || s) return cout<<-1, 0;
    for(i=N-1;i>=0;i--)
    {
        if((x & (1LL<<i)) && (ans + (1LL<<i)) <= a[0])
        {
            ans += (1LL<<i);
        }
    }
    cout<<(ans==0 ? -1 : (a[0]-ans));
    return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt();
        for(int i = 0; i < n; i++){
            if(a[i] % 2 == 0){
                if(a[i] % 3 != 0 && a[i] % 5 != 0){
                    System.out.println("DENIED");
                    return;
                }
            }
        }
        System.out.println("APPROVED");
        scan.close();
    }
}

Measured memory_bytes: 27180
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
using namespace std;
int main()
{
	int p, q, r;
	cin >> p >> q >> r;
	int a = p + q;
	int b = q + r;
	int c = r + p;
	if (a <= b && a <= c) {
		cout << a;
	}
	else if (b <= a && b <= c) {
		cout << b;
	}
	else {
		cout << c;
	}

	return 0;
}

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

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

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  while(a-1<b){
    b -= (a-1);
    ans++;
  }
  if(b == 1)cout << ans << endl;
  else cout << ans+1 << endl;
}


Measured memory_bytes: 256
#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) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n;
	while(cin>>n,n){
		int x[3000],y[3000];
		set<pair<int,int> > pset;
		REP(i,n){
			scanf("%d %d",&x[i],&y[i]);
			pset.insert(make_pair(x[i],y[i]));
		}
		int ans = 0;
		REP(i,n)FOR(j,i+1,n){
			int x1 = x[i], x2 = x[j], y1 = y[i], y2 = y[j];
			int dx = x2-x1;
			int dy = y2-y1;
			int S = dx*dx+dy*dy;
			if(S < ans) continue;
			if(pset.count(pair<int,int>(x1+dy, y1-dx)) && pset.count(pair<int,int>(x2+dy, y2-dx))){
				ans = max(ans, dx*dx+dy*dy);
			}
			dx *= -1; dy *= -1;
			if(pset.count(pair<int,int>(x1+dy, y1-dx)) && pset.count(pair<int,int>(x2+dy, y2-dx))){
				ans = max(ans, dx*dx+dy*dy);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1076
from scipy.misc import comb
# from scipy.special import comb


MOD = 10 ** 9 + 7

def main():
    N, K = map(int, input().split())

    note = [[-1 for i in range(N)] for j in range(N)]

    def calc_comb(n, r):
        if note[n][r] != -1:
            return note[n][r]
        a = comb(n, r, exact=True)
        note[n][r] = a
        return a

    def print_patterns(i, N, K):
        m = N - K
        if i - 1 > m:
            print(0)
            return
        if i == 1:
            p = 1 * (m+1) % MOD
            print(p)
            return
        p = calc_comb(K-1, i-1) * calc_comb(m+1, i) % MOD
        print(p)

    for i in range(1, K+1):
        print_patterns(i, N, K)


main()

Measured memory_bytes: 45956
#include <bits/stdc++.h>
using namespace std;
const long long N=2e5;
long long a[N+5],cont[N+5];
long long ans[N+5];
int main() {
	long long n;
	cin>>n;
	vector < long long > v;
	set < long long > vis;
	for(long long i=0;i<n;i++) {
		cin>>a[i];
		if(vis.count(a[i])==0) v.push_back(a[i]);
		cont[a[i]]++;
		vis.insert(a[i]);
	}
	long long sum=0;
	for(long long i=0;i<v.size();i++) {
		sum+=cont[v[i]]*(cont[v[i]]-1)/2;
	}
	for(long long i=0;i<n;i++) {
		cout<<sum-(cont[a[i]]-1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 11764
import java.util.*;

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

      long A=sc.nextLong();
      long B=sc.nextLong();
      long C=sc.nextLong();
      long D=sc.nextLong();
      long cnt=0;

      long lcmCD;
      long numAC,numAD,numACD,numBC,numBD,numBCD;
      long ansA,ansB,ans;

      lcmCD=lcm(C,D);

      numAC=(A-1)/C;  //A未満でCの倍数の個数(切り捨てされる)
      numAD=(A-1)/D;  //A未満でDの倍数の個数(切り捨てされる)
      numACD=(A-1)/lcmCD;  //A未満でLCM(C,D)の倍数の個数(切り捨てされる)
      ansA=(A-1)-(numAC+numAD-numACD);  //A未満でC,D,LCMで割り切れない数

      numBC=B/C;  //B以下でCの倍数の個数(切り捨てされる)
      numBD=B/D;  //B以下でDの倍数の個数(切り捨てされる)
      numBCD=B/lcmCD;  //B以下でLCM(C,D)の倍数の個数(切り捨てされる)
      ansB=B-(numBC+numBD-numBCD);  //B以下でC,D,LCMで割り切れない数

      ans=ansB-ansA;

      System.out.println(ans);
    }

  public static long gcd(long i,long j){
    if(i<j){return gcd(j,i);} //大きい方をiとして再実行}
    if(i%j==0){return j;}
    else{return gcd(j,i%j);}
  }
  public static long lcm(long i,long j){
    return i*j/gcd(i,j);
  }

}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n;cin>>n;
    ll x[n];rep(i,0,n-1)cin>>x[i];
    ll ans=inf;
    ll sum=0;
    rep(i,1,100){
        sum=0;
        rep(j,0,n-1){
            sum+=pow(x[j]-i,2);
        }
        ans=min(ans,sum);
    }
    cout<<ans<<endl;
    
    return 0;
}



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

int compare_int(const void *a, const void *b) {
  long *A = (long *)a;
  long *B = (long *)b;
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

int main(){
  int N,K;
  int i,j;
  long k=10000000000000;
  scanf("%d %d",&N,&K);
  
  long A[N];
  for(i=0;i<N;i++)
    scanf("%ld",&A[i]);
  
  qsort(A, N, sizeof(long), compare_int);
  
  for(i=0;i<N-K+1;i++){
    if(k > A[i+K-1]-A[i])
      k=A[i+K-1]-A[i];
  }
  
  printf("%ld\n",k);
  return 0;
}
  



Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
	
	char right[11]={'y','u','i','o','p','h','j','k','l','n','m'};
	string s;
	while(1){
		int flag=0;
		cin>>s;
		if(s=="#")break;
		int cnt=0;
		
		for(int i=0;i<11;i++){
			if(s[0]==right[i]){
				flag=1;
				break;
			}
		}
		
		for(int i=1;i<s.size();i++){
			for(int j=0;j<11;j++){
				if(s[i]==right[j]){
					if(flag==0)cnt++;
					flag=1;
					break;
				}
				if(j==10){
					if(flag==1)cnt++;
					flag=0;
				}
			}
			//out<<cnt<<" ";
			
		}
		cout<<cnt<<endl;
		
	}
	return 0;
}

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

int main(int argc, char *argv[])
{
    int N;
    cin >> N;
    int res = 0;
    int min_element = 1e9;
    for (int i = 0; i < N; i++) {
        int v;
        cin >> v;
        if (v <= min_element) res++;
        min_element = min(min_element, v);
    }
    cout << res << "\n";
    return 0;
}


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

#define int long long
#define ALL(x) x.begin(),x.end()
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb(x) push_back(x)
#define eb emplace_back
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend()) 
#define mp(x, y) make_pair(x, y)
#define INF 1000000000
#define MOD 1000000007
#define F(i, a, n) for(i=a;i<n;i++)
#define SI(x) cin>>x
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define FI(w, x, y, z) cin>>w>>x>>y>>z
#define SO(x) cout<<x<<"\n"
#define DO(x, y) cout<<x<<" "<<y<<"\n"
#define TO(x, y, z) cout<<x<<" "<<y<<" "<<z<< "\n"
#define FO(w, x, y, z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<"\n"
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

bool solve()
{  
    int i, j;
    int n;
    SI(n);
    multiset<int> ms;
    vi v(1<<n);
    F(i, 0, 1 << n)
        SI(v[i]);
    sort(v.begin(), v.end());
    vi x;
    x.pb(v[(1<<n) - 1]);
    F(i, 0, (1<<n) - 1)
        ms.insert(v[i]);
    F(j, 0, n)
    {
        vi w = x;
        for(int i: x)
        {
            auto it = ms.lower_bound(i);
            if(it == ms.begin())
                return false;
            --it;
            w.push_back(*it);
            ms.erase(it);
        }
        DESC(w);
        x = w;
    }
    return true;
}

int32_t main(void)
{
    FASTER;
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    if(solve())
        SO("Yes");
    else
        SO("No");
    #ifdef LOCAL
    	cout<<endl<<endl<<"Time: "<<(float)clock()/CLOCKS_PER_SEC<<" seconds"<<endl;
    #endif
    return 0;
}


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


int main() {
  char x[4] = {'A', 'C', 'G', 'T'};

  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int tmp = 0;
    for (int j = i; j < n; ++j) {
      bool ok = false;
      for (int k = 0; k < 4; ++k) {
	if (s[j] == x[k]) ok = true;
      }
      if (ok) tmp++;
      else break;
    }
    ans = max(ans, tmp);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
def main():
    ans, m_rem = 0, 0
    for _ in range(5):
        m = int(input())
        rem = m % 10
        if rem == 0:
            ans += m
        else:
            m_rem = max(m_rem, 10 - rem)
            ans += m + 10 - rem
    print(ans - m_rem)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <stdio.h>
int num[100];
int main() {
	int i, j, ans, s, N;
	while(1) {
		scanf("%d", &N);
		if(N == 0) break;
		for(i = 0; i < N; ++ i) scanf("%d", &num[i]);
		ans = 0;
		for(i = N; i > -1; -- i) {
			for(j = 1; j < i; ++ j) {
				if(num[j - 1] > num[j]) {
					ans ++; s = num[j - 1]; num[j - 1] = num[j]; num[j] = s;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 600
def combination():
    cnt = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    cnt += 1
    return cnt

while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break

    print(combination())



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
 
#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define loopi(n) for(int i=0;i<n;i++)
#define loopj(n) for(int j=0;j<n;j++)
#define loop(a,b,c) for(int i=a;i<=b;i=i+c)
 
#define     all(x)      (x).begin(),(x).end()
#define     reset(a)    memset(a,0,sizeof(a))
#define     sz(x)       ((int)(x.size()))
#define     pb          push_back
#define     pf          push_front
#define     pob	        pop_back
#define     pof         pop_front
#define     ins         insert
#define     F           first
#define     S           second
#define     mkp         make_pair
#define     mkt         make_tuple
#define     bitcount(x) __builtin_popcountll(x)
#define     gcd(a,b)    (__gcd(a,b))
#define     lcm(a,b)    ((a*b)/gcd(a,b))
 
const int mod=1e9+7;

void solve()
{
	int n;
	cin>>n;
	int c=0,ans=0;
	loopi(n)
	{
		int x,y;
		cin>>x>>y;
		if(x==y)
		{
			c++;
			if(c==3)
				ans=1;
		}
		else
			c=0;
	}
	cout<<(ans?"Yes":"No");
}
 
int main() 
{
	sync;
 
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		cout<<endl;
	} 
} 
	

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

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

  if(N==0) break;

  int cnt0 = 0;
  int cnt1 = 0;

  for(int i=0; i<N; i++){
   int k;
   cin >> k;
   
   if(k==0){
    cnt0++;
   }else if(k==1){
    cnt1++;
   }
  }
  
  if(cnt0+cnt1==N){
   cout << "NA" <<endl;
  }else{
   cout << N-cnt0+1 << endl;
  }
 }

 return 0;
}

Measured memory_bytes: 3076
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 20:57:31 2019
//
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var N int
	fmt.Scan(&N)

	ans := 1
	for i := 0; i < N; i++ {
		var t int
		fmt.Scan(&t)
		ans = ans * (t / gcd(ans, t))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    int x;
    vector<queue<int>> b(n);
    rep(i,n)rep(j,n-1){
        cin>>x;
        x --;
        b[i].emplace(x);
    }
    set<int> seen;
    int ans=-1;
    bool f=1;
    while(f){
        f=0;
        rep(i,n){
            if(b[i].empty()) continue;
            int op=b[i].front();
            if(op<i) continue;
            if(seen.count(op) || seen.count(i)) continue;
            if(b[op].front() != i) continue;
            f=1;
            b[i].pop();
            b[op].pop();
            seen.insert(op);
            seen.insert(i);
        }
        ans ++;
        seen.clear();
    }
    rep(i,n){
        if(!b[i].empty()){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 8056
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
unordered_map<int,int>mp;
bool solve(vector<double>a,vector<double>b){
   double dist;
   int d=a.size();
   double sum=0;
   for(int i=0;i<d;i++){
      sum+=abs(a[i]-b[i])*abs(a[i]-b[i]);
   }
   return mp.count(sum);
}
int main(void){
   int n,d;
   cin>>n>>d;
   int i=1;
   while(i<=20000){
      mp[i*i]=true;
      i++;
   }
   vector<vector<double>>num(n,vector<double>(d));
   for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
         cin>>num[i][j];
      }
   }
   int ans=0;
   for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
         vector<double>a,b;
         a=num[i];
         b=num[j];
         if(solve(a,b)){
            ans++;
         }
      }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
//for study and upsolving. other coder's code.
using namespace std;
 
const ll Mod = 1e9 + 7;
 
ll Rec(ll i,ll Mask);
 
ll n;
ll a[22][22];
ll Dp[22][1<<22];
 
int main()
{
    memset(Dp,-1,sizeof(Dp));
 
    cin>>n;
 
    for(ll i=0;i<n;i++)
        for(ll j=0;j<n;j++)
            scanf("%I64d",&a[i][j]);
 
    cout<<Rec(0,0);
}
 
ll Rec(ll i,ll Mask)
{
    if(i==n)    return 1;
 
    if(Dp[i][Mask]+1)   return Dp[i][Mask];
 
    ll Res = 0;
 
    for(ll j=0;j<n;j++)
        if(!(Mask&(1<<j))&&a[i][j])
            Res += Rec(i+1,Mask|(1<<j));
 
    return Dp[i][Mask] = Res%Mod;
}

Measured memory_bytes: 721152
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <string>

typedef long long ll;


using namespace std;
int main() {
    string s;
    cin >> s;
    ll o,z;
    for (auto c:s){
        if(c=='1'){o++;}else{z++;}
    }
    cout << min(o,z)*2 << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

void out(int st,int now,int &cnt){
	if(cnt!=0) cout<<" ";
	if(st!=now) cout<<st<<"-"<<now;
	else cout<<st;
	cnt++;
	//cout<<" "<<cnt;
}

signed main(){
	int n;
	while(cin>>n && n!=0){
		vi d(n+1);
		rep(i,0,n) cin>>d[i];
		d[n]=1e9;
		int cnt=0,st=d[0];
		rep(i,1,n+1){
			if(d[i]!=d[i-1]+1){
				out(st,d[i-1],cnt);
				st=d[i];
				//cnt++;
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1192