akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args)throws Exception {

        Scanner sc = new Scanner(System.in);

        while (!sc.hasNext("0")) {
            int sum = 0;
            String line = sc.nextLine();
            char[] ch = line.toCharArray();
            for (int i = 0; i < ch.length; i++) {
                sum += Integer.parseInt("" + ch[i]); 
            }
            System.out.println(sum);
            
        }
        sc.close();
    }

}

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

long long dp[6010][2010];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    long long m; cin >> m;
    dp[0][0] = 1;
    for (int i = 0; i < 3*n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] %= m;
            dp[i+1][j] += dp[i][j];
            dp[i+2][j+1] += dp[i][j] * (3*n-i-1) % m;
            dp[i+3][j+1] += dp[i][j] * (3*n-i-1) % m * (3*n-i-2) % m;
        }
    }
    long long ans = 0;
    for (int i = 0; i <= n; i++) {
        ans = (ans + dp[3*n][i]) % m;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 94464
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
dd = defaultdict(int)

for num in a:
    dd[num] += 1
    if len(dd) >= 4:
        print("No")
        exit()

if len(dd) == 1:    
    if dd[0] > 0:
        print("Yes")
    else:
        print("No")
    exit()

if n % 3 != 0:
    print("No")
    exit()
    
    
if len(dd) == 2:
    if dd[0] == n // 3:
        print("Yes")
    else:
        print("No")
        
else:
    lst = []
    for i, j in dd.items():
        lst.append(i)
        if j != n // 3:
            print("No")
            exit()
    if lst[0] ^ lst[1] ^ lst[2] == 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
long long n,m,i,sz[705],sz2[705],mp[705][705],cnt,vis[705],ans=123456789123456ll;
bool dp[705][705];
void dfs(int x,int y){if (vis[x]) return;vis[x]=y;if (y-1) sz[cnt]++;else sz2[cnt]++;for (int i=1;i<=n;i++)if (i!=x&&!mp[x][i]){if (vis[i]==y){cout<<-1<<endl;exit(0);}dfs(i,3-y);}}
int main(){	cin>>n>>m;
	for (i=1;i<=m;i++){int x,y;cin>>x>>y;
		mp[x][y]=mp[y][x]=1;
	}for (i=1;i<=n;i++){	if (vis[i]) continue;
		cnt++;	dfs(i,1);
	}
	dp[0][0]=1;for (i=1;i<=cnt;i++){for (int j=sz[i];j<=n;j++) dp[i][j]|=dp[i-1][j-sz[i]];for (int j=sz2[i];j<=n;j++) dp[i][j]|=dp[i-1][j-sz2[i]];}
	for (i=0;i<=n;i++) if (dp[cnt][i]) ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
        int a,b;
        cin >> a;
        cin >> b;
        switch(a+b){
                case 3:
                        cout << 3 << endl;
                        break;
                case 4:
                        cout << 2 << endl;
                        break;
                case 5:
                        cout << 1 << 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);
    String S = sc.nextLine();
    int n1 =0, n2 = 0;
    for(int i = 0; i < S.length(); i++){
      if((i%2 == 0 && S.charAt(i) == '0') || (i%2 == 1 && S.charAt(i) == '1')){
        n1++;
      }else{
        n2++;
      }
    }
    System.out.println(Math.min(n1, n2));
  }
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> grid(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> grid.at(i).at(j);
    }
  }
  
  /*
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << grid.at(i).at(j);
    }
    cout << "" << endl;
  }
  */
  vector<int> hcheck(h,0);
  vector<int> wcheck(w,0);
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(grid.at(i).at(j) == '#'){
        hcheck.at(i) = 1;
        wcheck.at(j) = 1;
      }
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(hcheck.at(i) == 1 && wcheck.at(j) == 1){
        cout << grid.at(i).at(j);
      }
    }
    if(hcheck.at(i) == 1){
	  cout << endl;
    }
  }
  
  return(0);
}

Measured memory_bytes: 256
#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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;
  P p[m];
  rep(i, m) {
    int x, y; cin >> x >> y;
    p[i] = make_pair(y, x);
  }

  sort(p, p+m);
  
  int ans = 1, j = p[0].first;
  for(int i = 1; i < m; ++i) {
    if(j <= p[i].second) {
      ++ans;
      j = p[i].first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>
#include <valarray>
#include<stack>
#include<sstream>
#include<math.h>

using namespace std;

void Solution()
{
    int n, m, l;
    long int a[100][100] = {{0}};
    long int b[100][100] = {{0}};
    //long int c[100][100] = {{0}};
    long int sum = 0;
    cin>>n>>m>>l;
    
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            cin>>a[i][j];
        }
    }
    
     for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < l; j++)
        {
            cin>>b[i][j];
        }
    }
    
     for(int i = 0; i < n; i++)
    {
         for(int x = 0; x < l; x++)
         {
            for(int j = 0; j < m; j++)
            {
               sum += a[i][j] * b[j][x];
            }
             if(x == l - 1)
             {
                 cout<<sum;
             }
             else
             {
                cout<<sum<<" ";
             }
             sum = 0;
         }
         
         cout<<endl;
    }
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1324
"use strict";

