akhauriyash/Code-Regression huggingface dataset:
from collections import deque

N = int(input())
X = [list(map(int, input().split())) for _ in range(N - 1)]

edges = [[] for _ in range(N + 1)]
for u, v in X:
    edges[u].append(v)
    edges[v].append(u)


def bfs(s, x):
    inf = 10 ** 9 + 7
    d = [inf] * (N + 1)
    d[s] = 0
    q = deque([s])
    while q:
        u = q.popleft()
        for v in edges[u]:
            if d[v] != inf:
                continue

            d[v] = d[u] + 1
            if v != x:
                q.append(v)

    return d


d1 = bfs(1, N)
d2 = bfs(N, 1)

cnt = 0
for i in range(1, N + 1):
    cnt += d1[i] <= d2[i]

if cnt > N // 2:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 79064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define lb lower_bound
#define right puta
using namespace std;
using namespace __gnu_pbds;
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9+7;
const int MAXN = 2e5+5;
const int MAXV = 1e6+5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

int32_t main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d}) << endl;
}

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

const int maxn = 100;
int n, m;
int f[maxn];
int main() {
  cin>>n>>m;
  for (int i=1; i<=m; i++) {
    int u,v;
    cin>>u>>v;
    f[u]++;
    f[v]++;
  }
  
  for (int i=1; i<=n; i++) {
    cout<<f[i]<<"\n";
  }
  return 0;
  
}

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

int main(){
  long long N, count = 0;
  unordered_map<string, int> mp;
  
  cin >> N;
  for(int i=0; i<N; i++){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    
    count += mp[s];
    mp[s]++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}



int main(){

  int N,K;
  cin >> N >> K;

  vector<ll> a(N);
  FOR(i,0,N)cin >> a[i];
  SORT(a);
  ll ans = 0;
  FOR(i,0,K){
    ans += a[i];
  }
  cout << ans << endl;

}



Measured memory_bytes: 3632
H, W = map(int,input().split())
S = ["."+input()+"." for k in range(H)]
S = ["."*(W+2)] + S + ["."*(W+2)]

A = [[""]*W for _ in range(H)]
for h in range(1,H+1):
    for w in range(1,W+1):
        if S[h][w] == "#":
            A[h-1][w-1] = "#"
        else:
            temp = 0
            for dx in range(-1,2):
                for dy in range(-1,2):
                    if S[h+dy][w+dx] == "#":
                        temp += 1
            A[h-1][w-1] = str(temp)
for e in A:
    print("".join(e))


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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        if (N == 1)
        {
            Console.WriteLine("Hello World");
            return;
        }

        var A = int.Parse(Console.ReadLine());
        var B = int.Parse(Console.ReadLine());

        Console.WriteLine(A + B);
    }

}



Measured memory_bytes: 11092
N = int(input())
S = input()

Ns = int(N/2)
flag = 0

if N%2 == 1:
	flag = 1
else:
	for i in range(Ns):
		if S[i] != S[i+Ns]:
			flag = 1
			break
		
if flag == 1:
	print("No")
else:
	print("Yes")

Measured memory_bytes: 3060
loop{
 a,op,b = STDIN.gets.split(' ')
 a = a.to_i
 b = b.to_i

  case op
  when "+"
    puts a + b

  when "-"
    puts a - b
  when "*"
    puts a * b
  when "/"
    puts a / b
  else
    break
  end
}

Measured memory_bytes: 8636
import sys
input = sys.stdin.readline
from collections import deque

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def main():
    N = int(input())
    edges = list(readlines(N-1))
    tree = {i:[] for i in range(N)}
    for a, b in edges:
        tree[a].append(b)

    ans = {}
    frontier = deque([(1,0)])
    while frontier:
        u, prev_color = frontier.pop()
        if tree.get(u) is None:
            continue
        for i, v in enumerate(tree[u], 1):
            color = i if i != prev_color else len(tree[u])+1
            ans[u, v] = color
            frontier.appendleft((v, color))

    print(max(ans.values()))
    for u,v in edges:
        print(ans[u,v])


    
main()

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

