akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    // entrar a primeira linha nos variaveis n e h
    ll n, hp, a;
    ll a_max = 0;
    cin >> n >> hp;
    // entrar valores 2 a 2 em vetores a e b
    vector<ll> b(n);
    for(int i = 0; i < n; i++){
        cin >> a >> b.at(i);
        a_max = max(a_max, a);
    }
    // 
    sort(b.rbegin(), b.rend());

    int answer = 0;

    for(int i = 0; i < n && a_max <= b.at(i) && hp > 0; i++){
        hp = hp - b.at(i);
        answer++;
    }

    if(hp > 0)
        answer = answer + (hp + a_max - 1) / a_max;
    cout << answer << endl;
}


Measured memory_bytes: 1024
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

//map<string, int> mp;
string aa, bb, cc;

int
main(void){  
  ios_base::sync_with_stdio(false);

  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  ll ans = 0LL;

  REP(i, a.size()){
    aa = "";
    bb = "";
    cc = "";
    aa += a[i]; bb += b[i]; cc += c[i];
    if(aa == bb && aa == cc) continue;
    //2 same    
    else if( (aa==bb) || (aa==cc) || (bb==cc) ) ans++;
    else ans+=2;
  }

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


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

int main() {
    string s;
    cin >> s;
    int suma = 0, sumb = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0) {
            if (s[i] == '1') suma++;
            if (s[i] == '0') sumb++;
        } else {
            if (s[i] == '1') sumb++;
            if (s[i] == '0') suma++;
        }
    }
    cout << min(suma, sumb) << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];

	map<int, int> a;
	map<int, int> b;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) a[v[i]]++;
		else b[v[i]]++;
	}

	vector<P> va;
	vector<P> vb;
	for (auto it = a.begin(); it != a.end(); it++) {
		va.push_back(P(it->second, it->first));
	}
	for (auto it = b.begin(); it != b.end(); it++) {
		vb.push_back(P(it->second, it->first));
	}
	sort(va.begin(), va.end(), greater<P>());
	sort(vb.begin(), vb.end(), greater<P>());

	int res = 0;
	if (va[0].second != vb[0].second) {
		res = (n / 2 - va[0].first) + (n / 2 - vb[0].first);
	} else {
		if (va[0].first > vb[0].first) {
			res = (n / 2 - va[0].first) + (n / 2 - vb[1].first);
		} else if (va[0].first < vb[0].first) {
			res = (n / 2 - va[1].first) + (n / 2 - vb[0].first);
		} else {
			int na = va.size(), nb = vb.size();

			if (va[1].first > vb[1].first) {
				res = (n / 2 - va[1].first) + (n / 2 - vb[0].first);
			} else {
				res = (n / 2 - va[0].first) + (n / 2 - vb[1].first);
			}
		}
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 6520
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}


ll modpow(ll a,ll b){
    ll ret = 1;
    while(b>0){
        if(b&1)ret = (ret*a)%MOD;
        a = (a*a)%MOD;
        b = b>>1;
    }
    return ret;
}