(function(stdin){
  let input = stdin.split("\n");
  // 10進数に変換
  let n = parseInt(input[0], 10);
  let a = input[1].split(" ");

  for (let i = 0; i < n; i++) {
    a[i] = parseInt(a[i], 10);
  }

  let ans = 0;
  let up = false;
  let down = false;
  for (let i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      up = true;
    }
    if (a[i] > a[i + 1]) {
      down = true;
    }
    if (up && down) {
      up = down = false;
      ans++;
    }
  }

  console.log(ans + 1);
})(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n,k;cin>>n>>k;
    int ans=INF;
    //bit全探索
    for(int bit=0;bit<(1<<n);bit++){
        int tmp=1;
        rep(i,n){
            if(bit&(1<<i)){
                tmp*=2;
            }
            else tmp+=k;
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}


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

using namespace std;

const int len = 100010;
int a[len],n,k;

int main() {
	cin >> n >> k;
	for (int i=1;i<=n;i++) {
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	long long sum = 0;
	for (int i=n;i>=((n-k+1 <= 0) ? 1:(n-k+1));i--) {
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
} 

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

int main() {
	char S[4];
	int n = 0;
	for (int i = 0; i < 4; i++) {
		cin >> S[i];
		if (S[i] == '+') {
			n++;
		}
		if (S[i] == '-') {
			n--;
		}
	}
	cout << n << endl;

	return 0;
}

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

using namespace std;

int main() {
    string s, t, u;
    cin >> s >> t;
    int a, b;
    scanf("%d%d", &a, &b);
    cin >> u;

    if (s == u) a--;
    if (t == u) b--;

    printf("%d %d\n", a, b);
}


Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));

  int ans = 1;
  REP(i, N){
    if(__builtin_mul_overflow(ans, A[i], &ans)){
      cout << -1 << "\n";
      return 0;
    }
  }

  if(ans > 1000000000000000000) cout << -1 << "\n";
  else cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3948
#include<stdio.h>

int main(){
  int n,max,min,min_a;
  int i,check=0,mark=0;

  scanf("%d",&n);

  int R[n];
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }

  max = R[1];
  min = min_a = R[0];
  if(max-min>0) check=1;

  for(i=2;i<n;i++){
    if(!check){
      if((R[i]-R[i-1])>0){
        max = R[i];
        min = R[i-1];
        check = 1;
      }else if((max-min)<(R[i]-R[i-1])){
        max = R[i];
        min = R[i-1];
      }
    }else{
      if(max<R[i]) max = R[i];
      else if(min>R[i]){
        if(min_a>R[i]) min_a = R[i];
      }

      if((max-min)<(R[i]-min_a)){
        max = R[i];
        min = min_a;
      }
    }
  }

  printf("%d\n",max-min);
  return 0;
}



Measured memory_bytes: 2508
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll k;cin >> k;
    string s;
    while(k){
        k--;
        s+='a'+(k%26);
        k/=26;
    }
    rev(all(s));
    cout << s <<endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

int main(){
    ll n, y;
    cin >> n >> y;
    
    ll i, j;
    for(i = y/10000; i >= 0; i--){
        if (i > n) continue;
        for(j = (y-10000*i)/5000; j >= 0; j--){
            if (i+j > n) continue;
            if(10000*i + 5000*j + 1000*(n-i-j) == y){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
 }


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

int main() {
 int A, B, C, X, Y;
 cin >> A >> B >> C >> X >> Y;
   
 int total = 0;
 if( A + B > 2*C ) total += 2*C * min(X, Y); 
 else total += (A + B) * min(X, Y); 
  
 if( A > 2*C && X == max(X, Y)) total += 2*C * (X - Y);
 else if( A <= 2*C && X == max(X, Y)) total += A * (X - Y); 
 else if( B > 2*C && Y == max(X, Y)) total += 2*C * (Y - X);
 else total += B * (Y - X);
  
 cout << total << endl;
      
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString();
    n.split('\n')
        .filter(x => x !== "")
        .map(x => x.split(' ')
            .map(x => Number(x)))
        .map(x => sortary(x[0],x[1]))
        .forEach(x => {
            if (x[0] != 0 || x[1] != 0) {
                console.log(`${x[0]} ${x[1]}`);
            }
        });
})

function sortary(a,b){
    if(a>b){
        return [b,a];
    }
        return [a,b];
}


Measured memory_bytes: 19876
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll X, A, B;
    cin >> X >> A >> B;

    if(B <= A){
        cout << "delicious" << endl;
    }else if(B <= A + X){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }

    return 0;
}

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

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

unordered_map<lint, lint> pf(lint x){
    unordered_map<lint, lint> res;
    for(lint i=2;i*i<=x;++i){
        if(x%i==0){
            int cnt = 0;
            while(x%i==0) ++cnt, x /= i;
            res[i] = cnt;
        }
    }
    if(x>1) res[x]++;
    return res;
}

class DDivGame {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint N;
        in>>N;
        auto MP = pf(N);
        lint ans = 0;
        for(auto p : MP){
            lint nxt = 1;
            while(p.second>=nxt){
                ++ans;
                p.second -= nxt;
                ++nxt;
            }
        }
        out<<ans<<'\n';
    }
};


int main() {
	DDivGame solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  string A;
  cin >> A;
  int B=0;
  
  for (int i=0;i<3;i++){
    if(A.at(i)=='1'){
      B++;
    }  
  }  
  cout << B << endl;
}

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

	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int T = sc.nextInt();
	int []hairetu1 = new int[N];
	int []hairetu2 = new int[N];
	for(int i=0;i<N;i++) {
		hairetu1[i]=sc.nextInt();
		hairetu2[i]=sc.nextInt();
	}
int count=0;
	for(int i=0;i<N;i++) {
	if(hairetu2[i]<=T){
		count++;
	}
		}
	if(count==0){
		System.out.println("TLE");
		System.exit(0);
	}
	
	int z=0;
	int []hairetu3 = new int[count];
	for(int i=0;i<N;i++) {
		if(hairetu2[i]<=T){
			hairetu3[z]=hairetu1[i];
			z++;
		}
	}
	int min = hairetu3[0];
	for(int i=0;i<count;i++){
		if(min>hairetu3[i]){
			min=hairetu3[i];
		}
	}
	System.out.println(min);
	}
	}