int main()
{
  int x;
  cin >> x;
  long long sol = 0;
  sol = x / 500 * 1000;
  x = x % 500;
  sol += x - x % 5;
  cout << sol;
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
  long long int i,c=0;
  string s,s1;
  cin>>s;
  cin>>s1;
  for(i=0;i<s.size();i++)
  {
    if(s[i]==s1[i])c++;
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
  short n,a[100], count=0;
  std::cin>>n;
  for(short i=0;i<n;i++){
    std::cin>>a[i];
  }
  short max = a[0];
  for(short i=0;i<n;i++){
    if(a[i]>=max){
      count++;
      max = a[i];
      //std::cout<<max<<" "<<a[i]<<std::endl;
    }
  }
  std::cout<<count;
  return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k, q;
	cin >> n >> k >> q;

	vector<int> a(n);

	for(int i = 0; i < q; i++) {
		int x;
		cin >> x;
		x--;
		a[x]++;
	}

	for(int i = 0; i < n; i++) {
		if(q - a[i] >= k) {
			cout << "No\n";	
		}
		else cout << "Yes\n";
	}


	return 0;
}


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
#define mxn 200005
using namespace std;


int n,m,cnt = 0,ans = 0;
vector<int> a[mxn];
vector<int> vis(mxn);
map<pair<int,int>,int> mp;

void dfs(int u)
{
    queue<int> q;
    q.push(u);
    cnt = 1;
    vis[u] = 1;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(auto i : a[u]){
            if(vis[i] == 0){
                q.push(i);
                vis[i] = 1;
                cnt++;
            }
        }
    }
}

void solve(){
    cin >> n >> m ;
    for(int i = 0; i < m; i++){
        int u,v;
        cin >> u >> v;
        if(mp[{u,v}] == 1);
        else{
            a[u].pb(v);
            a[v].pb(u);
            mp[{u,v}] = 1;
            mp[{v,u}] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        if(vis[i] == 0){
            cnt = 0;
            dfs(i);
            ans = max(ans,cnt);
        }
    }
    cout << ans ;
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 43584
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n;
    scanf("%d",&n);
    vector<ll> h(n,0);
    for (int i = 0; i<n; i++) scanf("%lld",&h[i]);
    bool flag = true;
    ll max_val = h[0];
    for (int i = 1; i < n; i++) {
        if(max_val - h[i] > 1) {
            flag = false;
            break;
        }
        max_val = max(max_val, h[i]);
    }
    if (flag) printf("Yes\n");
    else printf("No\n");
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		if (i + 1 < n) {
			dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		}
		if (i + 2 < n) {
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
		}
	}
	cout << dp[n - 1];
}



