akhauriyash/Code-Regression huggingface dataset:
// Problem: B - Making Triangle
// Contest: AtCoder - AtCoder Beginner Contest 175
// URL: https://atcoder.jp/contests/abc175/tasks/abc175_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//
//#include <immintrin.h>
//#include <emmintrin.h>

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
#define vi vector<int>
#define pii pair<int, int >
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define LL long long
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define all2(x,n) (x+1), (x+1+n)
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define mt make_tuple
#define eb emplace_back
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define contain(S,X) (((S)&o(X))!=0)
#define containL(S,X) (((S)&oL(X))!=0)
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;
inline int getplc(int x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}
LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}
// Smax
//int Smax() { return -INF; }
template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) { return max(a, Smax(args...)); }
// Smin
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) { return min(a, Smin(args...)); }
template <typename T>
// erro
#define errorl(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); errl(_it, args); }

void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr<<endl;}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}
void Solve();
int main() {
#ifndef ONLINE_JUDGE
//	freopen("in.txt","r",stdin);
//    freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}

//////////////////////////////////////////////////////////////////

int check(int x,int y,int z){
  if(x==y||x==z||y==z)return 0;
  if(x<y+z&&y<x+z&&z<x+y)return 1;
  return 0;
}

int a[N];
void Solve(){
  int n,ans=0;
  cin>>n;
  rep(i,1,n)cin>>a[i];
  rep(i,1,n){
    rep(j,i+1,n){
      rep(k,j+1,n){
        if(check(a[i],a[j],a[k]))ans++;
      }
    }
  }
  cout<<ans<<endl;
} 


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define int long long

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

  set<string> st;
  int n; cin >> n;
  for(int i = 0; i < n; i++){
    vector<int> p(3); cin >> p[0] >> p[1] >> p[2];
    sort(p.begin(),p.end());
    string s = to_string(p[0]*100000009 + p[1]*1000000007 + p[2]*1000000003);
    st.insert(s);
  }
  cout << n - st.size() << endl;

  return 0;
}



Measured memory_bytes: 3376
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n,count=0,maxi=0;
string s;
cin>>n;
cin>>s;
for(int i=0;i<s.size();i++){
    if(s[i]=='I'){
        count++;
    }
    else
        count--;
    maxi=max(maxi,count);

}
cout<<maxi;


    return 0;
}


Measured memory_bytes: 3556
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] num = new int[n];
        
        for (int i = 0; i < num.length; i++) {
            num[i] = sc.nextInt();
        }
        
        for (int i = num.length - 1; i >= 0; i--) {
            if (i != 0) {
                System.out.printf("%d ", num[i]);
            }
            else {
                System.out.printf("%d\n", num[i]);
            }
        }
    }
}

