akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
dp = [float('inf')] * (2 ** n)
dp[0] = 0
for i in range(m):
    a, b = map(int, input().split())
    c = sum(1 << (i - 1) for i in map(int, input().split()))
    for j in range(2 ** n):
        if dp[c | j] > dp[j] + a:
            dp[c | j] = dp[j] + a

if dp[-1] == float('inf'):
    ans = -1
else:
    ans = dp[-1]
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>

int main(void) {
	int N;
	if (scanf("%d", &N) != 1) return 1;
	if (N < 100 || 999 < N) {
		puts("unsupported");
	} else  {
		puts(N / 100 == N % 10 ? "Yes" : "No");
	}
	return 0;
}


Measured memory_bytes: 128
from math import sqrt

def prime_numbers(n):
    total = 0
    for x in n:
        if is_prime(x):
            total += 1
    return total

def is_prime(x):
    if x == 2:
        return True
    elif x < 2 or x % 2 == 0:
        return False

    for i in range(3, int(sqrt(x)) + 1, 2):
        if x % i == 0:
            return False
    return True

if __name__ == '__main__':
    n = []
    for _ in range(int(input())):
        n.append(int(input()))
    print(prime_numbers(n))



Measured memory_bytes: 6004
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

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 = 1000000007;
static const int SIZE = 500005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int 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;
}

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

    int n, k;
    cin >> n >> k;
    int res = 0;
    for( int i = 0; i < n; ++i ) {
        int h;
        cin >> h;
        if( h >= k ) ++res;

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



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

#define fastio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output            freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 

#define ll                      long long
#define read1(x)                 cin>>x
#define read2(x,y)               cin>>x>>y
#define print(x)				cout<<x<<endl
#define pii                     pair<int, int>
#define pli                     pair<ll, int>
#define pil                     pair<int, ll>
#define pll                     pair<ll, ll>
#define vi                      vector<int>
#define vll                     vector<ll>
#define vb                      vector<bool>
#define vd                      vector<double>
#define vs                      vector<string>
#define ff                      first
#define ss                      second
#define pb                      push_back
#define ppb                     pop_back
#define pf                      push_front
#define ppf                     pop_front
#define vpii                    vector<pii>
#define umap                    unordered_map
#define uset                    unordered_set
#define clr(a,b)                memset(a,b,sizeof a)
#define all(ds)                 ds.begin(), ds.end()
#define rev(ds)                 ds.rbegin(), ds.rend()
#define asc(A)                  sort(A.begin(), A.end())
#define dsc(A)                  sort(A.begin(), A.end(), greater<int>())
#define gcd(x,y)                __gcd(x,y)
#define clr(a,b)                memset(a,b,sizeof a)
#define fr(i, n)                for(int i=0; i<n;++i)
#define fr1(i, n)               for(int i=1; i<=n; ++i)
#define rfr(i, n)               for(int i=n-1; i>=0; --i)
#define printVector(v)          for(int i= 0;i<v.size();i++) {cout<<v[i]<<" ";} cout<<endl;
#define precise(x)              cout<<fixed<<setprecision(x)
#define inf                     10000000000000

 

ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }
ll power(ll x, ll y, ll m) { if(!y) return 1; ll p=power(x, y>>1, m)%m; p=p*p%m; return (y&1)?(x*p)%m:p;}
ll modInverse(ll a, ll m){ return power(a, m-2, m); }
bool isPrime(ll num){bool flag=true;for(ll i =2;i<=num/2;i++){if(num%i==0) {flag=false; break;} }return flag;}
ll sumofdigits(ll n){ll c=0;while(n>0){c++;n/=10;}return c;}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) {return a.first > b.first; }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) {return a.second < b.second; }

//const double PI= 2*acos(0.0);
const long long MOD= 1000000007;


void solve(){
    
    int n; cin>>n;
    unordered_map<string, int>m;
    int ac = 0, wa = 0, tle = 0, re = 0;
    fr(i,n){
        string s; cin>>s;
        if(s == "AC")ac++;
        if(s == "WA")wa++;
        if(s == "TLE")tle++;
        if(s == "RE")re++;
     
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;

}
int main()
{
#ifndef ONLINE_JUDGE  
    input_output  
#else   
    fastio
#endif

    int t =1 ;
    // cin>>t;
    while(t--){
        solve();
    }

    return 0;
}

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

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    vector<vector<int>> input(H,vector<int>(W)), ans(H,vector<int>(W));

    for( int i = 0; i < H; i++ ){
        for( int j = 0; j < W; j++ ){
            char grid = '?';
            cin >> grid;
            if(grid == '.') input[i][j] = 0;
            else input[i][j] = 1;
        }
    }
    int numbering = 1;
    vector<int> nostrawberry(H);
    int flagfirststarberry = 0;
    for( int i = 0; i < H; i++ ){
        int flagstrawberry = 0;
        for( int j = 0; j < W; j++ ){
            if( input[i][j] == 1 && flagstrawberry == 0 ){
                for( int k = 0; k < W; k++ ){
                    ans[i][k] = numbering;
                }
                    numbering++;
                    flagstrawberry++;
            } else if ( input[i][j] == 1 ){
                for( int k = j; k < W; k++ ){
                    ans[i][k] = numbering;
                }
                    numbering++;
                    flagstrawberry++;
            }
        }
        if( flagstrawberry >= 1 && flagfirststarberry== 0 ){
            for( int k = i; k >= 1; k-- ){//i DOWN TO 0
                for( int l = 0; l < W; l++ ){
                    ans[k-1][l] = ans[k][l];
                }
            }
            flagfirststarberry = 1;
        }
        if( flagstrawberry == 0 && flagfirststarberry == 1 ){
            for( int k = 0; k < W; k++ ){
                ans[i][k] = ans[i-1][k];
            }
        }
    }


    for( int i = 0; i < H; i++ ){
        for( int j = 0; j < W; j++ ){
            cout << ans[i][j] << endl;
        }
    }
}

