akhauriyash/Code-Regression huggingface dataset:
//Name: Sum of Cards
//Level: 2
//Category: 動的計画法,DP
//Note:

/*
 * dp[i][j]をi種類目のカードまでを使ってjを作るパターン数とすると，
 *   dp[i][j] = Σ(0≦k≦b_i) dp[i-1][j - a_i*k]
 * となる．
 *
 * 以下のコードでは，iのインデックスを1-originにしてベースケースを簡単にし，また配るDPにして書きやすくしている．
 * オーダーは O(M*G*B)．ただしGは合計値の最大(1000)，Bはカード枚数の最大(10)．
 */
#include <iostream>
#include <vector>

using namespace std;

int dp[8][1001];

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

    while(true) {
        int M;
        cin >> M;
        if(!M) break;
        dp[0][0] = 1;
        for(int i = 1; i <= M; ++i) {
            int A, B;
            cin >> A >> B;
            for(int j = 0; j < 1001; ++j) dp[i][j] = 0;
            for(int j = 0; j < 1001; ++j) {
                for(int k = 0; k <= B; ++k) {
                    const int next = j + A*k;
                    if(next <= 1000) dp[i][next] += dp[i-1][j];
                }
            }
        }
        int N;
        cin >> N;
        while(N--) {
            int NG;
            cin >> NG;
            cout << dp[M][NG] << endl;
        }
    }
    return 0;
}

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

using namespace std;

int main(){
    int N,X; cin>>N>>X;
    vector<int> L(N+1);
    vector<int> D(N+3);

    D[1]=0;
    int count=0;

    for(int i=1;i<=N;i++){
        cin>>L[i];
    }

    for(int i=1;i<=N;i++){
        D[i+1]=D[i]+L[i];
    }

    for(int i=1;i<=N+1;i++){
        if(D[i]<=X) count++;
    }

    printf("%d",count);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i,temp,count;
	long n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		count=0;
		temp=n+m;
		while(temp>=1){
			temp=temp/10;
			count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<math.h>
using namespace std;

long long mochila(long long W, long long N, long long vetorPeso[],long long vetorValor[]){
	
	int i, j;
	long long moc[N+1][W +1] = {};
	
	for(i = 0; i <= N; i++){
		for(j = 0; j<= W; j++){
			if(j == 0 || i == 0)
				moc[i][j] = 0;
			else if(vetorPeso[i-1] > j)
				moc[i][j] =  moc[i-1][j];
			else
				moc[i][j] = max(vetorValor[i-1] + moc[i-1][j - vetorPeso[i-1]], moc[i-1][j]);
		}
	}
	return	moc[N][W];
}

int main(){
	
	long long N,W;
	
	cin>>N>>W;

	long long w[N], v[N];
	
	for(int i=0; i < N; i++){
		cin>>w[i]>>v[i];
	}
	
	long long resultado = mochila(W, N, w, v);

	cout<<resultado<<endl;
	return 0;
}


Measured memory_bytes: 79104
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			String S = sc.next();
			char[] s = S.toCharArray();
			
			long r = 0;
			long g = 0;
			long b = 0;
			
			for(int i=0;i<n;i++) {
				if(s[i]=='R') {
					r++;
				}else if(s[i]=='G') {
					g++;
				}else {
					b++;
				}
			}
			
			long res = r*g*b;
			
			for(int i=0;i<n;i++) {
				for(int j=i+1;j<n;j++) {
					int k = j+(j-i);
					
					if(k<n&&s[i]!=s[j]&&s[j]!=s[k]&&s[i]!=s[k]) {
						res--;
					}
				}
			}
			
			if(res<=0) {
				System.out.println("0");
			}else {
				System.out.println(res);
			}
			
		}	
	}


Measured memory_bytes: 35852
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, W;
        cin >> n >> W;
        ll w[n], v[n];
        rep(i, n) cin >> w[i] >> v[i];

        ll dp[n + 100][W + 100];
        rep(i, n + 100) rep(j, W + 100) dp[i][j] = 0;
        rep(i, n) {
            repone(j, W) {
                dp[i + 1][j] = dp[i][j];
                if (j >= w[i]) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
            }
        }
        cout << dp[n][W] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 156672
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;

vector<queue<int>> dat;
int n, m;

bool calc(int x, vector<queue<int>>dt) {
	vector<bool>flag(m, false);
	while (true){
		vector<int>count(m, 0);
		for (int i = 0; i < n; i++) {
			if (dt[i].empty())return false;
			count[dt[i].front() - 1]++;
		}
		int l = -1;
		for (int i = 0; i < m; i++) {
			if (count[i] > x) {
				l = i;
				break;
			}
		}
		if (l < 0)break;
		flag[l] = true;
		for (int i = 0; i < n; i++) {
			while (flag[dt[i].front() - 1]) {
				dt[i].pop();
				if (dt[i].empty())return false;
			}
		}
	}
	return true;
}

