akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define ll long long
#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,c) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n)	for(int i=0;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
	typedef vector<int> vi;
	typedef vector<vector<int>> vvi;
	typedef vector<long long> vll;
	typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;
int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
bool comp(int a, int b) 
{ 
    return (a < b); 
} 

// string s,t,s1,t1;
// int ans()
// {
// 	// string s1,t1;
// 	s1.erase(all(s1));
// 	t1.erase(all(t1));
// 	int n= s.size();
// 	char c = s[0];
// 	if(n==1)return 0;
// 	// int n_s= s.size(),n_t = t.size();
// 	fr(i,n-1)
// 	s[i]=s[i+1];
// 	s[n-1]=c;
// 	fr(i,n)
// 	{
// 		if(t[i]!=s[i])
// 		{
// 			s1.pb(s[i]);
// 			t1.pb(t[i]);
// 		}
// 	}
// // 	s.clear();
// // 	t.clear();
// 	s=s1;
// 	t=t1;
// 	if(s1.size()==0)return 0;
// 	else
// 	{
// 		return ans()+1;
// 	}
// }

void solve()
{
	int n;
	cin>>n;
	vector<string> v;
	vi count1(4,0);
	string s;
	// cin>>s;
	// v.pb(s);
	// count1[0]=1;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		// auto it = find(all(v),s);
		// if(it==v.end()){v.pb(s);count1[v.size()-1]++;}
		// else
		// {
		// 	count1[it-v.begin()]++;
		// }
		if(s=="AC")count1[0]++;
		if(s=="WA")count1[1]++;
		if(s=="TLE")count1[2]++;
		if(s=="RE")count1[3]++;


	}
	// for(int i=0;i<v.size();i++)
	// {
	// 	cout<<v[i]<<" x "<<count1[i]<<endl;
	// }
	cout<<"AC x "<<count1[0]<<endl;
	cout<<"WA x "<<count1[1]<<endl;
	cout<<"TLE x "<<count1[2]<<endl;
	cout<<"RE x "<<count1[3]<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
	// {
	// 	solve();
	// 	cout<<endl;
	// }
	solve();
	return 0;
	
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, a;
	cin >> n;
	int mp[n+1];
	memset(mp, 0, sizeof(mp));
	for (int i = 2; i <= n; ++i) {
		cin >> a;
		mp[a]++;
	}
	for (int i = 1; i <= n; ++i) {
		cout << mp[i] << '\n';
	}

	return 0;
}

Measured memory_bytes: 4452
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	public static void main(String[] args) {
	String S =sc.next();
	if(S.charAt(2)==S.charAt(3)&&S.charAt(4)==S.charAt(5)) {
		p("Yes");
	}else {
		p("No");
	}
	
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

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)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

using Data = pair<pii, int>;

int N, C;

vector<pii> a[30];
int used[30][100010];
int imos[30][100010];

signed main()
{
	cin >> N >> C;


	rep(i, N) {
		int s, t, c; cin >> s >> t >> c;
		--c;
		a[c].PB(pii(s, t));
	}

	rep(i, C) sort(all(a[i]));

	rep(c, C) {
		for (pii &p : a[c]) {
			int s = p.fst, t = p.scd;
			if (imos[c][s + 1] < 0) {
				imos[c][s + 1]++;
			} else {
				imos[c][s]++;
			}
			imos[c][t + 1]--;
		}
	}

	rep(c, C) {
		for (int i = 1; i <= 100000; ++i) {
			imos[c][i] += imos[c][i - 1];
		}
	}

	int mx = 1;

	for (int i = 1; i <= 100000; ++i) {
		int sum = 0;
		rep(j, C) {
			sum += imos[j][i];
		}
		chmax(mx, sum);
	}


	cout << mx << endl;
}


Measured memory_bytes: 27264
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int t = 0;
  while (A > K * t) {
    t++;
  }
  if (K*t <= B) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> p(n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &p[i].first);
    p[i].second = i;
  }
  sort(p.begin(), p.end());
  int t = 1, m = 0;
  for(int i = 1; i < n; i++) {
    if(p[i].second > p[i - 1].second)
      t++;
    else
      m = max(m, t), t = 1;
  }
  m = max(m, t);
  printf("%d\n", n - m);
}

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n;
	cin >> n;
	vector <ll> inp (n);
	trav (a, inp) cin >> a;
	ll mx = inp[0], ans = 0;
	for (i = 1; i < n; ++i)
		mx = max (mx, inp[i]), ans += mx - inp[i];
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 4776
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] a = new int[N];
    int s = 0;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      s += a[i];
    }
    int max = 0;
    for (int k = 1; k * k <= s; k++) {
      if (s % k == 0) {
        if (possible(a, K, k)) max = Math.max(max, k);
        if (possible(a, K, s / k)) max = Math.max(max, s / k);
      }
    }
    System.out.println(max);
  }

  private static boolean possible(int[] a, int K, int k) {
    int N = a.length;
    int[] b = new int[N];
    for (int i = 0; i < N; i++) b[i] = a[i] % k;
    Arrays.sort(b);
    for (int i = 1; i < N; i++) b[i] += b[i - 1];
    int i = b[N - 1] / k;
    return b[N - i - 1] <= K;
  }
}


