akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int a[maxn],f[maxn],len=0;
int main(){
	int n=read();
	for(register int i=1;i<=n;i++)a[i]=read();
	f[++len]=a[1];
	for(register int i=2;i<=n;i++){
		if(a[i]>f[1])f[1]=a[i];
		else{
			if(a[i]<=f[len])f[++len]=a[i];
			else {
				int l=1,r=len,ans;
				while(l<=r){
					int mid=(l+r)>>1;
					if(f[mid]>=a[i])l=mid+1;
					else r=mid-1;
				}	
				f[l]=a[i];
			}
		}
	}
	printf("%d\n",len);
	return 0;
}

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

class Main {

    public static void main( String[] args ) {

	Scanner stdin = new Scanner(System.in);

	while ( true ) {
	    int[] size = new int[3];
	    size[0] = stdin.nextInt();
	    size[1] = stdin.nextInt();
	    size[2] = stdin.nextInt();

	    if ( size[0] == 0 && size[1] == 0 && size[2] == 0 ) {
		break;
	    }

	    Arrays.sort( size );
	    
	    int n = stdin.nextInt();
	    for ( int i = 0; i < n; i++ ) {
		int r = stdin.nextInt();
		
		if ( size[0] * size[0] + size[1] * size[1] < r * r * 4 ) {
		    System.out.println( "OK" );
		} else {
		    System.out.println( "NA" );
		}
	    }
	    
	}
	
    }
    
}

Measured memory_bytes: 17200
from itertools import product

N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = [int(i) for i in input().split()]

ans = 0
for t in product([0, 1], repeat=N):
    flag = 0
    j = 0
    for ks_j in ks:
        trial = 0
        for s_i in ks_j[1:]:
            trial += t[s_i-1]
        trial += p[j]
        if trial % 2 != 0:
            flag = 1
            break
        j += 1
    if flag == 0:
        ans += 1
print(ans)

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

using namespace std ;

int N ; 
int K ; 
long long int INF = 1000000000LL + 10LL ; 
long long int dp[100009] ; 
long long int H[100009]  ; 

long long int iabs(long long int a){
	if(a<0LL)return (a*-1LL) ; 
	return a ;  
}
long long minVal(long long a, long long b){
	if(a>b) return b ; 
	return a ; 
}

long long go(int cur)
{
	//if(cur < 0 ) return INF ; 
	long long int& ret = dp[cur]; 
	if(ret != -1LL) return ret ;
	if(cur==0) return ret = 0LL ; 
	ret = INF ; 
	for(int i = 1 ; i <= K; ++i)
	{
		if(cur-i < 0) break ; 
		ret = minVal(ret, go(cur-i)+iabs(H[cur]-H[cur-i])) ; 
	}
	//if(cur>0)ret = minVal(ret, go(cur-1)+iabs(H[cur]-H[cur-1])); 
	//if(cur>1) ret = minVal(ret, go(cur-2)+iabs(H[cur]-H[cur-2])) ; 
	return ret ;
}

int main()
{
	scanf("%d %d",&N, &K);
	//vector< int > H(N) ; 
	for(int i = 0 ; i < N ; ++i){
		scanf("%lld",&H[i]);
		dp[i]=-1LL; 
	}
	dp[N] = -1LL ; 
	//vector< int > dp(N+3, -1); 

	long long tmp = go(N-1) ; 

	assert(tmp != INF) ; 

	cout << tmp << "\n" ; 
	

	//cout << "Hello World\n" ; 
	return 0 ; 
}

