akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define END (64)
#define EMPTY (-2)
#define WALL (-1)
int px[24],py[24],kx,ky;
int H,W,N;
int field[12][12];

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

map<int,int> memo[24];

int dfs(int pos , int bit , bool done[12][12]){
	if(memo[pos].find(bit) != memo[pos].end() ) return memo[pos][bit];
	
	
	// SÌÆÉHÁ½ã³ïÉAêé©Ç¤©
	if(bit == (1<<N)-1){
		rep(d,4){
			int cx = px[pos]+dx[d] , cy = py[pos]+dy[d];
			while( field[cy][cx] != WALL){
				if(field[cy][cx] == END) return 1;
				cy += dy[d] , cx += dx[d];
			}
		}
		return 0;
	}
	
	// »êÈOÈçHÁÄÈ¢ÆÅÅÉ·éÆð©Â¯éB
	int ans = 0;
	rep(d,4){
		int cx = px[pos]+dx[d] , cy = py[pos]+dy[d];
		while( field[cy][cx] == EMPTY || field[cy][cx] == END || done[cy][cx] == true ){
			cy += dy[d] , cx += dx[d];
		}
		if(field[cy][cx] != -1){
			done[cy][cx] = 1;
			ans += dfs(field[cy][cx] , bit | (1<<field[cy][cx]) , done);
			done[cy][cx] = 0;
		}
	}
	
	// HÁ½ÆÌª19¢ÈçéB(Îô)
	if(__builtin_popcount(bit) < 19)
		memo[pos][bit] = ans;
	return ans;
}

int main(){
	while(cin >> W >> H ,W){
		// ú»
		N = 0;
		rep(i,12)rep(j,12)field[i][j] = WALL;
		
		// üÍ
		rep(i,H)rep(j,W){
			int t;
			cin >> t;
			switch(t){
			case 0:
				field[i+1][j+1] = EMPTY;
				break;
			case 1:
				field[i+1][j+1] = N;
				px[N] = j+1, py[N] = i+1;
				N++;
				break;
			case 2:
				kx = j+1 , ky = i+1;
				field[i+1][j+1] = END;
				break;
			}
		}
		px[N] = kx , py[N] = ky;
		
		// Tõ
		rep(i,24) memo[i].clear();
		bool done[12][12]={{false}};
		cout << dfs(N,0,done) << endl;
	}
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int X, Y, Z;
int V[10];
P event[100];
double dp[100][6000];

double rec(int p, int m){
    if(p >= Y){
        return m;
    }

    if(dp[p][m] >= 0){
        return dp[p][m];
    }

    double ev = 0;

    for(int i=0;i<X;++i){
        int np = p + V[i];

        int e, a;
        std::tie(e, a) = event[np];

        if(e == -1){
            ev += 1. / X * rec(np, m);
        }else if(e == 1){
            ev += 1. / X * rec(np + a, m);
        }else if(e == 2){
            ev += 1. / X * rec(np, m + a);
        }else if(e == 3){
            ev += 1. / X * rec(np, std::max(m - a, 0));
        }
    }

    return dp[p][m] = ev;
}

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

    while(true){
        std::cin >> X >> Y >> Z;

        if(X == 0){
            break;
        }

        for(int i=0;i<X;++i){
            std::cin >> V[i];
        }

        std::fill(event, event + 100, std::make_tuple(-1, -1));

        for(int i=0;i<Z;++i){
            int N, E, A;
            std::cin >> N >> E >> A;

            event[N] = std::make_tuple(E, A);
        }

        std::fill(&dp[0][0], &dp[0][0] + 100 * 6000, -1);

        double ev = rec(0, 0);
        std::cout << floor(ev) << std::endl;
    }
}



Measured memory_bytes: 7944
#  --*-coding:utf-8-*--

def main():
    N,K,S = map(int, input().split())

    k = (S+1) if S != 10**9 else 3
    A = [str(S)]*K + [str(k)]*(N-K)
    print(' '.join(A))

    

if __name__ == '__main__':
    main()


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

int main() {
	int s[5];
	for(int i=0; i<5; i++) cin >> s[i];
	
	int sm=10;
	int cnt=0;
	for(int i=0; i<5; i++){
		if(sm>s[i]%10&&0!=s[i]%10){
			sm=s[i]%10;
			cnt=i;
		}
	}
	
	for(int i=0; i<5; i++){
		if(i!=cnt&&s[i]%10!=0) s[i]=(s[i]/10+1)*10;
		else continue;
	}
	
	int sum=0;
	for(int i=0; i<5; i++) sum+=s[i];
	
	cout << sum << endl;

}

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