Measured memory_bytes: 25428
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
fn main() {
    input! {
        N:i64,
        A:[i64;N],
        Q:usize,
        BC:[[i64;2];Q]
    }
    let mut elements: Vec<i64> = vec![0; 100001];
    let mut s: Vec<i64> = vec![0; Q + 1];
    for a in A {
        elements[a as usize] += 1;
        s[0] += a;
    }
    let mut i = 0;
    for bc in BC {
        let t = elements[bc[0] as usize];
        elements[bc[0] as usize] = 0;
        elements[bc[1] as usize] += t;
        s[i + 1] = s[i] + t * (bc[1] - bc[0]);
        i += 1;
    }
    for j in 1..Q + 1 {
        println!("{}", s[j]);
    }
}


Measured memory_bytes: 10804
from collections import Counter
# import sys

# input = sys.stdin.readline

N = int(input())
A = [int(a) for a in input().split()]

A1 = [0]*N
A2 = [0]*N

for i in range(N):
    A1[i] = A[i] + i
    A2[i] = i - A[i]

c = Counter(A2)

cnt = 0
for i in range(N):
    cnt += c[A1[i]]

print(cnt)

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

int main()
{
    int i=1, x;
    while(1)
    {
        cin >> x;
        if(x == 0)
        {
            break;
        }
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
    return 0;
}


Measured memory_bytes: 3108
#include<cstdio>
#include<algorithm>
#include<string.h>

using namespace std;

int w[1000],v[1000];
int dp[100001];

int main() {
	int n, W;
	scanf("%d%d", &n, &W);
	for (int i = 0; i < n; i++) scanf("%d%d", &v[i], &w[i]);

	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < n; j++) {
			if (i + w[j] <= W) {
				dp[i + w[j]] = max(dp[i + w[j]], dp[i] + v[j]);
			}
		}

	}
	printf("%d\n", dp[W]);
}


Measured memory_bytes: 3136
S = input()
S = S[::-1]

while True:
    if S[:5] == "maerd":
        S = S[5:]
    elif S[:7] == "remaerd":
        S = S[7:]
    elif S[:5] == "esare":
        S = S[5:]
    elif S[:6] == "resare":
        S = S[6:]
    else:
        break

if len(S) == 0:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 3188
#include<cstdio>
using namespace std;
#define N 142
#define mod 1000000007
int n,m,st[N],c[N][N],as,fr[N];
char s[N];
int pw(int a,int p){int as=1;while(p){if(p&1)as=1ll*as*a%mod;a=1ll*a*a%mod;p>>=1;}return as;}
int solve(int k)
{
	int v1=0,v3=k,v2=k;
	for(int i=1;i<=m;i++)
	if(s[i]=='r')
	if(v3>0)v3--;
	else v1-=v1>0;
	else if(v2>v3&&st[v2]>1)v1+=st[v2]-2,v2--;
	else v1-=v1>0;
	if(st[v2]>1||v3||v1)return 0;
	int ls=1,v5=fr[k];
	for(int i=2;i<=k;i++)if(st[i]==st[i-1])ls++;
	else v5=1ll*pw(fr[ls],mod-2)*v5%mod,ls=1;
	v5=1ll*pw(fr[ls],mod-2)*v5%mod;
	int s1=n+1,s2=1;
	for(int i=1;i<=k;i++)s1-=2*st[i]-2*(st[i]>1),s2+=2*st[i];
	if(s1<0)return 0;
	return 1ll*v5*c[s1+s2-1][s2-1]%mod;
}
void dfs(int d,int su)
{
	if(su<=35)as=(as+solve(d-1))%mod;else return;
	for(int i=st[d-1];i<=36-su;i++)st[d]=i,dfs(d+1,su+i-(i>1));
}
int main(){scanf("%d%d%s",&n,&m,s+1);for(int i=0;i<=141;i++)c[i][0]=c[i][i]=1;for(int i=2;i<=141;i++)for(int j=1;j<i;j++)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;fr[0]=1;for(int i=1;i<=70;i++)fr[i]=1ll*fr[i-1]*i%mod;st[0]=1;dfs(1,0);printf("%d\n",as);}

