akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int solve(int x,vector<vector<int>> &k,vector<int> &z,vector<int> &parent){
  if(k[x].size()==1){
    z[x]=1;
    return 1;
  }
  if(z[x]>0) return z[x];
  int ans=0;
  for(int j:k[x]){
    if(j>100000)continue;
    if(x!=0){
      if(parent[x]==j){
        continue;
      }
    }
    ans+=solve(j,k,z,parent);
  }
  z[x]=ans+1;
  return ans+1;
}
int main(){
  int n;
  cin >> n;
  vector<vector<int>> k(n,vector<int>(1,10000000));
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    k[a-1].push_back(b-1);
    k[b-1].push_back(a-1);
  }
  int dis[n];
  rep(i,n){
    dis[i]=1000000;
  }
  vector<int> parent(n,0);
  dis[0]=0;
  queue<int> q;
  q.push(0);
  while(q.size()!=0){
    int u=q.front();
    q.pop();
    for(int w:k[u]){
      if(w>100000)continue;
      if(dis[w]<500000)continue;
      q.push(w);
      parent[w]=u;
      dis[w]=dis[u]+1;
    }
  }
  int p=(dis[n-1]+1)/2-1;
  int o=n-1;
  rep(i,p)o=parent[o];
  vector<int> z(n,0);
  int adiof=solve(0,k,z,parent);
  if(z[o]>(n-1)/2)cout << "Snuke" << endl;
  else cout << "Fennec" << endl;
}


Measured memory_bytes: 14720
x, y = list(map(int, input().split()))
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]

if x in a and y in a:
    print('Yes')

elif x in b and y in b:
    print('Yes')

elif x == 2 and y == 2:
    print('Yes')

else:
    print('No')


Measured memory_bytes: 2940
import sys

inf = float('inf')

n, T, *ct = map(int, sys.stdin.read().split())
ct = zip(*[iter(ct)] * 2)

def main():
    res = inf
    for c, t in ct:
        if t <= T:
            res = min(res, c)
    
    return res if res != inf else 'TLE'

if __name__ == '__main__':
    ans = main()
    print(ans)

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

int main() {
    int N;
    int A[1005];
    long long ans = 1;

    scanf("%d", &N);
    for (int i = 0; i <= N; i++) A[i] = 1;

    for (int i = 2; i <= N; i++) {
        int a = i;
        for (int j = 2; j <= N; j++) {
            while (a % j == 0) {
                A[j-1]++;
                a /= j;
            }
        }
    }

    for (int i = 0; i < N; i++) {
        ans *= A[i] % 1000000007;
        ans = ans % 1000000007;
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
namespace icl = boost::icl;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> D;

  invec<int> c(26);
  vector<vector<int>> s(D, vector<int>(26));
  for (auto&& i : s)
    for (auto&& j : i)
      cin >> j;
  vector<int> t(D);
  ll r = 0, cost = 0;

  constexpr int BEAM_WIDTH = 168;
  using node = tuple<int, deque<int>, array<int, 26>>;
  priority_queue<node> beam;
  beam.emplace(0, deque<int>(), array<int, 26>());
  
  REP(i, 26)
    cost += c[i];
  const int tier = cost;
  REP(i, D) {
    priority_queue<node> bnext;
    
    REP(k, BEAM_WIDTH) {
      if (beam.empty()) break;
      int score;
      deque<int> que;
      array<int, 26> last;
      tie(score, que, last) = move(beam.top()); beam.pop();
      REP(j, 26) {
        auto next = que;
        next.push_back(j);
        auto nlast = last;
    	nlast[j] = i + 1;
        bnext.emplace(score + s[i][j] + c[j] * (i + 1 - last[j]), move(next), move(nlast));
      }
    }
    beam = move(bnext);
    
    
  }
  
  int score;
  deque<int> que;
  array<int, 26> last;
  tie(score, que, last) = move(beam.top());
  
  for (auto i : que)
    cout << i + 1 << endl;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 27696
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a[m],v=0,t;
  for(int i=0;i<m;i++)
  { cin>>a[i];
  v=v+a[i];}
  t=n-v;
  if(t>=0)
    cout<<t<<endl;
  else
    cout<<-1<<endl;
  
  
}


Measured memory_bytes: 3632
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}

			n++;
			int p[] = new int[n];
			int t[] = new int[n];

			for (int i = 1; i < n; i++) {
				p[i] = sc.nextInt();
				t[i] = sc.nextInt();
			}

			int[][] dp = new int[n][4];

			for (int i = 0; i < n; i++) {
				Arrays.fill(dp[i], Integer.MAX_VALUE >> 2);
			}

			dp[0][0] = 0;

			int cand = 0;
			int i = 1;
			for (i = 1; i < n; i++) {
				// dp[i][1]
				cand = Integer.MAX_VALUE>> 2;
				for (int j = 1; j < 4; j++) {

					int b = p[i - 1] * (j + 1);
					b += p[i];

					if (b <= t[i] - t[i - 1]) {
						cand = Math.min(cand, dp[i - 1][j] + p[i - 1] + p[i]);
					}
				}
				dp[i][1] = cand;

				for (int j = 0; j < 3; j++) {

					int b = Math.abs(p[i - 1] - p[i]) * (j + 1);

					if (b <= t[i] - t[i - 1]) {
						dp[i][j + 1] = Math.min(dp[i][j + 1], dp[i - 1][j]
								+ Math.abs(p[i - 1] - p[i]));
						cand = Math.min(dp[i][j + 1], cand);
					}
				}
				if (cand == Integer.MAX_VALUE >> 2) {
					break;
				}

			}
			if (cand != Integer.MAX_VALUE >> 2) {
				System.out.println("OK " + (cand + p[n-1]));
			} else {
				System.out.println("NG " + i);
			}
		}
	}

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

