akhauriyash/Code-Regression huggingface dataset:
def main():
    s = list(input())
    s = list(set(s))
    
    if len(s)==4:
        print("Yes")
    elif len(s)==3:
        print("No")
    elif len(s)==2:
        if "N"in s and "S" in s:
            print("Yes")
        elif "E" in s and "W" in s:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
if __name__=='__main__':
    main()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define rint register int
#define ll long long 
#define mk make_pair
#define pb push_back
#define pa pair<int,int>

using namespace std;
int N,M,A[1100010],B[5050][220],top[220],Sta[220][5050];
ll tag[5050];
int main() {
	cin>>N>>M;
	for(rint i=1;i<N;++i) cin>>A[i];
	for(rint i=1;i<=N;++i) {
		for(rint j=1;j<=M;++j) {
			scanf("%d",&B[i][j]);
		}
	}
	ll ans=0;
	for(rint i=1;i<=N;++i) {
		ll Sum=0;
		for(rint j=1;j<=M;++j) {
			Sum+=B[i][j];
			while(top[j]&&B[Sta[j][top[j]]][j]<=B[i][j]) {
				top[j]--;
				if(top[j]) tag[Sta[j][top[j]]]-=B[Sta[j][top[j]]][j]-B[Sta[j][top[j]+1]][j];
			}
			Sta[j][++top[j]]=i;
			if(top[j]>=2) {
				tag[Sta[j][top[j]-1]]+=B[Sta[j][top[j]-1]][j]-B[Sta[j][top[j]]][j];
			}
		}
//		cout<<tag[1]<<endl;
//		cout<<Sum<<endl;
		ans=max(ans,Sum);
		for(rint j=i-1;j;--j) {
			Sum-=A[j];
			Sum+=tag[j];
			ans=max(ans,Sum);
		}
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 8980
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  const int MOD=1e9+7;
  const int N=2e5+2;

 
  int32_t main()
  {
    
    int n,k,x;
    cin>>n>>k;
    //cout<<n<<k<<endl;
    priority_queue<int,vector<int>, greater<int>> pq;
    for(int i=0;i<n;i++)
      {cin>>x;
       // trace1(x);
    pq.push(x);}
    int sum=0;
    while(k--)
    {
      sum+=pq.top();
     // trace1(pq.top());
      pq.pop();
      
    }
    cout<<sum;
 return 0;
   
 }


Measured memory_bytes: 3636
N, = list(map(int,input().split()))
c = [[0 for e in range(10)] for s in range(10)]
for i in range(1, N+1):
    c[int(str(i)[0])][int(str(i)[-1])] += 1
r = 0
for s in range(1, 10):
    for e in range(1, 10):
        r += c[s][e] * c[e][s]
print(r)

Measured memory_bytes: 3060
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import deque
INF = float('inf')


def main():
    H, W, K = map(int, readline().split())
    x1, y1, x2, y2 = map(int, readline().split())
    x1 -= 1
    y1 -= 1
    x2 -= 1
    y2 -= 1
    C = read().split()

    dist = [[-1] * W for i in range(H)]
    dist[x1][y1] = 0
    d = deque([[x1, y1]])
    dxy = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    while d:
        x, y = d.popleft()
        if (x, y) == (x2, y2):
            print(dist[x][y])
            quit()
        for dx, dy in dxy:
            xx = x
            yy = y
            for i in range(K):
                xx += dx;
                yy += dy
                if 0 <= xx < H and 0 <= yy < W and C[xx][yy] != '@':
                    if 0 <= dist[xx][yy] <= dist[x][y]:
                        break
                    if dist[xx][yy] == -1:
                        d.append([xx, yy])
                    dist[xx][yy] = dist[x][y] + 1
                else:
                    break

    print(-1)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

ll n,m;

vector<ll > input;
vector<pair<ll,ll>> change;
ll sum = 0;

int main() {
    cin >> n >> m;
    for(int i = 0;i<n;i++){
        ll u;
        cin >> u;
        input.push_back(u);
        sum+=u;
    }

    for(int i = 0;i<m;i++){
        ll u ,v;
        cin >> u>>v;
        change.push_back({v,u});
    }

    sort(input.begin(),input.end());
    sort(change.begin(),change.end(),greater<pair<ll,ll >>());

    /*for(auto i : change){
        cout<< i.first << ' ' << i.second<<endl;
    }*/

    for(int i = 0, j=0;i<n&&j<m;i++){
        if(change[j].first>input[i]){
            change[j].second--;
            sum-=input[i];
            sum+=change[j].first;
            if(change[j].second==0){
                j++;
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3188
H,W,K = map(int, input().split())
S = [[int(i) for i in list(input())] for _ in range(H)]

ans = float("inf")
for state in range(2 ** (H - 1)):
    flag = True

    # 横棒のカウント
    yoko = 0
    for i in range(H - 1):
        if (state >> i) & 1:
            yoko += 1

    res = yoko

    # ホワイトチョコレートの個数
    cntHW = [0] * (yoko + 1)
    for j in range(W):
        # 今のグループ
        now = 0
        # 列を探索
        cntH = [0] * (yoko + 1)
        for i in range(H):
            if S[i][j] == 1:
                cntH[now] += 1

            if (state >> i) & 1: # 区切り
                now += 1
        
        for cH in cntH:
            if cH > K:
                flag = False

        # 個数の最大値
        MAX = max(cH + cHW for cH,cHW in zip(cntH,cntHW))
        if MAX > K:
            res += 1
            cntHW = cntH[::]
        else:
            for i in range(yoko + 1):
                cntHW[i] += cntH[i]

    if flag:
        ans = min(ans, res)

print(ans)

Measured memory_bytes: 48988
#include <iostream>

 

using namespace std;

 

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if (x-r >= 0 && y-r >= 0 && x+r <= w && y+r <= h)
       cout << "Yes" << endl;
    else
       cout << "No" << endl;
    
}



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

using namespace std;

long long n;

long long cul(long long n,long long k){
    while(n >= k){
        if(n%k){
            n = n%k;
        }
        else{
            n = n/k;
        }
    }
    return n;
}

void solve(){
    long long i,j;
    string str;
    cin >> n;
    long long ans = 1;
    for(i = 2;i*i < n;i++){
        if(n%i == 0){
            if(cul(n,i) == 1) ans++;
            if(cul(n,n/i) == 1) ans++;
        }
    }
    if(i*i == n) ans++;
    n--;
    if(n >= 2) ans++;
    for(i = 2;i*i < n;i++){
        if(n%i==0) ans += 2;
    }
    if(i*i == n) ans++;
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int m,d;
    cin >> m >> d;
    ll ans = 0;
    for(int i = 1 ; i <= m; i++){
        for(int j = 1; j <= d; j++){
            if(j/10 > 0){
                if(((j/10)%10)*(j%10) == i && ((j/10)%10) > 1 && j%10 > 1) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
using namespace std;
const int INF = 2000000005;
int n, w;
int v[105] = { 0 }, g[105] = { 0 };
int dp[105][10005] = { 0 };
int main() {
	cin >> n >> w;
	for (int i = 1; i <= n; i++) cin >> v[i] >> g[i];
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= w; j++) {
			dp[i][j] = 0;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= w; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= g[i]) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - g[i]] + v[i]);
			}
			/*cout << dp[i][j] << " ";*/
		}
		/*cout << endl;*/
	}
	
	cout << dp[n][w] << endl;


	return 0;
}


Measured memory_bytes: 7032
from itertools import permutations

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

sum = 0
cnt = 0
for i in permutations(xy):
    for j in range(n - 1):
        sum += ((i[j][0] - i[j + 1][0]) ** 2 + (i[j][1] - i[j + 1][1]) ** 2) ** 0.5
    cnt += 1
print(sum / cnt)

Measured memory_bytes: 9456
/*
 * 2525.cc: Change
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

// cd = floor(rd*x/100) <= rd*x/100
// rd*x >= 100*cd, x >= 100*cd/rd

int main() {
  ll m, cd, cr;
  int rd, rr;
  cin >> m >> rd >> rr >> cd >> cr;

  ll yd = (100 * cd + rd - 1) / rd;
  ll yr = (100 * cr + rr - 1) / rr;
  ll y = m - (yd + yr);

  printf("%lld\n", (y >= 0) ? y : -1);
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>//数据输入输出流
#include <cstring>//字符串操作函数
#include <cstdio>//C的输入输出
#include <cstdlib>//定义杂项函数及内存分配函数
#include <cmath>//C中的数学函数
#include <string>//c++中的string类 他不能用strcpy等c函数去操作
#include <vector>//STL vetor
#include <list>//STL list
#include <map>// STL map
#include <queue>// STL queue
#include <stack>//sTL stack
#include <bitset>//bitset可按位定义串
//比如：bitset <1000> all;定义一个1000位的串
#include <algorithm>//STL各种算法 比如 swap sort merge max min 比较
#include <numeric>//常用数字操作 一般和algorithm搭配使用
#include <functional>//STL定义运算函数（代替运算符）
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
#define LOCAL
#define zeros(a,n) memset(a,0,(n)*sizeof(a[0]))
const int modn = 1e9+7;
int mod(int x) { return x<0?x+modn:x<modn?x:x-modn; }
//inv [ i ] = (modn - modn/i)*inv[ modn%i ] %modn;
const int N = 200005;
int n;
int a[N];
LL sum[N][2];
LL f[N];
LL dfs1(int p){
    if(p > n) return 0;
    if(f[p]) return f[p];
    return f[p] = max(a[p] + dfs1(p + 2), sum[p+1][(p+1)%2]);
}
LL dfs2(int p){
    if(p >= n) return 0;
    if(f[p]) return f[p];
    return f[p] = max(a[p] + dfs2(p + 2), dfs1(p+1));
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i = n; i>=1; --i){
        sum[i][0] = sum[i+1][0];
        sum[i][1] = sum[i+1][1];
        sum[i][i%2] = sum[i+1][i%2] + a[i];
    }
    if(n % 2 == 0){
        cout << dfs1(1) << endl;
    }else{
        cout << dfs2(1) << endl;
    }
    return 0;
}



Measured memory_bytes: 11724
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();
		scan.close();
		int ans = A * B - A - B + 1;
		System.out.println(ans);
	}
}

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

int main() {
  int H, W, A, B; cin >> H >> W >> A >> B;
  for(int y = 0; y < H; y++) {
    for(int x = 0; x < W; x++) {
      if(y < B) {
        if(x < A) cout << 0;
        else cout << 1;
      } else {
        if(x < A) cout << 1;
        else cout << 0;
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

heavy = [0] * (10 ** 5 + 1)
for x in A:
    heavy[x] += 1
suma = sum(A)

for i in range(Q):
    B, C = map(int, input().split())
    suma -= B * heavy[B]
    suma += C * heavy[B]
    heavy[C] += heavy[B]
    heavy[B] = 0
    print(suma)


Measured memory_bytes: 21056
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  ll n;
  cin>>n;
  map<int,int> memo;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0) memo[i]++;
  }
  ll ans=1e13;
  for(auto itr=memo.begin();itr!=memo.end();itr++){
    ans=min(ans,(itr->first)+n/(itr->first)-2);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
fn main() {
    let mut inputs: Vec<i32> = read().trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
    inputs.sort();

    let oddSum: i32 = inputs.iter().enumerate().filter(|&(i, _)| i%2==0).map(|(_, e)| e).sum();
    let evenSum: i32 = inputs.iter().enumerate().filter(|&(i, _)| i%2==1).map(|(_, e)| e).sum();
    
    println!("{}", (oddSum-evenSum).abs());
}

fn read() -> String {
    let mut s = String::new();

    // 最初は無視
    std::io::stdin().read_line(&mut String::new());

    std::io::stdin().read_line(&mut s);
    s
}


Measured memory_bytes: 4352
d = int(input())
c = list(map(int,input().split()))
s = []
for i in range(d):
  si = list(map(int,input().split()))
  s.append(si)
lastd = [-1 for _ in range(26)]
for i in range(d):
  mx = 0
  mj = 0
  #s = 0
  #for j in range(26):
    #s += (i-lastd[j])*c[j]
  for j in range(26):
    if s[i][j] + (i-lastd[j])*c[j] > mx:
      mx = s[i][j] + (i-lastd[j])*c[j]
      mj = j
  lastd[mj] = i
  print(mj+1)

Measured memory_bytes: 68492
import scala.annotation.tailrec

object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  sc.useDelimiter("\n")
  val N = sc.nextInt()
  val A = sc.next().split(" ").map(_.toLong)
  println(calc(0L, 0, 0L))
  
  @tailrec
  def calc(prev: Long, index: Int, acc: Long): Long = {
    if (index == A.length) {
      acc
    } else if (prev <= A(index)) {
      calc(A(index), index + 1, acc)
    } else {
      calc(prev, index + 1, acc + prev - A(index))
    }
  }

}


Measured memory_bytes: 84612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll gcd(ll a,ll b){
  if(a%b==0){
    return b;
  }
  else{
    return gcd(b,a%b);
  }
}

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  if(n==1){
    cout << a[0] << endl;
  }
  else{
    ll G=gcd(a[0],a[1]);
    ll ans=a[0]/G*a[1];
    FOR(i,2,n){
      G=gcd(ans,a[i]);
      ans=a[i]/G*ans;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char arr[5];
	scanf("%s",arr);
	if((arr[0]==arr[1])&&(arr[1]==arr[2]))
	{
		printf("Yes");
	}
	else if((arr[1]==arr[2])&&(arr[2]==arr[3]))
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

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

typedef long long ll;
ll n, s;
priority_queue<ll> qu;
int main()
{
	ll t;
	cin >> n;
	for (t = 1; t <= 9; t++) qu.push((-t));
	while (!qu.empty()) {
		t = qu.top(); qu.pop();
//		printf("%lld\n", t);
		t *= -1;
		s++;
		if (s == n) {
			cout << t << endl;
			return 0;
		}
		qu.push(-(t * 10 + t % 10));
		if (t % 10 > 0) qu.push(-(t * 10 + t % 10 - 1));
		if (t % 10 < 9) qu.push(-(t * 10 + t % 10 + 1));
	}
    return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>

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

Measured memory_bytes: 596
from bisect import bisect_right as br

def main():
    N = int(input())
    S = input()
    P = [[ ] for _ in range(10)]
    for s,index in zip(S,range(N)):
        P[int(s)].append(index)
    ans = 0 
    for i in range(0,1000):
        
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        try:
            if len(P[a]) > 0:
                point = P[a][0]
                if len(P[b]) > 0:
                    tmp = br(P[b],point)
                    if P[b][tmp] > point:
                        point = P[b][tmp]
                        if len(P[c]) > 0:
                            neko = br(P[c],point)
                            if P[c][neko] > point:
                                ans += 1
        except:
            ans = ans
    print(ans)
    return 

main()

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;

  int b[21];
  int a[21][21];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      sum += a[i][j] * b[j];
    }
    if (sum + c > 0) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

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

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var a2 = a.OrderBy(x => x).ToArray();
        var s = a2[n / 2 - 1];
        var L = a2[n / 2];
        for (int i = 0; i < n; i++)
            Console.WriteLine(a[i] <= s ? L : s);
    }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int Q; cin >> Q;
  pqdesc<int> mins;
  pqasc<int> maxs;
  i64 ans = 0;
  rep(_, Q) {
    int __; cin >> __;
    if (__ == 1) {
      int a, b; cin >> a >> b;
      ans += b;
      mins.push(a), maxs.push(a);
      int mi = mins.top(), ma = maxs.top();
      if (mi > ma) {
        mins.pop(), maxs.pop();
        mins.push(ma), maxs.push(mi);
        ans += abs(mi - ma);
      }
    } else {
      cout << mins.top() << " " << ans << '\n';
    }
  }
}


Measured memory_bytes: 3828
#include <cstdlib>
#include <functional>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

#define ll long long int

using namespace std;

ll factorial(ll x) {
  if (x == 0) {
    return 1;
  }

  ll ret = 1;
  for (ll i = 1; i <= x; i++) {
    ret *= i;
  }
  return ret;
}

int main(int argc, char *argv[])
{
  char result[100] = "";
  ll index = 0;

  string s;
  cin >> s;

  for (ll i = 0; i < s.size(); i++) {
    switch(s[i]) {
      case 'B' :
        if (index > 0) {
          result[--index] = '\0';
        }
        break;
      default:
        result[index] = s[i];
        index++;
        result[index] = '\0';
        break;
    }
  }

  cout << result;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
typedef pair<long long, long long> P;
int main(){

    long long n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<int> v(n);
    vector<int> w(m);
    rep(i,n){
        cin>>v[i];
    }
    rep(i,m){
        cin>>w[i];
    }
    sort(v.begin(),v.end());
    sort(w.begin(),w.end());
    if(v[n-1]<w[0]&& v[n-1]<y &&x<w[0]){
        cout<<"No War"<<endl;
    }
    else{
        cout<<"War"<<endl;
    }
    
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	cout << n*n << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define bl bool
#define INF 1e+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
int main(){
	ll r;
	read(r);
	cout<<3*r*r<<endl;
	return 0;
}

Measured memory_bytes: 256
a,b = map(int,input().split())
aaa = [list(map(int,input().split())) for i in range(b*2)]

c = set()
e = set([i for i in range(1,a+1)])
for i in range(1,len(aaa),2):
  for k in aaa[i]:
     e.discard(k)

print(len(e))

Measured memory_bytes: 9156
// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);
#define se second
#define fi first

const int inf = 0x3f3f3f3f;
const int maxm = 1e6;
int sv[maxm + 1];

void sieve()
{
    ms(sv, 0);
    sv[1] = 1;

    loop1(i,1,maxm){
      sv[i]=i;
    }

    for (int i = 2; i * i <= maxm; i++)
    {
        if (sv[i]!=i)
            continue;

        for (int j = i * i; j <= maxm; j += i)
        {
            sv[j] = min(i,sv[j]);
        }
    }

    // loop1(i, 1, maxm)
    // {
    //     cout<<i<<" "<<sv[i]<<"\n";
    // }
}

set<int> factors(int num)
{
    set<int> ret;

    while (num != 1)
    {
        int sp = sv[num];
        ret.insert(sp);
        num /= sp;
    }

    return ret;
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int pairw(int *arr, int n)
{
    set<int> fac;

    loop(i, 0, n)
    {
        auto it = factors(arr[i]);
        for (const auto &v : it)
        {
            if (fac.find(v) != fac.end())
            {
                return 0;
            }
            else
            {
                fac.insert(v);
            }
        }
    }
    return 1;
}

int setw(int *arr, int n)
{
    int g = arr[0];
    loop(i, 1, n)
    {
        g = gcd(arr[i], g);
    }
    return (g == 1);
}
void solve()
{

    int n;
    cin >> n;
    int a[n];
    sieve();
    loop(i, 0, n)
    {
        cin >> a[i];
    }
    int ans1 = setw(a, n);
    int ans2 = pairw(a, n);

    if (ans2)
        cout << "pairwise coprime\n";
    else if (ans1)
        cout << "setwise coprime\n";
    else
        cout << "not coprime\n";
}

int main()
{

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    io;
    solve();

    return 0;
}


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

ll n,m,x,y;
Graph G(n);
ll p[100010];

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  //入力
  cin >> n >> m;
  rep(i,n){
    cin >> p[i];
  }

  UnionFind tree(n);
  rep(i,m){
    cin >> x >> y;
    tree.unite(x-1,y-1);
  }
  int ans=0;
  rep(i,n){
    if (tree.same(i,p[i]-1))ans+=1;
  }

  //
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
    if(x%y==0) return y;
    return gcd(y,x%y);
}
int main(void){
    int k;
    cin >> k;
    int ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans+=gcd(i,(gcd(j,l)));
                
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 3552
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vs NAME(n);
  VIN(NAME)
  int m1=0,a1=0,r1=0,c1=0,h1=0;
  REP(i,n){
    char pre = NAME[i][0];
    if(pre=='M') m1++;
    if(pre=='A') a1++;
    if(pre=='R') r1++;
    if(pre=='C') c1++;
    if(pre=='H') h1++;
  }
  int sum = m1*a1*r1 + m1*a1*c1 + m1*a1*h1 + m1*r1*c1 + m1*r1*h1 + m1*c1*h1 + a1*r1*c1 + a1*r1*h1 + a1*c1*h1 + r1*c1*h1;
  OUT(sum);
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
long long dp[200010][3];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> A(n);
    for (auto & a : A) cin >> a;
    dp[0][0] = A[0];
    dp[1][1] = A[1];
    for (int i = 2; i < n; ++i) {
        dp[i][0] = dp[i-2][0]+A[i];
        dp[i][1] = dp[i-2][1]+A[i];
        dp[i][2] = dp[i-2][2]+A[i];
        if (i > 2) {
            dp[i][1] = max(dp[i][1], dp[i-3][0]+A[i]);
            dp[i][2] = max(dp[i][2], dp[i-3][1]+A[i]);
        }
        if (i > 3) {
            dp[i][2] = max(dp[i][2], dp[i-4][0]+A[i]);
        }
    }
    long long ans = max(dp[n-1][1+n%2], dp[n-2][0+n%2]);
    if (n > 2 && n%2 == 1) ans = max(ans, dp[n-3][0]);
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
  int k;
  cin >> k;
  int v[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
             1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << v[k - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
  ll x;
  mint() : x(0) {
  }
  mint(ll x) : x((x % MOD + MOD) % MOD) {
  }
  mint& operator+=(const mint& r) {
    if ((x += r.x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint& operator-=(const mint& r) {
    if ((x -= r.x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint& operator*=(const mint& r) {
    if ((x *= r.x) > MOD) {
      x %= MOD;
    }
    return *this;
  }
  mint& operator++() {
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return *this;
  }
  mint operator++(int) {
    mint ret = x;
    if ((++x) >= MOD) {
      x -= MOD;
    }
    return ret;
  }
  mint& operator--() {
    if ((--x) < 0) {
      x += MOD;
    }
    return *this;
  }
  mint operator--(int) {
    mint ret = x;
    if ((--x) < 0) {
      x += MOD;
    }
    return ret;
  }
  mint operator+(const mint& r) {
    mint ret;
    return ret = x + r.x;
  }
  mint operator-(const mint& r) {
    mint ret;
    return ret = x - r.x;
  }
  mint operator*(const mint& r) {
    mint ret;
    return ret = x * r.x;
  }
  mint operator-() {
    return mint() - *this;
  }
  bool operator<(const mint& a) {
    return x < a.x;
  }
  bool operator>(const mint& a) {
    return x > a.x;
  }
  bool operator<=(const mint& a) {
    return x <= a.x;
  }
  bool operator>=(const mint& a) {
    return x >= a.x;
  }
  bool operator==(const mint& a) {
    return x == a.x;
  }
  bool operator!=(const mint& a) {
    return x != a.x;
  }
};
ostream& operator<<(ostream& os, const mint& r) {
  os << r.x;
  return os;
}
ostream& operator>>(ostream& os, const mint& r) {
  os >> r.x;
  return os;
}

void solve(istream& cin, ostream& cout) {
  int k;
  int a, b;
  cin >> k;
  cin >> a >> b;
  FOR(i, a, b) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return;
    }
  }
  cout << "NG" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3648
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){

  ll N;
  cin >> N;
  vector<ll> A(N);//10^6+1
  rep(i,N)cin >> A[i];
  vector<ll> As(1000001,1);

  sort(A.begin(),A.end());
  rep(i,N){
    if(i > 0){
      if(A[i]==A[i-1]){
        As[A[i]] = 0;
        continue;
      }
    }

    for(ll j = A[i]*2;j <= 1000000;j += A[i]){
      As[j] = 0;
    }
  }

  ll ans = 0;
  rep(i,N){
    if(As[A[i]])ans++;
  }

  cout << ans << endl;

}


Measured memory_bytes: 12668
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll> 
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T=1;
	//cin >> T;
	ll t=0;
	while(t++<T){
		ll k;
		cin>>k;
		k=k/(gcd(k,7));
		ll n=1;
		ll ans=1;
		n%=k;
		vll v(k,0);
		while(true){
			if(v[n]==0 && n==0)break;
			else if(v[n]){ans=-1;break;}
			v[n]=1;
			n=n*10+1;
			n%=k;
			ans++;

		}
		cout<<ans<<endl;

	}
return 0;
}


Measured memory_bytes: 11056
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define STR 10
int main(){
    int k,x;
    scanf("%d %d",&k,&x);
    if(500*k>=x){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=b;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double,double>>
#define vpp vector<pair<int, pair<int,int>>>
#define pp pair<int,int>

int main()
{
   int n,w;
   cin>>n>>w;
   vector<pair<int,int>> v;
   ffor(i,0,n)
   {
   	   int a,b;
   	   cin>>a>>b;
   	   v.pb(mp(a,b)); //weight-value
   }
   long long int dp[n+1][100005];
   ffor(i,0,n+1)
   	 ffor(j,0,100005)
       dp[i][j]=1e18;
   dp[0][0]=0;
   ffor(i,1,n+1)
   {
   	 ffor(j,0,100001)
   	 {
   	 	if(v[i-1].ss<=j)
   	 		dp[i][j]=min(dp[i-1][j-v[i-1].ss] + v[i-1].ff, dp[i-1][j]);
   	    else
   	    	dp[i][j]=dp[i-1][j];
   	 }
   }
   for(int i=100000 ;i>=0; i--)
   	 if(dp[n][i]<=w)
   	 {
   	 	cout<<i<<endl;
   	 	break;
   	 }
}

Measured memory_bytes: 82536
#include <iostream>

using namespace std;

int main() {
	long long int n,i;
	cin >>n;
	long long int h[10000000];
	long long int ht[1000000];
	for(i=0;i<n+2;i++)
	   { cin>>h[i];
	    ht[i]=1000000000000;}
	ht[0]=0;
	for(i=0;i<n;i++)
	{
	    ht[i+1]=min(ht[i+1],ht[i]+abs(h[i+1]-h[i]));
	    ht[i+2]=min(ht[i+2],ht[i]+abs(h[i+2]-h[i]));
	}
// 	for(i=0;i<n;i++)
// 	    cout<<ht[i];
// 	cout<<endl;
	cout<<ht[n-1]<<endl;

}


Measured memory_bytes: 5120
#include <iostream>

using namespace std;

long calc(long left, long right, long left_len, long right_len) {
    return (left_len - left) + (right_len - right);
}

int main() {
    long n, left = 0, right = 0, left_len = 0;
    string s;
    cin >> n >> s;
    long right_len = n - 1;

    for (int i = 1; i < n; i++) {
        if (s[i] == 'W') {
            right++;
        }
    }

    long change = calc(left, right, left_len, right_len);
    long mini = change;

    for (int i = 1; i < n; i++) {
        if (s[i] == 'W') {
            right--;
        }

        if (s[i - 1] == 'E') {
            left++;
        }

        left_len++;
        right_len--;
        change = calc(left, right, left_len, right_len);
        mini = min(mini, change);
    }

    cout << mini << endl;
}

Measured memory_bytes: 3904
#include<bits/stdc++.h>
using namespace std;
#define MAX 2001
#define rep(i, n) for(int i=0;i<n;++i)
#define REP(i, k, n) for(int i=k; i<=n; ++i)
#define REPR(i, k, n) for(int i=k; i>=n; --i)

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

	int N, X, L, sum = 0, cnt = 0;

	cin >> N >> X;

	rep(i, N){
		cin >> L;
        sum = sum + L;

        if(sum <= X){
        	cnt++;
        }else{
        	break;
        }
	}

	cout << cnt+1 << "\n";

	return 0;

}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    string s;
    cin >> s;
    lint k;
    cin >> k;
    lint i = 0;
    while(s[i] == '1'){
        i++;
        if(i >= s.size()){
            break;
        }
    }
    if(i < k){
        cout << s[i] << endl;
    }else{
        cout << 1 << endl;
    }
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

//-----------------------------------------------------------------------------


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

	int num[185];
	for(int i=1;i<185;i++) {
		num[i-1]=i*(i+1)*(i+2)/6;
	}
	int dp[1000100],dp_odd[1000100];
	REP(i,1000100) dp[i]=dp_odd[i]=INF;
	dp[0]=dp_odd[0]=0;
	REP(i,1000000) {
		if(dp[i]!=INF) {
			REP(j,185) {
				if(num[j]+i>1000000) break;
				dp[i+num[j]]=min(dp[i+num[j]],dp[i]+1);
			}
		}
		if(dp_odd[i]!=INF) {
			REP(j,185) {
				if(num[j]+i>1000000) break;
				if(num[j]%2==0) continue;
				dp_odd[i+num[j]]=min(dp_odd[i+num[j]],dp_odd[i]+1);
			}
		}
	}

	while(true) {
		int n;
		cin>>n;
		if(n==0) break;
		cout<<dp[n]<<' '<<dp_odd[n]<<endl;
	}

	return 0;
}



Measured memory_bytes: 10952
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
#include<functional>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct E {
  int t, v; // v: positive => add, negative => remove
  E(int in_t, int in_v): t(in_t), v(in_v) {}
  bool operator<(E const& r) const { return t < r.t; }
};

int const INF = 1e9+5;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, Q; std::cin >> N >> Q;
  std::vector<E> events;
  for(int i = 0; i < N; ++i) {
    int S, T, X; std::cin >> S >> T >> X;
    if(X >= T) continue;
    S = std::max(0, S-X);
    T -= X;
    events.emplace_back(S, X);
    events.emplace_back(T, -X);
  }
  std::sort(events.begin(), events.end());
  std::map<int,int> m;
  std::map<int,int> stops;
  m[0] = INF;
  m[INF] = INF;
  stops[INF] = 1;
  for(auto& e: events) {
    if(e.v > 0) ++stops[e.v];
    else if(--stops[-e.v] == 0) stops.erase(-e.v);
    m[e.t] = stops.begin()->first;
  }
  std::vector<std::pair<int,int>> v(m.begin(), m.end());
  
  for(int i = 0; i < Q; ++i) {
    int D; std::cin >> D;
    auto it = std::upper_bound(v.begin(), v.end(), std::make_pair(D, INF+1));
    int ans = (it-1)->second;
    if(ans == INF) ans = -1;
    std::cout << ans << "\n";
  }
  return 0;
}



Measured memory_bytes: 26348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    ll N, W;
    cin >> N >> W;
    vector<ll> weight(N), value(N);
    ll sum = 0;
    for(int i = 0; i < N; i++) {cin >> weight[i] >> value[i]; sum += value[i];}
    vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, INF));
    for(int i = 0; i <= N; i++) dp[i][0] = 0;
    for(int i = 1; i <= N; i++){
        int w = weight[i - 1];
        int v = value[i - 1];
        for(int j = 1; j <= sum; j++){
            if(j < v) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + w);
        }
    }
    ll mx = -1;
    for(ll i = 0; i <= sum; i++){
        if(dp[N][i] <= W) mx = max(mx, i);
    }
    cout << mx;
}

Measured memory_bytes: 80256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key ){
			x = x->left;
		}
		else{
			x = x->right;
		}
	}
	
	z->parent = y;
	if(y == NIL){
		root = z;
	}
	else{
		if(z->key < y->key ){
			y->left = z;
		}
		else{
			y->right = z;
		}
	}
}

Node * find(Node *u, int k){
	while( u != NIL && k != u->key ){
		if(k < u->key ) u = u->left ;
		else u = u->right ;
	}
	return u;
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left );
	printf(" %d", u->key );
	inorder(u->right );
}

void preorder(Node *u){
	if(u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left );
	preorder(u->right );
}

int main(){
	int n, i, x;
	string com;
	
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		cin >> com;
		if(com == "find"){
			scanf("%d", &x);
			Node *t = find(root, x);
			if(t != NIL ) printf("yes\n");
			else printf("no\n");
		}
		else if(com == "insert"){
			scanf("%d", &x);
			insert(x);
		}
		else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;	
}





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

// 根付き木の各頂点の親, 深さ, 高さを求める
int root;
#define MAX_N 200001
vector<vector<int>>graph(MAX_N, vector<int>());
int par[MAX_N], depth[MAX_N], height[MAX_N]; // 0で初期化
void tree_init(int r){
    root = r;
    par[root] = -1;
    stack<int> st_op, st_cl;
    st_op.push(root);
    while (! st_op.empty()) {
        int t = st_op.top(); st_op.pop();
        st_cl.push(t);
        for (int x: graph[t]) {
            if (x == par[t]) continue;
            depth[x] = depth[t] + 1;
            par[x] = t;
            st_op.push(x);
        }
    }
    while (! st_cl.empty()) {
        int t = st_cl.top(); st_cl.pop();
        for (int x: graph[t]) {
            if (x == par[t]) continue;
            height[t] = max(height[t], height[x] + 1);
        }
    }
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    tree_init(v);
    int cnt = (depth[u] - 1) / 2;
    for (int i = 0; i < cnt; ++i) {
        u = par[u];
    }
    // 鬼は必ず高さ1の頂点で捕まえる
    int ans = depth[u] + height[u] - 1;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9728
N = int(input())
x = list(map(int, input().split()))

mod = 10 ** 9 + 7

c = [1]
for i in range(1,N-1):
    c.append(c[i-1]+pow(i+1,mod-2,mod))

ans = 0
for i in range(N-1):
    ans += (c[i] * (x[i+1] - x[i])) % mod
    ans %= mod
    
for i in range(1,N):
    ans *= i
    ans %= mod

print(ans)

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

int main() {
    long n, k, cnt = 0, even = 0, ans;
    cin >> n >> k;
    rep(i, n) {
        if((i + 1) % k == 0) cnt++;
        else if((i + 1) % k == k / 2) even++;
    }
    if(k % 2) ans = pow(cnt, 3);
    else ans = pow(cnt, 3) + pow(even, 3);
    cout << ans << endl;
}

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

int main() {
  long long L, R;
  std::cin >> L >> R;

  long long ans = L * (L + 1) % 2019;
  for (long long i = L; i < std::min(R, L + 2019); i++) {
    for (long long j = i + 1; j < std::min(R + 1, i + 2020); j++) {
      ans = std::min(ans, i * j % 2019);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

long long TwelvefoldWay2(long long n,long long k,long long MOD){
  long long ans = 1;
  FOR(i,0,n){
    ans *= (k-i);
    ans %= MOD;
  }
  return ans;
}

signed main(){
  ll n,k;
  cin >> n >> k;
  cout << TwelvefoldWay2(n,k,INF) << endl;
}


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

int main(){
  string s,t;
  cin >> s >> t;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
reverse(t.begin(),t.end());
if(s < t){ cout << "Yes"; }
else{ cout << "No"; }
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, long long L){
	ll a = 100000, sum = 0;
	repn(i,N) {
		if (abs(a)>abs(L+i-1)) a = L+i-1;
		sum += L+i-1;
	}
	cout << sum-a << endl;
}

int main(){	
	long long L;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&L);
	solve(N, L);
	return 0;
}



Measured memory_bytes: 256