Measured memory_bytes: 26060
def resolve():
    '''
    code here
    '''
    X, K, D = [int(item) for item in input().split()]

    if K*D > abs(X):
        temp = K - X // D

        if temp % 2 == 1:
            print(D - X%D)
        else:
            print(X%D)
    else:
        print(abs(X) - K*D)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9188
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    int n;
    scanf("%d",&n);
    vector<vector<int>>arr(n+1,vector<int>(n-1));
    for(int i=1; i<=n; i++)
        for(int j=n-2; j>-1; j--)
            scanf("%d",&arr[i][j]);


    int cnt=0,total=(n*(n-1))/2;
    int days=0;
    queue<int>q;
    for(int i=1; i<=n; i++)
        q.push(i);
    int sz=n,temp;
    while(cnt<total)
    {
        days++;
        set<int>st;
        for(; !q.empty(); sz=q.size())
        {
            while(sz--)
            {
                temp=q.front();
                q.pop();
                if(arr[temp].size()==0)
                    continue;
                int p1=arr[temp].back();
                if(arr[p1].back()==temp)
                {
                    st.insert(temp);
                    st.insert(p1);
                }
            }
        }
        if(st.size()==0)
        {
            puts("-1");
            return 0;
        }
        set<int>::iterator it=st.begin();
        cnt+=st.size()/2;
        for(; it!=st.end(); it++)
        {
            arr[*it].pop_back();
            q.push(*it);
        }
    }
    printf("%d\n",days);
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <set>
#include <vector>
#include <string>
using namespace std;
class Cube{
public:
	int c[6];
	Cube(){}
	bool operator == (const Cube &p) const{
		for(int i=0;i<6;i++)if(c[i]!=p.c[i])return false;
		return true;
	}
	void r1(){
		int tmp[6];
		for(int i=0;i<6;i++)tmp[i]=c[i];
		c[0]=tmp[4];
		c[1]=tmp[0];
		c[4]=tmp[5];
		c[5]=tmp[1];
		return;
	}
	void r2(){
		int tmp[6];
		for(int i=0;i<6;i++)tmp[i]=c[i];
		c[0]=tmp[2];
		c[2]=tmp[5];
		c[3]=tmp[0];
		c[5]=tmp[3];
		return;
	}
	void r3(){
		int tmp[6];
		for(int i=0;i<6;i++)tmp[i]=c[i];
		c[1]=tmp[3];
		c[2]=tmp[1];
		c[3]=tmp[4];
		c[4]=tmp[2];
		return;
	}
};
bool onaji(Cube &a,Cube &b){
	for(int i=0;i<4;i++){
		for(int j=0;j<4;j++){
			if(a==b)return true;
			a.r1();
		}
		a.r2();
	}
	a.r3();
	for(int j=0;j<4;j++){
		if(a==b)return true;
		a.r1();
	}
	a.r3();a.r3();
	for(int j=0;j<4;j++){
		if(a==b)return true;
		a.r1();
	}
	return false;
}
int GetID(string s){
	if(s=="Red")return 1;
	if(s=="Yellow")return 2;
	if(s=="Blue")return 3;
	if(s=="Magenta")return 4;
	if(s=="Green")return 5;
	if(s=="Cyan")return 6;
}
int main()
{
	int n;
	while(cin>>n&&n){
		Cube sta[30];
		vector<Cube> ans;
		for(int i=0;i<n;i++){
			string s;
			for(int j=0;j<6;j++){
				cin>>s;
				sta[i].c[j]=GetID(s);
			}
			bool neww=true;
			for(vector<Cube>::iterator it=ans.begin();it<ans.end();it++){
				Cube tmp;tmp=ans.at(it-ans.begin());
				if(onaji(tmp,sta[i]))neww=false;
			}
			if(neww)ans.push_back(sta[i]);
		}
		cout<<n-(int)ans.size()<<endl;
	}
    
    return 0;
}

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

#define ll long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

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

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {
    //COMint();
    int array[3];
    REP(i,3){
        array[i]=in();
    }
    sort(array,array+3);

    int s;
    s=array[2]*2-array[0]-array[1];
    int ans;
    if(s%2==1){
        ans=(s+3)/2;
    }else{
        ans=s/2;
    }
    print(ans);


}

