akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define INFTY 1000000007

int merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  
  //L[0...n1], R[0...n2] を生成
  int L[n1+1], R[n2+1];
  for(int i = 0; i < n1; i++) L[i] = A[left + i];
  for(int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  
  int i = 0, j = 0;
  for(int k = left; k < right; k++) {
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    }
    else { 
      A[k] = R[j];
      j++;
    }
  }
  return right-left;
}

int mergeSort(int A[], int left, int right) {
  int ret = 0;
  if(left+1 < right) {
    int mid = (left + right)/2;
    ret += mergeSort(A, left, mid);
    ret += mergeSort(A, mid, right);
    ret += merge(A, left, mid, right);
  }
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  int s[n];
  rep(i, 0, n) cin >> s[i];
  
  int ans = mergeSort(s, 0, n);
  
  rep(i, 0, n) 
    cout << (i ?" " :"") << s[i];
  
  cout << "\n" << ans << "\n";
}


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

using namespace std;
using ll = long long;

const ll MOD_VAL = 1e9+7;
ll dp[2][100005];
int n;
vector<int> edges[100005];

ll dfs(int s, int v, int p){
    if(dp[s][v]!=-1) return dp[s][v];
    //여유로운 경우

    ll black = 1;
    ll white = 1;
    if(s){
        for(int k: edges[v]){
            if(k==p) continue;
            black *= dfs(0, k, v);
            black %= MOD_VAL;
        }
    }
    for(int k: edges[v]){
        if(k==p) continue;
        white *= dfs(1, k, v);
        white %= MOD_VAL;
    }
    ll res = 0;
    if(s) res = (white+black)%MOD_VAL;
    else res = white%MOD_VAL;
    return dp[s][v] = res;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, -1, sizeof(dp));
    cin>>n;
    for(int i=0;i<n-1;i++){
        int x, y;
        cin>>x>>y;
        x--;y--;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    cout<<dfs(1, 0,-1);
    return 0;
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9 + 7;
pair<ll, ll>s4[4] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
pair<ll, ll>s8[8] = {{ -1, -1}, { -1, 0}, { -1, 1}, {0, -1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};

void judge() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int has[1000001] ;
void solve() {
    int n;
    cin >> n;
    int a[n];
    memset(has, 0, sizeof(has));
    for (int i = 0; i < n; i++) {
        cin >> a[i];

    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        if (a[i] == a[i - 1] && i > 0) {
            has[a[i]]++;
            continue;
        }

        for (int j = a[i]; j <= 1000000; j += a[i]) {
            has[j]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (has[a[i]] == 1)
            ans++;
    }
    cout << ans << nl;
}

signed main() {
    judge();
    boost;
    solve();
}


Measured memory_bytes: 8336
S = input()
T = input()
l = []
for i in range(len(S)-len(T)+1):
    flag = 0
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = 1
    if flag == 0:
        S1 = S[:i]+T+S[i+len(T):]
        S2 = S1.replace("?","a")
        l.append(S2)
print(sorted(l)[0] if len(l) > 0 else "UNRESTORABLE")

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

/* short */
#define pb push_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++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

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

struct Magic {
  ll damage;
  ll power;
  double eff;
};

bool operator< (Magic s, Magic t) {
  return s.power < t.power;
}

vector<Magic> ml;

ll N = 0;
ll H = 0;
ll t;
ll ret = 0;
string s;
ll table[10005];

void input() {
  IN(H);
  IN(N);
  REP(i, N) {
    ll A, B;
    IN(A);
    IN(B);
    Magic m = {A, B, ((double)A)/((double)B)};
    ml.pb(m);
  }
}

void solve() {
  FOR(i, 1, H+1) {
    ll s = 100000000;
    FOREACH(m, ml) {
      ll rest = i - m.damage;
      if (rest <= 0) CHMIN(s, m.power);
      else CHMIN(s, m.power + table[rest]);
    }
    table[i] = s;
    // DEBUG(s);
  }
  PRINT(table[H]);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 384
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc097d {
private:
    void dfs(int u, const vector<vector<int>> &g, const vector<int> &p, vector<int> &comp,
            vector<int> &comp2) {
        for (int v : g[u]) {
            if (!comp[v]) {
                comp2[p[v]] = comp[u];
                comp[v] = comp[u];
                dfs(v, g, p, comp, comp2);
            }
        }
    }
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        vector<int> p(N);
        for (int i = 0; i < N; ++i) {
            in >> p[i];
            --p[i];
        }
        vector<pair<int, int>> xy(M);
        vector<vector<int>> g(N);
        for (int i = 0; i < M; ++i) {
            in >> xy[i].first >> xy[i].second;
            --xy[i].first;
            --xy[i].second;
            g[xy[i].second].push_back(xy[i].first);
            g[xy[i].first].push_back(xy[i].second);
        }
        vector<int> comp(N, 0), comp2(N, 0);
        int id = 0;
        for (int i = 0; i < N; ++i) {
            if (!comp[i]) {
                comp[i] = ++id;
                comp2[p[i]] = id;
                dfs(i, g, p, comp, comp2);
            }
        }
        int res = 0;
        for (int i = 0; i < N; ++i) {
            if (comp[i] == comp2[i]) {
                ++res;
            }
        }
        out << res << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc097d solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int Ac(int na){
  return na*2;
}

int Bc(int nb,int kb){
  return nb+kb;
}


int main(){
  int n,k,a,b,c;
  cin >> n >> k;
  c = 1;
  for(int i = 0;i < n;i++){
    a = Ac(c);
    b = Bc(c,k);
    if(a < b){
      c = a;
    }
    else{
      c = b;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int Ht,Ha,At,Aa;
  scanf("%d",&Ht);
  scanf("%d",&At);
  scanf("%d",&Ha);
  scanf("%d",&Aa);
  while(1){
    Ha-=At;
    if(Ha<=0){
      printf("Yes");
      break;
    }
    Ht-=Aa;
    if(Ht<=0){
      printf("No");
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1692
//https://atcoder.jp/contests/arc071/tasks/arc071_d

#include<bits/stdc++.h>
const int N = 2e6 + 5;
const int mod = 1e9 + 7;
using namespace std;

int n, dp[N], sum[N];

void add(int&a, int b){
    a += b; if (a >= mod) a -= mod; if (a < 0) a += mod;
}

int main(){
    cin >> n;
    dp[0] = 1; sum[0] = 1;
    for (int i = 1; i <= 2*n; i++){
        if (i <= n) dp[i] = dp[i-1];
        if (i > 2) add(dp[i], sum[min(i-3, n-2)]);
        if (i > n+1) add(dp[i], -sum[i-n-2]);
        sum[i] = sum[i-1]; add(sum[i], dp[i]);
    }
    cout << (1LL * sum[n-2] * (n-1) % mod * (n-1) + 1LL * dp[n-1] * (n-1) % mod + sum[2*n] - sum[n-1] + mod) % mod;
}


Measured memory_bytes: 15872
import java.util.Scanner;
public class Main{
    public static void main (String [] args){
        Scanner sc= new Scanner (System.in);
        
        int x= sc.nextInt ();
         int y= sc.nextInt ();
        
        int result;
        if (((1 <= x) &&  (x <= 10000)) && ((1 <= y) &&  (y <= 10000))) {
        result = (x*y);
        if (result%2==0){
           System.out.println("Even");
        }
        else {
               System.out.println("Odd");
        }
        
    }
}
}

Measured memory_bytes: 20564
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int n;
vector<string> v;
int count(int line){
  int res = 0;
  int i = 0;
  while(v[line][i++]=='.') res++;
  return res;
}
int calc(int& line,int depth){
  if(v[line][depth]=='+'){
    int ret=0;
    line++;
    while(line<n && count(line)==depth+1){
      ret += calc(line,depth+1);
    }
    return ret;
  }
  else if(v[line][depth]=='*'){
    int ret=1;
    line++;
    while(line<n && count(line)==depth+1){
      ret *= calc(line,depth+1);
    }
    return ret;
  }
  else return v[line++][depth]-'0';
}
int solve(){
    int line = 0;
    int ans = calc(line,0);
    return ans;
}
int main(){
  while(cin >> n,n){
    v.resize(n);
    rep(i,n) cin >> v[i];
    cout << solve() << endl;
  }
  return 0;
}




Measured memory_bytes: 3156
x,y,z,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
sum_list = []
for a_i in range(x):
    for b_i in range(y):
        if a_i*b_i > k:
            break
        for c_i in range(z):
            if a_i*b_i*c_i > k:
                break
            sum_list.append(a[a_i]+b[b_i]+c[c_i])
sum_list.sort(reverse=True)
for i in range(k):
    print(sum_list[i])

Measured memory_bytes: 114380
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC110_A();
        }

        static void ABC110_A()
        {
            var ABC = Console.ReadLine().Split(' ').Select(int.Parse).OrderByDescending(x => x).ToArray();
            Console.WriteLine((ABC[0] * 10) + ABC[1] + ABC[2]);
        }
    }
}

Measured memory_bytes: 13396
#include<stdio.h>
int main(void){
  int n,k;
  long debt=100000;
  scanf("%d",&n);
  for(k=1;k<=n;k++){
    debt*=1.05;
    if(debt%1000!=0){
      debt/=1000;
      debt++;
      debt*=1000;
    }
  }
  printf("%ld\n",debt);
  return 0;
}

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

int main() {
  string s;
  while (cin >> s, s != "0") {
    int a = 0, b = 0;
    for (int i = 0; i < s.size() - 1; i++) {
      if (s[i + 1] == 'A') a++;
      else b++;
    }
    if (a > b) a++;
    else b++;
    cout << a << " " << b << "\n";
  }
}


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

using namespace std;

using ll = long long;

int main() {
	ll N;
	int K;
	cin>>N>>K;
	int ans = 0;
	while (N) {
		N /= K;
		ans += 1;
	}

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


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

int main() {
string S;
cin >> S;
string ans = "";
if (S == "Sunny") {
  ans = "Cloudy";
}
else if (S == "Cloudy") {
  ans = "Rainy";
}
else {
  ans = "Sunny";
}

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
//#define endl "\n"
#define fi first
#define se second
#define fr front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}




int main() {
	queue<string>que;
	queue<int>q;
	int n;
	cin >> n;
	que.push("a");
	q.push(1);
	while (que.front().size() <= n - 1) {
		for (int i = 0; i <= q.front(); i++) {
			que.push(que.front() + (char)(97 + i));
			if (i == q.front()) {
				q.push(q.front() + 1);
				continue;
			}
			q.push(q.front());
		}
		que.pop();
		q.pop();
	}
	while (!que.empty()) {
		cout << que.front() << endl;
		que.pop();
	}
}



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

const ll mod = 1e9+7;

ll factorial(ll x) {
  ll ans = 1;
  for (int i = 2; i <= x; ++i) {
    ans = (ans * i) % mod;
  }
  return ans;
}

int main()
{
  int N, M; cin >> N >> M;
  if (N == M) {
    ll fact = factorial(N);
    cout << (2*fact*fact)%mod << endl;
  } else if (abs(N-M) == 1){
    ll fact1 = factorial(N);
    ll fact2 = factorial(M);
    cout << (fact1*fact2)%mod << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<vector>

#define re register

#define il inline

#define ll long long

#define max(a,b) ((a)>(b)?(a):(b))

#define min(a,b) ((a)<(b)?(a):(b))

#define fp(i,a,b) for(re int i=a;i<=b;i++)

#define fq(i,a,b) for(re int i=a;i>=b;i--)

using namespace std;

const int mod=1e9+7,N=1e6+100;

ll n,x,jc[N],p,ans,Need,f[N],inv[N];

il ll gi()

{

  re ll x=0,t=1;

  re char ch=getchar();

  while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();

  if(ch=='-') t=-1,ch=getchar();

  while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();

  return x*t;

}

il ll C(re ll x,re ll y)

{

  return jc[y]*inv[y-x]%mod*inv[x]%mod;

}

int main()

{

  n=gi();Need=(n+1)/2;

  jc[0]=inv[0]=inv[1]=1;

  fp(i,2,n) inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;//printf("%lld ",inv[i]);

  fp(i,1,n) jc[i]=jc[i-1]*i%mod;

  fp(i,2,n) inv[i]=inv[i]*inv[i-1]%mod;

  fp(i,Need,n-1) f[i]=C(n-i-1,i-1)*jc[i]%mod*jc[n-i-1]%mod;

  fq(i,n-1,Need) f[i]=(f[i]-f[i-1]+mod)%mod;

  fp(i,Need,n-1) (ans+=(f[i]*i%mod))%=mod;

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

  return 0;

}


Measured memory_bytes: 21632
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

map<ll,ll> prime_factor(ll n){ //素因数分解
	map<ll,ll> ret;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0){
			ret[i]++;
			n /=i;
		}
	}
	if(n!=1) ret[n] =1;
	return ret;
} 

int main(){
	ll n,p;
    ll ans=1;
    cin >> n >> p;
  	map<ll,ll> sosuu = prime_factor(p);
    for(auto& it:sosuu){
        ans *= pow(it.F,(int)it.S/n);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int[] d = new int[n];
		for (int i = 0; i < n; i++)
			d[i] = scanner.nextInt();
		Arrays.sort(d);
		int ans = c / a;
		for (int i = n - 1; i >= 0; i--) {
			c += d[i];
			a += b;
			if (ans > c / a)
				break;
			ans = c / a;

		}
		System.out.println(ans);

	}
}

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

float abso(float a)
{
	if(a < 0)
		return (-1.0f)*a;
	else 
		return (1.0f)*a;
}

int main()
{
	int n;
	int c=1;
	float out = 0;
	float x[1000] = {0};
	float y[1000] = {0};
	float o[1000] = {0};

	while( cin >> n , n)
	{
		for( int i = 0; i < n; i++)
		{
			cin >> x[i] >> y[i];
		}
		
		for( int i = 1; i < n - 1 ; i++)
		{
			float x1 = x[i] - x[0];
			float x2 = x[i+1] - x[0];
			float y1 = y[i] - y[0];
			float y2 = y[i+1] - y[0];

			out += x1*y2 - x2*y1;
		}

		o[c] = 0.5*abso(out);
		c++;

		for( int i = 0; i < 1000; i++)
		{
			x[i] = 0;
			y[i] = 0;
		}
		out = 0;
	}

	for(int i = 1; i < c ; i++)
	{
		printf("%d %.1f\n", i, o[i]);
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int ai[200005];
int bi[200005];
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==0)
    {
        if(b==100)
            printf("101");
            else
            printf("%d",b);
    }
    if(a==1)
    {
        if(b==100)
            printf("10100");
        else
            printf("%d",b*100);
    }
    if(a==2)
    {
        if(b==100)
            printf("1010000");
        else
            printf("%d",b*10000);
    }
    return 0;
}


Measured memory_bytes: 128
use std::io;
use std::cmp;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();

    stdin
        .read_line(&mut buf)
        .unwrap();

    let abc: Vec<usize> = buf.split_whitespace().map(|n| n.parse().unwrap()).collect();
    println!("{}", cmp::min(cmp::min(abc[0]+abc[1], abc[1]+abc[2]), abc[0]+abc[2]))
}

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

int main() {
  int p,q,r;
  int ans=0;
  cin >> p >> q >>r;
  if(p > q && p > r){
    ans = q + r;
  }else if(q>r){
    ans = r + p;
  }else{
    ans = p + q;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<int>> next(26, vector<int>(n));
  vector<int> last_of(26, n);
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < 26; ++j)
      next[j][i] = last_of[j];
    last_of[s[i] - 'a'] = i;
  }
  vector<int> dist(n + 1);
  vector<int> use_value(n);
  dist[n] = 0;
  for (int i = n - 1; i >= 0; --i) {
    dist[i] = n + 1;
    for (int j = 0; j < 26; ++j) {
      int res = 1 + dist[next[j][i]];
      if (res < dist[i]) {
        use_value[i] = j;
        dist[i] = res;
      }
    }
  }
  int result_size = n + 1;
  for (int j = 0; j < 26; ++j)
    result_size = min(result_size, 1 + dist[last_of[j]]);
  string result(result_size, ' ');
  for (int j = 0; j < 26; ++j)
    if (1 + dist[last_of[j]] == result_size) {
      int k = 0;
      result[k++] = 'a' + j;
      for (int i = last_of[j]; i < n;) {
        result[k++] = 'a' + use_value[i];
        i = next[use_value[i]][i];
      }
      break;
    }
  printf("%s\n", result.c_str());
  return 0;
}


Measured memory_bytes: 22388
n = int(input())
A = list(map(int,input().split()))
for i in range(n):
    if A[i] % 2 == 0:
        if A[i]%3 == 0 or A[i] % 5 == 0:
            pass
        else:
            print('DENIED')
            exit()
print('APPROVED')


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

#define ff first
#define ss second
#define endl '\n'

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

	string s;
	cin >> s;

	int a, b, c, d;
	a = (1 << (s[0] - 'a'));

	for (int i = 1; i < s.size(); ++i) {
		b = (1 << (s[i] - 'a'));
		if (a & b) {
			cout << i << ' ' << i+1 << endl;
			return 0;
		}

		a = b;
	}

	a = (1 << (s[0] - 'a'));
	b = (1 << (s[1] - 'a'));
	for (int i = 2; i < s.size(); ++i) {
		c = (1 << (s[i] - 'a'));
		if ((a & b) || (b & c) || (a & c)) {
			cout << i-1 << ' ' << i+1 << endl;
			return 0;
		}

		a = b;
		b = c;
	}

	if (s.size() < 3) {
		cout << -1 << ' ' << -1 << endl;
		return 0;
	}

	a = (1 << (s[0] - 'a'));
	b = (1 << (s[1] - 'a'));
	c = (1 << (s[2] - 'a'));
	for (int i = 3; i < s.size(); ++i) {
		d = (1 << (s[i] - 'a'));
		if ((a & b & (a | b)) || (a & c & (b | d)) || (a & d & (b | c)) || (b & c & (a | d)) || (b & d & (a | c)) || (c & d & (a | b))) {
			cout << i-2 << ' ' << i+1 << endl;
			return 0;
		}

		a = b;
		b = c;
		c = d;
	}

	cout << -1 << ' ' << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
constexpr int INF = 1 << 30;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    VI a(m);
    REP(i,0,m) cin >> a[i];
    VI need = {-1,2,5,5,4,5,6,3,7,6};
    VI dp(n+1, -INF);
    dp[0] = 0;
    REP(i,0,n+1) {
        for (auto &num: a) {
            if (i - need[num] < 0) continue;
            dp[i] = max(dp[i], dp[i-need[num]]+1);
        }
    }
    int len = dp[n];
    sort(all(a));
    reverse(all(a));
    while (n > 0) {
        for (auto &i: a) {
            if (n - need[i] >= 0 && dp[n - need[i]] == len - 1) {
                cout << i;
                --len;
                n -= need[i];
                break;
            }
        }
    }
    cout << endl;
}

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

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

#define INT int
#define REP(i,a,b) for(INT i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
    char str[10];
    rep(i,3) {
        cin >> str[i];
    }
    
    if(str[0] != str[1] && str[0] != str[2] && str[1] != str[2]) cout << "Yes"<<endl;
    else cout << "No" << endl;
    
    return 0;
}


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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    x,y=MI()
    if x%y==0:
        print(-1)
    else:
        print(x*(y+1))

main()


Measured memory_bytes: 61888
import sys
sys.setrecursionlimit(10**8)

def dfs(v, dist, d = 0, p = -1):
#     print(v, d)
    dist[v] = d
    for u in to[v]:
        if u == p:
            continue
        dfs(u, dist, d + 1, v)
def calcDist(s, dist):
    dfs(s, dist)        
n, u, v = map(int, input().split())
u -= 1
v -= 1
to = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
distS = [0] * n
distT = [0] * n
calcDist(u, distS)
calcDist(v, distT)
mx = 0
for i in range(n):
    if distS[i] < distT[i]:
        mx = max(mx, distT[i])
ans = mx - 1
print(ans)

Measured memory_bytes: 117048
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int M = Integer.parseInt(sc.next());
        int[] A = new int[N];
        long[] ruiseki = new long[N+1];
        for (int i=0;i<N;i++) {
            A[i] = Integer.parseInt(sc.next());
            ruiseki[i+1] = ruiseki[i] + A[i];
        }
        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int i=0;i<N+1;i++) {
            int r = (int)(ruiseki[i]%M);
            if (map.containsKey(r)) {
                map.put(r, map.get(r)+1);
            } else {
                map.put(r, 1);
            }
        }
        ArrayList<Integer> value = new ArrayList<Integer>(map.values());
        long ans = 0L;
        for (Integer i : value) {
            ans += (long)i*(i-1)/2;
        }
        // System.out.println(map);
        // System.out.println(value);
        System.out.println(ans);
    }
}

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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)
#define pi (double)3.141592653589793238
bool comp(int a, int b){
	return a>b;
}

int main() 
{ 
	JJ;
	double a,b,h,m; cin>>a>>b>>h>>m;
	h=h*5+(m/12);
	double angle=((h-m)*pi)/30;
	double c=a*a + b*b - (2*a*b*cos(angle));
	cout<<fixed<<setprecision(20)<<sqrt(c)<<endl;





	return 0;



    
} 

Measured memory_bytes: 4180
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<tuple>
#define int long long
using namespace std;

signed main() {
	int D,N;
	cin >> D >> N;
	int A = 1;
	for(int i = 0;i < D;i++) {
		A = A * 100;
	}
	if(N == 100) {
		cout << 101 * A << endl;
	}
	else {
		cout << N * A << endl;
	}
}

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

using namespace std;

using ll = long long;

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n>0){
        if(n&1) res = res *x%mod;
        x = x*x%mod;
        n>>=1;
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; string s; cin >> n >> s;
    ll x = 0ll;
    ll y = 0ll;
    ll mod = 0;
    rep(i,0,n){
        if(s[i]=='1'){
            mod++;
        }
    }
    rep(i,0,n){
        if(s[i]=='1'){
            x += mod_pow(2,(n-i-1),mod+1);
            if(mod-1>0){
                y += mod_pow(2,(n-i-1),mod-1);
                y %= (mod-1ll);
            }
            x %= (mod+1ll);
        }
    }
    rep(i,0,n){
        ll ans = 1;
        ll p;
        if(mod-1==0 && s[i]=='1'){
            cout << 0 << endl;
            continue;
        }
        if(s[i]=='1'){
            p = y;
            p -= mod_pow(2,n-i-1,mod-1);
            p += 2*(mod-1);
            p %= (mod-1);
        }
        else{
            p = x;
            p += mod_pow(2,n-i-1,mod+1);
            p %= (mod+1);
        }
        while(p>0){
            ll mod1 = 0ll;
            for(ll j=1; j<=p; j *= 2ll){
                if(p & j){
                    mod1++;
                }
            }
            p %= mod1;
            ans++;
        }
        cout << ans << endl;
    }
}

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