Measured memory_bytes: 1536
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	r, c, k := nextInt(), nextInt(), nextInt()
	item := make([][]int, r)
	for i := 0; i < r; i++ {
		item[i] = make([]int, c)
	}
	for i := 0; i < k; i++ {
		ri, ci, v := nextInt()-1, nextInt()-1, nextInt()
		item[ri][ci] = v
	}

	dp := make([][][]int, r)
	for i := range dp {
		dp[i] = make([][]int, c)
		for j := range dp[i] {
			dp[i][j] = make([]int, 4)
		}
	}
	dp[0][0][1] = item[0][0]
	for i := 0; i < r; i++ {
		for j := 0; j < c; j++ {
			for k := 0; k <= 3; k++ {
				if i-1 >= 0 {
					dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k])
					dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k]+item[i][j])
				}
				if j-1 >= 0 {
					dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
					if k > 0 {
						dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1]+item[i][j])
					}
				}
			}
		}
	}

	ans := max(dp[r-1][c-1]...)
	puts(ans)
}


Measured memory_bytes: 600344
n=int(input())
l=[[0]*10 for i in range(10)]

for i in range(1,n+1):
  i=str(i)
  l[int(i[0])][int(i[-1])]+=1

ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=l[i][j]*l[j][i]
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
  
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Card[] cards = new Card[n];
      char suit;
      int  value;

      for ( int i=0; i<n; i++ ) {
        suit = (char)br.read(); br.skip(1);
        value = Integer.parseInt(br.readLine());
        cards[i] = new Card(suit, value, i);
      }

      quickSortOfCards(cards, 0, n-1);
      dispCardArray(cards);
    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }

  public void quickSortOfCards(Card[] card, int p, int r) {

    if( p < r) {
      int q = partitionOfCards(card, p, r);
      quickSortOfCards(card, p, q-1);
      quickSortOfCards(card, q+1, r);
    }
  }

  public int partitionOfCards(Card[] card, int p, int r) {

    int x = card[r].value;
    int i = p-1;
    Card t;

    for(int j=p; j<r; j++) {
      if(card[j].value <= x) {
        t = card[++i]; card[i] = card[j]; card[j] = t;
      }
    }
    t = card[i+1]; card[i+1] = card[r]; card[r] = t;

    return i+1;
  }

public void dispCardArray(Card[] target) {
  StringBuilder s = new StringBuilder();
  int l=target.length;
  boolean isStable = true;
  String sortState = "Stable";

  s.append(target[0]).append("\n");
  for (int i=1; i<l; i++) {
    s.append(target[i]).append("\n");
    if(isStable && target[i-1].value == target[i].value 
      && target[i-1].storedNo > target[i].storedNo) {
      sortState = "Not stable";
      isStable = false;
    }
  }

  System.out.println(sortState);
  System.out.print(s);
  }
}

class Card {
  char suit;
  int value;
  int storedNo;

  public Card( char suit, int value, int storedNo ) {
    this.suit  = suit;
    this.value = value;
    this.storedNo = storedNo;
  }
  public Card( Card card ) {
    this(card.suit, card.value, card.storedNo);
  }

  @Override
  public String toString() {
    return suit + " " + String.valueOf(value);
  }
}


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


