akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n, k;
	cin>>n>>k;
	string s;
	cin>>s;
	k--;
	s[k]+=32;
	cout<<s<<endl;
}

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

using namespace std;

int main(){
  long long int N,a[100010];
  
  
  cin >> N;
  
  for(int i=0;i<=N;i++)
    cin >> a[i];
  long long int temp = 0;
  long long int ans = 0;
  
 for(int i=0;i<=N;i++){
   ans += a[i];
 }
  
  if(N == 0){
    
    if(a[0] == 1){
    cout << "1" << endl;
    return 0;
    }
    
    else{
      cout << "-1" << endl;
      return 0;
    }
    
  }
  
  else if(N >0 && a[0] > 0){
    cout << "-1" << endl;
    return 0;
  }
    
  else{
  
  long long int res = 1;
  
  for(int i=0;i<=N;i++){
    temp += res;
    res -= a[i];
    ans -= a[i];
    
    if(res < 0){
      cout << "-1" << endl;
      return 0;
    }
    
    res = min(res*2 , ans);
    }
    
  
  
    cout << temp << endl;
      
  }
  
}     
    


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n;
  cin >> n;
  int b = 0;
  int bPrev = 0;
  int64_t sum = 0;
  for(int i=1;i<n;i++){
    cin >> b;
    if(i==1){
      bPrev = b;
      sum = b;
      continue;
    }
    sum += min(b,bPrev);
    bPrev = b;
  }
  sum += b;
  
  cout << sum << endl;
  return 0;
}




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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N; cin >> N;
  vector<ll> L(N);
  for (ll i = 0; i < N; i++) cin >> L[i];
  sort(L.begin(), L.end());
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    ll a = L[i];
    for (ll j = i + 1; j < N; j++) {
      ll b = L[j];
      if (a == b) continue;
      for (ll k = j + 1; k < N; k++) {
	ll c = L[k];
	if (b == c) continue;
	if (a + b <= c) continue;
	cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}



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


class programm
{
    static int res = 0;
    static long N = 0;
    static void Main(string[] args)
    {
        N = long.Parse(Console.ReadLine());
        // dfsの呼び出し
        // 全探索
        // 再帰関数
        dfs("0");
        Console.WriteLine(res);
    }

    static void dfs(string s)
    {
        if (long.Parse(s) > N) return;

        if (0 < s.Count(x => x == '7') && 0 < s.Count(x => x == '5') && 0 < s.Count(x => x == '3'))
        {
            res++;
        }

        foreach (char c in "753")
        {
            dfs(s + c);
        }
    }


}


Measured memory_bytes: 15308
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    vector<int> A_diff(N);
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N-1; i++) A_diff[i] = A[i+1] - A[i];
    A_diff[N-1] = K+A[0]-A[N-1];

    // resolve
    int max_distance = 0;
    for (auto d: A_diff) max_distance = max(max_distance, d);

    cout << K-max_distance << endl;

    return 0;
}


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

int main(){
 int a, b, c, t;
 cin >> a >> b >> c;

 if ( a > b ){ t = a; a = b; b = t; }
 if ( b > c ){ t = b; b = c; c = t; }
 if ( a > b ){ t = a; a = b; b = t; }

 cout << a << " " << b << " " << c << endl;

 return 0;
}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1e9
using namespace std;
typedef long long ll;

string s;

int main(int argc, char const *argv[]) {
  std::cin >> s;
  s[3] = '8';
  std::cout << s << '\n';
  return 0;
}


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

dp=[[float('inf')]*(n+1) for _ in range(m+1)]
dp[0][0]=0
for i in range(m):
    for j in range(n+1):
        if j-c[i]>=0:
            dp[i+1][j]=dp[i+1][j-c[i]]+1
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])

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


Measured memory_bytes: 43732
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

string solve(ll x){
    string ret="";
    while(x){
        ret+=('0'+x%2);
        x/=2;
    }
    while(ret.size()!=32)ret+="0";
    reverse(all(ret));
    return ret;
}

int main (){
    ll a,b;
    cin>>a>>b;
    cout<<solve(a&b)<<endl;
    cout<<solve(a|b)<<endl;
    cout<<solve(a^b)<<endl;
    
}



/*
00000000000000000000000000001000
11111111111111111111111111110111
00000000000000000000000000010000
00000000000000000000000000000100

00000000000000000000000000001000
11111111111111111111111111110111
00000000000000000000000000010000
*/



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