Measured memory_bytes: 256
/*input
7
994 518 941 851 647 2 581
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
    	int a; cin >> a;
    	ans += a - 1;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
def gridbfs(grid,sy,sx):
    INF = 10**18
 
    gridy = len(grid)
    gridx = len(grid[0])
 
    dist = [[INF]*gridx for _ in range(gridy)]
    dist[sy][sx] = 0
    q = deque([(sy,sx)])
 
    while q:
        y,x = q.popleft()
        for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
            yy,xx = y+dy, x+dx
            if not (0 <= yy < gridy and 0 <= xx < gridx):
                continue
            if grid[yy][xx] == '#':
                continue
            if dist[yy][xx] != INF:
                continue
            dist[yy][xx] = dist[y][x] + 1
            q.append((yy,xx))
 
    return dist
 
H,W = map(int,input().split())
grid = [input() for i in range(H)]
d = gridbfs(grid,0,0)
b = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            b += 1
 
print(max(H*W-b-d[H-1][W-1]-1,-1))

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

int main(){
	int n,k;
	cin>>n>>k;
	vector<int>h(n);
	for(int i=0;i<n;i++) cin>>h[i];
	vector<int> dp(n,INT_MAX);
	dp[0]=0;
	// dp[1]=abs(h[0]-h[1]);
	for(int i=1;i<n;i++){
		for(int j=i-1;j>max(i-k-1,-1);j--){
			dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i]);
		}
	}
	cout<<dp.back()<<endl;


	return 0;
}

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

int main()
{
  int K, N;

  cin >> K >> N;

  vector<int> A(N);

  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  vector<int> vec(N);

  for (int i = 0; i < N; i++)
  {
    if (i == 0)
    {
      vec.at(i) = K - A.at(N - 1) + A.at(i);
    }
    else
    {
      vec.at(i) = A.at(i) - A.at(i - 1);
    }
  }

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

  cout << K - vec.at(N - 1) << endl;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int N,ans=111;
  cin>>N;
  while(ans<N){
    ans+=111;
  }
  cout<<ans<<endl;
}


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

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

using ll = long long;
using namespace std;

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

    ll sum = 0;
    rep(n, i) {
      auto j = i + 1;
      if ( j % 3 == 0 || j % 5 == 0 )
        continue;
      sum += j;
    }

    cout << sum << endl;
}


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

int main(){
    int n; cin >> n;
    vector<vector<ll>> dp(10,vector<ll>(10,0));
    rep(i,n){
        string now = to_string(i+1);
        int a = now[0] - '0', b = now[now.size()-1]-'0';
        dp[a][b]++;
    }
    ll ans = 0LL;
    rep(i,10) rep(j,10) ans += dp[i][j]*dp[j][i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int b=1;
  while(c<=100001){
    c++;
    if(a[b-1]==2){
      cout<<c;
      return 0;
    }else{
      b=a[b-1];
    }
  }
  cout<<-1;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

struct edge {
    ll to, cost;
    edge() {
        to = 0;
        cost = 0;
    }
    edge(ll t, ll c) {
        to = t;
        cost = c;
    }
};

// p : (cost, position)
using p = pair<ll, ll>;

void djikstra(vector<ll> &d, vector<vector<edge>> &g, ll start) {
    ll inf = 1LL << 60;
    fill(d.begin(), d.end(), inf);
    d[start] = 0;

    priority_queue<p, vector<p>, greater<p>> q;
    q.push(p(0, start));

    while (!q.empty()) {
        p now = q.top();
        q.pop();
        ll now_cost = now.first, now_position = now.second;
        if (d[now_position] < now_cost)
            continue;
        for (edge e : g[now_position]) {
            if (d[e.to] > d[now_position] + e.cost) {
                d[e.to] = d[now_position] + e.cost;
                q.push(p(d[e.to], e.to));
            }
        }
    }
}

const ll coin_max = 3000;
ll make_num(ll v_num, ll coin_num) {
    coin_num = min(coin_num, coin_max - 1);
    return v_num * coin_max + coin_num;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m, s;
    cin >> n >> m >> s;
    vector<vector<edge>> g(n * coin_max);
    rep(i, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        repd(coin, a, coin_max) {
            ll from = make_num(u, coin), to = make_num(v, coin - a);
            g[from].push_back(edge(to, b));
            from = make_num(v, coin), to = make_num(u, coin - a);
            g[from].push_back(edge(to, b));
        }
    }
    rep(i, n) {
        ll c, d;
        cin >> c >> d;
        rep(coin, coin_max) {
            ll from = make_num(i, coin), to = make_num(i, coin + c);
            g[from].push_back(edge(to, d));
        }
    }

    vector<ll> d(n * coin_max);
    djikstra(d, g, make_num(0, s));

    ll inf = 1LL << 60;
    repd(t, 1, n) {
        ll ans = inf;
        rep(i, coin_max) {
            ll num = make_num(t, i);
            ans = min(ans, d[num]);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 27440
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pii;

bool mycomp(Pii a, Pii b)
{
    int da = a.second - a.first;
    int db = b.second - b.first;
    if (da > db) return true;
    if (da == db) return a.first > b.first;
    return false;
}

int main() {
    int N; cin >> N;
    vector<Pii> fst, nxt;
    int l = 0, r = 0;
    for (int i = 0; i < N; i++) {
        Pii inp = make_pair(0, 0);
        string S; cin >> S;
        for (char x : S) {
            if (x == '(') {
                inp.second++;
            } else {
                if (inp.second > 0) inp.second--;
                else inp.first++;
            }
        }
        if (inp.first == 0) l += inp.second;
        else if (inp.second == 0) r += inp.first;
        else if (inp.first < inp.second) fst.push_back(inp);
        else nxt.push_back(inp);

    }
    sort(fst.begin(), fst.end(), less<Pii>());
    sort(nxt.begin(), nxt.end(), mycomp);
    fst.insert(fst.end(), nxt.begin(), nxt.end());

    int k = l;
    for (Pii x : fst) {
        k -= x.first;
        if (k < 0) {
            cout << "No" << endl;
            return 0;
        }
        k += x.second;
    }
    k -= r;

    if (k != 0) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 6540
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

class BitSum:
    def __init__(self, n):
        self.n = n + 3
        self.table = [0] * (self.n + 1)

    def update(self, i, x):
        i += 1
        while i <= self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def InversionNumber(lst):
    bit = BitSum(max(lst))
    res = 0
    for i, a in enumerate(lst):
        res += i - bit.sum(a)
        bit.update(a, 1)
    return res

def main():
    s = input()
    n = len(s)
    ord_a = ord("a")
    cnts = [0] * 26
    s_code = []
    flag_odd = False
    for c in s:
        code = ord(c) - ord_a
        s_code.append(code)
        cnts[code] += 1
    odd_code = -1
    for code, cnt in enumerate(cnts):
        if cnt % 2 == 1:
            if flag_odd:
                print(-1)
                exit()
            else:
                odd_code = code
                flag_odd = True
        cnts[code] = cnt // 2
    tois = [[] for _ in range(26)]
    to_sort_idx = []
    new_idx = 1
    for code in s_code:
        if cnts[code] > 0:
            to_sort_idx.append(new_idx)
            tois[code].append(n + 1 - new_idx)
            cnts[code] -= 1
            new_idx += 1
        else:
            if flag_odd and code == odd_code:
                to_sort_idx.append(n // 2 + 1)
                flag_odd = False
            else:
                to_sort_idx.append(tois[code].pop())
    # print(to_sort_idx)
    print(InversionNumber(to_sort_idx))

main()


Measured memory_bytes: 15464
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;



int main(){
  bool flag=true;
  int data,ans=0,a=9;
  for(int i=0;i<5;i++){
    cin>>data;
    if(data%10==0) ans+=data;
    else {
      flag=false;
      ans+=data/10*10+10;
      a=min(data%10,a);
    }
  }
  if(flag) a=10;
  ans=ans-10+a;
  cout<<ans<<endl;
}


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

#define int long long

int a, b;

int f(int n) {
	return n * (n+1) / 2;
}

signed main() {
	cin >> a >> b;

	for (int i = 1; i < 999; i++) {
		int A = f(i), B = f(i+1);
		if (B - A == b - a) {
			cout << A - a << endl;
			return 0;
		}
	}

	return 0;
}


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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
constexpr int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend ostream &operator<<(ostream &os, const mint &a) { return (os << a.x); }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main() {
  ll num;
  int n;
  cin >> n;
  vector<int> a(n);
  num = 0;
  ll s = 0;
  map<ll, ll> mem;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    s += a[i];
    mem[s]++;
  }

  for (auto it = mem.begin(); it != mem.end(); ++it) {
    if ((*it).first == 0) {
      num += ((*it).second + 1) * (*it).second / 2;
    } else {
      num += (*it).second * ((*it).second - 1) / 2;
    }
  }

  cout << num << endl;
}


Measured memory_bytes: 13568
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		  Scanner in = new Scanner(System.in);
		  String s = in.next();
		  int count = 0;

		if ( s.charAt(0) == '1') {
			count++;
		}
		if( s.charAt(1) == '1') {
			count++;
		}
		if( s.charAt(2) == '1') {
			count++;
		}
		System.out.println(count);
		in.close();
	}
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
    template<class...T>
    ostream & operator << (ostream &os, tuple<T...> const &t){
        _ot<0>(os, t); return os;
    }
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/8;

const int MAX_D = 100000;
const int MAX_C = 30;

double dp[MAX_D+10][MAX_C+10]; // i日目にj回連続で得る確率
double ans[MAX_D+10];

int main(){
    memset(dp,0,sizeof(dp));
    memset(ans,0,sizeof(ans));
    dp[0][0] = 1;
    for(int i = 0; i < MAX_D; i++){
        double today = 0;
        for(int j = 0; j < MAX_C; j++){
            double win = pow(0.5, j);
            double lose = 1 - win;
            today += dp[i][j] * win;
            dp[i+1][j+1] += dp[i][j] * win;
            dp[i+1][0] += dp[i][j] * lose;
        }
        // if(i >= 100000){
        //     printf("%lf %lf %lf\n", ans[1], ans[2], ans[3]);
        // }
        ans[i+1] = ans[i] + today;
    }
    int n;
    while(scanf("%d", &n), n != 0){
        printf("%lf\n", ans[n]);
    }
}

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

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

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

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


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

    ll n, ans = 1;
    cin >> n;

    rep(i, n){
        ans *= (i+1);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<=n;i++){
        if(s.substr(i,n-i)==t.substr(0,n-i)){
            cout<<n+i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  string s; cin >> s;
  int ans = INF;
  REP(i,s.size()-2) ans = min(ans, abs(753 - stoi( s.substr(i, 3))));
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int A, B, H, M;
    double ans, sang, lang, ang, C, rad;

    cin >> A >> B >> H >> M;

    sang = 30*H + 0.5*M;
    lang = 6*M;

    ang = abs(sang-lang);

    if(ang==0) {
        cout << abs(A-B) << endl;
    } else if(ang==180) {
        cout << A+B << endl;
    } else {
        rad = ang*M_PI/180;
        C = pow(A,2) + pow(B,2) - 2*A*B*cos(rad);
        ans = pow(C,0.5);
        cout << fixed << setprecision(20) << ans << endl;
    }

    return 0;
    
}

Measured memory_bytes: 4224
while True:
    SC = input()
    SClist = SC.split()
    a = int(SClist[0])
    b = int(SClist[2])

    if SClist[1] == '+':
        print(a+b)
    elif SClist[1] == '-':
        print(a-b)
    elif SClist[1] == '*':
        print(a*b)
    elif SClist[1] == '/':
        print(a//b)
    elif SClist[1] == '?':
        break



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef pair<ll,ll> P;
#define se second
#define fi first
struct PP{ll fi;ll se;ll th;};
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    int sum=0;
    rep(i,3){
        int a;cin>>a;sum+=a;
    }
    if(sum>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

bool rev(int a){
    string s1 = to_string(a);
    string s2;
    REP(i, s1.size()) s2 += s1[s1.size()-i-1];
    return (s1 == s2);
}

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    rep(i, a, b+1){
        if (rev(i)) ans++;
     }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long fac[20000010], inv[20000010], finv[20000010]; 
long long MOD = 1000000007; 
void COMinit(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < 20000005; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
	long long H, W, K; 
	cin >> H >> W >> K; 
	COMinit(); 
	long long ans1 = ((fac[K + 2] * 500000004) % MOD - fac[K] + MOD) % MOD;
	ans1 *= COM(H + W, K); 
	ans1 %= MOD; 
	long long ans2 = ((H * W) % MOD) * 333333336 % MOD; 
	ans2 *= COM(H + W - 2, K - 2); 
	ans2 %= MOD; 
	ans2 *= fac[K + 1]; 
	ans2 %= MOD; 
	cout << (ans1 + ans2) % MOD << endl; 
}

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

using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int a[100001];
pint cb[100001];
int main() {
	int n, m;
	ll ans = 0;
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i];
		ans += a[i];
	}
	sort(a, a + n);
	int ci, bi;
	rep(i, m) {
		cin >> bi >> ci;
		cb[i] = { ci,bi };
	}
	sort(cb, cb + m, greater<pint>());
	int cur = 0, card = 0;
	while (cur < n) {
		if (cb[card].second == 0) ++card;
		if (card >= m) break;
		if (a[cur] < cb[card].first) {
			ans += cb[card].first - a[cur];
			--cb[card].second;
			++cur;
		}
		else break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#!/usr/bin/env python
# coding: utf-8

def main():
	swapping_numbers = []
	while True:
		x, y = [int(n) for n in raw_input().split(" ")]
		if x == 0 and y == 0:
			break
		swapping_numbers.append([x, y])

	for swapping_number in swapping_numbers:
		if swapping_number[0] > swapping_number[1]:
			swapping_number[0], swapping_number[1] = swapping_number[1], swapping_number[0]
		print "%d %d" % tuple(swapping_number)

if __name__ == '__main__':
	main()

Measured memory_bytes: 4472
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long double LD;

int n;
LD fm, ans;

int main()
{
	scanf("%d", &n);
	for (int i = 1, a; i <= n; i ++)
	{
		scanf("%d", &a);
		fm += LD(1.0) / a;
	}
	ans = LD(1.0) / fm;
	printf("%.9Lf\n", ans);
	return 0;
}

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

int main()
{
    int h; int w; string s;
    cin>>h>>w;
    for(int p=0;p<w+2;p++)
        cout<<"#";
        cout<<endl;
    for(int i=0;i<h;i++)
    {
        cin>>s;
        cout<<"#"<<s<<"#"<<endl;

    }
    for(int m=0;m<w+2;m++)
        cout<<"#";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair, tuple

int main(){
      long long int a,b,x;cin >> a >> b >> x;
      if(a == 0)cout << b / x + 1;
      else cout << b / x - (a - 1ll) / x;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;
    int d,x;cin>>n>>d>>x;
    int res = 0;
    rep(i,n){
        int a;cin>>a;
        int j = 0;
        while(1){
            if(a*j+1>d)break;
            res++;
            j++;
        }
    }
    cout<<res+x;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] count = new int[3];

        count[0] = sc.nextInt();
        count[1] = sc.nextInt();
        count[2] = sc.nextInt();
        int k = sc.nextInt();
        int sum = 0;
        
        if (count[0] >= k) {
            sum = k;
        } else if (count[0] + count[1] >= k) {
            sum = count[0];
        } else {
            sum = count[0] - (k - (count[0] + count[1]));
        }
        
        System.out.println(sum);
    }
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n;
  cin >> n;
  int a[21], b[21], c[21];
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];

  int ans = 0;
  REP(i, n+1){
    ans += b[a[i-1]-1];
    if(a[i-1] + 1 == a[i]) ans += c[a[i-1]-1];
  }

  cout << ans << endl;
}


/*





















*/


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, m, i, x, s=0;
    cin>>n>>m;
    for (i=0 ; i<m ; i++)
    {
        cin>>x;
        s+=x;
        if (s>n)
        {
            cout<<-1;
            return 0;
        }
    }
    cout<<n-s;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifndef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for (int i = a; i >= b; i--)
