akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    int N, K;
    cin >> N >> K;
    int ans = (N - 1) * (N - 2) / 2;
    vector<pair<int, int>> res;
    rep2(i, 2, N+1) {
        res.emplace_back(make_pair(1, i));
    }
    if (ans < K) {
        cout << -1 << endl;
        return 0;
    }
    if (ans != K) {
        for (int i = 2; i <= N; ++i) {
            for (int j = i+1; j <= N; ++j) {
                if (i == j) {
                    continue;
                } else {
                    res.emplace_back(make_pair(i, j));
                    ans -= 1;
                    if (ans == K) {
                        break;
                    }
                }
            }
            if (ans == K) {
                break;
            }
        }
    }
    cout << res.size() << endl;
    rep(i, res.size()) {
        cout << res[i].first;
        cout << " ";
        cout << res[i].second << endl;
    }
}


Measured memory_bytes: 384
// g++ A.cpp -Wall -Wextra -Woverflow -Wshadow -O2
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>
 
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;

const int MAXN = 100005;
int N, K;
int x[MAXN];
int main() {
  ios::sync_with_stdio(false); 
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  int ans = 1 << 30;
  for (int i = 0; i + K - 1 < N; i++) {
    if (x[i + K - 1] <= 0) {
      ans = min(ans, -x[i]);
    } else if (x[i] >= 0) {
      ans = min(ans, x[i + K - 1]);
    } else {
      int L = -x[i], R = x[i + K - 1];
      ans = min(ans, L + R + min(L, R));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
N=int(input())
N_list=list(map(str, list(input() for i in range (N))))
M=int(input())
M_list=list(map(str, list(input() for i in range (M))))


N_unique=list(set(N_list))

p_max=-101
for i in N_unique:
    p_max=max(p_max, N_list.count(i)-M_list.count(i))

if p_max<0:
    print(0)
else:
    print(p_max)

Measured memory_bytes: 3064
d[1<<22],i,N,p;w[99];main(j){for(*d=1;~scanf("%d",w+i++););for(N=*w;p<N<<N;d[i]%=j=1e9+7)d[i]+=d[j=p/N]*(j<(i=j|1<<p%N))*w[__builtin_popcount(j)*N+p++%N+1];printf("%d",d[i]);}

Measured memory_bytes: 10368
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n;cin>>n;
	vector<int> x(n);
	for(int i=0;i<n;i++){
		cin>>x[i];
//		cout<<x[i];
	}
	x.push_back(x[n-1]+1);
	n++;
	int l,q;cin>>l>>q;
	vector<int> a(q),b(q);
	for(int i=0;i<q;i++){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
	}
//	cout<<'a';
	vector<vector<int>> r,r2;
	vector<int> temp(n),ex(n);
	int j=1;
	for(int i=0;i<n-1;i++){
		while((x[i]+l>=x[j])*(j<n)){
			j++;
		}
		temp[i]=j-1;
	}
	temp[n-1]=n-1;
	r.push_back(temp);
	int flag=1;
	int count=1;
	while(flag){
		flag=0;
		ex=temp;
		temp=vector<int>(n,0);
//		for(int i=0;i<ex.size();i++){
//			cout<<ex[i];
//		}
		for(int i=0;i<n;i++){
			temp[i]=ex[ex[i]];
			if(temp[i]!=n-1){
				flag=1;
			}
		}
		r.push_back(temp);
		count++;
	}
	r2=vector<vector<int>>(n,vector<int>(count,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<count;j++){
			r2[i][j]=r[j][i];
//			cout<<r2[i][j]<<' ';
		}
//		cout<<endl;
	}
//	for(int i=0;i<r.size();i++){
//		for(int j=0;j<r[i].size();j++){
//			cout<<r[i][j]<<' ';
//		}
//		cout<<endl;
//	}
	vector<int> sp(count);
	sp[0]=1;
	for(int i=1;i<count;i++){
		sp[i]=sp[i-1]*2;
	}
	for(int i=0;i<q;i++){
		int ans=0;
		int start=a[i];
		int goal=b[i];
		if(a[i]>b[i]){
			start=b[i];
			goal=a[i];
		}
		int add=0;
		int j=0;
		while(3){
			j++;
			add=upper_bound(r2[start].begin(),r2[start].end(),goal)-r2[start].begin();
			if(add)add--;
			ans+=sp[add];
			start=r2[start][add];
//			cout<<start<<goal<<add<<endl;
			if(start>=goal)break;
		}
//		cout<<endl;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 19960
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}

template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main(){
  ll c,b;
  cin>>c>>b;
  vector<ll> a(3,0);
  a[0]=c+b;
a[1]=c-b;
a[2]=c*b;
   sort(all(a));
   op(a[2])
   return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	x := nextInt()
	n := nextInt()

	if n == 0 {
		fmt.Println(x)
		return
	}

	plist := make([]int, n)
	havetarget := false
	for i := 0; i < n; i++ {
		plist[i] = nextInt()
		// 対象外リストにxがふくまれていればtrueにする
		if plist[i] == x {
			havetarget = true
		}

	}

	// 対象外リストにxがふくまれていなければそこでxをかえす
	if havetarget == false {
		fmt.Println(x)
		return
	}

	sort.Sort(sort.IntSlice(plist))

	upper := 0
	for u := 1; u <= 102; u++ {
		// adjから上に向かって探索
		if hasX(x+u, plist) == false {
			upper = x + u
			break
		}
	}
	down := 0
	for u := 1; u <= 102; u++ {
		// adjから下に向かって探索
		if hasX(x-u, plist) == false {
			down = x - u
			break
		}
	}

	if abs(x-upper) == abs(x-down) {
		fmt.Println(down)
		return
	} else if abs(x-upper) < abs(x-down) {
		fmt.Println(upper)
		return
	}

	fmt.Println(down)
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func hasX(x int, plist []int) bool {

	for _, p := range plist {
		if x == p {
			return true
		}
	}
	return false
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1760
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    REP(i,0,n) cerr << a[i] << " ";
    cerr << endl;
    LL cnt = 0;
    REP(r,0,1000) {
        if (*max_element(all(a)) <= n * 10) break;
        REP(i,0,n) {
            LL tmp = (a[i] - 50) / n;
            if (tmp < 0) tmp = 0;
            cnt += tmp;
            a[i] -= n * tmp;
            REP(j,0,n) {
                if (i != j) a[j] += tmp;
            }
        }
    }
    while (*max_element(all(a)) >= n && cnt++ >= 0) {
        auto it = max_element(all(a));
        for (auto i = begin(a); i != end(a); ++i) {
            if (i != it) *i += 1;
            else *i -= n;
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n, cnt, sum, u[100], v[100], w[100], val[100];
void ins(int x, int y, int z) {
	u[cnt] = x;
	v[cnt] = y;
	w[cnt++] = z;
}
int main() {
	val[1] = 1;
	for (int i = 2; i <= 19; ++i) {
		val[i] = val[i-1] << 1;
		ins(i-1, i, 0);
		ins(i-1, i, val[i-1]);
	}
	scanf("%d", &n);
	for (int i = 19; i >= 1; --i) {
		while (n >= val[i]) {
			ins(i, 20, sum);
			sum += val[i];
			n -= val[i];
		}
	}
	printf("20 %d\n", cnt);
	for (int i = 0; i < cnt; ++i)
		printf("%d %d %d\n", u[i], v[i], w[i]);
}

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

#define ll long long

void solve()
{
    ll n, d;
    cin >> n >> d;
    ll x, y;
    ll cnt = 0;

    for(ll i = 0; i < n; i++)
    {
        cin >> x >> y;
        ll sum = x * x + y * y;

        if(sum <= d * d)
        {
            cnt++;
        }
    }

    cout << cnt;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    // ll t;
    // cin >> t;
    
    // while(t--)
    // {
        solve();
    // }

    return 0;
}


Measured memory_bytes: 3648
//
// Created by Tetsuya Shiota on 2019-01-27.
//

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl


typedef long long ll;

using namespace std;

//ハマったらチェックリスト見ろ!!

int main(){
    int N, M;
        cin >> N >> M;
    vector<int> IN(N);
    vector<int> P(N);
    map<int, vector<int> > Edge;
    for(auto& v:IN)v =0;
    for(auto& v:P)v =-1;
    rep(i, N-1 + M){
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        IN[to]++;
        Edge[from].push_back(to);
    }
    int root = -1;
    rep(i, N){
        if(IN[i]==0){
            root = i;
        }
    }

    queue<int> Q;
    Q.push(root);
    while(!Q.empty()){
        int now = Q.front();Q.pop();
        for(auto to : Edge[now]){
            IN[to]--;
            if(IN[to] == 0){
                P[to] = now;
                Q.push(to);
            }
        }
    }
    for(auto p : P){
        cout << p +1<<endl;
    }


    return 0;
}

Measured memory_bytes: 12544
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N, i;
    io.read(N, i);
    cout << N - i + 1; 
    return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int n = int.Parse(N);
            if (n < 3 || 10000 < n)
                Environment.Exit(0);

            for (int i = 1; i <= n; i++)
            {
                int x = i;

                if (x % 3 == 0) //3の倍数
                {
                    Console.Write(" {0}", i);
                    continue;
                }
                do //1の位以外が3
                {
                    if (x % 10 == 3) //1の位が3
                    {
                        Console.Write(" {0}", i);
                        break;
                    }
                    
                        x /= 10;
                } while (x!=0);
            }
            Console.Write("\n");
        }
    }
}


Measured memory_bytes: 17960
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[M];
		for (int i=0; i<M; i++) {
			A[i] = sc.nextInt();
		}
		int left = 0;
		int right = 0;
		for (int i=0; i<M; i++) {
			if (A[i] < X) left++;
			else right++;
		}
		System.out.println(Math.min(right, left));
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
typedef long long ll;

int main(){
	ll N,ans=0;
  cin>>N;
  
  rep(i,N+1){
  	if(i%3==0 || i%5==0){
    
    }else{
    	ans+=i;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <map>
#include <functional>
using namespace std;

int main() {
  int N,M;
  string str;
  map<string,int> points;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> str;
    if(points[str]==0){
      points[str]=1;
    }else{
      points[str]++;
    }
  }
  
  cin >> M;
  for(int i=0; i<M; i++){
    cin >> str;
    if(points[str]==0){
      points[str]= -1;
    }else{
      points[str]--;
    }
  }
  
  int ans=0;
  for (auto iter = points.begin(); iter != points.end(); iter++){
    ans = max(iter->second, ans);    
  }
  cout << ans << endl;  
}

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

int main() {
  int N, Sum=1;
  cin >> N;
  string S;
  cin >> S;
  rep(i, N-1){
    if(S.at(i)!=S.at(i+1)) Sum++;
  }
  cout << Sum << endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final String t = scanner.next();
        final char[] array = t.toCharArray();

        for (int i = 0; i < t.length(); i++) {
            if (array[i] == '?') {
                array[i] = 'D';
            }
        }
        System.out.println(new String(array));
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


Measured memory_bytes: 36788
#include <iostream>
#include <string>
#include <array>
#include <algorithm>

using namespace std;

int main() {
    int n,m,x;
    int a[100];
    int l = 0;
    int r = 0;

    cin >> n >> m >> x;
    for(int i = 0; i < m; i ++){
        cin >> a[i];
    }
    for(int i = 0; i < m; i ++){
        if(x > a[i]) l ++;
        else r ++;
    }
    if(l > r) cout << r;
    else cout << l;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <set>
#include <queue>
using namespace std;

typedef pair<string, int> P;

int bfs(string worm){
	queue<P> que;
	que.push(P(worm, 0));

	set<string> d;
	
	while(!que.empty()){
		P p = que.front();
		que.pop();
		if(d.count(p.first)) continue;

		string str = p.first;
		
		bool flag = false;
		for(int i=0;i<str.size()-1;i++){
			if(str[i] != str[i+1]){
				flag = true;
				break;
			}
		}
		if(!flag) return p.second;
		d.insert(p.first);

		for(int i=0;i<str.size()-1;i++){
			if(str[i] != str[i+1]){
				char temp;
				string next;

				if(str[i] != 'b' && str[i+1] != 'b'){
					temp = 'b';
				}else if(str[i] != 'g' && str[i+1] != 'g'){
					temp = 'g';
				}else{
					temp = 'r';
				}

				next = str;
				next[i] = next[i+1] = temp;

				que.push(P(next, p.second+1));
			}
		}
	}
	return -1;
}

int main(){
	string worm;
	while(cin >> worm && worm != "0"){
		int ret = bfs(worm);
		if(ret>=0) cout << ret << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 2932
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=2e6+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),sum(0),n,x,y,t,i,j,temp,k,ans(0),mn(M),mx(-9e9);
ll table[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	ll a[n];
	//memset(table,0,sizeof(table));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		table[a[i]]++;
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		for(j=2;j*a[i]<=a[n-1];j++)
		{
			table[a[i]*j]++;
		}
	}
	for(i=0;i<n;i++)
	{
		if(table[a[i]]<=1)
		{
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 12788
#include<stdio.h>
#include<math.h>

int main(void){
	double x=0, y=0;
	int turn, walk, c=90;
	while(1){
		scanf("%d,%d", &walk, &turn);
		if(!walk && !turn) break;
		x = x + walk*cos( ( (double)c * M_PI ) / 180.0);
		y = y + walk*sin( ( (double)c * M_PI ) / 180.0);
		c = c - turn;
	}
	printf("%d\n%d\n", (int)x, (int)y);
	return 0;
}

Measured memory_bytes: 600
N,K = map(int, input().split())
S = input()
K -= 1
if S[K] == 'A':
    S = S[0:K] + 'a' + S[K+1:]
elif S[K] == 'B':
    S = S[0:K] + 'b' + S[K+1:]
elif S[K] == 'C':
    S = S[0:K] + 'c' + S[K+1:]
print(S)

Measured memory_bytes: 3060
//Heaplax
#include<bits/stdc++.h>
#define N 100005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
    while(ch=getchar(),ch<33);
    if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
    while(ch=getchar(),ch>33)x=x*10+ch-48;
    if(fs)x=-x;
}
using namespace std;
int n,k,a[N],ans,in[N],dis[N],top,st[N];
int main()
{
	re(n),re(k);
	for(int i=1;i<=n;++i)
		re(a[i]);
	ans+=a[1]!=1;
	a[1]=1;
	for(int i=2;i<=n;++i)
		++in[a[i]];
	for(int i=2;i<=n;++i)
		if(!in[i])
			st[++top]=i;
	for(int i=1;i<=top;++i)
	{
		int u=st[i];
		if(dis[u]+1==k && a[u]!=1)++ans;
		else dis[a[u]]=max(dis[a[u]],dis[u]+1);
		if(a[u]!=1)
		{
			--in[a[u]];
			if(!in[a[u]])
				st[++top]=a[u];
		}
	}
	printf("%d\n",ans);
}

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

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PInt;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

int parent[1000010];
int weight[1000010];
int find(int a) {
  if (parent[a] == a) return a;
  int p = parent[a];
  parent[a] = find(p);
  weight[a] += weight[p];
  return parent[a];
}

int main() {
  int N, M;
  while(cin >> N >> M, N) {
    rep(i, N) parent[i] = i;
    rep(i, N) weight[i] = 0;
    rep(i, M) {
      char req;
      cin >> req;
      if (req == '!') {
        int a, b, w;
        cin >> a >> b >> w;
        a--, b--;

        if (find(a) == find(b)) continue;
        int ap = find(a);
        int bp = find(b);
        parent[bp] = ap;
        weight[bp] = w + weight[a] - weight[b];
      } else {
        int a, b;
        cin >> a >> b;
        a--, b--;

        if (find(a) == find(b)) {
          cout << weight[b] - weight[a] << endl;
        } else {
          cout << "UNKNOWN" << endl;
        }
      }
    }
  }
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  string t;
  cin >> t;
  i64 ans = 0;
  int zero = 0;
  {
    int now = 0;
    rep(i, sz(t)) {
      if (t[i] == '1') {
        now += 1;
        ans += (now + 1) / 2;
      } else {
        zero += 1;
      }
    }
  }
  string s;
  {
    rep(i, sz(t)) {
      if (t[i] != '1') {
        s += '0';
        continue;
      }
      int l = i;
      while (i < sz(t) && t[i] == '1') i++;
      int r = i;
      int d = r - l;
      if (d & 1) {
        s += '1';
      }
      ans += (i64) zero * (d / 2);
      i--;
    }
  }
  int n = sz(s);
  vi32 sums(n + 1);
  rrep(i, n) sums[i] = sums[i+1] + (s[i] == '0');
  int eo = 0;
  int cn = 0;
  rep(i, n) {
    if (s[i] == '0') {
      cn += 1;
      continue;
    }
    ans += (cn + eo) / 2 + sums[i + 1];
    eo = 1 - eo;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4612
min2 = lambda x,y: x if x < y else y
H,N = map(int,input().split())


dp = [float('inf')]*(H+1)
dp[0] = 0

for _ in range(N):
    a,b = map(int,input().split())
    for i,v in enumerate(dp):
        j = min2(H,i+a)
        dp[j] = min2(dp[j],v+b)

print(dp[-1])

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

public class Main {
    public static void main(String[] args) {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
            String s = in.readLine();
            int n = Integer.parseInt(in.readLine());
            for (int i = 0; i < n; i++) {
                String[] arr = in.readLine().split(" ");
                switch (arr[0]) {
                    case "print":
                        System.out.println(s.substring(Integer.parseInt(arr[1]), Integer.parseInt(arr[2]) + 1));
                        break;
                    case "reverse":
                        int p1 = Integer.parseInt(arr[1]);
                        int p2 = Integer.parseInt(arr[2]);
                        String subs = s.substring(p1, p2 + 1);
                        String reversed = new StringBuilder(subs).reverse().toString();
                        s = s.substring(0, p1) + reversed + s.substring(p2 + 1);
                        break;
                    case "replace":
                        char[] rearr = s.toCharArray();
                        int b = Integer.parseInt(arr[1]);
                        int e = Integer.parseInt(arr[2]);
                        String text = arr[3];
                        for (int j = 0; j < text.length(); j++) {
                            rearr[j + b] = text.charAt(j);
                        }
                        s = String.valueOf(rearr);
                        break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



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

using namespace std;

int n;
int arr[200100];
int brr[200100];

int main() {
    int i;

    scanf("%d",&n);
    for (i=0;i<n;i++) {scanf("%d",&arr[i]);brr[i]=arr[i];}
    sort(brr,brr+n);
    for (i=0;i<n;i++) {
        if (arr[i]<=brr[n/2-1]) printf("%d\n",brr[n/2]);
        else printf("%d\n",brr[n/2-1]);
    }

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#define maxn 2000
using namespace std;
int s[maxn];
int main()
{
    int N,cas=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>s[i];
        if(++cas>1) cout<<" ";
        cout<<s[i];
    }
    cout<<endl;
    for(int i=1;i<N;i++){
       int key=s[i];
       int j=i-1;
       while(j>=0&&s[j]>key){
           s[j+1]=s[j];
           j--;
           s[j+1]=key;
       }
        cas=0;
         for(int m=0;m<N;m++){
             if(++cas>1) cout<<" ";
               cout<<s[m];
           }
           cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3080
def main():
    n = int(input())
    L = list(map(int,input().split()))
    L.sort()
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if L[i]!=L[j] and L[i]!=L[k] and L[j]!=L[k]:
                    if L[k]<L[i]+L[j]:
                        ans+=1

    print(ans)
main()

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rg register
#define maxn 150000
const ll mod=1e9+7;
string s;
int dp[maxn][15];
int main()
{
	cin>>s;
	int len=s.length();
	dp[0][0]=1;
	for(rg int i=0;i<len;++i)
	{
		if(s[i]!='?')
		{
			for(rg int j=0;j<=12;++j)
			{
				dp[i+1][(j*10+s[i]-'0')%13]=dp[i][j];
			}
		}
		else
		{
			for(rg int j=0;j<=9;++j)
			{
				for(rg int k=0;k<=12;++k)
				{
					dp[i+1][(j+k*10)%13]=(dp[i+1][(j+k*10)%13]+dp[i][k])%mod;
				}
			}
		}
	}
	cout<<dp[len][5];
}


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

namespace _0242
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                string[] s = new string[n];
                for (int i = 0; i < n; i++)
                {
                    s[i] = Console.ReadLine();
                }
                char c = Console.ReadLine()[0];
                List<string> wordlist = new List<string>();
                List<int> countlist = new List<int>();
                for (int i = 0; i < n; i++)
                {
                    string[] x = s[i].Split();
                    for (int j = 0; j < x.Count(); j++)
                    {
                        if (x[j][0] == c)
                        {
                            if (wordlist.Contains(x[j]))
                            {
                                countlist[wordlist.IndexOf(x[j])]++;
                            }
                            else
                            {
                                wordlist.Add(x[j]);
                                countlist.Add(1);
                            }
                        }
                    }
                }
                string[] words = wordlist.ToArray();
                int[] counts = countlist.ToArray();
                if (words.Count() == 0) Console.WriteLine("NA");
                else
                {
                    Array.Sort(words,counts);
                    int a = 0;
                    for (int i = 10000; i > 0; i--)
                    {
                        for (int j = 0; j < words.Count(); j++)
                        {
                            if (counts[j] == i)
                            {
                                if (a < 5)
                                {
                                    if (a != 0) Console.Write(" ");
                                    Console.Write(words[j]);
                                }
                                a++;
                            }
                        }
                    }
                    Console.WriteLine();
                }
            }
        }
    }
}


Measured memory_bytes: 10608
#include <bits/stdc++.h>
using namespace std;
 
string S; int N, cnt;
 
int main() {
	cin >> N >> S;
	for (int i = 0; i < 1000; i++) {
		int c[3] = {i / 100, (i / 10) % 10, i % 10};
		int f = 0;
		for (int j = 0; j < N; j++) {
			if (S[j] == ('0' + c[f])) f++;
			if (f == 3) break;
		}
		if (f == 3) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

long long gcd(long long a,long long b){
    long long tmp;
    while(b!=0){
        tmp=a%b;
        a=b;
        b=tmp;
    }
    return a;
}

long long lcm(long long a,long long b){
    if(a*b==0){
        return 0;
    }
    return (a*b/gcd(a,b));
}

int main(){
    long long A,B,C,D,C_cou=0,D_cou=0,C_D_cou;
    cin>>A>>B>>C>>D;
    C_cou=B/C-(A-1)/C;
    D_cou=B/D-(A-1)/D;
    C_D_cou=B/lcm(C,D)-(A-1)/lcm(C,D);
    cout<<B-A+1-C_cou-D_cou+C_D_cou<<endl;

}

Measured memory_bytes: 256
import numpy as np
 
N = int(input())
S = input()
 
unique_list = list(np.unique(S))
 
ans = 1
 
for s in unique_list:
  tmp = S.count(s)
  ans = ans * (tmp + 1)
  
print((ans-1) % int((1e9 + 7)))

Measured memory_bytes: 12600
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if(n < 1200)
    {
        cout << "ABC" << endl;
    }
    else if(n < 2800)
    {
        cout << "ARC" << endl;
    }
    else cout << "AGC" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int n,p[1000][3],flg[1000],i,j,k,f,temp,cnt;
	cin>>n;
	for(i=0;i<n;i++) flg[i]=0;
	for(i=0;i<n;i++){
		for(j=0;j<3;j++) cin>>p[i][j];
	}
	for(i=0;i<n;i++){
		for(j=0;j<3-1;j++){
			for(k=j+1;k<3;k++){
				if(p[i][j]>p[i][k]){
					temp=p[i][j];
					p[i][j]=p[i][k];
					p[i][k]=temp;
				}
			}
		}
	}
	cnt=0;
	for(i=0;i<n-1;i++){
		if(flg[i]!=1){
			for(j=i+1;j<n;j++){
				f=1;
				for(k=0;k<3;k++){
					if(p[i][k]!=p[j][k]){
						f=0;
						break;
					}
				}
				if(f==1){
					cnt++;
					flg[j]=1;
				}
			}		
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int searchWin(int a, int b);

int main(){
    int a[5];
    while(cin >>a[0]){
        vector<int> vec(4, 0);
        if(a[0] == 0) break;
        vec[a[0]]++;
        bool aiko = false;
        for(int i = 1; i < 5; i++){
            cin >>a[i];
            vec[a[i]]++;
        }

        if(vec[1] != 0 && vec[2] != 0 && vec[3] != 0) aiko = true;
        if((vec[1] == 0 && vec[2] == 0) || (vec[2] == 0 && vec[3] == 0) || (vec[3] == 0 && vec[1] == 0)) aiko = true;

        if(aiko){
            for(int i = 0; i < 5; i++) cout <<3 <<endl;
        } else{
            vector<int> v;
            for(int i = 1; i <= 3; i++){
                if(vec[i] != 0) v.push_back(i);
            }
            int win = searchWin(v[0], v[1]);
            for(int i = 0; i < 5; i++){
                if(win == a[i]) cout <<1 <<endl;
                else cout <<2 <<endl;
            }
        }
    }
    return 0;
}

int searchWin(int a, int b){
    if(a == 1){
        if(b == 2) return a;
        else return b;
    } else if(a == 2){
        if(b == 1) return b;
        else return a;
    } else{
        if(b == 1) return a;
        else return b;
    }
}

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

namespace AtCoder.Abcdef
{
    public class QuestionC2
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            //Input int array
            int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            (int h, int w, int k) = (inputArray[0], inputArray[1], inputArray[2]);

            char[,] c = new char[h,w];
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine();
                for (int j = 0; j < s.Length; j++)
                {
                    c[i, j] = s[j];
                }
            }

            var ans = new List<int>();
            for (int i = 0; i < 1 << h; i++)
            {
                for (int j = 0; j < 1<<w; j++)
                {
                    var cnt = 0;
                    for (int i2 = 0; i2 < h; i2++)
                    {
                        for (int j2 = 0; j2 < w; j2++)
                        {
                            if (((j >> j2) & 1) == 1)
                            {
                                continue;
                            }
                            if (((i >> i2) & 1) == 1)
                            {
                                continue;
                            }
                            if (c[i2, j2] == '#') cnt++;
                        }
                    }
                    ans.Add(cnt);
                }
            }

            Console.WriteLine(ans.Where(item => item == k).Count()); 
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28368
#include<iostream>
#include<string>
using namespace std;
int main(void){
    string str;
    int q;
    cin >> str;
    cin >> q;
    for (int i=0;i<q;i++){
        string c;
        cin >> c;
        if (c=="print"){
            int a,b;
            cin >> a >> b;
            for (int i=a;i<=b;i++)
                cout << str[i];
            cout << endl;
        }
        if (c=="reverse"){
            int a,b;
            cin >> a >> b;
            char t;
            for (int i=0;i<=(b-a)/2;i++){
                t=str[a+i];
                str[a+i]=str[b-i];
                str[b-i]=t;
            }
        }
        if (c=="replace"){
            int a,b;
            string r;
            cin >> a >> b >> r;
            str.replace(a,b-a+1,r);
        }
    }
}


Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	cout << N * N * N << endl;
	return 0;
}


Measured memory_bytes: 256
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    a = ii()
    print(a+a**2+a**3)




main()




Measured memory_bytes: 10012
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int output=1;
        for(int i=0;i<n;i++){
            output=Math.min(output*2,output+k);
        }
        System.out.println(output);
         
    }
 
    
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

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

    ll N;
    ll a[5];

    cin >> N;

    for(ll i=0; i<5; i++)
    {
        cin >> a[i];
    }

    ll ans = 0;
    for(ll i=0; i<5; i++)
    {
        if(N%a[i]==0)
        {
            ans = max(ans, N/a[i]);
        }

        else
        {
            ans = max(ans, N/a[i]+1);
        }
    }

    cout << ans+4 << endl;    

    return 0;
}

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

using namespace std;

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

    string s;
    vector<string> stlist;

    stlist.clear();
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        stlist.push_back(s);
    }
    sort(stlist.begin(), stlist.end());

    int count = 1;

    for (int i = 1; i < n; i++)
    {
        if(stlist[i] != stlist[i-1]) count++;
        else continue;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 11656
#include <bits/stdc++.h>
        using namespace std;
         
        int main() {
          cin.tie(0);
          ios::sync_with_stdio(false);
          
          int a, b;
          cin >> a >> b;
          for(int i = 0; i < max(a, b); i++) {
            if(i != max(a, b) - 1) {
              cout << min(a, b);
            }else {
              cout << min(a, b) << endl;
            }
          }
        }

Measured memory_bytes: 256
n,m,q=map(int,input().split())
LR=[tuple(map(int,input().split())) for _ in range(m)]
PQ=[tuple(map(int,input().split())) for _ in range(q)]

MAP=[[0]*(n+1) for _ in range(n+1)]
for l,r in LR:
    MAP[l][r] +=1

for i in range(n+1):
    for j in range(n+1):
        MAP[i][j] +=MAP[i][j-1]

for i in range(n+1):
    for j in range(n+1):
        MAP[i][j] +=MAP[i-1][j]

for p,q in PQ:
    print(MAP[q][q]-(MAP[q][p-1]+MAP[p-1][q])+MAP[p-1][p-1])

Measured memory_bytes: 44740
K = int(input())
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1,
       5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][K - 1])

Measured memory_bytes: 2940
s = input()

a = int(s[0:2])
b = int(s[2:])

if a > 0 and a < 13:
  if b > 0 and b < 13:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if b > 0 and b < 13:
    print('YYMM')
  else:
    print('NA')


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}
int main() {
	string a,b,c; cin >> a >> b >> c;
	cout << upper(a[0]) << upper(b[0]) << upper(c[0]) << endl;
}

Measured memory_bytes: 256
def to_bit(n):
	ret = [0 for i in range(12)]
	i = 0
	while n > 1:
		ret[i] = n % 2
		n = n // 2
	return ret

def to_int(B):
	return sum([B[i] * 2**i for i in range(12)])

N,M = map(int,input().split())
key = []
for i in range(M):
	a,b = map(int,input().split())
	c = list(map(int,input().split()))
	C = [0 for x in range(12)]
	for x in c:
		C[x-1] = 1
	key.append((a, to_int(C)))
dp = [[-1 if j > 0 else 0 for j in range(2**N)] for i in range(M)]
dp[0][key[0][1]] = key[0][0]
for i in range(M-1):
	cost = key[i+1][0]
	bit = key[i+1][1]
	for j in range(2**N):
		if dp[i][j] >= 0:
			if dp[i+1][j] == -1:
				dp[i+1][j] = dp[i][j]
			else:
				dp[i+1][j] = min(dp[i+1][j], dp[i][j])
			I = i+1
			J = j | bit
			if dp[I][J] == -1:
				dp[I][J] = dp[i][j] + cost
			else:
				dp[I][J] = min(dp[I][J], dp[i][j] + cost)
print(dp[M-1][2**N-1])

Measured memory_bytes: 83800
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
    string input;

    cin >> input;

    vector<string>weather;
    weather.push_back("Sunny");
    weather.push_back("Cloudy");
    weather.push_back("Rainy");

    string tomorrow;
    for(int i=0;i<3;i++){
        if(weather[i]==input){
            tomorrow = weather[(i+1)%3];
        }
    }

    cout << tomorrow << endl;



    return 0;
}

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

namespace AtTest.ABC_124
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nk = ReadInts();
            int n = nk[0];
            int k = nk[1];
            string s = Read();
            List<int> cnts = new List<int>();
            if (s[0] == '0') cnts.Add(0);
            cnts.Add(1);
            for (int i = 1; i < n; i++)
            {
                if (s[i] == s[i - 1])
                {
                    cnts[cnts.Count - 1]++;
                }
                else
                {
                    cnts.Add(1);
                }
            }
            if (s[n - 1] == '0') cnts.Add(0);
            int sum = 0;
            if (cnts.Count <= 2*k+1)
            {
                for(int i = 0; i < cnts.Count; i++)
                {
                    sum += cnts[i];
                }
                WriteLine(sum);
                return;
            }
            for (int i = 0; i <  2 * k + 1; i++)
            {
                sum += cnts[i];
            }
            int res = sum;
            for (int i = 2; i + 2 * k < cnts.Count; i += 2)
            {
                sum -= cnts[i - 2] + cnts[i - 1];
                sum += cnts[i + 2 * k - 1] + cnts[i + 2 * k];
                res = Max(res, sum);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] -= i + 1;
  }
  ll ans = 0;
  sort(A.begin(), A.end());
  for (int i = 0; i < N; i++)
    ans += abs(A[i] - A[N / 2]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
from math import factorial
s= int(input())

def f(n):
	ans= 0
	for i in range(1, n//3+1):
		rem= n-3*i
		ans+= (factorial(rem+i-1)// factorial(i-1)//factorial(rem))%(10**9+7)
	return ans % (10**9+7)

print(f(s))

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

string abacus[] = {
    "* = ****",
    "* =* ***",
    "* =** **",
    "* =*** *",
    "* =**** ",
    " *= ****",
    " *=* ***",
    " *=** **",
    " *=*** *",
    " *=**** "
};

void print(int n) {
    vector<string> v;
    for (int k=10000; k>=1; k/=10) {
        v.push_back(abacus[n / k]);
        n %= k;
    }
    for (int i=0; i<8; ++i) {
        for (int j=0; j<5; ++j) {
            cout << v[j][i];
        }
        cout << endl;
    }
}

int main() {
    int n;
    bool lf = false;
    while (cin >> n) {
        if (lf) cout << endl;
        print(n);
        lf = true;
    }
    return 0;
}

Measured memory_bytes: 1200