const int N=2e5+10;

char s[N];

int main()
{
    scanf("%s",s);
    int t=0;
    for(int i=0;s[i]!='\0';i++) t=(t+s[i]-'0')%9;
    if(t) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 3832
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

a,b,c = sorted(I())
ans = 0
a += c-b
ans += c-b
if (c-a)%2==0:
    print(ans+(c-a)//2)
else:
    print(ans+(c-a)//2 +2)


Measured memory_bytes: 10052
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
long long M = 1e9+7;
long long power(long long a, long long p)
{
    if(p==0) return 1;
    long long ans= power(a,p/2);
    ans =(ans * ans) % M;
    if(p%2) ans = (ans*a) % M;
    return ans;
}

bool isPrime(long long n)
{
    if (n <= 1)
        return false;
    for (long long i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
long long SieveOfEratosthenes(long long n, long long a)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (long long p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (long long p=2; p<=n; p++)
       if (prime[p])
       {
           if(a%p==0)
           {
               return (a-p);
           }
       }
}
long long nCr(int n, int r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}
int vis[51][51];
int x[]={1,0,0,-1};
int y[]={0,1,-1,0};
void dfs_visit(long long n,long long a, long long b)
{
    vis[a][b]=1;
    for(int i=0; i<4; i++)
    {

        int p=a+x[i];
        int q=b+y[i];
        if(p>=0 && p<n && q>=0 && q<n && vis[p][q]==0)
        {
           // cout<<p<<" "<<q<<endl;
            vis[p][q]=1;
            dfs_visit(n,p,q);
        }
    }
}

int main()
{
    IOS;
    double a,b,c,d,e,h,l,n,t,f,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    long long a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,b6;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3,str4,str5,str6;
    char ch,ch1;
    //vector<long long>v; //vector<long long> v(n+1);
    //vector<long long>v1;
   // vector<string>vs;
   // vector<string>vs1;
    vector<char>vc;
    //map<long long,long long>mp;
    map<char,int>mp1;
    //set<long long>s;
    set<long long>s1;
    //list<char>li;
    queue<long long> q;
    //stack<long long> stk;
    //vector< pair<long long,long long> >v3;
    //map<long long,long long>::iterator it;
    //map<string,string>::iterator it;
   // vector<pair<char, pair<int,int> > > v3;
    //vector< pair<char,int > > v1;
    //int x[]={1,1,1,0,0,-1,-1,-1};
    //int y[]={0,1,-1,1,-1,1,-1,0};
    //int x[]={1,0,0,-1};
    //int y[]={0,1,-1,0};
    cin>>n;
    printf("%.20lf\n",2*pi*n);
    return 0;
}


Measured memory_bytes: 3848
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[10];
int main()
{
	int n,a1=0,a2=0,a3=0,a4=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		if(s[0]=='A')a1++;
		  else if(s[0]=='W')a2++;
		  else if(s[0]=='T')a3++;
		  else if(s[0]=='R')a4++;
	}
	printf("AC x %d\n",a1);
	printf("WA x %d\n",a2);
	printf("TLE x %d\n",a3);
	printf("RE x %d\n",a4);
	return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
    ll n,k;
    cin >> n >> k;
    vector<pair<int,int>> pr(n);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        pr[i].first = a;
        pr[i].second = b;
    }
    sort(pr.begin(),pr.end());
    int ans;
    for(int i=0;i<n;i++){
        k-=pr[i].second;
        if(k<=0){
            ans = pr[i].first;
            break;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 4024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Main
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int arr[] = new int[n];
        long totalSum = 0;
        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            totalSum += arr[i];
            map.put(arr[i], map.getOrDefault(arr[i],0) + 1);
        }

        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int b = sc.nextInt();
            int c = sc.nextInt();

            if(!map.containsKey(b)){
                System.out.println(totalSum);
                continue;
            }
            int bCount = map.get(b);
            long remSum = (long)bCount * b;
            long resSum = totalSum - remSum + c * (long)bCount;

            System.out.println(resSum);
            totalSum = resSum;

            map.remove(b);
            map.put(c, bCount + map.getOrDefault(c,0));
        }

    }
}

Measured memory_bytes: 60832
#include <bits/stdc++.h>
#define int long long
using namespace std;

int ma(int a,int b,int c){
	return max(a,max(b,c));
}

int mi(int a,int b,int c){
	return min(a,min(b,c));
}

int solve(int H,int W){
	int ans=10000000000;
	if(W>2){
		//cout<<"?"<<endl;
		if(W%3==0)ans=min(0LL,ans);
		else ans=min(ans,H);
	}
	if(H%2==0){
		if(W%3==0)ans=min(ans,0LL);
		else ans=min(ans,H/2);
	}
	if(H%2==1){
		for(int t=1;t<=W;t++){
			int S1=H*t;
			int S2=(W-t)*(H+1)/2;
			int S3=(W-t)*(H-1)/2;
			ans=min(ans,ma(S1,S2,S3)-mi(S1,S2,S3));
		}
	}
	return ans;
}

signed main(){
	int H,W; cin>>H>>W;
	int a=solve(H,W);
	int b=solve(W,H);
	// cout<<a<<endl;
	// cout<<b<<endl;
	cout<<min(a,b)<<endl;

}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for i in a:
  if sum([j * k for j, k in zip(i, b)]) + c > 0:
    cnt += 1
print(cnt)

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

int main() {
  char  c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
  cout << "vowel";
  else
  cout << "consonant";

}


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

using namespace std;
const int maxn = 5005;
typedef long long ll;
int dp[2][maxn],sum[maxn];
int main() {
	int n,mod,rt = 0;
	cin>>n>>mod;
	dp[rt][0] = 1;
	for(int i = 1;i < n;++i) {
		rt ^= 1;
		int s = i;
		if(n%2 == 1&& s > n/2 + 1) s = (n-i+1);
		if(n%2 == 0 && s > n/2) s = (n-i+1);
		memset(dp[rt],0,(n+1)<<2);
		for(int j = 0;j < n; ++j) {
			ll temp = 0;
			int k = 0;
			for(k = 0;k < n&&j-(k+16)*s>=0; k += 16) {
				temp += dp[rt^1][j-k*s];
				temp += dp[rt^1][j-(k+1)*s];
				temp += dp[rt^1][j-(k+2)*s];
				temp += dp[rt^1][j-(k+3)*s];
				temp += dp[rt^1][j-(k+4)*s];
				temp += dp[rt^1][j-(k+5)*s];
				temp += dp[rt^1][j-(k+6)*s];
				temp += dp[rt^1][j-(k+7)*s];
				temp += dp[rt^1][j-(k+8)*s];
				temp += dp[rt^1][j-(k+9)*s];
				temp += dp[rt^1][j-(k+10)*s];
				temp += dp[rt^1][j-(k+11)*s];
				temp += dp[rt^1][j-(k+12)*s];
				temp += dp[rt^1][j-(k+13)*s];
				temp += dp[rt^1][j-(k+14)*s];
				temp += dp[rt^1][j-(k+15)*s];
			}
			for(;k < n &&j - k*s >= 0; ++k) temp += dp[rt^1][j-k*s];
			dp[rt][j] = temp%mod;
		}
	}
	ll ans = 0;
	for(int i = 0;i < n; ++i) {
		int j = n-i-1;
		ans += 1ll*(j+1)* dp[rt][i];
		ans %= mod;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs

local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while primepos <= prime_num and dv <= lim do
    if x % dv == 0 then
      local t = {}
      t.p = dv
      t.cnt = 1
      x = x / dv
      while x % dv == 0 do
        x = x / dv
        t.cnt = t.cnt + 1
      end
      table.insert(tmp, t)
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    local t = {}
    t.p, t.cnt = x, 1
    table.insert(tmp, t)
  end
  return tmp
end

local function getdivisorCore(divisorparts)
  local t = {}
  local pat = 1
  local len = #divisorparts
  local allpat = 1
  for i = 1, len do
    allpat = allpat * (1 + divisorparts[i].cnt)
  end
  for t_i_pat = 0, allpat - 1 do
    local div = allpat
    local i_pat = t_i_pat
    local ret = 1
    for i = 1, len do
      div = mfl(div / (divisorparts[i].cnt + 1))
      local mul = mfl(i_pat / div)
      i_pat = i_pat % div
      for j = 1, mul do
        ret = ret * divisorparts[i].p
      end
    end
    table.insert(t, ret)
  end
  -- table.sort(t)
  return t
end

local function getdivisor(x, primes)
  local dvp = getdivisorparts(x, primes)
  return getdivisorCore(dvp)
end

local n = io.read("*n")
-- n = k^a * (bk + 1)
-- n = 1000 * 1000 * 1000 * 1000
-- 2 <= a
local a = 1
local ret = 0
while true do
  a = a + 1
  if n < (2^a) then break end
  local k = 1
  while true do
    k = k + 1
    local ka = 1
    for i = 1, a do
      ka = ka * k
    end
    if n < ka then
      --print(a, k, ka)
      break
    end
    if n % ka == 0 then
      local rem = mfl(n / ka)
      if rem % k == 1 then ret = ret + 1 end
    end
  end
end
-- a == 1
-- a == 1 and 0 < b
for k = 2, 1000000 do
  if k * k <= n then
    if n % (k * k) == k then ret = ret + 1 end
  end
end
-- a == 1 and b == 0
if 2 < n then ret = ret + 1 end
-- a == 0
if 2 < n then
  local primes = getprimes(1000000)
  local divisor = getdivisor(n - 1, primes)
  -- print(table.concat(divisor, " "))
  ret = ret + #divisor - 1
end
if n == 2 then print(1)
else
  print(ret)
end


Measured memory_bytes: 9600
a = gets.split
a[0] = a[0].to_i
a[1] = a[1].to_i
if a[0]>a[1] then
	print "a > b\n"
elsif a[0]==a[1] then
	print "a == b\n"
elsif a[0]<a[1] then
	print "a < b\n"
end

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

struct slide_min {
    using data = int;
    std::deque<std::pair<int, data>> deq;
    int c, w;
    slide_min(int w) : c(0), w(w) {}
    data query(data d) {
        while(!deq.empty() && deq.front().first <= c - w) deq.pop_front();
        while(!deq.empty() && deq.back().second >= d) deq.pop_back();
        deq.push_back(make_pair(c++, d));
        return deq.front().second;
    }
};

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> dp(W + 1);
    for(int i = 0; i < N; ++i) {
        int v, w, m;
        cin >> v >> w >> m;
        for(int j = 0; j < w; ++j) {
            slide_min sm(m + 1);
            for(int k = 0; k * w + j <= W; ++k) {
                int val = -dp[k * w + j] + k * v;
                dp[k * w + j] = -sm.query(val) + k * v;
            }
        }
    }
    cout << dp[W] << endl;
}


Measured memory_bytes: 3252
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i = 0; i < N; ++i) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        System.out.println(solve(A, B, M));

        sc.close();
    }

    static long solve(int[] A, int[] B, int M) {
        int[] sortedIndices = IntStream.range(0, A.length).boxed().sorted((i1, i2) -> Integer.compare(A[i1], A[i2]))
                .mapToInt(x -> x).toArray();

        long result = 0;
        for (int index : sortedIndices) {
            int count = Math.min(B[index], M);
            result += (long) A[index] * count;

            M -= count;
        }

        return result;
    }
}