int main(){
    int i,amari,tmp;
    cin >> i;

    tmp = i / (60*60);
    amari = i % (60*60);
    cout << tmp << ":";
    tmp = amari / 60;
    amari = amari % 60;
    cout << tmp << ":" << amari << endl;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(){
	int a[4][13], n, m, i, j; 
	char c,ch;
	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			a[i][j] = 0;  //カードを初期化
		}
	}
	//所持しているカードを出力
	scanf("%d",&m);
	for(i = 0; i < m; i++){
		getchar();      //%cにenterやスペースが入るのを防ぐ
		scanf("%c %d", &ch, &n);
		if(ch == 'S'){
			a[0][n] = 1;    //所持しているカードを1と考える
		}
		else if(ch == 'H'){
			a[1][n] = 1;
		}
		else if(ch == 'C'){
			a[2][n] = 1;
		}
		else if(ch == 'D'){
			a[3][n] = 1;
		}
	}
	//なくなったカードを出力
	for(j = 1; j <= 13; j++){
		if(a[0][j] != 1)   //所持カードは1となっているので、それ以外は所持していない
		printf("S %d\n",j);
	}
	for(j = 1; j <= 13; j++){
		if(a[1][j] != 1)
		printf("H %d\n",j);
	}
	for(j = 1; j <= 13; j++){
		if(a[2][j] != 1)
		printf("C %d\n",j);
	}
	for(j = 1; j <= 13; j++){
		if(a[3][j] != 1)
		printf("D %d\n",j);
	}
	return 0;
}