ll combmod(ll n,ll r){
    ll nn = 1;
    ll rr = 1;
//    if(n-r<r){
//        r=n-r;
//    }
    rep(i,r){
        nn *= (n-i);
        nn %=MOD;
        rr *= (r-i);
        rr %=MOD;
    }
    return nn*modpow(rr,MOD-2)%MOD;

}
int main(){
    ll n,k;
    cin>>n>>k;
    ll left = 0;
    ll right = 0;
    if(n<k){
        cout<<1<<endl;
        return 0;
    }

    for(int i=1;i<k;i++){
        left+=i-1;
        right+=(n-i+1);
    }
    ll ans = 0;
    //cout<<left<<" "<<right<<endl;

    for(int i=k;i<=n+1;i++){
        left+=i-1;
        right+=(n+1-i);

        //cout<<left<<" "<<right<<endl;
        ans += (right-left)+1;
        ans%=MOD;
        if(ans<0)ans+=MOD;

    }
    cout<<ans<<endl;














    
return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;int n,k,q,a[2005],b[2005];
inline bool chk(int l,int r) {int ans=0,cnt1=0,cnt2=0;
	for (register int i=1;i<=n;++i) {
		if (l<=a[i]&&a[i]<=r) ++cnt1,++cnt2;
		else if (l<=a[i]) ++cnt2;
		else ans+=max(0,min(cnt2-k+1,cnt1)),cnt1=cnt2=0;
	}return ans+max(0,min(cnt2-k+1,cnt1))>=q;
}int main() {int ans=0x3f3f3f3f;scanf("%d%d%d",&n,&k,&q);
	for (register int i=1;i<=n;++i) scanf("%d",a+i),b[i]=a[i];
	sort(b+1,b+n+1);for (register int i=1;i<=n;++i) {int l=i,r=n,mid;
		while (l<=r) mid=l+r>>1,(chk(b[i],b[mid])?ans=min(ans,b[mid]-b[i]),r=mid-1:l=mid+1);
	}printf("%d",ans);return 0;
}

Measured memory_bytes: 256
#coding: utf-8
y, m, d = map(int, input().split("/"))
heisei = 0
if y <= 2019:
    heisei += 1
    if m <= 4:
        heisei += 1
        if d >= 30:
            heisei += 1
if heisei > 1:
    print("Heisei")
else:
    print("TBD")

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

long long int gcd(long long int x,long long int y) {
  if(y == 0) return x;
  else {
    return gcd(y,x % y);
  }
}
int main() {
  long long int a,b;
  while(cin >> a >> b) {
    cout << gcd(a,b) << " " << a * b / gcd(a,b) << endl;
  }
}

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


int main(){
   vector<int> x(5);
   rep(i,5){
      cin >> x[i];
      if(x[i] == 0) cout << i + 1 << endl;
   }
}

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

  const int MOD = 1000000007;
  const double PI = acos(-1); 

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



// // 二分探索(最小値を出す問題は疑う)
// bool C(ll x){
//     ll res = 0;
//     for(int i = 0; i < N; ++i){
// 		res += max(0ll, A[i]-x/F[i]);
//     }
//     return res <= K;
// }

//   ll binary_search(ll ok, ll ng){
//     while(abs(ok - ng) > 1){
//       ll mid = (ok + ng) / 2;
//       if(C(mid)) ok = mid;
//       else ng = mid;
//     }
//     return ok;
//   }

int main(){
int N;
cin >> N;
vector<int> a(N);
REP(i, N) cin >> a[i];
int ans = 0;
REP(i, N){
if(i == a.at(a.at(i) - 1) - 1) ans++;
}

print(ans / 2);

}

Measured memory_bytes: 640
#include <stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
long long arr[63];

int main(){
	long long A,B;
	scanf("%lld %lld",&A,&B);
	long long d=2;
	if(A!=0) A--;
	for(int i=0;i<50;i++,d<<=1){
		arr[i]=(B/d*(d>>1))-(A/d*(d>>1));
		arr[i]+=(max(B%d-d/2+1,0));
		arr[i]-=(max(A%d-d/2+1,0));
	}
	long long sum=0;
	for(int i=49;i>=0;i--){
		sum=sum*2+(arr[i]%2?1:0);
	}
	printf("%lld",sum);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  int N;
  cin >> N;
  unordered_map<string, int> freq;
  vector<string> max_freq_strs;
  int max_freq = 0;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    freq[s]++;
    if (freq[s] == max_freq) {
      max_freq_strs.push_back(s);
    } else if (freq[s] > max_freq) {
      max_freq_strs = {s};
      max_freq = freq[s];
    }
  }
  sort(max_freq_strs.begin(), max_freq_strs.end());
  for (auto &str : max_freq_strs) {
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 25656
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // NIKI - lowkey

    int n; cin >> n;
    cout << (n == 3 || n == 5 || n == 7 ? "YES":"NO");
    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;
int n, a[N], ans;
long long sum;

int main () {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= n; ++i) {
        int inp; scanf("%d", &inp); a[i] -= inp;
        sum += a[i];
    }

    if (sum < 0) return printf("-1"), 0;

    sort(a + 1, a + n + 1);

    sum = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] >= 0) break ;
        sum += -a[i];
        ++ans;
    }

    for (int i = n; i > 0; --i) {
        if (sum <= 0) break ;
        ++ans;
        sum -= a[i];
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cstdio>
#include<queue>
#include<cstdlib>
#define MAX 3000
#define F first
#define S second
using namespace std;

class P{
public:
  int to,rev,capacity;
  P():to(0),rev(0),capacity(0){}
  P(int to,int capacity,int rev):to(to),capacity(capacity),rev(rev){}
};


typedef vector<int> VI;
typedef vector<vector<P> > VVP;
VVP G;
int st,ed;
bool used[MAX];

void add_node(int from,int to)
{
  G[from].push_back(P(to,1,G[to].size()));
  G[to].push_back(P(from,0,G[from].size()-1));
}

int dfs(int now,int f)
{
  if(now == ed)
    return f;
  used[now] = true;

  for(int i=0;i < G[now].size();i++)
    {
      P& p =  G[now][i];
      if(used[p.to] || p.capacity <= 0)
	continue;

      int res = dfs(p.to,min(f,p.capacity));
      if(res <= 0)
	continue;

      p.capacity -= res;
      G[p.to][p.rev].capacity += res;
      return res;
    }
  return 0;
} 

int maximum_flow(int n)
{
  int res = 0;
  for(;;)
    {
      for(int i=0;i<n;i++)
	used[i] = false;
      int f = dfs(st,1000000000);
      if(!f)
	return res;
      res += f;
    }
}

int main()
{

  int b,r,bn,rn;

  while(true)
    {
      // 0 -> start, bn+rn+1

      cin >> bn >> rn;
      if(bn+rn == 0)
	break;

      st = 0,ed = bn+rn+1;
      G.clear();
      G.resize(2+bn+rn); 

      vector<int> bs;
    
      for(int i=0;i<bn;i++)
	{
	  cin >> b;
	  add_node(0,i+1);
	  bs.push_back(b);
	}

      for(int i=0;i<rn;i++)
	{
	  cin >> r;
	  add_node(bn+i+1,ed);
	  for(int j=0;j<bs.size();j++)
	    if(__gcd(bs[j],r) != 1)
		add_node(j+1,bn+i+1);
	      
	}

      cout << maximum_flow(bn+rn+2) << endl;


    }

  return 0;
}

Measured memory_bytes: 5628
#!/usr/bin/python3

import array
from fractions import Fraction
import math
import os
import sys


def main():
    Q = read_int()
    for _ in range(Q):
        x0, y0, x1, y1, x2, y2, x3, y3 = read_ints()
        print(solve(Vec(x0, y0), Vec(x1, y1), Vec(x2, y2), Vec(x3, y3)))


CROSS = 1
NOT_CROSS = 0


def solve(a, b, c, d):
    p = b - a
    q = c - a
    r = d - a
    cq = p.cross(q)
    cr = p.cross(r)
    if cq == 0 and cr == 0:
        dq = p.dot(q)
        dr = p.dot(r)
        ap = p.abs2()
        aq = q.abs2()
        ar = r.abs2()
        if (dq < 0 and dr < 0) or (ap < aq and ap < ar):
            return NOT_CROSS
        return CROSS

    if cq * cr > 0:
        return NOT_CROSS

    p = d - c
    q = a - c
    r = b - c
    cq = p.cross(q)
    cr = p.cross(r)
    if cq * cr > 0:
        return NOT_CROSS

    return CROSS


###############################################################################
# AUXILIARY FUNCTIONS

class Vec(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        super().__init__()

    def __add__(self, other):
        return Vec(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vec(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __rmul__(self, scalar):
        return Vec(self.x * scalar, self.y * scalar)

    def __truediv__(self, scalar):
        return Vec(self.x / scalar, self.y / scalar)

    def __iadd__(self, other):
        self.x += other.x
        self.y += other.y
        return self

    def __isub__(self, other):
        self.x -= other.x
        self.y -= other.y
        return self

    def __imul__(self, scalar):
        self.x *= scalar
        self.y *= scalar
        return self

    def __idiv__(self, scalar):
        self.x /= scalar
        self.y /= scalar
        return self

    def __neg__(self):
        return Vec(-self.x, -self.y)

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def abs2(self):
        return self.x * self.x + self.y * self.y

    def __abs__(self):
        return math.sqrt(float(self.abs2()))

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)


DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7104
#include <iostream>
#include <cstdio>
using namespace std;
int n, x, a, ans, mn = 1e9;
int main() {
	cin>>n>>x;
	while(n--) {
		cin>>a;
		ans++;
		x -= a;
		mn = min(mn, a);
	}
	cout<<ans + x/mn;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
    
    int n;
    
    scanf("%d", &n);
    
    for(int i=1; i<=9; i++){
        
        for(int j=1; j<=9; j++){
            
            if(i*j==n){
                
                printf("Yes");
                
                return 0;
                
            }
            
        }
        
    }
    
    printf("No");
    
    return 0;
    
}

Measured memory_bytes: 128
#from math import ceil
N=int(input())
table=[]
for i in range(N):
    t,x=map(int,input().split())
    table.append((t,x))
A,B=1,1
def f(A,x):
    t=A//x
    if A%x!=0:
        t+=1
    return t
    
for x,y in table:
    t=max(f(A,x),f(B,y))
    A=t*x
    B=t*y
print(A+B)

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



int main(){
  int N;
  cin>>N;
  if(N>999) cout<<"ABD"<<endl;
  else cout<<"ABC"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[3];
void solve()
{
    sort(a,a+2);
    if (a[2]>=a[0]&&a[2]<=a[1]) puts("Yes");
    else puts("No");
}
int main()
{
    while(cin>>a[0]>>a[1]>>a[2])
        solve();
    return 0;
}

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

public class Main {

    public static void main(String[] args) {

        System.out.println(solve());
    }

    public static int solve() {

        FastScanner scan = new FastScanner(System.in);
        final int N = scan.nextInt();
        if (N == 1) {
            return 0;
        }

        final long[] H = new long[N];
        for (int i = 0; i < N; i++) {
            H[i] = scan.nextLong();
        }

        int max = 0;
        int count = 0;
        for (int i = 1; i < N - 1; i++) {
            if (H[i - 1] >= H[i]) {
                count++;
            } else {
                if (count > max) {
                    max = count;
                }
                count = 0;
            }
        }
        if (H[N - 2] >= H[N - 1]) {
            count++;
        }
        if (count > max) {
            max = count;
        }

        return max;
    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

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

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

}


Measured memory_bytes: 40404
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int solve(long long N, long long K, std::vector<long long> A)
{

  for (auto &&a : A)
    a--;

  int cur = 0;
  LL leng = 0;
  LL from = 0;
  vector<int> cnt(N, -1);
  while (true)
  {
    if (cnt[cur] != -1)
    {
      from = cnt[cur];
      break;
    }
    if (K == leng)
      return cur;
    cnt[cur] = leng;
    cur = A[cur];
    leng++;
  }
  if (from + 1 == leng)
    return cur;

  LL loop = leng - from;

  LL c = (K - from) % loop + from;

  for (int i = 0; i < N; i++)
    if (cnt[i] == c)
      return i;
  return -1;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  cout << solve(N, K, std::move(A)) + 1 << endl;
  return 0;
}


Measured memory_bytes: 5612
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    n = i_input()

    a = i_list()
    ans = []
    for m,i in enumerate(a):
        ans.extend([str(m+1)]*i)
    ans = list(ans)
    for i in range(1,h+1):
        if i%2 == 0:
            print(" ".join(ans[w*(i-1):w*(i-1)+w]))
        else:
            print(" ".join(ans[w*(i-1):w*(i-1)+w][::-1]))

if __name__=="__main__":
    main()


Measured memory_bytes: 10100
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int maxn = 2e5 + 1;
ll int arr[maxn];
int main()
{
	ll int N,ans= 0,max_num =-1 ; cin >> N;
	for(ll int i = 0; i < N ; i++)
		cin >> arr[i];
	max_num = arr[0];
	for(ll int i = 1; i < N; i++)
	{
		if( max_num > arr[i])
			ans+= (max_num - arr[i]);
		else 
			max_num = arr[i];
	}
	cout << ans << endl;	
}

Measured memory_bytes: 5164
import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class Main {
	static int mod = 1000000007;
	static InputReader in = new InputReader(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		
		int n=in.nextInt();
		int m=in.nextInt();
		int[] a=new int[n];
		Map<Integer, Integer> map=new HashMap<>();
		int[] psum=new int[n];
		long ans=0;
		map.put(0, 1);
		for(int i=0;i<n;i++)
		{
			a[i]=in.nextInt();
			if(i==0)
				psum[0]=a[0];
			else
				psum[i]=psum[i-1]+a[i];
			psum[i]%=m;
			if(map.containsKey(psum[i]))
				map.put(psum[i], map.get(psum[i])+1);
			else
				map.put(psum[i], 1);
		}
		for(int i : map.keySet())
		{
			if(map.get(i)>1)
			{
				ans+=((long)map.get(i)*(long)(map.get(i)-1))/2;
			}
		}
		out.println(ans);

		out.close();

	}

	static class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	private static void tr(Object... o) {
		if (!(System.getProperty("ONLINE_JUDGE") != null))
			System.out.println(Arrays.deepToString(o));
	}
}




Measured memory_bytes: 29620
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int count = 0;

	for(int i = 0; i < n-2; i++){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
			count++;
	}	
	cout << count << endl;



	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner scn = new Scanner(System.in);
        int [][][] office = new int[4][3][10];
        int b=0,f=0,r=0,v=0,count=0;
        
        
        int n=scn.nextInt();
        for(int i=0;i<n;i++){
            b=scn.nextInt();
            f=scn.nextInt();
            r=scn.nextInt();
            v=scn.nextInt();
            office[b-1][f-1][r-1]+=v;
          
        }
        
        build(0,office);
        build(1,office);
        build(2,office);
        build(3,office);
        
    }


    private static void build(int count_b, int [][][] office_b) {
       for(int i=0;i<3;i++){
            for(int j=0;j<10;j++){
                if(office_b[count_b][i][j]==0){
                    System.out.print(" "+0);
                }else{
                    System.out.print(" "+office_b[count_b][i][j]);
                }
                                
            }
        
                System.out.println("");
           
       }
       if(count_b!=3){
           System.out.println("####################");
       }
    }
    
}

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b;
    cin >> a >> b;
    if(a >= b) {
        for(int i = 0; i < a; i++) {
            cout << b;
        }
    }
    else {
        for(int j = 0; j < b; j++) {
            cout << a;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b) % 2 != 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
11 30
)");
#define cin input
#endif

int main()
{
	int a, b;
	cin >> a >> b;

	if (a <= b)
		cout << a << endl;
	else
		cout << a-1 << endl;
	
return 0;
}

Measured memory_bytes: 256
N,Q = list(map(int,input().split()))
ad={}
point={}
P = {}
color={}
child={}

for n in range(N):
    ad[n+1]=set()
    child[n+1]=set()
    color[n+1] = -1
    point[n+1] = 0
    P[n+1] = 0

for n in range(N-1):
    a,b = list(map(int,input().split()))
    ad[a].add(b)
    ad[b].add(a)
    
for q in range(Q):
    p,x = list(map(int,input().split()))
    point[p] += x

#BFS
from collections import deque
start=1
visit = []
que = deque([start])

i=0
while len(que) > 0:
    start = que.popleft()
    color[start] = 1
    
    for v in ad[start]:
        if color[v] == -1:
            que.append(v) 
            color[v] = 0
            point[v] += point[start]
    
#     print(que,point)
ans=' '.join(map(str,point.values()))
print(ans)

Measured memory_bytes: 237636
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size)
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main()
{
    string a,b,c; 
    cin >> a >> b >> c;
    string next = "a";
    while(true){
        if(next=="a"){
            if(a.empty()==true){
                next ="A";
                break;
            }
            next = a[0];
            a.erase(a.begin());
        }
        else if(next=="b"){
            if(b.empty()==true){
                next ="B";
                break;
            }
            next = b[0];
            b.erase(b.begin());
        }
        else if(next=="c"){
            if(c.empty()==true){
                next ="C";
                break;
            }
            next = c[0];
            c.erase(c.begin());
        }
    }
    cout << next;;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#include <assert.h>
 
 
using namespace std;
 
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 2e18 + 7;
const int maxN = 2e6 + 5;
const ll MOD = 1e9 + 7;
 
ll n, W, w[maxN], c[maxN], dp[101][maxN];

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> W;
	REP(i, n) {
		cin >> w[i] >> c[i];
		REP(j, W + 1) {
			dp[i][j] = -1; 
		}
	}
	dp[0][0] = 0;
	dp[0][w[0]] = c[0];
	ll maxAns = 0;
	RI(i, n) {
		dp[i][0] = 0;
		REP(j, W + 1) {
			dp[i][j] = dp[i - 1][j];
			if (j - w[i] >= 0 && dp[i - 1][j - w[i]] != -1) {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + c[i]);
			}
			maxAns = max(maxAns, dp[i][j]);
		}
	}
	cout << maxAns;
	return 0;
}


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

int main() {
	int n,i;
	cin >> n;
	char s;
	for (i = 0;i < n &&s !='Y' ;i++) {
		cin >> s;
	}
	if (i == n )cout << "Three" << endl;
	else cout << "Four" << endl;
}

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> dp(N + 1);
    dp[0] = 1;
    for (int i = 1; i < N + 1; i++)
        dp[i] = min(dp[i - 1] * 2, dp[i - 1] + K);
    cout << dp[N];
}

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