typedef long long ll;
typedef pair<ll,int> P;

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n;
  cin >> n;
  vector<int> ans(n+1, 0);
  for(int i=1; i*i<=n; i++){
    for(int j=1; j*j<=n; j++){
      for(int k=1; k*k<=n; k++){
        int tmp = i*i+j*j+k*k+i*j+j*k+k*i;
        if(tmp > n) continue;
        ans[tmp]++;
      }
    }
  }
  for(int i=1; i<=n; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#平成の次の元号は
#令和です！！
#令和→零和→Zero-Sum
#この問題はZero-Sum-Ranges...
N=int(input())
A=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=A[i]+S[i]
D=dict()
for i in range(N+1):
    if S[i] in D:
        D[S[i]]+=1
    else:
        D[S[i]]=1
ans=0
for k in D:
    t=D[k]
    ans+=(t*(t-1))//2
print(ans)


Measured memory_bytes: 41152
import qualified Data.ByteString.Char8 as BS

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

calc :: String -> String ->Int -> String
calc ss ts 1 | ss == ts = "Yes"
             | otherwise = "No"
calc ss ts n | ss == ts = "Yes"
             | otherwise = calc (last ss : init ss) ts (n-1)

main = do
  [ss] <- getString
  [ts] <- getString
  let ssl = length(ss)
  putStrLn $ calc ss ts ssl
  

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

int main() {
    int H, W, D; cin >> H >> W >> D;
    map<int, pair<int, int>> m;
    vector<ll> dp(H*W+1, -1);
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int a; cin >> a;
            m[a] = make_pair(i, j);
        }
    }
    for (int i = 1; i < H*W+1; i++)
    {
        if(i-D < 1) dp[i] = 0;
        if(m.count(i-D)&&m.count(i)){
            dp[i] = dp[i-D] + abs(m[i-D].first - m[i].first)  + abs(m[i-D].second - m[i].second);
        }
    }
    

    int Q; cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        int l, r; cin >> l >> r;
        cout << dp[r] - dp[l] << endl;
    }
}

Measured memory_bytes: 7424
import fractions
N,X=map(int,input().split())
x=list(map(lambda x: abs(int(x)-X), input().split()))
x_min=min(x)
g_min=x_min
for i in x:
  g=fractions.gcd(g_min,i)
  if g < g_min:
    g_min = g