Measured memory_bytes: 2048
s = input()
K = int(input())
pool = set()
n = 0
slist = list(s)

for i in range(26):
  c = s.count(chr(97+ i))
  for j in range(c):
    index = slist.index(chr(97+ i))
    slist[index] = ""
    for k in range(len(s)- index):
      pool.add(s[index:index+ k+ 1])
      if(k>= K):
        break
  if(len(pool)>= K):
    newlist = list(pool)
    newlist.sort()
    print(newlist[K- 1])
    break

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#pragma warning (disable:4996)
typedef long long LL;
const int maxn = 2005;
LL a[maxn], m[maxn];
int main() {
	LL n, cnt, sum = 0;
	scanf("%lld%lld", &n, &cnt);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		m[i] = a[i];
		sum += a[i];
	}
	LL Min = sum; int p;
	for (int k = 1; k < n; k++) {
		for (int i = 0; i < n; i++) {
			p = i - k < 0 ? i - k + n : i - k;
			if (a[p] < m[i]) {
				sum -= m[i] - a[p];
				m[i] = a[p];
			}
		}
		Min = min(Min, sum + cnt * k);
	}
	printf("%lld\n", Min);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# greedy algorithm
inp = list(map(int, input().split()))
N = inp[0]
C = inp[1]
K = inp[2]

