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

using namespace std;

int dp[501 + 10][2][10][3][500];
//dp[a][b][c][d][e]:a桁目 b1で自由に使える0で自由に使えない 今の桁はc
//d1で前より上がってる2で前より下がってる0で前と変わらない eは余り
int MOD = 10000;
int M;
string A, B;

//1~nまでのジグザグ数%10000
int calc(string n) {
	for (int i = 0; i <= 500; i++)for (int j = 0; j < 2; j++)for (int k = 0; k < 10; k++)
		for (int l = 0; l < 3; l++)for (int m = 0; m < 500; m++)dp[i][j][k][l][m] = 0;
	
	for (int i = 0; i < n[0] - '0'; i++)
		dp[1][1][i][0][i % M] = 1;

	dp[1][0][(n[0] - '0')][0][(n[0] - '0') % M] = 1;

	for (int a = 1; a < n.size(); a++) {
		for (int b = 0; b < 2; b++) {
			int limit = b ? 9 : n[a] - '0';
			for (int c = 0; c <= limit; c++) {
				for (int d = 0; d <= (b ? 9 : n[a - 1] - '0'); d++) {
					for (int e = 0; e < 3; e++) {
						for (int f = 0; f < M; f++) {
							if (e == 0) {
								//前と比べて増加も減少もしてない
								if (d == 0) {
									(dp[a + 1][b || c < limit][c][0][(f * 10 + c) % M] += dp[a][b][d][e][f]) %= MOD;
								}
								else {
									if (c < d) {
										(dp[a + 1][b || c < limit][c][2][(f * 10 + c) % M] += dp[a][b][d][e][f]) %= MOD;
									}
									if (c > d) {
										(dp[a + 1][b || c < limit][c][1][(f * 10 + c) % M] += dp[a][b][d][e][f]) %= MOD;
									}
								}
								
							}
							else if (e == 1) {
								//今増加→次減少
								if (c >= d)continue;
								(dp[a + 1][b || c < limit][c][2][(f * 10 + c) % M] += dp[a][b][d][e][f]) %= MOD;
							}
							else if (e == 2) {
								//今減少→次増加
								if (c <= d)continue;
								(dp[a + 1][b || c < limit][c][1][(f * 10 + c) % M] += dp[a][b][d][e][f]) %= MOD;
							}
						}
					}
				}
			}
		}
	}

	int ans = 0;
	for (int b = 0; b < 2; b++)for (int c = 0; c <= 9; c++)for (int e = 0; e <= 2; e++)
		ans += dp[n.size()][b][c][e][0];
	ans--;
	ans %= MOD;

	return ans;

}

bool isZigZag(string n) {
	bool f;
	if (n.size() == 1)return true;
	if (n[0] == n[1])return false;
	if (n[0] > n[1])f = true;
	if (n[0] < n[1])f = false;

	for (int i = 1; i < n.size() - 1; i++) {
		if (f) {
			if (n[i + 1] <= n[i])return false;
			f = !f;
		}
		else {
			if (n[i + 1] >= n[i])return false;
			f = !f;
		}
	}
	return true;

}

int main() {

	cin >> A >> B >> M;

	cout << (calc(B) - calc(A) + isZigZag(A) + MOD) % MOD << endl;

	return 0;
}



Measured memory_bytes: 61932
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<map>
using namespace std;

int from[100010],to[100010];
int n,m;
vector<int> V[100010];
int vis[100010],F[100010];
int ans;
map<int,map<int,int>> p;

int bfs(int st)
{
	queue<int> Q;
	memset(vis,-1,sizeof(vis));
	memset(F,0,sizeof(F));
	Q.push(st);
	vis[st]=1;
	F[st]=0;
	while(!Q.empty())
	{
		int cur=Q.front();
		Q.pop();
		for(auto k:V[cur])
		{
			int u=to[k];
			if(u==st) 
				return ans=cur;
			if(vis[u]!=-1) 
				continue;
			vis[u]=vis[cur]+1;
			F[u]=cur;
			Q.push(u);
		}
	}
	return ans=-1;
}