Measured memory_bytes: 6528
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
        rep(i,n) cin>>a.at(i);
    in ans=0;
    if(a[0]>k){
        ans +=a[0]-k;
        a[0]=k;
    }
    rep(i,n-1){
        if(a[i]+a[i+1]<=k) continue;
        ans +=a[i]+a[i+1]-k;
        a[i+1] -=a[i]+a[i+1]-k;
    }
    cout<<ans<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> grid(h, vector<int>(w, 1));
  rep(i, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      rep(i, x) rep(j, h)
        grid[j][i] = 0;
    }
    if (a == 2) {
      for (int i = x; i < w; i++) rep(j, h)
        grid[j][i] = 0;
    }
    if (a == 3) {
      rep(i, w) rep(j, y)
        grid[j][i] = 0;
    }
    if (a == 4) {
      rep(i, w) for (int j = y; j < h; j++)
        grid[j][i] = 0;
    }
  }
  int ans = 0;
  rep(i, w) rep(j, h)
    ans += grid[j][i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,cat;
  cin >> a >> b;
  cat = a*pow(10,floor(log10(b))+1)+b;
  if(cat == pow((int)sqrt(cat), 2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

int N, M;
double L[22], a[22], b[22];

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

  for (int i = 0; i < N; i++) cin >> L[i] >> a[i] >> b[i];

  double res = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int cnt = 0;
    bool ok[22] = {false};
    for (int k = 0; k < N; k++) {
      if (bit >> k & 1) {
        ok[k] = true;
        cnt++;
      }
    }
    if (cnt != M) continue;

    double dist = 0;
    for (int i = 0; i < N - 1; i++) {
      if (!ok[i]) continue;
      for (int j = i + 1; j < N; j++) {
        if (!ok[j]) continue;
        dist += (L[i] - L[j]) * (L[i] - L[j]) + (a[i] - a[j]) * (a[i] - a[j]) +
                (b[i] - b[j]) * (b[i] - b[j]);
      }
    }

    res = max(res, dist);
  }

  printf("%.8f\n", res);

  return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int n,m,k;
int main()
{
    cin>>n>>m>>k;
    if(n<m) swap(n,m);
    int ans=0;
    while(k>0)
    {
        k-=n;
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappop

readline = sys.stdin.readline


def solve():
    N = int(readline())

    left = []
    right = []
    ans = 0
    for _ in range(N):
        K, L, R = map(int, readline().split())
        if L > R:
            ans += R
            left.append((K - 1, R - L))
        else:
            ans += L
            right.append((N - K - 1, L - R))

    for vec in (left, right):
        vec.sort()
        hq = []
        for idx in range(len(vec) - 1, -1, -1):
            while vec and idx <= vec[-1][0]:
                heappush(hq, vec.pop()[1])
            if hq:
                ans -= heappop(hq)

    return ans


def main():
    T = int(readline())

    ans = [0] * T
    for i in range(T):
        ans[i] = solve()

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 94092
#pragma comment(linker, "/STACK:66777216")
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<bitset>
#include<ctime>
using namespace std;
using ll = long long;

void Solve() {
	int N;
	scanf("%d", &N);
	vector<int> L(2*N);
	for (int i = 0; i < 2*N; i++)
		scanf("%d", &L[i]);
	sort(L.begin(), L.end());
	int sum = 0;
	for (int i = 0; i < 2*N; i+=2)
		sum += min(L[i], L[i + 1]);
	printf("%d", sum);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	Solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << endl;
#endif

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e12;
const ll MOD = 1000000000 + 7;
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define mii map<int, int>
#define mci map<char, int>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  ll n, m;
  cin >> n >> m;
  if (abs(n - m) > 1)
    out(0);
  else {
    ll x = 1, y = 1;
    int b_n = n, b_m = m;
    while (n > 1) x = (x * n) % MOD, n--;
    while (m > 1) y = (y * m) % MOD, m--;
    if (b_n == b_m)
      out((2 * x * y) % MOD);
    else
      out((x * y) % MOD);
  }
}

int main(void) { solve(); }

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll key_bit[1005]={0},cost[1005]={0};
ll dp[8192][1005]={0};
int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<8192;i++){
    for(int j=0;j<1005;j++) dp[i][j]=174417441744;
  }
  dp[0][0]=0;
  for(int i=1;i<=m;i++){
    ll b;
    cin>>cost[i]>>b;
    for(int j=0;j<b;j++){
      ll c;
      cin>>c;
      c--;
      key_bit[i]+=(1<<c);
    }
  }
  for(ll i=0;i<(1<<n);i++){
    for(int j=0;j<m;j++){
      dp[i][j+1]=min(dp[i][j],dp[i][j+1]);
      dp[i|key_bit[j+1]][j+1]=min(dp[i|key_bit[j+1]][j+1],dp[i][j]+cost[j+1]);
    }
  }
  cout<<(dp[(1<<n)-1][m]==174417441744?-1:dp[(1<<n)-1][m])<<endl;
}


Measured memory_bytes: 64640
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;
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<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int A,B,C; cin >> A >> B >> C;
    string res = "NO";
    rep(i,A*B){
        if(i*A%B==C) res = "YES";
    }
    pr(res);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

double dist(pair<double,double> a, pair<double,double> b) {
    double ax,ay,bx,by;
    tie(ax,ay)=a;
    tie(bx,by)=b;
    return sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
}

int main() {
    int n;
    cin>>n;
    vector<pair<double,double>> vec(n);
    rep(i,n) {
        double x,y;
        cin>>x>>y;
        vec[i]=make_pair(x,y);
    }
    
    vector<int> perm;
    rep(i,n) perm.push_back(i);
    double ans=0;
    do {
        rep(i,n-1) {
            ans+=dist(vec[perm[i]],vec[perm[i+1]]);
        }
    } while(next_permutation(all(perm)));
    
    double bunshi=1;
    rep(i,n) bunshi*=(i+1);
    cout<<fixed<<setprecision(10)<<ans/bunshi<<endl;
}


Measured memory_bytes: 256
from operator import itemgetter
import sys

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

for i in range(n):
    ab.append(list(map(int,input().split())))
ab.sort(key=itemgetter(1))

total = 0
# flag = True 
for aabb in ab:
    total += aabb[0] 
    if total > aabb[1]:
        print("No")
        sys.exit()
        break

print("Yes")

Measured memory_bytes: 53720
#!/usr/bin/env python3

def main():
    line = input()
    (sA, sB, sC, sD) = line.split()
    A = int(sA)
    B = int(sB)
    C = int(sC)
    D = int(sD)
    area1 = A * B
    area2 = C * D
    if area1 > area2:
        answer = area1
    else:
        answer = area2
    print(answer)

main()


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import numpy as np
from collections import Counter
N = input()
t = np.array(map(int, raw_input().split()))

odd = t[0::2]
even = t[1::2]
rest = 0

co = Counter(odd)
ce = Counter(even)

omc = co.most_common()
emc = ce.most_common()

if omc[0][0] == emc[0][0]:
    if len(omc) < 2 and len(emc) < 2:       # same
        rest = len(even)
    elif len(omc) < 2:
        rest = len(even)
    elif len(emc) < 2:
        rest = len(odd)
    else:
        or1 = len(odd) - co.most_common()[0][1]
        or2 = len(odd) - co.most_common()[1][1]
        er1 = len(even) - ce.most_common()[0][1]
        er2 = len(even) - ce.most_common()[1][1]

        if or1 + er2 > or2 + er1:
            rest = or2 + er1
        else:
            rest = or1 + er2
else:
    rest = len(odd) - co.most_common()[0][1] + len(even) - ce.most_common()[0][1]


print rest



Measured memory_bytes: 35548
#include <stdio.h>

int field[1000][1000];
int count[1000][1000];

void set_count(int h, int w, int n);
void walk(int h, int w, int *y, int *x);

int main()
{
	while (1) {
		int h, w, n;
		int i, x, y;
		scanf("%d %d %d", &h, &w, &n);
		if (h == 0 && w == 0 && n == 0) {
			break;
		}
		for (y = 0; y < h; y++) {
			for (x = 0; x < w; x++) {
				scanf("%d", &field[y][x]);
			}
		}
		set_count(h, w, n);
		walk(h, w, &y, &x);
		printf("%d %d\n", y+1, x+1);
	}
	return 0;
}

void set_count(int h, int w, int n)
{
	int x, y;
	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			if (y == 0 && x == 0) {
				count[y][x] = n - 1;
			} else {
				int from_north, from_west;

				if (y == 0) {
					from_north = 0;
				} else {
					from_north = count[y-1][x] / 2;
					if (count[y-1][x] % 2 == 1 && field[y-1][x] == 0) {
						from_north += 1;
					}
				}

				if (x == 0) {
					from_west = 0;
				} else {
					from_west = count[y][x-1] / 2;
					if (count[y][x-1] % 2 == 1 && field[y][x-1] == 1) {
						from_west += 1;
					}
				}
				
				count[y][x] = from_north + from_west;
			}
		}
	}
}

