akhauriyash/Code-Regression huggingface dataset:
N,A,B,C=map(int, input().split())




S=[0]*N
for i in range(N):
    s=input()
    S[i]=s
memo=[0]*N
for i in range(N):  
    if S[i]=="AB":
        if A==0 and B==0:
            print("No")
            exit()
        if A==1 and B==1:
            if i+1<N:
                if S[i+1]=="BC" and C==0:
                    B+=1
                    A-=1
                    memo[i]="B"
                    continue
                elif S[i+1]=="AC" and C==0:
                    A+=1
                    B-=1
                    memo[i]="A"
                    continue
            A+=1
            B-=1
            memo[i]="A"
        elif A>B:
            A-=1
            B+=1
            memo[i]="B"
        elif B>A:
            A+=1
            B-=1
            memo[i]="A"
        else:
            A+=1
            B-=1
            memo[i]="A"



    if S[i]=="AC":
        if A==0 and C==0:
            print("No")
            exit()
        if A==1 and C==1:
            if i+1<N:
                if S[i+1]=="BC" and B==0:
                    C+=1
                    A-=1
                    memo[i]="C"
                    continue
                elif S[i+1]=="AB" and B==0:
                    A+=1
                    C-=1
                    memo[i]="A"
                    continue
            A+=1
            C-=1
            memo[i]="A"
        elif A>C:
            A-=1
            C+=1
            memo[i]="C"
        elif C>A:
            A+=1
            C-=1
            memo[i]="A"
        else:
            A+=1
            C-=1
            memo[i]="A"

    if S[i]=="BC":
        if C==0 and B==0:
            print("No")
            exit()
        if B==1 and C==1:
            if i+1<N:
                if S[i+1]=="AC" and A==0:
                    C+=1
                    B-=1
                    memo[i]="C"
                    continue
                elif S[i+1]=="AB" and A==0:
                    B+=1
                    C-=1
                    memo[i]="B"
                    continue
            B+=1
            C-=1
            memo[i]="B"
        elif B>C:
            B-=1
            C+=1
            memo[i]="C"
        elif C>B:
            B+=1
            C-=1
            memo[i]="B"
        else:
            B+=1
            C-=1
            memo[i]="B"

print("Yes")
for a in memo:
    print(a)

Measured memory_bytes: 17084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	V<string> s = {"Sunny","Cloudy","Rainy"};
	s.pb(s[0]);
	string a; cin >> a;
	rep(i,3) if(s[i] == a){
		cout << s[i+1] << endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

const int N = 105;

int link[N];
bool mp[N][N];
bool vis[N];

struct node
{
	int x,y;
} red[N],blue[N];

bool dfs(int u,int n)
{
	for (int i = 0;i < n;i++)
	{
		if (mp[u][i] && !vis[i])
		{
			vis[i] = 1;
			
			if (link[i] == -1 || dfs(link[i],n))
			{
				link[i] = u;
				return true;
			}
		}
	}
	
	return false;
}

int solve(int n)
{
	int ans = 0;
	
	for (int i = 0;i < n;i++)
	{
		memset(vis,0,sizeof(vis));
		if (dfs(i,n)) ans++;
	}
	
	return ans;
}

int main()
{
	int n;
	
	scanf("%d",&n);
	
	memset(link,-1,sizeof(link));
	
	for (int i = 0;i < n;i++)
	{
		scanf("%d%d",&red[i].x,&red[i].y);
	}
	
	for (int i = 0;i < n;i++)
	{
		scanf("%d%d",&blue[i].x,&blue[i].y);
	}
	
	for (int i = 0;i < n;i++)
	{
		for (int j = 0;j < n;j++)
		{
			if (red[i].x < blue[j].x && red[i].y < blue[j].y)
			{
				mp[i][j] = 1;
			}
		}
	}
	
	int ans = solve(n);
	
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
MOD = 10**9+7
n, m = map(int, input().split())
a = set([int(input()) for _ in range(m)])

ans = [0]*(n+1)
ans[0] = 1
ans[1] = 1 if not 1 in a else 0
for i in range(2, n+1):
    if i not in a:
        ans[i] = (ans[i-2] + ans[i-1])%MOD
print(ans[-1])


Measured memory_bytes: 13192
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, m;cin>>n>>m;
  rep(i, m){
    int a;cin>>a;
    n -= a;
  }
  if(n<0)cout<<-1<<endl;
  else cout<<n<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  int ans=0;
  if(N%2==0){
    ans+=N/10;
    int K=5;
    while(N>=K*10){
      int k=K*10;
      ans+=N/k;
      K*=5;
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

int getCost(pair<int, int> p1, pair<int, int> p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int main()
{
	int h, w, d;
	cin >> h >> w >> d;
	vector<pair<int, int> > place(h * w);
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			int a;
			cin >> a;
			a--;
			place[a] = make_pair(i, j);
		}
	}
	vector<vector<int> > cost(d, vector<int>());
	for(int i = 0; i < h * w; i++){
		if(cost[i % d].size() == 0){
			cost[i % d].push_back(0);
		} else {
			pair<int, int> nowPlace = place[i];
			pair<int, int> prevPlace = place[i - d];
			int prevCost = cost[i % d][cost[i % d].size() - 1];
			cost[i % d].push_back(prevCost + getCost(prevPlace, nowPlace));
		}
		// cout << i << " " << cost[i % d][i / d] << endl;
	}

	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		cout << cost[r % d][r / d] - cost[l % d][l / d] << endl;
	}

}

Measured memory_bytes: 6016
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc172
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc172A();
            Console.Out.Flush();
        }

        public static void solve_abc172B()
        {
        }

        public static void solve_abc172A()
        {
            int a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3));
        }
    }
}

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