Measured memory_bytes: 256
""" AtCoder """

S = input()

l = ['+', '']

n = 2** (len(S) - 1)
ans = 0

for i in range(n):
    tmp = ''
    for j in range(len(S) - 1):
        tmp += S[j] + l[(i >> j) & 1]
    tmp += S[-1]
    ans += eval(tmp)

print(ans)


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

int main(){
    string s;
    cin>>s;
    int days = s.size(), wins_needed = 8;
    for(auto c : s){
        if (c=='o') wins_needed--;
    }if (15-days >= wins_needed) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String> ) {
  val m:MutableMap<Char, Int> = mutableMapOf()
  readLine()!!.toList().map { x ->
    if( m.get(x) == null )
      m[x] = 0
    m[x] = m[x]!! + 1
  }
  val r = m.all { xy ->
    val (x, y) = xy
    y%2 == 0
  }
  when(r) {
    true -> println("Yes")
    false -> println("No")
  }
}


Measured memory_bytes: 31900
hash = {}

gets.to_i.times do
  b, f, r, v = gets.split

  key = b + f + r
  val = hash.fetch(key, 0)

  hash[key] = val + v.to_i
end

(1..4).each do |b|
  (1..3).each do |f|
    (1..10).each do |r|
      v = hash.fetch("#{b}#{f}#{r}", 0)
      print " #{v}"
    end
    puts
  end
  puts '####################' if b != 4
end



Measured memory_bytes: 6876
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int ans;
    if (s == "SUN") {
        ans = 7;
    }
    else if (s == "MON") {
        ans = 6;
    }
    else if (s == "TUE") {
        ans = 5;
    }
    else if (s == "WED") {
        ans = 4;
    }
    else if (s == "THU") {
        ans = 3;
    }
    else if (s == "FRI") {
        ans = 2;
    }
    else {
        ans = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <cstdio>

using namespace std;

using int64 = long long;

class Combination {
 public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 800000;
  class LookupTable {
   public:
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  LookupTable lt{};
  // return nCk
  constexpr int64 Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) %
           mod_;
  }

 private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
};

template<typename T> void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}

Combination com;

int main() {
 int x, y; fastin(x); fastin(y);
  auto ok = [](int xx, int yy) -> bool {
    if (xx * 2 < yy || xx > yy * 2) return false;
    return (xx + yy) % 3 == 0;
  };
 
  if (!ok(x, y)) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return 0;
  }
 
  int nn = (x + y) / 3;
  int r = x - nn;
 
  int64 ans = com.Get(nn, r);
  fastout(ans);

  return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

/*
0-index
functionの中を書いて使う
宣言の時に単位元を書く
*/
template<typename T>
class segtree{
	int n;vector<T> dat;T ZERO;
public:
	segtree(int n_,T zero):ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}
	void update(int k, int a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = function(dat[k*2+1],dat[k*2+2]);
	  }
	}
	
	T function(T a,T b){
		return a + b;
	}
	
	T get(int k){return dat[k+n-1];}
	T que(int a,int b){
		T L = ZERO,R = ZERO;
		int A = a + n - 1;
		int B = b + n - 1;
		while(A < B){
			if((A & 1) == 0)L = function(L,dat[A++]);
            if((B & 1) == 0)R = function(R,dat[--B]);
            A = A >> 1;
            B = B >> 1;
		}
		return function(L,R);
	}
};

int main(){
	
	int n;cin >> n;
	vector<pair<int,int>> v(n);
	REP(i,n){
		cin >> v[i].FI;
		v[i].SE = i;
	}
	sort(ALL(v),greater<pair<int,int>>());
	
	ll ans = 0;
	segtree<int> seg(n,0);
	
	int num = 0;
	while(num < n){
		vector<pair<int,int>> now;
		now.PB(v[num]);
		while(num < n && v[num].FI == v[num+1].FI){
			now.PB(v[num + 1]);
			num++;
		}
		REP(i,now.size()){
			ans += min(seg.que(0,now[i].SE), seg.que(now[i].SE, n));
		}
		REP(i,now.size()){
			seg.update(now[i].SE, 1);
		}
		num++;
	}
	
	cout << ans << endl;
		
	
	return 0;
}


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

