akhauriyash/Code-Regression huggingface dataset:
S = input()

S = S[::-1]

L = ['dream', 'dreamer', 'erase', 'eraser']
L = [l[::-1] for l in L]

can = True
ind = 0
S_max = len(S)

while can:
    
    # print(ind)
    if ind == S_max:
        break

    for l in L:
        if ind + len(l) > S_max:
            pass
        else:
    #        print(S[ind: ind+len(l)])
            if l == S[ind: ind+len(l)]:
                ind += len(l)
    #             print(1)
                break
    else:
    #     print(2)
        can = False

if can:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100010];
int partition(int p,int r){
	int x = a[r];
	int i = p-1;
	for(int j=p;j<r;j++){
		if(a[j]<=x){
			i++;
			swap(a[i],a[j]);
		}
	}swap(a[i+1],a[r]);
	return i+1;
}
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}int q = partition(0,n-1);
	for(int i=0;i<n;i++){
		if(i) cout<<' ';
		if(i==q) cout<<"[";
		cout<<a[i];
		if(i==q) cout<<"]";
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3476
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		char[][] grid = new char[h+2][w+2];
		for(int i=0; i<h; i++){
			s[i] = sc.next();
			for(int j=0; j<w; j++){
				grid[i+1][j+1] = s[i].charAt(j);
			}
		}
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				int count = 0;
				if(grid[i][j]=='#')System.out.print("#");
				else{
					if(grid[i+1][j+1]=='#')count++;
					if(grid[i+1][j]=='#')count++;
					if(grid[i+1][j-1]=='#')count++;
					if(grid[i][j+1]=='#')count++;
					if(grid[i][j-1]=='#')count++;
					if(grid[i-1][j+1]=='#')count++;
					if(grid[i-1][j]=='#')count++;
					if(grid[i-1][j-1]=='#')count++;
					System.out.print(count);
				}
			}
		System.out.println("");
		}
	}
}

Measured memory_bytes: 24148
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100005
 
using namespace std;

const int INF = 1e9 + 5;

void solve() {
	int n, W;
	sc(n); sc(W);

	vec<ll> dp(W + 1, 0);

	for(int item = 0; item < n; ++item) {
		int weight, value;
		cin >> weight >> value;

		for(int i = W; i >= weight; --i) {
			dp[i] = max(dp[i], dp[i - weight] + value);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) << el;
}



int main() {
    int ccc = 1;
    // sc(ccc);
    while(ccc--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int i=11,count=0,primecount;
  while(i<55555){
    primecount=0;
    for(int m=2;m<i/2;++m){
      if(i%m==0){
        primecount++;
      }
    }
    if(primecount==0){
    cout<<i<<" ";
    count++;
    }
    i+=30;
    if(count==n) break;
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }

// U,R,D,L
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
string Q;
bool rec(pii n,int d,int cnt,vector<vector<char>>& masu){
    if(cnt == 0){
        return true;
    }
    for(int k = -1; k <= 1; k++){
        int nk = (d+k+4)%4;
        
        int nx,ny; tie(nx,ny) = n;
        bool find = false;
        while(true){
            nx += dx[nk];
            ny += dy[nk];
            if(masu[nx][ny] == '#') break;
            if(masu[nx][ny] == 'o'){
                find = true;
                break;
            }
        }
        if(find){
            masu[nx][ny] = '.';
            Q.push_back(nk==0?'U':nk==1?'R':nk==2?'D':'L');
            if(rec(pii(nx,ny),nk,cnt-1,masu)) return true;
            Q.pop_back();
            masu[nx][ny] = 'o';
        }
    }
    return false;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll H,W; cin >> H >> W;
    vector<vector<char>> masu(H+2,vector<char>(W+2,'#'));
    pii S;
    int dir = 0;
    int cnt = 0;
    for(int i = 1; i <= H;i++) for(int j = 1; j <= W;j++){
        cin >> masu[i][j];
        if(masu[i][j] == 'U'){
            S = {i,j};
            dir = 0;
            masu[i][j] = '.';
        }
        if(masu[i][j] == 'R'){
            S = {i,j};
            dir = 1;
            masu[i][j] = '.';
        }
        if(masu[i][j] == 'D'){
            S = {i,j};
            dir = 2;
            masu[i][j] = '.';
        }
        if(masu[i][j] == 'L'){
            S = {i,j};
            dir = 3;
            masu[i][j] = '.';
        }
        cnt += masu[i][j] == 'o';
    }
    rec(S,dir,cnt,masu);
    cout << Q << endl;
    return 0;
}



Measured memory_bytes: 3236
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
    int n,p,ans;
    while(1){
        cin>>n>>p;
        if(n==0&&p==0)break;
        int a[50]={};
        int jud=0;
        while(1){
            for (int i = 0; i < n; i++) {
                if(p>0){
                    p--;
                    a[i]++;
                }else if(p==0){
                    p+=a[i];
                    a[i]=0;
                }
                jud=0;
                for (int ji = 0; ji < n; ji++) {
                    if(a[ji]!=0)jud=1;
                }

                if(jud==0){
                    ans=i;
                    break;
                }
            }
            if(jud==0)break;
        }
        cout<<ans<<"\n";

    }
    
    
    return 0;
}


Measured memory_bytes: 3088
def main():
    _ = input()
    aa = sorted(map(int, input().split()))

    cost_min = 1 << 30
    for x in range(aa[0], aa[-1] + 1):
        cost_min = min(cost_min, sum((x - a) ** 2 for a in aa))

    print(cost_min)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;
class Mod{
    static final long MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long adds(long... ar){
        long ans=0;
        for(long x:ar) ans = Mod.add(ans, x);
        return ans;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long mults(long... ar){
        long ans=1;
        for(long x:ar) ans = Mod.mult(ans, x);
        return ans;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(int n, int r){
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[n], mult(factInv[r],factInv[n-r]));
    }
    public static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        return (a/gcd(a,b))*b;
    }

}
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        long[] mod13 = new long[]{1,0,0,0,0,0,0,0,0,0,0,0,0};
        for(int d=0; d<S.length(); d++){
            char dig = S.charAt(d);
            long[] next = new long[13];
            switch (dig){
                case '?':
                    for(int i=0; i<13; i++){
                        for(int q=0; q<=9; q++){
                            next[(10*i+q)%13] = Mod.add(next[(10*i+q)%13], mod13[i]);
                        }
                    }
                    break;
                default:
                    for(int i=0; i<13; i++){
                        int q = dig - '0';
                        next[(10*i+q)%13] = Mod.add(next[(10*i+q)%13], mod13[i]);
                    }
            }
            mod13 = next;
        }
        System.out.println(mod13[5]);
    }
}

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