#define ll long long
#define F(i,a,b) for(ll i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))
#pragma comment(linker, "/STACK:102400000,102400000")
inline void read(int &x){x=0; char ch=getchar();while(ch<'0') ch=getchar();while(ch>='0'){x=x*10+ch-48; ch=getchar();}}

ll N,h,n,w;

int main()
{
    cin>>N;
    F(i,1,3500)F(j,1,3500)if(4*i*j-N*i-N*j>0)
    {
        if((N*i*j%(4*i*j-N*i-N*j)==0)&&(N*i*j/(4*i*j-N*i-N*j)>0))
        {
            printf("%lld %lld %lld\n",i,j,N*i*j/(4*i*j-N*i-N*j));return 0;
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n,x;cin>>n>>x;
int ans=0,yay=0;
for(int i=0;i<n;i++){
    int a;cin>>a;
    yay+=a;
if(yay<=x)ans++;

}
cout<<ans+1;

}

Measured memory_bytes: 256
import numpy as np

max_n = 12
max_m = 12
def main():
    nmx = list(map(int, input().split()))
    c = [None]*nmx[0]
    a = [None]*nmx[0]
    for i in range(nmx[0]):
        ca = list(map(int, input().split()))
        c[i] = ca[0]
        a[i] = ca[1:]

    ms = -1
    # for i in range(nmx[0]):
    #     for j in range(i, nmx[0]):


    # dp = np.zeros([nmx[0], nmx[1]], dtype=int)
    # price = np.zeros([nmx[0]], dtype=int)
    # for i in range(nmx[0]):
    #     n = [i]
    #     for j in range(i):

    #         dp[i,j] = 
    poo = []
    for i in range(nmx[0]):
        poo.append([i])
        df(nmx[0], [i], poo)
    
    for i in poo:
        score = np.zeros([nmx[1]])
        p = 0
        for j in i:
            score += np.array(a[j])
            p += c[j]
        # print(score, nmx[2], score >= nmx[2])
        if all(score >= nmx[2]) and (ms > p or ms < 0):
            ms = p

    
    print(ms)

def df(n, m, store):
    
    for i in range(m[-1], n-1):
        tmp = list(m)
        tmp.append(i+1)
        store.append(tmp)
        df(n, tmp, store)


if __name__ == '__main__':
    main()

Measured memory_bytes: 27380
import java.util.*;
import java.io.*;

class Item {
	int weight;
	long val;
	public Item(int weight, long val) {
		this.weight = weight;
		this.val = val;
	}
}
public class Main {


	public static void main(String[] args) {
		Main answer = new Main();
		System.out.println(answer.solve());
	}

	private long solve() {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxWeight = sc.nextInt();
		Item[] array = new Item[N+1];
		for(int i=1;i<=N;i++) {
			array[i] = new Item(sc.nextInt(), sc.nextLong());
		}
		//dp[i][j] = max value of in bag holding i items of maximum weight j
		// required dp[N][W]
 		long [][] dp = new long[N+1][maxWeight+1];

		dp[0][0] = 0;
		 
 		for(int w=0;w<=maxWeight;w++){
			dp[1][w]=0;
		}

		dp[1][array[1].weight] = array[1].val;
		 
  
		for(int i=2;i<=N;i++){
			for(int w=0;w<=maxWeight;w++){
				dp[i][w] = dp[i-1][w];
				if (array[i].weight<=w) dp[i][w] = Math.max(dp[i-1][w], dp[i-1][w-array[i].weight] + array[i].val);
			}
		}
		/*
		for(int i=1;i<=N;i++){
			System.out.println(Arrays.toString(dp[i]));
		}*/
		long bestValue =0;
		for(int w=0;w<=maxWeight;w++){
			bestValue = Math.max(dp[N][w], bestValue);
		}
		return bestValue;

	}

	 

	 
}

Measured memory_bytes: 137984
#include "bits/stdc++.h"
using namespace std;
template<typename T, typename S> void amax(T &a, S b){ if(a < b) a = b; }
template<typename T, typename S> void amin(T &a, S b){ if(a > b) a = b; }
#define rep(a,b,c) for(int a = b; a < c; a++)
#define per(a,b,c) for(int a = b; a > c; a--)
#define rit(it,v) for(auto &it:v)
#define mset(a, b) memset(a, b, sizeof(a))
#define mt make_tuple
#define pb push_back
using ii = pair<int,int>;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vll = vector<ll>;
const ll mod = 1000000007;
ll powm(ll a, ll b){ll ans=1;a %= mod;for(;b;b>>=1){if(b&1)ans=ans*a%mod;a = a*a%mod;}return ans;}
const int maxn = 101010;
ll cnt[maxn];
int main(){
	ll n, k; cin >> n >> k;
	rep(e, 0, n){
		ll a, b; cin >> a >> b;
		cnt[a] += b;
	}
	rep(e, 0, maxn){
		if(cnt[e] >= k)
			return cout << e << endl, 0;
		k -= cnt[e];
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    cout<<k<<endl;
    else if(k>a && k<=(b+a))
    cout<<a<<endl;
    else if(k>(b+a) && k<=(a+b+c))
    {
        int d=a;
        int x=k-(a+b);
        d-=x;
        cout<<d<<endl;
    }
    
}

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

int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	int ans = 0;
	for(int i = a; i <= b; i++)
		if(c % i == 0)
			ans++;
	printf("%d\n", ans);
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
ll a[100000];
//ll sum[100000];
int main() {
	ll N, M;
	scanf("%lld %lld", &N, &M);
	vector<ll>sum(N + 1,0);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
	}
	for (int i = 0; i < N; i++) {
		sum[i + 1] = (sum[i] + a[i])%M;
	}
	unordered_map<ll, ll>u_mp;
	for (int i = 0; i < N + 1; i++) {
		u_mp[sum[i]]++;
	}
	ll ans = 0;
	for (auto e : u_mp) {
		ans += e.second*(e.second - 1) / 2;
	}
	cout << ans << endl;
}


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

//const double PI = acos(-1.0); 

void solve();

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}

int main()
{
    fastio(); 

    // int t; 
    // cin >> t;

    // while (t--) 
    solve(); 

    return 0;
}

void solve()
{
    long long a;
    double b;
    cin >> a >> b;
    long long c = round(b * 100);
    long long ans =  (a * c) / 100;
    cout << ans << "\n";
}

Measured memory_bytes: 3804
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x);

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int w,h;
int ice[100][100];