ll N, AI;
map<ll, ll> S;

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

	cin >> N;
	for (ll i = 0; i < N; i++) {
		cin >> AI;
		S[AI]++;
	}

	ll x = 0, y = 0, ans = 0;
	for (auto it = S.rbegin(); it != S.rend(); it++) {
		if (it->second >= 2) {
			if (x == 0) x = it->first;
			else {
				ans = max(ans, max(ans, x*it->first));
				break;
			}
		}
	}
	for (auto it = S.rbegin(); it != S.rend(); it++) {
		if (it->second >= 4) {
			ans = max(ans, it->first*it->first);
			break;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 6528
s[50],i,j,p,q;
main(n){for(;n=atoi(gets(s)),n;printf("%d\n",i)){
for(i=0;i<n;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=j++>5?0:(j-2&&j-4?8:6);q>1;q-=s[p++]);
}}

Measured memory_bytes: 532
# coding: utf-8

N, M = list(map(int, input().split()))
begin = 0 if N == 1 else 10**(N-1)

sc = [[i for i in map(int, input().split())] for j in range(M)]

for i in range(begin, 10**N):
    flag = True
    for j in range(M):
        if str(i)[sc[j][0]-1] != str(sc[j][1]):
            flag = False
            break

    if flag == True:
        print(i)
        break

if flag == False: print(-1)

Measured memory_bytes: 3064
def main():
    n = int(input())
    base = n
    f = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            f.append(i)
            if i * i != n:
                f.append(n // i)
        i += 1
    if n != 1:
        f.append(n)
    f.sort()
    answer = float("inf")
    for ff in f:
        answer = min(answer, max(len(str(ff)), len(str(base // ff))))
    if base == 1:
        answer = 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
N = int(input())
A1 = [int(_) for _ in input().split()]
A2 = [int(_) for _ in input().split()]
candies = A1[0]+sum(A2)
ans = candies
for i in range(N-1):
    candies += A1[i+1] - A2[i]
    ans = max(ans, candies)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==5 && b==5 && c==7){
    cout << "YES" << endl;
  } else if (a==5 && b==7 && c==5){
    cout << "YES" << endl;
  } else if (a==7 && b==5 && c==5){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main()
{
    string Sori,S;
    cin>>Sori;
    int N = Sori.size();
    long count = 0;
    for(int i=0;i< (1<<(N-1));++i){
        S = Sori;
        for(int j = N-1;j;--j){
            if(i &(1<<j-1)){
                long c;
                c = stol(S.substr(j,S.size()-j));
                S.erase(S.begin()+j,S.end());
                count += c;
            }
        }
        count += stol(S);
    }
    cout<<count<<endl;
}

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

void Count(int*count)
{
  (*count)++;
}

void Merge(int A[], int p,int q,int r,int B[],int *count)
{
  int t;
  int i,left, right,k;
  k = p; left = p; right = q+1;
  while(k <= r)
  {
    if(right>r) t = A[left++];
    else if(left>q) t = A[right++];
    else if(A[left]<=A[right]) t = A[left++];
    else t =A[right++];
    B[k++]=t;
    Count(count);
  }
  for (i=p;i<=r;i++) A[i]=B[i];
}

void Merge_Sort(int A[], int p, int r,int B[], int *count)
{
  if(p<r)
  {
    int q = (p+r)/2;
    Merge_Sort(A,p,q,B, count);
    Merge_Sort(A,q+1,r,B, count);
    Merge(A,p,q,r,B,count);
    //Count(count);
  }
}

int main()
{
  int r;
  scanf("%d", &r);
  int *count, A[r], B[r];
  count = malloc(sizeof(int));
  *count=0;
  for(int i=0;i<r;i++)
  {
    scanf("%d", &A[i]);
  }
  Merge_Sort(A,0,r-1,B, count);
  for(int i=0;i<r-1;i++)
  {
    printf("%d ", A[i]);
  }
  printf("%d",A[r-1]);
  printf("\n%d\n", *count);
  return 0;
}

Measured memory_bytes: 5660
//  cd Desktop/Atcoder
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<math.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int x[10]={},y[10]={};
long double ans=0.0;

void perm(int *array,int n,int i){
    int j,k,tmp;
    if (i<n) {
        for (j=i; j<=n; j++) {
            tmp=array[j];
            for (k=j; k>i; k--) array[k]=array[k-1];
            array[i]=tmp;
            perm(array, n, i+1);
            for (k=i; k<j; k++) array[k]=array[k+1];
            array[j]=tmp;
        }
    }else{
        for (j=1; j<n; j++) ans+=sqrt((double)(x[array[j]-1]-x[array[j+1]-1])*(x[array[j]-1]-x[array[j+1]-1])+(y[array[j]-1]-y[array[j+1]-1])*(y[array[j]-1]-y[array[j+1]-1]));
    }
}

int main(){
    int i,n,ways=1,array[10]={};
    scanf("%d",&n);
    rep(i,n){
        scanf("%d%d",&x[i],&y[i]);
        ways*=i+1;
        array[i+1]=i+1;
    }
    perm(array,n,1);
    printf("%.10Lf",ans/ways);
    return 0;
}


Measured memory_bytes: 2184
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define sort(v) sort(v.begin(),v.end()) 
#define pb push_back
/*

ll ar[1000000+9]={0}; 
void seiv() { 
ll n=1000000,i,j; 
ar[1]=1; 
for(i=4;i<=n;i+=2)ar[i]=1; 
for(i=3;i<=n;i+=2) 
{ if(ar[i]==0) 
{ for(j=i*i;j<=n;j+=i*2)ar[j]=1; }
 }
 
 }
*/
 int main(){
ll a,b,d,e,i,j,k,c,x, y=1,l=0;
cin>>a;
if(a>=30)cout<<"Yes\n";
else cout<<"No\n";

}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

bool check(int x) {
	int s = round(sqrt(x));
	return x == s * s;
}

const int N = 1100;
int n;
int d;
vector<int> v[N];


signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> d;
	for (int i = 0; i < n; ++i) {
		v[i].resize(d);
		for (int &j : v[i]) {
			cin >> j;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int s = 0;
			for (int ind = 0; ind < d; ++ind) {
				int t = v[i][ind] - v[j][ind];
				s += t * t;
			}
			ans += check(s);
		}
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<typename T> void debug_out(string name, T arg) { cerr<<name<<"="<<arg<<endl; }
template<typename T1, typename... T2> void debug_out(string name, T1 arg, T2... args) {
    cerr<<name.substr(0, name.find(','))<<"="<<arg<<", ";
    debug_out(name.substr(name.find(',') + 1), args...); }
#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion


int main() {
    FASTIO

    ll a,b,n; cin>>a>>b>>n;
    ll mx = 0;

    auto f = [&](ll x) {
        mx |= MAX(a*x/b - a * (x/b));
    };

    ll ub = min(n+1,(ll)1e6+5);
    FOR(i,ub)
        f(i);
    
    if(b-1 <= n)
        f(b-1);
    if(b/a <= n)
        f(b/a);
    f(n);

    cout<<mx<<endl;


}

Measured memory_bytes: 3640
N, Q = map(int, input().split())
s1 = input()
t = [0 for _ in range(N+1)]
for i in range(N):
    t[i+1] = t[i] + (1 if s1[i:i+2] == 'AC' else 0)
for i in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

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

int main(){
	int N,D;
	cin>>N>>D;
	
	int num;
	num=N/(2*D+1);
	
	if(N%(2*D+1)==0)
		cout<<num;
	else
		cout<<num+1;
	return 0;
	
	
}

Measured memory_bytes: 256
a = [int(input()) for i in range(5)]
m=1000
for i in range(5):
    tmp = a[i]
    for j in range(5):
        if i!=j:
            if a[j]%10==0: tmp+=a[j]
            else: tmp+=(a[j]+10-a[j]%10)
    m = min(m,tmp)
print(m)

Measured memory_bytes: 38256
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# ノード、重さ→価値
@njit('(i4,i4[:],i4[:])', cache=True)
def precompute(N, V, W):
    U = 10**5 + 10
    dp = np.zeros((1024, U), np.int32)
    for v in range(1, min(1024, N + 1)):
        p = v // 2
        dp[v] = dp[p]
        dp[v, W[v]:] = np.maximum(dp[v, W[v]:], dp[p, :-W[v]] + V[v])
        for i in range(1, U):
            dp[v][i] = max(dp[v][i], dp[v][i - 1])
    return dp

@njit('(i4,i4[:],i4[:],i4[:],i4[:])', cache=True)
def main(N, V, W, v, L):
    dp = precompute(N, V, W)
    values = np.empty(1024, np.int32)
    weights = np.empty(1024, np.int32)

    def solve(i, lim, values, weights, dp):
        if i < 1024:
            return dp[i][lim]
        values[0] = 0
        weights[0] = 0
        p = 0
        while i >= 1024:
            for j in range(1 << p):
                values[j + (1 << p)] = values[j] + V[i]
                weights[j + (1 << p)] = weights[j] + W[i]
            p += 1
            i >>= 1
        best = 0
        for n in range(1 << p):
            if weights[n] > lim:
                continue
            x = dp[i][lim - weights[n]] + values[n]
            best = max(best, x)
        return best

    Q = len(v)
    for i in range(Q):
        x = solve(v[i], L[i], values, weights, dp)
        print(x)

N = int(readline())
stdin = np.array(read().split(), np.int32)
V = np.zeros(N + 1, np.int32)
W = np.zeros(N + 1, np.int32)
V[1:] = stdin[:N + N:2]
W[1:] = stdin[1:N + N:2]
query = stdin[N + N + 1:]
v, L = query[::2], query[1::2]

main(N, V, W, v, L)

Measured memory_bytes: 517360
#include<stdio.h>
int main(){
	char s[9999];
	scanf("%s",s);
	int a=0,b=0;
	for(int i=0;s[i];i++){
		if(s[i]=='N')a|=1;else
		if(s[i]=='S')a|=2;else
		if(s[i]=='E')b|=1;else
		if(s[i]=='W')b|=2;
	}
	puts(a==1||a==2||b==1||b==2?"No":"Yes");
	return 0;
}

Measured memory_bytes: 128
#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 namespace std;
using ll = long long;

int main() {
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	ll jump = x / d;
	ll ans = 0;
	if (jump < k) {
		ans = x;
		if ((1e15 / jump) < d) {
		//	if (jump >= d) {
				rep(i,jump)ans -= d;
				if ((k - jump) % 2 == 1)ans -= d;
			
		}
		else {
			ans = x - (jump * d);
			if ((k - jump) % 2 == 1)ans -= d;
		}
	}else{
		if ((1e15 / jump) < d) {
			if (jump >= d) {
				rep(i, jump)ans = min(ans, abs(x - (d * (i + 1))));
			}
			else {
				rep(i, d)ans -= jump;
			}
		}else ans = (abs(x - (k * d)));
	}
	cout << abs(ans) << endl;
	return 0;
}



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

using namespace std;

#define MOD 1000000007
#define N 100005
#define M 30
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

int a[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, i, last, ans, cur;
	cin>>n;
	for(i=0; i<n; i++){
		cin>>a[i];
	}
	last = a[0]; ans = 0, cur = 0;
	for(i=1; i<n; i++){
		if(last >= a[i]){
			cur++;
			last = a[i];
		}
		else{
			ans = max(ans, cur);
			last = a[i];
			cur = 0;
		}
	}
	ans = max(ans, cur);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define ll long long
#define inf 0x3f3f3f3f

using namespace std;

int n;

struct node{
    ll cost,r;
    friend bool operator < (node a,node b){
        return a.r<b.r;
    }
}A[200050];

int main(){
    cin>>n;
    FOR(i,1,n){
        scanf("%lld%lld",&A[i].cost,&A[i].r);
    }
    ll T=0;
    bool ok=true;
    sort(A+1,A+1+n);
    FOR(i,1,n){
        T+=A[i].cost;
        if(T>A[i].r){
            ok=false;
            break;
        }
    }
    if(ok)puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3328
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



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



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
#define N 100000
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll set_seq(ll *ary,ld rate,ll tax){
	ll i=0;
	if(tax/rate-static_cast<ll>(tax/rate)==0.00)
		ary[0] = static_cast<ll>(tax/rate);
	else
		ary[0] = static_cast<ll>(tax/rate+1);
	while(rate*(ary[i])<=tax+1){
		i++;
		ary[i]=ary[0]+i;
	}
	return i;
}

const ll KEY_NOT_FOUND = -1;
ll binary_search(ll *ary,ll key,ll imin,ll imax){
	if(imin > imax)
		return KEY_NOT_FOUND;
	else{
		ll imid = imin + (imax-imin)/2;
		if(ary[imid] > key)
			return binary_search(ary,key,imin,imid-1);
		else if(ary[imid] < key)
			return binary_search(ary,key,imid+1,imax);
		else
			return imid;
	}
}

int main(){
	ll a,b;
	cin >> a >> b;
	ll bb[10];
	bb[0] = 10*b;
	arep(1,i,10){
		bb[i] = 10*b+i;
	}
	ll aa[N];
	ll n = set_seq(aa,0.08,a);
	ll i=0;
	while(binary_search(bb,aa[i],0,9)==KEY_NOT_FOUND){
		if(i==n-1){
			cout << KEY_NOT_FOUND << endl;
			return 0;
		}
		i++;
	}	
	cout << bb[binary_search(bb,aa[i],0,n)] << endl;
}

Measured memory_bytes: 256
# Aizu Problem ITP_1_8_B: Sum of Numbers
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def digit_sum(n):
    s = 0
    while n > 0:
        s += n % 10
        n //= 10
    return s


while True:
    n = int(input())
    if n == 0:
        break
    print(digit_sum(n))

Measured memory_bytes: 7764
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
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;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n;
  cin >> n;
  int a[n+1]={0};
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  int cur = 1000;
  for(int i=2;i<=n;i++){
    if(a[i]>a[i-1]){
      int stk = cur/(a[i-1]);
      int rem = cur%(a[i-1]);
      cur = rem+stk*a[i];
    }
  }
  cout << cur << endl;


return 0;
}
///....


Measured memory_bytes: 3644
N = int(input())
dp = [[0 for i in range(3)]for j in range(N+1)]
a = []
for i in range(N):
    a.append(list(map(int,input().split())))
for i in range(N):
    for j in range (3):
        for k in range(3):
            if j !=k:
                dp[i+1][k] = max(dp[i+1][k],(dp[i][j]+a[i][k]))
print(max(dp[-1][0],dp[-1][1],dp[-1][2]))


Measured memory_bytes: 74716
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
	VI a(n); rep(i,n) cin>>a[i];
	vector<pair<int,PII>> q;
	rep(i,n){
		if(i-a[i]>0) q.PB(MP(i-a[i],MP(i,1)));
		if(i+a[i]<INF) q.PB(MP(i+a[i],MP(i,0)));
	}
	sort(ALL(q));
	ll ans=0, tmp=0;
	int m = q.size();
	int prev_num = 0, next_num=1;
	rep(i,m){
		next_num=q[i].first;
		if(prev_num==next_num){
			if(q[i].second.second==0) tmp++;
			else ans+=tmp;
		}else{
			if(q[i].second.second==0) tmp=1;
			else tmp=0;
		}
		prev_num = next_num;
		// cerr<<q[i].first SP q[i].second.first SP q[i].second.second SP tmp SP ans <<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 10352
date0=input().split(" ")
A=int(date0[0])
V=int(date0[1])
date1=input().split(" ")
B=int(date1[0])
W=int(date1[1])
T=int(input())
if V<=W:
    print("NO")
else:
    C=V-W
    D=A-B
    if D<0:
        D=-D
    if D%C==0:
        E=D/C
    else:
        E=(D-D%C)/C+1
    if T>=E:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9208
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a[4];
	int h=0;
	for(int i=0;i<4;i++){
		cin>>a[i];
		h+=a[i];
	}
	cout<<h/60<<endl;
	cout<<h-h/60*60<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <assert.h>
using namespace std;

#define N 5000001
#define mod 998244353
#define ll long long

int fac[N], invFac[N];
int mypow(int x, int c) {
	int ret = 1;
	while (c > 0) {
		if (c & 1) {
			ret = (ll)ret*x%mod;
		}
		c /= 2;
		x = (ll)x*x%mod;
	}
	return ret;
}
int combi(int n, int c) {
	int ret = (ll)fac[n] * invFac[c] % mod;
	ret = (ll)ret*invFac[n - c] % mod;

	return ret;
}
int add(int x, int y) {
	int ret = x + y;
	if (ret < 0) {
		ret += mod;
	}
	if (ret >= mod) {
		ret -= mod;
	}
	return ret;
}
int mul(int x, int y) {
	return (ll)x*y%mod;
}
void solve() {
	int n, m; scanf("%d %d", &n, &m);
	fac[0] = 1; invFac[0] = 1;
	for (int i = 1; i <N; ++i) {
		fac[i] = (ll)fac[i - 1] * i%mod;
		invFac[i] = mypow(fac[i], mod - 2);
	}
	int ret = 0;
	int maxOdd = min(n, m);
	for (int odd = 0; odd <= maxOdd; ++odd) {
		int sum = 3 * m - odd;
		if (sum % 2 == 0) {
			sum /= 2;
			int tmp = combi(sum + n - 1, n - 1);
			tmp = mul(tmp, combi(n, odd));
			ret = add(ret, tmp);
		}
	}
	for (int maxSum = 2 * m + 1; maxSum <= 3 * m; ++maxSum) {
		int rem = 3 * m - maxSum;
		int tmp = combi(rem + n - 2, n - 2);
		tmp = (ll)tmp*n%mod;
		ret = add(ret, -tmp);
	}
	printf("%d\n", ret);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	solve();
	return 0;
}

Measured memory_bytes: 39296
#include <iostream>
#include <unordered_map>

using namespace std;
using ll = long long;

int main() {
    ll N;
    cin >> N;

    unordered_map<ll, int> hash;
    for (int n = 0; n < N; n++) {
        ll A;
        cin >> A;

        auto itr = hash.find(A);
        if (itr == hash.end()) { hash[A] = 1; }
        else { hash.erase(itr); }
    }

    cout << hash.size() << endl;

    return 0;
}

Measured memory_bytes: 4388
H, W, M = map(int, input().split())
Hdst = [0]*H
Wdst = [0]*W
DST = [[0] * M for i in range(2)]
for i in range(M):
    hi, wi = map(int, input().split())
    Hdst[hi-1] += 1
    Wdst[wi-1] += 1
    DST[0][i] = hi-1
    DST[1][i] = wi-1

Hdstmax = max(Hdst)
Wdstmax = max(Wdst)
Hbomb = [i for i, x in enumerate(Hdst) if x == Hdstmax]
Wbomb = [i for i, x in enumerate(Wdst) if x == Wdstmax]

Hchk = [False]*H
Wchk = [False]*W
for i in Hbomb:
    Hchk[i] = True
for i in Wbomb:
    Wchk[i] = True

tmp = 0
for i in range(M):
    if Hchk[DST[0][i]] and Wchk[DST[1][i]]:
        tmp += 1

if len(Hbomb)*len(Wbomb) == tmp:
    print(Hdstmax + Wdstmax - 1)
else:
    print(Hdstmax + Wdstmax)


Measured memory_bytes: 65680
import sys
input = sys.stdin.readline

def main():
    h,w,n = map(int,input().split())
    dg = 10**10
    d = dict()

    def f(z):
        x,y = divmod(z,dg)
        if 2 <= x <= h-1 and 2 <= y <= w-1:
            return True
        else:
            False

    for i in range(n):
        a,b = map(int,input().split())
        
        if f((a-1)*dg + b-1):
            if (a-1)*dg + b-1 in d:
                d[(a-1)*dg + b-1] += 1
            else:
                d[(a-1)*dg + b-1] = 1
        
        if f((a-1)*dg + b):
            if (a-1)*dg + b in d:
                d[(a-1)*dg + b] += 1
            else:
                d[(a-1)*dg + b] = 1
        
        if f((a-1)*dg + b+1):
            if (a-1)*dg + b+1 in d:
                d[(a-1)*dg + b+1] += 1
            else:
                d[(a-1)*dg + b+1] = 1

        if f((a)*dg + b-1):
            if (a)*dg + b-1 in d:
                d[(a)*dg + b-1] += 1
            else:
                d[(a)*dg + b-1] = 1
        
        if f(a*dg + b):
            if a*dg + b in d:
                d[a*dg + b] += 1
            else:
                d[a*dg + b] = 1
        
        if f((a)*dg + b+1):
            if (a)*dg + b+1 in d:
                d[(a)*dg + b+1] += 1
            else:
                d[(a)*dg + b+1] = 1
        
        if f((a+1)*dg + b+1):
            if (a+1)*dg + b+1 in d:
                d[(a+1)*dg + b+1] += 1
            else:
                d[(a+1)*dg + b+1] = 1
        
        if f((a+1)*dg + b):
            if (a+1)*dg + b in d:
                d[(a+1)*dg + b] += 1
            else:
                d[(a+1)*dg + b] = 1
        
        if f((a+1)*dg + b-1):
            if (a+1)*dg + b-1 in d:
                d[(a+1)*dg + b-1] += 1
            else:
                d[(a+1)*dg + b-1] = 1
        
        
        
        
    res = [0]*10

    for e in d:
        res[d[e]] += 1

    res[0] = (h-2)*(w-2)-sum(res)

    for e in res:
        print(e)

if __name__ == "__main__":
    main()

Measured memory_bytes: 104304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> v(n);
  map <ll, ll> score;
  set <ll> s;
  rep(i, n) {
    cin >> v.at(i);
    s.insert(v.at(i));
    if (score.count(v.at(i))) {
      score.at(v.at(i))++;
    } else {
      score[v.at(i)] = 1;
    }
  }
  ll res = 0;
  for (auto value : s) {
    ll tmp = score.at(value);
    res += tmp*(tmp-1)/2;
  }
  rep(i, n) {
    ll ans = res;
    ll tmp = score.at(v.at(i));
    ans -= tmp*(tmp-1)/2;
    ans += (tmp-1)*(tmp-2)/2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 17024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  int i=0;
  while(true) {
    if(s[i].size()==0) {
      cout << char('A'+i) << endl;
      return 0;
    }
    char c=s[i][0];
    s[i].erase(0,1);
    i=c-'a';
  }
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	reverse(a, a + n);
	for(int i = 0; i < n; i += 2) cout << a[i] << ' ';
	for(int i = n - 1 - n % 2; i >= 0; i -= 2) cout << a[i] << ' ';
	cout << endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll n, k; cin >> n >> k; k--;
    ll h[n]; rep(i,0,n) cin >> h[i];

    sort(h,h+n);
    ll res = h[k] - h[0];
    rep(i,0,n-k){
        res = min(res, h[i+k] - h[i]);
      	//cout << res << " " << h[i+k]<< ednl;
    }
    cout << res << endl;

}


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

int main(){
  int N;
  cin >> N;
  
  vector<char> S(N);
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  
  vector<int> LW(N),RE(N);
  
  for(int i = 1; i < N; i++){
    if(S[i-1] == 'W'){
      LW[i] = LW[i-1] + 1;
    }
    else{
      LW[i] = LW[i-1];
    }
  }
  
  for(int i = N-2; i >= 0; i--){
    if(S[i+1] == 'E'){
      RE[i] = RE[i+1] + 1;
    }
    else{
      RE[i] = RE[i+1];
    }
  }
  
  int sum;
  int m = 300000;
  for(int i = 0; i < N; i++){
    sum = LW[i] + RE[i];
    if(sum < m){
      m = sum;
    }
  }
  cout << m << endl;
}

Measured memory_bytes: 2944
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine();
            if (r[2] == r[3] && r[4] == r[5] )
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

#define  MAX 3000

int main(int argc, char *argv[]) {
	
	int in[MAX][2] = {{ 0 }};
	int tmp = 0;
	int i = 0;
	
	do{
		fscanf(stdin, "%d %d", &in[i][0], &in[i][1]);
		if(in[i][0] > in[i][1]) {
			tmp = in[i][0];
			in[i][0] = in[i][1];
			in[i][1] = tmp;
		}
		i++;
	}while(in[i-1][0] != 0 || in[i-1][1] != 0);
	
	i = 0;
	while(in[i][0] != 0 || in[i][1] != 0) {
		fprintf(stdout, "%d %d\n", in[i][0], in[i][1]);
		i++;
	}
	
	return 0;
	
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

void solve(int x){
  bool flags[x+1];
  memset(flags,false,sizeof(flags));
  flags[x] = true;
  int ans = 0;
  while(x > 9){
    string tt = toString(x);
    int n = tt.size();
    int xx = 0;
    rep(i,n-1){
      string t1,t2="";
      t1 = tt.substr(0,i+1);
      if(i+1 < n) t2 = tt.substr(i+1);
      // cout << t1 << " " << t2 << endl;
      int tmp = toInt(t1);
      if(t2 != "") tmp *= toInt(t2);
      xx = max(tmp,xx);
    }
    if(flags[xx] == true){
      cout << -1 << endl;
      return;
    }
    flags[xx] = true;
    x = xx;
    ans++;
  }
  cout << ans << endl;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  rep(i,t){
    int x;
    cin >> x;
    solve(x);
  }
  return 0;
}



Measured memory_bytes: 4208
// verified
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_A&lang=jp
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=jp

#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

class DAG {
public:
    DAG(const vector<vector<int>> &edges)
    : tsort_done(false), acyc(false) {
        V = edges.size();
        E.resize(V);
        for(int i = 0; i < V; ++i) {
            for(int to : edges[i]) {
                E[i].push_back(to);
            }
        }
    }

    bool tsort() {
        vector<int> indeg(V, 0);
        for(int i = 0; i < V; ++i) {
            for(int to : E[i]) ++indeg[to];
        }

        queue<int> done;
        for(int i = 0; i < V; ++i) {
            if(indeg[i] == 0) done.push(i);
        }

        while(!done.empty()) {
            int cur = done.front();
            done.pop();
            order.push_back(cur);
            for(int to : E[cur]) {
                --indeg[to];
                if(indeg[to] == 0) done.push(to);
            }
        }

        tsort_done = true;
        acyc = (order.size() == V);
        return acyc;
    }

    int longest_path() {
        if(!tsort_done) tsort();
        if(!acyc) return -1;

        dp.resize(V);
        for(int i = 0; i < V; ++i) {
            int cur = order[i];
            for(int to : E[cur]) {
                dp[to] = max(dp[to], dp[cur] + 1);
            }
        }

        return *max_element(begin(dp), end(dp));
    }

    bool acyclic() {
        if(!tsort_done) tsort();
        return acyc;
    }

    int operator[](int i) {
        if(!tsort_done) tsort();
        return order[i];
    }

private:
    int V;
    vector<vector<int>> E;
    vector<int> order;
    bool tsort_done;
    bool acyc;
    vector<int> dp;
};



#include <iostream>
int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<int>> edges(V);
    while(E--) {
        int s,t;
        cin >> s >> t;
        edges[s].push_back(t);
    }

    DAG dag(edges);
    cout << !dag.acyclic() << endl;
}



// function only
bool tsort(vector<int> &order, const vector<vector<int>> &edges) {
    int V = edges.size();

    vector<int> indeg(V, 0);
    for(int i = 0; i < V; ++i) {
        for(int to : edges[i]) ++indeg[to];
    }

    queue<int> done;
    for(int i = 0; i < V; ++i) {
        if(indeg[i] == 0) done.push(i);
    }

    while(!done.empty()) {
        int cur = done.front();
        done.pop();
        order.push_back(cur);
        for(int to : edges[cur]) {
            --indeg[to];
            if(indeg[to] == 0) done.push(to);
        }
    }

    return order.size() == V;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

vector<int> Zalgorithm(const vector<ll> &s){
    int n=s.size();
    vector<int> z(n);
    z[0]=n;
    int i=1,j=0;
    while(i<n){
        while(i+j<n&&s[j]==s[i+j]) ++j;
        z[i]=j;
        if (j==0){++i; continue;}
        int k=1;
        while(i+k<n&&k+z[k]<j) z[i+k]=z[k],++k;
        i+=k,j-=k;
    }
    return z;
}

vector<int> LCP(const vector<ll> &s,const vector<ll> &t){
    vector<ll> u=s;
    u.insert(u.begin(),all(t));
    vector<int> Z=Zalgorithm(u);
    for (auto &i:Z) chmin(i,(int)t.size());
    return vector<int>(Z.begin()+t.size(),Z.end());
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N),b(N),c(2*N),d(N);
    rep(i,N) cin >> a[i];
    rep(i,N) cin >> b[i];
    rep(i,N) c[i]=a[i]^a[(i+1)%N],c[i+N]=c[i];
    rep(i,N) d[i]=b[i]^b[(i+1)%N];
    vector<int> v=LCP(c,d);
    rep(k,N){
        if (v[k]>=N) cout << k << ' ' << (a[k]^b[0]) << endl;
    }
}

Measured memory_bytes: 18120
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


//for(i=0; i<N; i++) cin >> a[i];


int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  
  k=0;
  while(N>26*(pow(26, k)-1)/25) k++;
  N-=26*(pow(26, k-1)-1)/25;
  N--;
  
  string s="";
  while(N>0) {
    s=(char)(N%26+'a')+s;
    N/=26;
  }
  
  s=string(k-s.size(), 'a')+s;
  pt(s);
  
}


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

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(i % 3 != 0 && i % 5 != 0)
        {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s; std::cin >> s;
	// cout << s << ' ' << s.size() << ' ' << s[0] << endl;
	//それで、ばん。
	int num;
	num = 0;
	if (s[0] == '1') {
		num++;
	}
	if (s[1] == '1') {
		num++;
	}
	if (s[2] == '1') {
		num++;
	}
	cout << num << "\n";
	std::cin >> s;
}

Measured memory_bytes: 256
while 1:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    else:
        for i in range(H):
            for j in range(W):
                if i==0 or i==H-1 or j==0 or j==W-1:
                    print("#",end="")
                else:
                    print(".",end="")
            print("")
        print("")


                       
                  

              
   
       

              
          

               

       
   
    


Measured memory_bytes: 7012