akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int s[n];
    int sum = 0;
    int t = 0;
    int cnt = 101;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        sum += s[i];
        if(s[i] % 10 != 0){
            t = 1;
        }
        if(s[i] % 10 != 0){
            cnt = min(cnt,s[i]);
        }
    }
    if(sum % 10 != 0){
        cout << sum;
    }else if(t == 0){
        cout << 0;
    }else{
        cout << sum - cnt;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const lint mod = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };

struct RollingHash {
	const _ulong MASK30 = (1ULL << 30) - 1;
	const _ulong MASK31 = (1ULL << 31) - 1;
	const _ulong MOD = (1ULL << 61) - 1;
	const _ulong MASK61 = MOD;

	vector<_ulong> hashed, power;

	RollingHash(const string& s, _ulong base) {
		int sz = SZ(s);
		hashed.assign(sz + 1, 0);
		power.assign(sz + 1, 0);
		power[0] = 1;
		for (int i = 0; i < sz; i++) {
			power[i + 1] = mul(power[i], base);
			hashed[i + 1] = mul(hashed[i], base) + s[i];
			if (hashed[i + 1] >= MOD) hashed[i + 1] -= MOD;
		}
	}

	//乱数生成、main関数にコピペする
	void generate_base() {
		_ulong base;
		{
			//乱数生成
			random_device seed_gen;
			mt19937 engine(seed_gen());
			uniform_real_distribution<> dist1(129, INT_MAX);
			base = dist1(engine);
		}
	}

	_ulong get(int l, int r) const {
		_ulong ret = hashed[r] + MOD - mul(hashed[l], power[r - l]);
		if (ret >= MOD) ret -= MOD;
		return ret;
	}

	//a*b mod 2^61-1を返す関数
	inline _ulong mul(_ulong a, _ulong b) const {
		_ulong u_a = a >> 31;//aの31bit以降
		_ulong d_a = a & MASK31;//aの31bit未満
		_ulong u_b = b >> 31;
		_ulong d_b = b & MASK31;

		_ulong mid = d_a * u_b + u_a * d_b;
		_ulong u_mid = mid >> 30;
		_ulong d_mid = mid & MASK30;
		return CalcMod(u_a * u_b * 2 + u_mid + (d_mid << 31) + d_a * d_b);
	}

	//mod 2^61-1を返す関数
	inline _ulong CalcMod(_ulong x) const {
		_ulong u_x = x >> 61;
		_ulong d_x = x & MASK61;
		_ulong res = u_x + d_x;
		if (res >= MOD) res -= MOD;
		return res;
	}
};

string rev(string s) {
	string tmp = s;
	REP(i, SZ(s) / 2) {
		tmp[i] = s[SZ(s) - i - 1];
		tmp[SZ(s) - i - 1] = s[i];
	}
	return tmp;
}