Measured memory_bytes: 3988
#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>;

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  cout << (s < t ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#include<iostream>

#include<math.h>

using namespace std;

int main(){

  long long n,mod=1e9+7;

  cin>>n;

  long long i,j,ans=1,a,k=sqrt(i);

  long long vec[n+10]={0};

  for(i=0;i<=n;i++){

   a=i;k=sqrt(a);

   for(j=2;j<=k;j++){

    while(a%j==0){

      vec[j]++;

      a/=j;

    }

   }

   if(a!=1)vec[a]++;

  }

  for(i=2;i<=n;i++){

    ans*=vec[i]+1;

    ans%=mod;

   //cout<<i<<" "<<vec[i]<<" "<<ans<<endl;

  }

  cout<<ans<<endl;

return 0;}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}

		vector<char> c(n);
		for (int i = 0; i < n; i++) {
			scanf(" %c ", &c[i]);
		}

		vector<int> freq(26);
		for (int i = 0; i < n; i++) {
			freq[c[i] - 'A']++;
		}

		int mx = max_element(freq.begin(), freq.end()) - freq.begin();
		int cnt = count(freq.begin(), freq.end(), freq[mx]);
		if (cnt != 1) {
			cout << "TIE" << endl;
			continue;
		}

		vector<int> f(26);

		for (int i = 0; i < n; i++) {
			f[c[i] - 'A']++;
			bool ok = true;
			for (int j = 0; j < 26; j++) {
				if (mx != j) {
					if (f[j] + (n - i - 1) >= f[mx]) {
						ok = false;
					}
				}
			}
			if (ok) {
				cout << (char)(mx + 'A') << " " << i + 1 << endl;
				break;
			}
		}
	}
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;

  vector<int> a(N);

  for(int i=0;i<Q;i++) {
    int answered;
    cin >> answered;

    a[answered-1]++;
  }

  for(int i=0;i<N;i++) {
    if(K - (Q - a[i]) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
import sys
import numpy as np

h, n = map(int, input().split())
ab = np.array(sys.stdin.read().split(), dtype=np.int64)
aaa = ab[0::2]
bbb = ab[1::2]

dp = np.zeros(10001, dtype=np.int64)
for i in range(1, h + 1):
    dp[i] = (dp[i - aaa] + bbb).min()
print(dp[h])


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

int main() {
    ll ans = 0;
    int N;
    cin >> N;
    rep(i, N + 1) {
        if(i != 0) {
            ll n = N / i;
            ans += n * (i + i * n) / 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3584
let input = require('fs').readFileSync('/dev/stdin', 'utf8')
// let input = require('fs').readFileSync('./sample_a.txt', 'utf8')
.split(/\n| /)
.map(item => parseInt(item))
.slice(0,-1)

const [D, T, S] = input.map(item => parseInt(item))

let now = 0
let time = 0
while(now < D){
    now += S
    time++
}
console.log(time <= T ? "Yes" : "No")

Measured memory_bytes: 29688
import bisect

n = int(input())
l = list(map(int, input().split()))

l.sort()

ans = 0
for i in range(n):
  for j in range(i + 1, n):
    k = bisect.bisect_left(l, l[i] + l[j])
    if k > j:
      ans += k - j - 1
    else:
      pass


print(ans)




Measured memory_bytes: 42972
#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)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main()
{
  int N,L;
  cin >> N >> L;
  vector<int> taste(N);
  REP(i,0,N) taste[i] = L + i;  // iがずれてる

  // N個のリンゴ全てを材料としてできるアップルパイの味
  int tasteSum = 0;
  REP(i,0,N) tasteSum += taste[i];

  int minv = INF; // 「味」の差の絶対値のmin
  int mini = -1;  // 最小を与えるリンゴの番号
  REP(i,0,N) { // リンゴiを食べない
    // 差はi番目のリンゴの味
    if (abs(taste[i]) < minv) {
      minv = abs(taste[i]);
      mini = i;
    }
  }
  // cout << mini << endl;

  // 食べていないN−1 個のリンゴを材料としてできるアップルパイの「味」
  int ans = tasteSum - taste[mini];
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int data;
	int point[100] = {0};
	int i;
	int max = 0;
	int num;
	
	while(scanf("%d", &data) != EOF){
		point[data-1]++;
	}
	for(i = 99; i >= 0; i--){
		if(max <= point[i]){
			max = point[i];
			num = i;
		}
	}
	printf("%d\n", num+1);
	
	for(i = num+1; i < 100; i++){
		if(max == point[i]){
			printf("%d\n", i+1);
		}
	}
	
	return 0;
}

Measured memory_bytes: 592
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
//#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    string s;
    cin >> s;
    if (s == "RRR") {
        put(3);
        return;
    }
    if (s == "SSS") {
        put(0);
        return;
    }
    if (s == "RRS" || s == "SRR") {
        put(2);
    } else {
        put(1);
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


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

#define N 100

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

  int G[N + 1][N + 1];
  for ( int i = 0; i <= n; i++ ) {
    for ( int j = 0; j <= n; j++ ) {
      G[i][j] = 0;
    }
  }

  for ( int i = 1; i <= n; i++ ) {
    int a, b;
    cin >> a >> b;
    for ( int j = 1; j <= b; j++ ) {
      int c;
      cin >> c;
      G[a][c] = 1;
    }
  }

  for ( int i = 1; i <= n; i++ ) {
    for ( int j = 1; j <= n; j++ ) {
      if ( j > 1 ) printf(" ");
      printf("%d", G[i][j]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int sum=0;
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1]){
			sum++;
		}
	}
	sum++;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  
  Q[tail] = x;
  
  if(tail + 1 == LEN){
    tail = 0;
  }
  else {
    tail = tail + 1;
  }
  
}

P dequeue(){
  
  P x;
  
  x = Q[head];
  if(head + 1 == LEN){
    head = 0;
  }
  else {
    head = head + 1;
  }
  return x;
  
}


int main(){
  int c=0;
  int i, q,sum=0;

  scanf("%d %d", &n, &q);
  
  head = 1;
  tail = n+1;
  
  for (i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  
  for(i = 1; i <= n+c; i++){
    
    
    if(q >= Q[head].t){
      
      sum += Q[head].t;
      
      printf("%s %d\n",Q[head].name,sum);
      
      dequeue();
    }
    
    else {
      
      sum += q;
      
      Q[head].t = Q[head].t - q;
      enqueue(Q[head]);
      dequeue();
   
      c++;
    }
    
  }
  return 0;
}

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

string x;

int solve();

int main() {
  cin >> x;

  cout << solve() << endl;
  return 0;
}

int solve() {
  stack<char> st;
  int xsize = x.size();
  for(int i = 0; i < xsize; ++i) {
    if(st.size() > 0 && st.top() == 'S' && x[i] == 'T')
      st.pop();
    else
      st.push(x[i]);
  }
  return st.size();
}

Measured memory_bytes: 644
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int K;
    string S;
    cin >> K;
    cin >> S;
    if(S.size() <= K) {
        cout << S << endl;
    } else {
        rep(i, K) { cout << S[i]; }
        cout << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s; cin >> s;
    ll k; cin >> k;

    int n;
    int m = sz(s);
    if (k <= m) n = k;
    else n = m;

    char ans = '1';
    rep(i, n) {
        if (s[i] != '1') {
            ans = s[i];
            break;
        }
    }

    cout << ans << endl;

}

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

# 1L
cost_per_1L=min(q*4, h*2, s)
# 2L
cost_per_2L=min(cost_per_1L*2, d)

q,r = divmod(n, 2)

print(cost_per_2L*q + cost_per_1L*r)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    while(1)
    {
        int h,w;
        cin>>h>>w;if(!h)return 0;
        int n;
        cin>>n;
        bool map[16][16];
        for(int i=0;i<16;++i){
            fill(map[i],map[i]+16,true);
        }
        for(int i=0;i<n;++i){
            int a,b;
            cin>>a>>b;
            map[a-1][b-1]=false;
        }
        long long dp[16][16]={{0}};
        dp[0][0]=1;
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(i>0&&map[i][j]){
                    dp[i][j]+=dp[i-1][j];
                }
                if(j>0&&map[i][j]){
                    dp[i][j]+=dp[i][j-1];
                }
            }
        }
        cout<<dp[h-1][w-1]<<endl;
    }
}

Measured memory_bytes: 1156
//import java.lang.annotation.Native;
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int w=sc.nextInt();
            int h=sc.nextInt();
            if(h==0&&w==0) break;
            int[][] s=new int[h][w];
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    s[i][j]=sc.nextInt();
                }
            }
            int n=h*w;
            ArrayList<ArrayList<Integer>> g=new ArrayList<ArrayList<Integer>>();
            for(int i=0;i<n;i++){
                g.add(new ArrayList<Integer>());
            }
            int[] ok=new int[n];
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    int now=i*w+j;
                    //G[now]=new ArrayList();
                    
                    if(s[i][j]==1){
                        ok[now]=1;
                        for(int x=-1;x<=1;x++){
                            for(int y=-1;y<=1;y++){
                                if(x==0&&y==0) continue;
                                if(i+x>=0&&i+x<h&&j+y>=0&&j+y<w){
                                    if(s[i+x][j+y]==1)g.get(now).add(w*(i+x)+j+y);
                                }
                            }
                        }
                    }
                }
            }
            int ans=0;
            int[] dist=new int[n];
            for(int i=0;i<n;i++) dist[i]=-1;
            Queue<Integer> que=new LinkedList<Integer>();
            for(int i=0;i<h*w;i++){
                if(ok[i]==0||dist[i]!=-1) continue;
                dist[i]=0;
                que.add(i);
                while(!que.isEmpty()){
                    int v=que.poll();
                    
                        for(int nv:g.get(v)){
                            if(nv>=0&&nv<n&&dist[nv]==-1){
                                dist[nv]=dist[v]+1;
                                que.add(nv);
                            }
                        }
                    
                    
                }
                ans++;
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 48112
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

lint ab_num(std::string s)
{
    lint out = 0;
    lint ab_count = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A')
        {
            ab_count = 1;
        }
        else if (s[i] == 'B' && ab_count == 1)
        {
            ab_count = 0;
            out++;
        }
        else
        {
            ab_count = 0;
        }
    }

    return out;
}