int main(){
    int n;
    //n = 1e5;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n)   cin >> b[i];

    //rep(i, n+1) a[i] = 1e9;
    //rep(i, n)   b[i] = 1e9;

    ll ans = 0;

    for(int i=0;i<n;i++){
        ll left = min(b[i], a[i]);
        b[i] -= left;
        ans += left;

        ll right = min(b[i], a[i+1]);
        a[i+1] -= right;
        ans += right;
    }

    cout << ans << endl;
    //cout << "100000000000000";


    return 0;
}

Measured memory_bytes: 1792
fun main() {
    abc129c()
}

fun abc129c() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val step = LongArray(n + 1) { 0L }
    repeat(m) {
        val i = readLine()!!.toInt()
        step[i] = -1L
    }
    step[0] = 1
    for (i in 1..n) {
        if (step[i] == -1L) continue
        val one = step[i - 1]
        val two = if (i > 1) step[i - 2] else 0L
        var s = 0L
        if (one != -1L) s += one
        if (two != -1L) s += two
        step[i] = s % 1_000_000_007L
    }
    println(step[n].coerceAtLeast(0L))
}


Measured memory_bytes: 58776
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int Inf = 1e9;
const double EPS = 1e-9;



int main()
{
  int d, n ;
  cin >> d >> n ;
  int count = 0 ;
  
  if(d==0){
    int i = 0 ;
    while(true){
      if(i%100!=0){
        i++ ;
        count++ ;
      }
      else{
        i++ ;
      }
      if(count==n){
        cout << i-1 <<endl ;
        return 0 ;
      }
    }
  }
    if(d==1){
    int i = 0 ;
    while(true){
      if(i%10000!=0 && i%100==0){
        i++ ;
        count++ ;
      }
      else{
        i++ ;
      }
      if(count==n){
        cout << i-1 <<endl ;
        return 0 ;
      }
    }
  }
    if(d==2){
    int i = 0 ;
    while(true){
      if(i%1000000!=0 && i%10000==0){
        i++ ;
        count++ ;
      }
      else{
        i++ ;
      }
      if(count==n){
        cout << i-1 <<endl ;
        return 0 ;
      }
    }
  }
  
}




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

