akhauriyash/Code-Regression huggingface dataset:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
else:
    x=[]
    for i in range(1,w):
        sub=[]
        sub.append([h*i,h*((w-i)//2),h*(w-i)-h*((w-i)//2)])
        sub.append([h*i,h*((w-i)//2+1),h*(w-i)-h*((w-i)//2+1)])
        sub.append([h*i,(w-i)*(h//2),h*(w-i)-(w-i)*(h//2)])
        sub.append([h*i,(w-i)*(h//2+1),h*(w-i)-(w-i)*(h//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    for i in range(1,h):
        sub=[]
        sub.append([w*i,w*((h-i)//2),w*(h-i)-w*((h-i)//2)])
        sub.append([w*i,w*((h-i)//2+1),w*(h-i)-w*((h-i)//2+1)])
        sub.append([w*i,(h-i)*(w//2),w*(h-i)-(h-i)*(w//2)])
        sub.append([w*i,(h-i)*(w//2+1),w*(h-i)-(h-i)*(w//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    print(min(x))


Measured memory_bytes: 34724
N = int(input())
A = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
B = [int(i) for i in input().split()]	# 1 2 3 4 5 ...
C = [int(i) for i in input().split()]	# 1 2 3 4 5 ...

A.sort()
B.sort()
C.sort()

#print(A)
#print(B)
#print(C)
##exit(0)

ab=[0]*N
bc=[0]*N

b=N-1
c=N-1
count=0
while (0<=b):
	while (0<=c):
		if B[b]<C[c]:
			count += 1
			c -= 1
		else:
			break
	bc[b] = count
	if b<N-1:
		bc[b] += bc[b+1]
	b -= 1

a=N-1
b=N-1
count=0
while (0<=a):
	while (0<=b):
		if A[a]<B[b]:
			count += 1
			b -= 1
		else:
			break
	ab[a] = count
	a -= 1


#print(ab)
#print(bc)

ans=0

for i in ab:
#	print(i, bc[N-i:N])
#	ans += sum(bc[N-i:N])
	if i>0:
		ans += bc[N-i]

print(ans)


Measured memory_bytes: 23644
import java.awt.Point;
import java.util.LinkedList;
import java.util.Scanner;
 
public class Main {
     
	static int W, H;
	static int[][] tate;
	static int[][] yoko;
	
    static void start()
    {
    	int[][] check = new int[H][W];
    	for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				check[y][x] = 0;
			}
		}
    	
    	LinkedList<Point> queue = new LinkedList<Point>();
    	LinkedList<Integer> turn = new LinkedList<Integer>();
    	queue.offer(new Point(0, 0));
    	turn.offer(new Integer(1));
    	
    	while (!queue.isEmpty()) {
			Point p = queue.poll();
			int t = turn.poll().intValue();
			
			if(check[p.y][p.x] != 0) continue;
			check[p.y][p.x] = t;
			
			// 上
			if(0 < p.y)
			{
				// 壁判定
				if(yoko[p.y-1][p.x] == 0)
				{
					queue.offer(new Point(p.x, p.y-1));
					turn.offer(new Integer(t + 1));
				}
			}
			
			// 下
			if(p.y < H-1)
			{
				// 壁判定
				if(yoko[p.y][p.x] == 0)
				{
					queue.offer(new Point(p.x, p.y+1));
					turn.offer(new Integer(t + 1));
				}
			}
			
			// 左
			if(0 < p.x)
			{
				// 壁判定
				if(tate[p.y][p.x-1] == 0)
				{
					queue.offer(new Point(p.x-1, p.y));
					turn.offer(new Integer(t + 1));
				}
			}
			
			// 右
			if(p.x < W-1)
			{
				// 壁判定
				if(tate[p.y][p.x] == 0)
				{
					queue.offer(new Point(p.x+1, p.y));
					turn.offer(new Integer(t + 1));
				}
			}
		}
    	
    	System.out.println(check[H-1][W-1]);
    }
     
    public static void main(String[] args)
    {
        Scanner sca = new Scanner(System.in);
        
        while(true)
        {
        	W = sca.nextInt();
        	H = sca.nextInt();
        	if(W == 0) break;
        	
        	tate = new int[H][W-1];
        	yoko = new int[H-1][W];
        	int y;
        	for (y = 0; y < H-1; y++) {
				for (int x = 0; x < W-1; x++) {
					tate[y][x] = sca.nextInt();
				}
				for (int x = 0; x < W; x++) {
					yoko[y][x] = sca.nextInt();
				}
			}
        	for (int x = 0; x < W-1; x++) {
				tate[y][x] = sca.nextInt();
			}
            
            start();
        }
        
    }
}

Measured memory_bytes: 70732
#include <iostream>
#include <vector>

int main(void){
  int h, w, a, b;
  std::cin >> h >> w >> a >> b;
  

  std::vector<std::vector<int> > mat(h, std::vector<int>(w));
  std::vector<int> tate_sum(w);
  std::vector<int> yoko_sum(h);
  
  for(int i=0; i<mat.size(); i++){
    for(int j=0; j<mat[i].size(); j++){
      if(yoko_sum[i] >= w-a) continue;
      if(tate_sum[j] >= h-b) continue;
      mat[i][j] = 1;
      yoko_sum[i]++;
      tate_sum[j]++;
    }
  }

  for(int i=0; i<mat.size(); i++){
    for(int j=0; j<mat[i].size(); j++){
      std::cout << mat[i][j];
    }
    std::cout << std::endl;
  }
  
  return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int N,W;
ll w[100],v[100];
ll dp[2][100010];

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

  cin>>N>>W;
  rep(i,N)cin>>w[i]>>v[i];

  int crt=0,nxt=1;
  rep(i,2)rep(j,100010)dp[i][j]=INF;
  dp[crt][0]=0;
  rep(i,N){
    rep(j,100010)dp[nxt][j]=INF;
    rep(j,100010){
      if(dp[crt][j]==INF)continue;
      if(j+v[i]<=100000)minch(dp[nxt][j+v[i]],dp[crt][j]+w[i]);
      minch(dp[nxt][j],dp[crt][j]);
    }
    swap(crt,nxt);
  }
  ll res=0;
  rep(j,100010)if(dp[crt][j]<=W)maxch(res,j);
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 1920
N,W =map(int,input().split())
weight,value=[],[]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
inf = float('inf')
dp = [[inf for _ in range(10**3*N+10)] for _ in range(N+10)]
maxv = sum(value)
#初期化
dp[0][0] =0
for i in range(N):
    for sum_v in range(maxv+1):
        if sum_v-value[i] >=0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v],dp[i][sum_v-value[i]] + weight[i])
        dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])
res =0
for sum_v in range(maxv+1):
    if dp[N][sum_v] <=W:
        res = sum_v
print(res)

Measured memory_bytes: 340024
n,m = map(int,input().split())
a = set([int(input()) for i in range(m)])
inf = 1000000007

dp = [0] * (n+1)
dp[0] = 1

if 1 not in a:
    dp[1] = 1
else:
    dp[1] = 0

for i in range(2,n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= inf

print(dp[n])

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

int main() {
  vector<ll> p = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
  ll N; cin >> N;
  map<ll, ll> count;
  for (ll n = 2; n <= N; n++) {
    for (ll i = 0; i < 15; i++) {
      ll pow = 0;
      ll num = n;
      while (num % p[i] == 0) {num/=p[i]; pow++;}
      count[p[i]] += pow;
    }
  }
  ll g3 = 0, g5 = 0, g15 = 0, g25 = 0, g75 = 0;
  for (ll i = 0; i < 15; i++) {
    if (count[p[i]] >= 74) {g3++; g5++; g15++; g25++; g75++;}
    else if (count[p[i]] >= 24) {g3++; g5++; g15++; g25++;}
    else if (count[p[i]] >= 14) {g3++; g5++; g15++;}
    else if (count[p[i]] >= 4) {g3++; g5++;}
    else if (count[p[i]] >= 2) {g3++;}
  }
  ll res = 0;
  res += g75;
  if (g25 > 0) {res += (g3-1)*g25;}
  if (g15 > 0) {res += (g5-1)*g15;}
  if (g5 > 1) {res += (g3-2)*g5*(g5-1)/2;}
  cout << res << endl;  
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    bool success = false;
    for (int i = 0; i < n; i++)
    {
        string ss = s.substr(i, n - i);
        string st = t.substr(0, n - i);
        if (ss == st)
        {
            success = true;
            cout << (n + i) << endl;
            break;
        }
    }
    if (!success)
    {
        cout << (2 * n) << endl;
    }
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [isize;n],
    }

    let n_minus_h: Vec<isize> = a.iter().enumerate().map(|(i, &v)| i as isize - v).collect();
    let mut n_plus_h: Vec<isize> = a.iter().enumerate().map(|(i, &v)| i as isize + v).collect();
    n_plus_h.sort();

    let mut ans: usize = 0;

    for i in n_minus_h {
        let upper = n_plus_h.upper_bound(&i);
        let lower = n_plus_h.lower_bound(&i);
        ans += upper - lower;
    }

    println!("{}", ans);
}


Measured memory_bytes: 9012
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int MX=2e5+7;
const int mod=1e9+7;
const double eps=1e-6;
const double pi=3.14159265358979;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}
ll __gcm(ll a,ll b){return a*b/__gcd(a,b);}
int G[MX],R[MX],B[MX];
char S[MX];
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  int N;
  cin>>N;
  //string S;
  cin>>S+1;
  for(int i=N;i>=1;i--){
    G[i]=G[i+1]+(S[i]=='G');
    R[i]=R[i+1]+(S[i]=='R');
    B[i]=B[i+1]+(S[i]=='B');
  }
  //cout<<G[1]<<" "<<R[1]<<" "<<B[1]<<endl;
  ll ans=0;
  for(int i=1;i<=N;i++)
  {
      for(int j=i+1;j<=N;j++)
      {
          if((S[i]=='R'&&S[j]=='B')||(S[i]=='B'&&S[j]=='R'))
             {
                 ans+=G[j+1];
                 if(2*j-i<=N)
                 {
                     ans-=G[2*j-i]-G[2*j-i+1];
                 }
             }
         else if((S[i]=='R'&&S[j]=='G')||(S[i]=='G'&&S[j]=='R'))
         {
                  ans+=B[j+1];
                 if(2*j-i<=N)
                 {
                     ans-=B[2*j-i]-B[2*j-i+1];
                 }
         }
         else if((S[i]=='B'&&S[j]=='G')||(S[i]=='G'&&S[j]=='B')){
                 ans+=R[j+1];
                 if(2*j-i<=N)
                 {
                     ans-=R[2*j-i]-R[2*j-i+1];
                 }
         }
      }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3680
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
#include <complex>
#define int long long
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
inline void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
inline void writeln(int x){
	write(x);puts("");
}
map<int,int>mp;
signed main()
{
	int n=read(),ans=0,sum=0;
	mp[0]=1;
	for(int i=1;i<=n;i++){
		sum+=read();ans+=mp[sum];
		mp[sum]++;
	}
	writeln(ans);
	return 0;
}

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

int n, m;
bool b[504];

int c;
bool s[501];
int DP[2][1<<25];

int bc(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {

    while(cin>>n>>m,n|m) {
        char a;
        rep(i, n) {
            rep(j, m) {
                cin>>a;
                b[i*m+j] = (a == '1');
            }
        }

        if(n<25) {
            int r = 0;
            rep(i, 1<<n) {
                rep(j, m)s[j] = true;

                c = bc(i);

                if(c<=r)continue;

                rep(j, n) {
                    if(i&(1<<j)) {
                        rep(k, m) {
                            if(b[j*m+k])s[k] = !s[k];
                        }
                    }
                }

                bool f = true;
                rep(j, m) {
                    if(!s[j]) {
                        f = false;
                        break;
                    }
                }
                if(f)r = c;
            }
            
            cout<<r<<endl;

        }else {
            c = 0;
            rep(j, m) {
                if(b[j])c += 1<<j;
            }

            rep(i, 1<<m) {
                DP[0][i] = -1;
                DP[1][i] = -1;
            }
            
            DP[0][0] = 0;
            DP[0][c] = 1;

            for(int i=1;i<n;i++) {
                c = 0;
                rep(j, m) {
                    if(b[i*m+j])c += 1<<j;
                }
                rep(j, 1<<m) {
                    DP[i&1][j] = DP[(i-1)&1][j];
                    if(DP[(i-1)&1][j^c]>=0 && DP[(i-1)&1][j^c]>=DP[i&1][j])DP[i&1][j] = DP[(i-1)&1][j^c]+1;
                }
            }

            cout<<(DP[(n-1)%2][0]<0?0:DP[(n-1)%2][0])<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 11216
#include <stdio.h>

int main(void){
  int a,b,c;
  int k;
  int i;
  int max;
  int notmax1,notmax2;
  int result;

  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&k);

  if(a>=b){
    if(a>=c){
      max=a;
      notmax1=b;
      notmax2=c;
    }
    else{
      max=c;
      notmax1=a;
      notmax2=b;
    }
  }
  else{
    if(b>=c){
      max=b;
      notmax1=a;
      notmax2=c;
    }
    else{
      max=c;
      notmax1=a;
      notmax2=b;
    }
  }

  for(i=0;i<k;i++){
    max*=2;
  }

  result=max+notmax1+notmax2;

  printf("%d\n",result);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
int main() {
  INIT;
  
  int n,h;
  int count =0;
  cin >> n >> h;
  int a[n],b[n];
  REP(i,n){
    cin >> a[i] >> b[i];
  }
  std::vector<int> va(a, a+n);

  int imax = *std::max_element(va.begin(), va.end());
  int suffix;
  REP(i,n){
    if(a[i] == imax){
      suffix = i;
      break;
    }
  }

  std::vector<int> vb(b, b+n);
  sort(vb.begin(), vb.end(),std::greater<int>());

  REP(i,n){
    if(vb[i] < imax){
      break;
    }
    h -= vb[i];
    count +=1;
    if(h <= 0){
      printf("%d\n", count);
      exit(0);
    }
  }

  while (1) {
    h -= imax;
    count++;
    if(h <= 0){
      printf("%d\n", count);
      exit(0);
    }
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

int main( int argc, char *argv[] ) {
	string n;
	cin >> n;
	int res;
	if ( n == "SUN" )
		res = 7;
	else if ( n == "SAT" )
		res = 1;
	else if ( n == "FRI" )
		res = 2;
	else if ( n == "THU" )
		res = 3;
	else if ( n == "WED" )
		res = 4;
	else if ( n == "TUE" )
		res = 5;
	else
		res = 6;
	cout << res << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; long long int S[100010] = {}; 
	cin >> N; 
	for(int i = 0; i < N; i++){
		cin >> S[i]; 
	}
	long long int ans = 0; // m=A-Bとするとmは1以上N-1以下
	for(int m = 1; m < N; m++){
		long long int mx = 0; 
		long long int tmp = 0; // S[0] + S[N-1] から始めて次は S[m] + S[N-1-m] を足す感じ
		for(int j = 1; N - 1 - j * m > m; j++){ // B > 0 に注意！
			if((N - 1) % m == 0 && N - 1 - j * m <= j * m) break; 
			tmp += S[j * m] + S[N - 1 - j * m]; 
			mx = max(mx, tmp); 
		}
		ans = max(ans, mx); 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 1024
// ==============================================
// Library
// ==============================================
#define _CRT_SECURE_NO_WARNINGS

// When you are using the gcc compiler, you need only the following lines.
// #include <bits/stdc++.h>

// When you are using other compilers, you need the following line instead.
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

// competitive macro
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i ,n) for (int i = (n) - 1; i >= 0; i--)
#define LL long long
#define ULL unsigned long long

// If you use this function, "cin" speeds up.
// However, you can not mix "cin" and "scanf", "cout" and "printf".
void fastIOS()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
}
// ==============================================
// ==============================================

array<int, 100000> A = {};

int main()
{
	fastIOS();

	int n;
	cin >> n;
	vector<int> T;
	REP(i, n)
	{
		int tmp1;
		cin >> tmp1;
		T.push_back(tmp1);
	}

	int m;
	cin >> m;
	vector<int> P, X;
	REP(i, m)
	{
		int tmpp, tmpx;
		cin >> tmpp >> tmpx;
		P.push_back(tmpp);
		X.push_back(tmpx);
	}


	REP(i, m)
	{
		int ans = 0;
		REP(j, n)
		{
			int pluser = T[j];
			if (j == (P[i] - 1))
				ans += X[i];
			else
				ans += T[j];
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, ans = "No";
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i]=='A' && s[i+1]=='C') {
      ans = "Yes";
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
        public static void main(String[] args) throws Exception {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st;
                PrintWriter pw = new PrintWriter(System.out);

                int n = Integer.parseInt(br.readLine());
                st = new StringTokenizer(br.readLine());
                int start = 1;
                for(int i=0 ; i<n ; i++) {
                        int x = Integer.parseInt(st.nextToken());
                        if(x == start) {
                                start++;
                        }
                }

                if(start == 1) {
                        pw.println(-1);
                }
                else {
                        start--;
                        pw.println(n-start);
                }


                pw.flush();
                pw.close();
        }
}


Measured memory_bytes: 43348
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  s = input()
  ans = 0
  for i in s:
    if i == '+':
      ans += 1
    else:
      ans -= 1
  print(ans)
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5244
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define ld long double
#define ll long long
#define pb push_back
#define S second
#define F first
using namespace std;
int n,m,k;
int p[100009];
int mp[100009];
vector < int > v[100009];
vector < int > vv[100009];
int get(int node){
    if(p[node] == node) return node;
    return p[node] = get(p[node]);
}
void merg(int a,int b){
    int A = get(a);
    int B = get(b);
    p[A] = B;
}
int main(){
    fast,cin>>n>>m>>k;
    for(int i=0;i<n;i++) p[i] = i;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].pb(b);
        v[b].pb(a);
        if(get(a) != get(b)){
            merg(a,b);
        }
    }
    for(int i=0;i<k;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        vv[a].pb(b);
        vv[b].pb(a);
    }
    for(int i=0;i<n;i++){
        mp[get(i)]++;
    }
    for(int i=0;i<n;i++){
        set < int > se;
        for(auto u:v[i]){
            se.insert(u);
        }
        int node = get(i);
        for(auto u:vv[i]){
            if(get(u) == node){
                se.insert(u);
            }
        }
        int sz = se.size();
        cout<<mp[node]-sz-1<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 17528
#include<iostream>
#include<cstdio>
#include<cctype>

using namespace std;

int main(){
  char ch;

  while((ch = getchar()) != EOF){
    if(islower(ch)) ch = toupper(ch);
    else            ch = tolower(ch);
    cout << ch;
  }
  return 0;
}

Measured memory_bytes: 1088
s = list(input())
n = len(s)
#print(n)
k,g=[],[]
for i in range(n):
    if i%2==0:
        k.append(s[i])
    else:
        g.append(s[i])
#print(k)
#print(g)
for j in k:
    if j == 'L':
        print('No')
        break

else:
    for l in g:
        if l == 'R':
            print('No')
            break
    else:
        print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
namespace IO{

cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
    return f?res:-res;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();
	return ch;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	s[top+1]='\0';return top;
}

}
using IO::read;
using IO::readll;
using IO::readstring;
using IO::readchar; 
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+b)>=mod?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b)>=mod?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);}
cs int N=105;
int n,cnt,f[N][N],a[N],h[N],c[N];
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(int i=1;i<=n;i++)h[i]=c[i]=read();
	sort(c+1,c+n+1),cnt=unique(c+1,c+n+1)-c-1;
	for(int i=1;i<=n;i++)a[i]=lower_bound(c+1,c+cnt+1,h[i])-c;
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		Add(f[i][0],mul(f[i-1][0],2));
		for(int j=a[i]+1;j<=a[i-1];j++)Add(f[i][0],mul(f[i-1][j],2));
		int d=ksm(2,max(0,h[i]-h[i-1]));
		for(int j=1;j<=min(a[i],a[i-1]);j++)Add(f[i][j],mul(f[i-1][j],d));
		if(i==1)Add(f[1][1],mul(f[0][0],mul(ksm(2,c[1])-2,ksm(2,h[i]-c[1]))));
		for(int j=max(2,a[i-1]+1);j<=a[i];j++)
		Add(f[i][j],mul(f[i-1][0],mul(ksm(2,c[j]-c[j-1])-1,mul(2,ksm(2,h[i]-c[j])))));
	}int res=0;
	for(int i=0;i<=a[n];i++)Add(res,f[n][i]);
	cout<<res<<'\n';return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  int pattern_num;


  while(~scanf("%d",&pattern_num)){

    int len2point[400];
    memset(len2point,-1,sizeof(len2point));

    for(int pattern_idx=0;pattern_idx<pattern_num;pattern_idx++){
      int lower_len,upper_len,point;
      scanf("%d %d %d",&lower_len,&upper_len,&point);
      for(int len=lower_len;len<=upper_len;len++){
	len2point[len] = max(len2point[len],point);
      }
    }
      
    int m;
    scanf("%d",&m);
    vector<int> point_vec;
    for(int melody_idx=0;melody_idx<m;melody_idx++){
      int w;
      scanf("%d",&w);
      int dp[400];
      memset(dp,-1,sizeof(dp));
      dp[0] = 0;
      for(int total_len=0;total_len<=w;total_len++){
	for(int add_bar_len=0;add_bar_len<=total_len;add_bar_len++){
	  if(len2point[add_bar_len] == -1) continue;
	  dp[total_len] = max(len2point[add_bar_len]+dp[total_len-add_bar_len],dp[total_len]);
	}
      }
      point_vec.push_back(dp[w]);
    }

    bool isok = true;
    for(int i=0;i<point_vec.size();i++){
      if(point_vec[i] == -1){
	isok = false;
      }
    }

    if(isok){
      for(int i=0;i<point_vec.size();i++){
	printf("%d\n",point_vec[i]);
      }
    }

    else{
      printf("%d\n",-1);
    }
  }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;

int arr[N];

int divisors[N];


int main(){

    int n;
    cin>>n;

    for (int i = 1; i <= n; ++i)
        for (int j = i; j <= n; j += i)
            ++divisors[j];

    long long ans = 0;
    for(int c=1;c<n;c++){
       int x = n-c;
       ans+=divisors[x];
    }
    cout<<ans<<endl;


    return 0;
}


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


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    ll x;
    cin>>x;
    
    if(x == 0)cout<<1;
    else cout<<0;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int K;cin>>K;
  	int S;cin>>S;
  	int ans =0;
  	rep(i,K+1){
    	rep(j,K+1){
        	if(S-(i+j)>=0&S-(i+j)<=K)ans+=1;
        }
    }
	cout<<ans<<endl;
  
}

Measured memory_bytes: 256
var n,i:longint;
    a,x:longint;
    max,maxx:longint;
begin
  read(n);
  for i:=1 to n do
  begin
    read(a,x);
    if a>max then
    begin
      max:=a;
      maxx:=x;
    end;
  end;
  writeln(max+maxx);
end.

Measured memory_bytes: 128
// ss

#include <iostream>
#include <string>

using namespace std;

int main(){
	string S;
	cin >> S;

	int l = S.length();

	for (int i = l-2; i >= 0; i -= 2){
		string pre, next;
		// substr (pos, N_elements);
		pre = S.substr(0, i/2);
		next = S.substr(i/2, i/2);
		// cout << pre << ' ' << next << endl;
		if (pre == next){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, K;
void perm(vector<ll>& A) {
  vector<ll> imos(N + 1, 0);
  for (ll i = 0; i < N; ++i) {
    ll a = A.at(i);
    imos.at(max(0ll, i - a)) += 1;
    imos.at(min(N, i + a + 1)) -= 1;
  }
  for (ll i = 0; i < N; ++i) {
    imos.at(i + 1) += imos.at(i);
  }
  bool all = true;
  for (ll i = 0; i < N; ++i) {
    A.at(i) = imos.at(i);
    if (imos.at(i) != N) {
      all = false;
    }
  }
  if (all) {
    A.at(0) = -1;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  for (ll i = 0; i < K; ++i) {
    perm(A);
    if (A.at(0) == -1) {
      for (ll i = 0; i < N; ++i) {
        cout << N << " ";
      }
      cout << "\n";
      return 0;
    }
  }
  for (ll i = 0; i < N; ++i) {
    cout << A.at(i) << " ";
  }
  cout << "\n";
}


Measured memory_bytes: 6344
#include<stdio.h>
 int main(){
 int a[100][100],b[100][100],i,j,k,n,m,l,x;
 long long int c[100][100]={0};
 scanf("%d %d %d",&n,&m,&l);
 
 for(i=0;i<n;i++){
 for(j=0;j<m;j++){
 scanf("%d",&x);
 a[i][j]=x;
 }
 }
 
 
 for(j=0;j<m;j++){
 for(k=0;k<l;k++){
 scanf("%d",&x);
 b[j][k]=x;
 }
 }
 
 for(i=0;i<n;i++){
 for(k=0;k<l;k++){
 for(j=0;j<m;j++){
 c[i][k]+=a[i][j]*b[j][k];
 }
 }
 }
 
 for(i=0;i<n;i++){
 for(k=0;k<l;k++){
 printf("%lld",c[i][k]);
 
if(k!=l-1)
{
    printf(" ");
}
 }
 printf("\n");
 }
 
 return 0;
 }

Measured memory_bytes: 764
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N, M, count = 0;
    cin >> N >> M;
    vector<int> h(N);
    
    for(int i = 0; i < N; i++){
        cin >> h.at(i);
        if(h.at(i) >= M){
            count++;
        }
    }    
    
    cout << count << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt(), b = sc.nextInt();

		System.out.println((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible" : "Impossible");

	}

}

Measured memory_bytes: 23380
/*0429??????????????§??£?§£???boolean??§???byte??§?????§????????????
 * 12??????????????????????¢???? ????????°??????????????????????????????????????????????????????????´???°????????????int ????????§????????????.?????????maxvalue???memory?¶??????????????????????
 * 
 * Created by SharpDevelop.
 * User: yog-sothoth
 * Date: 2017/04/23
 * Time: 17:25
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System.Collections.Generic;
using System;
using System.IO;

namespace Dictionary
{
	
	public class DictionaryList
	{
		
		
		public static void Main(string[] args)
		{		
			int num = int.Parse(Console.ReadLine());// the number of instructions
			
			
			byte[] table = new byte[67200000];
		
			var sw = new StreamWriter(Console.OpenStandardOutput())
	    	{ AutoFlush = false };
			
			Console.SetOut(sw);
			
			for (int i = 0; i < num; i++) {
				string iands = Console.ReadLine();//instruction and s tring
				string[] instAndStr = iands.Split();
			
				
				//Add list instAndStr[1]		
				if (instAndStr[0] == "insert") {//??????????????\???
					//??????????????°????????????????????????table[index]???????????°??????????????????????????¨????????????????????§????????????
					//????????°???????????????
					int index = 0;
					for (int j = 0; j < instAndStr[1].Length; j++) {
			
						index *= 4;
				
						switch (instAndStr[1][j]) {
							case 'A':
								index += 1;
								break;
							case 'C':
						
								index += 2;
						
								break;
							case 'G':
						
								index += 3;
								break;
							case 'T':
						
								index += 4;
								break;			
						}
						
		
					}
					table[index]=1;
		
					
				} else { //?????????find
					
					
					int index = 0;
					for (int k = 0; k < instAndStr[1].Length; k++) {
			
						index *= 4;
				
						switch (instAndStr[1][k]) {
							case 'A':
								index += 1;
								break;
							case 'C':
						
								index += 2;
						
								break;
							case 'G':
						
								index += 3;
								break;
							case 'T':
						
								index += 4;
								break;			
						}
						
		
					}
					if(table[index]!=1)
					{
						Console.WriteLine("no");
					}else
						Console.WriteLine("yes");
				}
				
			}
			Console.Out.Flush();
		}
		
	}
}

Measured memory_bytes: 116792
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,q,s,l):
    lst_ac = [0]*(len(s))
    for i in range(len(s)-1):
        if s[i]+s[i+1] == "AC":
            lst_ac[i+1] = lst_ac[i]+1
        else:
            lst_ac[i+1] = lst_ac[i]
    for item in l:
        print(lst_ac[item[1]-1] - lst_ac[item[0]-1])

def resolve():
    n,q = mi()
    s = input()
    l = mix(q)
    main(n,q,s,l)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 30716
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   
   int n;
   cin>>n;
   int c=0;
   for(int i=1;i<=n;i++)
   {
    int h;
    cin>>h;
         if(h!=i)
            c++;
   }
   if(c==0 || c==2)
   {
    cout<<"YES";
   }
   else 
    cout<<"NO";


 return 0;
}








Measured memory_bytes: 3584
#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> ;
vector<int> d;
vector<vector<int>> A;
 
int main () {
int N, K;
cin >> N >> K;
d.resize(K);
A.resize(K, vector<int> ());
rep(i, K) {
  cin >> d.at(i) ;
  A.at(i).resize(d.at(i));
  rep(j, d.at(i)){
    cin >> A.at(i).at(j) ;}
}
vector<int> LL ;
rep(i, K){
  rep(j, d.at(i)){
    LL.push_back(A.at(i).at(j));}
}
int ans = 0;
for ( int i = 1; i <= N ; i++ ){
 if (count(LL.begin(), LL.end(), i) == 0){
   ans++ ;}
}
cout << ans << endl;
return 0;
}

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

int main()
{
	int a,b,c=0,d=0,sum=0;
	string s;

	cin>>a>>s;
    for(int i=0;i<a;i++)
    {
        if(s[i]=='R')
            c++;
        else
        {
            d++;
        }
        
    }
    if(c>d)
        cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
	
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q), pt(n, k);
    rep(i,q) {
        cin >> a[i];
        pt[a[i] - 1]++;
    }
    rep(i,n) pt[i] -= q;
    rep(i,n) {
            cout << ((pt[i] <= 0) ? "No" : "Yes")  << "\n";
    }
    return 0;
}


Measured memory_bytes: 4016
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n;
		
		while(true) {
			n = scan.nextInt();
			
			if(n == -1) break;
			
			System.out.println(Integer.toString(n, 4));
		}
		
		scan.close();
	}
}

Measured memory_bytes: 31404
n = int(input())
score_taro = 0
score_hanako = 0
for i in range(n):
    animal_taro, animal_hanako = input().split()
    if animal_taro < animal_hanako:
        score_hanako += 3
    elif animal_taro == animal_hanako:
        score_taro += 1
        score_hanako += 1
    else:
        score_taro += 3
print(f"{score_taro} {score_hanako}")



Measured memory_bytes: 5608
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>

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

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

  string s;
  int64_t k;
  cin >> s >> k;

  rep(i,min((int64_t)s.size(), k)) {
    if (s[i] > '1') { cout << s[i] << endl; return 0; }
  }
  cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Runtime.Remoting;


namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public ulong NextUlong()
        {
            return ulong.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    struct MyStruct
    {
        public long N;
        public int Cnt;
    }

    class Program
    {
        private int N;
        private int[] H;
        void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            H = sc.IntArray();
        }

        public void Solve()
        {
            Scan();
            var ans = new int[N];
            for (int i = 0; i < N; i++)
            {
                ans[i] = int.MaxValue;
            }
            ans[0] = 0;
            for (int i = 1; i < N; i++)
            {
                int a = int.MaxValue;
                if (i - 2 >= 0)
                {
                    a = Math.Min(a, ans[i - 2] + Math.Abs(H[i] - H[i - 2]));
                }
                a = Math.Min(a, ans[i - 1] + Math.Abs(H[i] - H[i - 1]));
                ans[i] = a;
            }
            Console.WriteLine(ans[N - 1]);
        }



        static void Main() => new Program().Solve();
    }


}

Measured memory_bytes: 18528
import Data.List

main = do
  getLine
  co <- getContents
  let css = lines co
  let ans = compute css
  putStrLn $ if ans then "Yes" else "No"

-- 全ての'#'について、上下左右のいずれかに'#'があればよい。
-- 端については '.' にして失敗させる

compute :: [String] -> Bool
compute css = and $ map and chk4s
  where
    chk '.' _   = True
    chk '#' '#' = True
    chk _   _   = False
    cssN = repeat '.' : css -- 上
    cssS = tail css ++ [repeat '.'] -- 下
    cssE = map (tail.(++ ".")) css -- 右
    cssW = map ('.' :) css -- 左
    chkNs = zipWith (zipWith chk) css cssN
    chkSs = zipWith (zipWith chk) css cssS
    chkEs = zipWith (zipWith chk) css cssE
    chkWs = zipWith (zipWith chk) css cssW
    chkNSs = zipWith (zipWith (||)) chkNs chkSs
    chkEWs = zipWith (zipWith (||)) chkEs chkWs
    chk4s = zipWith (zipWith (||)) chkNSs chkEWs


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

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

Measured memory_bytes: 256
from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = [None] * (H*W)
matS = matE = 0
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat[matE] = (h, w, 0)
            matE+=1
    dp[h] = s

def search(dp, mat, nH, nW, cnt):
    global matE
    if dp[nH][nW] == ".":
        mat[matE] = (nH, nW, cnt+1)
        matE+=1
        dp[nH][nW] = "#"

while matS < matE:
    h, w, cnt = mat[matS]
    matS += 1

    if h > 0:
        search(dp, mat, h - 1, w, cnt)
    if h < H-1:
        search(dp, mat, h + 1, w, cnt)
    if w > 0:
        search(dp, mat, h , w - 1, cnt)
    if w < W-1:
        search(dp, mat, h , w + 1, cnt)

print(cnt)


Measured memory_bytes: 170460
import collections
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
sm = sum(a)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    if cnt.get(b) != None:
        num = cnt[b]
        del cnt[b]
        sm += num * (c-b)
        if cnt.get(c) != None:
            cnt[c] += num
        else:
            cnt[c] = num
    print(sm)

Measured memory_bytes: 21492
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[]=new int[n];
        int sum=0;
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
            sum+=arr[i];
        }
        if(sum%n==0)
        {
            int st=0;
            for(int i=0;i<n;i++)
            {
                st+=(int)Math.pow(arr[i]-sum/n,2);
            }
            System.out.println(st);
        }
        else
        {
            int av1=sum/n;
            int av2=sum/n+1;
            int st1=0,st2=0;
            for(int i=0;i<n;i++)
            {
                st1+=(int)Math.pow(arr[i]-av1,2);
                st2+=(int)Math.pow(arr[i]-av2,2);
            }
            System.out.println((int)Math.min(st1,st2));
        }
    }
}

Measured memory_bytes: 21972