int main()
{

    lint n;
    scanf("%lld", &n);

    lint ans = 0;

    lint top_b, bottom_a, tb_ab;
    top_b = bottom_a = tb_ab = 0;

    for (int i = 0; i < n; ++i)
    {
        std::string s;
        std::cin >> s;

        ans += ab_num(s);

        if (s.front() == 'B' && s.back() == 'A')
            tb_ab++;
        else if (s.front() == 'B')
            top_b++;
        else if (s.back() == 'A')
            bottom_a++;
    }

    if (tb_ab >= 1)
    {
        ans += tb_ab - 1;
        if (bottom_a >= 1)
        {
            ans++;
            bottom_a--;
        }
        if (top_b >= 1)
        {
            ans++;
            top_b--;
        }
    }

    ans += std::min(top_b, bottom_a);

    printf("%lld", ans);

    return 0;
}


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

using namespace std;

int main() {
    int n, x, y, b, p, min_cost;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> b >> p;
        min_cost = b * x + p * y;
        min_cost = min(min_cost, (max(b, 5) * x + max(p, 2) * y) * 4 / 5);
        cout << min_cost << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
using namespace std;
int main()
{
    char x,y;
    scanf("%c %c\n",&x,&y);
    if(x<y) {printf("<\n");return 0;}
    if(x>y) {printf(">\n");return 0;}
    if(x==y){printf("=\n");return 0;}
    return 0;
}

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

int main() {
  int H, W, a;
  cin >>H >>W;
  string S;
  
  for(int j=0; j<W+2; j++) {
    cout <<'#';
  }
  cout <<endl;
  
  for(int i=0; i<H; i++) {
    cin >>S;
    cout <<'#' <<S <<'#' <<endl;
  }
  for(int j=0; j<W+2; j++) {
    cout <<'#';
  }
  cout <<endl;
  
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    ll luk[90];
    ll n;
    cin>>n;
    luk[0]=2;
    luk[1]=1;
    for(int i=2;i<=n;i++){
        luk[i]=luk[i-2]+luk[i-1];
    }
    cout<<luk[n]<<endl;
    return 0;
}


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

char itoc(int c) {
  switch (c) {
    case 1: return '1';
    case 2: return '2';
    case 3: return '3';
    case 4: return '4';
    case 5: return '5';
    case 6: return '6';
    case 7: return '7';
    case 8: return '8';
    case 9: return '9';
    case 0: return '0';
    default: return '0';      
  }
}

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char>> data(H, vector<char>(W));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> data.at(i).at(j);
     }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int count = 0;
      
      if (i > 0 && data.at(i - 1).at(j) == '#')  {
        count++;  //上
      }
      if (i + 1 < H && data.at(i + 1).at(j) == '#') {
        count++;  //下
      }
      if (j > 0 && data.at(i).at(j - 1) == '#') {
        count++;  //左
      }
      if (j + 1 < W && data.at(i).at(j + 1) == '#') {
        count++;  //右
      }

      if (i > 0 && j > 0) {
        if (data.at(i - 1).at(j - 1) == '#') {
          count++;  //左斜め上
        }
      }
      if (i + 1 < H && j > 0) {
        if (data.at(i + 1).at(j - 1) == '#') {
          count++;  //左斜め下
        }
      }

      if (i > 0 && j + 1 < W) {
        if (data.at(i - 1).at(j + 1) == '#') {
          count++;  //右斜め上
        }
      }
      if (i + 1 < H && j + 1 < W) {
        if (data.at(i + 1).at(j + 1) == '#') {
          count++;  //右斜め下
        }
      }
      if (data.at(i).at(j) == '.') {
        data.at(i).at(j) = itoc(count);
      }
      cout << data.at(i).at(j);
    }
    cout << endl;
  }
}

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

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

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int n, k;
    cin >> n >> k;
    int ans = 0;
    rep(i, n){
        int x;
        cin >> x;
        ans += min(x * 2, abs(k - x) * 2);
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int n = sc.nextInt();

        int array[] = new int[n];

        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (i == j || j == k || i == k) {
                    } else {
                        int a = 0;
                        int b = 0;
                        int c = 0;
                        a = array[i];
                        b = array[j];
                        c = array[k];
                        if (a == b || b == c || a == c) {
                        } else {
                            if (a >= b && a >= c) {
                                if (Math.abs(b - c) < a && a < b + c) {
                                    ans++;
                                }
                            } else if (b >= a && b >= c){
                                if (Math.abs(a - c) < b && b < a + c) {
                                    ans++;
                                }
                            } else if (c >= a && c >= b){
                                if (Math.abs(b - a) < c && c < a + b) {
                                    ans++;
                                }
                            }
                        }
                    }
                }
            }
        }

        System.out.println(ans / 6);

        sc.close();

        }

    }