Measured memory_bytes: 12000
#include <stdio.h>

int main() {
  int X, A, B;
  scanf("%d %d %d", &X, &A, &B);
  int distA = (X > A) ? X - A : A - X;
  int distB = (X > B) ? X - B : B - X;
  printf("%c\n", (distA < distB) ? 'A' : 'B');
  return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int count = 0;
        while (n > 1) {
            if (n % 2 == 0) {
                n /= 2;
            } else {
                n = 3 * n + 1;
            }
            count++;
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
bool used[10005][4]={false};
ll dp[10005][16]={0};
void check(bool a){
  cout<<(a?"y ":"n ");
}
int main(){
  for(int i=0;i<10005;i++) for(int j=0;j<4;j++) used[i][j]=false;
  ll h,n;
  cin>>h>>n;
  for(int i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    used[y][x]=true;
  }
  bool f=false;
  for(int i=0;i<=h;i++) for(int j=0;j<16;j++) dp[i][j]=0;
  for(int i=0;i<h-1;i++){
    for(int j=0;j<16;j++){
      bool n12=true,n23=true,n34=true,n112=false,n123=false,n134=false;
      if(j>=8||(j%8)>=4) n34=false;
      if((j%8)>=4||(j%4)>=2) n23=false;
      if((j%4)>=2||(j%2)==1) n12=false;
        if(used[i][0]) n12=false;
        if(used[i][1]){
          n12=false;
          n23=false;
        }
        if(used[i][2]){
          n23=false;
          n34=false;
        }
        if(used[i][3]) n34=false;

      if(!used[i+1][0]&&!used[i+1][1]) n112=true;
      if(!used[i+1][1]&&!used[i+1][2]) n123=true;
      if(!used[i+1][2]&&!used[i+1][3]) n134=true;
      if(n12&n112){
        int nb=3;
        if(used[i+1][2]) nb+=4;
        if(used[i+1][3]) nb+=8;
        dp[i+1][nb]=max(dp[i+1][nb],dp[i][j]+1);
      //  if(nb==14) cout<<"NB 15 p01:"<<i<<" "<<j<<endl;
      }
      if(n23&&n123){
        int nb=6;
        if(used[i+1][0]) nb+=1;
        if(used[i+1][3]) nb+=8;
        dp[i+1][nb]=max(dp[i+1][nb],dp[i][j]+1);
//        if(nb==14) cout<<"NB 15 p02:"<<i<<" "<<j<<endl;

      }
      if(n34&&n134){
        int nb=12;
        if(used[i+1][0]) nb+=1;
        if(used[i+1][1]) nb+=2;
        dp[i+1][nb]=max(dp[i+1][nb],dp[i][j]+1);
  //      if(nb==14) cout<<"NB 15 p03:"<<i<<" "<<j<<endl;
      }
      if(n12&&n112&&n34&&n134){
        dp[i+1][15]=max(dp[i+1][15],dp[i][j]+2);
              //   cout<<"NB 15 p04:"<<i<<" "<<j<<endl;
      }
      int knb=0;
      if(used[i+1][0]) knb+=1;
      if(used[i+1][1]) knb+=2;
      if(used[i+1][2]) knb+=4;
      if(used[i+1][3]) knb+=8;
      dp[i+1][knb]=max(dp[i+1][knb],dp[i][j]);
    }
  }
  /*cout<<"idx:";
  for(int j=0;j<16;j++) printf("%3d",j);
  cout<<endl;
  for(int i=0;i<h;i++){
    cout<<i<<"  :";
    for(int j=0;j<16;j++) printf("%3lld",dp[i][j]);
    cout<<endl;
  }*/

  ll ans=0;
  for(int i=0;i<16;i++) ans=max(ans,dp[h-1][i]);
  cout<<ans<<endl;
}



Measured memory_bytes: 4408
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	vector<int>a(3);

	REP(i, 3) cin >> a[i];

	SORT(a);

	if (a[0] == a[1] && a[2] != a[1]) cout << "Yes" << endl;
	else if (a[1] == a[2] && a[0] != a[1]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;

}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <limits.h>
#include <queue>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using ll = long long;

using namespace std;

ll pow_mod(ll a, ll b, ll p) {
	if (b == 0)return 1;
	else if (b % 2 == 0)return (pow_mod(a*a, b / 2, p) % p);
	else return (pow_mod(a, b - 1, p)*a%p);
}

ll sum_digit(ll N) {
	int ans = 0;
	for (; N != 0;) {
		ans += N % 10;
		N /= 10;
	}
	return ans;
}

ll gcd(ll a,ll b) {
	if (!b)return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int H, W;
int a[505][505];
int x[505 * 505], y[505 * 505], nx[505 * 505], ny[505 * 505];

int main(){
	scanf("%d %d", &H, &W);
	rep(i, H)rep(j, W)scanf("%d", &a[i][j]);
	ll cnt = 0;
	rep(i, H) {
		rep(j, W - 1) {
			if (a[i][j] % 2) {
				y[cnt] = ny[cnt] = i, x[cnt] = j, nx[cnt] = j + 1;
				cnt++;
				a[i][j + 1]++;
			}
		}
	}
	rep(i, H-1) {
		if (a[i][W - 1] % 2) {
			x[cnt] = nx[cnt] = W - 1, y[cnt] = i, ny[cnt] = i + 1;
			cnt++;
			a[i + 1][W - 1]++;
		}
	}
	printf("%d\n", cnt);
	rep(i, cnt)printf("%d %d %d %d\n", y[i]+1, x[i]+1, ny[i]+1, nx[i]+1);
	return 0;
}

Measured memory_bytes: 6016
using System.Linq;
using System.Numerics;
using static System.Console;

class B
{
	static void Main()
	{
		var h = ReadLine().Split().Select(int.Parse).ToArray();
		var a = ReadLine().Split().Select(int.Parse).ToArray();

		BigInteger x1 = Enumerable.Range(0, h[0]).SelectMany(i => Enumerable.Range(0, i).Select(j => new { i, j })).Count(_ => a[_.j] < a[_.i]);
		BigInteger x2 = Enumerable.Range(0, h[0]).SelectMany(i => Enumerable.Range(i + 1, h[0] - i - 1).Select(j => new { i, j })).Count(_ => a[_.j] < a[_.i]);
		WriteLine((x1 * (h[1] - 1) + x2 * (h[1] + 1)) * h[1] / 2 % 1000000007);
	}
}


Measured memory_bytes: 19940
use strict;
use warnings;

main();

sub main{

	(my $N, my $A, my $B) = split" ",<STDIN>;
	my $sum = 0;

	foreach my $in (1..$N){
		my $total = ($in/10000%10) + ($in/1000%10) + ($in/100%10) + ($in/10%10) + ($in%10);
		if($A <= $total && $total <= $B){ $sum += $in } 
	}

	print $sum."\n";
	1;
}

Measured memory_bytes: 640
#include <iostream>
#include<math.h>
using namespace std;
 
int order(int k){
 int z=0;
 while(k%2==0){
  z++;
  k=k/2;
 }
 return z;
}
 
int main() {
 int a,b,c;
cin>>a>>b>>c;
int d=abs(a-b);
int e=abs(b-c);
int f=abs(c-a);
if(a%2==1 or b%2==1 or c%2==1){cout<<0;return 0;}
if(d==0 and e==0){cout<<-1;return 0;}
 
cout<<min(order(e),min(order(d),order(f)));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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; }

int main(){
	ll x;cin>>x;
	ll a = 100;
	ll y = 0;
	while(1){
		if (a >= x){
			cout << y << endl;
			return 0;
		}
		a *= 1.01;
		y++;
	}
	return 0;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#define MOD 998244353
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <functional>
#include <algorithm>
#include <iterator>
#include <cstdio>
#include <utility>
#include <unordered_map>
#include <cmath>
#include <chrono>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> P;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,-1)

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main(void) {
	int n, m, x, y, z, r;
	cin >> n >> m;
	UnionFind uf(n);
	REP(i, m) {
		cin >> x >> y >> z;
		uf.unite(x - 1, y - 1);
	}
	int cnt = 0;
	set<int> s;
	REP(i, n) {
		r = uf.root(i);
		if (r == -1) cnt++;
		else s.insert(r);
	}
	cnt += s.size();
	cout << cnt;
	return 0;
}

Measured memory_bytes: 5376
#include<stdio.h>
#include<string.h>
int main()
{
    char s[101];
    int len,cnt=0;

    scanf("%s",s);
    len=strlen(s);
    for(int i=0;i<len/2;i++){
        if(s[i]!=s[len-i-1]){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int w,h;
  while(cin>>w>>h,w||h){
    int a[22][22],b[10],c[10],x,y,n=0;
    memset(a,-1,sizeof(a));
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	char s;
	cin>>s;
	if(0){
	}else if(s=='x'){
	  a[j][i]=-1;
	}else if(s=='o'){
	  a[j][i]=-2;
	  x=j;
	  y=i;
	}else if(s=='*'){
	  a[j][i]=n;
	  b[n]=j;
	  c[n]=i;
	  n++;
	}else if(s=='.'){
	  a[j][i]=-2;
	}
      }
    }
    int d[22][22][1<<10];
    memset(d,-1,sizeof(d));
    queue<pair<pair<int,int>,pair<int,int> > > e;
    e.push(make_pair(make_pair(x,y),make_pair(0,0)));
    while(e.empty()==0){
      int x,y,v,w;
      x=e.front().first.first;
      y=e.front().first.second;
      v=e.front().second.first;
      w=e.front().second.second;
      if(v==~((~0)<<n))
	break;
      e.pop();
      if(d[x][y][v]==-1||d[x][y][v]>w){
	d[x][y][v]=w;
	if(a[x-1][y]!=-1){
	  if(a[x-1][y]==-2)
	    e.push(make_pair(make_pair(x-1,y),make_pair(v,w+1)));
	  else
	    e.push(make_pair(make_pair(x-1,y),make_pair(v|(1<<a[x-1][y]),w+1)));
	}
	if(a[x+1][y]!=-1){
	  if(a[x+1][y]==-2)
	    e.push(make_pair(make_pair(x+1,y),make_pair(v,w+1)));
	  else
	    e.push(make_pair(make_pair(x+1,y),make_pair(v|(1<<a[x+1][y]),w+1)));
	}
	if(a[x][y-1]!=-1){
	  if(a[x][y-1]==-2)
	    e.push(make_pair(make_pair(x,y-1),make_pair(v,w+1)));
	  else
	    e.push(make_pair(make_pair(x,y-1),make_pair(v|(1<<a[x][y-1]),w+1)));
	}
	if(a[x][y+1]!=-1){
	  if(a[x][y+1]==-2)
	    e.push(make_pair(make_pair(x,y+1),make_pair(v,w+1)));
	  else
	    e.push(make_pair(make_pair(x,y+1),make_pair(v|(1<<a[x][y+1]),w+1)));
	}
      }
    }
    cout<<(e.empty()?-1:e.front().second.second)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string x[300000];
int y[300000];
int main()
{
    map<string,int> mp;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        mp[x[i]]++;
    }
    int k=0;
    map<string,int>::iterator it=mp.begin();
    for(;it!=mp.end();it++)
    {
        y[k++]=it->second;
    }
    sort(y,y+k);
    for(it=mp.begin();it!=mp.end();it++)
    {
        if(it->second==y[k-1])
        {
            cout<<it->first<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 28288
S=input()
p='AC'
o=0
u=0
for i in range(len(S)):
  if i==0 and S[i]!='A':
    p='WA'
    break
  if 2<=i<=len(S)-2:
    if S[i]=='C':
      o+=1
  if len(S)-2<i and o!=1:
    p='WA'
    break
  if ord(S[i])<97:
    if i==0 or 2<=i<=len(S)-2:
      continue
    else:
      p='WA'
      break
print(p)

Measured memory_bytes: 9072
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int k;
  vector<int> data(5);
  for(int i = 0; i < 5; i++) cin >> data[i];
  cin >> k;
  for(int i = 0; i < 5; i++){
    for(int j = 0; j < 5; j++){
      if(i == j) continue;
      if(abs(data[i] - data[j]) > k) {
	cout << ":(" << endl;
	return 0;
      }
    }
  }
  cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pl;
const ll N = 2e3 + 50;
const ll MOD = 1e9+7;
set<string> q;
string t;

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>t;
        q.insert(t);
    }

    cout<<q.size()<<endl;
   return 0;
}


Measured memory_bytes: 19256
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var A = Number(lines[1]);
    var B = Number(lines[2]);
    var C = Number(lines[3]);
    var D = Number(lines[4]);
    var E = Number(lines[5]);

    var min = Math.min(A, B, C, D, E);

    console.log(4 + Math.ceil(N / min));
});

Measured memory_bytes: 11596
#include <iostream>

using namespace std;

int main(){
    int x, y;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0)
            break;
        if(x>y)
            cout << y << ' ' << x << endl;
        if(x<y)
            cout << x << ' ' << y << endl;
        if(x==y)
            cout << x << ' ' << y << endl;
    }
    return 0;
}

Measured memory_bytes: 2976
import collections
 
S = input()
l = [0]
a = 0
b = 1

for i in range(1,len(S)+1):
  a = (a+int(S[-i])*b)%2019
  l.append(a)
  b = (b*10)%2019
  

c = collections.Counter(l)
 
rlt = 0
for k in c:
  rlt += c[k]*(c[k]-1)//2

print(rlt)

Measured memory_bytes: 78004
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 2e3+5;
int n, x, y, d[maxn][maxn], ans[maxn];

void bfs(int src){
	queue<int> q;
	q.push(src);
	d[src][src] = 0;
	while(q.size()){
		int v = q.front(); q.pop();
		if (v == x && d[src][y] == -1) d[src][y] = d[src][v]+1, q.push(y);
		if (v == y && d[src][x] == -1) d[src][x] = d[src][v]+1, q.push(x);
		if (v<n && d[src][v+1] == -1) d[src][v+1] = d[src][v]+1, q.push(v+1);
		if (v>1 && d[src][v-1] == -1) d[src][v-1] = d[src][v]+1, q.push(v-1);
	}
}

int main(){
	memset(d, -1, sizeof(d));
	scanf("%d %d %d", &n, &x, &y);
	for(int i = 1; i<=n; i++) bfs(i);
	for(int i = 1; i<=n; i++)
		for(int j = i+1; j<=n; j++) ans[d[i][j]]++;
	for(int i = 1; i<n; i++){
		printf("%d\n", ans[i]);
	}
	

	return 0;
}


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

typedef pair<int,int>P;
typedef pair<P,int>PP;

int main(){
	int M,T,P,R;
	while(cin>>M>>T>>P>>R,M){
		int d[55][15][2]={0};//チーム///問題///フラグ/時間
		vector<PP>V(T);
		for(int i=0;i<V.size();i++){
			V[i].first.first=0;
			V[i].first.second=0;
			V[i].second=i+1;
		}
		for(;R--;){
			int m,t,p,j;
			cin>>m>>t>>p>>j;
			if(j==0 && d[t][p][0]==0){
				d[t][p][1]+=m;
				d[t][p][0]=1;
				V[t-1].first.first++;//解いた数
				V[t-1].first.second-=d[t][p][1];//合計時間
			}
			if(j!=0 && d[t][p][0]==0){
				d[t][p][1]+=20;
			}
		}
		sort(V.begin(),V.end());
		for(int i=V.size()-1;i>=0;i--){
			cout<<V[i].second;
			if(i==0)cout<<endl;
			else if(V[i].first==V[i-1].first)cout<<"=";
			else cout<<",";
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int c=0;
    if(s.length()==t.length())
    {
        for(int i=0;i<s.length();i++)
        {
            if(s[i]!=t[i])
                c++;
        }

    }
    cout<<c;
}


Measured memory_bytes: 3904
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define int long long
int mod = 1000000007;
using namespace std;
int n;
struct stst{
	long long a[4][4];
	stst() {
		memset (a, 0, sizeof a);
	}
	void build () {
		for (int i = 1; i <= 3; i++) a[i][i] = 1;
	}
}a;
stst operator *(const stst &x, const stst &y){
	stst z;
	for (int k = 1; k <= 3; k++)
		for (int i = 1; i <= 3; i++)
			for (int j = 1; j <= 3; j++)
				z.a[i][j] = (z.a[i][j] + x.a[i][k] * y.a[k][j] % mod) % mod;
	return z;
}
stst quickmod (stst a, long long b) {
	stst ans;
	ans.build ();
	while (b) {
		if (b & 1) ans = ans * a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}
long long k;
long long b[100005];
signed main () {
	scanf ("%lld %lld", &n, &k);
	for (int i = 1; i <= k; i++) scanf ("%lld", &b[i]);
	stst ans;
	ans.build();
	stst x, y;
	x.a[1][1] = 1, x.a[1][2] = 2, x.a[1][3] = 1;
	x.a[2][2] = 1, x.a[2][3] = 1, x.a[3][3] = 1;
	
	y.a[1][1] = 2, y.a[1][2] = 2, y.a[1][3] = 1;
	y.a[2][1] = 1, y.a[2][2] = 1, y.a[2][3] = 1;
	y.a[3][1] = 1, y.a[3][2] = 0, y.a[3][3] = 1;
	
	int last = 0;
	for (int i = 1; i <= k; i++) {
		int len = b[i] - last - 1;
		if (len > 0) ans = ans * quickmod (y, len);
		ans = ans * x;
		last = b[i];
	}
	int len = n - last - 1;
	if (len > 0) ans = ans * quickmod (y, len);
	printf ("%lld", (ans.a[1][1] + ans.a[1][2] + ans.a[1][3]) % mod);
	return 0;
}

Measured memory_bytes: 3952
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n),b(n),c(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }

    sort(all(a)),sort(all(b)),sort(all(c));

    ll sol = 0;
    for(int i = 0; i < n; i++){
        ll left = lower_bound(all(a),b[i]) - a.begin();
        ll right =  n - (upper_bound(all(c),b[i])-c.begin());

        sol += left * right;
    }

    cout << sol << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define endl "\n"

int main()
{
	faster;
	
	int n;
	cin >> n;

	vector<ll> a(n);

	ll balance = 1000,stock = 0;

	for(auto &x: a) cin >> x;

	for(int i = 0; i < n-1; i++){
		if(a[i] < a[i+1]){
			ll temp = balance/a[i];
			balance %= a[i];
			stock += temp;
			balance += (stock * a[i+1]);
			stock = 0;
		}
	}
	
	cout << balance << endl;

	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000007
#define ll long long
#define mp make_pair
int main()
{
	int n,i,a[35],b[35],vis[35];
	memset(vis,0,sizeof(vis));
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	cin>>n;
	a[0]=0,a[1]=1;
	b[0]=0,b[1]=1,b[2]=-2;
	for(i=2;i<=33;i++)a[i]=(a[i-1]*(-2));
	for(i=3;i<=33;i++)b[i]=(b[i-2]+a[i]);
	int pos=33;
	if(n==0)
	{
		cout<<0<<endl;
		return 0;
	}
	while(n!=0)
	{
		if(n>0)
		{
			for(i=pos;i>=0;i--)
			{
				if(n>=b[i]&&b[i]>=0)
				{
					if(n==b[i])
					{
					    vis[i]=1;
					    pos=i;
					    n-=a[i];
					}
					else
					{
					    vis[i+2]=1;
					    pos=i+2;
					    n-=a[i+2];
					}
					break;
				}
				else;
			}
		}
		else
		{
			for(i=pos;i>=0;i--)
			{
				if(n<=b[i]&&b[i]<=0)
				{
					if(n==b[i])
					{
						vis[i]=1;
					    pos=i;
					    n-=a[i];
					}
					else
					{
						vis[i+2]=1;
					    pos=i+2;
					    n-=a[i+2];
					}
					break;
				}
				else;
			}
		}
	}
	bool flag=false;
	for(i=33;i>0;i--)
	{
		if(!vis[i]&&!flag);
		else 
		{
			cout<<vis[i];
			flag=true;
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)

int main(){
    string S;
    cin >> S;
    int length =0, res = 0;
    rep(i,0,S.size()){
        if(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T'){
            length++;
        }else{
            length=0;
        }
        res = max(res, length);
    }
    cout << res << endl;
}

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

int main() {
  int n, m, k;
  cin>>n>>m>>k;
  int a[n], b[m];
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<m; i++) cin>>b[i];
  long long a_acc[n+1], b_acc[m+1];
  a_acc[0] = 0;
  for (int i=0; i<n; i++) a_acc[i+1] = a_acc[i] + a[i];
  b_acc[0] = 0;
  for (int i=0; i<m; i++) b_acc[i+1] = b_acc[i] + b[i];
  int ans = 0;
  for (int i=0; i<=n; i++) {
    if (a_acc[i] > k) {
      continue;
    }
    if (a_acc[i] == k) {
      ans = max(i, ans);
      continue;
    }
    auto it = upper_bound(b_acc, b_acc + (m + 1), k - a_acc[i]);
    int tmp = it - b_acc;
    ans = max(i + tmp - 1, ans);
  }
  cout<<ans<<endl;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,y;
    cin >> n >> y;
    vector<int> ans = {-1,-1,-1};
    for(int i = 0;i <= y/10000;i ++){
        int remain = y;
        remain -= 10000*i;
        for(int j = 0;j <= remain/5000&&remain>=0;j ++){
            remain -= 5000*j;
            if(remain-1000*(n-i-j)==0){
                ans[0]=i;
                ans[1]=j;
                ans[2]=n-i-j;
            }
            remain += 5000*j;
        }
    }
    cout << ans[0] << " " <<
      ans[1] << " " <<
      ans[2] << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[][] numsets = new long[n+1][];
    long[] answers = new long[n];
    long minNum = long.MaxValue;

    for(int i = 0; i < n; i++)
    {
      numsets[i] = new long[2];
      numsets[i][0] = nums[i];
      numsets[i][1] = i;
    }
    numsets[n] = new long[2];
    numsets[n][0] = 0;
    numsets[n][1] = 0;
    var sorted = numsets.OrderByDescending(a => a[0]).ThenByDescending(a => a[1]).ToList();

    for(int i = 0; i < n; i++)
    {
      minNum = Math.Min(minNum, sorted[i][1]);
      answers[minNum] += (i+1)*(sorted[i][0] - sorted[i+1][0]);
    }
    
    var answerText = new StringBuilder();
    for(long i = 0; i < answers.Length; i++)
    {
      answerText.AppendLine(answers[i].ToString());
    }
    Console.Write(answerText);
	}
}

Measured memory_bytes: 41208
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<cstdlib>

#define REP(i,n) for(int i = 0;i < n;i++)

typedef long long ll;

using namespace std;

vector<int> b;
int a[300100];
int n; 
 
int main()
{
	cin >> n;
	REP(i,n) scanf("%d",&a[i]);
	
	if(n % 2 == 0)
	{
		for(int i = n-1;i > 0;i -=2)
			printf("%d ",a[i]);
		for(int i = 0;i < n;i += 2)
			printf("%d ",a[i]);
	}
	else
	{
		for(int i = n-1;i >= 0;i -= 2)
			printf("%d ",a[i]);
		for(int i = 1;i < n ;i += 2)
			printf("%d ",a[i]);
	}
	
	cout << endl;
	
	return 0;
}

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

using namespace std;

#define sf scanf
#define pf printf
#define ll long long
#define fr(I,M,N) for(I=M;I<=N;I++)
#define fr_(I,M,N) for(I=M;I>=N;I--)
#define re return
#define sfn cin>>n
#define bal pf("bal\n")
#define pb push_back
#define ins insert
#define sz(X) X.size()
#define xx first
#define yy second
#define skip continue
#define memo(X,N) memset(X,N,sizeof(X))
#define all(X) X.begin(),X.end()
#define mp make_pair
#define pi acos(-1)


/*
#define nMX 5000000
#define pMX 500000
int pr[pMX+1],prnum[nMX+1];

int sieve()
{
    int i,j;
    for(i=1;i<=nMX;i++)
        prnum[i]=i+1;
    for(i=1;i<=nMX;i++)
        if(prnum[i]!=-1)
            for(j=2*prnum[i]-1;j<=nMX;j+=prnum[i])
                    prnum[j]=-1;
    j=0;
    for(i=1;i<=nMX;i++)
        if(prnum[i]!=-1)
            pr[++j]=prnum[i];
    re j;
}*/

/*ll m_ncr[10001][10001];
ll ncr(ll i,ll j)
{
    if(j==1) re i;
    if(i==j) re 1;
    if(m_ncr[i][j]!=-1) re m_ncr[i][j];
    re m_ncr[i][j]=ncr(i-1,j) + ncr(i-1,j-1);
}*/

/*ll m_fact[21];
ll fact(ll i)
{
    if(i==1 || i==0) re 1;
    if(m_fact[i]!=-1) re m_fact[i];
    re m_fact[i]=i*fact(i-1);
}*/

ll cn[200005];

int main()
{
    ios_base::sync_with_stdio(0);
    ll int i,j,x,y,n,m,cnt=0,k,g,flg,t;
    string s;
    cin>>n>>k;
    cin>>s;
    fr(i,1,n-1)
    {
        cn[i+1]=cn[i];
        if(s[i-1]=='A' && s[i]=='C')
        {
            cn[i+1]++;
        }
    }
    fr(i,1,k)
    {
        cin>>x>>y;
        printf("%lld\n", cn[y]-cn[x]);
    }
}


Measured memory_bytes: 1872
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,m,maxi,d,x;
	
	cin>>n;
	ll a[n];
	c=1;
	k=0;
	for(j=0;j<n;j++)
	{
		cin>>a[j];
		if(a[j]==0)
			k=1;
		
	}
	sort(a,a+n);
	if(k==1)
	{
		cout<<0;
		return 0;
	}
	fo(j,n)
	{
		c=c*a[j];
		if(c>1000000000000000000 || c<=0)
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<c<<endl;
}



	

		

Measured memory_bytes: 4436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		while(N < 2 || 200 < N){
			System.out.println("2から200までの数を入力してください。");
			N = sc.nextInt();
		}
		int[][] num = new int[N][3];
		int[] point = new int[N];
		int ptswt = 0;
		for(int i = 0; i < N; i++){
			point[i] = 0;
		}
		for(int i = 0; i < N; i++){
			num[i][0] = sc.nextInt();
			while(num[i][0] < 1 || 100 < num[i][0]){
				System.out.println("1から100までの数を入力してください。");
				num[i][0] = sc.nextInt();
			}
			num[i][1] = sc.nextInt();
			while(num[i][1] < 1 || 100 < num[i][1]){
				System.out.println("1から100までの数を入力してください。");
				num[i][1] = sc.nextInt();
			}
			num[i][2] = sc.nextInt();
			while(num[i][2] < 1 || 100 < num[i][2]){
				System.out.println("1から100までの数を入力してください。");
				num[i][2] = sc.nextInt();
			}
		}
		for(int j = 0; j < N; j++){ //参照するプレイヤー
			for(int i = 0; i < 3; i ++){ //ゲームの回数
				for(int k = 0; k < N; k++){ //その他のプレイヤー
					if(j != k){
						if(num[j][i] == num[k][i]){
							ptswt = 0;break;
						}else{
							ptswt = 1;
						}
					}
				}
				if(ptswt == 1){
					point[j] += num[j][i];
				}
			}
		}
		for(int i = 0; i < N; i++){
			System.out.println(point[i]);
		}
	}

}

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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

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

    int a, b, k;

    cin >> a >> b >> k;

    int count = 0;
    int i;
    for(i = min(a, b); i >= 1; i--) {
        if((a % i == 0) && (b % i == 0))
            count++;
        if(count == k)
            break;
    }
    cout << i << endl;


    return 0;
}

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

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

	static class ProblemB {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int numTests = in.nextInt();
			for (int test = 0; test < numTests; test++) {
				long a = in.nextLong();
				long b = in.nextLong();
				long c = in.nextLong();
				long d = in.nextLong();
				out.println(solve(a, b, c, d) ? "Yes" : "No");
			}
		}

		private boolean solve(long a, long b, long c, long d) {
			if (b > a) {
				return false;
			}
			if (a > c) {
				long k = (a - c) / b;
				if (a - k * b == c) {
					--k;
				}
				assert (a - k * b > c);
				assert (a - (k + 1) * b <= c);
				a -= k * b;
			}
			if (b > a) {
				return false;
			}
			if (b > d) {
				return false;
			}
			if (b == d) {
				return true;
			}
			if (b <= c) {
				return true;
			}

			long g = gcd(b, d);
			long closest = g - (a % g);
			if (b > c + closest) {
				return false;
			}

			return true;
		}

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

	}

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

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

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

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

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

	}
}



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