Measured memory_bytes: 60760
import java.io.*;
import java.util.*;
/**
 * Main
 */
public class Main {
       static int mod  = 1000000007;
        static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) {
       MyScanner ms  = new MyScanner();
       long A = ms.nextLong();
       long B = ms.nextLong();
       long C = ms.nextLong();
       long K =ms.nextLong();
       long sum=0;
       if(K>0){
        if(A>K)
        sum+=K;
        else
        sum+=A;
        K-=A;
       }
       if(K>0){
           K-=B;
       }
       if(K>0){
        if(C>K)
        sum-=K;
        else
        sum-=C;
           K-=C;
       }
       pw.println(sum);
    pw.flush();

    }public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 32780
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main(void)
{
	vector <int> v;
	int score, n, sum;
	cin >> n;

	sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> score;
		v.push_back(score);
		sum += v[i];
	}
	sort(v.begin(), v.end());

	if (sum % 10 != 0)
	{
		cout << sum << endl;
	}
	else
	{
		for (int i = 0; i < v.size(); i++)
		{
			sum -= v[i];
			if (sum % 10 != 0)
			{
				cout << sum << endl;
				return 0;
			}
			else
			{
				sum += v[i];
			}
		}
		sum = 0;
		cout << sum << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(int, a, b);

    int sum = 1;
    reps(i, 0, 100) {
        if (sum >= b) {
            print(i);
            return 0;
        }

        --sum;
        sum += a;
    }

    return 0;
}


Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    vector<int> v(n,0),c(n,0);
    rep(i,n) cin>>v[i];
    rep(i,n) cin>>c[i];
    rep(i,n)if(v[i]-c[i]>=0) ans+=v[i]-c[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define MOD 1000000007;
using namespace std;

bool inSet(const vector<int> &set, const int &num) {
	for (auto const &val: set) 
		if (val == num) return true;
	return false;
}

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

    int n {3};
    vector<int> set {};
    while (n--) {
    	int num {};
    	cin >> num;
    	if (!inSet(set, num)) {
    		set.push_back(num);
    	}
    }
    cout<<((set.size() == 2) ? "Yes": "No")<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	// your code goes here
	
	int i,n,k;
	double dice[200001];
	double sum =0, max = 0;
	int a;
	
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		dice[i] = (a+1.0)/2;
		sum = sum + dice[i];
		if(i>=k)
			sum = sum - dice[i-k];
		if(max<sum)
			max = sum;
			
		
	}
	printf("%.12f",max);
	return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