#define test  \
	int t;    \
	cin >> t; \
	while (t--)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve()
{
	ld w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << prec << w * h * 0.5 << " ";
	if (x * 2 == w && y * 2 == h)
		cout << 1;
	else
		cout << 0;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// test
	solve();
	return 0;
}


Measured memory_bytes: 3808
# -*- coding: utf-8 -*-

a,b,c = input().split()

lis_a = list(a)
lis_b = list(b)
lis_c = list(c)

isATrue = (lis_a[-1] == lis_b[0])
isBTrue = (lis_b[-1] == lis_c[0])

if isATrue and isBTrue:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    rep(i, 3)
    {
        if (s[i]==t[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;cin>>s;
  int k;cin>>k;
  char ans='1';
  rep(i,s.size()){
  	if (k-1<=i&&s.at(i)=='1')break;
	if (s.at(i)!='1') {
	  ans=s.at(i);
      break;
	}
  }
  cout<<ans<<endl;
	return 0;
}


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

using namespace std;
#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, b) FOR(i,0,b)
#define INF 1e9
#define all(a) (a).begin,(a).end()

#define int long long
typedef long long ll;
ll mod_pow(ll a, ll b, ll r) {
    return b <= 0? 1: (b % 2? a: 1) * mod_pow(a * a % r, b / 2, r) % r;
}
signed main(){

    int n,m,b;
    cin>>n>>m>>b;

    if(b!=0)cout<<fixed<<setprecision(10)<<(m-1)*(n-b)*2/(double)(n*n)<<endl;
    else cout<<fixed<<setprecision(10)<<(m-1)*(n-b)/(double)(n*n)<<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200005];
long long pre[200005];
long long cal(int i,int j,int k)
{
    //printf("CHK %d %d %d\n",i,j,k);
    if(i == j || j == k) return 1e18;
    if(i < 1 || k > n) return 1e18;
    long long a = pre[i];
    long long b = pre[j] - pre[i];
    long long c = pre[k] - pre[j];
    long long d = pre[n] - pre[k];
    //printf("%lld %lld %lld %lld\n",a,b,c,d);
    return max(a,max(b,max(c,d))) - min(a,min(b,min(c,d)));
}
long long cut(int x)
{
    long long p = pre[x] , q = pre[n] - pre[x];
    int l = 1 , r = x-1;
    vector<int> v , t;
    while(l < r){
        int mid = (l + r) / 2 + 1;
        if(pre[mid] * 2 <= p) l = mid;
        else r = mid - 1;
    }
    v.push_back(l);v.push_back(l + 1);
    //printf("FIND %d\n",l);
    l = x + 1 , r = n-1;
    while(l < r){
        int mid = (l + r) / 2 + 1;
        if((pre[mid] - p) * 2 <= q) l = mid;
        else r = mid - 1;
    }
    t.push_back(l);t.push_back(l + 1);
    //printf("FIND %d\n",l);
    long long ans = 1e18;
    for(int i = 0;i <= 1;i++){
        for(int j = 0;j <= 1;j++){
            ans = min(ans , cal(v[i] , x , t[j]));
        }
    }
    //printf("%d %lld\n",x,ans);
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++){
        scanf("%d",&a[i]);
        pre[i] = pre[i - 1] + a[i];
    }
    long long ans = 1e18;
    for(int i = 2;i <= n-2;i++){
        ans = min(ans , cut(i));
    }
    printf("%lld\n",ans);
    return 0;
}


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

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

	long long  N, M;
	cin >> N >> M;
	long long ans = N == 1 || M == 1? 1: ((N+1)/2)*((M+1)/2) + (N/2)*(M/2);
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int ans = 0;
    string S;
    cin >> S;
    for ( int i = 0; i < S.length(); i++ ) {
        if ( S[i] == '1' ) { ans++; }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
lines = readlines.map{|line| line.split(' ').map(&:to_i)}
a=[]
b=0
for i in 0..2
	a.push(lines[i])
end
for i in 0..2
  	a.push([lines[0][i],lines[1][i],lines[2][i]])
end
a.push([lines[0][0],lines[1][1],lines[2][2]])
a.push([lines[0][2],lines[1][1],lines[2][0]])

for i in 0..7
  for j in 3..lines[3][0]+3
    if a[i].index(lines[j][0])!=nil then
    	a[i].delete_at(a[i].index(lines[j][0]))
    end
  end
  if a[i].length==0 then
    b=1
    puts "Yes"
    break
  end
end
if b==0 then
  puts "No"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b; cin >> a >> b;
    int res = a + b;
    if(res >= 10){
        cout << "error" << endl;
    }
    else {
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from bisect import *
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
pat_b = [0]*N
for i in range(N):
    b = B[i]
    pat_b[i] = bisect_left(A, b)
    pat_b[i] *= (N - bisect_right(C, b))

print(sum(pat_b))

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  map<string, ll> mp;
  ll N, M;
  IN(N);
  string str;
  REP(i,N){
    IN(str);
    mp[str]++;
  }
  IN(M);
  REP(i,M){
    IN(str);
    mp[str]--;
  }

  ll ans = 0;
  for(auto itr : mp){
    chmax(ans, itr.second);
  }

  OUT(ans);


  return 0;
}

Measured memory_bytes: 256