akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef pair<int,int> pii;

int main(){
	int n; scanf("%d",&n);
	pii p[1000];
	rep(i,n) scanf("%d%d",&p[i].second,&p[i].first);

	sort(p,p+n);

	static int dp[1000001];
	rep(i,n){
		int a=p[i].second,b=p[i].first;
		for(int t=b;t>=max(a,0);t--) dp[t]=max(dp[t],dp[t-a]+1);
	}
	printf("%d\n",*max_element(dp,dp+1000001));

	return 0;
}

Measured memory_bytes: 0
input_line = input().split(" ")
min_fig = int(input_line[0])
max_fig = int(input_line[1])
sample = int(input_line[2])
if min_fig % sample == 0:
    minus_num = int(min_fig / sample) -1
else:
    minus_num = int(min_fig / sample)
plus_num = int(max_fig / sample)
print(plus_num-minus_num)

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int a[n];
  for(int i=0;i<n;++i) cin>>a[i];
  sort(a, a+n);
  int ans=0;
  for(int i=n-1;i!=0;--i){
    ans += a[i]-a[i-1];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cctype>
using namespace std;

int main(){
    int n,cnt;
    string s;
    cin >> n;
    while(n--){
        map <int,char> data;
        map <int,char>::iterator itr;
        cnt = 0;
        cin >> s;
        for(int i=0;i<s.length();i++){
            if(isalpha(s[i])){
                data.insert(map<int,char>::value_type(cnt,s[i]));
            }
            else if(s[i] == '<') cnt--;
            else if(s[i] == '>') cnt++;
        }
        for(itr=data.begin();itr!=data.end();itr++){
            cout << itr->second;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
string s="";
int main(){
  cin>>s;
  string ans="";
  for(int i=0;i<int(s.size());i++){
    if(s[i]=='0'){ans.push_back('0');}
    if(s[i]=='1'){ans.push_back('1');}
    if((s[i]=='B')&&(!ans.empty())){ans.pop_back();}
  }
  cout<<ans<<endl;
}


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

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

int main(){
  int N;
  cin >> N;
  vector<int>vec(N);

  for (int i_1 = 0; i_1 < N; i_1 ++){
    cin >> vec.at(i_1);
  }

  int n = 1;
  for (int i_2 = 0; i_2 < N; i_2 ++){
    n = vec.at(n-1);
    if (n == 2) {
      cout << i_2 + 1 <<endl;
      break;
    }
    else if (i_2 == N - 1) cout << -1 <<endl;
  }
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi x(n), y(n);
	double s = 0;
	rep(i, n) cin >> x[i] >> y[i];
	rep(i, n) rep(j, i) s += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
	s *= 2.0 / n;
	printf("%.20f\n", s);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	//freopen("input.txt", "r", stdin);
	string str1, str2;
	cin>>str1>>str2;
	int cnt = 0;
	if(str1[0]==str2[0]) cnt++;
	if(str1[1]==str2[1]) cnt++;
	if(str1[2]==str2[2]) cnt++;
	cout<<cnt<<endl;

 
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') cout << "vowel" << endl;
  else cout<< "consonant" << endl;
}

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

const int maxn = 2005;
int f[maxn],g[maxn];
vector<int>ve[maxn];
int n;
char ss[maxn];
int sz[maxn];
void dfs(int x,int ba=0) {
	sz[x] = (ss[x]=='1');
	f[x] = 0;
	g[x] = 0;
	for(auto y:ve[x]) {
		if(y==ba) continue;
		dfs(y,x);
		sz[x] += sz[y];
		g[x] += g[y]+sz[y];
	}
	for(auto y:ve[x]) {
		if(y==ba) continue;
		f[x] = max(f[x],f[y]+sz[y]-(g[x]-(g[y]+sz[y])));
	}
}
int work(int x) {
	dfs(x);
	if(f[x]||g[x]%2) return 1e17;
	return g[x]/2;
}

main() {
	scanf("%lld",&n);
	scanf("%s",&ss[1]);
	for(int i=1;i<n;i++) {
		int x,y; scanf("%lld%lld",&x,&y);
		ve[x].push_back(y);
		ve[y].push_back(x);
	}
	int ans = 1e17;
	for(int i=1;i<=n;i++) {
		ans = min(ans,work(i));
	}
	if(ans==(int)1e17) puts("-1");
	else printf("%lld",ans);
}

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

int main()
{
	int n;
	int nc;
	int inc, outc;

	int maxc = 0;

	int i;

	cin >> n >> nc;

	maxc = nc;

	for (i = 0; i < n; i++)
	{
		cin >> inc >> outc;
		
		nc += inc - outc;

		if (nc < 0)
		{
			cout << 0 << endl;
			return 0;
		}

		if (maxc < nc )
		{
			maxc = nc;
		}
	}

	cout << maxc << endl;

	return 0;
}

Measured memory_bytes: 3072
using System;
using System.Linq;

class Program {
  static void Main() {
    var g = new[] { 0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.WriteLine(g[a[0]] == g[a[1]] ? "Yes" : "No");
  }
}


Measured memory_bytes: 13396
import Data.Bool
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readParams >>= putStrLn . solve . tail

readParams :: IO [Int]
readParams = map b2int . B.words <$> B.getContents
  where b2int = fst . fromJust . B.readInt

solve :: [Int] -> String
solve = format . solve'

format :: Bool -> String
format = bool "No" "Yes"

solve' :: [Int] -> Bool
solve' (h:hs) = go h hs
  where go _ [] = True
        go n (x:xs)
          | n <= x     = go x xs
          | n - 1 == x = go n xs
          | otherwise  = False


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

using namespace std;

typedef  long long int ll;

int main() {
	
	ll n,k;
	cin>>n>>k;
	string ans = "";
	while(n) {
		ans += to_string(n%k);
		n = n/k;
	}
	cout<<ans.length()<<endl;
	return 0;
}


Measured memory_bytes: 256
# 重複組み合わせの全列挙

import itertools

# n+m-1個からn個を選ぶ組み合わせ
n, m, q = map(int, input().split())
seq = list(range(n+m-1))
p = list(itertools.combinations(seq, n))

a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

res = 0
for i in p:
    t = [0] * n
    idx = 0
    for e in i:
        t[idx] = 1 + e - idx
        idx += 1
    
    tmp = 0
    for j in range(q):
        if t[b[j]-1] - t[a[j]-1] == c[j]:
            tmp += d[j]
    
    res = max(res, tmp)

print(res)


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

int main(){
  int n;
  while(1){
    vector<int> ans;
    cin>>n;
    if(n==-1)break;
    if(!n)ans.push_back(0);
    while(n){
      ans.push_back(n%4);
      n/=4;
    }
    for(int i=ans.size()-1;i>=0;i--){
      cout<<ans[i];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1212
import java.util.*;
 public class Main {

 public static void main(String[] args) {
   Scanner no=new Scanner(System.in);
   int n=no.nextInt();
   int u=n;
   int m=no.nextInt();
   int minx=0;
   int maxx=n;
   int miny=0;
   int maxy=m;
   int v=m;
   int t=no.nextInt();
   for(int i=0;i<t;i++){
     int a=no.nextInt();
     int b=no.nextInt();
     int y=no.nextInt();
    /* 5 4 2
     2 1 1
     3 3 4*/
     if(y==1){
       if(a>minx){
         minx=a;
       }
       //u=a;
     }
     else if(y==2){
      if(maxx>a){
        maxx=a;
      }
      // a=a-n;
     }
     else if(y==3){
      if(b>miny){
        miny=b;
      }
       //v=b;
     }
     else{
      if(maxy>b){
        maxy=b;
      }
      // v=b-m;
     }
   }
   if(minx>=maxx||miny>=maxy){
     System.out.println("0");
   }
   else System.out.println((maxx-minx)*(maxy-miny));
 }

}
 

Measured memory_bytes: 35864
c=0
for W in iter(input,'0'):
 c+=1
 W=int(W)
 d=[0]*-~W
 for _ in[0]*int(input()):
  v,w=map(int,input().split(','))
  for i in range(W,w-1,-1):
   if d[i]<d[i-w]+v:d[i]=d[i-w]+v
 print(f'Case {c}:\n{d[W]}\n{d.index(d[W])}')


Measured memory_bytes: 5624
#include<iostream>
#include<utility>
#include<tuple>
#include<set>
#include<list>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

const long long MAXN = 1e6;
const long long MOD = 1e9+7;
const long long INF = __LONG_LONG_MAX__ / 2;

using namespace std;

int hoge[MAXN];

signed main(){
    string s1, s2;
    cin >> s1 >> s2;
    reverse(s1.begin(),s1.end());
    cout << ((s1 == s2) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

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

    double ans = 0;
    double num = 0;

    for(int i = 0; i < n; ++i){
        cin >> num;
        ans += 1/num;
    }

    cout << 1/ans << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w, d;
  cin >> h >> w >> d;

  vector<pair<int, int>> n_positions(h * w + 1);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int a;
      cin >> a;
      n_positions[a].first = i;
      n_positions[a].second = j;
    }
  }

  auto get_dist = [&](int a, int b) {
    auto &pos_a = n_positions[a];
    auto &pos_b = n_positions[b];
    return abs(pos_a.first - pos_b.first) + abs(pos_a.second - pos_b.second);
  };

  vector<vector<int>> dist_cache(d);
  for (int i = 0; i < d; i++) {
    auto &psums = dist_cache[i];
    psums.push_back(0);
    for (int j = i == 0 ? d * 2 : i + d; j <= h * w; j += d) {
      int dist = get_dist(j, j - d);
      psums.push_back(psums.back() + dist);
    }
  }

  int q;
  cin >> q;

  vector<int> ans;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;

    int md_r = l % d;
    auto &psum = dist_cache[md_r];

    int l_idx = (l - md_r) / d;
    int r_idx = (r - md_r) / d;
    if (md_r == 0) {
      l_idx--;
      r_idx--;
    }

    ans.push_back(psum[r_idx] - psum[l_idx]);
  }

  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}

Measured memory_bytes: 6528
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int,input().split())
UF = UnionFind(N)

for i in range(M):
    x, y, z = map(int,input().split())
    x-=1; y-=1
    UF.union(x,y)

print(UF.group_count())


Measured memory_bytes: 7860
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;

constexpr bool isPrime(const int &n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

main {
  int n;
  cin >> n;
  int c = 0;
  while (n--) {
    int a;
    cin >> a;
    c += isPrime(a);
  }
  cout << c << endl;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  int t;
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(b/c)-(a-1)/c<<endl;
  return 0;
}


Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def solve():
    N = II()
    A = LI()

    mx = max(A)

    memo = [0] * (mx + 1)
    for a in A:
        for i in range(a, mx+1, a):
            memo[i] += 1
    # print(memo)

    ans = 0
    for a in A:
        if memo[a] == 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 104148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int n, k;
  cin >> n >> k;
  int lim = (n - 1) * (n - 2) / 2;
  if (k > lim) {
    cout << -1 << endl;
    return 0;
  }
  int m = n * (n - 1) / 2 - k;
  cout << m << endl;
  int cnt = 0;
  rep(i, n - 1) for (int j = i + 1; j < n; j++) {
    if (cnt >= m) break;
    printf("%d %d\n", i + 1, j + 1);
    cnt++;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x;
  for(int i=0;i<=n-1;i++){
    int e;
    cin>>e;
    x.push_back(e);
  }
  vector<int> cnt(100,0);
  for(int i=0;i<=100;i++){
    for(int j=0;j<=n-1;j++){
      cnt[i]+=pow(x[j]-i-1,2);
    }
  }
  int  m=1000000;
  for(int i=0;i<=100;i++){
    m=min(cnt[i],m);
  }
  cout<<m<<endl;
  return 0;
}

Measured memory_bytes: 3632
def solve():
    N, Y = map(int, input().split())

    for x in range(N+1):
        for y in range(N+1-x):
            d = Y - x * 10000 - y * 5000
            if d % 1000 == 0:
                z = d // 1000
                if x + y + z == N:
                    print(x, y, z)
                    exit()
    print(-1, -1, -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin>>S;
  cin>>T;
   T.at(T.size()-1)='o';
  if(S+'o'==T){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid, typename OperatorMonoid, typename F, typename G, typename H>
struct LazySegmentTree{
	int sz;
	vector<Monoid> data;
	vector<OperatorMonoid> lazy;
	const F f;
	const G g;
	const H h;
	const Monoid e1;
	const OperatorMonoid e0;

	LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
		sz=1;
		while(sz<n) sz<<=1;
		data.resize(2*sz-1, e1);
		lazy.resize(2*sz-1, e0);
	}

	void build(vector<Monoid> v){
		for(int i=0; i<v.size(); i++) data[i+sz-1]=v[i];
		for(int i=sz-2; i>=0; i--) data[i]=f(data[2*i+1], data[2*i+2]);
	}

	void eval(int k, int l, int r){
		if(lazy[k]!=e0){
			data[k]=g(data[k], lazy[k], r-l);
			if(k<sz-1){
				lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
				lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
			}
		}
		lazy[k]=e0;
	}

	void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
		eval(k, l, r);
		if(r<=a || b<=l) return;
		if(a<=l && r<=b){
			lazy[k]=h(lazy[k], x);
			eval(k, l, r);
		}else{
			update(a, b, x, 2*k+1, l, (l+r)/2);
			update(a, b, x, 2*k+2, (l+r)/2, r);
			data[k]=f(data[2*k+1], data[2*k+2]);
		}
	}
	void update(int a, int b, const OperatorMonoid &x){
		return update(a, b, x, 0, 0, sz);
	}

	Monoid find(int a, int b, int k, int l, int r){
		eval(k, l, r);
		if(b<=l || r<=a) return e1;
		if(a<=l && r<=b) return data[k];
		else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
	}
	Monoid find(int a, int b){
		return find(a, b, 0, 0, sz);
	}
	Monoid operator[](const int &k){
		return find(k, k+1);
	}
};
struct myon{
	ll c0, c1, cv;
	myon(){}
	myon(ll c0, ll c1, ll cv):c0(c0), c1(c1), cv(cv){}
};
int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    vector<myon> v(n);
    for(int i=0; i<n; i++){
        int a;
        scanf("%d", &a);
        if(a) v[i]=myon(0, 1, 0);
		else v[i]=myon(1, 0, 0);
    }
	auto f=[&](myon a, myon b){
		return myon(a.c0+b.c0, a.c1+b.c1, a.cv+b.cv+a.c1*b.c0);
	};
	auto g=[&](myon a, bool x, int len){
		if(x) return myon(a.c1, a.c0, (ll)len*(len-1)/2-a.cv-a.c0*(a.c0-1)/2-a.c1*(a.c1-1)/2);
		else return a;
	};
	auto h=[&](bool x, bool y){
		return x^y;
	};
    LazySegmentTree<myon, bool, decltype(f), decltype(g), decltype(h)> seg(n, f, g, h, myon(0, 0, 0), 0);
    seg.build(v);
    while(q--){
        int t, l, r;
        scanf("%d %d %d", &t, &l, &r);
		l--;
        if(t==1){
            seg.update(l, r, 1);
        }else{
            printf("%lld\n", seg.find(l, r).cv);
        }
    }
    return 0;
}


Measured memory_bytes: 24980
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;

int main() {
 ll n;
  cin >> n;
  ll sum=0;
  ll l=0;
  ll k;
  if(n==1 || n==2){
    cout << n << endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    sum=sum+i;
    if(sum>n){
      l=sum-n;
      k=i;
      break;
    }
    else if(sum==n){
      k=i;
      break;
    }
  }
  for(ll i=1;i<k+1;i++){
    if(i!=l)
    cout << i << endl;
  }
}



Measured memory_bytes: 3628
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

A = inp()
B = inp()
S = {1,2,3} - {A,B}
print(min(S))


Measured memory_bytes: 4328
require 'prime'

N = gets.to_i

if N == 1
  puts 0
  exit
end

factors = N.prime_division.to_h

fs = factors.values.map do |val|
  (0..val).to_a
end
res = 0

[0].product(*fs).each do |ar|
  current = 1
  ar.slice(1, ar.length).each_with_index do |val, i|
    current *= factors.keys[i]**val
  end

  p = current
  m = N/p - 1
  if p < m
    res += m
  end
end
puts res


Measured memory_bytes: 4348
use std::io;

fn main() {
    let mut text = String::new();
    io::stdin().read_line(&mut text).expect("");
    let mut split = text.split_whitespace();
    let a = split.next().unwrap().parse::<u32>().unwrap();
    let b = split.next().unwrap().parse::<u32>().unwrap();
    let c = split.next().unwrap().parse::<u32>().unwrap();
    if a == b + c || b == c + a || c == a + b {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

#define mod ((int)1e+9 + 7)

int main() {

    int n, m;
    cin >> n >> m;

    long long ans = 1;
    for(int i = 0; i < n; i++) {
        ans = ans * max((n - i), 1) % mod;
        ans = ans * max((m - i), 1) % mod;
    }
    if(n == m) ans *= 2;

    cout << (abs(n - m) > 1 ? 0 : ans % mod) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,h[200001][2]={};
  vector<int> ss;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    if(a>b)swap(a,b);
    if(a==1)h[b][0]=1;
    if(b==n)h[a][1]=1;
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    if(h[i][0]+h[i][1]==2)cnt=1;
  }
  if(cnt==1)cout<<"POSSIBLE";
  else cout<<"IMPOSSIBLE";
  return 0;
}



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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n,m;
	cin >>n >>m;
	VI s(n), t(m);
	rep(i, n) cin >>s[i];
	rep(i, m) cin >>t[i];
	
	vector<VL> dp(n+2, VL(m+2, 0));
	dp[0][0] = 1;
	rep(i, n+1) rep(j, m+1){
		if(i) dp[i][j] += dp[i-1][j];
		if(j) dp[i][j] += dp[i][j-1];
		if(i && j && s[i-1] != t[j-1]) dp[i][j] += MD - dp[i-1][j-1];
		dp[i][j] %= MD;
	}
	cout << dp[n][m] <<"\n";
	return 0;
}


Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000010;
char A[maxn],B[maxn];
int n,q[maxn],l=1,r;
int main() {
	scanf("%d%s%s",&n,A+1,B+1);
	if(!strcmp(A+1,B+1)) return puts("0"),0;
	int cl=n,ans=0;
	for(int i=n;i;i--) if(B[i]^B[i-1]) {
		while(cl&&(cl>i||A[cl]!=B[i])) cl--;
		if(!cl) return puts("-1"),0;
		while(l<=r&&q[l]>=r-l+1+i) l++;
		if(cl<i) q[++r]=cl;
		ans=max(ans,r-l+1);
	}
	printf("%d\n",ans+1);
}


Measured memory_bytes: 6144
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(){
    int n, a[101];
    int ans=0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
    for(int i = 0; i < n; i++){
        //printf("%d ", a[i]);
        if(i%2) ans+=a[i];
        else ans-=a[i];
    }
    printf("%d\n", abs(ans));
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    int a,b,s;
    scanf("%d %d",&a,&b);
    if(a==3 || b==3) printf("Possible\n");
    else if(a<3 && b<3)
    {
        s=a+b;
        if(s%3==0) printf("Possible\n");
        else printf("Impossible\n");
    }
    else if(a>3 || b>3)
    {
        if(a%3==0) printf("Possible\n");
        else if(b%3==0) printf("Possible\n");
        else if((a>3 && b<3)||(a<3 && b>3))
    {
        s=a+b;
        if(s%3==0) printf("Possible\n");
        else printf("Impossible\n");
    }
        else if(a>3 && b>3)
    {
        s=a+b;
        if(s%3==0) printf("Possible\n");
        else printf("Impossible\n");
    }
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

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

		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		System.out.println(a<=8 && b <=8 ? "Yay!" : ":(");
	}

}


Measured memory_bytes: 22740
from collections import deque
def main():
    N,M = map(int,input().split())
    G = [deque([]) for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    stack = deque([0])
    sign = [0] * N
    while stack:
        v = stack.popleft()
        for w in G[v]:
            if sign[w] == 0:
                sign[w] = v+1
                stack.append(w)   

    sign = sign[1:]
    if all(s > 0 for s in sign):
        print('Yes')
        for s in sign:
            print(s)
    else:
        print('No')
        
main()

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

char s[125252];
int n;

int main(){
  scanf("%s",s);
  n = strlen(s);
  stack<int> S;
  REP(i,n){
    // putchar(s[i]);
    int c = s[i]-'0';
    if(S.size() && S.top() != c){
      S.pop();
    }else{
      S.push(c);
    }
  }
  printf("%d\n",n-(int)S.size());
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}

typedef long long ll;
#define INF 1LL << 60
int X, Y, Z, N;
ll A[101010], B[101010], C[101010];
ll AA[101010], BB[101010];
ll dp1[101010];
void dodp1() {
  priority_queue<ll> que;
  rep(i, 0, N) dp1[i] = -INF;
  ll sm = 0;

  rep(i, 0, N) {
    que.push(-BB[i]);
    sm += BB[i];
    if (Y < que.size()) {
      ll q = -que.top();
      sm -= q;
      que.pop();
    }
    if (que.size() == Y) dp1[i] = sm;
  }
}
ll dp2[101010];
void dodp2() {
  priority_queue<ll> que;
  rep(i, 0, N) dp2[i] = -INF;
  ll sm = 0;

  rrep(i, N - 1, 0) {
    que.push(-AA[i]);
    sm += AA[i];
    if (X < que.size()) {
      ll q = -que.top();
      sm -= q;
      que.pop();
    }
    if (que.size() == X) dp2[i] = sm;
  }
}
void _main() {
  cin >> X >> Y >> Z;
  N = X + Y + Z;
  rep(i, 0, N) cin >> A[i] >> B[i] >> C[i];

  ll ans = 0;
  rep(i, 0, N) {
    ans += C[i];
    A[i] -= C[i];
    B[i] -= C[i];
  }

  vector<int> v;
  rep(i, 0, N) v.push_back(i);
  sort(v.begin(), v.end(), [&](int a, int b) { return A[a] - B[a] < A[b] - B[b]; });
  rep(i, 0, N) {
    int j = v[i];
    AA[i] = A[j];
    BB[i] = B[j];
  }

  dodp1();
  dodp2();

  ll ma = -INF;
  rep(k, 0, N - 1) ma = max(ma, dp1[k] + dp2[k + 1]);

  ans += ma;
  printf("%lld\n", ans);
}


Measured memory_bytes: 7288
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int[] field = {1, 0, 0};
        String[] in;
        int rep1, rep2, tmp;
        while(sc.hasNext()) {
        	in = sc.next().split(",");
        	rep1 = setRep(in[0]);
        	rep2 = setRep(in[1]);
        	
        	tmp = field[rep1];
        	field[rep1] = field[rep2];
        	field[rep2] = tmp;
        }
        
        for(int i = 0; i < 3; i++) {
        	if(field[i] == 1)	System.out.println(setAlphabet(i));	
        }
    }
    
    static int setRep(String in) {
    	if(in.equals("A"))		return 0;
    	else if(in.equals("B"))	return 1;
    	else					return 2;
    }
    
    static String setAlphabet(int field) {
    	if(field == 0)		return "A";
    	else if(field == 1)	return "B";
    	else				return "C";
    }
}

Measured memory_bytes: 26056
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  int n;

  cin >> n;

  vector<int> x(n);
  vector<int> y(n);
  REP(i,n) cin >> x[i] >> y[i];
  
  vector<int> ind(n);
  REP(i,n) ind[i] = i;
  
  double ret = 0;
  
  int a = 0;
  do{
    double tmp = 0;
    REP(i,n-1){
      tmp += sqrt(pow(x[ind[i]] - x[ind[i+1]],2) + pow(y[ind[i]] - y[ind[i+1]],2));
      
    }
    a++;
    ret += tmp;
  }
  while(next_permutation(ind.begin(),ind.end()));
  ret /= a;

  cout << ret << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int n;
	string s1,s2;
	

	cin >> n >> s1 >> s2;

    ll ans = 1;
    int flag = 0;
    
    rep(i,0,n){
        if(s1[i] == s2[i]){
            if(flag == 0){//1 -> 3
                if(i == 0)ans *= 3;
                else ans *= 2;
                ans = mod(ans);
            }else{//2 -> 1
                
            }
            flag = 0;
        }else{
            if(flag == 0){//1 -> 3
                if(i == 0){
                    ans *= 6;
                }else{
                    ans *= 2;
                }
                ans = mod(ans);
            }else{//2 -> 1
                ans *= 3;
                ans = mod(ans);
            }
            flag = 1;
            i++;
        }
        
    }

    P(ans);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int par[101], d[101];
priority_queue<PP, vector<PP>, greater<PP> > G;

void init(int n){
	for(int i = 1;i <= n;i++){
		par[i] = i;
		d[i] = 0;
	}
}

int find(int x){
	if(x == par[x])return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y)return ;
	if(d[x] < d[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(d[x] == d[y])d[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	int n, x, y, t;
	scanf("%d", &n);
	init(n);
	
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			scanf("%d", &t);
			if(t != -1)G.push(PP(t, P(i, j)));
		}
	}
	
	int ans = 0;
	while(!G.empty()){
		PP pp = G.top();G.pop();
		P p = pp.second;
		int cost = pp.first, from = p.first, to = p.second;
		if(same(from, to))continue;
		unite(from, to);
		ans += cost;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3280
n, m = (int(i) for i in input().split())
broken = [False]*(n+1)

for i in range(m):
  a = int(input())
  broken[a] = True

dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1
for i in range(n)[::-1]:
  if broken[i]:
    dp[i] = 0
    continue
  dp[i] = (dp[i+1] + dp[i+2]) % mod
print(dp[0])

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

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

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

	if (a == 0) {
		cout << 0 << endl;
		return 0;
	}
	else {
		ll ama = n % (a + b);
		ll sum = n/(a + b);
		ll ans = sum * a;
		if (ama < a)ans += ama;
		else ans += a;
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll unsigned long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
int main(){
	ll n, w;
	cin >> n >> w;
	ll mx = 1010 * n;
	ll dp[mx];
	memset(dp,w + 1,sizeof(dp));
	ll cnt = 0;
	dp[0] = 0;
	fop(i,0,n){
		ll x, y;
		cin >> x >> y;
		cnt += y;
		for(ll j = cnt;j >= y;j--){
			dp[j] = min(dp[j-y] + x, dp[j]);
		}
	}
	for(ll i = mx - 1; i>= 0;i --){
		if(dp[i] <= w){
			cout << i ;
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    string s, t;
    cin >>n >> s >> t;
    string ans = "";
    for(int i = 0; i < n; i++) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

char a[104];
char b[] = "keyence";

int main() {
    scanf("%s", a);
    int l = strlen(a);
    int L = 0;
    while (L < 7 && L < l && a[L] == b[L])
        L++;
    int R = 0;
    while (R < 7 && R < l && a[l-1-R] == b[6-R])
        R++;
    printf(L+R > 6 ? "YES\n" : "NO\n");

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    struct Point
    {
        public int X;
        public int Y;
        public Point(int x, int y)
        {
            X = x;
            Y = y;
        }
    }

    enum Direction
    {
        None,
        North,
        East,
        South,
        West
    }

    class Abc170F
    {
        public static void Main()
        {
            var hwk = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var height = hwk[0];
            var width = hwk[1];
            var k = hwk[2];

            var xy = Console.ReadLine().Split(' ').Select(i => int.Parse(i) - 1).ToArray();

            var y0 = xy[0];
            var x0 = xy[1];
            var y1 = xy[2];
            var x1 = xy[3];
            var map = new int[height][];
            for (int i = 0; i < height; i++)
                map[i] = Console.ReadLine().Select(c => c == '@' ? int.MinValue : int.MaxValue).ToArray();
            var points = new HashSet<Point>(new[] { new Point(x0, y0) });
            map[y0][x0] = 0;

            var cost = 0;
            while (points.Any())
            {
                cost++;
                var nextPoints = new HashSet<Point>();
                foreach (var p in points)
                {
                    if (p.X == x1 && p.Y == y1)
                    {
                        Console.WriteLine(cost - 1);
                        return;
                    }

                    void MoveTo(Direction direction)
                    {
                        int dx = 0, dy = 0;
                        switch (direction)
                        {
                            case Direction.North:
                                dy--;
                                break;
                            case Direction.South:
                                dy++;
                                break;
                            case Direction.East:
                                dx++;
                                break;
                            case Direction.West:
                                dx--;
                                break;
                        }

                        var next = p;
                        for (int i = 0; i < k; i++)
                        {
                            next.X += dx;
                            next.Y += dy;
                            if (next.X < 0 || width <= next.X ||
                                next.Y < 0 || height <= next.Y || map[next.Y][next.X] < cost)
                                return;
                            map[next.Y][next.X] = cost;
                            nextPoints.Add(next);
                        }
                    }
                    MoveTo(Direction.North);
                    MoveTo(Direction.South);
                    MoveTo(Direction.East);
                    MoveTo(Direction.West);
                }
                points = nextPoints;
            }
            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 57508
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s; cin >> s;
  int cnts[4] = {0};
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'S') cnts[0]++;
    else if (s[i] == 'N') cnts[1]++;
    else if (s[i] == 'W') cnts[2]++;
    else cnts[3]++;
  }

  if ((cnts[0] == 0 && cnts[1] > 0) || (cnts[0] > 0 && cnts[1] == 0) || (cnts[2] == 0 && cnts[3] > 0) || (cnts[2] > 0 && cnts[3] == 0)) No();
  else Yes();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


# Fenwick Tree
def init(n):
    global N, bit
    N = n
    bit = [0] * (N + 1)  # 1-origin


def bit_add(pos, val):
    assert pos > 0
    x = pos
    while x <= N:
        bit[x] += val
        x += x & -x  # (x & -x) = rightmost 1 = block width


def bit_sum(pos):
    ret = 0
    x = pos
    while x > 0:
        ret += bit[x]
        x -= x & -x
    return ret


def bit_bisect(lower):
    "find a s.t. v1 + v2 + ... + va >= lower"
    x = 0
    k = 1 << (N.bit_length() - 1)  # largest 2^m <= N
    while k > 0:
        if (x + k <= N and bit[x + k] < lower):
            lower -= bit[x + k]
            x += k
        k //= 2
    return x + 1


def main():
    # parse input
    N, Q = map(int, input().split())
    init(N)
    AS = map(int, input().split())
    for i, a in enumerate(AS):
        bit_add(i + 1, a)

    for _q in range(Q):
        a, b, c = map(int, input().split())
        if a == 0:
            bit_add(b + 1, c)
        else:
            print(bit_sum(c) - bit_sum(b))


# tests
T1 = """
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
15
7
25
6
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 122256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

int main() {
  ll N,K;
  cin>>N>>K;
  ll mod=1000000007;
  vector<ll> A(N);
  for(ll i=0;i<N;i++) {
    cin>>A[i];
  }
  
  vector<vector<ll>> dp(N+1,vector<ll>(K+1));
  for(ll i=0;i<=N;i++) {
dp[i][0]=1;
  }
  
  
  for(ll i=N-1;i>=0;i--) {
    vector<ll> r(K+1);
    r[0]=1;
    
for(ll j=1;j<=K;j++) {
  r[j]=(r[j-1]+dp[i+1][j])%mod;
  dp[i][j]=r[j];
  if(A[i]<j) {
dp[i][j]-=r[j-A[i]-1];
    dp[i][j]%=mod;
  }
}
  }
  
  if(dp[0][K]<0) {
dp[0][K]+=mod;
  }
  cout<<dp[0][K]<<endl;
}

  
  
  
  


Measured memory_bytes: 83096
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int N;
vector<vector<int>> G;

void dfs(vector<int> &dist, int v) {
    for (auto g : G[v]) {
        if (dist[g] == -1) {
            dist[g] = dist[v] + 1;
            dfs(dist, g);
        }
    }
}

int main() {
    cin >> N; G.resize(N);
    REP(i, 0, N - 1) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> d1(N, -1), d2(N, -1);
    d1[0] = 0;
    dfs(d1, 0);
    d2[N - 1] = 0;
    dfs(d2, N - 1);

    int b = 0;
    REP(i, 0, N) if (d1[i] <= d2[i]) b++;

    if (b > N - b) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

Measured memory_bytes: 14248
N=int(input())
M=list(map(int,input().split()))
S=list(map(int,input().split()))
K=[0 for i in range(N)]
for i in range(N):
  if M[i]>=S[i]:
    K[i]=S[i]
  else:
    if M[i+1]>=S[i]-M[i]:
      M[i+1]-=S[i]-M[i]
      K[i]=S[i]
    else:
      K[i]=M[i]+M[i+1]
      M[i+1]=0
print(sum(K))
      
      

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

int main(){
    int s[3], d[2];
    int ret = 1 << 20;
    cin >> s[0] >> s[1] >> s[2] >> d[0] >> d[1];
    for(int i=0;i<3;i++)
        for(int j=0;j<2;j++)
            ret = min(ret, s[i]+d[j]-50);
    cout << ret << endl;
}

Measured memory_bytes: 0