Measured memory_bytes: 25672
N = int(input())
RC = []
for _ in range(N):
    RC.append(list(map(int, input().split())))

dp = {}

for i in range(N):
    dp[(i, i)] = 0

for w in range(2, N+1):
    for l in range(N-w+1):
        cost = float('inf')
        r = l+w-1
        for m in range(l, r):
            mul = RC[l][0] * RC[m][1] * RC[r][1]
            cost = min(cost, dp[(l, m)]+dp[(m+1,r)] + mul)
        dp[(l, r)] = cost
print(dp[(0, N-1)])


Measured memory_bytes: 6176
H, W = (int(i) for i in input().split())
#m = [[int(i) for i in input().split] for i in range(1)]
m = []
for i in range(10):
    m.append(list(map(int, input().split())))
wall = []
for i in range(H):
	wall.append(list(map(int, input().split())))
# wall = [[int(i) for i in input().split] for i in range(H)]
cost = 0

for k in range(10):
    for i in range(10):
        for j in range(10):
            if m[i][j] > m[i][k] + m[k][j]:
                m[i][j] = m[i][k] + m[k][j]

for i in range(H):
	for j in range(W):
		if wall[i][j] != 1 and wall[i][j] != -1:
			cost += m[wall[i][j]][1]

print(cost)

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll dp[100010][2]; int x[509][509]; int c[509][509];
int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	string s;
	cin >> s;
	bool ok = true, tmp = false;
	for (int i = 1; i < s.size(); i++) {
		if (!tmp && s[i] == 'C')
			tmp = true;
		else
			ok &= bool(islower(s[i]));
	}
	ok &= s[0] == 'A' && s[1] != 'C' && s[s.size() - 1] != 'C' && tmp;
	cout << (ok ? "AC" : "WA") << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

map<int, int> mp;