#define MAX_NUM (1000000)

char prime[MAX_NUM + 1];

void make_prime()
{
	for (int i = 0; i < MAX_NUM + 1; i++){
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;
	
	for (int i = 2; i * i < MAX_NUM; i++){
		if (prime[i] == 1){
			for (int j = 2; j * i <= MAX_NUM; j++){
				prime[j * i] = 0;
			}
		}
	}
}

int main(void)
{
	int n;
	int cnt;
	
	make_prime();
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		cnt = 0;
		for (int i = 3; i <= n / 2; i++){
			if (prime[i] == 1 && prime[n - i] == 1){
				cnt++;
			}
		}
		
		printf("%d\n", cnt);
	}
	
	return (0);
}

Measured memory_bytes: 0
N = int(input())
a = list(map(int,input().split()))
a = sorted(a)
sai = max(a)
ma = 100000000000000000000000000
naka = sai / 2
for i in range(N):
    sa = abs(naka - a[i])
    if ma > sa:
       ma = sa
       kore = a[i]
print(sai,kore)

Measured memory_bytes: 14428
# coding: utf-8
 
def is_prime2(q,k=100):
  q = abs(q)
  if q == 2: return True
  if q < 2 or q&1 == 0: return False
  for i in range(3,k):
    x,y = q,i
    while y:
      x, y =  y, x % y
    if x != 1: continue
    if pow(i, q-1, q) != 1:
      return False
  return True
 
