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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }


int n;
int x[8],y[8];

int main()
{
  fastio();

  cin >> n;
  forn(i,n) cin >> x[i] >> y[i];

  long double f = 1;
  forn1(i,n) f *= i;

  vi v;
  forn(i,n) v.push_back(i);

  long double total = 0;
  do {
    forn1(i,n-1) {
      long double dx = x[v[i]]-x[v[i-1]];
      long double dy = y[v[i]]-y[v[i-1]];
      total += sqrt(dx*dx + dy*dy);
    }

  } while (next_permutation(all(v)));

  cout << setprecision(20) << total / f << endl;

  return 0;
}


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

using namespace std;
typedef long long LL;

int main(){
  int N;
  cin >> N;
  vector<int> A,B;
  int a,b;
  for(int i = 1; i <= N + 1; ++i) {
    cin >> a;
    A.push_back(a);
  }
  for(int i = 1; i <= N; ++i) {
    cin >> b;
    B.push_back(b);
  }

  LL cnt = 0;
  for(int i = 0; i < N; ++i) {
    cnt += min(A[i], B[i]);
    B[i] -= min(A[i], B[i]);
    cnt += min(A[i+1], B[i]);
    A[i+1] -= min(A[i+1], B[i]);
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
 
int main(){
    int n;
    cin >> n;
    priority_queue<long long> q;
    long long a;
    rep(i,n){
        cin >> a;
        q.push(a);
    }
    long long a0,a1;
    int frag = 0;
    a0 = q.top();
    q.pop();
    rep(i,n-1){
        a1 = q.top();
        if (a0 == a1){
            frag = 1;
            break;
        }
        a0 = a1;
        q.pop();
    }
    if (frag == 1) cout << "NO";
    else cout << "YES";

    

    return 0;
}

Measured memory_bytes: 2420
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    h = ri()
    w = ri()
    n = ri()
    m = max(h, w)
    print((n+m-1)//m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define MOD 998244353
int iso_lower(vector<int> V, int x) {
    //ソートされたVの中から、V[i]>=xとなる最小のiを返す.存在しなければVの要素数を返す
    int s = V.size();
    //V.push_back(INF);
    int l = -1;
    int r = s;  //rが常にtrue
    while(r - l > 1) {
        int mid = (l + r) / 2;
        if(V[mid] < x)
            l = mid;
        else
            r = mid;
    }
    return r;
}
signed main(){
    int N,X,M;cin>>N>>X>>M;
    vector<int>Ru;
    Ru.push_back(-1);
    vector<int>Ju(M,-1);
    Ru.push_back(X);Ju[X]=1;
    int now=1,a=X;
    int fi,en;
    while(true){
        now++;
        a=(a*a)%M;
        Ru.push_back(a);
        if(now==N){
            int ans=0;
            for(int i=1;i<=N;i++){
                ans+=Ru[i];
            }
            cout<<ans<<endl;
            return 0;
        }
        if(Ju[a]==-1){
            Ju[a]=now;
            continue;
        }
        else{
            fi=Ju[a];
            en=now;
            break;
        }
    }
    int ans=0;
   // for(auto x:Ru)cout<<x<<' ';
    //cout<<endl;
    rep(i,fi-1)ans+=Ru[i+1];
    int roop=0;
    for(int i=fi;i<en;i++)roop+=Ru[i];
    int length=en-fi;
    int K=(N-fi+1)/length;
    ans+=roop*K;
    for(int i=1;i<=N-fi-length*K+1;i++){
        ans+=Ru[i+fi-1];
    }
    cout<<ans<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<char>> s(n, vector<char>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> s.at(i).at(j);
        }
    }

    int cnt = 0;
    for (int b = 0; b < n; b++) {
        bool ok = true;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                if (s.at(i).at((j + b) % n) != s.at(j).at((i + b) % n)) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) cnt += n;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 384
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		UnionFind u = new UnionFind(n);

		for (int i = 0; i < q; i++) {
			int com = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();

			if (com == 0) { // unite
				u.unite(x, y);
			} else { // same
				if (u.same(x, y)) {
					out.println(1);
				} else {
					out.println(0);
				}
			}
		}

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}

class UnionFind {

	int[] par;

	public UnionFind(int size) {
		par = new int[size];
		Arrays.fill(par, -1);
	}

	public int root(int x) {
		if (par[x] < 0) {
			return x;
		}
		int z = root(par[x]);
		par[x] = z;
		return z;
	}

	public boolean same(int a, int b) {
		return root(a) == root(b);
	}

	public void unite(int a, int b) {
		if (!same(a, b)) {
			int ra = root(a);
			int rb = root(b);

			if (par[ra] < par[rb]) {
				par[ra] += par[rb];
				par[rb] = ra;
			} else {
				par[rb] += par[ra];
				par[ra] = rb;
			}
		}
	}

	public int size(int a) {
		return -par[root(a)];
	}

}


Measured memory_bytes: 102392
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
	char a[105], b[105], c[105];
	scanf("%s %s %s", a, b, c);
	int lena = strlen(a);
	int lenb = strlen(b);
	int lenc = strlen(c);
	int ka = 0, kb = 0, kc = 0;
	char n = a[ka];
	while(1)
	{
		if(ka > lena)
		{
			printf("A\n"); return 0;
		}
		if(kb > lenb)
		{
			printf("B\n"); return 0;
		}
		if(kc > lenc)
		{
			printf("C\n"); return 0;
		}
		if(n == 'a') {n = a[ka]; ka++; continue;}
		if(n == 'b') {n = b[kb]; kb++; continue;}
		if(n == 'c') {n = c[kc]; kc++; continue;}
		}
	}

Measured memory_bytes: 128
/*input
3
0 1 1 2
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e5+5;
const ll maxlg=__lg(maxn)+5;
ll arr[maxn];
ll pref[maxn];
int main(){
    int n;
    cin>>n;
    if(n==0){
        int x;
        cin>>x;
        if(x!=1) cout<<-1;
        else cout<<1;
        return 0;
    }
    ll tot=0;
    REP(i,n+1){
        cin>>arr[i];
        tot+=arr[i];
    }
    ll ans=0;
    ll cur=1;
    REP(i,n+1){
        ans+=cur;
        if(cur<arr[i]){
            cout<<-1;
            return 0;
        }
        cur-=arr[i];
        cur*=2;
        tot-=arr[i];
        MNTO(cur,tot);
    }
    cout<<ans;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s[100001];
ll n,cnt=1,ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (int i=0;i<n;++i) cin>>s[i],sort(s[i].begin(),s[i].end());
	sort(s,s+n);
	//for (int i=0;i<n;++i) cout<<s[i]<<endl;
	for (int i=1;i<n;++i)
	{
		if (s[i]==s[i-1])
		{
			++cnt;
			continue;
		}
		ans=ans+cnt*(cnt-1)/2;
		cnt=1;
	}
	ans=ans+cnt*(cnt-1)/2;
	cout<<ans;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int K;
    cin >> K;
    vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << a[K - 1] << endl;
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> hoge(n);
	map<int,int> mp;

	for(int i=0;i<n;i++){
		int a;
		cin>>a;

		if(mp.count(a)) mp.at(a)++;
		else mp[a]=1;

		hoge.at(i)=a;
	}

	int ans=0;

	for(auto a:hoge){
		int b=mp.at(a);

		if(b>=a) ans+=b-a;
		else ans+=b;

		mp.at(a)=a;
	}

	cout<<ans<<endl;

	return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}
string str,qtr;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll i,c=0;

	cin >> str;
	cin >> qtr;
	for(i=0;i<(int)str.size();++i)
	{
		if(str[i] != qtr[i])
			c++;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793
const int INF = 100000000;
int dx[] = {0,1,-1,0,1,-1,1,-1};
int dy[] = {1,0,0,-1,1,-1,-1,1};

int main(){
    int s;
    cin >> s;
    unordered_map<int, int> m;
    m[s]++;
    int tmp = s;
    int ans = 1;
    while(1){
        if(tmp % 2)
            tmp = 3 * tmp + 1;
        else
            tmp /= 2;
        ans++;
        if(m[tmp])
            break;
        else
            m[tmp]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
 
        String sentence;
        int[] abc = new int[26];
 
        while ((sentence = input.readLine()) != null) {
            for (int i = 0; i < sentence.length(); i++) {
                char c = sentence.charAt(i);
                     c = Character.toLowerCase(c);
                char cc = 'a';
                for (int j = 0; j < abc.length; j++) {
                    if (cc == c)
                        abc[j]++;
                    cc++;
                }
            }
        }
 
        char cc = 'a';
        for (int i = 0; i < abc.length; i++) {
            System.out.println(cc + " : " + abc[i]);
            cc++;
        }
    }
 
}

Measured memory_bytes: 24156
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
int A[3005];
int V[3005][3005];
const int MOD = 1e9 + 7;
int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			if (A[i] < A[j]) ++V[i][j];
	ll half = 500000004;
	ll p2 = 1;
	for (int i = 0; i < q; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		vector<pair<pair<int, int>, int>> updates;
		auto add = [&](int c, int d, int v) {
			updates.push_back({{c, d}, v});
		};
		add(y, x, V[x][y]);
		add(x, y, V[y][x]);
		for (int a = 1; a <= n; ++a) {
			if (a == y || a == x) continue;
			add(a, x, V[a][y]);
			add(x, a, V[y][a]);
			add(a, y, V[a][x]);
			add(y, a, V[x][a]);
		}
		for (auto u : updates) {
			int& v = V[u.first.first][u.first.second];
			v += u.second;
			v = v * half % MOD;
		}
		p2 = p2 * 2 % MOD;
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		assert(!V[i][i]);
		for (int j = 1; j < i; ++j) {
			ans += V[i][j];
			ans %= MOD;
		}
	}
	ans = ans * p2 % MOD;
	printf("%lld\n", ans);
}


Measured memory_bytes: 35872
fun main(args: Array<String>?): Unit {
    val money = IntArray(100001){0}
    val (n, d, x) = readLine()!!.trim().split(' ').map(String::toInt)
    var current = x
    val prices = List(d){ readLine()!!.trim().split(' ').map(String::toInt)}
    for (i in 1 until d) {
        money.fill(-1)
        for (j in 0 .. current) money[j] = j
        for (p in 0 until n) {
            if (prices[i][p] > prices[i - 1][p]) for (j in prices[i - 1][p] .. current) {
                if (money[j - prices[i - 1][p]] + prices[i][p] > money[j]) {
                    money[j] = money[j - prices[i - 1][p]] + prices[i][p]
                }
            }
        }
        current = money[current]
    }
    println(current)
}



Measured memory_bytes: 33692
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>
#include<functional>
using namespace std;

#define MAX_N 200
#define INF 101010101

int N,M,L,K,A,H,a1,a2,a3;
vector<pair<int,int>>X[MAX_N];
int dp[MAX_N][MAX_N];
int p[MAX_N];

priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>>Q;

int main(){
	while(true){
		for(int i=0;i<MAX_N;i++){
			for(int j=0;j<MAX_N;j++){
				dp[i][j]=INF;
			}
		}
		for(int i=0;i<MAX_N;i++){
			X[i].clear();
			p[i]=0;
		}
		cin>>N>>M>>L>>K>>A>>H;
		if(N==0 && M==0 && L==0 && K==0 && A==0 && H==0){
			break;
		}
		for(int i=0;i<L;i++){
			cin>>a1;
			p[a1]=1;
		}
		for(int i=0;i<K;i++){
			cin>>a1>>a2>>a3;
			X[a1].push_back(make_pair(a2,a3));
			X[a2].push_back(make_pair(a1,a3));
		}
		Q.push(make_tuple(0,A,M));
		dp[A][M]=0;
		while(!Q.empty()){
			tuple<int,int,int>tup=Q.top();
			Q.pop();
			int b1=get<0>(tup);
			int b2=get<1>(tup);
			int b3=get<2>(tup);
			if(b3<M && p[b2]==1){
				if(dp[b2][b3+1]>dp[b2][b3]+1){
					dp[b2][b3+1]=dp[b2][b3]+1;
					Q.push(make_tuple(dp[b2][b3+1],b2,b3+1));
				}
			}
			for(int i=0;i<X[b2].size();i++){
				int c1=X[b2][i].first;
				int c2=X[b2][i].second;
				if(b3>=c2){
					if(dp[c1][b3-c2]>dp[b2][b3]+c2){
						dp[c1][b3-c2]=dp[b2][b3]+c2;
						Q.push(make_tuple(dp[c1][b3-c2],c1,b3-c2));
					}
				}
			}
		}
		int minx=INF;
		for(int i=0;i<=M;i++){
			minx=min(minx,dp[H][i]);
		}
		if(minx==INF){
			cout<<"Help!"<<endl;
		}
		else{
			cout<<minx<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3352
from collections import defaultdict

N = int(input())

d = defaultdict(int)

for i in range(0, N):
    s = input().strip()
    d[s] = d[s] + 1

max_ids = []
max_count = 0
for k, v in d.items():
    if v > max_count:
        max_ids = []
        max_ids.append(k)
        max_count = v
    elif v == max_count:
        max_ids.append(k)

for s in sorted(max_ids):
    print(s)



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

typedef long long ll;

ll div_num(ll x, ll y){
    return x / y;
}
ll lcm(ll x, ll y) {
    ll original_x = x;
    ll original_y = y;
    ll r = x % y;
    while (r != 0) {
        x = y;
        y = r;
        r = x % y;
    }
    ll gcd = y;
    return original_x / gcd * original_y; 
}
 
int main(){
long long A, B, C, D;   cin >> A >> B >> C >> D;
long long N = B - A + 1;
cout << N - (div_num(B, C) - div_num(A - 1, C)) - (div_num(B, D) - div_num(A - 1, D)) + (div_num(B, lcm(C, D)) - div_num(A - 1, lcm(C, D))) << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  int a[n];
  REP(i,n) cin >> a[i];
  sort(a, a+n, greater<int>());
  int ans = 0;
  REP(i,n) {
    if (i % 2 == 0) ans += a[i];
    else ans -= a[i];
  }
  COUT(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 100;

using namespace std;

typedef long long ll;
typedef long double ld;

int c, n, m, s, d;
int C[101][101], D[101][101];
int DP[101][16];

// co=割引券, cost=現在の値段
void solve(int st, int co, int cost) {
  if (st == d-1) {
    return;
  }
  // 次の町探し
  rep(i, n) {
    if (i == st || C[st][i] == INFTY) {
      continue;
    }
    int tmp = cost + C[st][i];
    int tmp2 = cost + C[st][i]/2;
    if (DP[i][co] > tmp) {
      DP[i][co] = tmp;
      solve(i, co, tmp);
    }
    if (co < c && DP[i][co+1] > tmp2) {
      DP[i][co+1] = tmp2;
      solve(i, co+1, tmp2);
    }
  }
}


int main() {
  while (cin >> c >> n >> m >> s >> d, c) {
    rep(i, n) {
      rep(j, n) {
        C[i][j] = INFTY;
        D[i][j] = INFTY;
      }
      rep (q, c+1) {
        DP[i][q] = INFTY;
      }
    }
    rep(i, m) {
      int a,b,f;
      cin >> a >> b  >> f;
      C[a-1][b-1] = f;
      C[b-1][a-1] = f;
    }
    solve(s-1, 0, 0);
    int res = INFTY;
    rep(i, c+1) {
      res = min(res, DP[d-1][i]);
    }
    cout << res << endl;
  }
  return 0;
}



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

using namespace std;

int main() {
  long long a, v, b, w, t = 0;
  cin >> a;
  cin >> v;
  cin >> b;
  cin >> w;
  cin >> t;

  if (abs(a - b) <= (v - w) * t) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
ll dp[55][55][5000];

signed main(){
	//cout << fixed << setprecision(10);
	ll n,k; cin>>n>>k;
	vl a(n);
	rep(i,0,n)cin>>a[i],a[i]--;
	vl s;
	vl t(n+1,-1);
	ll v=0;
	while(t[v]==-1){
		t[v]=s.size();
		s.push_back(v);
		v=a[v];
	}
	ll c = s.size()-t[v];
	ll l = t[v];
	if(k<l)cout << s[k]+1<< endl;
	else{
		k-=l;
		k%=c;
		cout << s[k+l]+1<<endl;
	}



	return 0;
}

Measured memory_bytes: 8500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int n;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// n = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		int k = Integer.parseInt(str[1]);

		str = br.readLine().split(" ");

		int a[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(str[i]);
		}

		Arrays.sort(a);

		long sum = 0;
		for (int i = 0; i < n - k; i++) {
			sum += a[i];
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 55508
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        if(inpt[0]%inpt[1]==0) {
            Console.WriteLine(-1);
            return;
        }
        for (long i = inpt[0]; i < long.MaxValue; i+=inpt[0]) {
            if(i%inpt[1]!=0) {
                Console.WriteLine(i);
                return;
            }
        }
        Console.WriteLine(-1);
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"

3 3


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int n;
    long T;
    cin>>n>>T;
    vector<long> t(n);
    for(int i=0;i<n;i++) cin>>t[i];

    long sum=0;
    for(int i=0;i<=n-2;i++){
        sum+=min(T,t[i+1]-t[i]);
    }
  sum+=T;
    cout<<sum<<endl;
}    

Measured memory_bytes: 1792
#include <stdio.h>
#define SIZE 1000
int main()
{
	unsigned int star[SIZE], stop[SIZE], diff[SIZE], sum = 0;
	int i, N;
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d %d", &star[i], &stop[i]);
		diff[i] = stop[i] - star[i] + 1;
		sum += diff[i];
	}
	
	printf("%d", sum);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a <= b && c <= d){
       cout << a+c << endl;
}
   else if(a <= b && c >= d){
       cout << a+d << endl;
}
else if(a >= b && c <= d){
       cout << b+c << endl;
}
else if(a >= b && c >= d){
       cout << b+d << endl;
}

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int last[26];
int c[26];
int s[365][26];
int a[365];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    for(int i=0;i<26;i++){
    	cin >> c[i];
    }
    for(int i=0;i<d;i++){
    	for(int j=0;j<26;j++){
    		cin >> s[i][j];
    	}
    }
    for(int i=0;i<d;i++){
    	cin >> a[i];
    }
    int res=0;
    for(int i=0;i<d;i++){
    	res+=s[i][a[i]-1];
    	last[a[i]-1]=i+1;
    	for(int j=0;j<26;j++){
    		res-=c[j]*(i+1-last[j]);
    	}
    }
    int q; cin >> q;
    while(q--){
        int day,qq; cin >> day >> qq;
        int qqq=a[day-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            res+=c[qq-1]*(i+1-last[qq-1]);
            res+=c[qqq-1]*(i+1-last[qqq-1]);
        }
        a[day-1]=qq;
        res-=s[day-1][qqq-1];
        res+=s[day-1][qq-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            res-=c[qq-1]*(i+1-last[qq-1]);
            res-=c[qqq-1]*(i+1-last[qqq-1]);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 3684
#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

unsigned long long int
calcgcd(unsigned long long int a,
            unsigned long long int b) {
  unsigned long long int buf;
  while(b!=0) {
    buf = b;
    b = a % b;
    a = buf;
  }
  return a;
}

unsigned long long int
gcd(unsigned long long int a,
        unsigned long long int b,
        unsigned long long int c) {
  unsigned long long int buf = calcgcd(a,b);
  if (buf>c) {
    return calcgcd(buf, c);
  } else {
    return calcgcd(c, buf);
  }
}

unsigned long long int
gcd_loader(unsigned long long int a,
               unsigned long long int b,
               unsigned long long int c) {
  unsigned long long int buf;
  if (a<b) {
    buf = a;
    a = b; b = buf;
  }
  if (b<c) {
    buf = b;
    b = c; c = buf;
  }
  if (a<b) {
    buf = a;
    a = b; b = buf;
  }
  return gcd(a, b, c);
}

int main () {
  unsigned long long int input;
  unsigned long long int sum = 0;
  cin>>input;
  for (int i = 1; i <= input; i++) {
    for (int j = 1; j <= input; j++) {
      for (int k = 1; k <= input; k++) {
        sum += gcd_loader(i, j, k);
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3636
/*
   Username : moondancer
   Name : Moon Dancer
*/


#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin>>s;
    int ans=0;
    for(char i:s){
        int x=i-'0';
        ans=(ans+x)%9;
    }
    if(ans%9==0)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 1e9 + 7;
int h, w;
int dp[111][111] = {};
string board[111];

signed main() {
    cin>>h>>w;
    for (int i = 0; i < h; i++) {
        cin>>board[i];
    }
    dp[0][0] = board[0][0] == '#';
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (i == j && j == 0) continue;
            if (i == 0) {
                dp[i][j] = dp[i][j - 1] + (board[i][j - 1] == '.' && board[i][j] == '#');
            } else if (j == 0) {
                dp[i][j] = dp[i - 1][j] + (board[i - 1][j] == '.' && board[i][j] == '#');
            } else {
                dp[i][j] = min(
                    dp[i][j - 1] + (board[i][j - 1] == '.' && board[i][j] == '#'),
                    dp[i - 1][j] + (board[i - 1][j] == '.' && board[i][j] == '#')
                );
            }
        }
    }
    cout<<dp[h - 1][w - 1]<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