void walk(int h, int w, int *y, int *x)
{
	*y = 0;
	*x = 0;
	while (*y < h && *x < w) {
		int d;
		d = (field[*y][*x] + count[*y][*x]) % 2;
		if (d == 0) {
			*y += 1;
		} else if (d == 1) {
			*x += 1;
		}
	}
}

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

string s;

bool reve(int st, int gl)
{
    for (int i = st; i < gl / 2; i++)
    {
        if (s[i] != s[gl - i-1])
            return false;
    }
    return true;
}

int main(void)
{
    cin >> s;

    int n = s.length();
    string ans = "No";

    if (reve(0, n))
        if (reve(0, (n - 1) / 2))
            if (reve((n + 3 / 2) - 1, n))
                ans = "Yes";

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


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

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

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;

using namespace std;

vector<int> cnt(200000);
vector<int> sum(200000);
vector<int> visited(200000);
vector<vector<int>> graph(200000);

void dfs(int now, int add){
  visited[now] = 1;
  add += cnt[now];
  sum[now] = add;
  for(auto e:graph[now]){
    if(visited[e]) continue;
    dfs(e, add);
  }
}

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

  int a, b;
  REP(i, N-1){
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int p, x;
  REP(i, Q){
    cin >> p >> x;
    cnt[p-1] += x;
  }
  dfs(0, 0);

  REP(i, N){
    cout << sum[i];
    SPBR(i, N);
  }

  return 0;
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n;i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b;i++)
#define repv(x, arr) for (auto& x:arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a,b) make_pair(a,b)
#define op(i) cout << (i) << endl;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

const ll mod = 1e9 + 7;



int main(){
    string S;
    cin >> S;
    int N = S.size();
    ll ans = 0;
    rep(i,pow(2,N-1)){
        //cout << ans << endl;
        ll now = i;
        ll tanni = 1;
        ll res = 0;
        rep(j,N){
            res += (S[N-j-1]-'0') * tanni;
            if(now%2==1){
                tanni = 1;
            }
            else{
                tanni *= 10;
            }
            now /= 2;
        }
        ans += res;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll dsum(ll x){
	ll ret = 0ll;
	while(x){
		ret += (x%10);
		x /= 10;
	}
	return ret;
}

int main(void){
	int i,n,ans=0;
	ll a,m,y,x;
	bool flag;
	cin >> a >> n >> m;
	for(y=1ll; y<=10000ll; ++y){
		flag = true; x = 1ll;
		for(i=0; i<n; ++i){
			x *= (y+a);
			if(x>m){
				flag = false;
				break;
			}
		}
		if(!flag){
			continue;
		}
		if(dsum(x)==y){
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3116
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	line := nextLine()

	cols := strings.Split(line, " ")

	nums := []int{}

	for _, s := range cols {
		n, _ := strconv.Atoi(s)
		nums = append(nums, n)
	}

	num := nums[0] + nums[1]

	if num%2 == 0 {
		fmt.Println(num / 2)
	} else {
		fmt.Println(num/2 + 1)
	}

}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline


def read():
    X = int(input().strip())
    return X,


def solve(X):
    if X >= 30:
        return "Yes"
    else:
        return "No"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9164
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];
  vector<vector<int>> dp(101, vector<int>(100005, INF));
  dp[0][0] = 0;
  rep(i, N) {
    rep(j, 100005) {
      cmin(dp[i + 1][j], dp[i][j]);
      if (100001 < j + v[i]) continue;
      cmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
    }
  }
  int ans = 0;
  rep(i, 100005) if (dp[N][i] <= W) cmax(ans, i);
  cout << ans << endl;

  return 0;
}


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

const int mod=1e9+7;
long a[2010];
int main()
{
    long n, k; cin>>n>>k;
    for(int i=0; i<n; ++i) cin>>a[i];
    long res=0;
    for(int i=0; i<n; ++i) {
        for(int j=i+1; j<n; ++j)
            if (a[i]>a[j]) (res+=k*(k+1)/2)%=mod;
        for(int j=0; j<i; ++j)
            if (a[i]>a[j]) (res+=k*(k-1)/2)%=mod;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long n; cin >> n;
    long cnt = 0;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin >> v[i];
    sort(v.begin(), v.end());
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(v[i] + v[j] > v[k])cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int a=gi();
	    int b=gi();
	    int c=gi();

	   
	    System.out.print(Math.max(c-(a-b), 0));

//        if ((x.charAt(0)==x.charAt(1) && x.charAt(2)==x.charAt(3) && x.charAt(0)!=x.charAt(2))
//        || (x.charAt(0)==x.charAt(2) && x.charAt(1)==x.charAt(3) && x.charAt(0)!=x.charAt(1))
//        || (x.charAt(0)==x.charAt(3) && x.charAt(2)==x.charAt(1) && x.charAt(0)!=x.charAt(2))) {
//        	System.out.print("Yes");
//        }else {
//        	System.out.print("No");
//        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35684
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(r, d, x) = sc.nextLine.split(" ").map(_.toInt)
    (1 to 10).scanLeft(x){
      (n, _) => r * n - d
    }.slice(1, 11).foreach(println)
  }
}


Measured memory_bytes: 26012
#include <stdio.h>
int n,b,f,r,v,i,j,k;
int A[3][10],B[3][10],C[3][10],D[3][10];
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %d %d %d %d",&b,&f,&r,&v);
    if(b==1){
      A[f-1][r-1]+=v;
    } else if(b==2){
      B[f-1][r-1]+=v;
    } else if(b==3){
      C[f-1][r-1]+=v;
    } else if(b==4){
      D[f-1][r-1]+=v;
    }
  }
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
        if(i==0){
          printf(" %d",A[j][k]);
        } else if(i==1){
          printf(" %d",B[j][k]);
        } else if(i==2){
          printf(" %d",C[j][k]);
        }
      }
      printf("\n");
    }
    printf("####################\n");
  }
  for(j=0;j<3;j++){
    for(k=0;k<10;k++){
      printf(" %d",D[j][k]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2704
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int m,f,r;
        int sum;
        while(true){
            m=sc.nextInt();
            f=sc.nextInt();
            r=sc.nextInt();
            if(m==-1&&f==-1&&r==-1)break;
            
            if(m==-1||f==-1)System.out.println("F");
            else{
                sum=m+f;
                if(sum>=80)System.out.println("A");
                else if(sum>=65)System.out.println("B");
                else if(sum>=50)System.out.println("C");
                else if(sum>=30){
                    if(r>=50)System.out.println("C");
                    else System.out.println("D");
                }
                else System.out.println("F");
            }
        }
    }
}



Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;

int main()
{

    int h, a;
    cin >> h >> a;
    int ans = (h + a - 1) / a;
    Cout(ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n;
	cin >> n;
	string s[n];
	ll t[n];
	for(ll i=0;i<n;i++)
	{
		cin >> s[i];
		cin >> t[i];
	}
	string s1;
	cin >> s1;
	ll br=0;
	for(ll i=0;i<n;i++)
	{
		if(s[i]==s1)
		{
			br=i+1;
			break;
		}
	}
	ll ans=0;
	for(ll i=br;i<n;i++)
	{
		ans+=t[i];
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a, b, c, karisu;

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

	if(a > b)
	{
		karisu = a;
		a = b;
		b = karisu;
	}

	if(a > c)
	{
		karisu = a;
		a = c;
		c = karisu;
	}

	if(b > c)
	{
		karisu = b;
		b = c;
		c = karisu;
	}

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

	return 0;
}

Measured memory_bytes: 596
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i])
	}

	ans := 1000000
	for i := 0; i <= 100; i++ {
		tmp := 0
		for _, x := range v {
			tmp += (x - i) * (x - i)
		}
		if tmp < ans {
			ans = tmp
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int n = Input.ScanInt();
          long[] A = Input.ScanLongArray();
          long[] rain = new long[n];
          
          rain[0] = Math.Min(A[0],A[n-1]);
          
          for(int i=1;i<n;i++){
              rain[i] = A[i-1] - rain[i-1];
          }
          
          long z = A[n-1] - (rain[0] + rain[n-1]);
          
          Console.Write($"{2*rain[0] + z}");
          int sgn = -1;
          for(int i=1;i<n;i++, sgn*=-1){
            Console.Write($" {2*rain[i] + (z*sgn)}");
          }
        }
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

    static class MyMath {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 31060
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int A, B;
  cin >> A >> B;

  int x1 = ceil((float)A / 0.08);
  int x2 = ceil((float)(A + 1) / 0.08) - 1;
  int y1 = B / 0.1;
  int y2 = (B + 1) / 0.1 - 1;

  for (int i = x1; i <= x2; ++i) {
    if (i >= y1 && i <= y2) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

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

int op(int a, int b) {
	return max(a, b);
}
int e() {
	return -1;
}

int main() {
	cin.tie(nullptr); ios_base::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	segtree<int, op, e> st(a);
	for (int i = 0; i < q; ++i) {
		int t, x, y; cin >> t >> x >> y;
		if (t == 1) st.set(x-1, y);
		else if (t == 2) cout << st.prod(x-1, y) << "\n";
		else cout << st.max_right(x-1, [&y](int z) {return z < y;}) + 1 << "\n";
	}
	return 0;
}

Measured memory_bytes: 6056
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  vector<int> z;
  vector<int> x;
  char tmp = '1';
  map<int, int> mp;
  int cnt = 0;
  rep(i,n) {
    if(tmp == '1' && s[i] == '0') {
      z.push_back(i);
      tmp = '0';
    } else if (tmp == '0' && s[i] == '1') {
      tmp = '1';
      x.push_back(i);
    }
  }
  if(s[n-1] == '0') {
    x.push_back(n);
  }
  int ans = 0;
  if(z.size() <= k) {
    ans = n;
    cout << ans << endl;
    return 0;
  }
  int prev = -1;
  z.push_back(n);
  rep(i, z.size()-k) {
    int l;
    if(prev == -1) {
      l = z[i+k] - prev - 1;
    } else {
      l = z[i+k] - x[i-1];
    }
    // debug(z[i]);
    // debug(x[i-1]);
    // debug(l);
    ans = max(l, ans);
    prev = z[i];
  }
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 1024
//n奇数：奇数回目：前、偶数回目：後ろ
//n偶数：奇数回目：後ろ、偶数回目：前
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  deque<int> que;
  if(n%2!=0){
    rep(i, n){
      int num;
      cin >> num;
      if(i%2==0){
        que.push_front(num);
      }else{
        que.push_back(num);
      }
    }
  }else{
    rep(i, n){
      int num;
      cin >> num;
      if(i%2==0){
        que.push_back(num);
      }else{
        que.push_front(num);
      }
    }
  }
  for(auto p : que){
    cout << p << " ";
  }
  return 0;
}

Measured memory_bytes: 4472
#include<iostream>

int main(){
	int n;
	std::cin >> n;
	
	if(n>=10){
		n = n - (n/10)*10;
	}
	
	if(n == 3){
		std::cout << "bon" << std::endl;
	}else if(n==0 || n==1 || n==6 || n==8){
		std::cout << "pon" << std::endl;
	}else{
		std::cout << "hon" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> a(N + 1, 0);
    vector<int> flg(N + 1, 1);
    REP(i, M)
    {
        int p;
        cin >> p;
        flg[p] = 0;
    }
    a[0] = 1;
    a[1] = flg[1] ? 1 : 0;
    REPS(i, N)
    {
        if (flg[i] == 1)
        {
            a[i] = (a[i - 1] + a[i - 2]) % MOD;
        }
    }
    cout << a[N] << "\n";
}


Measured memory_bytes: 1024
// Pana2020 A
// 2020.3.14 bal4u

#include <stdio.h>

int a[35] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2,
 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
	int K;

	scanf("%d", &K);
	printf("%d\n", a[K-1]);
	return 0;
}


Measured memory_bytes: 128
s=list(input())
n=len(s)
zenhan=s[0:int((n-1)/2)]
kouhan=s[int((n+3)/2-1):n]
if s==s[::-1] and zenhan==zenhan[::-1] and kouhan==kouhan[::-1]:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var result = 0L;
        var sum = new int[str.Length + 1];
        sum[str.Length] = 0;
        for(var i = str.Length-1; i >=0; i--)
        {
            if (str[i] == 'W') sum[i] = sum[i + 1] + 1;
            else sum[i] = sum[i + 1];
        }
        for(var i = 0; i < str.Length; i++)
        {
            if (str[i] == 'B') result += sum[i];
        }
        WriteLine(result);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 12512
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int huiwen(int s)
{
    int d=0;
    while(s)
    {
        d=d*10+s%10;
        s=s/10;
    }
    return d;
}
int main()
{
    int a,b,sum=0;
    scanf("%d%d",&a,&b);
    for(int i=a;i<=b;i++)
    {
        int q=huiwen(i);
        if(i==q)
          sum++;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N,T=map(int,input().split())
A=list(map(int,input().split()))

buy=10**9
buy_loc=[]
benefit=0
for index,item in enumerate(A):
    if buy>item:
        buy=item
        buy_loc.append(index)
    benefit=max(item-buy,benefit)

buy_loc.append(10**6)
buy_loc=buy_loc[::-1]

ans=0
buy_count=0
sell_count=0
for i in range(len(A)):
    if i==buy_loc[-1]:
        buy_loc.pop(-1)
        buy=A[i]
        #print(buy_count,sell_count)
        ans+=min(buy_count,sell_count)
        buy_count=0
        sell_count=0
    if A[i]==buy:
        buy_count+=1
    if A[i]-buy==benefit:
        sell_count+=1

ans+=min(buy_count,sell_count)
print(ans)
#print(benefit)
#print(buy_loc)

Measured memory_bytes: 15060
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;

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

  vector<int> bucket(26,0);
  for(int i=0; i<s.size(); i++){
    bucket[s.at(i) - 97] += 1;
  }

  int min = 99999;
  char ans = 97;
  for(int i=0; i<26; i++){
    if( min > bucket.at(i) && bucket.at(i) == 0 ){
      min = bucket.at(i);
      ans = 97 + i;
    }
  }
  if(min == 99999){
    cout << "None";
  }else{
    cout << ans;
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> heights;
	vector<int> score;
	score.push_back(0);
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		heights.push_back(a);
	}
	if(heights.size() <= 3){
		if(n == 2){
			cout << heights[1] - heights[0] << endl;	
		}
		else{
			cout << heights[2] - heights[0] << endl;
		}
		
	}
	else{
		score.push_back(abs(heights[1] - heights[0]));
		score.push_back(abs(heights[2] - heights[0]));
		for(int i=3; i<n; i++){
			if((score[score.size() - 1] + abs(heights[i] - heights[i - 1])) <= (score[score.size() - 2] + abs(heights[i] - heights[i - 2]))){
				score.push_back(score[score.size() - 1] + abs(heights[i] - heights[i - 1]));
				//cout << score[score.size() - 1] << endl;
			}
			else{
				score.push_back(score[score.size() - 2] + abs(heights[i] - heights[i - 2]));
			}
		}
		// for(int i=0; i<score.size(); i++){
		// 	cout << score[i] << endl;
		// }
		cout << score[score.size() - 1] << endl;		
	}
	return(0);
}

Measured memory_bytes: 1400
import std.functional, std.algorithm, std.container, std.typetuple,
  std.typecons, std.bigint, std.string, std.traits, std.array, std.range, std.stdio, std.conv;

enum INF = (1 << 30);
alias Edge = Tuple!(long, "dst", long, "cost");

long[] dijkstra(in Edge[][] tree, long start) {
  alias PriorityQueue = BinaryHeap;
  alias tie = TypeTuple;

  size_t V = tree.length;
  auto dist = new long[V];
  fill(dist, INF);

  auto queue = new PriorityQueue!(Array!Edge, "a.cost >= b.cost")();

  dist[start] = 0;
  queue.insert(Edge(start, 0));
  while (!queue.empty()) {
    long v;
    long cost;
    tie!(v, cost) = queue.front();
    queue.popFront();

    if (dist[v] < cost) {
      continue;
    }
    foreach (const ref Edge e; tree[v]) {
      if (dist[v] + e.cost < dist[e.dst]) {
        dist[e.dst] = dist[v] + e.cost;
        queue.insert(Edge(e.dst, dist[e.dst]));
      }
    }
  }

  return dist;
}

enum M = INF;

string disp(long[] arr) {
  return arr.map!(x => x == M ? "M" : x.to!string).join(" ");
}

void main() {
  int[] VEr = readln.chomp.split.to!(int[]);
  int V = VEr[0], E = VEr[1], r = VEr[2];
 
  auto tree = new Edge[][](V, 0);
  foreach (_; 0 .. E) {
    int[] _std = readln.chomp.split.to!(int[]);
    int s = _std[0], t = _std[1], d = _std[2];
    tree[s] ~= Edge(t, d);
  }

  long[] ret = dijkstra(tree, r);

  foreach (i; 0 .. V) {
    long d = ret[i];
    if (d >= INF) {
      writeln("INF");
    } else {
      writeln(d);
    }
  }
}



Measured memory_bytes: 55564
#include<bits/stdc++.h>
using namespace std;
 
int main()
{

int n;
string s;
cin>>n;
cin>>s;


char t = s[0];
int x=1;
for(int i=1;i<n;i++)
{
    if(s[i]!=t)
    {
        t=s[i];
        x++;
    }
}
cout<<x;

}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=1;i<N;i++){
        int v=A[i];
        int j=i-1;
        for(int k=0;k<N-1;k++){
            cout<<A[k]<<" ";
        }cout<<A[N-1]<<endl;
        
        while(j>=0 && A[j]>v){
            int B=A[j+1];
            A[j+1]=A[j];
            A[j]=B;
            j--;
        }
        A[j+1]=v;
    }
    for(int i=0;i<N-1;i++){
        cout<<A[i]<<" ";
    }cout<<A[N-1]<<endl;
    return 0;
}



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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N, M;
int graph[100][100];
int dig[100];
vector<int> use;
int calc(int depth, int need){
  if(use.size() == need) {
    int ret = 0;
    REP(i, need) {
      int minf = INF;
      REP(j, need) if(i != j) minf = min(minf, graph[use[i]][use[j]]);
      ret += minf;
    }
    return ret;
  }
  if(depth == N) return 0;
  int ret = calc(depth + 1, need);
  if(dig[depth] >= need - 1){
    FORIT(it, use) if(graph[*it][depth] == 0) return ret;
    use.push_back(depth);
    ret = max(ret, calc(depth + 1, need));
    use.pop_back();
  }
  return ret;
}

int main(){
  while(cin >> N >> M && N){
    REP(i, M){
      int u, v, f;
      cin >> u >> v >> f;
      u--; v--;
      graph[u][v] = graph[v][u] = f;
      dig[u]++; dig[v]++;
    }
    int ans = 0;
    for(int d = 2; d <= 15; d++){
      ans = max(ans, calc(0, d));
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1256
zipAdj :: [a] -> [(a, a)]
zipAdj x = zip x $ tail x

count :: Eq a => a -> [a] -> Int
count y (x:[]) = if x == y then 1 else 0
count y (x:xs) = (if x == y then 1 else 0) + (count y xs)

main = do
    n <- readLn :: IO Int
    w <- sequence (replicate n $ getLine)
    let rule1 = all (\(w1, w2) -> (last w1) == (head w2)) (zipAdj w)
    let rule2 = all (\word -> count word w == 1) w
    putStrLn $ if rule1 && rule2 then "Yes" else "No"

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 3005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

ldouble dp[SIZE][SIZE];

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

    int N;
    cin >> N;

    vector<ldouble> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
    }

    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= i + 1; ++j) {
            if(i == 0) {
                if(j == 0) {
                    dp[i][j] = 1.0 - v[i];
                } else {
                    dp[i][j] = v[i];
                }
            } else {
                dp[i][j] = dp[i - 1][j] * (1.0 - v[i]);
                if(j > 0) {
                    dp[i][j] += dp[i - 1][j - 1] * v[i];
                }
            }
        }
    }

    ldouble res = 0;
    for(int i = N / 2 + 1; i <= N; ++i) {
        res += dp[N - 1][i];
    }
    printf("%.10Lf\n", res);
    return 0;
}



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

