akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};
 
struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};
 
constexpr ran rn0(const i64 e) noexcept { return ran(e); }
constexpr ran rn0(const i64 b, const i64 e) noexcept { return ran(b, e); }
constexpr ran rn1(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rn1(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }
 
i64 pow_(i64 x, i64 p) {
  i64 ans = 1;
  while(p) {
    if(p & 1) ans *= x;
    x = x * x;
    p >>= 1;
  }
  return ans;
}
 
i64 calc(i64 x) {
  i64 ans = 0;
  while(x) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}
 
int main() {
  i64 a, n, m;
  cin >> a >> n >> m;
  i64 ans = 0;
  for(i64 z = 1;pow_(z, n) <= m;z++) {
    i64 x = pow_(z, n);
    i64 y = z - a;
    if(calc(x) == y) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3112
package main

import (
	"fmt"
)

func main() {
	var s, t string
	var sRunes, tRunes []rune
	fmt.Scan(&s, &t)

	sRunes = []rune(s)
	tRunes = []rune(t)

	for i := 0; i < len(sRunes); i++ {
		if isEqual(sRunes, tRunes) {
			fmt.Println("Yes")
			return
		}

		sRunes = rotRunes(sRunes)
	}

	fmt.Println("No")
}

func rotRunes(input []rune) []rune {
	var result []rune

	result = append(result, input[len(input)-1])
	for i := 0; i < len(input)-1; i++ {
		result = append(result, input[i])
	}

	return result
}

func isEqual(s, t []rune) bool {
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			return false
		}
	}

	return true
}


Measured memory_bytes: 640
#include <iostream>

int main() {
    int n, k;
    std::cin >> n >> k;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int h;
        std::cin >> h;
        if (h >= k) ++ans;
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 2019
int cnt[M];
int main(){
  string s;
  cin>>s;
  int n=s.length();
  int pot=1;
  int suf=0;
  cnt[suf]++;
  long long int ans=0;
  for(int i=n-1;i>=0;i--){
    int dig=s[i]-'0';
    suf=(suf+pot*dig)%M;
	ans+=cnt[suf];
    cnt[suf]++;
    pot=(pot*10)%M;
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 3720
#include<iostream>

using namespace std;

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

    if (a+b > c+d){
        cout<< "Left" << endl;
    }
    else if(a+b < c+d){
        cout<< "Right" <<endl;
    }
	else {
        cout<< "Balanced" <<endl; 
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
  unsigned long long n, num;
  unsigned long long shortest=0;
  cin >> n;
  for(int i=0; i<5; i++){
    unsigned long long tmp;
    cin >> tmp;
    if(i==0 || shortest>tmp){
      shortest = tmp;
    }
    num = n/shortest;
    if(n%shortest==0)num-=1;
    num += 5;
  }
  
  
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
res = 0
mod = 10**9+7

fac = [1]
caf = [1]


def pow(n, p):
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod


for i in range(1, n+1):
    fac.append((fac[i - 1] * i) % mod)
    caf.append(pow(fac[i], mod - 2))


def ncr(n, r):
    if n < r or r < 0:
        return 0
    return fac[n] * caf[r] * caf[n - r]



res = 0
for i in range(n):
    res += (a[i]*ncr(i,k-1))%mod
    res -= (a[i]*ncr(n-i-1,k-1))%mod
    res %= mod

print(res)

Measured memory_bytes: 66344
#include<iostream>
#include<string>
using namespace std;
int p[10][10];
int check_digit(int G) {
    if (G < 10000) {
        int a = G / 1000, b = (G / 100) % 10, c = (G / 10) % 10, d = G % 10;
        int F = p[p[p[p[0][a]][b]][c]][d]; return F;
    }
    int a = G / 10000, b = (G / 1000) % 10, c = (G / 100) % 10, d = (G / 10) % 10, e = G % 10;
    int F = p[p[p[p[p[0][a]][b]][c]][d]][e]; return F;
}
int main() {
    int cnt = 0;
    for (int i = 0; i < 100; i++)cin >> p[i / 10][i % 10];
    for (int i = 0; i < 10000; i++) {
        string S = to_string(i); while (S.size() < 4)S = '0' + S;
        S += (char)('0' + check_digit(stoi(S)));
        bool OK = true;
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 10; k++) {
                if (S[j] == ('0' + k))continue;
                string T = S; T[j] = '0' + k;
                if (check_digit(stoi(T)) == 0)OK = false;
            }
        }
        for (int j = 0; j < 4; j++) {
            if (S[j] == S[j + 1])continue;
            string T = S; swap(T[j], T[j + 1]);
            if (check_digit(stoi(T)) == 0)OK = false;
        }
        if (OK == false)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3252
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

char s[300048];
LL dp[300048][5][2][2];
//i: current pos
//j: suffix zero num(<3)
//k: the odd's zero / the even's zero
//m: whether there exists an odd's zero
LL pros[300048];

inline int calc(int x)
{
	while (x>2) x-=2;
	return x;
}

int main ()
{
	int i,j,k,m,len;LL ans=0;
	scanf("%s",s+1);len=strlen(s+1);
	pros[len+1]=1;
	for (i=len;i;i--) pros[i]=(pros[i+1]*(s[i]=='?'?2:1))%MOD;
	dp[0][0][1][0]=1;
	for (i=0;i<=len-1;i++)
		for (j=0;j<=2;j++)
			for (k=0;k<=1;k++)
				for (m=0;m<=1;m++)
					if (dp[i][j][k][m])
					{
						if (s[i+1]!='1')
							dp[i+1][calc(j+1)][k][m]+=dp[i][j][k][m]%=MOD;
						if (s[i+1]!='0')
						{
							if (j==1)
							{
								dp[i+1][0][k][m]+=dp[i][j][k][m]%=MOD;
								continue;
							}
							if (j==2)
							{
								dp[i+1][0][k^1][m]+=dp[i][j][k][m]%=MOD;
								continue;
							}
							if (m==1 && !k) {ans=(ans+(dp[i][j][k][m]*pros[i+2])%MOD)%MOD;continue;}
							if (m==0 && k) {dp[i+1][0][k^1][1]+=dp[i][j][k][m]%=MOD;continue;}
							dp[i+1][0][k^1][m]+=dp[i][j][k][m]%=MOD;
						}
					}
	ans=(ans+dp[len][0][0][1])%MOD;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 49792
// matrix chain multiplication
#include<iostream>
#define MAX 2000000
void MatrixChainMultiplication(int*,int);
int **F;
int main(){
  int n,i,j,*matrix;
  std::cin >> n;
  matrix = new int[n+1];
  F = new int*[n+1];
  for(i=1; i<=n; i++) F[i] = new int[n+1];
  for(i=0; i<n; i++){
    std::cin >> matrix[i] >> (i != n - 1 ? j : matrix[i+1]);
  }
  MatrixChainMultiplication(matrix,n);
  std::cout << F[1][n] << "\n";
  return 0;
}

void MatrixChainMultiplication(int* p,int n){
  int i,j,k,l,q;
  for(i=1; i<=n; i++) F[i][i] = 0;
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i + l - 1;
      F[i][j] = MAX;
      for(k=i; k<=j-1; k++){
        q = F[i][k] + F[k+1][j] + p[i-1] * p[k] * p[j];
        F[i][j] = (F[i][j] < q ? F[i][j] : q);
      }
    }
  }
}

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n;
    cin >> n;
    vector<int> v(1);
    v[0] = 0;
    int j = 1;
    while(v[j-1] < n){
        v.push_back(v[j-1]+j);
        j++;
    }
    if(v[j-1] == n){
        cout << "Yes" << endl;
        cout << j << endl;
        vector< vector<int> > ans(j);
        int now = 1;
        rep(i, j-1){
            ans[0].push_back(now);
            now++;
        }
        REP(i, 1, j){
            rep(k, i){
                ans[i].push_back(ans[k][i-1]);
            }
            REP(k, i, j-1){
                ans[i].push_back(now);
                now++;
            }
        }
        rep(i, j){
            cout << j-1;
            rep(k, j-1){
                cout << " " << ans[i][k];
            }
            cout << endl;
        }
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <math.h>
 
int isprime(int x){
  int i;
 
  if(x==2) return 0;
 
  if(x<2 || x%2==0) return 1;
 
 
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return 1;
    i+=2;
  }
  return 0;
}

int main(){
 
  int n,res=0;
  int i;
  int A[10000];
   
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    if(isprime(A[i])==0) res++;
  }
  printf("%d\n",res);
 
  return 0;
}

Measured memory_bytes: 628
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())

def main():
    N, T = mis()
    lis = []
    for _ in range(N):
        c,t = mis()
        if t<=T:
            lis.append(c)
    if lis:
        print(min(lis))
    else:
        print('TLE')

main()


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

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

  cout << a + b + c - max({a, b, c}) << endl;
  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c, d;
    cin >> a >> b >> c >> d ;
    //*/

    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    //*
    if( ( abs(a - b) <= d && abs(c - b) <= d ) || ( abs(a - c) <= d ) ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << min(a, b) << endl;

    return 0; 
}


Measured memory_bytes: 3604
n = int(input())

a = [[0 for i in range(10)] for j in range(10)]
for i in range(1,n+1):
    s = str(i)
    a[int(s[0])][int(s[-1])] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += a[i][j]*a[j][i]
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>

int main(){
	int n;
	while(scanf("%d", &n), n){
		bool tmp[30][50], v[30][50];
		bool end = false;
		for(int i = 0; i < 30; i++){
			for(int j = 0; j < 50; j++) tmp[i][j] = false;
		}
		for(int i = 0; i < n; i++){
			int f;
			scanf("%d", &f);
			for(int j = 0; j < f; j++){	
				int t;
				scanf("%d", &t);
				t--;
				tmp[t][i] = true;
			}
		}
		for(int i = 0; i < 30; i++){
			for(int j = 0; j < 30; j++) for(int k = 0; k < 50; k++) v[j][k] = tmp[j][k];
			for(int j = i-1; j >= 0; j--){
				for(int k = 0; k < n; k++){
					if(v[i][k] == true && v[j][k] == true){
						for(int l = 0; l < n; l++){
							if(v[j][l] == true) v[i][l] = true;
						}
						break;
					}
				}
			}
			bool ok = true;
			for(int j = 0; j < n; j++){
				if(v[i][j] == false){
					ok = false;
					break;
				}
			}
			if(ok){
				printf("%d\n", i+1);
				end = true;
				break;
			}
		}
		if(!end) printf("-1\n");
	}
}

Measured memory_bytes: 1040
array = list(map(int, input().split()))
#pythonなら.sort()も用意されてるんやで
array.sort()
#for i in range(1,len(array)):
#  if array[i-1] > array[i]:
#    temp = array[i]
#    array[i] = array[i-1]
#    array[i-1] = temp
print(array[0], array[1], array[2])


Measured memory_bytes: 5588
import sys
import numpy as np

read=sys.stdin.read
readline=sys.stdin.readline

def main():
  wb={'W':1,'B':0}
  n,k=map(int,readline().split())
  xyc=[l.split() for l in read().splitlines()]
  xy=[[int(lst[0]) % (2*k),(int(lst[1])+k*wb[lst[2]]) % (2*k)] for lst in xyc]
  mat=np.zeros((k+1,2*k+1),dtype='int64')
  cand=np.zeros((k+1,k+1),dtype='int64')
  for e in xy:
    f0=e[0]>=k
    f1=e[1]>=k
    mat[e[0]-f0*k+1,e[1]+(-1)**f1*f0*k+1]+=1
  mat=np.cumsum(mat,axis=0)
  mat=np.cumsum(mat,axis=1)
  cand=mat[k,2*k]-mat[k,k:2*k+1]+mat[k,:k+1]\
       -np.reshape(mat[:k+1,2*k],(k+1,1))+2*mat[:,k:2*k+1]-2*mat[:,:k+1]
  print(max(np.max(cand),mat[k,2*k]-np.min(cand)))
  
if __name__=='__main__':
  main()
  
  
  


Measured memory_bytes: 103212
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define ll long long
#define inf  1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな

signed main()
{
    ll n,s;
    ll ans=-1;
    cin>>n>>s;
    ll r=(ll)sqrt(n)+1LL;
    for(ll i=2;i<r;i++)
    {
        ll cp=n;
        ll temp=0;
        while(cp!=0)
        {
            temp+=cp%i;
            cp/=i;
        }
        if(temp==s)
        {
            ans=i;
            break;
        }
        //cerr<<i<<" "<<temp<<endl;
    }
    if(ans==-1)
    {
        ll mm=1e15-1;
        //2ケタの探索
        for(ll p=1;p<r;p++)
        {
            ll q=s-p;
            ll i=(n-q)/p;
            if(i<r)
                continue;
            ll cp=n;
            ll temp=0;
            while(cp!=0)
            {
                temp+=cp%i;
                cp/=i;
            }
            if(temp==s)
            {
                mm=min(i,mm);
            }
        }
        if(mm<1e15-1)
            ans=mm;
    }
    
    if(s==n && ans==-1)
        ans=n+1;
    if(s==1 && ans==-1)
        ans=n;
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{
    int n; cin>>n;
    int res = 0;
    for(int i=1;i<=n;++i){
        int c; cin>>c;
        if(i&1 && c&1) ++res;
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
	"math"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		debt := float64(100000)
		for i:=1; i<=n; i++ {
			debt = debt*1.05
			debt = math.Ceil(debt*0.001) * 1000
		}		
		fmt.Println(int(debt))
	}
}


Measured memory_bytes: 1052
#include<vector>

class UnionFind {
public:
    UnionFind(int N) :parent(N), rank(N, 0), size(N, 1) {
        for (int i = 0; i < N; ++i) parent[i] = i;
    }
    int find(int x) {
        return x == parent[x] ? x : parent[x] = find(parent[x]);
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) parent[x] = y;
        else {
            parent[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
            std::swap(x, y);
        }
        size[y] += size[x];
        size[x] = 0;
    }
    int getParentRank(int x) {
        return rank[find(x)];
    }
    int getParentSize(int x) {
        return size[find(x)];
    }
    int getSize(int x) {
        return size[x];
    }
private:
    std::vector<int> parent, rank, size;
};
#include<iostream>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    UnionFind UF(n);
    for(int i=0;i<m;++i){
        int a,b;
        cin>>a>>b;
        UF.unite(a,b);
    }
    int q;
    cin>>q;
    for(int i=0;i<q;++i){
        int a,b;
        cin>>a>>b;
        cout<<(UF.same(a,b)?"yes":"no")<<endl;
    }
}

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

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N), h(N);
    rep(i, N) cin >> x[i] >> y[i] >> h[i];
    
    rep(Cx, 101) rep(Cy, 101) {
        int H = -1;
        rep(i, N) {
            if (h[i] != 0) {
                H = h[i] + abs(Cx - x[i]) + abs(Cy - y[i]);
                break;
            }
        }
        bool judge = true;
        rep(i, N) {
            if (h[i] != max(0, H - abs(Cx - x[i]) - abs(Cy - y[i]))) {
                judge = false;
            }
        }
        if (judge) {
            printf("%d %d %d\n", Cx, Cy, H);
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef pair<double, int> P;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a, b) > EPS) return 1;
    if(cross(a, b) < -EPS) return -1;
    if(dot(a, b) < -EPS) return 2;
    if(norm(a) < norm(b)) return -2;

    return 0;
}