Measured memory_bytes: 36456
#include <iostream>

using namespace std;

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

    if (n == 0)
      break;

    int left = 1;
    int right = 1;
    long long sum = 0;

    while (true) {
      if (sum < n) {
	sum += right++;
      } else if (sum > n) {
	sum -= left;
	left++;
      } else {
	break;
     }
    }
    cout<<left<<" "<<(right - left)<<endl;
  }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)998244353
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,W;
    cin >>n >>W;
    vector<int> v(n),w(n);
    rep(i,n) cin >>w[i] >>v[i];

    vector<ll> dp(W+1);
    rep(i,n){
        for(int j=W; j>=0; --j){
            int nj = j+w[i];
            if(nj>W) continue;
            dp[nj] = max(dp[nj], dp[j]+v[i]);
        }
    }

    ll ans = 0;
    rep(i,W+1) ans = max(ans, dp[i]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;


int main() {

	int n;

	double temp;

	vector<double> v;

	cin >> n;

	double sum=0;

	for (int i = 0; i < n; i++) {
		cin >> temp;

		v.push_back(temp);

		
	}

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


	sum = (v[0] + v[1]) / 2.0;
	for (int i = 2; i < v.size(); i++) {
		sum = (sum + v[i]) / 2.0;
	}

	printf("%0.10lf\n",sum);

	//cout << sum << endl;
	
	


	return 0;
}



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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int n, m, x; cin >> n >> m >> x;
	map<int ,int> mp;
	rep(i, 1, m+1){
		int a; cin >> a;
		mp[a]++;
	}
	int left = 0;
	int right = 0;
	rep(i, 0, x) left += mp[i];
	rep(i, x, n+1) right += mp[i];
	cout << min(left, right) << endl;
	return 0;
}