int dfs(int x, int y){
  int ret = 0;
  ice[y][x] = 0;
  REP(i,4){
    int xx = x + _dx[i];
    int yy = y + _dy[i];
    if(ISIN(xx,yy,w,h) && ice[yy][xx] == 1)
      ret = max(ret, dfs(xx,yy));
  }
  ice[y][x] = 1;
  return ret + 1;
}

int main(){
  while((w = getInt()) + (h = getInt())){
    REP(i,h) REP(j,w) ice[i][j] = getInt();

    int ans = 0;
    REP(i,h) REP(j,w){
      if(ice[i][j] == 1)
        ans = max(ans, dfs(j,i));
    }

    print(ans);
  }
  return 0;
}

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

int main()
{
    char input;
    int res = 700;
    for (int i = 0; i < 3; i++)
    {
        scanf("%c", &input);
        res += (input == 'o') ? 100 : 0;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n;
  bool ans=true;
  cin >> n;
  while (n--)
  {
    int u;
    cin >> u;
    if (u%2==0 && u%3!=0 && u%5!=0) ans = false;
  }
  if (ans) cout << "APPROVED"; else cout << "DENIED";
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>

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

using namespace std;

int T;
void solve(){
	int ans=0;
	char st[256]={};
	rep(i,T){
		string s;
		cin >> s;
		st[ (int)s[0] ] = s[1];
		if( ans%2 == 0 ){
			if( st['l'] == 'u' && st['r'] == 'u' ){
				ans++;
			}
		}else{
			if( st['l'] == 'd' && st['r'] == 'd' ){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

int main(){
	while(cin>>T, T){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3112
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    print(1 << __lg(N));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  int N;
  cin >> N;
  string S[N];
  int i;
  long long n[5]={0,0,0,0,0};
  for(i = 0;i < N;i++){
    cin >> S[i];

    switch(S[i][0]){
      case 'M':
        n[0]++;
        break;
      case 'A':
        n[1]++;
        break;
      case 'R':
        n[2]++;
        break;
      case 'C':
        n[3]++;
        break;
      case 'H':
        n[4]++;
        break;
      default:
        break;
    }
  }
  int a[]={0,0,0,0,0,0,1,1,1,2};
  int b[]={1,1,1,2,2,3,2,2,3,3};
  int c[]={2,3,4,3,4,4,3,4,4,4};
  long long count = 0;
  for(i = 0;i < 10;i++){
    count += n[a[i]]*n[b[i]]*n[c[i]];
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
  ll n;
  cin>>n;
  if(n==1){cout<<"Yes"<<endl;}
  else{vector<ll> h(n);
  rep(i,n){cin>>h[i];}
  bool ans=true;
  rep(i,n-1){
    if(h[i]-h[i+1]>=2){ans=false;break;}}
  if(ans){rep(i,n-1)
    if(i==0){if(h[0]>=h[1]){h[0]--;}}
    else if(h[i]>=h[i+1]&&h[i]>h[i-1]){h[i]--;}}
  if(ans){rep(i,n-1){
    if(h[i]>h[i+1]){ans=false;break;}}}
  if(ans){cout<<"Yes"<<endl;}
  else cout<<"No"<<endl;     
}}

Measured memory_bytes: 1024
n, k = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = [0]

for a in A:
    B.append(B[-1] + a)

C = []

for i in range(n+1):
    for j in range(i, n+1):
        C.append(B[j] - B[i])

ans = 0
flag = False
D = []

for i in range(40, -1, -1):
    if flag:
        C = D
        flag = False
    D = []
    bit = 1 << i
    for c in C:
        if bit & c:
            D.append(c)
    if len(D) >= k:
        flag = True
        ans += bit
    
print(ans)


Measured memory_bytes: 23856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 3005;
ll dp[MAX_N][MAX_N],arr[MAX_N];
/*
题意 给你一个序列一个人先拿 另一个人后拿 只能从序列的开头或者结尾拿一个元素
先拿的分数是 X 后拿的人分数是 Y 他们都想要自己的分数差最大 也就是第一个人是 X - Y最大
第二个人是 Y - X最多    我们发现对这类dp 只有dp[l][r] 代表区间 l 到 区间 r 的最大 X - Y
只有当L = R的时候 才能确定取的是arr[l],arr[R] 
如果不等于 就从上个状态 arr[L] - dp[L+1][R] , arr[R] - dp[L][R-1]
推过来 为什么要减 因为上个人的值正好是下个人的负值
因为是L + 1 所以我们 L 从n 到 1
因为是R - 1 所以我们R 从 L 到 n
*/
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 1;i<=n;++i) scanf("%d",&arr[i]);
    
    for(int L = n;L>=1;--L)
    {
        for(int R = L;R<=n;++R)
        {
        	//dp[L][R]为区间L到R的最大x-y; 
        	
            dp[L][R] = max(arr[L]-dp[L+1][R],arr[R]-dp[L][R-1]);
            
            //区间L->R为 区间尾-区间L+1->R   和     区间头-区间L->R-1    的最大值；
			//反向算法 
        }
    }
    printf("%lld\n",dp[1][n]);
    return 0;
}


Measured memory_bytes: 49952
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main ()
{
    ll a;
    cin>>a;
    string x;
    a--;
    while(a>=0)
    {
        int c=a%26;
        char b=c+97;
        x.push_back(b);
        a=a/26;
        a--;
    }
    reverse(x.begin(),x.end());
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <map>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001

using namespace std;


int f1[100001];
int f2[100001];

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		int temp; cin >> temp;
		if (i % 2 == 0)
			f1[temp] += 1;
		else
			f2[temp] += 1;
	}

	int x1 = max_element(&f1[0], &f1[0] + 100001) - f1;
	int y1 = max_element(&f2[0], &f2[0] + 100001) - f2;
	if (x1 != y1)
	{
		cout << n - (f1[x1] + f2[y1]) << endl;
		return 0;
	}
	auto t1 = f1[x1];
	auto t2 = f2[y1];
	f1[x1] = f2[y1] = 0;
	int x2 = max_element(&f1[0], &f1[0] + 100001) - f1;
	int y2 = max_element(&f2[0], &f2[0] + 100001) - f2;
	f1[x1] = t1;
	f2[y1] = t2;

	cout << min((n - f1[x1] - f2[y2]), (n - f1[x2] - f2[y1])) << endl;

	return 0;
}

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

using namespace std;

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

    string ans="Yes";
    map<string,int> check;
    
    string s;
    string s_before;
    cin >> s_before;
    check[s_before]=1;
    for(int i=1;i<n;i++){
        cin >> s;

        if(check[s]==1) ans="No";
        check[s]=1;

        if(s[0]!=s_before[s_before.length()-1]) ans="No";
        s_before=s;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int ct = 0;
    rep(i, s.length())
    {
        if (s[i] != t[i])
        {
            ++ct;
        }
    }
    cout << ct << endl;
}

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

using namespace std;
int n,k,sol;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin>>n>>k;
    if(n%k==0) cout<<0;
    else cout<<1;
    return 0;
}


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

const int Maxn = 1000005;
const int mod= 1000003;
inline long long powermod(long long x, long long y) {
	long long res = 1;
	while (y) {
		if (y & 1) (res *= x) %= mod;
		(x *= x) %= mod, y >>= 1;
	}
	return res;
}
long long x, d, n;
long long fact[Maxn];
int main() {
	fact[1] = 1;
	for (int i = 2; i < Maxn; ++ i)
		fact[i] = fact[i - 1] * i % mod;
	int tests;
	scanf("%d", &tests);
	while (tests --) {
		scanf("%lld %lld %lld", &x, &d, &n);
		if (!d) {
			printf("%lld\n", powermod(x, n));
			continue;
		}
		long long ans = powermod(d, n);
		(x *= powermod(d, mod - 2)) %= mod;
		if (!x || x + n - 1 >= mod) {
			putchar('0');
			putchar('\n');
			continue;
		}
		printf("%lld\n", ans * fact[x + n - 1] % mod * powermod(fact[x - 1], mod - 2) % mod);
	}
	return 0;
}

Measured memory_bytes: 8576
A,B,C = list(map(int,input().split(" ")))
min_number = min(A,B)
listA = []
for i in range(1,min_number+1):
    if A % i == 0 and B % i == 0:
        listA.append(i)
listA.sort(reverse=True)
print(listA[C-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,k,ans=0;
	cin>>n>>k;
	while(n){
		ans++;
		n/=k;
	}
	cout<<ans<<endl;
	return 0;
}


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

odd = [i for i in a if i % 2 == 1]
even = [i for i in a if i % 2 == 0]
ecnt = pow(2, len(even))
ocnt = pow(2, max(len(odd)-1,0))
print(0 if (len(odd) == 0 and p == 1) else ecnt * ocnt)


Measured memory_bytes: 38384
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	s <- getLine
	if all (== head s) s
		then putStrLn "No"
		else putStrLn "Yes"


Measured memory_bytes: 380
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int w, h;
int map[20][20];
int startRow, startLine, goalRow, goalLine;
int ans;
int Min(int a, int b){
	return a <= b ? a : b;
}
int Move(int map[20][20], int kaisu, int stoneRow, int stoneLine, int w, int h){
	if (kaisu == 10)
		return 11;
	int slide = 0, ans = 11;
	while (stoneRow - slide > 0 && map[stoneRow - slide - 1][stoneLine] == 0)
		slide++;
	if (stoneRow - slide > 0){
		if (map[stoneRow - slide - 1][stoneLine] == 3)
			return kaisu + 1;
		else if (slide > 0){
			map[stoneRow - slide - 1][stoneLine] = 0;
			ans = Min(ans, Move(map, kaisu + 1, stoneRow - slide, stoneLine, w, h));
			map[stoneRow - slide - 1][stoneLine] = 1;
		}
	}
	slide = 0;
	while (stoneLine - slide > 0 && map[stoneRow][stoneLine - slide - 1] == 0)
		slide++;
	if (stoneLine - slide > 0){
		if (map[stoneRow][stoneLine - slide - 1] == 3)
			return kaisu + 1;
		else if (slide > 0){
			map[stoneRow][stoneLine - slide - 1] = 0;
			ans = Min(ans, Move(map, kaisu + 1, stoneRow, stoneLine - slide, w, h));
			map[stoneRow][stoneLine - slide - 1] = 1;
		}
	}
	slide = 0;
	while (stoneRow + slide < h - 1 && map[stoneRow + slide + 1][stoneLine] == 0)
		slide++;
	if (stoneRow + slide < h - 1){
		if (map[stoneRow + slide + 1][stoneLine] == 3)
			return kaisu + 1;
		else if (slide > 0){
			map[stoneRow + slide + 1][stoneLine] = 0;
			ans = Min(ans, Move(map, kaisu + 1, stoneRow + slide, stoneLine, w, h));
			map[stoneRow + slide + 1][stoneLine] = 1;
		}
	}
	slide = 0;
	while (stoneLine + slide < w - 1 && map[stoneRow][stoneLine + slide + 1] == 0)
		slide++;
	if (stoneLine + slide < w - 1){
		if (map[stoneRow][stoneLine + slide + 1] == 3)
			return kaisu + 1;
		else if (slide > 0){
			map[stoneRow][stoneLine + slide + 1] = 0;
			ans = Min(ans, Move(map, kaisu + 1, stoneRow, stoneLine + slide, w, h));
			map[stoneRow][stoneLine + slide + 1] = 1;
		}
	}
	return ans;
}
int main(){
	while (true)
	{
		cin >> w >> h;
		if (w + h == 0)break;
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++){
				cin >> map[i][j];
				if (map[i][j] == 2){
					startRow = i;
					startLine = j;
				}
				else if (map[i][j] == 3){
					goalRow = i;
					goalLine = j;
				}
			}
		map[startRow][startLine] = 0;
		ans = Move(map, 0, startRow, startLine, w, h);
		if (ans == 11)ans = -1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nmd = arr.shift().split(" ").map(Number);
var n = nmd[0];
var m = nmd[1];
var d = nmd[2];
var yx = [];
while(arr.length!=0)yx.push(arr.shift().split(""));
var cnt = 0;
for(var y=0;y<n;y++) for(var x=0;x<m - d+1;x++){
   var flag = true;
   for(var i= 0; i<d;i++){ 
      if(yx[y][x+i] == "#") flag = false;
   }
   if(flag)cnt++;
}
for(var y=0;y<n-d+1;y++) for(var x=0;x<m;x++){
   var flag = true;
   for(var i= 0; i<d;i++){ 
      if(yx[y+i][x] == "#") flag = false;
   }
   if(flag)cnt++;
}
console.log(cnt);

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

long long kMod = 998244353;

int main()
{
  long long n, s;
  cin >> n >> s;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  vector<vector<long long>> dp(n+1, vector<long long>(s+1, 0));
  dp.at(0).at(0) = 1;
  for (int i = 1; i <= n; i++) {
    for (int sum = 0; sum <= s; sum++) {
      dp.at(i).at(sum) += 2 * dp.at(i-1).at(sum);
      dp.at(i).at(sum) %= kMod;
      if (sum + a.at(i-1) <= s) {
        dp.at(i).at(sum + a.at(i-1)) += dp.at(i-1).at(sum);
        dp.at(i).at(sum + a.at(i-1)) %= kMod;
      }
    }
  }
  cout << dp.back().back() << '\n';

  return 0;
}


Measured memory_bytes: 73744
#include <iostream>
using namespace std;
int main(void){
    int n,m;
    int mat[100][100];
    int vec[100], out[100]={0};
    
    cin>>n>>m;
    for(int i=0; i < n; i++){
        for(int j=0; j<m;j++){
            cin >> mat[i][j];
        }
    }
    for(int i=0; i < m; i++)cin >> vec[i];

    for(int i=0; i < n; i++){
        for(int j=0; j<m;j++){
            out[i] += mat[i][j]*vec[j];
        }
    }
    for(int i=0; i < n; i++)cout << out[i] << endl;
    
    return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll st(ll i){
    while(i>=10)i/=10;
    return i;
}
ll last(ll i){
    return i%10;
}
int main(){
    ll ans=0;
    ll n;cin>>n;
    vvi v(10,vi(10));
    REP(i,1,n+1){
        v[st(i)][last(i)]++;
    }
    rep(i,10)rep(j,10)ans+=v[i][j]*v[j][i];
    out(ans);
}

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

struct Edge{
    int to, cap, rev;
};

const int INF = INT_MAX;
vector<Edge> G[202];
const int ns = 200;
const int nt = 201;

bool used[202];

void add_edge(int from, int to, int cap) {
    G[from].push_back((Edge){ to, cap, (int)G[to].size() });
    G[to].push_back((Edge){ from, 0, (int)G[from].size()-1 });
}

int maxflow(int s, int t, int f) {
    used[s] = true;
    int ret;
    if (s == t) {
        ret = f;
    } else {
        ret = 0;
        for (Edge &e: G[s]) {
            if ( ! used[e.to] && e.cap > 0) {
                int maxf = maxflow(e.to, t, min(f, e.cap));
                if (maxf > 0) {
                    e.cap -= maxf;
                    G[e.to][e.rev].cap += maxf;
                    ret = maxf;
                    break;
                }
            }
        }
    }
    return ret;
}

int main() {
    int X, Y, E;
    cin >> X >> Y >> E;
    for (int i=0; i<E; ++i) {
        int x, y;
        cin >> x >> y;
        add_edge(x, y+100, 1);
    }
    for (int i=0; i<X; ++i) add_edge(ns, i, 1);
    for (int i=0; i<Y; ++i) add_edge(i+100, nt, 1);

    int mx = 0;
    while (1) {
        fill(used, used+202, false);
        int f = maxflow(ns, nt, INF);
        if (f == 0) break;
        mx += f;
    }
    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 3340
/*
Keep clam  Believe youself
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<stack>
#include<set>
#include<cmath>
#define Xiaobo main
#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
const int maxn=2e5+7;
const int mod=1e9+7;
const double eps=1e-15;
const double pi=acos(-1);
const int INF=0x3f3f3f3f;
typedef long long ll;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
//别急 dp找状态 问题看看本身的规律 贪心找方法


int ans[maxn],vis[maxn];
vector<int>num[maxn];
int f[maxn],size[maxn];
int find(int x) {
	if(x!=f[x]) f[x]=find(f[x]);
	return f[x];
}

int Xiaobo()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) f[i]=i,size[i]=1;
	while(m--) {
		int u,v;
		cin>>u>>v;
		num[u].push_back(v);
		num[v].push_back(u);
		int uu=find(u);
		int vv=find(v);
		if(uu!=vv) {
			size[vv]+=size[uu],f[uu]=vv;
		}
	}
	while(k--) {
		int u,v;
		cin>>u>>v;
		if(find(u)==find(v)) {
			num[u].push_back(v);
			num[v].push_back(u);
		}
	}
//	cout<<"\ngg\n";
//	for(int i=1;i<=n;i++) {
//		//for(auto item:num[i]) cout<<item<<' ';
//		cout<<i<<' '<<size[i]<<'\n';
//		//cout<<'\n';
//	}
//	cout<<"\ngg\n";
	for(int i=1;i<=n;i++) {
		ans[i]=size[find(i)]-num[i].size()-1;
	}
	for(int i=1;i<=n;i++) {
		cout<<ans[i]<<' ';
	}
	return 0;
}

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

using namespace std;

const unsigned mod = 1e9 + 7;
unsigned power[234567], lad[26][234567];

struct SegmentTree
{
  vector< unsigned > hashed;
  vector< int > lazy;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    hashed.assign(2 * sz - 1, 0);
    lazy.assign(2 * sz - 1, -1);
  }

  void push(int k, int l, int r)
  {
    if(~lazy[k]) {
      hashed[k] = lad[lazy[k]][r - l];
      if(k < sz - 1) {
        lazy[2 * k + 1] = lazy[k];
        lazy[2 * k + 2] = lazy[k];
      }
      lazy[k] = -1;
    }
  }

  void add(int a, int b, int x, int k, int l, int r)
  {
    push(k, l, r);
    if(a >= r || b <= l) return;
    if(a <= l && r <= b) {
      lazy[k] = x;
      push(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) >> 1);
      add(a, b, x, 2 * k + 2, (l + r) >> 1, r);
      hashed[k] = hashed[2 * k + 1] * power[(r - l) >> 1] + hashed[2 * k + 2];
    }
  }

  void add(int a, int b, int x)
  {
    add(a, b, x, 0, 0, sz);
  }

  pair< unsigned, int > get(int a, int b, int k, int l, int r)
  {
    push(k, l, r);
    if(a >= r || b <= l) return {0, 0};
    if(a <= l & r <= b) return {hashed[k], r - l};
    auto ll = get(a, b, 2 * k + 1, l, (l + r) >> 1);
    auto rr = get(a, b, 2 * k + 2, (l + r) >> 1, r);
    return {ll.first * power[rr.second] + rr.first, ll.second + rr.second};

  }

  unsigned get(int a, int b)
  {
    return (get(a, b, 0, 0, sz).first);
  };
};

int main()
{
  power[0] = 1;
  for(int i = 0; i < 234566; i++) power[i + 1] = power[i] * mod;
  for(int i = 0; i < 26; i++) {
    const char cc = 'a' + i;
    for(int j = 0; j < 234566; j++) lad[i][j + 1] = lad[i][j] * mod + cc;
  }


  int N, Q;
  string U;

  cin >> N;
  cin >> U;
  SegmentTree tree(N);
  for(int i = 0; i < N; i++) tree.add(i, i + 1, U[i] - 'a');

  cin >> Q;
  while(Q--) {
    string S;
    cin >> S;
    if(S == "set") {
      int x, y;
      char z;
      cin >> x >> y >> z;
      tree.add(--x, y, z - 'a');
    } else {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      --a, --c;
      int ok = 0, ng = min(d - c, b - a) + 1;
      while(ng - ok > 1) {
        int mid = (ok + ng) >> 1;
        if(tree.get(a, a + mid) == tree.get(c, c + mid)) ok = mid;
        else ng = mid;
      }

      if(ok == d - c && ok == b - a) {
        cout << "e\n";
      } else if(b - a == ok || (d - c != ok && tree.get(a + ok, a + ok + 1) < tree.get(c + ok, c + ok + 1))) {
        cout << "s\n";
      } else {
        cout << "t\n";
      }
    }
  }

}

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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    string s, t;
    cin >> s >> t;

    string s2 = s + s;
    bool ok = false;
    rep(i, s.size()){
        if(s2[i] == t[0]){
            string tmp;
            tmp = s2.substr(i, s.size());
            if(tmp == t) ok = true;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>

using namespace std;
#define copy(a, b) number[a - 1] = temp[b - 1];

class Dice {
public:
	Dice() {
		for (int i = 0; i < 6; i++)
			cin >> number[i];
	}

	void rotate(char c) {
		int temp[6];
		for(int i = 0; i < 6; i++)
			temp[i] = number[i];
		switch (c) {
		case 'E':
			copy(1, 4);
			copy(4, 6);
			copy(6, 3);
			copy(3, 1);
			break;
		case 'W':
			copy(1, 3);
			copy(3, 6);
			copy(6, 4);
			copy(4, 1);
			break;
		case 'N':
			copy(5, 1);
			copy(1, 2);
			copy(2, 6);
			copy(6, 5);
			break;
		case 'S':
			copy(2, 1);
			copy(1, 5);
			copy(5, 6);
			copy(6, 2);
			break;
		}
	}
	void print(int x) {
		cout << number[x - 1] << endl;
	}
	int getnum(int x) {
		return number[x - 1];
	}
	void spin() {
		int temp[6];
		for (int i = 0; i < 6; i++)
			temp[i] = number[i];
		copy(2, 3);
		copy(3, 5);
		copy(5, 4);
		copy(4, 2);	
	}
private:
	int number[6];
};

int main() {
	Dice d1;
	Dice d2;
	int check = 0;

	for (int i = 0; i < 4; i++) {
		d1.rotate('S');
		if (d1.getnum(1) == d2.getnum(1))
			break;
	}
	if (d1.getnum(1) != d2.getnum(1)) {
		while (d1.getnum(1) != d2.getnum(1)) {
			d1.rotate('E');
		}
	}

	while (d1.getnum(2) != d2.getnum(2)) {
		d1.spin();
	}

	for (int j = 1; j <= 6; j++) {
		if (d1.getnum(j) != d2.getnum(j))
			check++;
	}

	if (!check)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
		


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

//エラトステネスの篩,n以下の素数の列挙の時に
vector<int> prime;
vector<bool> is_prime(55560,true);

void sieve(int n){
    is_prime[0]=false;
    is_prime[1]=false;
    FOR(i,2,n+1){
        if(is_prime[i]){
            if(i%5==1) prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    sieve(55555);
    rep(i,n){
      cout<<prime[i]<<' ';
    }
    cout<<endl;
}

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

int main()
{
    string s;
    cin>>s;
    int cnt=0;
    if(s[0]=='1')cnt++;
    if(s[1]=='1')cnt++;
    if(s[2]=='1')cnt++;
    cout<<cnt<<endl;
}


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

int main() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int sum;
  for (int i = 1; i < 3; i++)
  {
    sum += vec.at(i) - vec.at(i-1);
  }
  cout << sum << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    set<ll> s;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int _move[8][2] = {-1,-1,0,-1,1,-1,-1,0,1,0,-1,1,0,1,1,1,};
int main( ){
    int h,w;
    cin>>h>>w;
    char _map[55][55];
    for(int i = 0;i<52;i++){
        _map[0][i]='.';
        _map[i][0]='.';
    }
    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            cin>>_map[i][j];
        }
    }
    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            if(_map[i][j]=='.'){
                _map[i][j]='0';
                for(int x=0;x<8;x++){
                    if(_map[i+_move[x][0]][j+_move[x][1]]=='#'){
                        _map[i][j]++;
                    }
                }
            }
        }
    }
    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            cout<<_map[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var str string
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%s", &str)

	//	chars := strings.Split(str, "")
	//	fmt.Println(chars)
	r := regexp.MustCompile(`^.*keyence$|^k.*eyence$|^ke.*yence$|^key.*ence$|^keye.*nce$|^keyen.*ce$|^keyenc.*e$|^keyence.*$`)
	if r.MatchString(str) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int N;
    cin >> N;
    vector<int> D(N);
    for(int i=0; i<N; i++) cin >> D[i];
    if(D[0] > 0){
        cout << 0 << endl;
        return 0;
    }
    vector<int> num(N);
    for(int d : D) num[d]++;
    if(num[0] > 1){
        cout << 0 << endl;
        return 0;
    }
    int64_t ans = 1;
    for(int d=1; d<N; d++) for(int k=0; k<num[d]; k++) mul(ans, num[d-1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys

[A,B] = list(map(int, input().split()))

if A == B:
    print(A)
    sys.exit(0)

ans = 0

if A % 2 == 0:
    if (B-A+1) % 4 in [2,3]:
        ans +=1
else:
    if (B-A+1) % 4 in [1,2]:
        ans += 1

for i in range(1, 64):

    a_k = (A >> i) & 1
    b_k = (B >> i) & 1

    a_index = A & ( (1 << i) - 1)
    b_index = B & ( (1 << i) - 1)

    count_bit = 0

    if B-A+1 <= (1 << i) - a_index:
        count_bit = a_k*(B-A+1)
    else:
        count_bit += a_k*( (1 << i) - a_index) 
        count_bit += b_k*(b_index+1)

    if count_bit % 2 == 1:
        ans |= (1 << i)

print(ans)

    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int turndis(char a) {
  if(a == 'a') return 0;
  else if(a == 'b') return 1;
  else if(a == 'c') return 2;
}
int main () {
  string a, b, c;
  cin >> a >> b >> c;
  int coa = 0, cob = 0, coc = 0, turn = 0;
  char ans;
  while(1) {
    if(turn == 0) {
      if(a.size()== coa) {
        ans = 'A';
        break;
      }
      turn = turndis(a.at(coa));
      coa++;
    } else if(turn == 1) {
      if(b.size()== cob) {
        ans = 'B';
        break;
      }
      turn = turndis(b.at(cob));
      cob++;
    } else if(turn == 2) {
      if(c.size()== coc) {
        ans = 'C';
        break;
      }
      turn = turndis(c.at(coc));
      coc++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256