int main(){
    int n;
    cin >> n;
    vector<double> prob(1);
    prob[0] = 1;
    for (int i = 0; i < n; i++){
        double p;
        cin >> p;
        vector<double> newprob(prob.size() + 1, 0);
        for (int j = 0; j < prob.size(); j++){
            newprob[j + 1] += prob[j] * p;
            newprob[j] += prob[j] * (1 - p);
        }
        prob = newprob;
    }
    double res = 0;
    for (int i = n / 2 + 1; i < prob.size(); i++) res += prob[i];
    cout << fixed << setprecision(15);
    cout << res << endl;
}


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

ll n, m, h[200020], a[200020];
vector<ll> dp;
void update(int i, ll x) {
  i += m - 1;
  dp[i] = max(dp[i], x);
  while (i > 0) {
    i = (i - 1) >> 1;
    dp[i] = max(dp[i * 2 + 1], dp[i * 2 + 2]);
  }
}
ll query(int a, int b, int l, int r, int i) {
  if (b <= l || r <= a) return 0;
  if (a <= l && r <= b) return dp[i];
  ll v1 = query(a, b, l, (l + r) >> 1, i * 2 + 1);
  ll v2 = query(a, b, (l + r) >> 1, r, i * 2 + 2);
  return max(v1, v2);
}