void print_num_bombs(vector <vector<int>> s) {
    int h = s.size();
    int w = s.at(0).size();
    for (int i = 1; i < h-1; i++) {
        for (int j = 1; j < w-1; j++) {
            if (s.at(i).at(j) == 0) {
                int nb = s.at(i-1).at(j-1) +
                    s.at(i-1).at(j) +
                    s.at(i-1).at(j+1) +
                    s.at(i).at(j-1) +
                    s.at(i).at(j+1) +
                    s.at(i+1).at(j-1) +
                    s.at(i+1).at(j) +
                    s.at(i+1).at(j+1);
                cout << nb;
            } else cout << "#";
        }
        cout << endl;
    }
}

int main() {
    int h, w;
    char tmp;
    cin >> h >> w;
    vector <vector<int>> s(h+2, vector<int>(w+2));

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> tmp;
            if (tmp == '#') s[i+1][j+1] = 1;
            else s[i+1][j+1] = 0;
        }
    }
    print_num_bombs(s);

    return 0;
}


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

const int NMAX = 1123;
const int MMAX = 212345;

std::vector<int> g[NMAX];
std::deque<int> deq;
std::vector<int> ans;
bool vis[NMAX];
int anssize = NMAX;

void dfs1(int cur) {
  vis[cur] = true;
  deq.push_back(cur);
  for (int dst : g[cur]) {
    if (dst == deq.at(0)) {
      if (anssize > deq.size()) {
	anssize = deq.size();
      }
    } else {
      if (vis[dst]) continue;
      dfs1(dst);
    }
  }
  deq.pop_back();
  return;
}