#define vl vector<ll>
#define vi vector<int>
 
#define ff first
#define ss second
 
#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
 
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
ll sqr(ll x){return x*x;}
inline ll add(ll a, ll b){ ll c = a + b; if(c >= MOD) c -= MOD; return c; }
inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
const int nax = 1000*1000 + 10;
const int MAX_  = 5e6 + 2;
ll fac[MAX_];
ll inv[MAX_];
ll facinv[MAX_];

ll power(ll a,ll b){
    ll ans = 1LL;
    while(b){
        if(b&1){
            ans = mul(ans,a);
            b--;
        }
        else{
            a = mul(a,a);
            b /= 2;
        }
    }
    return ans;
}

void furious()
{
    fac[1] = 1;fac[0] = 1;
    inv[0] = inv[1] =1 ;
    facinv[0]= facinv[1] = 1;
    for(int i =2;i<MAX_;i++)
    {
        fac[i] = (i*fac[i-1])%MOD;
        inv[i] = (inv[MOD % i] * (MOD - MOD/i))%MOD;
        facinv[i] = (inv[i] * facinv[i-1])%MOD;
    }
}

ll ncrm(ll n, ll r){
   if(n==r || r==0){
       return 1;
   }
   if(n<r){
       return 0;
   }
   return mul(fac[n],mul(facinv[r],facinv[n-r]));
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    furious();
    ll k; cin>>k;
    string str; cin>>str;
    ll n = str.size();
    n += k;
    ll pos = power(26,n);
    for(int i = 0;i<str.size();++i){
        ll val = mul(ncrm(n,i) , power(25,n-i));
        pos = sub(pos,val);
    }
    cout << pos;

    

    return 0;
}
    