int main()
{
  cin >> n;
  REP(i, n) cin >> h[i];
  REP(i, n) cin >> a[i];
  // init
  for(m = 1; m < n; m <<= 1);
  dp.resize(m * 2 - 1);

  REP(i, n) {
    ll mx = query(0, h[i], 0, m, 0) + a[i];
    update(h[i] - 1, mx);
  }

  cout << query(0, m, 0, m, 0);
  return 0;
}

Measured memory_bytes: 7424
ABs = []

N = int(input())
for i in range(N):
    ABs.append(list(map(int,input().split())))

ABs = sorted(ABs, key=lambda x: x[1])

sum = 0
for pair in ABs:
    sum += pair[0]
    if sum > pair[1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 48604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<(ll)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
const ll INF = 1e9;

ll gcd(ll a, ll b){
    if(b>a) {
        ll t=a;
        a=b;
        b=t;
    }
    if(b==0) return a;
    return gcd(b, a%b); 
}

bool is_prime(ll x){
    if(x==1) return false;
    for(ll i=2; i*i<=x;i++){
        if(x%i == 0) return false;
    }
    return true;
}

int main(){
    fast_io
    
    ll a, b;
    cin>>a>>b;

    ll g = gcd(a, b);
    ll ans=0;

    for(ll i=1;i*i<=g;i++){
        if(g%i == 0){
            if(is_prime(i)) ans++;
            ll tmp=g/i;
            if(tmp != i && is_prime(tmp)) ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define INF 0x7fffffff
using namespace std;
ll n,m;
char A[1001][1001];
ll dp[1001][1001];
ll solve(ll i,ll j){
    if(i == n || j == m)
        return 0;
    if(i == n-1 && j == m-1)
        return 1;
    if(dp[i][j] != -1)
        return dp[i][j];
    if(A[i][j] == '#')
        return 0;
    return dp[i][j] = (solve(i+1,j) + solve(i,j+1))%MOD;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    memset(dp,-1,sizeof dp);
    for(ll i = 0; i < n; i++){
        string s;
        cin>>s;
        for(ll j = 0; j < m ; j++){
            A[i][j] = s[j];
        }
    }
    cout<<solve(0,0);
    return 0;
}




//freopen("input.in","r",stdin);
//freopen("output.out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);


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

#define int             long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

int lcm(int a, int b)
{
	return (a / gcd(a, b)) * b;
}

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	char c;
	cin>>c;
	if(c>=97)
	cout<<"a";
	else 
	cout<<"A"<<endl;
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}



Measured memory_bytes: 3680
mod=10**9+7

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr

n=int(input())
dat = [0] * 2000 

res = 1
for i in range(1, n + 1):
    d = factorization(i)
    #print(d)
    for j in range(len(d)):
        dat[d[j][0]] += d[j][1]

#print(dat)

for i in range(2, n + 1):
    res *= (dat[i] + 1)
    res %= mod

print(res)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {

    int N;
    cin >> N;
    bool ans = false;
    for (int i = 1; i < 10; i++){
        if (N % i == 0 && 1 <= (N / i) && (N / i) <= 9) ans = true;
    }
    if (ans){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := intSliceScanner(n)
	sort.Ints(a)
	ans := 0
	if len(a)%2 == 0 {
		for i := 0; i < n/2-1; i++ {
			ans -= a[i] * 2
		}
		ans -= a[n/2-1]
		ans += a[n/2]
		for i := n/2 + 1; i < n; i++ {
			ans += a[i] * 2
		}
	} else {
		x := 0
		y := 0
		for i := 0; i < n/2-1; i++ {
			x -= a[i] * 2
		}
		x -= a[n/2-1]
		x -= a[n/2]
		for i := n/2 + 1; i < n; i++ {
			x += a[i] * 2
		}
		for i := 0; i < n/2; i++ {
			y -= a[i] * 2
		}
		y += a[n/2]
		y += a[n/2+1]
		for i := n/2 + 2; i < n; i++ {
			y += a[i] * 2
		}
		if x > y {
			ans = x
		} else {
			ans = y
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2944
l = [int(input()) for i in range(5)]
rest = []
time = 0
for v in l:
  if v %10 == 0:
    time += v
  else:
    time += int(v/10)*10
    rest.append(v%10)
#print(rest)
if rest != []:
  time += ((len(rest)-1)*10)
  time += min(rest)
print(time)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main(){
  ll a,b,n;
  cin>>a>>b>>n;
  
  if(b==1){
    cout<<0<<endl;
    return 0;
  }
  
  ll k=(n+1)/b-1;
  
  ll x;
  if(k<0) x=n;
  else x=b*k+b-1;
  
  ll ans=floor(a*x/b)-a*floor(x/b);
  
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
static const ll MAX_L = (ll)1 << 62;

int N, A;
int x[51];
ll dp[51][51][3010];
void print(ll p) {
	cout << endl;
	cout << "  ";
	rep(i, 0, 50) {
		cout << i % 10;
	}
	cout << endl;
	repe(i, 0, N) {
		cout << i << " ";
		rep(j, 0, 50) {
			cout << dp[p][i][j] % 10;
		}
		cout << endl;
	}
}

int main() {
	ll a; cin >> N >> a;
	repe(i, 1, N)cin >> x[i];

	dp[0][0][0] = 1;

	repe(i, 1, N) {
		ll X = x[i];
		repe(h, 0, i) {
			rep(w, 0, 2501) {
				if (dp[i - 1][h][w] != 0) {
					dp[i][h][w] += dp[i - 1][h][w];
				}

				if (w - X >= 0 && h - 1 >= 0 && dp[i - 1][h - 1][w - X] != 0) {
					dp[i][h][w] += dp[i - 1][h - 1][w - X];
				}
			}
		}

		//print(i);
	}

	ll ans = 0;
	repe(i, 1, N) {
		ans += dp[N][i][a*i];
	}
	cout << ans << endl;
	return 0;
}

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

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


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

int main(){
	string s; cin >> s;
	vl num(4); rep(i,4)num[i] = s[i] - '0';
	rep(tmp,(1 << 3)){
		bitset<3> p(tmp);
		int sum = num[0];
		rep(i,3)p.test(i) ? sum += num[i+1] : sum -= num[i+1];
		if(sum == 7){
			vector<char> r(3);
			rep(i,3)p.test(i) ? r[i] = '+' : r[i] = '-' ;
			cout << num[0] << r[0] << num[1] << r[1] << num[2] << r[2] << num[3] << "=7" << endl;
			return 0; 
		}
		
	}
	
}

Measured memory_bytes: 256