void prime_factors(int n) {
	if(n == 1) { // n=1 の素因数分解は n^1
		mp[n] = 1;
		return;
	}
	for(int i = 2, _n = n; i*i <= _n; ++i) {
		while(n % i == 0) {
			++mp[i]; // 素因数i^{res[i]}
			n /= i;
        }
    }
	if(n != 1) mp[n]++; // nが素数のとき
	return;
}

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

    int n; cin >> n;
    FOR(i, 2, n+1) prime_factors(i);
    ll ans = 1;
    for(const auto& p: mp) {
        ans *= (p.se+1)%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

void solve(int idx, int & cnt, vector< vector< int > > & path, vector< int > & c, vector< int > & ans) {
  if (ans[idx] > 0) return;
  ans[idx] = c[cnt];
  cnt++;
  for (auto cld : path[idx]) {
    solve(cld, cnt, path, c, ans);
  }
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< vector< int > > path(n);
  for (int i=1; i<n; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    path[a].push_back(b);
    path[b].push_back(a);
  }
  vector< int > c(n);
  for (int i=0; i<n; ++i) cin >> c[i];
  sort(c.begin(), c.end(), greater<int>());
  int root = 0;
  for (int i=0; i<n; ++i) {
    if (path[i].size() > path[root].size()) root = i;
  }
  vector< int > ans(n, 0);
  int cnt = 0;
  solve(root, cnt, path, c, ans);
  int sum = 0;
  for (int i=1; i<n; ++i) sum+=c[i];
  cout << sum << endl;
  for (int i=0; i<n; ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 1280
# encoding:utf-8
import copy
import numpy as np
import random



def to_4digit(i,n):
    digits = [0 for i in range(n)]
    digit = 0
    while(i>=1):
        digits[digit] = i%4
        digit += 1
        i//=4
    return digits

def main():
    n,a,b,c = map(int,input().split())
    l = []
    for i in range(n):
        l.append(int(input()))
    print(solve(n,a,b,c,l))

def solve(n,a,b,c,l):
    ans = 10**20
    for i in range(4**n-1):
        choice = to_4digit(i,n)
        abc = [0 for i in range(3)]
        mp = 0
        # print(choice)
        for j in range(len(choice)):
            if choice[j]==3:#trash
                pass
            else:
                if abc[choice[j]]!=0:
                    mp += 10
                abc[choice[j]] += l[j]
        if 0 in abc:
            pass
        else:
            mp += abs(abc[0]-a)+abs(abc[1]-b)+abs(abc[2]-c)
            if ans>mp:
                ans = mp


        # print(ans)
    return ans


if __name__ == "__main__":
    main()


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

using ll = long long;

const ll MOD = 1e15 + 9;

int main() {
    int N;
    string S;
    cin >> N >> S;
    map<string, ll> m1, m2;
    rep(i, 1 << N) {
        string a = "", b = "", c = "", d = "";
        rep(j, N) {
            if ((i >> j) % 2) {
                a += S[j];
                b += S[2 * N - 1 - j];
            } else  {
                c += S[j];
                d += S[2 * N - 1 - j];
            }
        }
        //cout << i << endl;
        //cout << a << endl;
        //cout << b << endl;
        m1[a + " " + c]++;
        m2[b + " " + d]++;
        //cout << m1[a] << endl;
        //cout << m2[b] << endl;
    }
    ll ans = 0;
    for (auto i = m1.begin(); i != m1.end(); i++) {
        ans += i->second * m2[i->first];
        //cout << i->first << i->second << m2[i->first] << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 83584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;
ll mod=1e6+3;

ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*a %mod;
        a=a*a %mod;
        b/=2;
    }
    return res;
}

int main(){
    vector<ll> fact(mod);
    fact[0]=1;
    for(ll i=1;i<=mod;i++)fact[i]=fact[i-1]*i %mod;
    int q;cin>>q;
    while(q--){
        ll x,d,n;cin>>x>>d>>n;
        if(d==0){cout<<power(x,n) %mod<<endl;continue;}
        x=x*power(d,mod-2) %mod;
        if(x+n-1>=mod){cout<<0<<endl;continue;}
        cout<<fact[x+n-1]*power(fact[x-1],mod-2) %mod *power(d,n) %mod;
        cout<<endl;
        
    }
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

int N;
vector<vector<int>> adj;
vector<int> child;
vector<int> par;

void input() {
    cin >> N;
    adj.resize(N, vector<int>());
    child.resize(N, 0);
    par.resize(N, -1);
    rep(i, N-1) {
        int a, b; cin >> a >> b;
        --a; --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
}

int dfs(int from, int now) {
    int res = 1;
    for(auto to: adj[now]) if (to!=from) { par[to] = now; res += dfs(now, to); }
    return child[now] = res;
}

void solve() {
    dfs(-1, 0);
    ll ans = 0;
    rep(now, N) {
        ll num = modpow(2, N-1) + 1;
        ll ue = N-1;
        for(auto to: adj[now]) if (par[to] == now) ue -= child[to];
        //cout << ue << endl;
        for(auto to: adj[now]) {
            if (par[to] == now) num += modpow(2, child[to]) + mod - 1;
            else num += modpow(2, ue) + mod - 1;
            chmod(num);
            //cout << ans << endl;
        }
        num = modpow(2, N) - num;
        chmod(num);
        ans += num;
        chmod(ans);
    }

    ans *= modpow(modpow(2, N), mod-2);
    chmod(ans);

    cout << ans << endl;
}


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

    input();
    solve();

    return 0;
}


Measured memory_bytes: 21632
#include <cstdio>
#include <algorithm>
#include <cstring>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 200010;

struct Edge{ int to, next;} edge[N * 2];
int head[N], num;
void add_edge(int a, int b)
{
	edge[++ num] = (Edge){b, head[a]}, head[a] = num;
}

int d[N], c[N];
LL g[N];

bool flag = false;

void dfs(int x, int fa)
{
	int cnt = 0;
	LL mx = 0, sum = 0;
	RepG(i, x) if (v != fa) {
		dfs(v, x);
		sum += g[v], mx = max(mx, g[v]), cnt ++;
	}
	if (cnt >= 2){
		g[x] = 1ll * c[x] * 2 - sum;
		if (g[x] < 0 || (sum - g[x]) / 2 > (sum - mx) || g[x] > c[x]) flag = true;
	}
	else if (cnt) {
		if(c[x] < g[x]) flag = true;
		g[x] = c[x];
	}
	else g[x] = c[x];
}

int main()
{
	int n;
	scanf("%d", &n);
	Rep(i, n) scanf("%d", &c[i]);
	Rep(i, n - 1) {
		int a, b;
		scanf("%d%d", &a, &b);
		add_edge(a, b); add_edge(b, a);
		d[a] ++, d[b] ++;
	}
	if (n == 2) {
		if (c[1] == c[2]) printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	int rt;
	Rep(i, n) if (d[i] >= 2) rt = i;
	dfs(rt, 0);
	if (g[rt]) flag = true;
	if (!flag) printf("YES\n");
	else printf("NO\n");
	
	return 0;
}


Measured memory_bytes: 12544
const
	inf=1000000000;
var
	a:array[0..100010] of longint;
	n,min,sum,i,t:longint;
begin
	readln(n);
	min:=inf;
	for i:=1 to n do read(a[i]);
	sum:=0;
	while sum<n-1 do
	begin
		for i:=1 to n do
			if (a[i]<min) and (a[i]>0) then
			begin 
				min:=a[i];
				t:=i;
			end;
		for i:=1 to n do
			if i<>t then 
				if a[i]>0 then 
				begin
					a[i]:=a[i] mod min;
					if a[i]=0 then inc(sum);
				end;
	end;
	writeln(min)
end.

Measured memory_bytes: 512
import sys
input = sys.stdin.buffer.readline

N = int(input())
Edges = [list(map(int, input().split())) for _ in range(N-1)]

ans = 0
for l in range(1, N+1):
    ans += (N-l+2)*(N-l+1)//2


for a, b in Edges:
    if a > b:
        b, a = a, b
    ans -= a * (N-b+1)

print(ans)

Measured memory_bytes: 98088
#include <bits/stdc++.h>
using namespace std;
const int N=300010;
const int INF=1e9;
typedef pair<int,int> pp;
int a[N],n,p[N],l,r;
int solve(int l,int r){
//	cout<<l<<" "<<r<<endl;
	for (int i=l; i<=r; ++i) if (a[i]<l||a[i]>r) return puts("No"),0;
	int prev=-INF;
	for (int i=l; i<=r; ++i)
	if (a[i]>i){
		if (a[i]>prev) prev=a[i];
		else return puts("No"),0;
	}
	prev=-INF;
	for (int i=l; i<=r; ++i)
	if (a[i]<i){
		if (a[i]>prev) prev=a[i];
		else return puts("No"),0;
	}
	return 1;
}
int main(){
	cin>>n;
	for (int i=1; i<=n; ++i){
		cin>>a[i];
		p[i]=(a[i]==i);
	}
	for (int i=2; i<n; ++i) if (!p[i]&&!p[i-1]&&!p[i+1]) return puts("No"),0;
	for (int i=1; i<=n; ++i)
	if (p[i]==0){
		if (i==1||p[i-1]==1){
			if (l) r=i;
			else l=r=i;
		}
		else{
			if (l&&!solve(l,r)) return 0;
			l=r=i;
		}
	}
	else if (p[i]==1){
		if (l){
			if (p[i-1]!=0){
				if (!solve(l,r)) return 0;
				l=0;
			}
		}
	}
	if (l) if (!solve(l,r)) return 0;
	puts("Yes");
}

Measured memory_bytes: 2560
fun main(args: Array<String>){
    val input = readLine()!!.map { it.toString().toInt() }.toTypedArray()
    val result = D0929A(input).judge()
    println(result)
}

class D0929A(
    val ints: Array<Int>
){
    fun judge(): String{
        return ints.map { 10 - it }
                   .joinToString("")
    }
}

Measured memory_bytes: 33820
import math
k=int(input())
res=0
#すべてが同じ値の場合:1-kの合計
res += k*(k+1)//2
#2値が同じ場合:*3
for i in range(1,k+1):
  for j in range(1,k+1):
    if i==j:
      continue
    res += math.gcd(i,j)*3
#全部違う場合:*6
for i in range(1,k+1):
  for j in range(i+1,k+1):
    for m in range(j+1,k+1):
      if len(list(set([i,j,k]))) == 3:
        res += math.gcd(math.gcd(i,j),m)*6
print(res)

Measured memory_bytes: 68412
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>

const int INF = 0x3f3f3f3f;

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

	int n, w;
	cin >> n >> w;
	int value_max = n*1000+1;
	int n_max = n + 1;
	int dd[n_max][value_max];

	// initialize
	memset(dd, INF, sizeof dd);
	/*
	for (int nn = 0; nn < n_max; nn++) {
	  for (int v = 0; v < value_max; v++) {
	    dd[nn][v] = INF;
	  }
	}
	*/

	for (int nn = 0; nn <= n; nn++) {
	  dd[nn][0] = 0;
	}
	for (int nn = 1; nn < n_max; nn++) {
	  int www, nu;
	  cin >> www >> nu;
	  for (int v = 1; v < value_max; v++) {
	    // don't use item nn-1
	    int cur = dd[nn-1][v];

	    // use item nn-1
	    if (nu <= v) {
	      int rem_v = v - nu;
	      int cand = dd[nn-1][rem_v] + www;
	      if (cand <= w && cand < cur) {
		cur = cand;
	      }
	    }

	    dd[nn][v] = cur;
	  }
	}
	bool done = false;
	for (int v = value_max-1; v >= 0; v--) {
	  if (done) {
	    break;
	  }
	  for (int nn = 0; nn < n_max; nn++) {
	    if (dd[nn][v] != INF) {
	      cout << v << '\n';
	      done = true;
	      break;
	    }
	  }
	}

	if (!done) {
	  cout << 0 << '\n';
	}
	return 0;
}


Measured memory_bytes: 39680
#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

int n, k;
vector<ll> a;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    a.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = k; i < n; ++i){
        cout << (a[i - k] < a[i] ? "Yes" : "No") << "\n";
    }
    return 0;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi(x) vector<x>
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define mii map<int,int>
#define MOD 1000000007
#define int long long
using namespace std;
//typedef long long ll;
void solve()
{
	int l,r, d;
	cin>>l>>r>>d;
	if(l%d==0)
	cout<<(r/d)-(l/d)+1<<endl;
	else 
	cout<<(r/d)-(l/d)<<endl;
	
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
solve();
}

return 0;
}
// Problem : A - Number of Multiples
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)



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

signed main(){
  int n;
  cin>>n;
  int s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int q;
  cin>>q;
  int t[q];
  for(int i=0;i<q;i++) cin>>t[i];
  int ans=0;
  for(int i=0;i<q;i++){
    int l=0,r=n;
    while(l+1<r){
      int m=(l+r)/2;
      if(s[m]<=t[i]) l=m;
      else r=m;
    }
    if(s[l]!=t[i]) continue;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}



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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    void solve(){
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a.begin(),a.end(),greater<>());
        ll total=0;
        int id=0;
        for(int i=0;i<n-1;i++){
            total+=(ll)a[id];
            if(i%2==0)
                id++;
        }
        cout<<total;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 4000
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, k; cin >> n >> k;
    vector<ll> a(n, 0);
    REP(i, n) cin >> a[i];

    // 候補は総和の約数
    ll asum = accumulate(ALL_OF(a), 0LL);
    vector<ll> cand; cand.reserve(10000);
    for (ll f = 1; f * f <= asum; f++) {
        if (asum % f == 0) {
            cand.push_back(f);
            if (f * f != asum) {
                cand.push_back(asum / f);
            }
        }
    }

    // 試す
    ll ans = 1;
    vector<ll> b(n, 0);
    vector<ll> bposimos(n+1, 0), bnegimos(n+1, 0);
    for (ll p : cand) {

        REP(i, n) b[i] = a[i] % p;
        sort(ALL_OF(b));
        REP(i, n) {
            bnegimos[i+1] = bnegimos[i] + b[i];
            bposimos[i+1] = bposimos[i] + p - b[i];
        }
        ll neededop = LINF;
        RANGE(i, 1, n-1) {
            ll opneg = bnegimos[i] - bnegimos[0];
            ll oppos = bposimos[n] - bposimos[i];
            if (opneg == oppos)
                chmin(neededop, opneg);
        }
        DUMP(p);
        DUMP(neededop);
        if (neededop <= k) {
            chmax(ans, p);
        }

    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        char[] n = sc.nextLine().toCharArray();
        int count = 0;
        int seven = 0;
        for(char c: n){
            if(c == '5'){
                count++;
            }
            if(c == '7'){
                seven++;
            }
        }
        if(count == 2 && seven == 1){
            System.out.println("YES");
        } else {
            System.out.println("NO");

        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int a, b;
  cin >> a >> b;
  cout << (n * m) - (m * a) - (n * b) + (a * b) << endl;
}





Measured memory_bytes: 256
n = int(input())
s = input()
 
r = s.count('R')
g = s.count('G')
b = s.count('B')
 
ans = r*g*b
 
for i in range(n):
  for j in range(i+2, n, 2):
    if s[i] != s[j] and s[i] != s[int((i+j)/2)] and s[int((i+j)/2)] != s[j]:
      ans -= 1
print(ans)

Measured memory_bytes: 68216
#include<stdio.h>

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

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

int main() {
  int x,a,b,c;
  cin>>x>>a>>b;
  c=b-a;
  if(c>x) cout<<"dangerous"<<endl;
  else if(c>0) cout<<"safe"<<endl;
  else cout<<"delicious"<<endl;
}
  

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

int main() {
  int n;
  cin >> n;
  map<int, bool> in;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if (in[tmp]) {
      in.erase(tmp);
    }
    else {
      in[tmp] = true;
    }
  }
  cout << in.size() << endl;
}


Measured memory_bytes: 8212
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            char op = in.nextChar();
            int b = in.nextInt();
            out.println(op == '-' ? a - b : a + b);
        }

    }

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

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

    }
}