t = []
for i in range(0, N):
    t.append(int(input()))

t.sort()

b = 0
p = 0
s = -1
for i in range(0, N):
    # passenger limit or last passenger
    if p == C:
        b += 1
        p = 0
        s = -1
    # first passenger
    if s == -1:
        s = t[i]
        p = 1
        continue
    # passenger gets anger if he takes the last bus
    if t[i] > s + K:
        b += 1
        p = 1
        s = t[i]
        continue
    # following passenger in time
    else:
        p += 1
# last passenger left
if p > 0:
    b += 1
print(b)

Measured memory_bytes: 7444
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)



int main() {
	int n, cnt = 0, mem;
	string s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'E')cnt++;
		mem = cnt;
	}
	
	for (int i = 0; i < n; i++) {
		//cout << cnt << endl;
		if (s[i] == 'W') cnt++;
		if (s[i] == 'E') cnt--;
		//if (s[i] == 'E') cnt--;

		if (min(mem, cnt) == cnt) {
			mem = cnt;
		}
	}

	cout<< mem << endl;
}




Measured memory_bytes: 900
main = do
  getLine
  s <- lines <$> getContents
  let xs = map searchAB s
  let xsum = sum $ map (\(i, _, _) -> i) xs
  let endAsum = length $ filter (\(_, l, _) -> l) xs
  let startBsum = length $ filter (\(_, _, l) -> l) xs
  let loneAorB = any (\(_, l, m) -> l /= m) xs
  print $ xsum + max 0 (min endAsum startBsum - (if loneAorB then 0 else 1))
  