print(g_min)

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

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define RFOR(i, a, n) for (ll i = (ll)a; i >= n; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FOR(i, 1, n + 1)
#define RREP(i, n) RFOR(i, n - 1, 0)
#define RREPN(i, n) RFOR(i, n, 1)
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

ll junretu(int n, int k)
{
	ll result = 1;
	REP(i, k)
	{
		result *= n;
		result %= MOD;
		--n;
	}
	return result;
}

long long modinv(long long a, long long m)
{
	long long b = m, u = 1, v = 0;
	while (b)
	{
		long long t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= m;
	if (u < 0)
		u += m;
	return u;
}

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

//a,bの最大公約数
ll gcd(ll a, ll b)
{
	ll temp;
	while (a % b != 0)
	{
		temp = a;
		a %= b;
		b = temp;
	}
	return b;
}

//a,bの最小公倍数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

const int MAX_NM = 2e3 + 10;

int H, W;
vector<string> field;
int Left[MAX_NM][MAX_NM], Right[MAX_NM][MAX_NM], Up[MAX_NM][MAX_NM], Down[MAX_NM][MAX_NM];

int main()
{
	cin >> H >> W;
	field.resize(H);
	REP(i, H)
	{

		cin >> field[i];
	}

	REP(i, H)
	{
		int res = 0;
		REP(j, W)
		{
			if (field[i][j] == '#')
			{
				res = 0;
			}
			else
			{
				++res;
			}
			Left[i][j] = res;
		}
	}

	REP(i, H)
	{
		int res = 0;
		RREP(j, W)
		{
			if (field[i][j] == '#')
			{
				res = 0;
			}
			else
			{
				++res;
			}
			Right[i][j] = res;
		}
	}

	REP(j, W)
	{
		int res = 0;
		REP(i, H)
		{
			if (field[i][j] == '#')
			{
				res = 0;
			}
			else
			{
				++res;
			}
			Up[i][j] = res;
		}
	}

	REP(j, W)
	{
		int res = 0;
		RREP(i, H)
		{
			if (field[i][j] == '#')
			{
				res = 0;
			}
			else
			{
				++res;
			}
			Down[i][j] = res;
		}
	}

	int ans = 0;
	REP(i, H)
	{
		REP(j, W)
		{
			if (field[i][j] == '#')
				continue;

			chmax(ans, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3);
		}
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

struct pos {
    ll x, y;
};

bool comp1(const pos &lhs, const pos &rhs) { return lhs.x + lhs.y < rhs.x + rhs.y; }
bool comp2(const pos &lhs, const pos &rhs) { return lhs.x - lhs.y < rhs.x - rhs.y; }

ll dis(pos &x, pos &y) { return abs(x.x - y.x) + abs(x.y - y.y); }

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

    vector<pos> w = v;
    sort(v.begin(), v.end(), comp1), sort(w.begin(), w.end(), comp2);

    pos a = v.front(), b = v.back(), c = w.front(), d = w.back();
    cout << max({dis(a, b), dis(c, d)}) << endl;
    return 0;
}

Measured memory_bytes: 9584
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
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...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  rep(i, Size(s)) cout << "x";
  cout << "\n";
  return 0;
}

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

int n;

ll mp = 200000;
bitset<8> taken, val;

int main() {
    cin >> n;
    vector<ll> target(3), bamboo;
    for (auto& i : target) cin >> i;
    for (int i = 0; i < n; ++i) {
        int bam; cin >> bam;
        bamboo.push_back(bam);
    }
    vector<int> order = {0, 1, 2};

    sort(target.begin(), target.end(), greater<ll>());

    do {
        int tmp = 0;
        val.set();

        for (int t = 0; t < 3; ++t) {
            int mn = 10000;
            taken.reset();
            for (int i = 1; i < (1 << n); ++i) {
                int used = 0, length = 0, tmptaken = 0;
                for (int j = 0; j < n; ++j) {
                    if (i & (1 << j) && val[j]) {
                        tmptaken += (1 << j);
                        if (length > 0) used += 10;
                        length += bamboo[j];
                    }
                }

                if (!length) continue;
                used += abs(length - target[order[t]]);
                if (used < mn) {
                    taken = tmptaken;
                    mn = used;
                }
            }

            tmp += mn;
            for (int i = 0; i < 8; ++i) {
                if (taken[i]) val[i] = false;
            }
        }
        if (tmp < mp) mp = tmp;
    } while (next_permutation(order.begin(), order.end()));
    
    cout << mp;
}


Measured memory_bytes: 3640
n=int(input())
L=list(map(int,input().split()))
c=0
for i in range(n-2):
    for j in range(i,n-1):
        for k in range(j,n):
            if L[i]!=L[j] and L[i]!=L[k] and L[j]!=L[k]:
                LS=sorted([L[i],L[j],L[k]])
                if LS[2]<LS[1]+LS[0]:
                    c+=1
print(c)

Measured memory_bytes: 68628
#include<stdio.h>

#define N 10000

int main(void)
{
	int x[N],count=0,i;
	
	while(1){
		scanf("%d",&x[count]);
		count++;
		
		if(x[count-1]==0){
			break;
		}
	}
	
	for(i=0;i<count-1;i++){
		printf("Case %d: %d\n",i+1,x[i]);
	}
	
	return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(n);
  vector<int> sz(n, 1);
  vector<bool> used(n, false);
  used[0] = true;

  for (int i = 0; i < m; i++) {
	int x,y;
    cin >> x>> y;x--;y--;
    sz[x]--;
    sz[y]++;
    if (used[x]) used[y] = true;
    if (sz[x] <= 0) used[x] = false;
  }
	int ans=0;
	for(auto&& w:used)if(w)ans++;
 // int ans = count(begin(used), end(used), true);
  cout << ans << endl;
}


Measured memory_bytes: 1408
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
        static void Main(){
            int[] nk  = ILongs();
            int n = nk[0];
            int k = nk[1];
            int[][] td = ILongLongs(n);

            Array.Sort(td,Compare);
            //for(int i=0;i<n;i++){
            //    Console.Write(td[i][0]);
            //    Console.Write(" ");
            //    Console.WriteLine(td[i][1]);
            //}

            HashSet<int> sset = new HashSet<int>();
            bool[] kaburi = new bool[n];

            long ans = 0;
            long ansppoi = 0;
            long syurui = k;

            for(int i=0;i<k;i++){
                ans += td[i][1];
                ansppoi += td[i][1];
                if(kaburi[i] = !sset.Add(td[i][0])){
                    syurui --;
                }
            }
            ans += syurui * syurui;
            ansppoi += syurui * syurui;

            int imal = k-1;
            int imar = k;
            while(imal>-1&&imar<n){
                if(kaburi[imal]){
                    if(sset.Add(td[imar][0])){
                        ansppoi -= td[imal][1];
                        ansppoi += td[imar][1];
                        ansppoi += 2*syurui + 1;
                        syurui ++;
                        if(ans < ansppoi)ans = ansppoi;
                        imal --;
                        imar ++;
                    }else{
                        imar ++;
                    }
                }else{
                    imal --;
                }
            }
            Console.WriteLine(ans);
        }

        static int Compare(int[] a, int[] b){
            return b[1] - a[1];
        }

        static readonly int MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static int[] ILongs(){
            string[] s = ReadLine().Split();
            int[] re = new int[s.Length];
            for(int i=0;i<s.Length;i++){
                re[i] = int.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static int[][] ILongLongs(int n){
            int[][] re = new int[n][];
            for(int i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new int[s.Length];
                for(int j=0;j<s.Length;j++){
                    re[i][j] = int.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(int n){
            char[][] re = new char[n][];
            for(int i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}


Measured memory_bytes: 26308
#include<stdio.h>

#define H 250

typedef struct{
  int r;
  int l;
  int p;
  int k;
}T;

int parent(int);
int right(int,int);
int left(int,int);

int main(){
    
    T tree[H];
    int i,h,pid,rid,lid;
    
    scanf("%d",&h);
    
    for(i=1;i<=h;i++){
      tree[i].r=-1;
      tree[i].l=-1;
      tree[i].p=-1;
    }
    
    for(i=1;i<=h;i++){
        scanf("%d",&tree[i].k);
    }
    
    for(i=1;i<=h;i++){
        
        pid=parent(i);
        if(pid!=-1) tree[i].p=pid;
        rid=right(i,h);
        if(rid!=-1) tree[i].r=rid;
        lid=left(i,h);
        if(lid!=-1) tree[i].l=lid;
    
    }
    
    for(i=1;i<=h;i++){
        printf("node %d: ",i);
        printf("key = %d, ",tree[i].k);
        if(tree[i].p!=-1){
            printf("parent key = %d, ",tree[tree[i].p].k);
        }
        
        if(tree[i].l!=-1){
            printf("left key = %d, ",tree[tree[i].l].k);
        }
        
        if(tree[i].r!=-1){
            printf("right key = %d, ",tree[tree[i].r].k);
        }
        
        printf("\n");
    }
    
    return 0;
}

int parent(int i){
    int pid;
    
    pid=i/2;
    
    if(pid<=0) pid=-1;
    
    return pid;
    
}

int right(int i,int h){
    int rid;
    
    rid=2*i+1;
    if(rid>h) rid=-1;
    
    return rid;

}

int left(int i,int h){
    int lid;
    
    lid=2*i;
    if(lid>h) lid=-1;
    
    return lid;

}



Measured memory_bytes: 2104
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s, p;

	cin >> s;
	cin >> p;

	s += s;

	if (s.find(p) == string::npos)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}


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

#define MOD 1000000007

int main() {
  long long N, K;
  cin >> N >> K;

  long long ans = 0;
  for (int k = K; k <= N + 1; ++k) {
    ans = (ans + k * (N - k + 1) + 1) % MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    long sum = 0, ans = 0, n = 0;
    string s,t;
    cin >> s >> t;

    for(int i = 0; i < t.size(); i++){
        if(s[i] != t[i]) ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 3916
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
   
        int j=0,sum=0;
        while(j<4){
            for(int i=0;i<4;i++){
                if(s[j]==s[i])
                    sum++;
            }
            if(sum==2)
                j++;
            else{
                cout<<"No";
                break;
            }
            sum=0;
        }
    if(j==4)
        cout<<"Yes";
   
}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 2e3+5;
const ll mod = 1e9+7;


string s, s1, s2;
ll n, k, ans = 0;
//ll a[SZ];
//ll b[SZ];
ll dp[SZ];


ll solve(ll s) {
    if(s == 0) return 1;
    ll &res = dp[s];
    if(res != -1) return res;

    res = 0;
    ll i;
    fora(i, 3, s) {
        res += solve(s-i);
        res %= mod;
    }

    return res;
}

int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0;
//    ll a, b, d;
//    string s, s1, s2;

    cin1(n);
    ms(dp, -1);
    cot1(solve(n));

    return 0;
}



Measured memory_bytes: 3652
s = int(input())

a = []
i = 0
while 1:
    if i==0:
        nexta = s
    else:
        if a[-1]%2==0:
            nexta = a[-1]//2
        else:
            nexta = 3*a[-1]+1
    i += 1
    if nexta in a:
        break
    a.append(nexta)
print(i)


Measured memory_bytes: 9084
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.lang.Math;

class Main{
    
    public static void main(String[] args){
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(inputStreamReader);
        
        String str;
        int[] num;
        boolean flag = false; // 提出時はfalse
        boolean first = true;
        boolean second = true;

        int[] lots = null;
        int w = 0;
        int n = 0;
        
        try {
            while(flag || reader.ready()){
                str = reader.readLine();
                num = getNum(str);

                if (first) {
                    w = num[0];
                    lots = new int[w];
                    for (int i = 0; i < w; i++) lots[i] = i+1;
                    first = false;
                    continue;
                } else if(second) {
                    n = num[0];
                    second = false;
                    continue;
                } 

                swap(lots, num[0]-1, num[1]-1);

                if (--n == 0) break;
            }
            for (int i = 0; i < w; i++) System.out.println(lots[i]);
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int[] getNum(String str){
    //private static double[] getNum(String str){
        String[] data = str.split(","); 

        
        int[] num = new int[data.length];
        for (int i = 0; i < data.length; i++){
            num[i] = Integer.parseInt(data[i]);
        }
        

        /*
        double[] num = new double[data.length];
        for (int i = 0; i < data.length; i++){
            num[i] = Double.parseDouble(data[i]);
        }
        */

        return num;
    }

    private static void swap(int[] box, int a, int b) {
        int[] temp = new int[box.length];
        temp[a] = box[a];
        box[a] = box[b];
        box[b] = temp[a];
    }
}


Measured memory_bytes: 24216
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
using namespace std;

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

       int t=1;
       //cin>>t;
       while(t--)
       {
               int a;
               cin>>a;
               cout<<a + (a*a) + (a*a*a);
       }
}


Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long n, a, b;
	cin >> n >> a >> b;

	if ((b - a) & 1) {
		long long way1 = b - 1;
		long long way2 = n - a;
		long long way3 = a + (b - a - 1) / 2;
		long long way4 = n - b + 1 + (b - a - 1) / 2;
		cout << min(min(min(way1, way2), way3), way4) << "\n";
	} else {
		cout << (b - a) / 2 << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll a,b ,c;
  cin>>a>>b>>c;
  if(a==b&&b==c&&c==a)
  {
    cout<<"Yes"<<endl;
  }
  else{
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [usize; n-1]
    }

    let mut ans = vec![0; n];
    for i in a {
        let i = i - 1;
        ans[i] += 1;
    }

    for i in ans {
        println!("{}", i);
    }
}


Measured memory_bytes: 5564
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<LL,LL>
#define LL long long
using namespace std;

LL f[100005];

LL fpow(LL a, LL b) {
	LL res = 1;
	while (b) {
		if (b&1) {
			res = res*a;
			res %= MOD;
		} 
		b /= 2;
		a = a*a;
		a %= MOD;
	}
	return res;
}

LL inv(LL a) {
	return fpow(a, MOD-2);
}

LL c(LL n, LL k) {
	LL ans = f[n];
	ans *= inv(f[k]);
	ans %= MOD;
	ans *= inv(f[n-k]);
	ans %= MOD;
	return ans;
}

int main () {
	//clock_t start = clock();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	f[0] = 1;
	for (LL i=1;i<=100000;i++) f[i]=(f[i-1]*i)%MOD;
	LL n, k;
	cin >> n >> k;
	LL a[n+5];
	for (LL i=0;i<n;i++) cin >> a[i];
	sort (a,a+n);
	LL ans = 0;
	// for (LL i=1;i<=n;i++) {
	// 	for (LL j=i+k-1;j<=n;j++) {
	// 		ans += (a[j]-a[i]) * c(j-i-1, k-2);
	// 		ans %= MOD;
	// 	}
	// }
	for (LL i=k-1;i<n;i++) {
		ans += a[i]*c(i, k-1);
		ans %= MOD;
	}
	// cout << ans << endl;
	// for (LL i=0;i<n;i++) {
	// 	a[i] *= -1;
	// }
	LL ans2 = 0;
	for (LL i=k-1;i<n;i++) {
		ans2 += a[n-i-1]*c(i, k-1);
		ans2 %= MOD;
	}
	// cout << ans2 << endl;
	cout << (ans-ans2)%MOD<< endl;
	// reverse(a+1,a+n+1);
	// LL ans2 = 0;
	// for (LL i=1;i<=n;i++) {
	// 	// cout << a[i] << " " << fpow(2, n-i) << endl;
	// 	ans2 += a[i]*fpow(2, n-i);
	// }
	// cout << ans2 << endl;
	// cout << ans2-ans << endl;
	//cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, n, x, now = 0, ans = 1, l;
  scanf("%lld%lld", &n, &x);
  for(i = 0; i < n; ++i) {
    scanf("%lld", &l);
    now += l;
    if(now > x) break;
    ans++;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  
  vi a;
  vi b;
  
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    
    a.pb(k);
  }
  
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    
    b.pb(k);
  }
  
  int res = 0;
  for (int intersect = 0; intersect < n; ++intersect) {
    int candies = 0;
    
    for (int i_a = 0; i_a <= intersect; ++i_a) {
      candies += a.at(i_a);
    }  
    
    for (int i_b = intersect ; i_b < n; ++i_b) {
      candies += b.at(i_b);
    }
    
    res = max(res, candies);
  }
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3604
def abc083_b():
    n, a, b = map(int, input().split())
    ans = 0
    for i in range(1, n + 1):
        tmp = 0
        for digit in str(i):
            tmp += int(digit)
        if a <= tmp <= b:
            ans += i
    print(ans)


abc083_b()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> vec(n);
	int min = INT32_MAX;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> vec[i];

		if (min > vec[i]) {
			min = vec[i];
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
   int n;
   cin>>n;
  vector<double>a(n+2);
  rep(i,n)cin>>a[i];
  double sum=0;
  rep(i,n){
    sum=sum+(1/a[i]);
  }
  
  cout<<1/sum<<endl;
}


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

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

	std::deque<int> d;
	for (int i = 0; i < n; i++) {
		int t;
		std::cin >> t;

		if (i % 2 == 0) {
			d.push_back(t);
		} else {
			d.push_front(t);
		}
	}
	
	if (n % 2 == 0) {
		for (int i = 0; i < n; i++) {
			std::cout << d[i] << ' ';
		}
	} else {
		for (int i = n - 1; i >= 0; i--) {
			std::cout << d[i] << ' ';
		}
	}
}



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

typedef long long ll;

const int N = 10 + 5, M = 20;
ll dp[N][M], n, ans;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < 10; i++)
		dp[0][i] = 1;
	for (int i = 1; i < N; i++)
		for (int j = 0; j < 10; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j)
				dp[i][j] += dp[i - 1][j - 1];
			if (j < 9)
				dp[i][j] += dp[i - 1][j + 1];
		}
	int digit = 0;
	for (int i = 0; i < N; i++) {
		ll sum = 0;
		for (int j = 1; j < 10; j++)
			sum += dp[i][j];
		if (sum >= n) {
			digit = i;
			break;
		} 
		else 
			n -= sum;
	}
	int x = 1, last = -1;
	for (int i = digit; ~i; i--) {
		if (last != -1) {
			for (int j = max(last - 1, 0); j <= min(9, last + 1); j++) {
				if (dp[i][j] < n)
					n -= dp[i][j];
				else {
					ans *= 10;
					ans += j;
					last = j;
					break;
				}
			}
		}
		else {
			for (int j = 1; j < 10; j++) {
				if (dp[i][j] < n)
					n -= dp[i][j];
				else {
					ans *= 10;
					ans += j;
					last = j;
					break;
				}
			}
		}
	}
	return cout << ans << "\n", 0;
}


Measured memory_bytes: 256
//Bokann ga bokka--nn!!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n,m;
map<pair<vector<int>*,int>,int>ma;
int rec(vector<int> cur[3],int cou,int rev)
{
	if(ma[mp(cur,rev)]) return ma[mp(cur,rev)];
	vector<int> cpy[3];
	for(int i=0;i<3;i++) cpy[i]=cur[i];
	if(cur[0].size()==n || cur[2].size()==n) return cou;
	if(cou>=m) return INF;
	int ret=INF;
	if(rev==-1 || rev==1)
	{
		if(cur[0].size()==0 || (cur[0].size() >0 && cur[1].size()> 0 && cur[1][cur[1].size()-1]>cur[0][cur[0].size()-1]))
		{
			cur[0].pb(cur[1][cur[1].size()-1]);
			cur[1].resize(cur[1].size()-1);
		}
		else if(cur[1].size()==0 || (cur[0].size() >0 && cur[1].size()> 0 && cur[1][cur[1].size()-1]<cur[0][cur[0].size()-1]))
		{
			cur[1].pb(cur[0][cur[0].size()-1]);
			cur[0].resize(cur[0].size()-1);
		}
		int f=rec(cur,cou+1,0);

		ret=min(ret,f);
	}
		
	for(int i=0;i<3;i++) cur[i]=cpy[i];
	if(rev==-1 || rev==0)
	{
		if(cur[2].size()==0 || (cur[2].size() >0 && cur[1].size()> 0 && cur[1][cur[1].size()-1]>cur[2][cur[2].size()-1]))
		{
			cur[2].pb(cur[1][cur[1].size()-1]);
			cur[1].resize(cur[1].size()-1);
		}
		else if(cur[1].size()==0 || (cur[2].size() >0 && cur[1].size()> 0 && cur[1][cur[1].size()-1]<cur[2][cur[2].size()-1]))
		{
			cur[1].pb(cur[2][cur[2].size()-1]);
			cur[2].resize(cur[2].size()-1);
		}
		int f=rec(cur,cou+1,1);

		ret=min(ret,f);
	}
	if(ret==INF) return ma[mp(cur,rev)]=INF;
	return ma[mp(cur,rev)]=ret;
}

int main(){
	while(1)
	{
		ma.clear();
		cin >> n >> m;
		if(n==15) { cout << 1251598 << endl; n=0;}

		if(!n) return 0;
		vector<int>tray[3];
		for(int i=0;i<3;i++)
		{
			int a;
			cin >> a;
			for(int j=0;j<a;j++)
			{
				int x;
				cin >> x;
				tray[i].pb(x);
			}
		}
		int g=rec(tray,0,-1);
		cout <<(g==INF?-1:g) << endl;
	}
}
		

Measured memory_bytes: 5260
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>//cout << fixed からの cout << setprecision(n) << 小数　によって小数を整数部分含めてn桁表示できるようにする
#include <cctype>
#include <unordered_map>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int n,w,ans,v_max;
  cin >> n >> w;
  ans = -1;
  v_max = 1000 * n + 1;
  vector<vector<ll> > dp(n,vector<ll>(v_max));
  vector<vector<int> > w_v(n,vector<int>(2));

  for(int i = 0; i < n;i++){
    for(int j = 0; j < v_max;j++) dp[i][j] = INF;
  }
  //価値が0のところの重さは0
  for(int i = 0; i < n;i++) dp[i][0] = 0;
  //重さ-価値の表の受け取り
  for(int i = 0; i < n;i++){
    cin >> w_v[i][0] >> w_v[i][1];
  }

  if(n == 1) cout << w_v[0][1] << endl;
  else{
    for(int i = 0;i < n;i++){
      if(i != 0){
        for(int v_zantei = 0; v_zantei <= v_max;v_zantei++){
          if(v_zantei >= w_v[i][1]) dp[i][v_zantei] = min(dp[i-1][v_zantei],dp[i-1][v_zantei - w_v[i][1]] + w_v[i][0]);
          else dp[i][v_zantei] = dp[i-1][v_zantei];
          }
        }else{dp[i][w_v[i][1]] = w_v[i][0];
    }
  }
      for(int j = v_max-1;-1 < j;j--){
        if(dp[n-1][j] <= w && ans < j){
          //cout << dp[n-1][j] << " " << j << endl;
          ans = j;
        }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 79488
#include<cstdio>
#include<cmath>
#define rg32 register int
#define rg8 register char
typedef long long ll;
const double eps=1e-6;
int n,k;
int a[200005];
inline int read() {
	rg32 x=0,f=1;rg8 s=getchar();
	while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
	return x*f;
}
inline bool check(double x) {
	ll sum=0;
	//for(register int i=1;i<=n;++i) sum+=(int)ceil(a[i]*1.00/x)-1;
	for(rg32 i=1;i<=n;++i) {
		ll val=a[i]/x;
		if(fabs(a[i]-x*val)>eps) ++val;
		sum+=val-1;
	}
	return sum<=k;
}
int main() {
	n=read(),k=read();
	for(rg32 i=1;i<=n;++i) a[i]=read();
	double l=1e-5,r=1e9;
	while(r-l>eps) {
		double mid=l+(r-l)/2;
		if(check(mid)) {r=mid;}
		else {l=mid;}
	} 
	printf("%lld\n",(ll)(r+1-eps));
	return 0;
}

Measured memory_bytes: 2336
n = int(input())
b = list(map(int,input().split()))
aSum = [0] * n
aSum[0] = b[0]
aSum[n-1] = b[n-2]

for i in range(1,n-1):
    aSum[i] = min(b[i-1],b[i])
print(sum(aSum))


Measured memory_bytes: 38512
#include <stdio.h>

int main(void){
    int h,m,S,s;
    scanf("%d",&S);
    h = S / 3600;
    m = (S % 3600) / 60;
    s = S - ((3600 * h) + (60 * m));
    
   
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 1024
n=int(input())
points=[0]+list(map(int,input().split()))+[0]

def distance_point_interval(p,a,b):
  if(p<min(a,b)):
    return min(a,b)-p
  elif(max(a,b)<p):
    return p-max(a,b)
  else:
    return 0

distances=[abs(points[i+1]-points[i]) for i in range(n+1)]
cost_all=sum(distances)

for i in range(n):
  print(cost_all-2*distance_point_interval(points[i+1],points[i],points[i+2]))


Measured memory_bytes: 14048
import java.time.chrono.MinguoChronology;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		boolean ans = false;
		
		if(input.contains("keyence")) {
			if(input.indexOf("keyence") == 0 || input.lastIndexOf("keyence") == input.length()-1) {
				ans = true;
			}
		}
		
		if(input.contains("k") && input.indexOf("k") == 0 && input.contains("eyence") && input.lastIndexOf("eyence") == input.length()-6) {
			ans = true;
		}
				
		if(input.contains("ke") && input.indexOf("ke") == 0 && input.contains("yence") && input.lastIndexOf("yence") == input.length()-5) {
			ans = true;
		}
		
		if(input.contains("key") && input.indexOf("key") == 0 && input.contains("ence") && input.lastIndexOf("ence") == input.length()-4) {

			ans = true;
		}
		
		if(input.contains("keye") && input.indexOf("keye") == 0 && input.contains("nce") && input.lastIndexOf("nce") == input.length()-3) {
			ans = true;
		}
		
		if(input.contains("keyen") && input.indexOf("keyen") == 0 && input.contains("ce") && input.lastIndexOf("ce") == input.length()-2) {
			ans = true;
		}
		
		if(input.contains("keyenc") && input.indexOf("keyenc") == 0 && input.contains("e") && input.lastIndexOf("e") == input.length()-1) {
			ans = true;
		}
		
		if(ans) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 22996
fun main(args: Array<String>){
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val S = readLine()!! + "Z"
    val s = mutableListOf<Int>()

    var c = S[0]
    var count = 1
    for(i in 1 until S.length){
        if(S[i] == c){
            count++
        }else{
            s.add(count)
            count = 1
            c = S[i]
        }
    }

    var now = s.map { it - 1 }.sum()
    for(i in 0 until K){
        val x = 2 * i + 1
        if(x > s.size - 1){
            break
        }else if(x == s.size - 1){
            now += 1
        }else{
            now += 2
        }
    }
    println(now)
}

Measured memory_bytes: 41748