int main() {
	cin >> n >> m;
	int a;
	for (int i = 0; i < n; i++) {
		dat.push_back(queue<int>());
		for (int j = 0; j < m; j++) {
			cin >> a;
			dat[i].push(a);
		}
	}
	int left = n, right = 0;
	while (left - right > 1) {
		int mid = (left + right) / 2;
		if (calc(mid,dat))left = mid;
		else right = mid;
	}
	cout << left << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
 
int N,M,A,B,C,K;
string s,t="ATCG";

signed main() {
    IOS();
    cin>>s;
    int ans=0,ma=0;
    rep(i,0,(int)s.size()){
        rep(j,0,4){
            if(s[i]==t[j]){
                ma++;
                break;
            }
            if(j==3)ma=0;
        }
        chmax(ans,ma);
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
//BISMILLAH
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int t;
   char ch[1];
    scanf("%s",ch);

    if(ch[0] >= 'A' && ch[0] <= 'Z') cout<< "A"<<endl;
    else cout<< "a"<<endl;


    return 0;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int ans=0;
int l,r;
for(int i=1;i<=n;i++){
	l=sc.nextInt();
	r=sc.nextInt();
	ans=ans+r-l+1;
}
System.out.println(ans);

	}}

Measured memory_bytes: 24660
#include<iostream>

#include<algorithm>
#include<cstring>
using namespace std;

typedef long long ll;
ll a[100002];
int main() {
    int n;
    cin >> n;
    ll ans = 1;
    int ok = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (!a[i]) ok = 1;
    }
    for (int i = 0; i < n; i++) {
     //   cout << ans << endl;
        if (a[i] > (ll)1e18/ ans) {ans = -1; break;}
        ans *= a[i];
    }
    if (ok) ans = 0;
    cout << ans;
   // system("pause");
}

Measured memory_bytes: 3916
// C - String Transformation
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MAXSIZE 200000

int main(){
	string S, T; cin>>S>>T;
	vector<int> ss(26, 0), tt(26, 0), //[char-'a']<count per alphabet>
		cs(MAXSIZE+1, 0), ct(MAXSIZE+1, 0); //[count per alphabet]<count per counted number>
	rp(i, 0, S.size()) ss[S[i]-'a']++;
	rp(i, 0, T.size()) tt[T[i]-'a']++;
	rp(i, 0, 26) cs[ss[i]]++, ct[tt[i]]++;
	rp(i, 1, MAXSIZE+1) if(cs[i] != ct[i]){ puts("No"); return 0; }
	puts("Yes");
}

Measured memory_bytes: 2312
package main

import "fmt"

func main() {
	var (
		n int
		a int64
	)

	fmt.Scanln(&n)

	alist := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)

		if a == 0 {
			fmt.Println(0)
			return
		}

		alist[i] = a
	}

	var prod int64 = 1
	for _, v := range alist {
		if v > 1000000000000000000/prod {
			fmt.Println(-1)
			return
		}

		prod *= v
	}

	fmt.Println(prod)
}


Measured memory_bytes: 6296
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,cnt[20],ok[1<<17],dp[1<<17],val[N];
typedef pair<int,int> pii;
vector<pii> e[N];
void dfs(int x,int fa){
	for (auto i:e[x]){
		int v=i.first;
		if (v==fa) continue;
		val[v]=i.second;
		val[x]^=val[v];
		dfs(v,x);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int u,v,l;
		scanf("%d%d%d",&u,&v,&l);u++;v++;
		e[u].push_back(pii(v,l));
		e[v].push_back(pii(u,l));
	}
	dfs(1,0);
	for (int i=2;i<=n;i++) cnt[val[i]]++;
	int ans=0;
	for (int i=1;i<=15;i++) ans+=cnt[i]/2,cnt[i]%=2;
	for (int i=1;i<=15;i++) ans+=cnt[i];
	cnt[0]=0;
	int U=1<<16;
	for (int i=0;i<U;i++){
		int s=0;
		for (int j=0;j<16;j++)
		if (i>>j&1) s^=j;
		if (!s) ok[i]=1;
	}
	for (int i=0;i<U;i++)
	for (int j=i;j;j=(j-1)&i){
		if (ok[j]) dp[i]=max(dp[i],dp[i^j]+1);
		dp[i]=max(dp[i],dp[i^j]);
	}
	int tmp=0;
	for (int i=0;i<16;i++) tmp^=cnt[i]<<i;
	printf("%d\n",ans-dp[tmp]);
	return 0;
}

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