searchAB s = (countAB, isendA, isstartB)
  where
    countAB = length . filter (== True) $ zipWith isAB s (tail s)
    isAB x y = if x == 'A' && y == 'B' then True else False
    isendA = last s == 'A'
    isstartB = head s == 'B'


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

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ir = N / R;

    int ans = 0;
    for (int i = 0; i <= ir; i++) {
        int ig = (N - i * R) / G;
        for (int j = 0; j <= ig; j++)
        {
            int tmp = i * R + j * G;
            if (tmp <= N && ((N - tmp) % B == 0))
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define FFOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>


signed main(){
	
	int q,h,s,d;cin>>q>>h>>s>>d;
	int n;cin>>n;
	
	if(2*q<h) h=2*q;
	if(2*h<s) s=2*h;
	if(2*s<d) d=2*s;
	
	int ans = 0;
	
	ans += n/2 * d;
	n%=2;
	ans += n*s;
	
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[200010];
ll ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 1; i < n; i++)ans += a[i / 2];
	cout << ans << endl;
}


Measured memory_bytes: 4412
import sys


N, *AB = map(int, open(0).read().split())
A = AB[:N]
B = AB[N:]

# 手前から数を揃えて余りを蓄積させていく
# 最後に余りをやりくりできれば Yes さもなくば No 
res_a = 0
res_b = 0
for i, (a, b) in enumerate(zip(A, B)):
  if i < N - 1:
    if a == b:
      continue
    
    # b の方が大きい場合、偶奇を合わせて res_b を増やす
    elif a < b:
      # 偶奇を合わせる
      if (b - a) % 2:
        b += 1
        if res_b:
          res_b -= 1
        else:
          a += 2
          
      # res_a が余っていれば補填する
      if b - a <= res_a:
        res_a -= b - a
      # res_a で補填できなければ res_b を増やす
      else:
        a += res_a
        res_a = 0
        res_b += (b - a) // 2
      
    else:
      # bの方が小さい場合、余っている数で補填する
      # 補填できれば、continue
      if a - b <= res_b:
        res_b -= a - b
      # 補填できなければ、偶奇を合わせて res_a を増やす
      else:
        b += res_b
        res_b = 0
        
        # 偶奇合わせ
        if (a - b) % 2:
          res_a += 2
          b += 1
        
        res_a += 2 * (a - b)
        
  
  else:
    a += res_a
    b += res_b
      
    if a > b:
      print("No")
      sys.exit()
    else:
      print("Yes")
      sys.exit()


Measured memory_bytes: 5236
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int h1 = s.nextInt();
        int m1 = s.nextInt();
        int h2 = s.nextInt();
        int m2 = s.nextInt();
        int k = s.nextInt();
        int c = 0;
        int st = h1*60+m1;
        int ed = h2*60+m2;
        for(int i=0; ;i++)
        {
            ed-=k;
            if(ed>=st)
            {
                c=ed-st;
                break;
            }
            else
                break;
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 35608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
  if (left > right) {
    cout << "Left" << endl;
  } else if (left < right) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n, m;
	cin >> n >> m;
	if (n>= m/2) print(m / 2);
	else {
		print(n+(m - n * 2) / 4);
	}
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
int ans=1;
while(ans<=n){
    ans*=2;
}
ans/=2;
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>
#include <utility>

using namespace std;

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

signed main()
{
	int A, B; cin >> A >> B;

	int ans = 1010;

	if (12.5 * A <= 10*B and 10*B < 12.5 * (A+1)) {
		ans = min(ans, 10*B);
	}

	if (10 * B <= 12.5 * A and 12.5 * A < 10 * (B + 1)) {
		if (A % 2 == 0) {
			ans = min(ans, 25 * A / 2);
		} else if (10*B <= ceil(12.5*A) and ceil(12.5*A) < 10*(B+1)) {
			ans = min(ans, (int)ceil(12.5*A));
		}
	}

	if (ans == 1010) 
		cout << -1 << endl;
	else
		cout << ans << endl;
}


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

int n, a[100111];

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

	cin >> n;

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

	bool ok = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] > a[i + 1] && a[i] - 1 == a[i + 1]) a[i]--;
		else if (a[i] > a[i + 1]) ok = 0;
	}

	if (ok) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>