map<_ulong, lint> mp;
int main() {
	_ulong base;
	{
		//乱数生成
		random_device seed_gen;
		mt19937 engine(seed_gen());
		uniform_real_distribution<> dist1(129, INT_MAX);
		base = dist1(engine);
	}
	
	lint N;
	cin >> N;
	vector<string> arr(N);
	string s;
	REP(i, N) {
		cin >> s; 
		arr[i] = rev(s);
	}
	sort(ALL(arr), [&](string a, string b) {return SZ(a) < SZ(b); });
	lint ans = 0;
	REP(i, N) {
		RollingHash rh(arr[i], base);
		lint sz = SZ(arr[i]);
		lint cnt[26] = { 0 };
		REP(j, sz) {
			cnt[arr[i][j] - 'a']++;
		}
		REP(j, sz) {
			REP(k, 26) {
				if (cnt[k] == 0) continue;
				if ((mp[rh.get(0, j)] & (1ull << k)) != 0) ans++;
			}
			cnt[arr[i][j] - 'a']--;
		}
		lint msk = (1ull << (arr[i][sz - 1] - 'a'));
		mp[rh.get(0, sz - 1)] |= msk;
	}
	cout << ans << endk;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> primes, ans{2};
  primes.push_back(2);
  for (int i = 3; i <= 55555; i += 2) {
    for (auto p: primes) {
      if (i % p == 0) break;
      if (i < p * p) {
        primes.push_back(i);
        if (i % 5 == 1) ans.push_back(i);
        break;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i];
    if (i < n - 1) cout << " ";
    else cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 int A[100005],B[100005],dp[100005][1],i,n,sum,say,k;

int main()
{
	
	
	
	scanf("%d %d",&n,&k);
	say= n/(2*k+1);
	if(n%(2*k+1)!=0){
		say++;
	}
	
		
		
	
	
	printf("%d\n",say);
	
	

	
	return 0;
}

Measured memory_bytes: 256
s = list(input())
p = list(input())
li = [i for i, x in enumerate(s) if x == p[0]]
ans = False
for l in li:
    i = l
    for check in p:
        if not s[i] == check:
            break
        i = (i+1) % len(s)
    else:
        ans = True
        break
if ans:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.*;
import java.util.ArrayList;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static int cnt=0;
	static ArrayList<Integer> G = new ArrayList<Integer>();

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		int N = Integer.parseInt(br.readLine());
		int[] A = new int[N];
		for(int i=0;i<N;i++){
			A[i] = Integer.parseInt(br.readLine());
		}
		int tmp = 1;
		while(tmp<=N){
			G.add(tmp);
			tmp=3*tmp+1;
		}
		int m =shellSort(A,N);
		System.out.println(m);
		tmp = 1;
		for(int i=m-1;i>=0;i--){
			if(i<m-1)
				System.out.print(" ");
			System.out.print(G.get(i));
		}
		System.out.print("\n");
		System.out.println(cnt);
		for(int i=0; i<N;i++){
			System.out.println(A[i]);
		}

	}
	
	static int shellSort(int[] A,int n){
		int m;
		m = G.size();
		for(int i=m-1; i>=0;i--)
			insertionSort(A, n, G.get(i));
		return m;
	}
	
	static void insertionSort(int[] A, int n, int g){
		int v,j;
		for(int i=g;i<n;i++){
			v = A[i];
			j=i-g;
			while (j>=0 && A[j] >v){
				A[j+g]=A[j];
				j=j-g;
				cnt++;
			}
			A[j+g] = v;

		}
	}
}

Measured memory_bytes: 107068
s=list(str(input()))
s1=int("".join(s[:2]))
s2=int("".join(s[2:]))
if s1>0 and s1<= 12:
    if s2>0 and s2<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if s2>0 and s2<=12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
  input! {
    n: u32,
  };

  println!("{0}", n.pow(3));
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#define f(i,n)for(int i=0;i<n;i++)
#define s (scanf("%d",&e),e)
int main(){
	int a=0,w,n,m,b,e,d[99];
	f(i,99){
		d[i]=0;
	}
	n=s;
	m=s;
	if(n==0)exit(0);
	f(i,m){
		w=0;
		b=0;
		f(j,n){
			s;
			if(e){
				f(k,3){
					e=d[j+k];
					if(e&&e-w){
						if(w){
							f(l,n+2){
								d[l]=d[l]==e?w:d[l];
							}
							a--;
						}
						else{
							w=e;
						}
					}
				}
				if(w==0){
					a++;
					w=i*n+j+1;
				}
			}
			else{
				w=0;
			}
			d[j]=b;
			b=w;
		}
		d[n]=b;
		w=0;
	}
	printf("%d\n",a);
	main();
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n, ans = 0, i, temp;
    cin >> n;
    for (i = 1; i < n; i++)
    {
        temp = n / i;
        if (n % i == 0)
            temp--;
        ans += temp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

#define ll long long
#define VEC2(type, name, dim0, dim1, init_val) vector<vector<type>> name(dim0, vector<type>(dim1, init_val))
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name)

#define REP(name, start, end) for(ll name = (start); (name) < (end); ++(name))
#define REPR(name, end, start) for(ll name = (start - 1); (name) >= (end); --(name))
#define ALL(iterable) (iterable).begin(), (iterable).end()

template<typename _T> void OutIter(_T beg, _T end, string separator = " ", bool eol = true) {
	cout << *beg;
	for (auto it = beg + 1; it != end; ++it) {
		cout << separator << *it;
	}
	if(eol)cout << endl;
}

int main()
{
	cout << fixed << setprecision(6);
	IN(ll, n);
	IN(ll, k);
	IN(string, s);

	vector<pair<ll, ll>> range;

	ll lidx = 0;
	REP(i, 1, n){
		if (s[i - 1] != s[i]) {
			range.push_back(make_pair(lidx, i - 1));
			lidx = i;
		}
	}
	range.push_back(make_pair(lidx, n - 1));

	pair<ll, ll> longest(0, 0);
	if (k * 2 >= range.size()) {
		longest.first = 0;
		longest.second = n - 1;
	}
	else {
		REP(i, k * 2, range.size()) {
			if (longest.second - longest.first < (range[i].second - range[i - k * 2].first)) {
				longest.first = range[i - k * 2].first;
				longest.second = range[i].second;
			}
		}
	}

	ll cnt = 0;
	if (longest.first > 0 && s[0] == s[1] && s[0] == 'R')++cnt;
	if (longest.second < n - 1 && s[n - 1] == s[n - 2] && s[n - 1] == 'L')++cnt;
	REP(i, 1, n - 1) {
		if (i < longest.first || i > longest.second) {
			if (s[i] == s[i + 1] && s[i] == 'R')++cnt;
			if (s[i] == s[i - 1] && s[i] == 'L')++cnt;
		}
	}
	cnt += longest.second - longest.first;

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <math.h>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;


int main() {
	int m, k;
	cin >> m >> k;
	if (k < pow(2, m)) {
		if (m == 0) {
			cout << "0 0" << endl;
		}
		else if (m == 1) {
			if (k == 0) {
				cout << "0 0 1 1" << endl;
			}
			else {
				cout << "-1" << endl;
			}
		}
		else {
			rep(i, pow(2,m)) {
				if(i != k) cout << i << " ";
			}
			cout << k << " ";
			for (int i = pow(2, m) - 1; i >= 0; i--) {
				if(i != k) cout << i << " ";
			}
			cout << k << endl;
		}
	}
	else {
		cout << "-1" << endl;
	}


	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    string a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( a.at(0) != a.at(1) || a.at(1) != a.at(2) ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << ((floor(a / 2) + fmod(a, 2)) / a) << endl;
    
    return 0; 
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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


    if(a+b <= 2*c){
        cout << a*x + b*y << endl;
    }
    else{
        if(x <= y){
            int ans = 0;
            ans += 2*c*x;
            ans += min((y-x)*b, 2*c*(y-x));
            cout << ans << endl;
        }
        else{
            int ans = 0;
            ans += 2*c*y;
            ans += min((x-y)*a, (x-y)*2*c);
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
using namespace std;
vector< vector< vector< vector<int> > > >d( 22 , vector< vector< vector<int> > >( 22 , vector< vector<int> >( 22 , vector<int>( 22 , 10000) ) ) );
string a[22];
const int fx1[4]={-1,1,0,0};
const int fx2[4]={0,0,-1,1};
signed main()
{
	int n,m;
	cin>>n>>m;
	int ans=-1;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			if (a[i][j]=='#')  continue;
			d[i][j][i][j]=0;
			queue<pair<int , int> >que;
			que.push(make_pair(i,j));
			while (sz(que)){
				pair<int , int> fr=que.front();
				que.pop();
				for (int k=0;k<4;k++){
					if (fr.first+fx1[k]<n && fr.first+fx1[k]>=0 && fr.second+fx2[k]<m && fr.second+fx2[k]>=0 && d[i][j][fr.first+fx1[k]][fr.second+fx2[k]]==10000 && a[fr.first+fx1[k]][fr.second+fx2[k]]=='.'){
						d[i][j][fr.first+fx1[k]][fr.second+fx2[k]]=d[i][j][fr.first][fr.second]+1;
						ans=max(ans , d[i][j][fr.first+fx1[k]][fr.second+fx2[k]]);
						que.push( make_pair( fr.first+fx1[k] , fr.second+fx2[k] ) );
					}
				}
			}/*
			for (int k=0;k<n;k++){
				for (int l=0;l<m;l++){
					cout<<d[i][j][k][l];
				}
			}*/
		}
	}
	cout<<ans; 
	re 0;
}


Measured memory_bytes: 1536
package main

import "fmt"

var S, T [2000000]int
var n, q int

func main() {
	var count int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&S[i])
	}
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&T[i])
	}
	for j := 0; j < q; j++ {
		count += binarySearch(T[j])
	}
	fmt.Println(count)
}
func binarySearch(key int) int {
	left := 0
	right := n
	var mid int
	for left < right {
		mid = (left + right) / 2
		if S[mid] == key {
			return 1
		} else if key < S[mid] {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return 0
}



Measured memory_bytes: 10628
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5&&b==5&&c==7)
        printf("YES\n");
    else if(a==5&&b==7&&c==5)
        printf("YES\n");
     else if(a==7&&b==5&&c==5)
        printf("YES\n");
        else
            printf("NO\n");
   return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <stdio.h>
using namespace std;
int main(){
	int a, b;
	char op;
	while (1){
		cin >> a >> op >> b;
		if (op == '+'){
			cout << a + b << endl;
		}
		else if (op == '-'){
			cout << a - b << endl;
		}
		else if (op == '*'){
			cout << a* b << endl;
		}
		else if (op == '/'){
			cout << a / b << endl;
		}
		else if (op == '?')break;
	}
	return 0;
}

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

int main(){
  int N,M,ans ;
  cin >> N >> M;
  ans = 0;
  vector<int> yes(M);

  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    vector<int> v(x);
    for(int j=0; j<x; j++){
      cin >> v.at(j);
    }
    for(int l=1;l<M+1;l++){
  for(int k=0; k<x; k++){
    if(v.at(k)==l)
      yes.at(l-1)++;
    else
      continue;
  }
}
}
 for(int m=0; m<M;m++){
   if(yes.at(m)==N)
     ans ++;
     else
     continue;
   }
  cout << ans << endl;
 }

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
r=[0]*(n+1)
for i in range(n):
    r[i+1]=r[i]+l[i]
ans=10**10
for i in range(1,n):
    a=r[i]
    b=s-r[i]
    ans=min(ans,abs(a-b))
print(ans)

Measured memory_bytes: 89680
#include <iostream>
#include <cstdlib>
#include <list>
using namespace std;

int main() {
    list<int>L; int n, x; char s[15];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        if (s[0] == 'i')cin >> x,  L.push_front(x);
        else if (s[6] == 'F')L.pop_front();
        else if (s[6] == 'L')L.pop_back();
        else {
            cin >> x;
            for (list<int>::iterator it = L.begin(); it != L.end(); it++)
                if (*it == x) {
                    L.erase(it); break;
                }
        }

    }
    n = 0;
    for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
        if (n++)cout << " ";
        cout << *it;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 34316
#include<iostream>
#include<string.h>

using namespace std;
#define         ll              long long
#define         f(i,a,b)        for(ll i=a;i<b;i++)
#define         pb              push_back

ll power(ll x,ll y)
{
    ll res = 1;
    while (y > 0)
    {       if (y & 1)
            res = res*x;
            y = y>>1;
            x = x*x;
    }
    return res;
}


int main()
{

    string s,t;cin>>s>>t;ll cnt=0;
    f(i,0,s.length()){if(s[i]!=t[i])cnt++;}
    cout<<cnt;
}


Measured memory_bytes: 3480
import java.util.*;

class Main {
    public static int gcd(int a, int b) {
        if (a < 0 || b < 0) {
            return -1;
        }
        if (b == 0) {
            return a;
        }
        while (a % b != 0) {
            int temp = a % b;
            a = b;
            b = temp;
        }
        return b;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        long sum = 0;

        for(int i = 1; i<= input; i++) {
            for(int p = 1; p <= input; p++) {
                for(int q = 1; q <= input ; q ++){
                    sum += gcd(gcd(i,p),q);
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 35828
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
int a[10010]={0};
int b[10010]={0};
int ans=1001,w;
void kotani(int i,int j,int c,int n);
int main(){
	while(1){
	int n;
	scanf("%d",&n);
		w=n;
		ans=n;
		if(n==0)break;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		for(int j=1;j<=3;j++){
			memcpy(b,a,sizeof(int) *n);
			if(b[i]!=j){
				b[i]=j;
				kotani(0,1,1,n);
			}
		}
	}
	printf("%d\n",ans);
	}
}
void kotani(int i,int j,int c,int n){
	if(b[i]==b[j]&&j<n){
		kotani(i,j+1,c+1,n);
	}
	else{
		if(c>=4){
			int u=0;
			for(int z=j;z<n;z++){
				b[i+u]=b[z];
				u++;
			}
			ans=min(ans,n-c);
			kotani(0,1,1,n-c);
		}
		else if(i+1<n){
			kotani(i+1,i+2,1,n);
		}
	}
}

Measured memory_bytes: 3292
import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    private static Scanner sc = new Scanner(new BufferedInputStream(System.in));

    public static void main(String[] args) {
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] a = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            a[i] = sc.nextInt();
        }

        HashMap<Integer, Integer> mymap = new HashMap<>();
        HashMap<Integer, Integer> mymap2 = new HashMap<>();
        int cur = 1;
        int jump = 0;
        while (mymap.get(cur) == null) {
            mymap.put(cur, jump);
            mymap2.put(jump, cur);
            jump += 1;
            cur = a[cur];
        }
        int temp = mymap.get(cur);

        int num = mymap.size();

        if (K < temp) {
            int ans = (int)K;
            System.out.println(mymap2.get(ans));
        } else {
            int ans = (int) ((K - temp) % (num - temp));
            ans = mymap2.get(ans + temp);
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 82076
s = input('')
t = input('')

slen = len(s)
tlen = len(t)

sone = ''

small = 0

if slen != tlen:
    for i in range(slen-tlen):
        sone = s[i:i+tlen]
        count = 0
        for e in range(tlen):
            if sone[e] != t[e]:
                count = count + 1
        if i == 0:
            small = count
        else:
            if count <= small:
                small = count
else:
    sone = s
    count = 0
    for e in range(tlen):
        if sone[e] != t[e]:
            count = count + 1
    small = count

print(small)


Measured memory_bytes: 82020
n = gets.to_i

a = []
n.times do
  a.push readline.strip
end

r = a.group_by(&:itself)
max = r.max_by{|k, v|v.size}[1].size

r.keys.sort.each do |k|
  if r[k].size == max
    puts k
  end
end

Measured memory_bytes: 57832
def calc_gcd(x, y):
    
    if x < y:
        x, y = y, x

    while y > 0:
        x, y = y, x % y

    return x


a, b = map(int, input().split())

gcd = calc_gcd(a, b)

x1 = 1
y1 = 0
z1 = a_prime = a / gcd

x2 = 0
y2 = 1
z2 = b_prime = b / gcd

while z2 != 1:
    q = (z1 - (z1 % z2)) / z2

    (x1, y1, z1), (x2, y2, z2) = (x2, y2, z2), (x1 - (q * x2), y1 - (q * y2), z1 - (q * z2))


t = 0
x = x2 + b_prime * t
y = y2 + a_prime * t

print(int(x), int(y))


Measured memory_bytes: 5608
def modpow(x,n)
  ret = 1
  while n > 0
    ret = (ret * x) % MOD if n&1 == 1
    x = (x*x) % MOD
    n >>= 1
  end
  return ret
end

def fact(n)
  @memo ||= []
  @memo[n] ||= (n==0) ? 1 : (n * fact(n-1)) % MOD;
end

def combin(n,k)
  return (((fact(n) * modpow(fact(n-k),MOD-2)) % MOD) * modpow(fact(k),MOD-2)) % MOD
end
MOD = 10**9 + 7

200000.times do |i|
  fact(i)
end


n,a,b,c = gets.split.map(&:to_i)
na = 1
nb = 1
ta = (a * modpow(100-c,MOD-2)) % MOD
tb = (b * modpow(100-c,MOD-2)) % MOD

pa = modpow(ta,n)
pb = modpow(tb,n)
#p [pa,modpow(16,MOD-2)]
ans = 0
n.upto(n*2-1) do |i|
  x = combin(i-1,n-1)
  ans += i * x * pa * nb
  ans %= MOD
  ans += i * x * pb * na
  ans %= MOD
  
  #p [i,x]
  #p [(i*x*pa*nb/modpow((i.gcd(x).gcd(pa).gcd(nb)),4)) % MOD]
  #p [(x*pb*na) % MOD]

  na *= ta
  na %= MOD

  nb *= tb
  nb %= MOD
end

=begin test
testa = [1,1,5,5]
testb = [8,4,16,16]
testc = []
4.times do |i|
  x,y = testa[i],testb[i]
  p (x * modpow(y,MOD-2)) % MOD
end
=end
ans = ans * 100 * modpow(100-c,MOD-2) % MOD if c != 0
p ans

Measured memory_bytes: 3528
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}

ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100000+5;

int n;
int h[N];
int memo[N];

int main(){
	ri(n);
	for(int i=1; i<=n; i++){
		ri(h[i]);
	}
	memo[1] = 0;
	for(int i=2; i<=n; i++){
		memo[i] = INT_MAX;
		if(i-1 >= 1){
			memo[i] = min(memo[i],memo[i-1]+abs(h[i]-h[i-1]));
		}
		if(i-2 >= 1){
			memo[i] = min(memo[i],memo[i-2]+abs(h[i]-h[i-2]));
		}
	}
	cout << memo[n] << endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.buffer.readline

n,A,B,C = map(int,input().split())
L = []
for _ in range(n):
    L.append(int(input()))

res = 10**9

for i in range(4**n):
    flag = i
    a,b,c,tmp = 0,0,0,0
    for j in range(n):
        flag,now = divmod(flag,4)
        if now == 1:
            if a != 0:
                tmp += 10
            a += L[j]
        elif now == 2:
            if b != 0:
                tmp += 10
            b += L[j]
        elif now == 3:
            if c != 0:
                tmp += 10
            c += L[j]
    if a*b*c == 0:
        continue

    tmp += abs(A-a) + abs(B-b) + abs(C-c)

    res = min(res,tmp)

print(res)

Measured memory_bytes: 74344
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long int ll;
const int MOD=1000000007;

int main(){
    int h,w;cin>>h>>w;
    int n;cin>>n;
    vector<int> a(n);
    queue<int> clr;
    int c[h][w];
    rep(i,n){
        cin>>a[i];
        rep(j,a[i])clr.push(i+1);
    }
    
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                int cl = clr.front();clr.pop();
                c[i][j] = cl;
            }
        }else{
            for(int j = w-1;j>=0;j--){
                int cl = clr.front();clr.pop();
                c[i][j] = cl;
            }
        }

    }
    rep(i,h){
        rep(j,w)cout<<c[i][j]<<" ";
        cout<<endl;
    }
    return 0;
}

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

int main(){
  int n,x=0,y=0;
  cin>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
    y+=p[i];
  }
  for(int i=0;i<n;i++){
    x=max(x,p[i]);
  }
  if(x>=y-x){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int l, r, d;
  cin >> l >> r >> d;
  ll ans = 0;
  rep(i,l,r+1) if (i%d==0) ++ans;
  cout << ans << '\n';
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main()
{
  int a,b,c;
  while(cin >> a >> b >> c){
    if(a + b < 16) cout << "YES" << endl;
    else if(a + b > 16) cout << "NO" << endl;
    else if(c <= 4) cout << "NO" << endl;
    else cout << "YES" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<vector<ll>> edge(N);
    for (ll i = 0; i < N; i++) {
        string S;
        cin >> S;
        for (ll j = 0; j < N; j++) {
            if (S[j] == '1') {
                edge[i].push_back(j);
            }
        }
    }

    ll ans = 0;

    for (ll i = 0; i < N; i++) {

        queue<ll> q;
        vector<ll> V(N, -1);
        q.push(i);
        V[i] = 1;
        while (!q.empty()) {
            auto f = q.front();
            q.pop();
            for (ll next_node : edge[f]) {
                if (V[next_node] == -1) {
                    V[next_node] = V[f] + 1;
                    q.push(next_node);
                } else if (V[next_node] != V[f] - 1 && V[next_node] != V[f] + 1) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }

        ans = max(ans, *max_element(V.begin(), V.end()));
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val k, x = sc.nextInt
    sc.close()

    val min = x - k + 1
    val max = x + k - 1
    val ans = (min to max).toList.mkString(" ")
    println(ans)
  }
}

Measured memory_bytes: 27308
#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 repr(i,a,b) for(int i=(int)(a-1);i>=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 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;

#define INF INT_MAX/3

int main() {
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  int a, ans = 0;
  rep(i, n) {
    cin >> a;
    while(a % 2 == 0) ans++, a /= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
ttt = list(map(int, input().split()))

time = 0
for i in range(N):
    if(i==N-1):
        time += T
        break
    if(ttt[i+1]-ttt[i]<=T):
        time += ttt[i+1]-ttt[i]
    else:
        time += T
        
print(time)

Measured memory_bytes: 25200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=1000000007;
ll ans=0;
vector<ll> dp(100100, 999); 

int main()
{
ll n;
cin >> n;
dp[0]=0;
ll dp9[6]={9,81,729,6561,59049,531441};
ll dp6[]={6,36,216,1296,7776,46656,279936};
for(ll i = 0; i < 100001; i++){
    rep(j,6){
        if(i+dp9[j]<100001){
            dp[i+dp9[j]]=min(dp[i+dp9[j]],dp[i]+1);
        }
    }
    rep(j,7){
        if(i+dp6[j]<100001){
            dp[i+dp6[j]]=min(dp[i+dp6[j]],dp[i]+1);
        }
    }
    dp[i+1]=min(dp[i+1],dp[i]+1);
}
cout << dp[n] << endl;
return 0;
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
	int n, k;
	ll ans = 0;
	cin >> n >> k;
	deque<int> d;
	rep(i, n){
		int t;
		cin >> t;
		d.push_back(t);
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; i + j <= min(n,k); j++){
			// cout << i << " " << j;
			deque<int> tmp = d;
			// cout << " copied";
			ll st = 0;
			int vt[100] = {};
			rep(x, i){
				vt[x] = tmp.front();
				tmp.pop_front();
			}
			// cout << " poped";
			rep(x, j){
				vt[x + i] = tmp.back();
				tmp.pop_back();
			}
			// cout << " poped";
			sort(vt, vt + (i+j));
			rep(x, n){
				if(x < k - (i+j)){
					st += max(vt[x], 0);
				}else if(x < min(k, n)){
					st += vt[x];
				}
				// cout << " " << vt[x];
			}
			if(st > ans) ans = st;
			// cout <<  " " << st << " " << ans << endl;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P)[::-1]
Q = sorted(Q)[::-1]
# R = sorted(R)[::-1]

P = P[:X]
Q = Q[:Y]

# print(P, Q, R)

L = P + Q + R
L = sorted(L)[::-1]

print(sum(L[: (X + Y)]))


Measured memory_bytes: 24368
a, b = 2.times.map{ gets.split.map(&:to_i) }

def roll(d, cmd)
	case cmd
	when ?E
		d[0], d[2], d[5], d[3] = d[3], d[0], d[2], d[5]
	when ?N
		d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
	when ?S
		d[0], d[1], d[5], d[4] = d[4], d[0], d[1], d[5]
	when ?W
		d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]
	when ?C # clockwise
		d[1], d[2], d[4], d[3] = d[2], d[4], d[3], d[1]
	end
end

def _same?(a, b)
	return false if a[0] != b[0]

	4.times do
		return true if a == b
		roll(b, ?C)
	end

	return false
end

def same?(a, b)
	return false if a.sort != b.sort

	return true if _same?(a, b)
	%w[N E E E N].each do |c|
		roll(b, c)
		return true if _same?(a, b)
	end

	return false
end

puts same?(a, b) ? 'Yes' : 'No'

Measured memory_bytes: 8644
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>

#define mp make_pair

using namespace std;
int a[100005];
int n;
int main(){
	cin>>n;
	n++;
	a[0]=0;
	int i,j;
	int mx,mx1,M,M1;
	mx=mx1=M=M1=0;
	for(i=1;i<n;i++) cin>>a[i];
	int ans=0;
	for(i=1;i<n;i++){
		ans+=abs(a[i]-a[i-1]); 
	}
	ans+=abs(a[n-1]-a[0]);
//	cout<<ans<<endl;
	a[n]=0;
	for(i=1;i<n;i++) cout<<ans-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
	return 0;
} 

Measured memory_bytes: 1664
import copy
shogen = {}
N = int(input())
for i in range(N):
    Ax = int(input())
    current_shogen = {}
    for j in range(Ax):
        x, y = list(map(int, input().split()))
        current_shogen[x-1] = y
    shogen[i] = current_shogen

def return_total(index, is_liar, hito_list):
    if not is_liar:
        if hito_list[index] is not None and hito_list[index] != 1:
            return 0
        hito_list[index] = 1
        current_shogen = shogen[index]
        for x,y in current_shogen.items():
            if hito_list[x] is not None:
                if hito_list[x] != y:
                    """mujun"""
                    return 0
            else:
                hito_list[x] = y
    else:
        if hito_list[index] is not None and hito_list[index] != 0:
            return 0
        hito_list[index] = 0
    if index == N-1:
        # print(hito_list)
        return sum(hito_list)
    else:
        return max(return_total(index+1, False, copy.deepcopy(hito_list)), return_total(index+1, True, copy.deepcopy(hito_list)))

print(max(return_total(0, False, [None for i in range(N)]), return_total(0, True, [None for i in range(N)])))

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(){
    long int N, W, w, v, answer = 0;

    cin >> N >> W;
    vector<vector<long int>> dp(N + 1,vector<long int>(W + 1));
    for(int i = 0;i < N; i++){
        cin >> w >> v;
        for(int j = 0;j < W;j++){
            if(j+w <= W) dp[i+1][j+w] = max(dp[i+1][j+w], dp[i][j] + v); // 取る場合
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]); // 取らない
        }
    }

    for(int i = 0; i <= W; i++){
        answer = max(answer,dp[N][i]);
    }

    cout << answer << endl;
    return 0;
}


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

int main() {
  int n,l;
  cin>>n>>l;
  int q;
  if (l>0) {
    q=(2*l+n)*(n-1)/2;
  } else if (l<1-n) {
    q=(2*l+n-2)*(n-1)/2;
  } else {
    q=(2*l+n-1)*n/2;
  }
  cout<<q<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <stdbool.h>
#define PI 3.141592653589
#define N_MAX 100

int main()
{
  int count[4][3][10];
  int n,b,f,r,v;
  int i,j,k,l;
  for(j = 0; j < 4; j++)
    {
      for(k = 0; k < 3; k++)
	{
	  for(l = 0; l < 10; l++)
	    {
	      count[j][k][l] = 0;
	    }
	}
    }
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    {
      scanf("%d %d %d %d",&b,&f,&r,&v);
      count[b-1][f-1][r-1] += v;
    }
  for(j = 0; j < 4; j++)
    {
      for(k = 0; k < 3; k++)
	{
	  for(l = 0; l < 10; l++)
	    {
	      printf(" %d",count[j][k][l]);
	    }
	  printf("\n");
	}
      if(j != 3) printf("####################\n");
    }
  return 0;
}

Measured memory_bytes: 612
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ABC140B
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);
            var B = cin.ReadIntArray(N);
            var C = cin.ReadIntArray(N - 1);

            int ans = 0;
            for(int i = 0; i < N; i++)
            {
                ans += B[A[i] - 1];
            }
            for(int i = 0; i < N - 1; i++)
            {
                if(A[i + 1] == A[i] + 1)
                {
                    ans += C[A[i] - 1];
                }
            }

            Console.WriteLine(ans);
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
import math


def main():
    N = int(input())
    x = math.floor(math.sqrt(N*2))
    if x * (x+1) != N*2:
        print("No")
        return
    print("Yes")
    print(x+1)
    s = [[] for _ in range(x+1)]
    counter = 1
    for i in range(x+1):
        for j in range(i+1, x+1):
            s[i].append(counter)
            s[j].append(counter)
            counter += 1
    for i in range(x+1):
        print(len(s[i]), *s[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 47196
// https://atcoder.jp/contests/abc142/tasks/abc142_e

#include "algorithm"
#include "iostream"
#include "vector"
#define rep(i, from, to) for (int i = from; i < (to); ++i)
using namespace std;
typedef long long ll;

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

const ll INF = 1ll << 60;

void solve() {
  ll N, M;
  cin >> N;
  cin >> M;

  vector<ll> costs(M), boxes(M, 0);

  costs.push_back(1);
  rep(i, 0, M) {
    ll box_ct;
    cin >> costs[i] >> box_ct;

    rep(j, 0, box_ct) {
      ll box_num;
      cin >> box_num;
      boxes[i] |= (1 << (box_num - 1));
    }
  }

  ll dp[1 << N];
  rep(i, 0, 1 << N) dp[i] = INF;
  dp[0] = 0;

  rep(i, 0, M) {
    ll box_mask = boxes[i];

    rep(j, 0, 1 << N) { chmin(dp[j | box_mask], dp[j] + costs[i]); }
  }

  if (dp[(1 << N) - 1] == INF) {
    cout << -1 << endl;
    return;
  }

  cout << dp[(1 << N) - 1] << endl;
}

#ifndef TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
#endif


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

ll dp[4][3005];

int main() {
    vector<int> RGB(3);
    rep(i, 3) cin >> RGB[i];
    int N;
    cin >> N;

    rep(i, 4) rep(j, N + 1) dp[i][j] = 0;
    rep(i, 3) dp[i + 1][RGB[i]] = 1;

    rep(i, 3) rep(j, N + 1) {
        dp[i + 1][j] += dp[i][j];
        if (j - RGB[i] >= 0) dp[i + 1][j] += dp[i + 1][j - RGB[i]];
    }
    cout << dp[3][N] << endl;
}

Measured memory_bytes: 3700
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    double r;
    scanf("%lf", &r);
    printf("%.6lf %.6lf\n", r * r * M_PI, 2.0 * r * M_PI);
    return 0;
}

Measured memory_bytes: 1080
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct edge {
	int to, cost;
	edge(int t, int c):to(t), cost(c){}
};

struct node {
	int dist, room, ball;
	node(int d, int r, int b):dist(d), room(r), ball(b){}

	bool operator> (const node& o) const {
		return dist > o.dist;
	}
};

int n, m, l, k;
int ball[50];
vector<vector<edge> > es;

int dijkstra(int s, int g) {
	priority_queue<node, vector<node>, greater<node> > que;
	int d[n][1 << l][k];
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < (1 << l); ++j)
			for(int o = 0; o < k; ++o)
				d[i][j][o] = INT_MAX;

	que.push(node(0, s, (ball[s] == -1 ? 0 : (1 << ball[s]))));
	d[s][0][0] = 0;

	while(!que.empty()) {
		node cur = que.top();
		que.pop();

		if(cur.dist > d[cur.room][cur.ball][k - 1])
			continue;

		if(cur.room == g && cur.ball == (1 << l) - 1 && d[g][cur.ball][k - 1] == cur.dist)
			return cur.dist;

		for(int i = 0; i < es[cur.room].size(); ++i) {
			edge e = es[cur.room][i];
			int nextBall = cur.ball;
			int nextDist = cur.dist + e.cost;

			if(ball[e.to] != -1)
				nextBall |= (1 << ball[e.to]);

			if(d[e.to][nextBall][k - 1] > nextDist) {
				d[e.to][nextBall][k - 1] = nextDist;
				for(int i = k - 2; i >= 0; --i)
					if(d[e.to][nextBall][i] > d[e.to][nextBall][i + 1])
						swap(d[e.to][nextBall][i], d[e.to][nextBall][i + 1]);
					else
						break;

				que.push(node(nextDist, e.to, nextBall));
			}
		}
	}

	return -1;
}

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

	for(; cin >> n >> m >> l >> k, n;) {
		es.clear();
		es.resize(n);

		for(int i = 0; i < m; ++i) {
			int u, v, c;
			cin >> u >> v >> c;
			--u; --v;
			es[u].push_back(edge(v, c));
			es[v].push_back(edge(u, c));
		}

		int s, g;
		cin >> s >> g;
		--s; --g;

		memset(ball, -1, sizeof(ball));
		for(int i = 0; i < l; ++i) {
			int in;
			cin >> in;
			--in;
			ball[in] = i;
		}

		int ans = dijkstra(s, g);
		if(ans == -1)
			cout << "NA" << endl;
		else
			cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 4256
from scipy.sparse import*
e=enumerate
h,*s=open(0)
h,w=map(int,h.split())
r,c=[],[]
for i,t in e(s):
  for j,u in e(t):
    if u>'#'<t[j+1]:r+=i*w+j,;c+=i*w+j+1,
    if(i<h-1)*u>'#'<s[i+1][j]:r+=i*w+j,;c+=j-~i*w,    
print(int((csgraph.johnson(csr_matrix(([1]*len(r),(r,c)),[h*w]*2),0).clip(0,999)%999).max()))

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    int used[26],n;
    while(cin >> s)
    {
        memset(used, 0, sizeof used);
        n = s.size();
        for(int i = 0; i < n; i++)
            used[s[i]-'a'] = 1;
        int pos = -1;
        for(int i = 0; i < 26 && pos == -1; i++)
            if(!used[i])
                pos = i;
        if(pos != -1)
            cout << s << char('a'+pos) << '\n';
        else
        {
            int finished = 0;
            for(int i = n-2; i >= 0 && !finished; i--)
            {
                int pos = -1;
                for(int j = i+1; j < n; j++)
                    if(s[j] > s[i] && (pos == -1 || s[j] < s[pos]))
                        pos = j;
                if(pos != -1)
                {
                    swap(s[i], s[pos]);
                    s.resize(i+1);
                    finished = 1;
                }
            }
            cout << (!finished? "-1" : s) << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
int a[100010];
int b[100010];
signed main() {	
	a[0] = 1;
	a[1] = 2;
	loop(i, 2, 100001) {
		a[i] = a[i - 1] + a[i - 2];
		a[i] %= inf;
	}
	int n, m,ans;
	cin >> n >> m;
	if (m == 0) {
		cout << a[n - 1] << endl;
		return 0;
	}
	rep(i, m) {
		cin >> b[i];
	}
	if (b[0] == 1) {
		ans = 1;
	}
	else { ans = a[b[0] - 2]; }
	ans %= inf;
	loop(i,1,m){
		if (b[i]-b[i-1]==1) {
			cout << 0 << endl; return 0;
		}
		ans *= max((ll)1,a[b[i] - b[i - 1]-3]);
		ans %= inf;
	}
	int sum =max((ll)0, n - b[m - 1]-2);
	ans *= a[sum];
	ans %= inf;
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct Edge{
	int next,to;
}edge[N*2];
int fi[N],se,pre[N],que[N],s,t;
inline void add_edge(int u,int v){edge[++se]={fi[u],v},fi[u]=se;}
inline void add(int u,int v){add_edge(u,v),add_edge(v,u);}
int main(){
	int n,m,u,v;scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)scanf("%d%d",&u,&v),add(u,v);
	que[t++]=1;
	while(s<t){
		int u=que[s++];
		for(int i=fi[u];i;i=edge[i].next){
			int v=edge[i].to;if(pre[v])continue;
			pre[v]=u,que[t++]=v;
		}
	}
	if(s<n)return puts("No"),0;
	puts("Yes");for(int i=2;i<=n;i++)printf("%d\n",pre[i]);
	return 0;
}

Measured memory_bytes: 7988