bool intersect(Point p1, Point p2, Point p3, Point p4){
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}

bool intersect(Segment s1, Segment s2){
    return intersect(s1.first, s1.second, s2.first, s2.second);
}

double solve(vector<Point> &pa, vector<Point> &pb){

    Segment base = {pa[0], pa[1]};
    double ans = abs(pa[0] - pa[1]);

    vector<double> dist(1000, 1e9);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[0] = 0;
    que.emplace(0, 0);

    while(que.size()){
        double ccost; int cv;
        tie(ccost, cv) = que.top();
        que.pop();

        if(dist[cv] < ccost) continue;

        for(int i=0; i<pb.size(); i++){
            int nv = i;
            Segment sg = {pb[cv], pb[nv]};

            if(intersect(base, sg)) continue;

            double cdist = abs(pb[nv] - pb[cv]);

            if(dist[cv] + cdist < dist[nv]){
                dist[nv] = dist[cv] + cdist;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return  (ans + dist[1]);
}

int main(){
    int na, nb; cin>>na>>nb;
    vector<Point> pa;
    for(int i=0; i<na; i++){
        double x, y; cin>>x>>y;
        pa.emplace_back(x, y);
    }

    vector<Point> pb;
    for(int i=0; i<nb; i++){
        double x, y; cin>>x>>y;
        pb.emplace_back(x, y);
    }

    double ansa = solve(pa, pb);
    double ansb = solve(pb, pa);

    if(1e9 <= ansa and 1e9 <= ansb){
        cout << -1 << endl;
    }
    else{
        double ans = min(ansa, ansb);
        printf("%.12f\n", ans);
    }
}


Measured memory_bytes: 3316
#include <stdio.h>

int main() {

  int n,m,i,j;
  int a,b;
  int A[100][100] = {0};
  int B[100] = {0};
  int c[100] = {0};

  scanf("%d %d " ,&n,&m);

  for(j=0; j<n; j++) {
  for(i=0; i < m; i++) {
    scanf("%d",&a);
    A[j][i] = a;
  }
}

  for(j=0; j<m; j++) {
    scanf("%d",&b);
    B[j] = b;
  }

  for(j=0;j<n ; j++){ 
  for(i = 0; i<m; i++){
     c[j] = c[j] + A[j][i]*B[i];
    }
  }

  for(i=0;i<n;i++) {
    printf("%d\n",c[i]);
  }
  return 0;
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
int p[105];
int main() {
  for(int i = 1; i <= 9; i++) {
    for(int j = i; j <= 9; j++) {
      p[i * j] = 1;
    }
  }
  int a;
  cin >> a;
  if(p[a]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
vector<int> p;
void makeprimelist(int n)
{
	bool *isp=new bool[++n];
	for(int i=0;i<n;i++)isp[i]=true;
	for(int i=2;i<=n;i++)
	{
		if(isp[i])
		{
			p.push_back(i);
			for(int j=2;j<=n/i;j++)isp[i*j]=false;
		}
	}
	return;
}

int main() {
	int n;
	while(cin>>n)
	{
		p.clear();
		makeprimelist(n);
		cout<<p.size()<<endl;
	}
	return 0;
}

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

rate=[0]*8
variety=0
special=0
for i in range(N):
    if A[i]<400:
        if rate[0]==0:
            variety+=1
        rate[0]+=1
    elif A[i]<800:
        if rate[1]==0:
            variety+=1
        rate[1]+=1
    elif A[i]<1200:
        if rate[2]==0:
            variety+=1
        rate[2]+=1
    elif A[i]<1600:
        if rate[3]==0:
            variety+=1
        rate[3]+=1
    elif A[i]<2000:
        if rate[4]==0:
            variety+=1
        rate[4]+=1
    elif A[i]<2400:
        if rate[5]==0:
            variety+=1
        rate[5]+=1
    elif A[i]<2800:
        if rate[6]==0:
            variety+=1
        rate[6]+=1
    elif A[i]<3200:
        if rate[7]==0:
            variety+=1
        rate[7]+=1
    else:
        special+=1

if special==0:
    print(variety,variety)
elif variety==0:
    print(1,special)
else:
    print(variety,variety+special)

Measured memory_bytes: 3444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main
{
  public static void main(String[] args) throws NumberFormatException, IOException
  {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    ArrayList<Integer[]> inputList = new ArrayList<>(100);

    while (input.ready())
    {
      final String[] inputStrArray = input.readLine().split(",");
      final Integer[] inputIntArray =
      { Integer.parseInt(inputStrArray[0]), Integer.parseInt(inputStrArray[1]) };

      inputList.add(inputIntArray);
    }
    final int[] ans = solver(inputList);
    System.out.println(ans[0]);
    System.out.println(ans[1]);

  }

  private static int[] solver(ArrayList<Integer[]> list)
  {
    int prodSum = 0;
    double sum = 0;
    for (Integer[] each : list)
    {
      prodSum += each[0] * each[1];
      sum += each[1];
    }
    final int[] ret =
    { prodSum, (int) Math.round(sum / list.size()) };
    return ret;
  }

}

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

using namespace std;

using Int = long long;

Int kth_lunlun(const int k) {
    if (k < 10) return k;
    
    queue<Int> q;
    for (int i = 1; i != 10; ++i) {
        q.push(i);
    }
    
    Int ans = -1;
    
    for (int i = 1; i <= k; ++i) {
        const Int x = q.front();
        q.pop();
        const Int last_digit = x % 10;
        
        if (last_digit) q.push(10 * x + last_digit - 1);
        q.push(10 * x + last_digit);
        if (last_digit != 9) q.push(10 * x + last_digit + 1);
        
        ans = x;
    }
    
    return ans;
}   

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int k;
    cin >> k;
    cout << kth_lunlun(k) << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
long long combination2(long long n)
{
	return n * (n - 1) / 2;
}
 
 
int main()
{
	int N;
	cin >> N;
	vector<int> balls(N+1);
	vector<int> count(N+1);
	//unordered_multiset<int> ballscount;
 
 
 
	long long ans = 0;
	long long tot = 0;
 
	for (int i = 1; i <= N; i++)
	{
		int a;
		cin >> a;
		balls[i] = a;
	}
 
	for (int i = 0; i <= N; i++)
	{
		count[balls[i]]++;
	}
 
	for (int i = 0; i <= N; i++)
	{
		tot += combination2(count[i]);
	}
 
	for (int i = 1; i <= N; i++)
	{
		ans = tot;
		ans -= combination2(count[balls[i]]);
		ans += combination2(count[balls[i]] - 1);
		cout << ans << endl;
	}
 
 
 
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
 
int main(){
    unsigned a,b;
    std::cin >> a >> b;
    char tmp;
    
    for(unsigned i=0; i<a; i++){
        std::cin >> tmp;
        if(tmp<'0' || tmp>'9'){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cin >> tmp;
    if(tmp!='-'){
       std::cout << "No" << std::endl;
       return 0; 
    }
    for(unsigned i=0; i<b; i++){
        std::cin >> tmp;
        if(tmp<'0' || tmp>'9'){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::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++)

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

	vector<pair<pair<string, int>, int>> data(N);

	rep(i, N) {
		string s;
		int p;
		cin >> s >> p;
		data.at(i) = make_pair(make_pair(s, -1*p), i+1);
	}

	sort(data.begin(), data.end());
  
  rep(i,N){
    cout << data[i].second << endl;
  }
}
    


Measured memory_bytes: 256
from sys import stdin
from itertools import permutations
def main():
    N,M,R = map(int,stdin.readline().split())
    r = list(map(int,stdin.readline().split()))
    r = tuple(map(lambda x: x-1,r))
    dist = [[2**60]*N for _ in range(N)]
    for _ in range(M):
        A,B,C = map(int,stdin.readline().split())
        A -= 1
        B -= 1
        dist[A][B] = C
        dist[B][A] = C
    for i in range(N):
        dist[i][i] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
    dist = tuple(map(lambda x: tuple(x),dist))
    ans = 2**60
    for t in tuple(permutations(r,R)):
        tmp = 0
        for i in range(R-1):
            tmp += dist[t[i]][t[i+1]] 
        ans = min(ans,tmp)
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 50268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }

    bool ans = true;
    for(int i=1; i<n; i++){
        for(int j=0; j<i; j++){
            if(s[i] == s[j]){
                ans = false;
                break;
            }
        }
        if(s[i-1].back() != s[i].front()){
            ans = false;
            break;
        }
    }
    if(ans){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

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

int ketasu(long long int a){
	int count=0;
	while(1){
	if(a/10==0){
		return count+1;
	}else{
		a = a/10;
		count++;
	}
	}
}

long long int zyo(int a,int b){
	long long int ans = 1;
	for(int i=0;i<b;i++){
		ans = ans*a;
	}
	return ans;
}

int main() {
	long long int N;
	long long int sum = 0;
	scanf("%lld",&N);
	int keta = ketasu(N);
	int n[keta];
	for(int i=0;i<keta;i++){
		n[keta-1-i] = N%10;
		N = N/10;
	}
	for(int i=0;i<keta;i++){
		for(int j=1;j<=keta-i;j++){
			if(j==keta-i){
				sum += n[i]*zyo(10,j-1)*zyo(2,keta-j);
			}else{
			sum += n[i]*zyo(10,j-1)*zyo(2,keta-j-1);
			}
			
			//数の桁数＊通り
			//}
		}
	}
	
	printf("%lld",sum);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

int a()
{
    std::vector<std::vector<int>> bingoSeat;
    std::vector<std::vector<int>> isFound;
    for(int i = 0; i < 3; i++)
    {
        int a, b, c = 0;
        std::cin >> a >> b >> c;
        
        std::vector<int> temp;
        temp.push_back(a);
        temp.push_back(b);
        temp.push_back(c);
        bingoSeat.push_back(temp);
        
        std::vector<int> tempFound(3, 0);
        isFound.push_back(tempFound);
    }
    
    int n = 0;
    std::cin >> n;
    
    for(int i = 0; i < n; i++)
    {
        int temp = 0;
        std::cin >> temp;
        for(int k = 0; k < 3; k++)
        {
            auto myRow = bingoSeat[k];
            if(myRow[0] == temp)
            {
                isFound[k][0] = 1;
            }
            if(myRow[1] == temp)
            {
                isFound[k][1] = 1;
            }
            if(myRow[2] == temp)
            {
                isFound[k][2] = 1;
            }
        }
    }
    
    // ビンゴ判定
    bool hasBingo = false;
    for(int i = 0; i < 3; i++)
    {
        if(isFound[i][0] && isFound[i][1] && isFound[i][2])
        {
            hasBingo = true;
        }
        if(isFound[0][i] && isFound[1][i] && isFound[2][i])
        {
            hasBingo = true;
        }
    }
    if(isFound[0][0] && isFound[1][1] && isFound[2][2])
    {
        hasBingo = true;
    }
    if(isFound[0][2] && isFound[1][1] && isFound[2][0])
    {
        hasBingo = true;
    }
    
    if(hasBingo)
    {
        std::cout << "Yes";
    }
    else
    {
        std::cout << "No";
    }

    return 0;
}

int main(int argc, const char * argv[])
{
    // insert code here...
    a();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

vector<int> to[100005];
const int INF = 100100100;

int main() {
    int n,m;
    cin >> n >> m;
    rep(i,m){
      int a,b;
      cin >> a >> b;
      a--;b--; //頂点番号をデクリメント
      to[a].push_back(b); //b->a
      to[b].push_back(a); //a->b
    }

    queue<int> q;
    vector<int> dist(n,INF); //距離を記録
    vector<int> pre(n,-1); //どこから来たか記録
    dist[0] = 0;
    q.push(0); //0を入れる
    while(!q.empty()){
      int v = q.front(); q.pop(); //頂点を先頭から取り出す
      for(int u : to[v]){ //vにつながっている頂点を全探索
        if(dist[u] != INF) continue;
        dist[u] = dist[v]+1;
        pre[u] = v; //ここがいつものBFSと違う
        q.push(u); //uをqueueに追加
      }
    }

    cout << "Yes" << endl;
    rep(i,n){
      if(i == 0) continue;
      int ans = pre[i];
      ans++; //戻さないと
      cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10728
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
#include <unordered_map>

using namespace std;
typedef long long  ll;

int main()
{
	ll N;
	cin >> N;
	vector<ll> a(N), b(N);
	for (ll i = 0; i < N; i++)
	{
		cin >> a[i] >> b[i];
	}
	ll npush = 0;
	for (ll i = N - 1; i >= 0; i--)
	{
		if ((npush + a[i]) % b[i] != 0)
		{
			npush += b[i] - (npush + a[i]) % b[i];
		}
	}
	cout << npush << endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, M;
    cin >> N >> M;
    ll A[330][330];
    REP(i, N) REP(j, M){
    	cin >> A[i][j];
    	A[i][j]--;
    }
    ll res = (1ll << 60);
    set<ll> st;
    while(st.size() < M){
    	vector<ll> cnt(M, 0);
    	REP(i, N){
    		REP(j, M){
    			if(st.find(A[i][j]) != st.end()) continue;
    			cnt[A[i][j]]++;
    			break;
    		}
    	}
    	ll ma = -1;
    	ll ind;
    	REP(i, M){
    		if(ma < cnt[i]){
    			ma = cnt[i];
    			ind = i;
    		}
    	}
    	res = min(res, ma);
    	st.insert(ind);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2510&lang=jp
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N;
	while (cin >> N, N) {
		vector<pll> rw(N);
		for (int i = 0; i < N;i++)cin >> rw[i].first >> rw[i].second;
		sort(rw.begin(), rw.end());
		ll sum = 0;
		for (int i = 0; i < N - 1;i++)sum += rw[i].first;
		if (rw[N - 1].first <= sum) {
			ll ans = 0; ans = sum + rw[N - 1].first;
			for (int i = 0;i < N;i++) ans += rw[i].second;
			cout << ans << endl;
		}
		else {
			vector<vector<ll>> dp(N, vector<ll>(rw[N - 1].first - sum + 1, 0));
			dp[0][0] = 1;
			ll max_impress = 0;
			for (int i = 0; i < N-1;i++) {
				for (int t = 0; t <= rw[N - 1].first - sum;t++) {
					if (dp[i][t] != 1) continue;
					dp[i + 1][t] = dp[i][t];
					if (t + rw[i].second <= rw[N - 1].first - sum) {
						dp[i + 1][t + rw[i].second] = 1;
						max_impress = max(max_impress, t + rw[i].second);
					}
				}
			}
			ll ans = 0; ans = sum + rw[N - 1].first;
			for (int i = 0;i < N;i++) ans += rw[i].second;
			ans += (rw[N - 1].first - sum - max_impress);
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3664
import bisect
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
sm=0
for j in B:
  sm+=bisect.bisect_left(A,j)*(n-bisect.bisect_right(C,j))
print(sm)
  

Measured memory_bytes: 107108
long bit[2<<17];
n,h[2<<17],a;
long sum(i)
{
	long ans=0;
	for(;i>0;i-=i&-i)ans=fmax(ans,bit[i]);
	return ans;
}
add(i,a)long a;
{
	for(;i<2<<17;i+=i&-i)bit[i]=fmax(bit[i],a);
}
i,j;
main()
{
	for(scanf("%d",&n);i<n;)scanf("%d",h+i++);
	for(;~scanf("%d",&a);j++)add(h[j],sum(h[j])+a);
	printf("%ld",sum(n));
}

Measured memory_bytes: 2560
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static boolean solve() {
		int sum = 0;
		int[] a = new int[4];
		for (int i=0; i<4; i++) {
			a[i] = in.nextInt();
			sum += a[i];
		}
		if (sum == 0) return false;

		Arrays.sort(a);

		do {
			for (int i=0; i<3; i++) {
				for (int j=0; j<3; j++) {
					for (int k=0; k<3; k++) {
						int ans = calc(a[0],a[1],i);
						ans = calc(ans,a[2],j);
						ans = calc(ans,a[3],k);
						if (ans == 10) {
							print(a,i,j,k);
							return true;
						}

						if (10 == calc(calc(a[0],a[1],i), calc(a[2],a[3],k), j)) {
							print2(a,i,j,k);
							return true;
						}
					}
				}
			}
		} while (nextPermutation(a));

		out.println(0);
		return true;
	}

	static boolean nextPermutation(int[] a) {
		int n = a.length, i, j;
		for (i=n-2; i>=0 && a[i]>=a[i+1]; i--);
		if (i == -1) return false;
		for (j=i+1; j<n && a[i]<a[j]; j++);
		int tmp = a[i]; a[i] = a[j-1]; a[j-1] = tmp;
		for (int l=i+1, r=n-1; l<r; l++,r--) {
			tmp = a[l]; a[l] = a[r]; a[r] = tmp;
		}
		return true;
	}

	static int calc(int a, int b, int o) {
		switch(o) {
			case 0: return a + b;
			case 1: return a - b;
			case 2: return a * b;
		}

		return -1;
	}

	static void print(int[] a, int i, int j, int k) {
		out.print("(((");
		out.print(a[0]+" ");
		out.print(i == 0 ? '+' : (i == 1 ? '-' : '*'));
		out.print(" "+a[1]+") ");
		out.print(j == 0 ? '+' : (j == 1 ? '-' : '*'));
		out.print(" "+a[2]+") ");
		out.print(k == 0 ? '+' : (k == 1 ? '-' : '*'));
		out.println(" "+a[3]+") ");
	}

	static void print2(int[] a, int i, int j, int k) {
		out.print("((" + a[0]+" ");
		out.print(i == 0 ? '+' : (i == 1 ? '-' : '*'));
		out.print(" "+a[1]+") ");
		out.print(j == 0 ? '+' : (j == 1 ? '-' : '*'));
		out.print(" ("+a[2]+" ");
		out.print(k == 0 ? '+' : (k == 1 ? '-' : '*'));
		out.println(" "+a[3]+"))");
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		while(solve());
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26588
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
	string name,nick;
	cin >> name;
	for(int i=0;i<3;i++){
		cout << name[i];
	}
	return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

const int N = 1e5 + 5;

bool valid[N];

int num[N] , n , m , x , y;

int main(void) {
	scanf("%d%d" , &n , &m); for(int i = 1;i <= n;i ++) num[i] = 1; valid[1] = 1;
	for(int i = 1;i <= m;i ++) {
		scanf("%d%d" , &x , &y);
		if(valid[x]) {
			valid[y] = 1;
		}
		num[x] --; num[y] ++;
		if(!num[x]) valid[x] = 0;
	}
	int ans = 0;
	for(int i = 1;i <= n;i ++) if(valid[i]) ans ++;
	cout << ans << endl;
}

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

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


int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i, s.size()) {
    if ('Z' - s.at(i) < n) {
      s.at(i) = n - 1 - 'Z' + s.at(i) + 'A';
    }
    else {
      s.at(i) = s.at(i) + n;
    }
    cout << char(s.at(i));
  }
  
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int M = 998244353;

inline int add(int a, int b)
{
    a += b;
    if (a >= M) a -= M;
    return a;
}

inline int mul(int a, int b)
{
    return (a * (ll) b) % M;
}

map <string, int> mem_dp;
map <string, int> mem_a;
map <string, int> mem_start_a;

int a(string s);
int start_a(string s);
int dp(string s);

string str_min(string a, string b)
{
    string s = "";
    for (int i = 0; i < (int) a.size(); i++)
    {
        if (a[i] == '0' || b[i] == '0') s += '0';
        else s += '1';
    }
    return s;
}

int a(string s)
{
    if (mem_a.count(s)) return mem_a[s];
    int n = (int) s.size();
    int ans = 0;
    for (int i = 1; i < n; i++)
    {
        if (n % i == 0)
        {
            string cur = s.substr(0, i);
            for (int j = i; j < n; j += i)
            {
                cur = str_min(cur, s.substr(j, i));
            }
            ans = add(ans, dp(cur));
        }
    }
    return mem_a[s] = ans;
}

int start_a(string s)
{
    if (mem_start_a.count(s)) return mem_start_a[s];
    int n = (int) s.size();
    int ans = 0;
    for (int i = 1; i < n; i++)
    {
        string p = s.substr(0, i);
        string q = s.substr(i);
        ans = add(ans, mul(a(p), dp(q)));
    }
    return mem_start_a[s] = add(ans, a(s));
}

int dp(string s)
{
    if (mem_dp.count(s)) return mem_dp[s];
    int n = (int) s.size();
    int ans = 0;
    int kek = 1;
    for (int i = 0; i < n; i++)
    {
        ans = add(ans, mul(kek, start_a(s.substr(i))));
        if (s[i] == '1')
        {
            kek = mul(kek, 2);
        }
    }
    return mem_dp[s] = add(ans, kek);
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    string s;
    cin >> s;
    cout << dp(s) << '\n';
}


Measured memory_bytes: 17664
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();

		int[] l = new int[n * 2];
		for (int i = 0; i < n * 2; i++) {
			l[i] = sc.nextInt();
		}

		Arrays.sort(l);

		int total = 0;
		for (int i = 0; i < n; i++) {
			total += l[i * 2];
		}

		out.println(total);
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 8020
l, r = map(int, input().split())

ans = 2019
for i in range(l, r):
   for j in range(l+1, r+1):
      tmp = i*j % 2019
      if ans > tmp:
         ans = tmp         
      if ans == 0:
         print(ans)
         exit(0)
         
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
using namespace std;
int n, i;
long long sum;
int v[100005];
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> v[i];
        sum += v[i];
    }
    sort(v + 1, v + n + 1);
    for(i = n - 1; i >= 1; i--){
        sum -= v[i + 1];
        if(2 * sum < v[i + 1]){
            break;
        }
    }
    cout<< n - i;
}


Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  sx,sy,tx,ty=LI()

  ans=''
  ans+='R'*(tx-sx)
  ans+='U'*(ty-sy)
  ans+='L'*(tx-sx)
  ans+='D'*(ty-sy)

  ans+='D'
  ans+='R'*(tx-sx+1)
  ans+='U'*(ty-sy+1)
  ans+='L'
  ans+='U'
  ans+='L'*(tx-sx+1)
  ans+='D'*(ty-sy+1)
  ans+='R'

  return ans

print(main())


Measured memory_bytes: 7820
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define o(x)		  cout << x << endl;
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	//cin >> t;
	while (t--) {
		string str, t;
		cin >> str >> t;

		ll count = 0;
		forn(i, 0, t.size()) {
			if (str[i] != t[i])
				count++;

		}

		o(count)
	}
	CLOCK
	return 0;
}



Measured memory_bytes: 3932