int main() {
   int x,y;
   cin >> x >> y;
   double candi = double(x+y)/2;
   if (candi != (x+y)/2) {
      cout << "IMPOSSIBLE" << endl;
      return 0;
   }
   if (candi == (x+y)/2) {
      if((x-candi) == (candi-y)) {
         cout << int(candi) << endl;
         return 0;
      }
      if((y-candi) == (candi-x)){
         cout << int(candi) << endl;
         return 0;
      }
   }
   if (x == y) {
      cout << int(x) << endl;
      return 0;
   }
   return 1; 
}


Measured memory_bytes: 256
from fractions import gcd
def lcm(a):

    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]//2) // gcd(x, a[i]//2)
    return x

def map_all(es):
    return all([e == es[0] for e in es[1:]]) if es else False

n,m = map(int,input().split())
a = list(map(int,input().split()))
tmp = [0] * n
for i in range(n):
    tmpnum = a[i]
    while 1:
        if tmpnum%2:
            break
        else:
            tmpnum/=2
            tmp[i]+=1

if not map_all(tmp):
    print('0')
    exit()
    
tmplcm = lcm(a)


m -= tmplcm//2
ans = m // tmplcm +1

print(max(ans,0))

Measured memory_bytes: 16344
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)

int main(){
  string s ;
  cin >> s;
  if(s.back()=='s'){
    cout << s << 'e' << 's';
  }else{
    cout << s << 's';
  }
  return 0;
}

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

using namespace std;

string save[9] = {"lol","SUN","MON","TUE","WED","THU","FRI","SAT"};