Measured memory_bytes: 3556
N=int(input())
lxy=[]
for i in range(N):
    lxy.append(list(map(int,input().split())))
def dij(l1,l2):
    return ((l1[0]-l2[0])**2+(l1[1]-l2[1])**2)**0.5
dsum=0
for i in range(N):
    for j in range(i+1,N):
        dsum+=dij(lxy[i],lxy[j])
print(2*dsum/N)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef int64_t ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

// n! を p で何回割れるか
ll g1(ll n, int p) {
  if (n == 0) return 0;
  return n/p + g1(n/p, p);
}

// n!! を p で何回割れるか
ll g2(ll n, int p) {
  ll res = g1(n/2, p);
  if (p == 2) res += n/2;
  return res;
}

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

  ll n;
  cin >> n;

  if (n % 2 == 1) {
    puts("0");
    return 0;
  }

  ll ans = min(g2(n, 2), g2(n, 5));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void edit_query(int ind, int l, int r, int index, int val1, int val2, vector<vector<int>>& st){
	if(l>r || index>r || index<l)
		return;
	if(l==r && r==index){
		st[ind][val1]++;
		if(val2!=-1){
			st[ind][val2]--;
		}
		return;
	}

	edit_query(2*ind+1,l,(l+r)/2,index,val1,val2,st);
	edit_query(2*ind+2,(l+r)/2+1,r,index,val1,val2,st);
	int mid=(l+r)/2;
	for(int j=0;j<26;j++){
		st[ind][j]=(l<=mid?st[2*ind+1][j]:0)+(mid+1<=r?st[2*ind+2][j]:0);
	}
}

void search_query(int ind, int l, int r, int s, int e, vector<vector<int>>& st, vector<int>& ans){
	if(l>r || e<l || s>r){
		return;
	}
	if(s<=l && r<=e){
		for(int i=0;i<26;i++)
			ans[i]+=st[ind][i];
		return;
	}

	search_query(2*ind+1,l,(l+r)/2,s,e,st,ans);
	search_query(2*ind+2,(l+r)/2+1,r,s,e,st,ans);
}