int N;
int F[110][20];
int P[110][20];

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)for(int j = 0; j < 10; j++)scanf("%d",&F[i][j]);
    for(int i = 0; i < N; i++)for(int j = 0; j <= 10; j++)scanf("%d",&P[i][j]);
    int ans = -1001001001;
    for(int i = 1; i < (1 << 10); i++)
    {
        int res = 0;
        for(int j = 0; j < N; j++)
        {
            int cnt = 0;
            for(int k = 0; k < 10; k++)if((i >> k) & 1 && F[j][k] == 1)cnt++;
            res += P[j][cnt];
        }
        ans = max(ans,res);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#define MII map<int,int>
using namespace std;
int main()
{
  string s;
  int n,d;
  MII m1,m2;
  for(;;){
    getline(cin, s);
    if(s == "") break;
    sscanf(s.c_str(), "%d,%d", &n,&d);
    m1[n]++;
  }
  for(;;){
    getline(cin, s);
    if(s == "") break;
    sscanf(s.c_str(), "%d,%d", &n,&d);
    m2[n]++;
  }
  for(MII::iterator p = m1.begin(); p != m1.end(); p++){
    MII::iterator q = m2.find((*p).first);
    if(q != m2.end())
      cout << (*p).first << " " << (*p).second + (*q).second << endl;
  }
  return 0;
}

Measured memory_bytes: 0
from collections import defaultdict
from math import factorial

n = int(input())
s = []

for i in range(n):
    t = list(input())
    t.sort()
    s += [t]

for i in range(n):
    s[i] = ",".join(s[i])
    s[i] = s[i].replace(",","")
    
ans = 0

d = defaultdict(int)

for key in s:
    if key in d:
        ans += d[key]
    d[key] += 1
    
print(ans)

Measured memory_bytes: 30612
#include<iostream>
using namespace std;
int main()
{
    

/*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
    long n;
    cin>>n;
    long double a;
    long long ans=1;
    long double check=1;
    for(int i=0;i<n;i++){
        cin>>a;
        ans*=a;
        check*=a;
    }
    if(check>1000000000000000000)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
int n,h,w;
int main()
{
	SPEED;
	cin>>n>>h>>w;
	int ans=(n-h+1)*(n-w+1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import collections
import copy

a = list(map(int,input().split()))
c = []
d = []
for i in range(a[2]):
    b = list(map(int,input().split()))
    c.append(b[0])
    d.append(b[1])

ans1 = 0
ans2 = 0

cp = copy.copy(c)
dp = copy.copy(d)

e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]
ans1 += gc
ans2 += hc
for i in range(a[2]):
    if cp[i] == g:
        d[i] = -1
    if dp[i] == h:
        c[i] = -1
e = collections.Counter(c)
f = collections.Counter(d)
g = e.most_common()[0][0]
gc = e.most_common()[0][1]
h = f.most_common()[0][0]
hc = f.most_common()[0][1]

if g == -1:
    if gc == a[2]:
        gc = 0
    else:
        g = e.most_common()[1][0]
        gc = e.most_common()[1][1]
if h == -1:
    if hc == a[2]:
        hc = 0
    else:
        h = f.most_common()[1][0]
        hc = f.most_common()[1][1]

ans1 += hc
ans2 += gc
if ans1 > ans2:
    print(str(ans1))
else:
    print(str(ans2))

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

int main() {
  int A,B;
  int socket=1;
  int plag=0;
  cin >> A >> B;
  for (int i=1; socket < 21;i++){
     if (socket >=B){
        break;
     }
     socket+=(A-1);
     plag++;
  }
  cout << plag << endl;
}

Measured memory_bytes: 256
use std::io::*;//Not mine.
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let n:i32 = read();
    let mut a:Vec<i32> = (0..n).map(|_| read()).collect();
    let mut sumA = 0;
    let mut sumB = 0;
    a.sort();
    a.reverse();
    for (i, &l) in a.iter().enumerate(){
        if(i % 2 == 0){
            sumA += l;
        }
        if(i % 2 != 0){
            sumB += l;
        }
    }
    println!("{}", sumA - sumB);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
#define fs front().first
using namespace std;
typedef pair<int,int> pii;

template<class Comp>
inline void add(deque<pii> &q, pii nxt, Comp comp){
  while(!q.empty() && comp(q.back(),nxt))q.pop_back();
  q.push_back(nxt);
}

inline void del(deque<pii> &q, int p){
  if(q.front().second == p)q.pop_front();
}

int main(){
  int n,d;
  scanf("%d%d",&n,&d);
  
  vector<pii> x(n),y(n);
  rep(i,n){
    int X,Y,B;
    scanf("%d%d%d",&X,&Y,&B);
    x[i] = pii(B,X); y[i] = pii(B,Y);
  }
  sort(all(x)); sort(all(y));

  long long res = 0;
  deque<pii> maxx, maxy, minx, miny;
  int r = 0;
  rep(l,n){
    while(r<n && x[r].first-x[l].first<=d){
      add(maxx,pii(x[r].second,r),less<pii>());
      add(minx,pii(x[r].second,-r),greater<pii>());
      add(maxy,pii(y[r].second,r),less<pii>());
      add(miny,pii(y[r].second,-r),greater<pii>());
      r++;
    }

    res = max( res, (long long)(maxx.fs - minx.fs) * (maxy.fs - miny.fs) );

    del(maxx,l); del(minx,-l);
    del(maxy,l); del(miny,-l);
  }
  printf("%lld\n",res);
}

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

int main() {
    int n;
    cin >> n;
    unordered_set<string> s;
    rep(i,n){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 17624
#include<bits/stdc++.h>
using namespace std;
#define sz 200005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

struct str
{
    string s;
    int num;
    int id;
};

bool compare1(str x,str y)
{
    if(x.s == y.s) return x.num>y.num;
    return x.s<y.s;
}

int main()
{
    faster_io;
    int n,x,y;
    cin>>n;
    str res[n+5];
    string s;

    for(int i=0;i<n;i++){
        cin>>s>>x;
        res[i].s = s;
        res[i].num = x;
        res[i].id = i+1;
    }

    sort(res,res+n,compare1);

    for(int i=0;i<n;i++) cout<<res[i].id<<endl;

    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()

#define equal equalll
#define less lesss
const int N = 2e5 + 10;
const long long INF = 1e9 + 19;


int a[N];
int p[N];
int ll[N];
int rr[N];
bool use[N];
int n;

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

int getId(int v) {
    return p[v] == v? v: p[v] = getId(p[v]);
}

void merge(int v, int u) {
    v = getId(v);
    u = getId(u);
    if (v != u) {
        p[v] = u;
        ll[u] = min(ll[u], ll[v]);
        rr[u] = max(rr[u], rr[v]);
    }
}

void solve() {
    for (int i = 0; i < n; i++) {
        p[i] = i;
        ll[i] = i;
        rr[i] = i;
    }
    vector<pair<int, int>> b;
    for (int i = 0; i < n; i++)
        b.pb(mp(a[i], i));

    sort(b.begin(), b.end(), greater<pair<int, int>>());

    long long answer = 0;
    for (auto x: b) {
        int pos = x.sc; 
        use[pos] = 1;
        for (int dx = -1; dx <= 1; dx += 2) {
            int y = pos + dx;
            if (0 <= y && y < n && use[y] == 1) {
                merge(y, pos); 
            }
        }
        int v = getId(pos);
        int left = pos - ll[v] + 1;
        int right = rr[v] - pos + 1;
        answer += x.fr * 1ll * left * right;
    }

    cout << answer << endl;

}

void stress() {

}

int main(){
#ifdef MY_DEBUG
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    if (1) {
        int k = 1;
        for (int tt = 0; tt < k; tt++) {
            read();
            solve();
        }
    }
    else {
        stress();
    }

    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  vector<int> a(n);
  rep(i,n){
    a[i]=s.at(i)-'0';
  }
  
  ll ans=0;
  for(int bit=0; bit<(1<<(n-1)); bit++){
    ll num=0;
    ll cur=a[0];
    for(int i=0; i<n-1; i++){
      if(bit&(1<<i)){
        num=num+cur;
        cur=a[i+1];
      }else{
        cur=cur*10+a[i+1];
      } 
    }
    num+=cur; 
    ans+=num;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
sa = list(input())
sb = list(input())
sc = list(input())

turn = "a"

while True:
    if turn == "a":
        if len(sa) != 0:
            turn = sa.pop(0)
        else:
            print("A")
            exit()
    elif turn == "b":
        if len(sb) != 0:
            turn = sb.pop(0)
        else:
            print("B")
            exit()
    else:
        if len(sc) != 0:
            turn = sc.pop(0)
        else:
            print("C")
            exit()





Measured memory_bytes: 3064
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=305;
int mp[N][N],cnt[N],id[N],bg[N],vis[N],res,mx,n,m;
int main(){
	scanf("%d%d",&n,&m);
	fp(i,1,n)fp(j,1,m)scanf("%d",&mp[i][j]);
	fp(i,1,n)bg[i]=1,++cnt[mp[i][1]];
	res=2333;
	while(2333){
		mx=0;fp(i,1,m)cmax(mx,cnt[i]);
		cmin(res,mx);
		fp(i,1,m)if(cnt[i]==mx)vis[i]=1;
		fp(i,1,n)while(bg[i]<=m&&vis[mp[i][bg[i]]])++bg[i];
		fp(i,1,n)if(bg[i]>m)return printf("%d\n",res),0;
		fp(i,1,m)cnt[i]=0;
		fp(i,1,n)++cnt[mp[i][bg[i]]];
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<ll, ll> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }
    
    vl v;
    for(auto p : mp) {
        if(p.second >= 4) {
            rep(i, 2) {
                v.pb(p.first);
            }
         }
        else if(p.second >= 2) {
            v.pb(p.first);
        }
    }
    sort(rall(v));
    
    if(v.size() == 0) {
        out(0);
    }
    else {
        out(v[0]*v[1]);
    }
    
    re0;
}

Measured memory_bytes: 6528
// inputに入力データ全体が入る
function Main(input) {
    input = input.split(' ');
    //文字列から10進数に変換するときはparseIntを使います
    var d = parseInt(input[0], 10);
    var n = parseInt(input[1], 10);
    
    var count = d;
    var tmp = 1;
    var ans = 0;
    while (count != 0) {
        tmp *= 100;
        count--;
    }
    ans = tmp * n;
    if (d == 0 && ans == 100) {
        ans++;
    } else if (d == 1 && ans == 10000) {
        ans += 100;
    } else if (d == 2 && ans == 1000000) {
        ans += 10000;
    }
    console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
use std::io;


fn main() {
    let s = read_one::<usize>();
    let mut buf = Vec::new();
    let mut prev = s;
    for i in 1..1000000 {
        let v;
        if i == 1 { v = s; }
        else {
            if prev % 2 == 0 { v = prev / 2; }
            else { v = prev * 3 + 1; }
        };

        if buf.contains(&v) {
            println!("{}", i);
            return;
        }
        buf.push(v);
        prev = v;
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

bool kaibun(int n){
  string s = "";
  while(n > 0){
    s.push_back((char)(n%10 - '0'));
    n /= 10;
  }
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}

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

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n = int(input())

print((n-2)*180)


Measured memory_bytes: 3564
a, b, k = map(int,input().split())

if a >= k:
    a = a - k
    print('{} {}'.format(a, b))
elif k <= a + b:
    b = b - (k - a)
    a = 0
    print('{} {}'.format(a, b))
else:
    a = 0
    b = 0
    print('{} {}'.format(a, b))


Measured memory_bytes: 3060