#define fst first
#define snd second
#define fore(i,a,b) for(int i=a, ThxDem=b; i<ThxDem; ++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define SZ(s) int(s.size())
#define DBG(x) cerr <<#x << " = " << (x) << "\n"

#define SQR(x) ((x) * (x))

#define PI 3.1415926535897932385
#define INF 1000111222
#define eps 1e-7
#define maxN 11

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<bool> vbool;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vbool> vvbool;

vll ns,dp;
ll n;

ll solve(ll pos){
	ll & d = dp[pos];
	if(d != -1) return d;
	ll v=INF;
	if((pos+1)<n)v = min(v,abs(ns[pos+1]-ns[pos])+solve(pos+1));
	if((pos+2)<n)v = min(v,abs(ns[pos+2]-ns[pos])+solve(pos+2));
	if(pos == (n-1)) v = 0;
	return d = v;
}

int main(){FIN
	
	cin >> n;
	ns.resize(n);
	dp.assign(100010,-1);
	fore(i,0,n)cin >> ns[i];
	
	solve(0);
	
	cout << dp[0] << "\n";

	return 0;
}


Measured memory_bytes: 9508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = ReadInts();
            WriteLine(ab.Average());
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 20368
N = int(input())
for i in range(N):
    a,b,c = map(int,input().split())
    
    if a*a == b*b + c*c:
        print('YES')
    elif b*b == a*a + c*c:
        print('YES')
    elif c*c == a*a + b*b:
        print('YES')
    else:
        print('NO')



Measured memory_bytes: 5596
import sys


class Node:
    def __init__(self, key=None, pri=None):
        self.left = None
        self.right = None
        self.key = key
        self.pri = pri


def right_rotate(t: Node):
    s = t.left
    t.left = s.right
    s.right = t
    return s


def left_rotate(t: Node):
    s = t.right
    t.right = s.left
    s.left = t
    return s


def insert(t: Node, key: int, pri: int):
    if t is None:
        return Node(key, pri)
    if key == t.key:
        return t
    if key < t.key:
        t.left = insert(t.left, key, pri)
        if t.pri < t.left.pri:
            t = right_rotate(t)
    else:
        t.right = insert(t.right, key, pri)
        if t.pri < t.right.pri:
            t = left_rotate(t)
    return t


def erase(t: Node, key: int):
    if t is None:
        return None
    if key == t.key:
        if t.left is None and t.right is None:
            return None
        elif t.left is None:
            t = left_rotate(t)
        elif t.right is None:
            t = right_rotate(t)
        else:
            if t.left.pri > t.right.pri:
                t = right_rotate(t)
            else:
                t = left_rotate(t)
        return erase(t, key)
    if key < t.key:
        t.left = erase(t.left, key)
    else:
        t.right = erase(t.right, key)
    return t


def find(t: Node, x: int):
    while t is not None:
        if t.key == x:
            return 1
        elif t.key > x:
            t = t.left
        else:
            t = t.right
    return 0


def inorder(t: Node):
    if t.left is not None:
        inorder(t.left)
    print(" {}".format(t.key), end='')

    if t.right is not None:
        inorder(t.right)
    return


def preorder(t: Node):
    print(" {}".format(t.key), end='')

    if t.left is not None:
        preorder(t.left)
    if t.right is not None:
        preorder(t.right)
    return


def print_key(t: Node):
    inorder(t)
    print("\n", end='')
    preorder(t)
    print("\n", end='')
    return


line = sys.stdin.readline()
n = int(line)
root = None
for i in range(n):
    line = sys.stdin.readline().split()
    if line[0] == 'insert':
        k, p = int(line[1]), int(line[2])
        root = insert(root, k, p)
    elif line[0] == 'delete':
        k = int(line[1])
        root = erase(root, k)
    elif line[0] == 'find':
        k = int(line[1])
        if find(root, k):
            print("yes")
        else:
            print("no")
    else:
        print_key(root)



Measured memory_bytes: 52032
#include <bits/stdc++.h>
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long int
#define ld long double
#define el '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < int(n); i++)
#define pll pair<ll, ll>
#define mll map<ll,ll>
#define vli vector<pair<ll,int>>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

vector<ll> parent, rak;

void make_set(int f){
    fo(i,f+1)parent.pb(i);
    rak.assign(f+1,1);
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

ll union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rak[a]+=rak[b];
        return (rak[a]-rak[b])*(rak[b]);
    }
    return 0;
}

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