int main(){
	double t;
	scanf("%lf", &t);
	double max = t, min = t;
	while(~scanf("%lf", &t)){
		if(max < t){
			max = t;
		}
		if(min > t){
			min = t;
		}
	}
	printf("%lf", max - min);
}

Measured memory_bytes: 1076
// Working program with FastReader
import java.io.BufferedReader; 

import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer;
import java.lang.*;
public class Main
{ 
	static class FastReader 
	{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

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

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

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

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	} 

	long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		return gcd(b,a%b);
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int k = ob.nextInt(),x=ob.nextInt();
		if((k*500)<x) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
	}

} 


Measured memory_bytes: 21332
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#define RG register
#define LL long long
using namespace std;
LL n,s,anss=3e18;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline I mi(const I&a,const I&b){return a<b ? a : b;}
template<typename I>inline I f(I bb,I nn)
{
	I ans=0;
	for(;nn;nn/=bb) ans+=nn%bb;
	return ans;
}
int main()
{
	//freopen("Digit Sum.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,s);
	if(n==s)
	{
		printf("%lld\n",n+1);
		return 0;
	}
	if(n<s) 
	{
		printf("-1\n");
		return 0;
	}
	for(LL i=2;i<=sqrt(n);i++)
	{
		if(f(i,n)==s)
		{
			printf("%lld\n",i);
			return 0;
		}
	}
	for(LL i=1;i*i<=n-s;i++)
	{
		if((n-s)%i==0)
		{
			LL b=(n-s)/i+1;
			if(f(b,n)==s) anss=mi(anss,b);
		}
	}
	printf("%lld\n",anss==3e18 ? -1 : anss);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#pragma warning (disable:4996)

int main() {
	int n;
	scanf("%d", &n);
	int m = (int)(n / 10);
	switch (n - m * 10) {
	case 0:
	case 1:
	case 6:
	case 8:
		printf("pon");
		break;
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		printf("hon");
		break;
	case 3:
		printf("bon");
		break;
	}
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
long long a[45];
int main()
{
    string s;
    int i,a,b,c,d;
    cin>>s;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    if(((a==0 && b!=0) || (a==1 && b<=2)) && ((c==0 && d!=0) || (c==1 && d<=2) ))
        cout<<"AMBIGUOUS"<<endl;
    else if(((a==0 && b!=0) || (a==1 && b<=2)))
        cout<<"MMYY"<<endl;
    else if(((c==0 && d!=0) || (c==1 && d<=2) ))
        cout<<"YYMM"<<endl;
    else
        cout<<"NA"<<endl;
//    for(i=0;i<=41;i++)
//    {
//        a[i]=pow(2,i);
//        cout<<a[i]<<" ";
//    }
//    for(i=0;i<=41;i++)
//    {
//        if(a[i]>n)
//        {
//            f=2;
//            break;
//        }
//        else if(a[i]==n)
//        {
//            f=1;
//            break;
//        }
//    }
//    cout<<i<<endl;
//    if(f==1)
//        cout<<1+((i+2)*2)<<endl;
//    else
//       cout<<1+((i+1)*2)<<endl;
}




Measured memory_bytes: 256
k,n = map(int, input().split())

a = [ int (x) for x in input().split() ]

kyori_sa = []

for i in range(n):
  if i == len(a)-1:
    kyori_sa.append(a[0] + ( k - a[i] ))
  else:
    kyori_sa.append(a[i+1] - a[i])

print(k-max(kyori_sa))
     

Measured memory_bytes: 25452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
#define INF 1000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n % 2 == 0) {
    ll mM = b[n/2] + b[(n/2)-1];
    ll mm = a[n/2] + a[(n/2)-1];
    cout << mM - mm + 1 << endl;
  } 
  else {
    cout << b[n/2] - a[n/2] + 1;
  }
}

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