int main()
{
	cin>>n>>m;
	for(int i=1; i<=m; i++)
	{
		cin>>from[i]>>to[i];
		V[from[i]].push_back(i);
	}
	int len=12345678;
	int A=0;
	for(int i=1; i<=n; i++)
	{
		int tmp=bfs(i);
		if(tmp==-1) 
			continue;
		if(vis[tmp]<len)
		{
			A=i;
			len=vis[tmp];
		}
	}
	if(!A)
	{
		cout<<-1<<endl;
		return 0;
	}
	bfs(A);
	cout<<len<<endl;
	for(int i=1; i<=len; i++)
	{
		cout<<ans<<endl;
		ans=F[ans];
	}
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	vi v(9);
	REP(i, 9) cin >> v[i];
	vi p = { 1, 2, 3, 4, 5 ,6, 7, 8, 9 };
	int ans = 0;
	do
	{
		bool f = true;
		REP(i, 9)
		{
			if (v[i] != -1 && v[i] != p[i])
			{
				f = false;
			}
		}
		if (!f) continue;
		int l = p[0] + p[1] * 10 + p[2] + p[3] * 100 + p[4] * 10 + p[5];
		int r = p[6] * 100 + p[7] * 10 + p[8];
		if (l == r) ans++;
	} while (next_permutation(ALL(p)));
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    string s;

    cin >> n >> s;

    for (char c: s)
    {
        cout << char((((c-'A') + n) % 26) + 'A');
    }

    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int m,f,r;

	while(1)
	{
		scanf("%d %d %d",&m,&f,&r);

		//m、f、r がすべて -1 のとき入力の終わりとします。
		if(m==-1 && f==-1 && r==-1) break;
		
		//中間試験、期末試験のいずれかを欠席した場合成績は F。
		if(m==-1 || f==-1)
		{
			printf("F\n");
		
		//中間試験と期末試験の合計点数が 80 以上ならば成績は A 。	
		}else if((m+f)>=80){
			printf("A\n");
		
		//中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。	
		}else if((m+f)>=65){
			printf("B\n");
		
		//中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。

		}else if((m+f)>=50){
			printf("C\n");
			
		//中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
		}else if((m+f)>=30){
			if(r>=50)
			{
				printf("C\n");
			}else
			{
				printf("D\n");
			}
			
		//中間試験と期末試験の合計点数が 30 未満ならば成績は F。	
		}else{
			printf("F\n");
		}
	}
	return 0;
}



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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b[10];

main() {
    rep(i,3) {
        cin >> a;
        b[a]++;
    }
    if (b[5] == 2 && b[7] == 1) ct("YES")
    else ct("NO")
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    rep(h,0,3501){
        rep(n,1,3501){
            ll v1 = N*h*n;
            ll v2 = 4*h*n - N*(n+h);
            if(v2 > 0 && v1%v2 == 0 && v1/v2 <= 3500){
                cout << h << " " << n << " " << v1/v2 << endl;
                return 0;
            }
        }
    }

 }

Measured memory_bytes: 256
N = int(input())

ans = [0]*4
for n in range(N):
  C = input()
  if C == "AC":
    ans[0] += 1
  elif C == "WA":
    ans[1] += 1
  elif C == "TLE":
    ans[2] += 1
  elif C == "RE":
    ans[3] += 1

print("AC x {}".format(ans[0]))
print("WA x {}".format(ans[1]))
print("TLE x {}".format(ans[2]))
print("RE x {}".format(ans[3]))

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;

int main(){

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

cin>>N;

ll cnt_odd=0;
ll cnt_4=0;
ll cnt=0;
rep(i,N){
	ll a;
	cin>>a;
	if(a%2) cnt_odd++;
	else if(a%4==0) cnt_4++;
	else cnt++;
}

if(cnt==0){
if(cnt_odd>cnt_4+1) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
else{
if(cnt_odd>cnt_4) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}


}
	


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
 
	public static void main(String[] args) {

		int n,i;
		double ave,std;

		Scanner scan = new Scanner(System.in);
		
		while(true)
		{
			int sum=0;
			double var=0;
			
			n = scan.nextInt();
			
			if(n==0) break;
			
			int a[] = new int[n];
			
			for(i=0; i<n; i++)
			{
				a[i] = scan.nextInt();
				sum += a[i];
			}
			
			ave = (double)sum/n;
			
			for(i=0; i<n; i++)
			{
				var += ( (a[i] - ave)*(a[i] - ave) );
			}
			
			std = Math.sqrt(var/n);
			
			System.out.printf("%.5f\n",std);
		}
		
		scan.close();
	}
}

Measured memory_bytes: 31928
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

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

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

