akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
string = input()
count = 0
max_count = 0
for s in string:
    if s == 'R':
        count += 1
    else:
        if count > max_count:
            max_count = count
        count = 0

    if count > max_count:
            max_count = count

print(max_count)

Measured memory_bytes: 8972
#include <bits/stdc++.h>
using namespace std;
const int maxn = 888;
int w, h, k, ans = maxn;
int sx, sy;
char s[maxn][maxn];
int step[maxn][maxn];
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
struct Item {
    int x, y;
};
vector<Item> reach;
int cal (int x) {
    if (x == 0) return 0;
    else return (x-1)/k+1;
}
int main () {
    scanf ("%d%d%d", &w, &h, &k);
    memset (step, -1, sizeof (step));
    for (int i = 1; i <= w; i++) {
        //printf ("%d\n", i);
        scanf ("%s", s[i]+1);
    }
    for (int i = 1; i <= w; i++) for (int j = 1; j <= h; j++) {
        //printf ("%c", s[i][j]);
        if (s[i][j]=='S') {
            sx = i; sy = j;
        }
    }
    step[sx][sy] = 0;
    queue<Item> q;
    q.push ({sx, sy});
    while (!q.empty()) {
        Item u = q.front(); q.pop();
        //printf ("%d %d\n", u.x, u.y);
        reach.push_back ({u.x, u.y});
        if (step[u.x][u.y] == k) continue;
        for (int i = 0; i < 4; i++) {
            int nx = u.x + dx[i], ny = u.y + dy[i];
            if (step[nx][ny] == -1 && s[nx][ny] == '.') {
                step[nx][ny] = step[u.x][u.y]+1;
                q.push ({nx, ny});
            }
        }
    }
    //printf ("%d\n", -1/3+1);
    for (int i = 0; i < reach.size(); i++) {
        Item u = reach[i];
        //printf ("%d %d\n", u.x, u.y);
        ans = min (ans, cal(u.x-1));
        ans = min (ans, cal(w-u.x));
        ans = min (ans, cal(u.y-1));
        ans = min (ans, cal(h-u.y));
    }
    printf ("%d\n", ans+1);
}

Measured memory_bytes: 14316
n, k = map(int, input().split())
ls = list(map(int, input().split()))

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged

ll = merge_sort(ls)
if n <= k:
    print(0)
else:
    print(sum(ll[:n-k]))

Measured memory_bytes: 26024
#include <bits/stdc++.h>
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vector dp(N + 1, vector(401, vector(401, INF)));
    dp[0][0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int aa = 0; aa <= 400; aa++) {
            for(int bb = 0; bb <= 400; bb++) {
                chmin(dp[i + 1][aa][bb], dp[i][aa][bb]);
                if(aa + a[i] <= 400 && bb + b[i] <= 400) {
                    chmin(dp[i + 1][aa + a[i]][bb + b[i]],
                          dp[i][aa][bb] + c[i]);
                }
            }
        }
    }
    int A = Ma, B = Mb;
    int ans = INF;
    while(A <= 400 && B <= 400) {
        chmin(ans, dp[N][A][B]);
        A += Ma;
        B += Mb;
    }
    cout << (ans >= INF ? -1 : ans) << endl;
}