// Химаншу


Measured memory_bytes: 121440
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    vector<int> a(9);
    cin >> a[0] >> a[1] >> a[2];
    cin >> a[3] >> a[4] >> a[5];
    cin >> a[6] >> a[7] >> a[8];
    int n;
    cin >> n;
    REP(i, n) {
        int tmp;
        cin >> tmp;
        auto idx = find(a.begin(), a.end(), tmp);
        if(idx!=a.end()) a[(idx-a.begin())] = 0;
    }
    REP(i, 9) {
        //cout << a[i] << endl;
    }
    if(((a[0]==a[1]) && (a[1]==a[2])) ||
        ((a[3]==a[4]) && (a[4]==a[5])) ||
        ((a[6]==a[7]) && (a[7]==a[8])) ||
        ((a[0]==a[3]) && (a[3]==a[6])) ||
        ((a[1]==a[4]) && (a[4]==a[7])) ||
        ((a[2]==a[5]) && (a[5]==a[8])) ||
        ((a[0]==a[4]) && (a[4]==a[8])) ||
        ((a[2]==a[4]) && (a[4]==a[6]))
    ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll K,m=0,n;
  cin >> K;
  n=7%K;
  rep(i,K){
    m*=10;
    m+=7;
    m%=K;
    if(m==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
      
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 3e5+1;
int n, a[N], b[N], ans[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  scanf("%d", &n);
  FOR(i, 0, n){
    int c;
    scanf("%d", &c);
    b[a[c]]--;
    b[++a[c]]++;
  }
  int s=0, t=n;
  FORR(i, n, 1){
    maxs(ans[t/i], i);
    t -= s += b[i];
  }
  FORR(i, n, 1) maxs(ans[i-1], ans[i]);
  FOR(i, 1, n+1) printf("%d\n", ans[i]);
}

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

typedef struct {
    int x;
    int y;
} point_t;
point_t a[300*300*2];
long b[300*300*2];

inline long dist(const point_t& a, const point_t& b){
    return labs(a.x-b.x)+labs(a.y-b.y);
}

int main(void){
    long h, w, d;
    cin >> h >> w >> d;
    for (long i = 0; i < h; i++) {
        for (long j = 0; j < w; j++) {
            long t;
            cin >> t;
            point_t p;
            p.x=j;
            p.y=i;
            a[t] = p;
        }
    }
    for (long i = 0; i < h*w; i++) {
        b[i+d] = b[i] + dist(a[i], a[i+d]);
    }
    /*
    for (long i = 0; i < h*w; i++) {
        cout << b[i] << endl;
    }
    */
    long q;
    cin >> q;
    for (long i = 0; i < q; i++) {
        long l, r;
        cin >> l >> r;
        long sum = b[r] - b[l];
        /*
        for(long j=l; j<r; j+=d){
            sum += b[j];
        }
        */
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#define N 8

using namespace std;

int main(){
  int i, j;
  string data[N];

  for(i=0; i<N; ++i)
    cin >> data[i];

  cout << "90" << endl;
  for(i=0; i<N; ++i){
    for(j=0; j<N; ++j)
      cout << data[N-1-j][i];
    cout << endl;
  }

  cout << "180" << endl;
  for(i=0; i<N; ++i){
    for(j=0; j<N; ++j)
      cout << data[N-1-i][N-1-j];
    cout << endl;
  }

  cout << "270" << endl;
  for(i=0; i<N; ++i){
    for(j=0; j<N; ++j)
      cout << data[j][N-1-i];
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 0
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if j == n-1:
            continue
        x = l[i] + l[j]
        cnt += bisect.bisect_left(l[j+1:], x)
print(cnt)

Measured memory_bytes: 74956
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<long long> P,M,Z;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i]==0)Z.push_back(0);
		else if(A[i]>0)P.push_back(A[i]);
		else M.push_back(A[i]);
	}
	if(P.size()+M.size()<K){
		cout<<0<<endl;
		return 0;
	}
	
	if((P.size()+M.size()==K && M.size()%2==1)||(P.size()==0&&K%2==1)){
		if(Z.size()>0){
			cout<<0<<endl;
		}
		else{
			sort(P.rbegin(),P.rend());
			sort(M.begin(),M.end());
			int ans = 1;
			for(int i=0;i<K;i++){
				if(P.size()==0){
					A1:
					ans = mod(ans * mod(M.back()));
					M.pop_back();
				}
				else if(M.size()==0){
					A0:
					ans = mod(ans * P.back());
					P.pop_back();
				}
				else if(P.back()<abs(M.back())){
					goto A0;
				}
				else goto A1;
			}
			cout<<ans<<endl;
		}
		return 0;
	}
	
	sort(P.begin(),P.end());
	sort(M.rbegin(),M.rend());

	vector<long long> X;
	int c = 0;
	for(int i=0;i<K;i++){
		if(P.size()==0){
			C1:
			X.push_back(M.back());
			c++;
			M.pop_back();
		}
		else if(M.size()==0){
			C0:
			X.push_back(P.back());
			P.pop_back();
		}
		else if(P.back()>abs(M.back())){
			goto C0;
		}
		else goto C1;
	}
	
	if(c%2==1){
		if(M.size()==0){
			B0:
			for(int i=X.size()-1;i>=0;i--){
				if(X[i]<0){
					
					X.erase(X.begin()+i);
					break;
				}
			}
			X.push_back(P.back());
		}
		else if(P.size()==0){
			B1:
			for(int i=X.size()-1;i>=0;i--){
				if(X[i]>0){
					X.erase(X.begin()+i);
					break;
				}
			}
			X.push_back(M.back());
		}
		else{
			long long aa = P.back(),bb = M.back();
			for(int i=X.size()-1;i>=0;i--){
				if(X[i]>0){
					aa *= X[i];
					break;
				}
				if(i==0)goto B0;
			}
			for(int i=X.size()-1;i>=0;i--){
				if(X[i]<0){
					bb *= X[i];
					break;
				}
				if(i==0)goto B1;
			}
			if(aa>bb)goto B0;
			else goto B1;
		}
	}
	
	int ans = 1;
	for(int i=0;i<X.size();i++)ans = mod(ans * mod(X[i]));
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 9452
#include<iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a > c && c > b) cout << "Yes" << endl;
  else if (a < c && c < b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

const int INF = 1000000000;

bool debug = false;

int main(){
	int n,cost[10001],dp[10001][2];
	scanf("%d",&n);
	for(int i=1;i<n;i++) scanf("%d",cost+i);
	cost[0] = 0;
	for(int i=0;i<=n;i++){
		for(int j=n;j>=0;j--){
			for(int k=1;k>=0;k--){
				if(i==0||j==0){
					dp[j][k] = INF;
					if(i==0&&j==0&&k==0) dp[j][k] = 0;
				}else if(k==0){
					dp[j][k] = min(dp[j-1][0],dp[j-1][1]+cost[i-1]);
				}else{
					dp[j][k] = min(dp[j][0]+cost[i-1],dp[j][1]);
				}
				if(debug){
					printf("dp[%d][%d][%d] = %d\n",i,j,k,dp[j][k]);
				}
			}
		}
	}
	int ans = min(dp[n/2][0],dp[n/2][1]);
	printf("%d\n",ans);
}

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

int main()
{
  int x , y;
  std::cin >> x >> y;
  if (y % 2 != 0)
  {
    std::cout << "No" << std::endl;
    return 0;
  }
  else if (4 * x - y < 0 || y - 2 * x < 0)
  {
    std::cout << "No" << std::endl;
    return 0;
  }
  else
  {
    std::cout << "Yes" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3616
x =  [int(s) for s in  list(input())]
num = []
for s in x:
    if(len(num) == 0):
        num.append(s)
    else:
        if(num[len(num)-1] == s):
            print('Bad')
            break
        else:
            num.append(s)

if(len(num) == 4):print('Good')

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

int main()
{

    int h, k;

    cin >> h >> k;

    int ans=0;
    for(int i=1;i<=h;i++){
        if(i==1) ans = k;
        else ans = ans*(k-1);
    }

    cout << ans <<endl;
    
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;
typedef long long ll;

int N, A, B, C;
vector<int> L(8);

int dfs(int cur, int a, int b, int c) {
  if(cur == N) {
    int minValue = min(min(a, b), c);
    return (minValue > 0) ? abs(a - A) + abs(b - B) + abs(c - C) - 30 : 1000000;
  }
  int ret0 = dfs(cur + 1, a, b, c);
  int ret1 = dfs(cur + 1, a + L[cur], b, c) + 10;
  int ret2 = dfs(cur + 1, a, b + L[cur], c) + 10;
  int ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10;
  return min(min(ret0, ret1), min(ret2, ret3));
}

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

  cout << dfs(0, 0, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-21 20:42:23 +0900
# LastModified: 2020-06-21 21:10:40 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    n,k = map(int, input().split())
    p = list(map(int, input().split()))
    p.sort()
    print(sum(p[:k]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes(){
  cout << "Yes" << endl;
}

void no(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  ll n; cin >> n;
  //k(k-1)/2 = n を満たすkはあるか？
  ll neg = 0, pos = n+2, k = -1;
  while(neg+1<pos){
    ll m = (neg+pos)/2;
    if(m*(m-1)/2 > n) pos = m;
    else if(m*(m-1)/2 < n ) neg = m;
    else {
      k = m;
      break;
    }
  }
  if(k==-1) no();
  
  yes();
  cout << k << endl;
  vector<vector<ll>> ans(k,vector<ll>(k-1,0));
  ll s = 0, cur = 1;
  while(s<k){
    FOR(j,s,k-1) ans[s][j] = cur + j-s;
    FOR(i,s+1,k){
      ans[i][s] = cur + i-(s+1);
    }
    cur += k-(s+1);
    s++;
  }
  REP(i,k){
    cout << k-1 << " ";
    REP(j,k-1){
      cout << ans[i][j] << " \n"[j==k-2];
    }
  }
}

Measured memory_bytes: 2944
import sys
input = sys.stdin.readline

def isprime(x):
  if x <= 1:
    return False
  for i in range(2, int(x**0.5) + 1):
    if x % i == 0:
      return False
  return True


A = [0] * 10 ** 5
B = [0] * 10 ** 5
con = 0

for i in range(10 ** 5):
  if isprime(i):
    A[i] = 1
  if A[i] and A[(i + 1) // 2]:
    con += 1
  B[i] = con

Q = int(input())

for _ in range(Q):
  l, r = map(int, input().split())
  print(B[r] - B[l - 1])


Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i > (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define IN(x) cin >> x
#define DE(x) cerr << (x) << " "
#define BR cerr << "\n"
#define OUT(x) cout << (x) << endl
#define FIX cout << fixed << setprecision(10)

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K;
ll ret = 0;

int main(void){
  
  IN(N);
  IN(K);
  vl A(N);
  REP(i, N) {
    IN(A[i]);
  }

  ll left = 1;
  ll right = 1000000000;
  while(right - left > 1) {
    ll mid = (left + right) / 2;
    ll k = 0;
    REP(i, N) {
      k += (A[i] + mid - 1) / mid - 1;
    }
    if (k < K) {
      right = mid;
    } else if (k > K) {
      left = mid;
    } else {
      right = mid;
    }

    // DE(k);
    // DE(left);
    // DE(right);
    // BR;
  }

  ll left_k = 0;
  REP(i, N) {
    left_k += (A[i] + left - 1) / left - 1;
  }

  // ll right_k = 0;
  // REP(i, N) {
  //   right_k += (A[i] + right - 1) / right - 1;
  // }

  if (left_k > K) {
    OUT(right);
  } else {
    OUT(left);
  }
  
}


Measured memory_bytes: 4824
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

int main()
{
	int N, K;
	cin >> N >> K;
	ll ans = numeric_limits<ll>::max();
	vector<pair<int, int>> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p.begin(), p.end());
	for (int i = 0; i < N; i++) {
		vector<int> ys;
		for (int j = i; j < N; j++) {
			ys.push_back(p[j].second);
			sort(ys.begin(), ys.end());

			for (int k = 0; k + K-1 < (int)ys.size(); k++) {
				ans = min(ans, 1LL * abs(p[i].first - p[j].first) * abs(ys[k] - ys[k + K - 1]));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  //int N = 1000;
  string S,S_ans;
  //long int k;
  
  cin >> S;
  
  //cout << S <<endl;
   
  S_ans = S;
  
  	if(S.at(S.size()-1) == 's') {
		cout << S << "es";
    }else{
   	  	cout << S << "s";
    }
  	
}

Measured memory_bytes: 3648
import heapq
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
candidates = []
for i in range(X):
    candidates.append(-1 * p[i])
for i in range(Y):
    candidates.append(-1 * q[i])
for i in range(C):
    candidates.append(-1 * r[i])
heapq.heapify(candidates)
ans = 0
for _ in range(X + Y):
    val = heapq.heappop(candidates)
    ans += val
print(-ans)

Measured memory_bytes: 115308
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    string hoge;
    cin>>hoge;
    string yesno = "Yes";
    for(int i=0;i<hoge.size();i++){
        if(i%2==0){
            if(hoge.at(i)=='L')yesno = "No";
        }
        if(i%2==1){
            if(hoge.at(i)=='R')yesno = "No";
        }
    }
    cout<<yesno;
}

Measured memory_bytes: 256
n,x,m = gets.split.map(&:to_i)
db = Array.new(Math.log(n,2).to_i+1).map{Array.new(m)}
s = Array.new(Math.log(n,2).to_i+1).map{Array.new(m)}

y = x
while true
  if db[0][y**2%m]
    db[0][y] = y**2%m
    s[0][y] = y**2%m
    break
  else
    db[0][y] = y**2%m
    s[0][y] = y**2%m
    y = y**2%m
  end
end
for i in 0..(Math.log(n,2).to_i-1)
  for j in 0..(m-1)
    if  db[i][j] != nil
      db[i+1][j] = db[i][db[i][j]]
      s[i+1][j] = s[i][j] + s[i][db[i][j]]
    end
  end
end
sum = x
pre = x
for k in 0..(Math.log(n,2))
  if n[k] == 1
    sum += s[k][pre]
    pre = db[k][pre]
  end
end
puts sum-pre

Measured memory_bytes: 67776