X = int(input())
 
for i in range(X,10**5+4):
  if is_prime2(i):
    print(i)
    exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
signed main(){
  vector<int> alpha[30];
  int loop=0,h,l,m,now=-1,siz,len;
  string s,t;
  cin>>s;
  for(int i=0;i<s.size();i++){
    alpha[s[i]-'a'].push_back(i);
  }
  
  cin>>t;
  
  for(int i=0;i<t.size() && loop != -1;i++){
    len=t[i]-'a' , siz=alpha[len].size();
 
    if(siz == 0){
      loop=-1;
    } 
    
    else {
      if(now >= alpha[len][siz-1]){
        loop++;
        now=alpha[len][0];
      } 
      else {
        h=siz-1,l=0,m=(h+l)/2;
        while(h-l > 0){
          if(now<alpha[len][m]){
            h=m;
          } else {
            l=max(l+1,m);
          }
          m=(h+l)/2;
        }
        now=alpha[len][h];
      }
    }
  }
  
  if(loop == -1){
    cout<<"-1\n";
  } else { 
    cout<<loop*s.size()+now+1<<endl;
  }
      
  return(0);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define pb push_back
#define x first
#define y second
#define pii pair<int,int>

const int mod = 1e9+7;

int main()
{
	IOS
	string s;
	cin>>s;
	int cnt[2]={0,0};
	int i;
	for(i=0;i<3;i++)
		cnt[s[i]-'A']++;
	if(cnt[0] && cnt[1])
		cout<<"Yes";
	else
		cout<<"No";
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int t,ts[33];
int n;
int plan[111];

int dp[111][33];

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>t;
		if(t==0)break;
		rep(i,t)cin>>ts[i];
		cin>>n;
		rep(i,111)plan[i]=INF;
		rep(i,n){
			int d,m;
			cin>>d>>m;
			d--;
			plan[d]=min(plan[d],m);
		}
		rep(i,111)rep(j,33)dp[i][j]=INF;
		dp[0][0]=0;
		rep(i,101)rep(j,t){
			if(dp[i][j]==INF)continue;
			if(plan[i]>=ts[j]){
				minch(dp[i+1][(j+1)%t],dp[i][j]);
			}
			minch(dp[i+1][1],dp[i][j]+1);
		}
		int res=INF;
		rep(i,33)minch(res,dp[101][i]);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 3108
# ABC133D
N = int(input())
A = list(map(int,input().split()))

x = [0 for i in range(N)]

cnt = 0
for i in range(N):
    if i % 2 == 0:
        cnt += A[i]
    else:
        cnt -= A[i]
x[0] = cnt/2

for i in range(1,N):
    x[i] = A[i-1]-x[i-1]
    #print(x,A)

L = [str(int(i*2)) for i in x]
print(' '.join(L))

Measured memory_bytes: 20552
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
//using namespace atcoder;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> size;
    UnionFind(int N): par(N),size(N) {

         //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++){
            par[i] = i;
            size[i] = -1;
        }
            
    }
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        size[ry] += size[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int getsize(int x){
        return -size[root(x)];
    }
    int getNunion(){//これちょっと遅い sameと組み合わせて順次数えていけば早くなりそう。
        map<int,int> m;
        rep(i,par.size()){
            m[this->root(i)]++;
        }
        return int(m.size());
    }
};

int main(){
    ll N,M;
    cin >> N >> M;
    ll a,b;
    UnionFind tr(N);
    rep(i,M){
        cin >> a >> b;
        a--;b--;
        tr.unite(a,b);
    }
    cout << tr.getNunion() - 1 << endl;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int use[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

int main()
{
  int n, m;
  int a[9];
  cin >> n >> m;
  REP(i, m)
  {
    int tmp;
    cin >> tmp;
    a[i] = tmp - 1;
  }
  sort(a, a + m, greater<int>());

  int dp[10000];
  REP(i, n + 1)
  {
    dp[i] = -1;
    if (i == 0)
    {
      dp[i] = 0;
      continue;
    }
    REP(j, m)
    {
      int c = use[a[j]];
      if (c <= i)
      {
        if (dp[i - c] >= 0 && dp[i] < dp[i - c] + 1)
        {
          dp[i] = 1 + dp[i - c];
        }
      }
    }
  }

  int result[5000];
  int count = n;
  int length = 0;
  REP(i, dp[n])
  {
    REP(j, m)
    {
      int c = use[a[j]];
      if (count - c >= 0)
      {
        if (dp[count - c] == dp[n] - length - 1)
        {
          count -= c;
          length++;
          result[length - 1] = a[j] + 1;
          break;
        }
      }
    }
  }

  REP(i, length)
  {
    cout << result[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
# 整数の入力
N = int(input())

# 桁数が奇数である整数をカウントする変数
count = 0

# 各数を文字列に変換して桁数を求め、奇数であるか判定
for i in range(1, N + 1):
    if len(str(i)) % 2 != 0:
        count = count + 1
        
print("{}".format(count))

Measured memory_bytes: 2940
import java.util.Scanner;

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

    private void bPlusMinusA() {
        try (Scanner scan = new Scanner(System.in)) {
            int a = Integer.parseInt(scan.next());
            int b = Integer.parseInt(scan.next());
            if (b % a == 0) {
                System.out.println(a + b);
            } else {
                System.out.println(b - a);
            }
        }
    }
}


Measured memory_bytes: 21844
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = (ll)1e9+7;
//}}}

int A[200000];
int a[200001];
int main(){
  int N, K;
  cin >> N >> K;
  rep(i, N) cin >> A[i];
  rep(i, N){
    a[A[i]]++;
  }
  int count = 0;
  rep(i, N + 1){
    if(a[i] == 0){
      count++;
      a[i] = N + 1;
    }
  }
  sort(a, a + N + 1);
  int num = N + 1 - count - K;
  int ans = 0;
  rep(i, num){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}


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

int n,a[100010],dp[100010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[1]=0;dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++){
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#define int long long
 
// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

std::string yes = "Yes\n";
std::string no = "No\n";

void solve();

signed main() {
  solve();
  return 0;
}

void solve() {
  int a, b;
  std::cin >> a >> b;
  cout((a+b)%24);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int cnt[50];
int main()
{
	for (int i=0;i<3;i++)
	{
		int a,b;
		cin>>a>>b;
		cnt[a]++;cnt[b]++;
	}
	if (*max_element(cnt+1,cnt+5)>2) puts("NO");
	else puts("YES");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;
	vll A(N);
	ll sum = 0;
	vll B(N);
	rep(i, 0, N) {
		std::cin >> A[i];
		sum += A[i] - i - 1;
		B[i]=A[i] - i - 1;
	}
	sort(B.begin(), B.end());

	ll b;
	if (N & 1) {
		b = B[N / 2];
	}
	else {
		b = (B[N / 2] + B[N / 2 - 1])/2;
	}

	ll ans = 0;
	rep(i, 0, N) {
		ans += abs(A[i] - i - 1 - b);
	}

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


Measured memory_bytes: 3328
'use strict'
function main(input) {
  // お決まりの処理
  const tmp = input.split('\n');
  const info = tmp[0].split(' ').map((elem) => parseInt(elem, 10));
  const N = info[0];
  const K = info[1];
  const h = tmp[1].split(' ').map((elem) => parseInt(elem, 10));
  
  // 動的計画法にお決まりの必要な配列を作って満たす処理
  let dp = new Array(N).fill(Infinity);
  // 最初は0
  dp[0] = 0;
  for(let i = 0; i < N; i++){
      for(let j = 0; j <= K; j++){
        if(i-j >= 0) {
          dp[i] = Math.min(dp[i],dp[i-j] + Math.abs(h[i] - h[i - j])); 
        }
      }
  }
  console.log(dp[N - 1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 27732
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    string A,B,C;
    cin >> A >> B >> C;
    cout << A[0] << B[0] << C[0] << endl;
}

Measured memory_bytes: 256
N = list(map(int, list(input())))
ans = 0

for i in range(len(N) - 1, -1, -1):
    if N[i] > 9:
        if i > 0:
            N[i - 1] += 1
        else:
            ans += 1
    elif N[i] == 5 and i > 0:
        if N[i - 1] >= 5:
            ans += 5
            N[i - 1] += 1
        else:
            ans += N[i]
    elif N[i] < 6:
        ans += N[i]
    else:
        if i > 0:
            N[i - 1] += 1
            ans += 10 - N[i]
        else:
            ans += 10 - N[i] + 1

print(ans)


Measured memory_bytes: 21348
using System;
using System.Linq;

class C
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Read();
		var b = Read();

		int i = 0, j = 0, c = 0;
		new Perm<int>().Find(Enumerable.Range(1, n).ToArray(), n, p =>
		{
			++c;
			if (p.SequenceEqual(a)) i = c;
			if (p.SequenceEqual(b)) j = c;
		});
		Console.WriteLine(Math.Abs(i - j));
	}
}

class Perm<T>
{
	T[] v, p;
	bool[] u;
	Action<T[]> act;

	public void Find(T[] _v, int r, Action<T[]> _act)
	{
		v = _v; p = new T[r]; u = new bool[v.Length]; act = _act;
		if (p.Length > 0) Dfs(0); else act(p);
	}

	void Dfs(int i)
	{
		for (int j = 0; j < v.Length; ++j)
		{
			if (u[j]) continue;
			p[i] = v[j];
			u[j] = true;
			if (i + 1 < p.Length) Dfs(i + 1); else act(p);
			u[j] = false;
		}
	}
}


Measured memory_bytes: 17376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 123456789012
#define MAX_V 9000

struct edge{ll to,cost;};
typedef pair<ll,ll> P;
ll d[MAX_V];
ll V;
vector<edge> G[MAX_V];

edge makeedge(ll t,ll c){
    edge e;
    e.to=t;
    e.cost=c;
    return e;
}

void addedge(ll s,ll t,ll c){
    G[s].push_back(makeedge(t,c));
    //G[t].push_back(makeedge(s,c)); //双方向
}

void dijkstra(ll s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s)); 

    while(!que.empty()){
        P p=que.top(); que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        for(ll i=0;i<G[v].size();i++){
            edge &e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}



int main(){
    ll i,j;
    ll n,m;
    cin>>n>>m;

    ll N=(1<<n);
    V=N;
    for(i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        ll h=0;
        for(j=0;j<b;j++){
            int c;
            cin>>c;
            c--;
            h+=(1<<c);
        }
        for(j=0;j<N;j++){
            addedge(j,j|h,a);
        }
    }
    dijkstra(0);
    if(d[N-1]<INF) cout<<d[N-1]<<endl;
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 66432
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

const int MAX = 5000, MAXD = 32;
int n, k, p[MAX], c[MAX], ans = -INF;
ii A[MAX][MAXD];

signed main() {
	cin >> n >> k;
	FOR(i, n) {
		cin >> p[i];
		p[i]--;
	}
	FOR(i, n) cin >> c[i];
	FOR(i, n) A[i][0].fi = p[i], A[i][0].se = c[p[i]];
	for (int i = 1; i < MAXD; i++) FOR(j, n) {
		A[j][i].fi = A[A[j][i - 1].fi][i - 1].fi;
		A[j][i].se = A[j][i - 1].se + A[A[j][i - 1].fi][i - 1].se;
	}
	FOR(i, n) {
		int cur = i, cnt = 0, kk = k;
		FOR(j, min(MAX, kk)) {
			cur = p[cur];
			cnt += c[cur];
			ans = max(ans, cnt);
		}
		kk -= min(MAX, kk);
		if (kk - MAX >= 0) {
			for (int i = MAXD - 1; i >= 0; i--) {
				if ((kk - MAX) & (1 << i)) {
					cnt += A[cur][i].se;
					cur = A[cur][i].fi;
				}
			}
			ans = max(ans, cnt);
			kk = MAX;
		}
		FOR(j, min(MAX, kk)) {
			cur = p[cur];
			cnt += c[cur];
			ans = max(ans, cnt);
		}
	}
	cout << ans;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(a) for (ll i = 0; i < a; i++)
#define fio                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define mn 0;
#define mx 10000;


int main()
{
    fio;
    ll n;
    cin>>n;
    ll arr[n];
    f(n){cin>>arr[i];}
    ll f[n];
    f[0]=0;
    f[1]=abs(arr[0]-arr[1]);
    for(ll i=2;i<n;i++)
    {
        f[i]=min((abs(arr[i]-arr[i-2])+f[i-2]),(abs(arr[i]-arr[i-1])+f[i-1]));
    }
    cout<<f[n-1];



    return 0;
}



Measured memory_bytes: 5112
import collections


def read_nums():
    return map(int, raw_input().split(' '))


H, W, N = read_nums()

vs = []
for i in range(-1, 2):
    for j in range(-1, 2):
        vs.append((i, j))

cnt = []
for i in range(N):
    a, b = read_nums()
    for v in vs:
        i, j = v
        x = a + i
        y = b + j
        if x >= 2 and x <= H-1 and y >= 2 and y <= W-1:
            cnt.append(x * W + y)

cnt = collections.Counter(cnt)
cnt2 = [0] * 10
cnt2[0] = (H - 2) * (W - 2)

for k in cnt:
    cnt2[cnt[k]] += 1
    cnt2[0] -= 1

for c in cnt2:
    print c


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


public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while(true){
			int cnt = s.nextInt();
			if(cnt==0)
				break;
			int[] times = new int[cnt];
			for(int i=0 ; i<cnt ; i++) {
				times[i] = s.nextInt();
			}
			Arrays.sort(times);
			System.out.println(solve(times));
		}
	}

	public static long solve(int[] times) {
		long sumWaitTime = 0;
		long waitT = 0;
		for(int i=0 ; i<times.length-1 ; i++) {
			waitT += times[i];
			sumWaitTime += waitT;
		}
		return sumWaitTime;
	}
}

Measured memory_bytes: 45084
n=int(input())
a=sorted([int(input()) for i in range(n)])
tmp = a[0]
rank= 1
ans = 0
for i in a[1:]:
    if i == tmp:
       rank += 1
    else:
        tmp = i
        ans += rank%2
        rank = 1
ans += rank%2
print(ans)

Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m;
  cin>>n>>m;
  int arr[n];
  for(int i=0;i<n;i++){
  	cin>>arr[i];
  }
  int sum=0;
  for(int i=0;i<n;i++){
  	sum+=arr[i];
  }
  int d=4*m;
  int score;
   if(sum&1==1){
   	   score=(sum/d) +1 ;
   }
   else{
   	 score=sum/d ;
   }
   int count=0;
   for(int i=0;i<n;i++){
  	if(arr[i]>=score){
  		count++ ;
  	}
  }
  if(count>=m){
  	cout<<"Yes"<<endl;
  }
  else{
  	cout<<"No"<<endl;
  }
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int sockets = 1;
    while (sockets < b)
    {
        ans++;
        sockets = sockets - 1 + a;
    }
    cout << ans << endl;
    return 0;
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

ll knapSack(ll W,ll wt[],ll val[],ll n)
{
    ll i, w;
    ll K[n + 1][W + 1];

    // Build table K[][] in bottom up manner
    for (i = 0; i <= n; i++) {
        for (w = 0; w <= W; w++) {
            if (i == 0 || w == 0)
                K[i][w] = 0;
            else if (wt[i - 1] <= w)
                K[i][w] = max(
                    val[i - 1] + K[i - 1][w - wt[i - 1]],
                    K[i - 1][w]);
            else
                K[i][w] = K[i - 1][w];
        }
    }

    return K[n][W];
}
int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
       ll n,w;
       cin>>n>>w;
       ll val[n],ww[n];
       loop(i,0,n-1) cin>>ww[i]>>val[i];
       cout<<knapSack(w,ww,val,n);
    }
    return 0;
}


Measured memory_bytes: 82496