Measured memory_bytes: 30120
def main():
    x, k, d = map(int, input().split())

    cur = abs(x)
    rem = k

    cnt = min(cur//d, k)
    cur -= d * cnt
    rem -= cnt
    if rem > 0:
        if rem % 2 == 1:
            cur = cur - d

    ans = abs(cur)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9184
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;

struct Node {
	int key;
	Node *prev;
	Node *next;
};

Node* nil;

void init() {
	nil = new Node();
	nil->key = -1;
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	Node* x = new Node();
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key) {
	Node* cur = nil->next;
	// 終了条件:
	// 1. there exists cur s.t.  cur->key == key
	// 2. cur == nil 
	//cout << endl;
	while(cur != nil && cur->key != key) {
		cur = cur->next;
		//cout << cur << endl;
	}
	//cout << "------------" << endl;
	return cur; 
}

void deleteNode(Node* t) {
	if(t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	delete t;
}

void deleteFirst() {
	deleteNode(nil->next);
}

/// ring 状にpointしていることに注意する
void deleteLast() {
  deleteNode(nil->prev);	
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

int main(){
	int n;
	scanf("%d\n", &n);

	init();
	for (int i=0; i<n; ++i) {
		char tmp[20];
		int key;
		scanf("%s%d", tmp, &key);
		//
		if(tmp[0] == 'i') {
			insert(key);
		} else if(tmp[0] == 'd') {
			string s(tmp);
			//cout << s << endl;
			if (s.length() > 6) {
				if (tmp[6] == 'F') {
					deleteFirst();
				} else if (tmp[6] == 'L') {
					deleteLast();
				}
			} else {
				deleteKey(key);
				//cout << "After delete key " << key << endl;
			}
		}
	}
	Node* cursor = nil->next;
	while (1) {
		if (cursor == nil) break;
		printf("%d", cursor->key);
		cursor = cursor->next;
		if (cursor != nil) {
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}




Measured memory_bytes: 34464
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
int getbit(vector<int> &A, int i, int j){
	return A[i]&(1<<j);
}
void setbit(vector<int> &A, int i, int j){
	A[i] = A[i]|(1<<j);
	return;
}
void unset(int & N, int i){
	N = N&(~(1<<i));
}
pair<int,int> dfs(int i, int N, vector<int> &A, int &Men, vector<vector<lli> > &M){
	pair<int, int> p;
	if(i==N) { p.first=1; p.second=1;return p;}
	if(Men==0) {p.first=0; p.second=0; return p;}
	pair<int, int> temp, c;
	p.second = 0;
	c.first = i;
	c.second = Men;
	if(M[i][Men]!=-1)
	{p.first = M[i][Men]; p.second = 1; return p;}

	for (int k = 0; k <N ; ++k)
	{
		if(getbit(A, i, k) and (Men & (1<<k)))
		{
			Men = Men&(~(1<<k));
			temp = dfs(i+1, N, A, Men, M);
			if(temp.second)
				{	p.first += temp.first; p.first%=1000000007; p.second = 1;}
			Men = Men|(1<<k);
		}
	}
	M[i][Men] = p.first%1000000007;
	return p;
}

int main(int argc, char const *argv[])
{
    int N, x;
    cin>>N;
	vector<int> A(N, 0);
    for (int i = 0; i < N; ++i)
    {
    	for (int j = 0; j < N; ++j)
    	{
    		cin>>x;
    		if(x)
    			setbit(A, i, j);
    	}
    }
    int Men = INT_MAX;
    for (int i = N; i <32 ; ++i)
    {
    	unset(Men, i);
    }
    vector<vector<lli> > M(N, vector<lli> ((1<<21), -1));
    cout<<dfs(0, N, A, Men, M).first;
    return 0;
}

Measured memory_bytes: 360832
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;

int main()
{
	scanf("%d",&n);
	int a;
	int A=0,B=0,C=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		if(a%4==0)A++;
		else if(a%2==1)B++;
		else if(a%2==0)C++;
	}
	bool ans;
	if(C==0){
		if(A+1>=B)ans = true;
		else ans=false;
	}else{
		if(A>=B)ans=true;
		else ans=false;
	}
	if(ans)printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\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;}
//------------------------------------------------------------------
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}

ll div2(ll x){
	ll num=0;
	while(x%2==0){
		num++;
		x/=2;
	}
	return num;
}

int main(void){
	ll n, m;
	cin >> n >> m;
	arrll(a,n);

	rep(i,n){
		a[i]/=2;
	}

	ll k=div2(a[0]);
	rep(i,n){
		if(k!=div2(a[i])){
			prt(0);
			return 0;
		}
		a[i]>>=k;
	}
	m>>=k;


	ll l=1;
	rep(i,n){
		l = lcm(a[i], l);
		if(l>m){
			prt(0);
			return 0;
		}
	}

	prt((m-l)/(2*l)+1);

}


Measured memory_bytes: 4056
#include <iostream>

#include <cmath>
#include <algorithm>

using namespace std;

#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];


// k????????§????????????p?????????????£?????°??´§???
int check(llong P) {
    int i = 0;
    for(int j = 0; j < k;j++) {
        llong  s = 0;
        while(s+T[i] <= P) {
            s += T[i];
            i++;
            if(i == n) {
                return n;
            }
        }
    }

    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000*10000;
    llong mid;
    while(left+1<right) {
        mid = (left+right)/2;
        int v = check(mid);
        if(v>=n) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return right;
}

int main() {
    cin>>n>>k;
    for(int i = 0; i < n;i++) {
        cin>>T[i];
    }
    llong ans = solve();
    cout<<ans<<endl;
}

Measured memory_bytes: 3892
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

template <unsigned T>
bool nextBitset(bitset<T> &bs, int digit)
{
    if(bs.none())
        return false;
    bitset<T> x, y, z;
    x = bs.to_ulong() & (~(bs.to_ulong()) + 1ULL);
    y = bs.to_ulong() + x.to_ulong() + 0ULL;
    z = bs & ~y;
    if(bs[digit-1] && bs == z)
        return false;
    bs = ((z.to_ulong() / x.to_ulong()) >> 1) + 0ULL;
    bs |= y;
    return true;
}

long long solve(vector<long long>& a)
{
    int n = a.size();
    sort(a.rbegin(), a.rend());

    long long ret = 0;
    for(int i=0; i<n-5; ++i){
        if(a[i] < a[i+1] + a[i+2]){
            for(int j=i+3; j<n-2; ++j){
                if(a[j] < a[j+1] + a[j+2]){
                    ret = a[i] + a[i+1] + a[i+2] + a[j] + a[j+1] + a[j+2];
                    break;
                }
            }
            break;
        }
    }

    for(int i=0; i<n-5; ++i){
        bitset<6> bs((1<<3)-1);
        do{
            vector<long long> x, y;
            for(int j=0; j<6; ++j){
                if(bs[j])
                    x.push_back(a[i+j]);
                else
                    y.push_back(a[i+j]);
            }
            if(x[0] < x[1] + x[2] && y[0] < y[1] + y[2])
                return max(ret, accumulate(a.begin()+i, a.begin()+i+6, 0LL));
        }while(nextBitset(bs, 6));
    }

    return ret;
}

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

    vector<long long> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    
    cout << solve(a) << endl;

    return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
int log[30];
int now;

void solve(int mos,int tot){
	if(tot==1){
		for(int i=0;i<now;i++)printf("%d ",log[i]);
		printf("1\n");
		return;
	}
	else if(mos<tot){
		log[now++]=mos;
		solve(mos,tot-mos);
		now--;
	}
	else if(mos==tot){
		for(int i=0;i<now;i++)printf("%d ",log[i]);
		printf("%d\n",mos);
	}
	if(mos>1)solve(mos-1,tot);
}

int main(){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0)break;
		now=0;
		for(int i=0;i<n;i++)log[i]=0;
		solve(n,n);
	}
}

Measured memory_bytes: 1036
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    D = Counter(A)
    ev = 0
    for k, v in D.items():
        if v % 2 == 0:
            ev += 1

    print(len(D) if ev % 2 == 0 else len(D) - 1)


if __name__ == '__main__':
    resolve()


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n, k;
    cin >> n >> k;

    vector<int> a(n);
    for(int in=0;in<n;in++) {
        cin >> a[in]; a[in]--;
    }

    vector<int> visited(n);
    vector<int> path;
    int now = 0;
    while(visited[now]==0) {
        visited[now] = 1;
        path.push_back(now);
        now = a[now];
    }

    int s = find(path.begin(), path.end(), now) - path.begin();
    int r = (int)path.size() - s;
    if(k<s) cout << path[k] + 1 << endl;
    else cout << path[(k-s)%r+s]+1 << endl;
    return 0;
}


Measured memory_bytes: 5864
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[] str = Console.ReadLine().Split();
		int[]A = new int[N];
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str[i]);
		}
		Array.Sort(A);
		int ans = 0;
		for(var i=0;i<N;i++){
			for(var j=i+1;j<N;j++){
				int min = j+1;
				int max = N;
				while(min<max){
					int m = (min+max)/2;
					if(A[i]+A[j]<=A[m]){
						max = m;
					} else {
						min = m+1;
					}
				}
				ans += min-j-1;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
typedef unsigned long long ull;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

const int N = 1e5;
int val[N];
const int B = 4;
const int MB = 1<<B;
const int MMB = 1<<MB;
int cnt[MB];
int d[MMB];
int bitvalue[MMB];
int bitcnt[MMB];
int main()
{
  int n; scanf("%d", &n);
  for (int i = 1; i <= n-1; ++i)
    {
      int u, v, x;
      scanf("%d %d %d", &u, &v, &x);
      val[u] ^= x;
      val[v] ^= x;
    }
  for (int i = 0; i < n; ++i) ++cnt[val[i]];
  int ans = 0;
  for (int i = 0; i < MB; ++i) bitvalue[1<<i] = i;
  for (int i = 1; i < MB; ++i) ans += cnt[i]/2, cnt[i] %= 2;
  for (int i = 1; i < MMB; ++i)
    {
      int lb = i&-i;
      bitvalue[i] = bitvalue[i^lb] ^ bitvalue[lb];
      bitcnt[i] = bitcnt[i>>1] + (i&1);
      d[i] = MB;
      for (int sub = i; sub; sub = (sub-1)&i)
	if (bitvalue[sub] == 0)
	  d[i] = min(d[i], bitcnt[sub] -1 + d[i^sub]);
    }
  int mask = 0;
  for (int i = 1; i < MB; ++i) mask ^= cnt[i] << i;
  printf("%d\n", d[mask] + ans);
}


Measured memory_bytes: 1408
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll ans = 0;
    ll l,r,d; cin >> l >> r >> d;
    rep(i,l,r+1){
        if(i % d == 0)ans++;
    }

    cout << ans << "\n";
}

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

int main()
{
  ll N,M;
  cin >> N >> M;
  vector<ll> vec(M);
  rep(i,M)
  {
    cin >> vec.at(i);
  }
  ll sum=0;
  rep(i,M)
  {
    sum+=vec.at(i);
  }
  if(sum<=N)
  {
    cout << N-sum << endl;
  }
  else
    cout << -1 << endl;
  return 0;
}  
  

Measured memory_bytes: 3708
// i層目のバーガー
// B + [i-1層目のバーガー] + P + [i-1層目のバーガー] + B
// i層目の層の総数 3+2*[i-1層目の層の総数]
// i層目のPの総数 1+2*[i-1層目のPの総数]

// なんか何回やってもあらかじめi層目の層の総数を計算しておくみたいなのしか思いつかん

package main
import "fmt"
var nth, pth []int
func main(){
	var N, X int
	fmt.Scan(&N, &X)
	nth = make([]int, 51)
	pth = make([]int, 51)
	nth[0], pth[0] =1, 1
	for i:=1; i<=50; i++{
		nth[i] = 3+2*nth[i-1]
		pth[i] = 1+2*pth[i-1]
	}
	fmt.Println(rec(N, X))
}


func rec(n, x int)int{
	if x == 0 {
		return 0
	}
	if n == 0{
		if x == 0{
			return 0
		}
		return 1
	}
	if 2*x < nth[n]{
		return rec(n-1, x-1)
	}else{
		// これが鬼 第2引数を間違えていた 脳死で2*x-nth[n]としていた
		// 半分より左側をごっそりけずるのでnth[n-1]としなければならない
		return pth[n-1] + rec(n-1, x-2-nth[n-1]) + 1
	}
	fmt.Println("ファーーー")
	return -9999999999999999
}

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

int main() {
    ll K, N;
    cin >> K >> N;
    vector<ll> A(N);
    for (ll i=0; i<N; i++) {
        cin >> A[i];
    }

    sort(A.begin(),A.end());
    vector<ll> kankaku(N);
    kankaku[0] = (K-A[N-1]) + A[0];
    for (ll i=1; i<N; i++) {
        kankaku[i] = A[i] - A[i-1];
    }
    sort(kankaku.begin(),kankaku.end());
    ll ans = 0;
    for (ll i=0; i<N-1; i++) {
        ans += kankaku[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 6400
#include <iostream>
#include <vector>
#include <algorithm>

void solve(int N, std::vector<int> L)
{
  std::sort(L.begin(), L.end());
  int count = 0;
  for (size_t i = 0; i < N-2; i++)
  {
    for (size_t j = i+1; j < N-1; j++)
    {
      if(L[j+1] > L[i] + L[j]){
        continue;
      }
      for (size_t k = j+1; k < N; k++)
      {
        if(L[i] < L[j] + L[k] &&
           L[j] < L[i] + L[k] &&
           L[k] < L[i] + L[j])
        {
          count ++;
        }
      }

    }
  }
  std::cout << count << std::endl;

}

int main(void)
{
  int N;
  std::cin >> N;
  std::vector<int> L(N);
  for(auto i0 = 0; i0 < N; ++i0)
  {
    std::cin >> L[i0];
  }
  solve(N,L);
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define INF 0x3f3f3f3f
#define CLR(a) memset(a, 0, sizeof(a))
using namespace std;
int N,T,A;
int h[1005];
int main(){
	ios::sync_with_stdio(0);
	while(cin>>N){
		cin>>T>>A;
		double mmin=INF,tmp;
		int loc=1;
		for(int i=1;i<=N;i++){
			cin>>h[i];
			tmp=abs(1.0*T-0.006*h[i]-A);
			if(tmp<mmin){
				mmin=tmp;
				loc=i;
			}
		}
		printf("%d\n",loc);
	}
	return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int l , r , d ;
    cin >> l >> r >> d ;
    int ans = r / d - (l - 1) / d ;
    cout << ans << endl;
    return 0; 
}

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

using namespace std;

long long a[5005][5005];

int main()
{
    long long Max=0,num,num1;
    long long p,i,j,ans,N,K,P[5005],C[5005];
    memset(a,0,sizeof(a));
    p=0;
    cin>>N>>K;
    for(i=1; i<=N; i++)
        cin>>P[i];
    for(i=1; i<=N; i++)
        cin>>C[i];
    for(i=1; i<=N; i++)
    {
        j=P[i];
        ans=1;
        while(j!=i)
        {
            a[i][ans]=a[i][ans-1]+C[j];
            if(p==0||a[i][ans]>Max)
            {
                Max=a[i][ans];
                p=1;
            }
            j=P[j];
            ans++;
            if(ans>=K)
                break;
        }
        a[i][ans]=a[i][ans-1]+C[j];
        if(p==0||a[i][ans]>Max)
        {
            Max=a[i][ans];
            p=1;
        }
        a[i][0]=ans;
    }
    for(i=1; i<=N; i++)
        if(a[i][0]<K&&a[i][a[i][0]]>0)
        {
            num=a[i][a[i][0]]*(K/a[i][0]-1);
            for(j=1; j<=a[i][0]; j++)
            {
                num1=num;
                num1+=a[i][j];
                if(num1>Max)
                    Max=num1;
            }
            num+=a[i][a[i][0]];
            for(j=1; j<=K%a[i][0]; j++)
            {
                num1=num;
                num1+=a[i][j];
                if(num1>Max)
                    Max=num1;
            }
            if(num>Max)
                Max=num;
        }
    /*for(i=1;i<=N;i++)
    {
        for(j=1;j<=a[i][0];j++)
        cout<<a[i][j]<<' ';
        cout<<endl;
    }*/
    cout<<Max<<endl;
    return 0;
}


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

int main() {
  int a;
  cin>>a;
  string s;
  switch (a) {
    case 22: s = "Christmas Eve Eve Eve"; break;
    case 23: s = "Christmas Eve Eve"; break;
    case 24: s = "Christmas Eve"; break;
    case 25: s = "Christmas"; break;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
    int i;
    int c=0;
    char word[10];
    char s[1000];
    scanf("%s",word);
    for(i=0; i<strlen(word); i++) word[i]=toupper(word[i]);
    while(1){
        scanf("%s", s);
        if(strcmp("end_of_text",s)==0)continue;
        for(i=0; i<strlen(s); i++) s[i]=toupper(s[i]);
        if(strcmp(s,"END_OF_TEXT")==0)break;
        if(strcmp(s,word)==0)c++;
    }
    printf("%d\n", c);
    return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	int a,b,c; cin>>a>>b>>c;
	if(b+c>a) cout<<b+c-a;
	else cout<<0;
	return 0;
}

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

using namespace std;

const int N = 1e5+77;
typedef long long ll;
const ll Z = 1e10+7;

unordered_map<ll,int> ile;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

inline ll pot(ll x, int r) {
	if(r == 0) return 1;
	return r == 1 ? x : x*x;
}


inline ll fast_pot(ll a, ll b, ll mod) {
	ll res = 1;
	ll akta = a;
	while(b) {
		if(b%2==1) {
			res *= akta;
			res %= mod;
		}
		akta *= akta;
		akta %= mod;
		b/=2;
	}
	return res;
}

//bool zlozona[(int)1e6+7];

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

	int n;
	cin >> n;
	
	/*for(int i=2;i<(int)1e6;i++)
		for(int j=i+i;j<=(int)1e6;j+=i)
			zlozona[j] = 1;
	*/
	ll x;

	vector<pll> X;

	int res = 0;
	ll magicn = 2155;

	for(int i=0;i<n;i++) {
		cin >> x;
		ll tx = x;
		ll first = 1, second = 1;

		for(ll j=2;j<magicn;j++) {
			if(tx == 1)
				break;

			int cnt = 0;
			while(tx%j==0) {
				cnt++;
				tx /= j;
			}
			first *= pot(j, cnt%3);
			second *= pot(j, (3-cnt%3)%3);
		}

		bool rob = true;
		if(tx != 1) {
			ll s = sqrtl(tx);
			if(s*s == tx) {
				//cout << "kwa" << endl;
				first *= s*s;
				second *= s;
			} else {
				if(tx <= (int)1e5 and fast_pot(7,tx-1,tx) == 1 and fast_pot(5,tx-1,tx) == 1) {
					first *= tx;
					second *= tx * tx;
				} else {
					res++;
					rob = false;
				}	
			}
		}

		if(rob) {
			ile[first]++;
			X.push_back(pll(first,second));
		//	cout << "wrzucam " << first << " " << second << endl;
		}
	}


	for(pll x: X) {
		if(x.first == 1 and ile[x.first] > 0) {
			res++;
			ile[x.first] = 0;
		}
		res += max(ile[x.first], ile[x.second]);

		ile[x.first] = 0;
		ile[x.second] = 0;
	}
	
	cout << res << endl;
}


Measured memory_bytes: 8944
///*/////////////////////////////*///
/// IN THE NAME OF ALMIGHTY ALLAH ///
///*/////////////////////////////*///

///*////////////////////*///
/// Author : SAIFULLAH29 ///
///*////////////////////*///

///*//////////////////////////////////////////*///
/// "When you want something, all the universe ///
///  conspires in helping you to achieve it."  ///
///              - Paulo Coelho, The Alchemist ///
///*//////////////////////////////////////////*///

#include <bits/stdc++.h>

#define SS           " "
#define endl         "\n"
#define EPS          1e-9
#define gcd          __gcd
#define pb           push_back
#define pi           acos(-1.0)
#define Ars          greater<int>()
#define vi           vector<int>
#define vvi          vector<vector<int> >
#define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define wow          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long              ll;
typedef double                 dbl;
typedef unsigned long long     ull;

ll lcm(ll a, ll b)
{
    return (a/gcd(a, b))*b;
}

void solve()
{
    int a, b, cnt=0;
    cin>>a>>b;

    for(int i=a; i<=b; i++)
    {
        string s, t;
        s = to_string(i);
        t = s;
        reverse(s.begin(), s.end());

        if(s == t)
            cnt++;
    }

    cout<<cnt<<endl;
}

int main()
{
    wow

    int t=1;
    //cin>>t;

    while(t--)
        solve();

    return 0;
}

///*////////////////////////////////////////////*///
/// "There is only one thing that makes a dream  ///
/// impossible to achieve: the fear of failure." ///
///                - Paulo Coelho, The Alchemist ///
///*////////////////////////////////////////////*///


Measured memory_bytes: 3708
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;
ll n, ans;
ll a[200005], b[200005];
ll c[200005], d[200005];

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for(ll i = 0; i < n; i++)
    {
        scanf("%lld", &b[i]);
    }
    for(ll i = 0; i < 30; i++)
    {
        ll k = 1<<i;
        for(ll j = 0; j < n; j++)
        {
            c[j] = a[j] % (k * 2);
            d[j] = b[j] % (k * 2);
        }
//        sort(c, c + n);
        sort(d, d + n);
        ll cnt = 0;
        for(ll j = 0; j < n; j++)
        {
            cnt += lower_bound(d, d + n, 2 * k - c[j]) - lower_bound(d, d + n, 1 * k - c[j]);
            cnt += lower_bound(d, d + n, 4 * k - c[j]) - lower_bound(d, d + n, 3 * k - c[j]);
        }
        if(cnt % 2 == 1) ans |= k;
    }
    printf("%lld", ans);
    return 0;
}


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

int l,r,d;
int main()
{
	int i,cnt=0;
	scanf("%d%d%d",&l,&r,&d);
	for(i=l;i<=r;i++)
		if(i%d==0) cnt++;
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 3812
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
const int MAXV = 50000;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char text[MAXN];
int arr[MAXN];

int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ll x;
    scanf("%lld", &x);
    string s;
    while (x) {
        x--;
        s += 'a' + (x % 26);
        x /= 26LL;
    }
    reverse(s.begin(), s.end());
    cout << s;
    return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPD(i,n) for(int i=(n)-1;i>=0;--i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define TLE() cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms.\n";
const ll MOD = 1E9+7;
const ll IINF = 1E18;
const int INF = 1e9;
const double EPS = 1E-9;
const double PI = atan(1.0) * 4.0;
template<class T> T getbit(T s, int i) {return s>>i&1;}
template<class T> void flipbit(T& s, int i) {s^=(1LL<<i);}
constexpr int cntbit(ll x) {return __builtin_popcountll(x);}
constexpr int lg2(ll x) {return __lg(x);} // return int(log2(x))
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
ll fpow(ll a,ll p){ll res=1LL;while(p){if(p&1LL) res=res*a%MOD;a=a*a%MOD;p>>=1LL;} return res;}

int n,m,res;
int p[15];
vector<int> link[15];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	REP(i,m){
		int k;
		cin>>k;
		REP(j,k){
			int x;
			cin>>x;
			link[i].pb(x-1);
		}
	}
	REP(i,m) cin>>p[i];
	REP(i,1<<n){
		int t=0;
		REP(j,m){
			int cnt=0;
			for(auto x:link[j])
				cnt+=getbit(i,x);
			if(cnt%2==p[j]) t++;
		}
		if(t==m) res++;
	}
	cout<<res<<'\n';
}



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

int main() {
  int x, y;
  cin >> x >> y;
  int p, q;
  
  if (x == 2) p = 0;
  else if (x == 4 || x == 6 || x == 9 || x == 11) p = 1;
  else p = 2;
  
  if (y == 2) q = 0;
  else if (y == 4 || y == 6 || y == 9 || y == 11) q = 1;
  else q = 2;
  
  if (p == q) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void solve() {
    string decks[(int) 'c' + 1];
    int pnts[(int) 'c' + 1];
    vector<char> order = {'a', 'b', 'c'};
    for (auto c: order) {
        cin >> decks[c];
        pnts[c] = 0;
    }
    char cur = 'a';
    while (pnts[cur] != decks[cur].size()) {
        cur = decks[cur][pnts[cur]++];
        //cout << cur << endl;
    }
    cout << (char)toupper(cur) << endl;
}

int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        if (0) {
            freopen("weapons.in", "r", stdin);
            freopen("weapons.out", "w", stdout);
        }
    #endif

    solve();

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for(auto &x : a){
        cin >> x;
        mp[x]++;
    }
    ll ans = 0;
    for(auto x : mp){
        ll k = x.second;
        ans += (k*(k-1))/2;
    }
    for(int i=0; i<n; i++){
        cout << ans - mp[a[i]] + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 9984
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int min = l;
		int max = l+n-1;
		int ans = 0;
		for(int i = 1; i <= n; i++){
			ans+=l+i-1;
		}
		if(max < 0){
			ans-=max;
		}else if(0 < min){
			ans-=min;
		}
		System.out.print(ans);
	}
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);


long long gcd(long long a, long long b) {
   if (a%b == 0) {
       return(b);
   }
   else {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a, long long b) {
   long long tmp = max(a,b)/gcd(a,b);
   return min(a,b)*tmp;}

int main() {
    ll N,M;
    cin >> N >> M;
    string S,T;
    cin >> S >> T;

    ll L = lcm(N,M);

    map<ll,char> X;

    bool t = true;

    rep(i,N) {
        ll idx = 1 + i*(L/N);
        X[idx] = S[i];
    }
    rep(i,M) {
        ll idx = 1 + i*(L/M);
        if (!X.count(idx)) continue;
        else if (X[idx]!=T[i]) t = false;
    }

    if (t) cout << L << endl;
    else cout << -1 << endl;
        
}

Measured memory_bytes: 9392
def main():
    N, M = (int(i) for i in input().split())
    p = (0.5)**M
    np = 1 - p
    t = (1900*M + 100*(N-M))
    ans = 0
    for i in range(1, 10**5)[::-1]:
        ans += i*t*p*(np**(i-1))
    print(round(ans))


if __name__ == '__main__':
    main()


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

const int MOD = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  vector<vector<int>> dp(h, vector<int>(w, 0));
  dp[0][0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
       if (i == 0) {
         if (j > 0 && a[i][j] == '.') dp[i][j] = dp[i][j - 1];
       } else if (j == 0) {
         if (i > 0 && a[i][j] == '.') dp[i][j] = dp[i - 1][j];
       } else {
         if (a[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
       }
    }
  }
  cout << dp[h - 1][w - 1] << endl;
}


Measured memory_bytes: 5248
#include<stdio.h>
#include<stdlib.h>

#define N 100
#define inf 10000000

void dijkstra(int);
void initializeSingleSource(int);

int w[N][N], d[N], pi[N],n,k, s, c[N];

int main(){

  int i,j, v;

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


  for(i=0;i<n;i++){

    scanf("%d %d",&s,&k);

    for(j=0;j<k;j++){

      scanf("%d ",&v);
      scanf("%d",&w[s][v]);
    } 
  }

   dijkstra(s);

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

void dijkstra(int s){

  int mincost, i;
  int u, v;

  initializeSingleSource(s);
  // fprintf(stderr,"error\n");
  /* for(i=0;i<n;i++)
     printf("%d\n",d[i]);*/

  while(1){
    mincost = inf;
    
    for(i=0;i<n; i++){

      if(c[i] != 2 && d[i] < mincost){
	mincost = d[i];
	u = i;
      }}
    if(mincost == inf)break;

    c[u] = 2;

    for(v = 0;v<n;v++){
      //	printf(" %d n %d %d\n",w[u][v],d[v],v);
      if(c[v] != 2 && d[u] + w[u][v]< d[v]){
	//	pi[v] = u;
	d[v] =  w[u][v]+d[u];	
      }
    }
  }
}

void initializeSingleSource(int s){

  int v;

  for(v=0;v<n;v++){

    d[v] = inf;
    c[v] = 0;
    pi[v] = 0;
  }
  d[0] = 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct Vertex {
  int v, n;
  string s;

  Vertex() {}
  Vertex(string s, int v, int n): s(s), v(v), n(n) {}

  bool operator < (const Vertex& v) const {
    return s > v.s;
  }
};

int n, a, s, g;
vector<pair<int, string>> G[45];
string d[45][505];

void init() {
  rep(i, 45) G[i].clear();
  rep(i, 45) rep(j, 505) d[i][j] = "~";
}

void dijkstra() {
  d[s][0] = "";
  priority_queue<Vertex> pq;
  pq.push({"", s, 0});
  while (pq.size()) {
    int v = pq.top().v, resm = pq.top().n;
    pq.pop();
    for (auto p: G[v]) {
      int u = p.first;
      string c = p.second;
      int m = resm + c.length();
      if (m > 500) continue;
      if (chmin(d[u][m], d[v][resm] + c)) {
        pq.push({d[u][m], u, m});
      }
    }
  }
  string ans = "~";
  rep(i, 501) {
    if (chmin(ans, d[g][i]) && i >= 300) {
      cout << "NO\n";
      return;
    }
  }
  if (ans == "~") {
    cout << "NO\n";
    return;
  }
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  while (cin >> n >> a >> s >> g, n) {
    init();
    rep(i, a) {
      int x, y;
      string lab;
      cin >> x >> y >> lab;
      G[x].push_back({y, lab});
    }

    dijkstra();
  }

  




  
  return 0;
}


Measured memory_bytes: 31536
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;

fn main() {
    input!{
        n: usize,
        w: usize,
        v: [[usize; 2]; n]
    }
    let mut tab: Vec<Vec<usize>> = vec![vec![0; w + 1]; n + 1];
    for i in 1..n + 1 {
        for j in 1..w + 1 {
            tab[i][j] = tab[i - 1][j];
            if v[i - 1][0] <= j {
                tab[i][j] = max(tab[i][j], tab[i - 1][j - v[i - 1][0]] + v[i - 1][1]);
            }
        }
    }
    println!("{}", tab[n][w]);
}


Measured memory_bytes: 106748
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

ll lmin(ll x,ll y){
    if(x <= y) return x;
    else return y;
};

int main(){
    ll n; cin >> n;
    ll min = 1e16;
    rep(i,5){
        ll x; cin >> x;
        min = lmin(min, x);
    }
    if(n % min != 0) n+= min;
    n /= min;
    cout << n + 4 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

bool is_palindrome(string s)
{
	string t = s;
	reverse(all(t));
	rep(i,sz(s))if(s[i] != t[i])return false;
	return true;
}

void solve()
{	
	string s; cin >> s;
	int n = sz(s);
	string s_0 = s.substr(0,(n-1)/2);
	string s_1 = s.substr((n+1)/2,(n-1)/2);
	if(is_palindrome(s_0) && is_palindrome(s_1) && is_palindrome(s))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,x;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        x = i;
        if(i%3==0)
        {
            printf(" %d",i);
        }
        else
        {
            while(x>0)
            {
                if(x%10==3)
                {
                    printf(" %d",i);
                    break;
                }
                else
                {
                    x = x/10;
                }
            }
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2120
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

#include<vector>

#define INF 999999
using namespace std;
int main(){
    int N;
    cin>>N;
    while(N--){
        int score=0,hitcnt=0;
        string sum;
        for(int out=0;out!=3;){
            cin>>sum;
            if(sum[0]=='O')out++;
            else if(sum[0]=='H'&&sum[1]=='I'){
                if(hitcnt==3)score++;
                else hitcnt++;
            }
            else{
                score+=hitcnt+1;
                hitcnt=0;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}

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

string to_string(string s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = k;
  for (int i = 1; i < n; i++) {
    ans *= (k-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256