int main(){
	string s;
	cin >> s;
	for(int i=1;i<=7;i++)
		if(s==save[i]) { cout << 7-(i-1) << endl; return 0; }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 300010;

int k, n, ls;
int res[N];

void Dec(int k, int n, int *res, int &ls) {
    if (!ls) return;
    --res[ls];
    if (res[ls]) {
        for (++ls; ls <= n; ++ls)
            res[ls] = k;
    }
    --ls;
    return;
}

void Solve(int k, int n, int *res, int &ls) {
    ls = n;
    if (!(k & 1)) {
        res[1] = k / 2;
        for (int i = 2; i <= n; ++i)
            res[i] = k;
        return;
    }
    for (int i = 1; i <= n; ++i)
        res[i] = (k + 1) / 2;
    for (int i = n / 2; i; --i)
        Dec(k, n, res, ls);
    return;
}

int main() {
    scanf("%d%d", &k, &n);
    Solve(k, n, res, ls);
    for (int i = 1; i <= ls; ++i)
        printf("%d ", res[i]);
    putchar('\n');
    return 0;
}

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

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

const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

int main() {
#ifdef Mr_Emrul
	freopen("inputf.in", "r", stdin);
#endif /// Mr_Emrul

	long double a, b;
	cin >> a >> b;
	ll l = 0, r = 1e18;
	ll ans = 0;
	while(l <= r) {
		ll mid = (l + r) >> 1;
		if((long double) mid / b >= a) {
			ans = mid;
			r = mid - 1;
		}
		else {
			l = mid + 1;
		}
	}
	long double here = a * b;
	if(abs(here - (long double) ans) > 1e-15) {
		ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3724
#include<iostream>
using namespace std;
int main()
{
	long long a,b;
	char c;
	cin>>a>>c>>b;
	if(c=='+') cout<<a+b<<endl;
	if(c=='-') cout<<a-b<<endl;
	if(c=='*') cout<<a*b<<endl;
	if(c=='/') cout<<a/b<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
long a,i;
long b=0;
long k=0;
long min=999999;
char s[300000];
long kazu[300000];
int main(){
scanf("%ld",&a);
scanf("%s",s);
for(i=a;i>=0;i--){
if(s[i]=='E'){
b++;
}
kazu[i-1]=b;
}
b=0;
for(i=0;i<a;i++){
if(s[i]=='W'){
b++;
}
if(min>kazu[i]){
min=kazu[i];
}
kazu[i+1]+=b;
}
printf("%ld",min);
}


Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll N,K,ans=1,t=0;
  cin>>N>>K;
  REP(i,N){
    if(ans<=K) ans*=2;
    else ans+=K;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int n, k, x, y;
    scan(n);
    scan(k);
    scan(x);
    scan(y);
    writeln(x*(min(k, n)) + y*(max(0, n - k)));
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
struct Cards {
	int start,end;
	Cards(int _start,int _end) {start=_start,end=_end;}
};
vector<Cards> cards; 
int card[100000];
int main() {
	int n,k,i,j;
	bool blank;
	while(scanf("%d %d",&n,&k),n|k) {
		memset(card,0,sizeof(card));
		cards.clear();
		blank=0;
		for(i=0;i<k;i++) {
			scanf("%d",&card[i-blank]);
			if(card[i-blank]==0) blank=1;
		}
		k-=blank;
		sort(card,card+k);
		int ans=0;
		for(i=0;i<k;i++) {
			for(j=i+1;j<k;j++) {if((card[j]-card[j-1])!=1)break;}
			cards.push_back(Cards(card[i],card[j-1]));
			ans=max(ans,card[j-1]-card[i]+1);
			i=j-1;
		}
		if(!blank) {printf("%d\n",ans); continue;}
		for(i=0;i<cards.size();i++) {
			if(i==0) {
				if(cards[i].start>1)
					ans=max(ans,cards[i].end-cards[i].start+2);
			}else if((cards[i].start-cards[i-1].end)==2) {
				ans=max(ans,(cards[i].end-cards[i].start+1)+(cards[i-1].end-cards[i-1].start+1)+1);
			}
		}
		if(cards[i-1].end<n) ans=max(ans,(cards[i-1].end-cards[i-1].start+1));
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1572
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1e9+7;

ll f(pair<string,ll>&x ,pair<string,ll>&y) 
{
	if(x.first == y.first) 
	{
		return x.second>y.second;
	}
	else 
	{
		return x.first<y.first;
	}
}
 
void solve()
{
	ll n;
	cin >> n;
	vector<pair<string ,ll>> a(n);
	
	map<ll,ll>idx;
	
	for(ll i=0;i<n;i++) 
	{
		cin>>a[i].first>>a[i].second;
		idx[a[i].second]=i+1;
	}
	
	sort(a.begin(),a.end(),f);
	
	for(ll i=0;i<n;i++) 
	{
		cout<<idx[a[i].second]<<endl;
	}
	
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();
        
        return 0;
}


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

#define ll long long int
#define ff(i,a,b) for(ll i = a; i < b; i++)
#define bf(i,b,a) for(ll i = b-1; i >= a; i--)
#define itf(i,a) for(auto i = a.begin(); i != a.end(); i++)
#define itfr(i,a) for(auto i = a.rbegin(); i != a.rend(); i++)
#define MII map<ll,ll> 
#define MCI map<char,ll>
#define MSI map<string,ll>
#define VI vector<ll> 
#define VC vector<char> 
#define VS vector<string> 
#define MP make_pair
#define tc ll t; cin>>t; while(t--)
#define DISPV(v) itf(i,v) cout << *i << ' ';
#define DISPM(m) itf(i,m) cout << i->first << ' ' << i->second << endl;

const int MOD = int(1e9) + 7;

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n,x,t;
    cin >> n >> x >> t;
    if(n%x == 0){
        cout << (n/x) * t;
    }
    else
        cout << ((n/x)+1) * t;
    // cout << a*t;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;


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

	total = (n - 1)*(m - 1);

	cout << total;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    	double d, t, s;
      	cin >> d >> t >> s;
      	double x = d/s;
     	if(x <= t)
          cout << "Yes" << "\n";
      	else
          cout << "No" << "\n";
      	return 0;
    }

Measured memory_bytes: 3720
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P,P> P2;
const int INF = 1 << 30;
const double EPS = 1E-9;

int t[100][2];
int c[100][2];

int main(){
	int n;
	while(cin >> n && n){
		fill(&c[0][0], &c[99][1], INF);
		for(int i = 0; i < 2; i++){
			for(int j = 0;j < n; j++){
				cin >> t[j][i];
			}
		}
		int a[2];
		a[0] = a[1] = 0;
		for(int i = 0; i < 2; i++){
			if(t[0][i] == 0) continue;
			while(a[i]+1 < n && t[a[i]+1][i] == 1) a[i]++;
		}
		c[a[0]][0] = c[a[1]][1] = 0;
		queue<P> que;
		que.push(P(a[0], 0));
		que.push(P(a[1], 1));
		while(!que.empty()){
			P p = que.front();
			que.pop();
			int tower = p.second;
			int nt = (tower+1) % 2;
			int pl = p.first;
			for(int i = 0; i < 3; i++){
				if(pl + i >= n) continue;
				if(t[pl+i][nt] == 0){
					if(c[pl+i][nt] > c[pl][tower] + 1){
						c[pl+i][nt] = c[pl][tower] + 1;
						que.push(P(pl+i, nt));
					}
				}else if(t[pl+i][nt] == 1){
					int j = 0;
					while(pl + i + j + 1 < n && t[pl+i+j+1][nt] == 1) j++;
					if(c[pl+i+j][nt] > c[pl][tower] + 1){
						c[pl+i+j][nt] = c[pl][tower]+1;
						que.push(P(pl+i+j, nt));
					}
				}else{
					int j = 0;
					while(t[pl+i-j][nt] == 2) j++;
					if(c[pl+i-j][nt] > c[pl][tower] + 1){
						c[pl+i-j][nt] = c[pl][tower] + 1;
						que.push(P(pl+i-j, nt));
					}
				}
			}
		}
		if(c[n-1][0] == INF && c[n-1][1] == INF) cout << "NA" << endl;
		else cout << min(c[n-1][0], c[n-1][1]) << endl;
	}
	return 0;
}
	

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize ("O3")
using namespace std;
int main () {
    ios::sync_with_stdio(false);
    cin.tie (0);    
    ll a; cin>>a;
    ll b=3*a*a;
    cout<<b;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>

using namespace std;

#define ll long long
#define f0(i,n)for(i=0;i<n;i++)
#define f1(i,n)for(i=1;i<=n;i++)
#define fc(i,c,n)for(i=c;i<=n;i++)
#define f0r(i,n)for(i=n-1;i>=0;i--)
#define f1r(i,n)for(i=n;i>0;i--)
#define fcr(i,c,n)for(i=n;i>=c;i--)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

long long i, j, q;

int main() {
	IO;
	ll mod = 1000000007;
	//ifstream cin("In.txt");
	ll n, c;
	//2 1 2 2 1 2 2 2 1 2
	cin >> n;
	VEC vc(n + 1), lp(200001), ans(n + 1, 1);
	f1(i, n) {
		cin >> c;
		ans[i] = ans[i - 1] + ((lp[c] && (i - lp[c]>1)) ? ans[lp[c]] : 0);
		ans[i] %= mod;
		lp[c] = i;
	}
	cout << ans[n] << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#include <queue>
#define MAX 100000000000001
using namespace std;

long long X;
long long a[1000];

int main(){
    cin >> X;
    int i=0;
    a[0]=0ll;
    bool b=true;
    while(a[i]<MAX){
        i++;
        a[i]=pow(i,5);
    }
    for(int j=0;j<=i;j++){
        if(b){
            for(int k=0;k<=i;k++){
                if(a[j]+a[k]==X){
                    cout << j << " " << -k << endl;
                    b=false;
                    break;
                } else if(a[j]-a[k]==X){
                    cout << j << " " << k << endl;
                    b=false;
                    break;
                }
            }
        }
    }

}

Measured memory_bytes: 4108
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val k = sc.nextLong()
    var one = 0
    while(one < s.length && s[one] == '1') one++

    if (k <= one) {
        println(1)
    } else {
        println(s[one])
    }
}

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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const ll mod=1e9+7;

// basic matrix class, properties:
// can be initialized with value or as empty with given dimentions
// vals can be accessed via [][]
// can be multiplied
// can be written to stream
template<class T>
struct matrix{
	vector<vector<T>>vals;
	int n,m;
	matrix(int n,int m):n(n),m(m){
		vals.resize(n,vector<T>(m));
	}
	matrix(vector<vector<T>>v):vals(v),n(vals.size()),m(vals[0].size()){}
	vector<T>&operator[](int idx){return vals[idx];}
};

// multiplication
template<class T>
matrix<T>operator*(matrix<T> m,matrix<T> m2){
	matrix<T> r(m.n,m2.m);
	for(int i=0;i<m.n;++i)
		for(int j=0;j<m2.m;++j)
			for(int k=0;k<m2.n;++k)
				r[i][j]=(r[i][j]+m[i][k]*m2[k][j])%mod;
	return r;
}

// writing to stream
template<class T>
ostream &operator<<(ostream &s,matrix<T>&m){
	for(int i=0;i<m.n;++i,s<<endl)
		for(int j=0;j<m.m;++j)
			s<<m[i][j]<<" ";
	return s;
}

// matrix exponentiation
template<class T>
matrix<T> exp(matrix<T> a,ll b){
	if(b==1)return a;
	if(b%2)return a*exp(a*a,b/2);
	return exp(a*a,b/2);
}

const int N=55;
int n;
ll k;
main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>k;
	matrix<ll>m(n+1,n+1);
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin>>m[i][j];
	for(int i=0;i<n;++i)m[n][i]=1;
	m=exp(m,k+1);
	ll res=0;
	for(int i=0;i<n;++i)res=(res+m[n][i])%mod;
	cout<<res<<endl;
}


Measured memory_bytes: 7604
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0,(i##_len)=(n);(i)<(i##_len);(i)++)
#define rep2(i,a,b) for(ll (i)=(a),(i##_len)=(b);(i)<=(i##_len);(i++))
#define Yes(n) cout<<((n)?"Yes\n":"No\n")
#define pb push_back
using namespace std;
using ll = long long;

template<class T> bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> T abs(T x){return max(x,-x);}
template<class T> T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> T lcm(T m,T n) {return m*n/gcd(m,n);}
template<class T> T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm<T>(r,v.at(i));return r;}
template<class T> T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> T nCr(T n,T k){return factorial<T>(n)/(factorial<T>(k)*factorial<T>(n-k));}
template<class T> T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> T sum(vector<T>v){return reduce(all(v),0LL);}
vector<string> split(const string&s,char d){vector<string>r;stringstream ss(s);string k;while(getline(ss,k,d))if(!k.empty())r.pb(k);return r;}

// Template ends here

void solve(ll K){
    ll sum = 0;
    rep2(a, 1, K) {
        rep2(b, 1, K) {
            rep2(c, 1, K) {
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << "\n";
}

int main() {
    ll K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  long long ans = 0;
  long long  a = 0;
  for(auto c : s) {
    if(c == 'R') {
      ans++;
      a = max(a, ans);
    } else {
      ans = 0;
    }
  }
  cout << a << endl;
  return 0;
}


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

int main() {
  int n;
  scanf("%d", &n);
  double x[n], ans = 0.0;
  char u[n][4], jpy[4] = "JPY", btc[4] = "BTC";
  for (size_t i = 0; i < n; i++) {
    scanf("%lf%s", x+i, u[i]);
    if (strcmp(u[i], jpy) == 0) {
      ans += x[i];
    } else {
      ans += x[i] * 380000.0;
    }
  }
  printf("%lf\n", ans);
  return 0;
}


Measured memory_bytes: 128
N, M = (int(i) for i in input().split())

def yaku(N):
    res = []
    for i in range(1, round(N**(1/2)) + 3 ):
        if N%i == 0:
            res.append(i)

    res2 = [N//i for i in res]
    res = list(set(res + res2))
    return res


import bisect

L = yaku(M)

L.sort()
ii = bisect.bisect_left(L,N)

print(M//L[ii])

Measured memory_bytes: 38640
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<stack>
#include<vector>
//#include<conio.h>
#include<string>
#include<map>
#include<cstdlib>
#include<queue>
#include<math.h>
#include<time.h>
#include<set>
#include<cstdio>
#include<stdio.h>
#include<algorithm>
using namespace std;
inline int read(){
	int ans=0,flag=1;
	char ch=getchar();
	while((ch>'9'||ch<'0')&&ch!='-') ch=getchar();
	if(ch=='-') flag=-1,ch=getchar();
	while(ch>='0'&&ch<='9'){
		ans=(ans<<1)+(ans<<3)+(ch^'0');
		ch=getchar();
	}
	return ans*flag;
}
int n,a;
int main(){
	n=read(),a=read();
	if(n%500<=a) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

using namespace std;

int main() {
	vector<Int> a(7);
	for (int i = 0; i < 7; ++i) { cin >> a[i]; }

	Int ans = 2*(a[0]/2 + a[3]/2 + a[4]/2) + 3*((a[0]&1) && (a[3]&1) && (a[4]&1));
	if (a[0] && a[3] && a[4]) {
		ans = max(ans, 2*((a[0]-1)/2 + (a[3]-1)/2 + (a[4]-1)/2) + 3);
	}
	cout << ans + a[1] << "\n";

	return 0;
}


Measured memory_bytes: 3636
#N個から3個を取り出す組み合わせ
#ただし、Sが設定されているため、同じ３桁の数字が出てくる場合があるので、実際に消さないといけない
#逆に、３桁なので000<=ans<=999
N = int(input())
S = input()
ans = 0

for i in range(0, 1000):
  i = str(i)
  S_ = S
  i = i.zfill(3)
  if i[0] in S_:
    fir = S_.find(i[0])
    S_ = S_[fir+1:]
    if i[1] in S_:
      sec = S_.find(i[1])
      S_ = S_[sec+1:]
      if i[2] in S_:
        ans += 1
        
print(ans)

Measured memory_bytes: 3188
///spaesk

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define pi acos(-1)
#define int long long int
#define ld long double
#define ar array
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int maxN = 1000007;

///
///

void solve()
{

    int n;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i ++) {
        cin>>a[i];
    }
    int ans = 1000;
    for(int i = 1; i < n; i ++) {
        int x = ans / a[i - 1];
        int y = x * a[i];
        int p = ans;
        ans %= a[i - 1];
        if(ans + y > p)
            ans = ans + y;
        else
            ans = p;
    }
    cout<<ans;
    cout<<"\n";
    return ;
}

/*
*/

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
const int MOD = 1000000007;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}


int main() {
    int n; cin >> n; int ans = 0,cnt = 0;
    int a[n]; cin >> a[0];
    for(int i = 1;i < n;i++){
        cin >> a[i];
        if(a[i] <= a[i-1]){
            cnt++;
        }else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    cout << max(ans,cnt);
}


Measured memory_bytes: 3988
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D;
    ll X[4];
    string S,T;
int main(){
    cin>>A;
    if(A<=25)cout<<"Christmas";
    if(A<=24)cout<<" Eve";
    if(A<=23)cout<<" Eve";
    if(A<=22)cout<<" Eve";
    return 0;
}

Measured memory_bytes: 256