void dfs2(int cur) {
  vis[cur] = true;
  deq.push_back(cur);
  for (int dst : g[cur]) {
    if (dst == deq.at(0)) {
      if (anssize == deq.size()) {
	ans.resize(anssize);
	for (int i = 0; i < anssize; ++i) ans[i] = deq[i];
      }
    } else {
      if (vis[dst]) continue;
      dfs2(dst);
    }
  }
  deq.pop_back();
  return;
}

int main() {
  int N, M;
  std::cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0;j < N; ++j) vis[j] = false;
    dfs1(i);
  }
  if (anssize == NMAX) {
    std::cout << "-1" << std::endl;
  } else {
    for (int i = 0; ans.empty() && i < N; ++i) {
      for (int j = 0;j < N; ++j) vis[j] = false;
      dfs2(i);
    }    
    std::cout << ans.size() << std::endl;
    while (!ans.empty()) {
      std::cout << (ans.back() + 1) << std::endl;
      ans.pop_back();
    }
  }
}


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


using namespace std;

int main(){

  int s;

  cin >> s;
  cin.ignore();

  // 月: 1〜12
  // 年: 任意 ただし0以外

  int low = s % 100;
  bool lowmonth = false;
  if ((1 <= low) && (low <= 12)){
    lowmonth = true;
  }

  int high = s / 100;
  bool highmonth = false;
  if ((1 <= high) && (high <= 12)){
    highmonth = true;
  }

  if (lowmonth & highmonth){
    cout << "AMBIGUOUS" << endl;
  } else if(lowmonth){
    cout << "YYMM" << endl;
  } else if(highmonth) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}
  


Measured memory_bytes: 256