int main() {
  int N, M; cin >> N >> M;
  vector<int> p(N); cin >> p;

  UnionFindTree tree(N);
  for (int i = 0; i < M; ++i) {
    int x, y; cin >> x >> y; --x, --y;
    tree.Unite(x, y);
  }

  map<int, set<int>> m;
  for (int i = 0; i < N; ++i) {
    int root = tree.Root(i);
    if (root < 0) m[i].insert(i);
    else          m[root].insert(i);
  }

#if 0
  for (auto [k, v] : m) {
    cout << v << endl;
  }
  cout << "---------" << endl;
#endif

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int x = p[i] - 1;
    int root = tree.Root(i);
    if (root < 0) root = i;
    if (m[root].count(x)) ++cnt;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 17900
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int n, cnt = 0;
vi v;
inline void merge(int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	vi L(n1 + 1), R(n2 + 1);
	rep(i, 0, n1) {
		L[i] = v[left + i];
	}
	rep(i, 0, n2) {
		R[i] = v[mid + i];
	}
	L[n1] = R[n2] = 1e9;
	int i = 0, j = 0;
	rep(k, left, right) {
		++cnt;
		if(L[i] <= R[j]) {
			v[k] = L[i];
			++i;
		} else {
			v[k] = R[j];
			++j;
		}
	}
}
inline void mergeSort(int left, int right) {
	if(left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}
}
int main() {
	cin >> n;
	v.resize(n); rep(i, 0, n) cin >> v[i];
	mergeSort(0, n);
	rep(i, 0, n) cout << v[i] << (i + 1 == n ? "\n" : " ");
	P(cnt);
	return 0;
}

Measured memory_bytes: 6672
#include <iostream>
#include <iomanip>

int main() {

    int a, b;
    std::cin >> a >> b;

    int     d = a / b;
    int     r = a % b;
    double  f = 1. * a / b;

    std::cout << std::fixed << std::setprecision(5);

    std::cout << d << " " << r << " " << f << std::endl;

    return 0;
}



Measured memory_bytes: 3284
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#define range(i, n) for (int i = 0; i<n; i++)
using namespace std;
using ll = long long;
int main(){
    ll N, W;
    cin >> N >> W;
    vector<vector<ll>> darray(N+1, vector<ll> (W+1,0));
    ll wt[N], vel[N];
    for (int i = 0; i < N; i++){
        cin >> wt[i] >> vel[i];
    }
    for (int i = 1; i <= N; i++){
        for (int w = 1;w <= W; w++){
            if (wt[i - 1] <= w){
                darray[i][w] = max(vel[i-1] + darray[i-1][w-wt[i-1]],darray[i-1][w]);
                }
            else 
                darray[i][w] = darray[i-1][w];
        }
    }
    cout << darray[N][W];
    return 0;
}

Measured memory_bytes: 82956
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
char s[MAXN],t[MAXN];
int n;
bool ok(int x){
	for(int i=0;i<n;i++)
		s[i]=t[i];
	int odd=0;
	for(int i=0;i+x-1<n;i++){
		if((s[i]-'0')^odd)
			odd^=1;		
		s[i]='0';	
	}
	if(odd){
		for(int i=n-x+1;i<n;i++){
			if(s[i]=='1')
				s[i]='0';
			else
				s[i]='1';
		}
	}odd=0;	
	for(int i=n-1;i-x+1>=0;i--){
		if((s[i]-'0')^odd)
			odd^=1;		
		s[i]='0';	
	}	
	if(odd){
		for(int i=0;i<x-1;i++){
			if(s[i]=='1')
				s[i]='0';
			else
				s[i]='1';
		}
	}
	for(int i=0;i<n;i++)
		if(s[i]=='1')
			return 0;
	return 1;		
}
int main(){
    //~ freopen("file.in", "r", stdin);
    scanf("%s",s);
    n=strlen(s);
    for(int i=0;i<n;i++)
		t[i]=s[i];
    int st=1,en=n;
    while(st+1<en){
		int mid=(st+en)>>1;
		if(ok(mid))
			st=mid;
		else
			en=mid;
	}
	if(ok(en))
		printf("%d\n",en);
	else
		printf("%d\n",st);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll n){ ll p=(n+1)/2; if(n%2==0){ if(p&1) return n^1; return n^0;} else{ if(p&1) return 1;else return 0;}}
int main() {ll a,b; cin>>a>>b;  cout<<(f(a-1)^f(b));}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int l,r,ans;
char s[1000000];
int main(){
	cin>>s;l=0;r=strlen(s)-1;
	while (l<r){
		if (s[l]==s[r]){l++;r--;continue;}
		if (s[l]=='x'){l++;ans++;continue;}
		if (s[r]=='x'){r--;ans++;continue;}
		cout<<-1<<endl;return 0;
	}cout<<ans<<endl;
}

Measured memory_bytes: 384
from itertools import chain, combinations

def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

n, m, x = map(int, input().split())

arr = []
for _ in range(n):
    i = map(int, input().split())
    arr.append((next(i), [*i]))

min_cost = float('inf')
for s in powerset(range(n)):
    cost = 0
    cur = [0]*m
    for i in s:
        cost += arr[i][0]
        for j in range(m):
            cur[j] += arr[i][1][j]

    ans = True
    for i in cur:
        if i < x:
            ans = False

    if ans:
        min_cost = min(min_cost, cost)


print(min_cost if min_cost != float('inf') else -1)            


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

int main(){
    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    rep(i ,N){
        cin >> w[i] >> v[i];
    }

    ll dp[N][W+1];

    rep(j, W+1){
        if(j>=w[0]){
            dp[0][j] = (ll) v[0];
        }else{
            dp[0][j] = (ll) 0;
        }
    }
    // rep(j, W+1){
    //     printf("%d\n", dp[0][j]);
    // }

    for(int i=1;i<N;i++){
        rep(j, W+1){
            if(j-w[i]>=0){
                dp[i][j] = max(dp[i-1][j-w[i]] + v[i], dp[i-1][j]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    // rep(i, N){
    //     rep(j, W+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    printf("%lld\n", dp[N-1][W]);
    return 0;
}

Measured memory_bytes: 78336
package main

import (
	"fmt"
)

func main() {
	var a, b, c int64
	fmt.Scan(&a, &b, &c)

	d := c - a - b
	if d < 0 {
		fmt.Println("No")
		return
	}
	if d*d > 4*a*b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
// template version 1.7

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 1e9+7
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int solve(){
  int a[5];rep(i, 5){cin>>a[i];}
  int k;cin>>k;
  rep(i,5){
    rep(j,5){
      if (abs(a[i]-a[j])>k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int mx = A;
  mx = max(mx,max(B,C));
  int Ans = 0;
  Ans += mx*pow(2,(double)K);
  Ans += A + B + C;
  Ans -= mx;

  printf("%d\n",Ans);
  return 0;

}


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

int main() {
  int a, b, c, k, n = 0;
  cin >> a >> b >> c >> k;
  while(a >= b) {
    b *= 2;
    n++;
  }
  while(b >= c) {
    c *= 2;
    n++;
  }
  cout << (n <= k ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
// https://atcoder.jp/contests/abc132/tasks/abc132_c

#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#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++)
#define FORR(i, m, n) for (int(i) = (n); (i) >= (m); i--)
#define rep(...) _overload3(__VA_ARGS__, FOR, REP, )(__VA_ARGS__)
#define repr(...) _overload3(__VA_ARGS__, FORR, REPR, )(__VA_ARGS__)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, d, r = 0;
  vector<int> D;

  cin >> N;
  REP(i, N)
  {
    cin >> d;
    D.pb(d);
  }

  if (N % 2 == 0)
  {
    sort(ALL(D));
    r = D[N / 2] - D[N / 2 - 1];
  }

  cout << r << '\n';
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int sum = 0;//合計人数
  for(int i = 0; i < N;++i){
    int st,en;
    cin >> st >> en;
    sum += (en - st) + 1;
  }
  cout << sum << endl;
}


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

int solve(vector<int> const &height, int k)
{
    vector<int> dp(height.size()+4,0);
    for(int i=1 ; i<height.size() ; ++i)
    {
        dp[i]=dp[i-1]+abs(height[i]-height[i-1]);
        for(int j=2 ; j<=k; ++j)
        {
            if((i-j)<0)
            break;
            dp[i]=min(dp[i],dp[i-j]+abs(height[i]-height[i-j]));
        }
    }
    return dp[height.size()-1];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,k;
    cin>>n>>k;
    vector<int> height(n);
    for(int i=0 ; i<n ; ++i)
    cin>>height[i];
    cout<<solve(height,k)<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
long double pi=3.1415926535897932384626433832795028;
int main(void){
  long double r;
  cin>>r;
  double ans=2*r*pi;
  cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 3760
fun main(args :Array<String>) {
    val MOD = 1000000007L
    val MAX = 3000
    val combination = Array<LongArray>(MAX) { LongArray(MAX) }
    combination[0][0] = 1
    for (i in 1 until MAX) {
        for (j in 0..i) {
            val left = if (j - 1 >= 0) combination[i - 1][j - 1] else 0
            val right = combination[i - 1][j]
            combination[i][j] = (left + right) % MOD
        }
    }

    val (n, k) = readIntegerList()
    for (i in 1..k) {
        println((combination[n - k + 1][i] * combination[k - 1][i - 1]) % MOD)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 117892
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

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

    int i = 1;
    vector<int> primes;
    while(true) {
        i++;
        bool isPrime = true;
        for(int p: primes) {
            if(i%p == 0) {
                isPrime = false;
                break;
            }
        }
        if(isPrime) {
            if(i >= N) {
                cout << i << endl;
                break;
            }
            primes.push_back(i);
        }
    }


    return 0;
}

Measured memory_bytes: 888
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){	
	int x,d;
	cin>>x>>d;
	int a[x][d];
	for(int i=0;i<x;i++){
		for(int j=0;j<d;j++){
			cin>>a[i][j];
		}
	}
	int ans=0;
	for(int i=0;i<x;i++){
		for(int k=i+1;k<x;k++){
			if(k!=i){
				int sum=0;
				for(int j=0;j<d;j++){
					sum+=abs(a[i][j]-a[k][j])*abs(a[i][j]-a[k][j]);
				}
				for(int j=0;;j++){
					if(j*j==sum){
						ans++;
						break;
					}
					else if(j*j<sum&&(j+1)*(j+1)>sum){
						break;
					}
				}
			}
		}
	}
	cout<<ans;
    return 0;
} 

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int K = in.Int();
            if (K % 2 == 0 || K % 5 == 0) {
                out.println(-1);
                return;
            }

            int cur = 7 % K;
            int ans = 1;
            while (cur != 0) {
                cur = cur * 10 + 7;
                cur %= K;
                ans++;
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

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

    }
}



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

bool has_nine(int x)
{
    while(x > 0)
    {
        if(x % 10 == 9) return true;
        x /= 10;
    }
    return false;
}

int main(int argc, char *argv[])
{
    int n;
    cin >> n;
    cout << (has_nine(n) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
# define x first
# define y second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int n, k; cin >> n >> k;

  double ans = 0;
  reps(i, n){
    double win = 1; int pt = i;
    while(pt < k){
      win /= 2;
      pt *= 2;
    }
    ans += win;
  }

  ans /= n;

  printf("%.12f\n", ans);
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,em=0,om=0,emi,omi,ems=0,oms=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  map<int,int> e,o;
  for(int i=0;i<n;i++){
    if(i%2)o[a[i]]++;
    else e[a[i]]++;
  }
  for(auto itr=e.begin();itr!=e.end();++itr)if(em<itr->second){em=itr->second;emi=itr->first;}
  for(auto itr=o.begin();itr!=o.end();++itr)if(om<itr->second){om=itr->second;omi=itr->first;}
  cerr<<endl<<"emi-omi:"<<emi-omi<<endl;
  if(emi-omi!=0)cout<<n-em-om;
  else{
    for(auto itr=e.begin();itr!=e.end();++itr){if(itr->first==emi)continue;ems=max(ems,itr->second);}
    for(auto itr=o.begin();itr!=o.end();++itr){if(itr->first==omi)continue;oms=max(oms,itr->second);}
    cout<<min(n-em-oms,n-ems-om);
  }
  cout<<endl;
  cerr<<em<<" "<<om<<" "<<emi<<" "<<omi<<" "<<ems<<" "<<oms<<" "<<endl;
}


Measured memory_bytes: 7296
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	cout << static_cast<double>(2 * n) * PI << endl;
	return 0;
}


Measured memory_bytes: 3764
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) x.begin(),x.end()
#define endl '\n'

#ifndef ONLINE_JUDGE       
template<typename T>    
void __p(T a) {
  cerr<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cerr<<"[";
  __p(a.first);
  cerr<<",";
  __p(a.second);
  cerr<<"]";
}
template<typename T>
void __p(std::vector<T> a) {
  cerr<<"[";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cerr<<",]"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr<<name<<" : ";
  __p(arg1);
  cerr<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cerr.write(names,comma-names)<<" : ";
  __p(arg1);
  cerr<<" | ";
  __f(comma+1,args...);
}
#define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...)
#endif

void test_case(){
	string s,t;
	cin>>s>>t;
	int a=s.length(),b=t.length();
	int ans=INT_MAX;
	for(int i=0;i<a;i++){
		int p=i,ans1=0;
		if(p+b-1>=a){
			break;
		}
		for(int j=0;j<b;j++){
			ans1+=(s[p]!=t[j]);
			p++;
		}
		ans=min(ans,ans1);
	}
	cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 
    int T=1;
    //cin>>T;
    for(int TT=1; TT<=T; TT++){
        test_case();
    }

    cerr<<endl<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

    return 0;
}


Measured memory_bytes: 3776
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
signed main()
{
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	int num = max({ a,b,c,d,e }) - min({ a,b,c,d,e });
	if (num > k)cout << ":(";
	else cout << "Yay!";
}

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

int main() {
	long long N,H;
cin>>N>>H;
long long a[N],b[N];
for(int long long i=0; i<N; i++){
cin>>a[i]>>b[i];
}

sort(a,a+N);
sort(b,b+N);

long long A=a[N-1];
long long ans=0;

long long p=N-1;
while(p>=0 && H>0 && A<=b[p]){
H-=b[p];
p--;
ans++;
}
if(H>0){
ans+=(H+A-1)/A;
}
cout <<ans<<endl;



	return 0;
}

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

int main()
{
	string s,t;
	cin>>s>>t;
	
	sort(s.begin(),s.end());
	sort(t.begin(),t.end(),greater<char>());
	
	bool f=1;
	for(int i=0;i<s.length();i++){
		if(s[i]>t[i]){
			f=0;
			break;
		}else if(s[i]<t[i])
			break;
	}
	if(s==t) f=0;
	
	cout<<(f? "Yes":"No")<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
#define MAXN 10000005
int spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
long long numFactors(int n){
	vector<int> v = getFactorization(n);
	long long p = 1, c = 1;
	for(int i = 1; i < v.size(); i++){
		if(v[i] == v[i-1])
			c++;
		else{
			p *= c + 1;
			c = 1;
		}
	}
	p *= c + 1;
	return p;
}
signed main(){
	sieve();
	int n;
	cin >> n;
	long long ans = 0;
	for(int i = 2; i <= n; i++){
		long long t = spf[i] == i ? 2 : numFactors(i);
//		cout << t << endl;
		ans += t * i;
	}
	cout << ans + 1;
	return 0;
}

Measured memory_bytes: 81692
import collections as co
class Vec(co.namedtuple('Vec','x y')):
    def __add__(self,v):
        return Vec(self.x+v.x, self.y+v.y)

field = dict()
h,w = map(int,input().split())
for y in range(h):
    ma = map(int,input().split())
    for x,population in enumerate(ma):
        field[Vec(x,y)] = population

# def printField(field):
#     for y in range(h):
#         for x in range(w):
#             print('{: 3}'.format(field[Vec(x,y)]), end='')
#             # print(field[Vec(x,y)], end='')
#         print()

def distmapFor(v0):
    distmap = dict()
    # for y in range(h):
    #     for x in range(w):
    for v in field.keys():
        distmap[v] = min(abs(v0.x-v.x), abs(v0.y-v.y))
    return distmap
# printField(distmapFor(Vec(1,1)))
# printField(field)

def totalFor(v):
    total = 0
    distmap = distmapFor(v)
    for v in field.keys():
        total += distmap[v]*field[v]
    return total

mi = min(map(totalFor, list(field.keys())))
print(mi)



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

int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  int ans=0;
  for(int i=1;i<n-1;i++)
    if(v[i]>v[i-1]&&v[i]<v[i+1])
      ans++;
    else if(v[i-1]>v[i]&&v[i]>v[i+1])
      ans++;
  cout<<ans<<"\n";
  
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[1000005];
int main()
{
    int n,q;
    scanf("%d",&n);
    scanf("%s",s+1);
    scanf("%d",&q);
    while(q--)
    {
        int k;
        scanf("%d",&k);
        long long ans=0,res=0,d=0,m=0;
        for(int i=1;i<=n;i++)
        {
            if(i>k)
            {
                if(s[i-k]=='D') d--,res-=m;
                if(s[i-k]=='M') m--;
            }
            if(s[i]=='D') d++;
            if(s[i]=='M') m++,res+=d;
            if(s[i]=='C') ans+=res;
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 100000000
#define pll pair<long,long>
#define se second
#define fi first
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update>pllordered_set;

vector<ll> g[100050];
vector<ll> vis(100050,0);
ll ans=0;
void dfs(ll s)
{
	vis[s]=1;
	for(auto i:g[s])
	{
		if(!vis[i])
		{
			
			dfs(i);
		
		}
	}
}


int main()
{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);
			ll n,m;
			cin>>n>>m;
			
			
	
			while(m){
			
				m--;
				ll x,y,z;
				cin>>x>>y>>z;
				g[x].pb(y);
				g[y].pb(x);
			
		}
		for(ll i=1;i<=n;i++)
		{
			
			if(!vis[i])
			{
			//	cout<<i<<" ";
				dfs(i);
				ans++;
			}
		}
	//	cout<<endl;
		cout<<ans;
			
}


Measured memory_bytes: 9600
n,m=map(int,input().split())
t=[tuple(map(int,input().split()))for i in range(m)]
ans=[]
ans_2=[]
for i in range(m):
    if t[i][0]==1:
        ans.append(t[i][1])
    if t[i][1]==n:
        ans_2.append(t[i][0])
a=set(ans)
b=set(ans_2)
if a&b:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
    



Measured memory_bytes: 39272
#include<stdio.h>
int main(void)
{
	int k,n,a,b,c,d,an[365],r;
	scanf("%d",&k);
	for(n=0;n<k;n++)
	{
		scanf("%d %d %d %d",&a,&b,&c,&d);
		if(c<5||d<2)
		{
			an[n]=a*c+b*d;
			if(c<5)
			{
				c=5;
			}
			if(d<2)
			{
				d=2;
			}
			r=(a*c+b*d)*8/10;
			if(r<an[n])
			{
				an[n]=r;
			}
		}
		else
		{
			an[n]=(a*c+b*d)*8/10;
		}
	}
	for(n=0;n<k;n++)
	{
		printf("%d\n",an[n]);
	}
	return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans;
int t(int n,int k);
int main()
{
    int x,m;
    cin>>x>>m;
    t(x,m);
    cout<<ans<<endl;
    return 0;
}
int t(int n,int k)
{
    int r;
    r=n%k;
    n=n/k;
    if(n!=0) t(n,k);
    ans++;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N, Q;
    cin >> N >> Q;
    map<ll, vector<pair<ll, ll> > > X;
    REP(i,N){
        ll s, t, x;
        cin >> s >> t >> x;
        if(X.find(x) == X.end()){
            vector<pair<ll, ll> > v;
            v.emplace_back(s-x, t-x);
            X[x] = v;
        }
        else{
            X[x].emplace_back(s-x, t-x);
        }
    }

    set<ll> D;
    vector<ll> DD(Q);
    REP(i,Q){
        ll d;
        cin >> d;
        D.insert(d);
        DD[i] = d;
    }


    map<ll, int> ans;
    for(auto&& p : X){
        ll loc = p.first;
        auto v = p.second;
        for(auto pp : v){
            ll start = pp.first;
            ll end = pp.second;
            auto iter0 = D.lower_bound(end);
            auto iter1 = D.lower_bound(start);
            vector<ll> erase;
            for(auto it = iter1; it != iter0; ++it){
                ll d = *it;
                if(ans.find(d) == ans.end()) {
                    //D.erase(it);
                    erase.push_back(d);
                    ans[d] = loc;
                }
            }
            for(auto x : erase){
                D.erase(x);
            }
        }
    }

    REP(i,Q){
        ll d = DD[i];
        ll xx;
        if(ans[d] == 0) xx = -1;
        else xx = ans[d];
        cout << xx << endl;
    }
    return 0;
}


Measured memory_bytes: 46080
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

#include <regex>

int main() {
    
    string s;
    cin>>s;
    bool ch=0;
    if (regex_match(s,regex(".*keyence"))){
        ch=1;
    }
    if (std::regex_match(s,regex("k.*eyence$"))){
        ch=1;
    }
    if (std::regex_match(s, regex("ke.*yence"))){
        ch=1;
    }
    if (std::regex_match(s, regex("key.*ence"))){
        ch=1;
    }
    if (std::regex_match(s,  regex("keye.*nce"))){
        ch=1;
    }
    if (std::regex_match(s,regex("keyen.*ce"))){
        ch=1;
    }
    if (std::regex_match(s, regex("keyenc.*e"))){
        ch=1;
    }
    if (std::regex_match(s, regex("keyence.*"))){
        ch=1;
    }
    if (std::regex_match(s, regex("keyence"))){
        ch=1;
    }
    if(ch)fin("YES");
    else fin("NO");
}

Measured memory_bytes: 256
n = int(input())
lh = reversed(list(map(int, input().split())))

t = 10 ** 9 + 1

res = "Yes"

for h in  lh:
	if h <= t:
		t = h
	elif h - 1 <= t:
		t = h - 1
	else:
		res = "No"
		break

print(res)

Measured memory_bytes: 14396
import java.util.*;

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

        String s = sc.next();
        final int tag = 753;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i <= s.length() - 3; i++) {
            if (s.substring(i, i + 3).equals("0")) {
                continue;
            }
            int si = Integer.parseInt(s.substring(i, i + 3));
            if (Math.abs(si - tag) < min) {
                min = Math.abs(si - tag);
            }
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 25044
#include <iostream>
#include <vector>
#include <map>
using namespace std;
map<long long, long long> divide(long long n){//素因数分解
    map<long long, long long> res;
    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
int n;
void dfs(vector<int> &ve, int &ans, int ind, int now){
    if(ind >= n) return;
    if(now == 1){
        ans++;
        return;
    }
    if(ve[ind] >= 74 && now % 75 == 0) dfs(ve, ans, ind + 1, now / 75);
    if(ve[ind] >= 24 && now % 25 == 0) dfs(ve, ans, ind + 1, now / 25);
    if(ve[ind] >= 14 && now % 15 == 0) dfs(ve, ans, ind + 1, now / 15);
    if(ve[ind] >= 4 && now % 5 == 0) dfs(ve, ans, ind + 1, now / 5);
    if(ve[ind] >= 2 && now % 3 == 0) dfs(ve, ans, ind + 1, now / 3);
    dfs(ve, ans, ind + 1, now);
}
int main(){
    int N;
    cin >> N;
    map<long long, long long> m;
    for(int i = 2; i <= N; i++){
        map<long long, long long> t = divide(i);
        for(auto v: t){
            m[v.first] += v.second;
        }
    }
    n = (int)m.size();
    vector<int> vec(n);
    int ind = 0;
    for(auto v: m){
        vec[ind] = v.second;
        ind++;
    }
    int ans = 0;
    dfs(vec, ans, 0, 75);
    cout << ans << endl;
}

Measured memory_bytes: 3572
from heapq import *


x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)
a.append(-float('inf'))
b.append(-float('inf'))
c.append(-float('inf'))

done = {}
h = []
heappush(h, (-(a[0] + b[0] + c[0]), 0, 0, 0))
done[0,0,0] = 1
ind = 0
while ind < k:
    t = heappop(h)
    print(-t[0])
    ind += 1
    if (t[1]+1, t[2], t[3]) not in done:
        done[t[1]+1, t[2], t[3]] = 1
        heappush(h, (-(a[t[1]+1] + b[t[2]] + c[t[3]]), t[1] + 1, t[2], t[3]))
    if (t[1], t[2]+1, t[3]) not in done:
        done[t[1], t[2]+1, t[3]] = 1
        heappush(h, (-(a[t[1]] + b[t[2]+1] + c[t[3]]), t[1], t[2]+1, t[3]))
    if (t[1], t[2], t[3]+1) not in done:
        done[t[1], t[2], t[3]+1] = 1
        heappush(h, (-(a[t[1]] + b[t[2]] + c[t[3]+1]), t[1], t[2], t[3]+1))


Measured memory_bytes: 58204
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		long[] s=sc.La;
		long[] a=sc.La;
		long ans=0,b=s[1],c=0,z=1;
		int m=s[1]==0?0:(int)Math.Log(s[1],2);
		int[] h=new int[m+1];
		for(int i = 0;i<s[0];i++) {
			for(int j = 0;j<=m;j++){
				if((a[i]&(z<<j))!=0){h[j]++;}
			}
		}
		for(int i = 0;i<=m;i++) {
			if(h[i]*2<s[0]){long v=z<<i;c|=v;}
		}
		if(b>=c){
			for(int i = 0;i<s[0];i++) {ans+=a[i]^c;}
		}
		else{
			for(int i = 0;i<s[0];i++) {ans+=a[i]^(b&c);}
			for(int i = m;i>=0;i--) {
				if((b&(z<<i))>0){
					long q=b&(~((z<<(i+1))-1)),o=0;
					q|=(z<<i)-1;
					q&=c;
					for(int j = 0;j<s[0];j++) {o+=a[j]^q;}
					ans=Math.Max(ans,o);
				}
			}
		}
		Console.WriteLine("{0}",ans);
	}
}

class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 32348
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), x = sc.nextInt();
		long[] a = new long[N];
		long[] b = new long[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[N - 1 - i] = a[i];
		}
		long ans = 0;
		for(int i = 0; i + 1 < N; i++) {
			if(a[i] + a[i + 1] > x) {
				long minus = a[i + 1] + a[i] - x;
				ans += Math.max(minus, 0);
				if(minus <= 0) continue;
				a[i + 1] = Math.max(a[i + 1] - minus, 0);
				minus -= a[i + 1];
				if(minus > 0) {
					a[i] -= minus;
				}
			}
		}

		long ansB = 0;
		for(int i = 0; i + 1 < N; i++) {
			if(b[i] + b[i + 1] > x) {
				long minus = b[i + 1] + b[i] - x;
				ansB += Math.max(minus, 0);
				if(minus <= 0) continue;
				b[i + 1] = Math.max(b[i + 1] - minus, 0);
				minus -= b[i + 1];
				if(minus > 0) {
					b[i] -= minus;
				}
			}
		}
		System.out.println(Math.min(ans, ansB));
	}
}

Measured memory_bytes: 63176
import math
A,B,N = map(int,input().split())
siki = 0
k = math.floor(N/B)
m = k*B
if (B-1) <= N:
    siki = math.floor((A*(B-1))/B)-A*math.floor((B-1)/B)
elif B>N:
    siki = math.floor((A*N)/B)-A*math.floor((N/B))

print(siki)

Measured memory_bytes: 62176