int main() {
  int N;
  int health = 0;
  vector<int> takoyaki;

  cin >> N;

  for (int i = 0; i < N ; i++) {
    int input;
    cin >> input;
    takoyaki.push_back(input);
  }

  for (int j = 0; j < N; j++) {
    for (int k = j + 1; k < N; k++) {
      health += takoyaki[j] * takoyaki[k];
    }
  }
  cout << health;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int A,B,C,D,E,F ;
  cin >>A>> B >> C >> D >> E >> F ;
  int answ=0 ;
  int anss=0 ;
  double a=-1 ;
  for(int i=0;A*100*i<=F;i++){
    for(int j=0;A*100*i+B*100*j <= F;j++){
      double water = A*100*i+B*100*j ;
      for(int k=0;C*k <= E*water/100 && water+C*k <= F;k++){
        for(int l=0;C*k + D*l <= E*water/100 && water+C*k+D*l<=F;l++){
          double suger = C*k+D*l ;
          if(water != 0){
            double ans=100*suger/(water+suger) ;
            if(ans > a){
              a = ans;
              answ = water + suger ;
              anss = suger ;
            }
          }
        }
      }
    }
  }
  cout << answ << " " << anss << endl;
}
          

Measured memory_bytes: 256
object Main extends App {
  import io.StdIn.readLine
  