void solve(){
	int n,q;
	string s;
	cin>>n>>s>>q;
	vector<vector<int>> st(4*n,vector<int>(26,0));
	for(int i=0;i<n;i++){
		edit_query(0,0,n-1,i,int(s[i]-'a'),-1,st);
	}

	vector<int> ans(26,0);
	int tp, ind, l,r,out;
	char c;
	for(int iquer=0;iquer<q;iquer++){
		cin>>tp;
		if(tp==1){
			cin>>ind>>c;
			edit_query(0,0,n-1,ind-1,int(c-'a'),int(s[ind-1]-'a'),st);
			s[ind-1]=c;
		}
		else{
			cin>>l>>r;
			l--;
			r--;
			search_query(0,0,n-1,l,r,st,ans);
			out=0;
			for(int i=0;i<26;i++){
				out+=(ans[i]>0?1:0);
				ans[i]=0;
			}
			cout<<out<<"\n";
		}
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 268444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		int n = sc.nextInt();
		int k = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		while(k-- > 0) {
			int d = sc.nextInt();
			
			while(d-- > 0) {
				int snack = sc.nextInt();
				set.add(snack);
			}
		}
		
		System.out.println(n - set.size());
		
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 33308
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

#define INF 9999999999;
#define D(x) cout << x << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;

string a[60];
string b[60];
int n, m;

bool match(int x, int y) {
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (a[x + i][y + j] != b[i][j]) {
        return false;
      }
    }
  }
  return true;
}

int main() {

  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  bool found = false;
  for (int i = 0; i <= n - m; i++) {
    for (int j = 0; j <= n - m; j++) {
      if (match(i, j)) {
        found = true;
      }
    }
  }
  cout << (found ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N;
bool is_ng[200000];
int64_t H[200000];
int main()
{
    using std::endl;
    in.sync_with_stdio(false);
    out.sync_with_stdio(false);
    in.tie(nullptr);
    out.tie(nullptr);

    int M;
    in >> N >> M;
    for (size_t i = 0; i < N; i++)
    {
        in >> H[i];
    }
    for (size_t i = 0; i < M; i++)
    {
        int a, b;
        in >> a >> b; --a; --b;

        if (H[a] <= H[b]) {
            is_ng[a] = true;
        }
        if (H[b] <= H[a]) {
            is_ng[b] = true;
        }
    }

    out << std::count_if(is_ng, is_ng + N, [](auto b) {return !b; }) << endl;


    return 0;
}
#endif


Measured memory_bytes: 4080
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int power(int x){
    return (x * x * x * x * x);
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int p = 1;
        vector<int> v;
        map<int, int> mp;
        while(power(p) < 1e11){
            v.pb(power(p));
            mp[power(p)] = p;
            p++;
        }
        p = -1;
        while(power(p) > -1e11){
            v.pb(power(p));
            mp[power(p)] = p;
            p--;
        }
        v.pb(0);
        sort(all(v));
        mp[0] = 0;
        int x;
        cin >> x;
        pair<int, int> ans;
        for(auto &it : v){
            if(mp.find(it + x) != mp.end()){
                ans = {mp[it], mp[it + x]};
            }
        }
        cout << max(ans.ff, ans.ss) << ' ' << min(ans.ff, ans.ss) << '\n';
    }
}


Measured memory_bytes: 34540
//climpet problems are extremely easy
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int oo=1e9+10;
const int mx=1e5+10;
const int mxl=22;
int x[mx];
int f[2][mxl][mx];
int main(){
   int n,l,q,r;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)scanf("%d",x+i);
   x[0]=x[1]-1;
   x[n+1]=x[n]+1;
   n+=2;
   scanf("%d %d",&l,&q);
   for(int it=0;it<2;it++){
      for(int i=0;i<n;i++){
         int idx=upper_bound(x,x+n,x[i]+l)-x-1; 
         f[it][0][i]=idx;
      }
      for(int l=1;l<mxl;l++){
         for(int i=0;i<n;i++){
            f[it][l][i]=f[it][l-1][f[it][l-1][i]];
         }
      }
      reverse(x,x+n);
      for(int i=0;i<n;i++)x[i]=oo-x[i];
   }
   while(q--){
      scanf("%d %d",&l,&r);
      int it=0;
      if(l>r){
         it=1;
         l=n-1-l;
         r=n-1-r;
      }
      assert(l<=r);
      int ans=0;
      for(int h=mxl-1;h>=0 && l<r;h--){
         if(f[it][h][l]<=r){
            ans+=(1<<h);
            l=f[it][h][l];
         }
      }
      if(l<r)ans++;
      printf("%d\n",ans);
   }
   return 0;
}


Measured memory_bytes: 18432
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