dp = [0]*n

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    a = dp[i-1] + abs(h[i]-h[i-1])
    b = dp[i-2] + abs(h[i]-h[i-2])
    dp[i] = min(a,b)

# print(dp)
print(dp[n-1])

Measured memory_bytes: 13980
# Wrote in Mar 5, 2020 21:48 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".to_i")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end

#---------------

n = gets.to_i
s = gets.to_s

puts s.scan('ABC').length

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

int main(){
	ios::sync_with_stdio(0); 
	cin.tie(0);
	
	ll a,b,c,k;
	
	cin>>a>>b>>c>>k;
	
	ll co = 0;
	while(k--){
		
		if(a>0){
		  co++;
		  a--;
		}
		
		else if(b>0){
			co+=0;
			b--;}
			else if(c>0){
			co--;
			c--;}
			
			//cout<<k<<endl;
		
	}
	
	cout<<co<<endl;
	
	
   
}



Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int sum = y+x;
		int cun = 0;


		System.out.println(sum+1-gcd(x,y));
	}
	private static long gcd(long m, long n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
}



Measured memory_bytes: 26372
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vl p,q,r;
    vector <pair<ll,ll>> v;
    rep(i,a)
    {
        ll c;
        cin>>c;
        p.pb(c);
        v.pb(mp(c,1));
    }
    rep(i,b)
    {
        ll c;
        cin>>c;
        q.pb(c);
        v.pb(mp(c,2));
    }
    rep(i,c)
    {
        ll x;
        cin>>x;
        r.pb(x);
        v.pb(mp(x,0));
    }
    sort(all(v));
    reverse(all(v));
    ll green=0,red=0,extra=0,ans=0;
    for(int i=0;i<v.size();i++)
    {
        auto it=v[i];
        if((green+red+extra)==(x+y))
            break;
        if(it.second==1)
        {
            if(red<x)
            {
                red++;
                ans+=(it.first);
            }
        }
        else if(it.second==2)
        {
            if(green<y)
            {
                green++;
                ans+=(it.first);
            }
        }
        else
        {
            extra++;
            ans+=(it.first);
        }
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

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

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

    long long int ans = 0;
    for(int i=1; i<n; i++){
        ans += min((x[i] - x[i-1]) * a, b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();

        var f1 = s[0] == 'A';
        s[0] = 'a';

        var f2 = 0;
        var i = 2;
        for (; i <= s.Length - 2; i++)
        {
            if (s[i] == 'C')
            {
                s[i] = 'c';
                f2++;
            }
        }

        var f3 = true;
        for (int j = 0; j < s.Length; j++)
        {
            f3 &= char.IsLower(s[j]);
        }

        Console.WriteLine(f1 && f2 == 1 && f3 ? "AC" : "WA");
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   int cnt=0;
   for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
         if(i%2==0 && j%2!=0) cnt++;
      }
   }

   cout << cnt << endl;



   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long long int f(long long int a)
{
	return a * a * a * a * a;
}
int main()
{
	long long int x;
	scanf("%lld", &x);
	long long int a, d;
	for (d = 1; d * d <= x; d++)
	{
		if (x % d == 0)
		{
			a = 0;
			while (f(a + d) - f(a) < x)
				a++;
			if (f(a + d) - f(a) == x)
			{
				printf("%lld %lld\n", a + d, a);
				return 0;
			}
			d = x / d;
			a = 0;
			while (f(a + d) - f(a) < x)
				a++;
			if (f(a + d) - f(a) == x)
			{
				printf("%lld %lld\n", a + d, a);
				return 0;
			}
			d = x / d;
		}
	}
	x *= -1;
	for (d = 1; d * d <= -1 * x; d++)
	{
		if (x % d == 0)
		{
			a = 0;
			while (f(a - d) - f(a) < x)
				a++;
			if (f(a - d) - f(a) == x)
			{
				printf("%lld %lld\n", -a + d, -a);
				return 0;
			}
			d = x / d;
			a = 0;
			while (f(a - d) - f(a) < x)
				a++;
			if (f(a - d) - f(a) == x)
			{
				printf("%lld %lld\n", -a + d, -a);
				return 0;
			}
			d = x / d;
		}
	}
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  int s1, s2, s3;
  
  cin >> s;
  s1 = (s - (s % 100)) / 100;
  s2 = ((s % 100) - (s % 100) % 10) / 10;
  s3 = (s % 100) % 10;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int i = 0;
	int j = n - 1;
	while (i < n and s[i] == 'R') i++;
	while (j >= 0 and s[j] == 'W') j--;

	int wCnt = 0, rCnt = 0;

	for (int k = i; k <= j; k++) {
		s[k] == 'R' ? rCnt++ : wCnt++;
	}

	int ans = min(wCnt, rCnt);

	int nrCnt = 0, nwCnt = 0;

	for (int k = i; k < j; k++) {
		s[k] == 'R' ? nrCnt++ : nwCnt++;
		// cur = extra whites till now + extra r's after replacement
		int cur = nwCnt + rCnt - nrCnt - min(nwCnt, rCnt - nrCnt);
		// dbg(k, cur);
		ans = min(ans, cur);
	}

	cout << ans << endl;


}

// you should probably see down .. believe me it would help
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

// COME ON DUDE .... GIVING UP NOT GONNA HELP
// JUST GET YOUR ASS TO WORK ALREADY ..
// AND FOR FUCKING SAKE ... DONT PANIC !!


Measured memory_bytes: 3780
#include<stdio.h>

int solve(int i, int m, int A[],int n){
	if(m==0){
		return 1;
	}
	if(i>=n){
		return 0;
	}
	
	int res;
	
	res=solve(i+1, m, A, n)||solve(i+1,m-A[i], A, n);
	
	return res;
}

int main(void){
	int n1,n2;
	int A[50];
	int M;
	
	scanf("%d",&n1);
	for(int i=0;i<n1;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&n2);
	for(int i=0;i<n2;i++){
		scanf("%d",&M);
		if(solve(0,M,A,n1)){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 2068
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD

        ll ans=0;
        ll n;
        cin>>n;
        ll a[n];
        ll co=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]<0)
            co++;
            if(a[i]<0)
            a[i]*=-1;
            
        }
        sort(a,a+n);
        if(co%2==0)
        {
            for(int i=0;i<n;i++)
            {
                ans+=abs(a[i]);
            }
        }
        else
        {
            for(int i=1;i<n;i++)
            {
                ans+=abs(a[i]);
            }
            ans-=abs(a[0]);
        }
        cout<<ans;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; 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(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    string s,t; cin >> s >> t;
    int n = s.length();
    vector<int> cs(26,-1);
    vector<int> ct(26,-1);
    bool ans = true;
    REP(i,n) {
        if(cs[s[i]-97]<0) cs[s[i]-97] = t[i]-97;
        else {
            if(cs[s[i]-97] != t[i]-97) {
                ans = false;
                break;
            }
        }
        if(ct[t[i]-97]<0) ct[t[i]-97] = s[i]-97;
        else {
            if(ct[t[i]-97] != s[i]-97) {
                ans = false;
                break;
            }
        }
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 776
parseInt(x) = parse(Int, x)

function main()
	n,m = map(parseInt, split(readline()))
	x = map(parseInt, split(readline()))
	y = map(parseInt, split(readline()))
	sx = 0
	sy = 0
	for k in 1:n
		sx += ((k-1)*x[k] - (n-k)*x[k])%1000000007
	end
    for k in 1:m
		sy += ((k-1)*y[k] - (m-k)*y[k])%1000000007
    end
	println((sx%1000000007)*(sy%1000000007)%1000000007)
end

main()

Measured memory_bytes: 151740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>]
#include <map>
#include <math.h>
#include <set>
using namespace std;

int main(){
    string a,b;cin>>a>>b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
/*vector<int> fac; //precompute fac array
// fac.resize(n+1);
// fac[0] = 1; 
// for (int i=1; i<=n; i++)   fac[i] = m(m(fac[i-1])*m(i));
int modInverse(int n){ 
return p(n, MOD-2); 
}  
int nCrModPFermat(int n, int r){   
    if(r == 0)  return 1; 
    return m(m(m(fac[n])*m(modInverse(fac[r])))*m(modInverse(fac[n-r]))); 
} 
*/
signed main(){
    fast();
    ld a, b, h, ma;
    cin >> a >> b >> h >> ma;
    ld pi = acos(-1.0);
    h += 1.0*ma/60;
    h *= 30;
    ma *= 6;
    ld angle = abs(h-ma);
    // if(angle > 180) angle = 360-angle;
    angle *= pi/180;
    ld ans = sqrt(a*a+b*b-2*a*b*cos(angle));
    printf("%.12LF\n", ans);
}

Measured memory_bytes: 4176
N,*as=$<.read.split.map(&:to_i)

as = ([0]+as+[0])

sum = 0
as.each_cons(2) do |a,b|
    sum += (a-b).abs
end

1.upto(as.length-2) do |i|
    puts sum - (as[i-1]-as[i]).abs - (as[i]-as[i+1]).abs + (as[i-1]-as[i+1]).abs
end

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

int n, l, r;

bool check(int x, int *a){
    int i;
    for(i = 0; i < n; i++)  if(x % a[i] == 0)  break;
    if(i != n){
        return i%2 == 0;
    }else{
        return n%2 == 0;
    }
}

int main(){
    while(cin >> n >> l >> r, n+l+r){
        int a[n];
        for(int i = 0; i < n; i++)  cin >> a[i];
        int cnt = 0;
        for(int x = l; x <= r; x++) if(check(x, a)) cnt++;
        cout << cnt << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	int i = 0;
	for (; n; n /= 2) {
		if (n % 2) {
			if (i % 2) n += 1;
			else n -= 1;
			s = string("1") + s;
		}
		else s = string("0") + s;
		i++;
	}
	cout << (s.empty() ? "0" : s) << endl;
	return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<double, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class DirectedGraph {
    struct edge {
        int to;
        double cost;
    };

public:
    int V;
    vector<vector<edge>> G;

    DirectedGraph(int v) : G(v), V(v) {}

    void add_edge(int u, int v, double cost) {
        G[u].push_back({v, cost});
    }

    // O(E * logV)
    vector<double> dijkstra(int s) {
        vector<double> d(V, INF);
        d[s] = 0;

        priority_queue<P, vector<P>, greater<>> que;
        que.push({0.0, s});

        while (!que.empty()) {
            P  p = que.top(); que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;

            for (edge e : G[v]) {
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push({d[e.to], e.to});
                }
            }
        }

        return move(d);
    }
};

signed main() {
    int xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;

    int n;
    cin >> n;

    int x[n+2];
    int y[n+2];
    int r[n+2];
    x[0] = xs;
    y[0] = ys;
    x[n+1] = xt;
    y[n+1] = yt;
    r[0] = 0;
    r[n+1] = 0;

    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i] >> r[i];
    }

    DirectedGraph g = DirectedGraph(n+2);

    for (int i = 0; i < n + 2; i++) {
        for (int j = 0; j < n + 2; j++) {
            if (i == j) continue;
            double cost = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) - (r[i] + r[j]);
            if (cost < 0) cost = 0;
            g.add_edge(i, j, cost);
            g.add_edge(j, i, cost);
        }
    }

    vector<double> dis = g.dijkstra(0);
    cout << fixed << setprecision(10) << dis[n+1] << endl;

    return 0;
}

Measured memory_bytes: 38384
N,K = map(int,input().split())
S =  input()
max_happiness = len(S)-1

L_cnt = S.count('L')
R_cnt = S.count('R')

new_S = S.replace('LR','L,R').replace('RL','R,L')
split_S = new_S.split(',')

happiness = max_happiness - new_S.count(',')

happiness = happiness + K*2

print(min(happiness,max_happiness))

Measured memory_bytes: 5236
#include<stdio.h>
const int maxn = 100;
typedef long long LL;
int mp[36];
char a[105];
int vis[28];
int main(){
	int n;
	scanf("%d",&n);
	getchar();
	gets(a);
	int ans = 0,pos = 0;
	for(int i = 0;i<n;i++){
		mp[a[i]-'a']++;
		pos = 0;
		for(int k = 0;k<28;k++)
			vis[k] = 0;
		for(int j = i+1;j<n;j++){
			if(vis[a[j]-'a']) continue;
			if(mp[a[j]-'a']) {
				vis[a[j]-'a'] = 1;
				pos++;
			}
		}
		if(pos > ans) ans = pos;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int A, B, C; cin >> A >> B >> C;

    string ans = A+B>=C ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
// 整数の入力
fscanf(STDIN, "%d", $n);

$hund = floor($n / 100);
$ten = floor(($n % 100)/10);
$one = floor($n % 10);


if ($hund == 1) {
  $hund = 9;
} else {
  $hund = 1;
}
if ($ten == 1) {
  $ten = 9;
} else {
  $ten = 1;
}
if ($one == 1) {
  $one = 9;
} else {
  $one = 1;
}


echo 100 * $hund + 10 * $ten + $one;

?>

Measured memory_bytes: 3828
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(long long*)a - *(long long*)b;
}

int min_comp(int min, int a)
{

}
int max_comp(int max, int a)
{
  if(max>a)    return max;
  else    return a;
}


int main()
{
  //int A, B, C, X, Y;
//  int m[101]={};
  long long min=0;
  long long A, B;
  long long x[100001]={};
  long long v[100001]={};
  int i,j;
  long long cnt=0;
  long long max=0;
  long long ca=0;
  long long point_a=0;
  long long point_b=0;
  
//    int k=0;

  scanf("%lld %lld", &A ,&B);
  //printf("%d\n", A);
 if(A<=B)  max = A; 
 else  max = A -1;
//    printf("%lld\n", max); 
  
  
  
  
  printf("%lld\n", max); 
return 0;
}


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

const i64 mod = 1e9+7;

int main(){
    i64 n,ans=0,a=1,b=1,c=1;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    for(i64 i=0;i<n;i++){
        a *=  10;
        b *= 9;
        c *= 8;
        a %= mod;
        b %= mod;
        c %= mod;
    }
    i64 d = b*2-c;
    d = (mod + d)%mod;
    ans = (a-d+mod)%mod;
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int x = a + b;
    int y = c + d;
    if (x > y) cout << "Left" << endl;
    else if (x == y) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}

Measured memory_bytes: 256
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
for i in range(N):
    if i == N-1:
        if x == a[i]:
            ans += 1
        break
    if x - a[i] >= 0:
        x -= a[i]
        ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  long double pi = 3.141592653589793238;
  long double Lx,Ly,Sx,Sy;
  Lx=A*sin(2.0*pi/12.0*(H+M/60.0));
  Ly=A*cos(2.0*pi/12.0*(H+M/60.0));
  Sx=B*sin(2.0*pi/60.0*M);
  Sy=B*cos(2.0*pi/60.0*M);
  //cout << (Lx-Sx)*(Lx-Sx)+(Ly-Sy)*(Ly-Sy)<<endl;
  cout << fixed << setprecision(20)<<sqrt((Lx-Sx)*(Lx-Sx)+(Ly-Sy)*(Ly-Sy)) << endl;
  return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int main()
{
  fastio;
  int n, r;
  cin >> n >> r;
  cout << r + max(0, 10 - n) * 100;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second

char s[105];
int n,k;
LL dp[105][4][2];

LL f( int i, int k, int u ){
	if ( i == 0 ){
		return k == 0;
	}
	LL &ans = dp[i][k][u];
	if ( ans != -1 ) return ans;
	ans = 0;

	if ( u && s[n-i] == '0' ) ans += f(i-1,k,1);
	else ans += f(i-1,k,0);

	if ( k == 0 ) return ans;
	for ( int j = 1; j <= 9; j++ ){
		if ( u && s[n-i]-'0' < j ){
			continue;
		}
		if ( u && s[n-i]-'0' == j ){
			ans += f(i-1,k-1,1);
		} else {
			ans += f(i-1,k-1,0);
		}
	}
	return ans;
}

int main(){

	scanf("%s",&s);
	scanf("%d",&k);
	n = strlen(s);
	memset(dp,-1,sizeof(dp));

	LL ans = 0;
	for ( int i = 1; i <= n; i++ ){
		if ( i == n ){
			for ( int j = 1; j <= 9; j++ ){
				if ( s[0]-'0' == j ){
					ans += f(i-1,k-1,1);
					break;
				}
				ans += f(i-1,k-1,0);
			}
		} else {
			for ( int j = 1; j <= 9; j++ ){
				ans += f(i-1,k-1,0);
			}
		}
		// printf("%d %lld\n",i,ans);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    vector<pair<ll, ll>> cnt(n, {0, 0}), a, b;
    rep(i, n)cin >> s[i];
    rep(i, n){
        rep(j, s[i].size()){
            if(s[i][j] == '(')cnt[i].first++;
            else{
                if(cnt[i].first)cnt[i].first--;
                else cnt[i].second++;
            }
        }
    }
    ll now1 = 0, now2 = 0;
    rep(i, n)if(!cnt[i].second)now1 += cnt[i].first;
    rep(i, n)if(!cnt[i].first)now2 += cnt[i].second;
    rep(i, n){
        ll f = cnt[i].first, s = cnt[i].second;
        if(f && s){
            if(f >= s)a.push_back({s, f-s});
            else b.push_back({f, s-f});
        }
    }
    sort(all(a));
    sort(all(b));
    rep(i, a.size()){
        if(now1 - a[i].first < 0){cout << "No" << endl; return 0;}
        now1 += a[i].second;
    }
    rep(i, b.size()){
        if(now2 - b[i].first < 0){cout << "No" << endl; return 0;}
        now2 += b[i].second;
    }
    cout << (now1 == now2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 50084
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int digit(int num)
{
    int dig;
    int sum = 0;
    while(num){
        dig = num % 10;
        sum = sum + dig;
        num = num / 10;
    }
    return sum;
}


int atcoder(){
    //入力
    int n;
    cin >> n;
    //処理
    //出力
    if(n%digit(n)==0) cout << "Yes" << ENT;
    else cout << "No" << ENT;
    return 0;
}

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


Measured memory_bytes: 256
import Data.List
main=interact $ show.minimum.f.map read.words.head.tail.lines
f::[Int]->[Int]
f x = map (g x) [-100..100]
g::[Int]->Int->Int
g x y = sum $ map (h y) x
h::Int->Int->Int
h y a = (y-a)^2

Measured memory_bytes: 1020
#include<iostream>
#include<vector>

struct fast_input{
  #if local
    static constexpr int input_max = 1e2;
  #else
    static constexpr int input_max = 1e7;
  #endif
  char buf[input_max];
  char* itr;
  fast_input(){fread(buf,1,input_max,stdin);itr=buf;}
  constexpr inline bool isdigit(char* ptr)const noexcept{
    return '0' <= *ptr and *ptr <= '9';
  }
  constexpr inline uint32_t operator()(){
    while(!isdigit(itr))itr++;
    uint32_t num{};
    while(isdigit(itr)){
      num *= 10;
      num += *itr-'0';
      itr++;
    }
    return num;
  }
}in;

struct fast_output{
  #if local
    static constexpr int output_max = 1e2;
  #else
    static constexpr int output_max = 1e7;
  #endif
  char buf[output_max];
  char* itr;
  fast_output(){itr=buf;}
  ~fast_output(){fwrite(buf,1,itr-buf,stdout);}
  void newl(){*itr++='\n';}
  void putc(char c){*itr++=c;}
  void operator()(uint32_t num){
    if(num==0){*itr++='0';return;}
    char tmp[33];
    int i{};
    while(num){
      tmp[i++] = num%10+'0';
      num /=10;
    }
    while(i--)*itr++=tmp[i];
  }
  void newl(uint32_t num){
    this->operator()(num);
    *itr++='\n';
  }
}out;

#include<atcoder/dsu>
using atcoder::dsu;
 
int main(){
 
  int n{in()},q{in()};
  dsu uni(n);
  while(q--){
    int t{in()};
    if(t)out.newl(uni.same(in(),in()));
    else uni.merge(in(),in());
  }
 
}

Measured memory_bytes: 6428
import java.util.*
import kotlin.collections.HashSet

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val s = HashSet<Int>()

    for(i in 0 until k) {
        val d = sc.nextInt()
        for(j in 0 until d) {
            s.add(sc.nextInt())
        }
    }

    print(n - s.size)


}

Measured memory_bytes: 46856
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
 
#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;
#define alog(a, n)                  for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 
const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

int di1, di2;
int n;


int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int s = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> di1 >> di2;
        s += (di1 == di2 ? 1 : -s);
        if(s == 3)
            return cout << "Yes" << endl, 0;
    }
    cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3656
/*
 * 降参
 * 解説を見て
 */
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <limits>
#include <cmath>
#include <map>

using namespace std;

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

  vector<int> ls;
  for (int i = 0; i < n; i++) {
    cin >> l;
    ls.emplace_back(l);
  }

  sort(ls.begin(), ls.end());

  long long int result = 0;
  for (auto i1 = ls.begin(); i1 < ls.end(); i1++) {
    for (auto i2 = i1 + 1; i2 < ls.end(); i2++) {
      auto i3 = lower_bound(i2 + 1, ls.end(), *i1 + *i2);
      result += distance(i2 + 1, i3);
    }
  }

  cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  bool chk = false;
  if(s.length() < t.length()){
    bool flg = true;
    for(int i = 0; i < s.length(); i++){
      if(s[i] != t[i]) {
        flg = false;
        break;
      }
    }
    if(flg) chk = true;
  }
  for(int i = 0; i < min(s.length(), t.length()); i++){
    if(s[i] == t[i])
      continue;
    else if(s[i] > t[i])
      break;
    else{
      chk = true;
      break;
    }      
  }
  if(chk)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    x, a, b = list(map(int, readline().split()))
    if b - a <= 0:
        print("delicious")
    elif b - a < x + 1:
        print("safe")
    else:
        print("dangerous")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
import java.util.Scanner

object Main {
  def main(args:Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val data = sc.nextLine().split(" ")

    if (data(1) == "+") {
      println(data(0).toInt + data(2).toInt)
    } else if (data(1) == "-") {
      println(data(0).toInt - data(2).toInt)
    }
  }
}

Measured memory_bytes: 27312
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    vector<int> x(5);
    int a;
    for(int i=0; i<5; i++){
        cin >> x[i];
        if(x[i] == 0) a = i+1;
    }
    cout << a << endl;
    return 0;
}

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

int main() {
    string stra;
    cin >> stra;
    for(int i=0;i<5;i++){
        cout << stra[i];
    }
    cout << " ";
    for(int i=6;i<13;i++){
        cout << stra[i];
    }
    cout << " ";
    for(int i=14;i<=18;i++){
        cout << stra[i];
    }
    cout << endl;

}

Measured memory_bytes: 3532
#include<iostream>
using namespace std;
int a[100005]={0};
int main(){
    int t;
    cin>>t;
    int cnt=0;
    for(int i=1;i<=t;i++){
        int q;
        cin>>q;
        a[q]++;
        if(a[q]>1) cnt++;
    }
    int ans=0;
    if(cnt%2==0) ans=t-cnt;
    else if(cnt%2==1) ans=t-cnt-1;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
def solve():
    flag = True
    N = int(input())
    schedules = []
    for _ in range(N):
        a,b = input().split(' ')
        schedules.append((int(a),(int(b))))
        
    s_s = sorted(schedules, key=lambda x:x[1])
    time = 0
    for s,limit in s_s:
        time += s;
        if(time > limit): 
            flag = False
            break
    if flag:
        print('Yes')
    else:
        print('No')

solve()

Measured memory_bytes: 33396
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  
  int s = 0;
  for (int i = 0; i < N - 1; i++) {
    s += L[i];
  }
  
  if (L[N - 1] < s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

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

//1-index
template<typename T>
struct BIT{
private:
  vector<T> A;
  const int n;
  
public:
  BIT(int _n) : A(_n+1,0), n(_n){}
  
  //i番目までの累積和
  T sum(int i){
    T s=0;
    while(i>0){
      s+=A[i];
      i-=i&-i;
    }
    return s;
  }
  
  //[i,j]の要素の総和
  T sum(int i,int j){
    return sum(j)-sum(i-1);
  }
  
  //i番目にxを代入
  void add(int i,T x){
    while(i<=n){
      A[i]+=x;
      i+=i&-i;
    }
  } 
};

int main(){
  int n,q;
  cin>>n>>q;
  
  ll c,x,y;
  BIT<ll> bit(n);
  
  rep(i,n){
    cin>>c;
    bit.add(i+1,c);
  }
  
  rep(i,q){
    cin>>c>>x>>y;
    if(c==0) bit.add(x+1,y);
    else cout<<bit.sum(x+1,y)<<endl;
  }
   
  return 0;
}

Measured memory_bytes: 8212
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
struct Edge{
	int to,next;
}e[MAXN];
int head[MAXN],n,cnt,rk[MAXN];
inline void insert(int u,int v)
{
	e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
}
void dfs(int x)
{
	vector<int>t;
	for(int i=head[x];i;i=e[i].next){
		int v=e[i].to;
		dfs(v);
		t.push_back(rk[v]);
	}
//	cout<<x<<" "<<"Size:  "<<t.size()<<endl;
//	for(int i=0;i<t.size();++i)
//		cout<<t[i]<<" ";
//	cout<<endl;
	sort(t.begin(),t.end(),greater<int>());
	for(int i=0;i<t.size();++i)
		rk[x]=max(rk[x],i+1+t[i]);
}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i){
		int fa;
		scanf("%d",&fa);
		insert(fa,i);
	}
	dfs(1);
	cout<<rk[1]<<endl;
	return 0;
}


Measured memory_bytes: 9600