  println {
    (readLine().last: @annotation.switch) match {
      case '2' | '4' | '5' | '7' | '9' => "hon"
      case '0' | '1' | '6' | '8' => "pon"
      case _ => "bon"
    }
  }
}

Measured memory_bytes: 54528
k, n = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)
b = []
for i in range(n - 1):
    b.append(a[i + 1] - a[i])

b.append(k - (a[n - 1] - a[0]))

print(k - max(b))


Measured memory_bytes: 25580
N=int(input())
listA1=list(map(int,input().split()))
listA2=list(map(int,input().split()))
SUM=0
if N==1:
  SUM=sum(listA1)+sum(listA2)
else:  
  for i in range(1,N):
    if sum(listA1[:i]+listA2[i-1:])>SUM:
      SUM=sum(listA1[:i]+listA2[i-1:])
print(SUM)

Measured memory_bytes: 3064
N, Q = map(int, input().split())
S = input()
cnt = 0
last = ' '
x = []

for i in range(N):
    if S[i] == 'A':
        last = 'A'
    else:
        if last == 'A' and S[i] == 'C':
            cnt += 1
        last = ' '
    x.append(cnt)

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


Measured memory_bytes: 6128
#include<stdio.h>
int main(void){
    int a,b,i,j;
    scanf("%d",&a);
    int n[a][3],ans[200][3]={0},cou[a];
    for(i=0;i<a;i++){
        scanf("%d %d %d",&n[i][0],&n[i][1],&n[i][2]);
    }
    for(b=0;b<3;b++){
        for(i=0;i<a;i++){
            for(j=i+1;j</*a-i-1*/a;j++){
                if(n[i][b]==n[j][b]){
                    ans[i][b]=1;
                    ans[j][b]=1;

                }
            }
        }
    }
    for(i=0;i<a;i++){
        for(j=0;j<3;j++){
            if(ans[i][j]==1){
                n[i][j]=0;
            }
        }
    }
    for(i=0;i<a;i++){
        cou[i]=n[i][0]+n[i][1]+n[i][2];
    }
    for(i=0;i<a;i++){
        printf("%d\n",cou[i]);
    }
return 0;
}

Measured memory_bytes: 600