class CWelcomeToAtCoder {
 public:
  void solveOne(std::istream &in, std::ostream &out) {
    int n, m, tmp;
    in >> n >> m;
    string ac;

    map<int, bool> M;

    int penal = 0;

    map<int, int> mp;

    forn(i, m) {
      in >> tmp >> ac;

      if (ac == "AC") {
        M[tmp] = true;
      } else {
        if (M.count(tmp) == 0)mp[tmp]++;
      }
    }

    for (auto e : M) {
      if (e.second) {
        penal += mp[e.first];
      }
    }
    out << M.size() << ' ' << penal << endl;

  }
  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int i = 0; i < nt; ++i)
      solveOne(in, out);
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  CWelcomeToAtCoder solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;

public class Main {
	static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {

		String str = s.next();
		int flag = 0;
		

		if (str.length() >= 3 && str.length() % 2 == 1)
			flag = 1;

		if (flag == 1) {
			for (int i = 0; i < str.length() / 2; i++) {
				if (str.charAt(i) != str.charAt(str.length() - 1 - i)) {
					flag = 0;
					break;
				}
			}
		

			if (flag == 1) {
				String ans = str.substring(0, (str.length() - 1) / 2);
				for (int i = 0; i < ans.length() / 2; i++) {
					if (ans.charAt(i) != ans.charAt(ans.length() - 1 - i)) {
						flag = 0;
						break;
					}
				}
			}
			
			if (flag == 1) {
				String ans = str.substring(((str.length()+3)/2)-1,str.length());
				for (int i = 0; i < ans.length() / 2; i++) {
					if (ans.charAt(i) != ans.charAt(ans.length() - 1 - i)) {
						flag = 0;
						break;
					}
				}
			}

		}
		if(flag ==1) {
			System.out.println("Yes");
			
		}
		else
			System.out.println("No");


	}
		
}



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

using namespace std;

int a[100007], b[100007], c[100007];
int memo[100007][4];
int n; 

int solve(int p, int last) {
    if(p == n) return 0;
    int & st = memo[p][last];
    if(st == -1) {
        st = max({
            last != 1? solve(p+1, 1) + a[p] : 0,
            last != 2? solve(p+1, 2) + b[p] : 0,
            last != 3? solve(p+1, 3) + c[p] : 0
        });
    }
    return st;
}
int main() {
    memset(memo, -1, sizeof memo);
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }

    cout << solve(0, 0);
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define For(i,n) for(long i=0;i<(n);i++)
int main(void){
    string S;
    cin>>S;
    //vector<long> num(N);
    long k=0;
    For(i,S.size()){
        if(S.at(i)=='o'){
            k++;
        }
    }
    if(15+k-S.size()>=8){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
  int s;
  cin>>s;
  int ans=0;
  for(int i=1;i<=s;i++){
      if((1<=i&&i<10)||(100<=i&&i<1000)||(10000<=i&&i<100000)) ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  int n;
  string s;
  cin>>n>>s;
  int ans = 0;
  fr(i, n-2) if(s.substr(i, 3) == "ABC") ans++;


  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,k;
  cin >> n >> m >> k;
  int i,j;
  bool chk = false;
  for(i=0;i<=n;i++){
    for(j=0;j<=m;j++){
      int tmp = i*m + j*n - 2*i*j;
      if(tmp==k)chk=true;
    }
  }
  if(chk)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

void swap(int* num_1, int* num_2) {
	int temp = *num_1;
	*num_1 = *num_2;
	*num_2 = temp;
}

int partition(int* array, int p, int r) {
	int i = p - 1, j;

	for (j = p; j < r; j++) {
		if (array[j] <= array[r]) {
			i++;
			swap(&array[i], &array[j]);
		}
	}
	swap(&array[i + 1], &array[r]);
	return i + 1;
}

int main() {
	int part, array_num, i;
	scanf("%d", &array_num);

	//dynamic scan
	int* array;
	array = (int*)malloc(array_num * sizeof(int));
	for (int i = 0; i != array_num; i++) {
		scanf("%d", &array[i]);
	}

	part = partition(array, 0, array_num - 1);

	for (i = 0; i != array_num - 1; i++) {
		if (i)printf(" ");
		if (i == part) printf("[");
		printf("%d", array[i]);
		if (i == part) printf("]");
	}
	printf(" %d\n", array[array_num - 1]);

	return 0;
}


Measured memory_bytes: 2088