/*const int N = 1000001;
int lp[N+1];
vector<int> pr;
void s(){
for (int i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }
}*/


ld kv;
ll t,n,x,y,h,k,z,p,q,w;
string s;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    ll m;
    cin>>n>>m;
    pll a[m];
    fo(i,m)cin>>a[i].ff>>a[i].ss;
    make_set(n);
    vl v(m);
    v[m-1]=n*(n-1)/2;
    fo(i,m-1){
        x=union_sets(a[m-1-i].ff,a[m-1-i].ss);
        v[m-2-i]=v[m-1-i]-x;
    }
    pt(v);
    return 0;
}


Measured memory_bytes: 5364
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
  int key;
  struct node *l, *r, *par;
}Node;

Node *NIL, *root;

Node* find(Node *u,int k){
  while(u!= NIL && k!= u->key){
    if(k < u->key)u=u->l;
    else u = u->r;
  }
  return u;
}

void insert(int k){
  Node *x=root;
  Node *y=NIL;
  Node *z;

  z=(Node *)     malloc(sizeof(Node));
  z-> key=k;
  z-> l=NIL;
  z-> r=NIL;
  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x ->l;
    }
    else{
      x = x->r;
    }
  }

  z -> par=y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z ->key < y->key){
      y-> l=z;
    }
    else{
      y-> r=z;
    }
  }
}