Measured memory_bytes: 20820
#include<iostream>

int main(){
    int n,isi[1001],hito[1001];
    std::cin>>n;
    for(int i=0;i<n;i++){
        std::cin>>isi[i]>>hito[i];
    }
    for(int i=0;i<n;i++){
        if(isi[i]%hito[i]==0){
            std::cout<<hito[i]<<std::endl;
        }else{
            std::cout<<isi[i]%hito[i]<<std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstring>
using namespace std;
int N;
char S[100005];
void Read()
{
    cin.getline(S + 1, 100005);
    N = strlen(S + 1);
}

void Solve()
{
    int left = 1, right = N, ans = 0;
    while(left <= right)
    {
        if(S[left] == S[right])
        {
            ++left;
            --right;
            continue;
        }
        if(S[left] != S[right] && S[left] != 'x' && S[right] != 'x')
        {
            cout << "-1\n";
            return;
        }
        if(S[left] == 'x')
        {
            ++left;
            ans++;
        }
        else
        {
            --right;
            ans++;
        }
    }
    cout << ans << "\n";
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
long long n,m,vis[maxn],head[maxn],sum[2],e=0;
int pp=0;
struct edge{
	int next,to;
}edge[maxn*2];
void add(int from,int to){
	edge[++e].next=head[from];
	edge[e].to=to;
	head[from]=e;
}
void dfs(int x,int pos){
	vis[x]=pos;
	sum[pos]++;
	pos=(pos==0)?1:0;
	for(int i=head[x];i;i=edge[i].next){
		int to=edge[i].to;
		if(vis[to]!=-1) {
			if(vis[to]!=pos){
				printf("%lld\n",n*(n-1)/2-m);
				pp=1;
				return;
			}
		}
		else dfs(to,pos);
		if(pp) break;
	}
	if(pp) return;
}
int main(){
	int x,y;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	memset(vis,-1,sizeof(vis));
	dfs(1,0);
	if(pp) {
		return 0;
	}
	printf("%lld",sum[0]*sum[1]-m);
}

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

using namespace std;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
//s = char []
#define ss(s) scanf("%s",&s)
//s = string to read with spaces
#define read(s) getline(cin,s)


int main()
{
    int n,x;
    si(n);
    int arr[100002] = {0};
    for(int i=0;i<n;i++){
        si(x);
        arr[x]++;
        if(x!=0)
            arr[x-1]++;
        arr[x+1]++;
    }
    int maxx = 0;
    for(int i=1;i<=100001;i++){
        maxx = max(maxx,arr[i]);
    }
    cout << maxx;
    return 0;
}


Measured memory_bytes: 640
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> P;
int read()
{
    int x=0,flag=1;
    char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

int main()
{
    int L=read(),R=read(),d=read();
    int ans=0;
    REP(i,L,R) if(i%d==0) ans++;
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3592
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=5005;
int p[N],n,A,B;ll dp[N],tmp;
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),A=read(),B=read();
	fp(i,1,n)p[i]=read();
	++n,p[n]=n;
	fp(i,1,n){
		dp[i]=1e18,tmp=0;
		fd(j,i-1,0)p[j]<p[i]?(cmin(dp[i],dp[j]+tmp),tmp+=B):tmp+=A; 
	}
	printf("%lld\n",dp[n]);
	return 0;
}


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

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            int a = Integer.parseInt(bf.readLine());
            int x;
            for (int i = 1; i <= a; i++) {
                if (i % 3 == 0)
                    System.out.printf(" %d", i);
                else {
                    x = i;
                    do {
                        if (x % 10 == 3) {
                            System.out.printf(" %d", i);
                            break;
                        }
                        x /= 10;
                    } while (x != 0);
                }
            }
            System.out.print("\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    cout << (n % 500 <= a ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
<?php

$input = fgets(STDIN);
$array = explode(' ', $input);

$n = (int)$array[0];
$m = (int)$array[1];

if ($n === 1 && $m ===1) {
    echo 0;
} elseif ($n <= 1 && $m >1) {
    echo $m * ($m - 1) / 2;
} elseif ($n > 1 && $m <=1) {
    echo $n * ($n - 1) / 2;
} else {
    $nAll = $n * ($n - 1) / 2;
    $mAll = $m * ($m - 1) / 2;
    echo $nAll + $mAll;
}

Measured memory_bytes: 15972
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
int main(void){
    std::vector<int> a;
    for(int i=0;i<10;i++){
      int b;
      std::cin>>b;
      a.push_back(b);
    }
    sort(a.begin(),a.end(),std::greater<int>());
    for(int j=0;j<3;j++){
       std::cout<<a[j]<<"\n";
    }
}

Measured memory_bytes: 3064
/*input
40
*/
/*
if n == 0:
        return (0, 1)
    else:
        a, b = _fib(n // 2)
        c = a * (b * 2 - a)
        d = a * a + b * b
        if n % 2 == 0:
            return (c, d)
        else:
            return (d, c + d)
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_.pop();
    return_
}

fn fibonacci(n: u64) -> (u64, u64) {
    if n == 0 {
        (0, 1)
    } else {
        let (a, b): (u64, u64) = fibonacci(n / 2);
        let c: u64 = a * (b * 2 - a);
        let d: u64 = a * a + b * b;
        if n % 2 == 0 {
            (c, d)
        } else {
            (d, c + d)
        }
    }
}

fn main() {
    let n: u64 = read_line().parse().unwrap();
    println!("{}", fibonacci(n + 1).0);
}



Measured memory_bytes: 5036
# 2019/12/01
# 三井住友信託銀行プログラミングコンテスト2019 - B

# Input
n = int(input())

# Calc
val_d = n / 1.08
val_i = int(n / 1.08)

if val_d == val_i:
    ans = val_i
else:
    if int((val_i + 1) * 1.08) == n:
        ans = val_i + 1
    else:
        ans = ":("

# Output
print(ans)

Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	long long a,b,c,d,x[4],y,i;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	x[0]=a*d;
	x[1]=a*c;
	x[2]=b*c;
	x[3]=b*d;
	y=x[0];
	for(i=0;i<4;i++){
		if(y<x[i]) y=x[i];
	}
	printf("%lld\n",y);
	return 0;
}


Measured memory_bytes: 1712
def is_can?(a, b, remains)
  next_ball = remains.first
  return false if next_ball <= a && next_ball <= b
  return true if remains.length == 1
  if next_ball > a
    return true if is_can?(next_ball, b, remains.slice(1..(remains.length - 1)))
  else
    return is_can?(a, next_ball, remains.slice(1..(remains.length - 1)))
  end
end

count = gets.chomp.to_i
count.times do |n|
  remains = gets.chomp.split(" ").map(&:to_i)
  puts is_can?(0, 0, remains) ? "YES" : "NO"
end

Measured memory_bytes: 8744
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>

using namespace std;

int main()
{
	struct Sushi {
		uint32_t neta;
		uint32_t val;
		bool     eat;
	};
	struct ValuableSushi {
		uint32_t val;
		uint32_t idx;
	};

	uint32_t n, k;
	cin >> n >> k;

	vector<Sushi> ss(n);
	for (uint32_t i = 0; i < n; i++) {
		auto & s = ss[i];
		cin >> s.neta >> s.val;
	}

	std::sort(ss.begin(), ss.end(), [](const Sushi& lhs, const Sushi&rhs) {
		return lhs.val > rhs.val;
	});

	vector<ValuableSushi> h_n; // 1 origin
	for (uint32_t i = 0; i < n; i++) {
		const auto & s = ss[i];

		if (h_n.size() < s.neta + 1) {
			h_n.resize(s.neta + 1);
		}
		if (h_n[s.neta].val < s.val) {
			h_n[s.neta].val = s.val;
			h_n[s.neta].idx = i;
		}
	}

	std::sort(h_n.begin(), h_n.end(), [](const ValuableSushi& lhs, const ValuableSushi& rhs) {
		return lhs.val > rhs.val;
	});

	vector<uint32_t> n_u(h_n.size());
	uint64_t result = 0;
	uint32_t n_num = 0;
	for (int i = 0; i < k; i++) {
		const auto& s = ss[i];
		result += s.val;
		if (n_u[s.neta] == 0) n_num++;
		n_u[ss[i].neta]++;
	}

	uint64_t max_val = result + ((uint64_t) n_num) * n_num;

	int rem = k - 1;
	int add = k;
	while (true) {
		while (add < n && n_u[ss[add].neta] != 0) {
			add++;
		}
		while (0 <= rem && n_u[ss[rem].neta] == 1) {
			rem--;
		}
		if (n <= add || rem < 0) break;

		uint32_t add_n_val = 2 * n_num + 1;
		
		n_num++;
		n_u[ss[rem].neta]--;
		n_u[ss[add].neta]++;

		result -= ss[rem].val - ss[add].val;
		max_val = max(max_val, result + ((uint64_t)n_num * n_num));

		rem--;
		add++;
	}
	
	cout << max_val << endl;

	return 0;
}

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

int main(void){

  int num[3];

  cin >> num[0] >> num[1] >> num[2];

  sort(num,num+3);

  cout << num[0] << " " << num[1] << " " << num[2] << endl;

  return 0;
}

Measured memory_bytes: 1180
let str1 = readLine()!
    let str2 = readLine()!
    
    let charArr = str2.map{($0)}
    var str: String = ""
    
    var s: Int = 0
    
    for i in 0 ..< charArr.count {
      
      str += String(charArr[i])
      
      if str == str1 {
        
        s += 1
        break
      }
      
    }
    
    if s == 1 {
      print("Yes")
    } else {
      print("No")
    }

Measured memory_bytes: 7708
#include<stdio.h>
int main()
{
    int a, b, i;
    int cnt=0;
    char s[11];

    scanf("%d%d", &a, &b);
    scanf("%s", s);

    for(i=0;i<a+b+1;i++){
       if(s[i]=='-'){
           cnt++;
       }
    }

    if(s[a]=='-'&&cnt==1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int d;
    cin >> d;
    if(d==25)cout << "Christmas"<<endl;
    else if(d==24)cout << "Christmas Eve"<<endl;
    else if(d==23)cout << "Christmas Eve Eve"<< endl;
    else if(d==22)cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int a[10000];
int s[100][100];

int main()
{
	int h,w;
	int n;
	int ans=0;
	int index=0;
	
	cin>>h>>w;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			while(a[index]==0)
			{
				index++;
				if(index>=n)
					break;
			}
			int c = index+1;
			s[i][j]=c;
			a[index]--;
			while(a[index]==0)
			{
				index++;
				if(index>=n)
					break;
			}
		}
		i++;
		if(i==h)
			break;
		for(int j=0;j<w;j++)
		{
			while(a[index]==0)
			{
				index++;
				if(index>=n)
					break;
			}
			int c=index+1;
			s[i][j]=c;
			a[index]--;
			while(a[index]==0)
			{
				index++;
				if(index>=n)
					break;
			}
		}
		reverse(s[i],s[i]+w);
	}
	
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout<<s[i][j];
			if(j<w-1)
				cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit =
    println((List.fill[Int](sc.nextInt)(sc.nextInt * 60 + sc.nextInt) ::: List.fill[Int](sc.nextInt)(sc.nextInt * 60 + sc.nextInt))
          .toSet.toList
      .sorted
      .map(A => ((A / 60): Int) + ":%02d".format(A % 60))
      .mkString(" "))


  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }
}

Measured memory_bytes: 46088
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int main(void){
	int a,b,k;
	scanf("%d %d %d", &a, &b, &k );
	for(int i=0;i<k;i++){
		if(i%2==0){
			if(a%2==1)	a--;
			a /=2;
			b += a;
		}else{
			if(b%2==1)	b--;
			b /= 2;
			a += b;
		}
	}
	printf("%d %d", a,b);
	return 0;
}

int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}

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

int main(){
  unsigned long int N, A, B, sumFatigue=0;
  unsigned int dist1, dist2;

  cin >> N >> A >> B;
  cin >> dist1;
  
  for(int i=1; i<N; i++){
    cin >> dist2;
    sumFatigue += min((dist2 - dist1) * A, B);
    dist1=dist2;    
  }

  cout << sumFatigue << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
    int n,m,p,x[101],i,money,q;
    while(1) {
        q=0;
        scanf("%d %d %d",&n,&m,&p);
        if (n==0&&m==0&&p==0) break;
        for (i=1;i<=n;i++) {
            scanf("%d",&x[i]);
            q+=x[i];
        }
        if (x[m]!=0) {
            money=q*(100-p)/x[m];
            printf("%d\n",money);
        }
        else printf("%d\n",0);
    }
    return 0;
}

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

int main(){
    unsigned long N;
    cin >> N;
    unsigned long a{0}, s{0};
    for(unsigned long i = 0, d; i < N; ++i){
        cin >> d;
        a += d * s;
        s += d;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

ans = 0
total = 0
right = 1
for left in range(N):
    while right < N+1:
        cur = A[right-1]
        if total & cur == 0:
            right += 1
            total += cur
        else:
            total -= A[left]
            break
        
        ans += right-left-1

        
print(ans)

Measured memory_bytes: 25916
ans=0
a=[0]*5
for i in range(5):
    t=int(input())
    t2=t%10

    if t2==0:
        a[i]=t2+10
        ans=ans+t
    else:
        a[i]=t2
        ans=ans+((t//10)*10)+10
if min(a) !=10 :
    print(ans-10+min(a))
else:
    print(ans)

Measured memory_bytes: 3060