void inorder(Node *u){
  if(u == NIL)         return;
  inorder(u -> l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(Node *u){
  if(u == NIL)                 return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  int n,i,a;
  char ary[10];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s",ary);
    if(strncmp(ary,"f",1)==0){
      scanf("%d",&a);
      Node *v=find(root,a);
      if(v!=NIL)              printf("yes\n");
      else                    printf("no\n");
    }
    else if(strcmp(ary,"insert")==0){
      scanf("%d",&a);
      insert(a);
    }
    else if(strcmp(ary,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20440
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, T;
    vector<int> c;
    vector<int> t;
    cin >> n >> T;
    for(int i = 0;i < n;i++) {
        int x, y;
        cin >>x >> y;
        c.push_back(x);
        t.push_back(y);
    }
    int min = 10000;
    for(int i = 0;i < n;i++) {
        if(t[i]<=T) {
            if(min>c[i]) {
                min = c[i];
            }
        }
    }
    if(min!=10000) cout << min << endl;
    else cout << "TLE" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  string f=s;
  int n=s.size();
  reverse(f.begin(),f.end());  
  if(s!=f){
    cout << "No" << endl;
    return 0;
  }
  string a=s.substr(0,(n-1)/2);
  string b=s.substr((n+1)/2,(n-1)/2);
  string w=a;
  reverse(w.begin(),w.end());
  if(w!=a){
    cout << "No" << endl;
    return 0;
  }
  string q=b;
  reverse(q.begin(),q.end());
  if(b!=q){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    LL N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;
    
    if(N <= min({A, B, C, D, E})){
        cout << 5 << endl;
        return 0;
    }

    LL r1 = min({N, A});
    LL r2 = min({r1, B});
    LL r3 = min({r2, C});
    LL r4 = min({r3, D});
    LL r5 = min({r4, E});

    LL ans = (N%r5 == 0)? N/r5 + 5 - 1 : N/r5 + 5;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long LL;

const int nmax = 30005; const LL inf = 2e18;

int v[nmax],N,x1[nmax],x2[nmax],s[nmax];
struct el{
 int x,y;
}a[nmax];
int main(){
//   #ifndef GLOBAL_JUDGE
//      freopen("txt.in","r",stdin);
//      freopen("txt.out","w",stdout);
//   #endif // GLOBAL_JUDGE
   int i,j,p,g;
   cin >> N;
   for(i = 1,j=300000000; i <= N; ++i,++j)
      cin >> a[i].x,a[i].y =j,v[a[i].x] = i;


   for(i = 1; i <= N; ++i){
        p = v[i];
        g = a[p].y;
        if(i == 1){
         x1[i] = 1;
         x2[i] = g-1;
         continue;
        }
        j = x1[i-1]+1;
        while(g-j>=x2[i-1])++j;
        x1[i] = j;
        x2[i] = g-j;
   }
   for(i = 1; i <= N; ++i)
      cout << x1[i] << ' ';
   cout << '\n';
   for(i = 1; i <= N; ++i)
      cout << x2[i] << ' ';
   return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
signed main() {
	int n = 0; cin>> n;
	int ans = 0;
	int v[123], c[123];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		ans += max(0, v[i] - c[i]);
	}cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int k, x;
    cin >> k >> x;
    if (500*k>=x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

data = []
for i in range(N):
    t,x,y = map(int,input().split())
    data.append((t,x,y))

ct,cx,cy = 0,0,0
for i in range(N):
    hdist = abs(data[i][1] - cx) + abs(data[i][2] - cy)
    if hdist > abs(data[i][0] - ct) or abs(hdist - abs(data[i][0] - ct)) % 2 != 0:
        print("No")
        break
    ct,cx,cy = data[i][0],data[i][1],data[i][2]
else:
    print("Yes")
    


Measured memory_bytes: 17304
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	int A,B;

	cin >> A >> B;

	FOR(C, 1, 4) {
		if ((A * B * C) % 2 != 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
vector<int>v(n);
for(int i=0;i<n;i++)
    cin>>v[i];
vector<int>f(n,INT_MAX);
f[0]=0,f[1]=abs(v[1]-v[0]);
if(n>2)
{
    for(int i=2;i<n;i++)
    {
        if(i-k>=0)
        for(int j=i-k;j<i;j++)
        {
            if((abs(v[i]-v[j])+f[j])<f[i])
                f[i]=(abs(v[i]-v[j])+f[j]);
        }
        else
        {
            for(int j=0;j<i;j++)
            {
                if((abs(v[i]-v[j])+f[j])<f[i])
                f[i]=(abs(v[i]-v[j])+f[j]);
            }
        }

    }
    cout<<f[n-1];
}
else cout<<f[n-1];

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define debug(x) cout<<x<<'\n'
#define pii pair<ll,pair<ll,ll> >
using namespace std;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans;
}
ll mul(ll a,ll b){//大数取模乘法防止溢出
    ll ans=0;
    a%=mod,b%=mod;
    while(b) { if(b&1) ans = (ans+a)%mod; a = (a*2)%mod; b >>= 1; }
    return ans;
}
//(b/a)%p=b*a^(p-2)%p
int pr(ll num){//判断素数
     if(num == 1) return 0;
     if(num ==2|| num==3 ) return 1 ;
     if(num %6!= 1&&num %6!= 5) return 0 ;
     int tmp =sqrt( num);
     for(int i= 5;i <=tmp; i+=6 )
          if(num %i== 0||num %(i+ 2)==0 )return 0 ;
     return 1 ;
}
int Day(int y,int m, int d){
    if(m==1||m==2) { m+=12; y--; }
    int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
    return w+1;
}
inline int read() {
    int c = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        c = c * 10 + ch - '0';
        ch = getchar();
    }
    return c * f;
}

//#pragma comment(linker, "/STACK:1024000000,1024000000")//外挂开栈
//stable_sort 排序不处理相同元素
//map<int,int>::reverse_iterator rit;
//for(rit=mp.rbegin();rit!=mp.rend();rit++)
//vec动态二维数组
//vector<vector<int>> g(26,vector<int>(100005));
//初始化vec里面套了n个vec

//lower_bound(begin,end,num) 有序数列中返回第一个>=num的数字的地址
//upper_bound( begin,end,num) 返回第一个>num的数字的地址

const int maxn=1e5+5;
struct ac{
    int a,b,c,d;
}r[55];
int n,m,q;
ll ans=0;
int choice[11];
void DFS(int deep,int minn){
    if(deep==n+1){
        ll s=0;
        for(int i=1;i<=q;++i){
            if(choice[r[i].b]-choice[r[i].a]==r[i].c) s+=r[i].d;
        }
        ans=max(ans,s); return ;
    }
    for(int i=minn;i<=m;++i){
        choice[deep+1]=i;
        DFS(deep+1,i);
    }
}
int main(){
    cin>>n>>m>>q;
    for(int i=1;i<=q;++i){
        cin>>r[i].a>>r[i].b>>r[i].c>>r[i].d;
    }
    DFS(0,1);
    cout<<ans<<endl;
    return 0;
}


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

long hits(long h){
	if( h == 1)
      return 1;
  
	return ( 2 * hits(h/2) + 1);
}


int main(){
  long H;
  cin >> H;
  
  cout << hits(H);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g;}
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

int main()
{
	int d, g;
	cin >> d >> g;
	vi p(d), c(d);
	rep(i, d)cin >> p[i] >> c[i];
	int ans = 2000;
	rep(mask, 1 << d)
	{
		vb solved(d, false);
		int g_now = g;
		int tmp = 0;
		rep(pos, d)
		{
			if (1 << pos & mask)
			{
				g_now -= (pos + 1)*100 * p[pos] + c[pos];
				tmp += p[pos];
				solved[pos] = true;
			}
		}
		rep(pos, d)
		{
			int g_now2 = g_now;
			int tmp2 = tmp;
			int j = 0;
			if (!solved[pos])
			{
				while (j <= p[pos] && g_now2 > 0)
				{
					g_now2 -= (pos + 1) * 100;
					j++;
				}
			}
			if (g_now2 <= 0)
			{
				tmp2 += j;
				chmin(ans, tmp2);
			}
		}
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<int> p(100001, 0);
vector<vector<int>> root(100001);
bitset<100001> used;
vector<int> v;

void rec(int corrent){
    if(used[corrent]) return;
    used[corrent] = true;
    v.push_back(corrent);
    for(auto c : root[corrent]) rec(c);
    return;
}

int main(void){
    
    used.set();
    scanf("%d %d", &N, &M);
    for(int i = 1; i <= N; ++i) scanf("%d", &p[i]);
    for(int i = 0; i < M; ++i){
        int x, y; scanf("%d %d", &x, &y);
        root[x].push_back(y), root[y].push_back(x);
        used[x] = used[y] = false;
    }
    
    int ans = 0;
    for(int i = 1; i <= N; ++i) if(used[i] && p[i] == i) ++ans;
    
    for(int i = 1; i <= N; ++i){
        if(used[i]) continue;
        v.clear();
        rec(i);
        map<int, int> mp;
        for(auto idx : v) ++mp[idx], ++mp[p[idx]];
        for(auto m : mp) if(m.second == 2) ++ans;
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 14200
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 5000000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) {
            a[i + 1] <<= 1;
            a[i + 1] += a[i + 1] << 2;
            a[i + 1] += *pos++ - '0';
        }
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    rep(i, m) {
        while('0' <= *pos) {
            b[i + 1] <<= 1;
            b[i + 1] += b[i + 1] << 2;
            b[i + 1] += *pos++ - '0';
        }
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


Measured memory_bytes: 7832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m;
  in2(n, m);
  if(m == 1){
    out(0);
    memi;
    return 0;
  }
  vector<ll> a(m), b(m - 1);
  rep(i, m)
    in(a[i]);
  sort(all(a));
  rep(i, m - 1)
    b[i] = a[i + 1] - a[i];
  sort(all(b));
  rep(i, n - 1)
    b[max(0ll, m - i - 2)] = 0;
  n = 0;
  rep(i, b.size())
    n += b[i];
  out(n);
  memi;
}


Measured memory_bytes: 1792
from collections import deque
n, m = map(int, input().split())
#z:oddなら a_x, a_y の一方が1、もう一方が２
#z:evenなら a_x, a_yがどちらも２またはどちらも１
edges = [[]*n for _ in range(n)]
for i in range(m):
    x, y, z = map(int, input().split())
    edges[x-1].append(y-1)
    edges[y-1].append(x-1)

d = deque()
id_list = [-1]*n


def dfs(start, id):
    d.append(start)
    id_list[start] = id
    while d:
        p = d.pop()
        for c in edges[p]:
            if id_list[c] != -1:
                continue
            id_list[c] = id
            d.append(c)

id = 1
for i in range(n):
    if id_list[i] == -1:
        dfs(i, id)
        id += 1

print(max(id_list))

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

sum_a = sum(a)
divisors = []
for i in range(1,int(sum_a**0.5)+1):
    if sum_a % i == 0:
        divisors.append(i)
        if i != n // i:
            divisors.append(sum_a//i)

divisors.sort(reverse=True)

for i in range(len(divisors)):
    b = [0]*n
    for j in range(n):
        b[j] = a[j] % divisors[i]
    b.sort(reverse=True)
    plus = sum(b)
    minus = 0
    for j in range(n):
        if plus == minus:
            break
        else:
            plus -= b[j]
            minus += (divisors[i] - b[j])
    if plus <= k:
        print(divisors[i])
        break


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] lines = line.split(" ");
		int N = Integer.parseInt(lines[0]);
		int K = Integer.parseInt(lines[1]);

		line = sc.nextLine();
		lines = line.split(" ");
		long[] M = new long[N];

		for(int i = 0; i < N; i++) {
			M[i] = Integer.parseInt(lines[i]);
		}

		for(int i = K; i < N; i++) {

			if(M[i-K] < M[i]) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}

		}
	}

}


Measured memory_bytes: 84036
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

vector<LL> fact;
vector<LL> inver(200001);

LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}


LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}

void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}

vector<LL> divi(LL K){
    vector<LL> v;
    for(int i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

vector<LL> t;
LL N,M;

LL dfs(int k,LL sum,LL c){
    if(c>N) return 0;
    if(k==t.size()-1) return sum==1?1:0;
    LL ret=0;
    for(int i=0;;i++){
        ret+=combi(N-c,i)*dfs(k+1,sum,c+i);
        ret%=mod;
        if(sum%t[k]) break;
        sum/=t[k];
    }
    return ret%mod;
}



int main(){
    cin >> N >> M;
    t=divi(M);
    reverse(ALL(t));
    set_combi();
    cout << dfs(0,M,0)%mod << endl;
    return 0;
}


Measured memory_bytes: 4988
from itertools import permutations
import math
def rangeT(a,b):
    return (math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2 ))

n=int(input())

X=[[0]*2 for _ in range(n)]

for i in range(n):
    X[i]=[int(x) for x in input().split()]

total=0
for perm in permutations(range(n)):
    for i,j in zip(perm,perm[1:]):
        total += rangeT(X[i],X[j])

print(total/math.factorial(n))

Measured memory_bytes: 3064
// atcoder/abc133/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> a(n);
    cin >> a;

    lli x = 0;
    for (int i = 0; i < a.size(); ++i) {
      if (i % 2) x -= a[i];
      else x += a[i];
    }

    vector<lli> v;
    v.push_back(x);

    for (int i = 1; i < n; ++i) {
      v.push_back((a[i - 1] - v.back() / 2) * 2);
    }

    for (int i = 0; i < v.size(); ++i) {
      cout << v[i] << ' ';
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
    int n;
    cin>>n;
    int ans=0;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i+=2)
        if(((i+1)%2==1)&&(a[i]%2==1))
                ans++;
    cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=500005;
int n,q,D;
int d[max_n];
int a[max_n];
int dp[max_n];
int main(){
    scanf("%d%d",&n,&D);
    for(int i=1;i<=n;i++)scanf("%d",d+i);
    int now=D;
    for(int i=1;i<=n;i++){
        a[i]=now;
        now=min(now,abs(now-d[i]));
    }
    dp[n]=1;
    for(int i=n-1;i>=1;i--){
        if(dp[i+1]>d[i+1]/2)dp[i]=dp[i+1]+d[i+1];
        else dp[i]=dp[i+1];
    }
    scanf("%d",&q);
    while(q--){
        int x;scanf("%d",&x);
        if(dp[x]<=a[x])printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 7808
#N, M = map(int, input().split())
#
#ans = [0 for i in range(M)]
#
#for i in range(N):
#    tmp = list(map(int, input().split()))
#    for j in range(tmp[0]):
#        ans[tmp[j]]+=1
#        
#now = 0
#        
#for i in range(M):
#    if ans[i]==N:
#        now+=1
#        
#print(now)

N = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    if a<b:
        b,a = a,b
        
    while b:
        a, b = b, a%b
    
    return a


ans = 0
now = a[0]

for i in range(N-1):
    tmp = gcd(now, a[i+1])
    now = tmp

    
print(now)

Measured memory_bytes: 14252
// コンテスト中に書いた解法

#include <bits/stdc++.h>

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int tar; scanf("%d",&tar);

	vector<mint> dp(tar+1);
	dp[0]=1;
	for(int i=3;i<=tar;i++) dp[i]=dp[i-1]+dp[i-3];
	cout<<dp[tar]<<'\n';

	return 0;
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	string s, t;
	cin >> s >> t;
	int mini = (int) 1e5;
	for (int i = 0; i < (int) s.size() - (int) t.size() + 1; i++) {
		int c = 0;
		int idx1 = i, idx2 = 0;
		while (idx2 < (int) t.size()) {
			if (s[idx1] != t[idx2]) {
				c++;
			}
			idx1++;
			idx2++;
		}
		mini = min(mini, c);
	}
	cout << mini << "\n";
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005


ll V;
vector<int> G[SIZE];
ll A[SIZE],B[SIZE],diff[SIZE];
ll COUNT[SIZE];

void dfs(int node_id,int pre){

	diff[node_id] = A[node_id]-B[node_id];

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == pre)continue;

		dfs(child,node_id);
		diff[node_id] += diff[child];
	}
}

void dfs2(int node_id,int pre){

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];

		if(child == pre){
			COUNT[node_id] = COUNT[pre]+diff[node_id];
			break;
		}
	}

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == pre)continue;

		dfs2(child,node_id);
	}
}


int main(){

	scanf("%lld",&V);

	int from,to;
	for(ll i = 0; i < V-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
		G[to].push_back(from);
	}
	for(ll i = 0; i < V; i++){

		scanf("%lld",&A[i]);
	}
	for(ll i = 0; i < V; i++){

		scanf("%lld",&B[i]);
	}

	dfs(0,-1);

	COUNT[0] = 0;
	dfs2(0,-1);

	ll ans = 0;
	ll minimum = HUGE_NUM;

	for(int i = 0; i < V; i++){

		ans += COUNT[i];
		minimum = min(minimum,COUNT[i]);
	}

	ans -= V*minimum;

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

	return 0;
}



Measured memory_bytes: 17664
#include "bits/stdc++.h"
#include "sstream"
#define EPS 1e-9
using namespace std;
const int N=1e3+5,OO=0x3f3f3f3f;
typedef long long ll;
const int mod=1e9+7;
int main() {
     string s,t; cin>>s>>t;
     cout<<((s+t.back()==t)?"Yes":"No");
}

Measured memory_bytes: 3628
var num = (val) => Array.isArray(val) ? val.map( (v)=>Number(v) ) : Number(val)
var print = console.log

if (require('os').type() != "Darwin") {
	Main(require("fs").readFileSync("/dev/stdin", "utf8"));
	return;
}

function Main(input) {

	var a = input.split(" ")

	a = num(a).sort(function(a, b) {
		if (a < b) return -1;
		if (a > b) return 1;
		return 0;
	});



	print(a[0] + a[1])

}


Main(`700 600 780`)


Measured memory_bytes: 21320
#include <stdio.h>
#include <string.h>
#define ll long long
const int mod = 1e9+7;
const int N = 2e6+10;
char inp[N]; int n, k;
inline ll power(ll a, ll x) {
	ll ans = 1;
	while (x) {
		if (x&1) ans=ans*a%mod;
		a=a*a%mod;
		x>>=1;
	}
	return ans;
}
ll fac[N], inv[N];
inline ll C(int n, int m) {
	return fac[n] * inv[m] % mod * inv[n-m] % mod;
}
int main() {
	scanf("%d%s", &k, inp); n = strlen(inp);
	fac[0] = 1;
	for (int i=1; i<N; i++) fac[i] = fac[i-1] * i % mod;
	inv[N-1] = power(fac[N-1], mod-2);
	for (int i=N-2; i>=0; i--) inv[i] = inv[i+1] * (i+1) % mod;
	ll ans = 0;
	for (int i=0; i<=k; i++) {
		ans = (ans + power(26, i) * C(n-1+k-i, n-1) % mod * power(25, k-i) % mod) % mod;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 33932
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<ll,ll>
#define vint vector<ll>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
ll read(){
	ll g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const ll N=20;
const ll S=1<<16;
const ll mod=1e9+7;
ll n,m,a[N],f[N][S],siz[S],fac[S+5],inv[S+5],id[S],ans;
ll C(ll n,ll m){
	if(n<m)return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main(){
	n=read(),m=read();
	for(ll i=1;i<=m;i++)a[i]=read();
	for(ll i=1;i<1<<n;i++)siz[i]=siz[i>>1]+(i&1);
	for(ll i=0;i<n;i++)id[1<<i]=i;
	fac[0]=1;for(ll i=1;i<=S;i++)fac[i]=fac[i-1]*i%mod;
	inv[1]=1;for(ll i=2;i<=S;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inv[0]=1;for(ll i=1;i<=S;i++)inv[i]=inv[i-1]*inv[i]%mod;
	f[m+1][0]=1;
	for(ll i=m+1;i>=2;i--)for(ll sta=0;sta<1<<n;sta++)if(f[i][sta]){
		f[i-1][sta]=(f[i-1][sta]+f[i][sta])%mod;
		ll fsta=((1<<n)-1)^sta;
		for(;fsta;){
			ll x=id[fsta&(-fsta)];
			if((1<<n)-a[i-1]+1>=(sta|(1<<x)))f[i-1][sta|(1<<x)]=(f[i-1][sta|(1<<x)]+f[i][sta]*C((1<<n)-a[i-1]-sta,(1<<x)-1)%mod*fac[1<<x]%mod)%mod;
			fsta-=fsta&(-fsta);
		}
	}
	for(ll sta=0;sta<1<<n;sta++)ans=(ans+(siz[sta]&1?mod-1:1)*f[1][sta]%mod*fac[(1<<n)-1-sta]%mod*(1<<n)%mod)%mod;
	return cout<<ans,signed();
}
/*
2 1 3
4 3 2 4 6
3 0
3 3 3 4 7
16 16 5489 5490 5491 5492 5493 5494 5495 5497 18993 18995 18997 18999 19000 19001 19002 19003
*/

Measured memory_bytes: 11612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] a = new int [n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[a.length-1] - a[0]);
    }
}

Measured memory_bytes: 21972