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

int main(){
int H,W;
  cin>>H>>W;
char C[210][110];
  for(int i=0;i<H; i++){
   for(int j=0; j<W; j++){
    cin>>C[i][j]; }}
  
  for(int i=0; i<H; i++){
    cout<<C[i]<<endl;
    cout<<C[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

const int INF = 110000;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}
vector<vector<int>> a(100010, vector<int>(3));
int dp[100010][3];

int main() //input->compute->output
{
        int N;
        cin >> N;

        rep(i, N)
        {
                rep(j, 3) { cin >> a[i][j]; }
        }

        rep(i, N)
        {
                rep(j, 3)
                {
                        rep(k, 3)
                        {
                                if (j != k)
                                {
                                        dp[i + 1][k] = max(dp[i][j] + a[i][k], dp[i + 1][k]);
                                }
                        }
                }
        }

        cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;

        return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>

int main()
{
	int a,b,c;
	int swp;

	scanf("%d %d %d", &a, &b, &c);

	if(a > b)
	{
		swp = a;
		a = b;
		b = swp;
	}
	if(a > c)
	{
		swp = a;
		a = c;
		c = swp;
	}
	if(b > c)
	{
		swp = b;
		b = c;
		c = swp;
	}

	printf("%d %d %d\n", a, b, c);
	
	return 0;
}

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

int main() {
    int N,a,b, ans=0;
    cin >> N;
    rep(i, N) {
        cin >> a >> b;
        ans += b-a + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,K;
  cin >> N >> K;
  vi A(N);
  rep(i,N) cin >> A[i];
  
  rep2(i,K,N) {
    if(A[i]>A[i-K]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 4044
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll x, a, b;
  cin >> x >> a >> b;
  
  if (b <= a){
    cout << "delicious" << endl;
  } 
  else if (b - a <= x){
    cout << "safe" << endl;
  }
  else 
    cout << "dangerous" << endl;
  
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
    cin>>n>>k;
    int dp[n+1];
    int h[n+1];
    for(int i=1;i<=n;i++)
    	cin>>h[i];
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
    	 dp[i]=1e18;
    	 for(int j=1;j<=k;j++)
    	 {
    	   if(i>j)
    	   dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
         }
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[] one = new int[N];
		int[] two = new int[N];
		int[] three = new int[N];
		
		for(int i = 0; i < N; i++) {
			one[i] = sc.nextInt();
			two[i] = sc.nextInt();
			three[i] = sc.nextInt();
		}
		
		int[] pointOne = new int[N];
		int[] pointTwo = new int[N];
		int[] pointThree = new int[N];
		
		int flag = 0;
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(i == j) {
					continue;
				} else if(one[i] == one[j]) {
					flag = 1;
					break;
				}
			}
			
			if(flag == 0) {
				pointOne[i] = one[i];
			} else {
				pointOne[i] = 0;
			}
			
			flag = 0;
		}
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(i == j) {
					continue;
				} else if(two[i] == two[j]) {
					flag = 1;
					break;
				}
			}
			
			if(flag == 0) {
				pointTwo[i] = two[i];
			} else {
				pointTwo[i] = 0;
			}
			
			flag = 0;
		}
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(i == j) {
					continue;
				} else if(three[i] == three[j]) {
					flag = 1;
					break;
				}
			}
			
			if(flag == 0) {
				pointThree[i] = three[i];
			} else {
				pointThree[i] = 0;
			}
			
			flag = 0;
		}
		
		for(int i = 0; i < N; i++) {
			System.out.println(pointOne[i] + pointTwo[i] + pointThree[i]);
		}
		
	}
}

Measured memory_bytes: 28580
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <ctime>
#include <map>
#include <random>
#include <iomanip>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <bitset>
#include <deque>
#include <utility>

using namespace std;

vector<int> z_func(string &s) {
    int n = (int) s.size();
    vector<int> ret(n, 0);
    int l = 0;
    int r = -1;
    for (int i = 1; i < n; ++i) {
        if (l <= i && i <= r) {
            ret[i] = min(r - i + 1, ret[i - l]);
        }
        while (ret[i] + i < n && s[i + ret[i]] == s[ret[i]]) {
            ret[i]++;
        }
        if (i + ret[i] - 1 >= r) {
            l = i;
            r = i + ret[i] - 1;
        }
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t1 = a / d;
    if (t1 * d < a) {
        t1++;
    }
    int t2 = c / b;
    if (t1 * b < c) {
        t2++;
    }
    if (t1 >= t2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


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

const int maxn=105;
int len1, len2;
char s1[maxn], s2[maxn];

bool check(int pos){
    if(len1-pos+1<len2)return 0;
    for(int j=pos;j<pos+len2;j++){
        if(s1[j]!='?'&&s1[j]!=s2[j-pos])return 0;
    }
    return 1;
}

int main()
{
    int n, k;
    while(~scanf("%s%s", &s1, &s2)){
        len1=strlen(s1), len2=strlen(s2);
        if(len1<len2){
            printf("UNRESTORABLE\n");continue;
        }
        bool ans=0;
        int tpos=0;
        for(int i=0;i<len1;i++){
            if(check(i)){
                ans=1;
                tpos=i;
            }
        }
        if(!ans)printf("UNRESTORABLE\n");
        else{
            for(int i=tpos;i<tpos+len2;i++){
                s1[i]=s2[i-tpos];
            }
            for(int i=0;i<len1;i++){
                if(s1[i]=='?')s1[i]='a';
            }
            printf("%s\n", s1);
        }

    }
    return 0;
}


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

int main() {
	int k,n,a[200002];
	fill (a,a+200000,9999999);
	cin>>n>>k;
	int amt;
	amt=0;
	for (int x=0;x<n;x++){
		int b;
		cin>>b;
		if (a[b]==9999999){
			a[b]=1;
			amt+=1;
		}
		else {
			a[b]+=1;
		}
	}
	int pat;
	pat=0;
	sort (a,a+200000);
	for (int y=0;y<amt-k;y++){
		pat+=a[y];
	}
	cout<<pat<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <set>

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

using namespace std;

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

int main(void){
    string s, t;
    cin >> s >> t;
    int ctr = 10000;
    int n = s.size(), m = t.size();
    REP(i,n-m+1){
        int tmp = 0;
        REP(j,m){
            if(s[i+j] != t[j]){
                tmp++;
            }
        }
        ctr = min(ctr, tmp);
    }
    cout << ctr << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,i,j,res=0,paso=1;
		cin>>N;
		for(i=0;i<N;i++){
			cin>>arr[i];
		}
		sort(arr,arr+N);
		for(i=N-1;i>=0;i--){
			if(paso==1){
				res+=arr[i];
			}
			else {
				res-=arr[i];
			}
			paso=paso^1;
		}
		cout<<res;
	}
int main(){
	cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}

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

int main(){
  int i,a,b,c,N,ct;
  long long res;
  cin >> N;
  res = 0;
  for(i=1;i<N;i++)
    res += (N-1) / i;
  cout << res << endl;
  return 0;
}


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

int n;
int a[100001][3];

int dp[100001][3];

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


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#pragma warning(disable : 4996)
struct Node {
	int key;
	Node *p, *l, *r;
};
Node *root;
void insert(int key_) {
	Node *x = root, *y = 0, *z;
	z = (Node*)malloc(sizeof(Node));
	z->key = key_, z->l = 0, z->r = 0;
	while (x != 0) {
		y = x;
		x = (z->key < x->key) ? x->l : x->r;
	}
	z->p = y;
	if (y == 0) root = z;
	else if (z->key < y->key) y->l = z;
	else y->r = z;
}
void walk1(Node *x) { if (x == 0) return; walk1(x->l); printf(" %d", x->key); walk1(x->r); }
void walk2(Node *x) { if (x == 0) return; printf(" %d", x->key); walk2(x->l); walk2(x->r); }
int n, v; char c[8];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", &c);
		if (c[0] == 'i') scanf("%d", &v), insert(v);
		else walk1(root), printf("\n"), walk2(root), printf("\n");
	}
}

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

int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  cout<<*min_element(a.begin(), a.end())<<" ";
  cout<<*max_element(a.begin(), a.end())<<" ";
  cout<<accumulate(a.begin(), a.end(),0LL)<<endl;
}


Measured memory_bytes: 3140
n = gets.to_i

edges = []
g = Array.new(n){ [] }
(n-1).times do |i|
  e = gets.split.map(&:to_i).map{|k|k-=1}
  e[1], e[0] = e[0], e[1] if e[0] > e[1] # 辺は頂点 i < j の形で入れる。
  g[e[0]] << e[1] # 隣接リストに
  g[e[1]] << e[0] # 反対向きにも隣接リストに.無向グラフなので
  edges << e # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [0] # 頂点0から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてて頂点jは探索済みで,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

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

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;
	if (bool(int(s.size()) & 1) ^ (s.front() == s.back()))
		cout << "First\n";
	else
		cout << "Second\n";
}


Measured memory_bytes: 3788
using System;

namespace AOJ
{
    class Program
    {
        static void Main()
        {
            string[] line = Console.ReadLine().Split(' ');

            int[] num = TypeConverter.arrayStrToInt(line);
            Array.Sort(num);

            line = TypeConverter.arrayIntToStr(num);

            Console.WriteLine(string.Join(" ", line));
        }
    }

    class TypeConverter
    {
        static public int[] arrayStrToInt(string[] str)
        {
            return Array.ConvertAll<string, int>(str,
                delegate(string value)
                {
                    return int.Parse(value);
                }
            );
        }

        static public string[] arrayIntToStr(int[] x)
        {
            return Array.ConvertAll<int, string>(x,
                delegate(int value)
                {
                    return value.ToString();
                }
            );
        }
    }
}

Measured memory_bytes: 5748
/* -- 0105:Book Index -- */

#include	<iostream>
#include	<string>
#include	<vector>
#include	<utility>
#include	<algorithm>

using namespace std;

typedef pair< string, int > P;
typedef vector< P > Vec_S_I;

int main(void) {
	Vec_S_I Indexes;
	int buf_i, c;
	string buf_s;
	bool mstFirst = true, i_First = true;
	
	while(1) {
		cin >> buf_s >> buf_i;
		
		if( cin.eof() ) { break; }
		Indexes.push_back(P(buf_s, buf_i));
	}
	sort(Indexes.begin(), Indexes.end());
	Vec_S_I::iterator it = Indexes.begin();
	buf_s.erase();
	while(it != Indexes.end()) {
		if(buf_s != it->first) {
			if(!mstFirst) { cout << endl; }
			cout << it->first << endl;
			buf_s = it->first;
			i_First = true;
		}
		if(!i_First) { cout << ' '; }
		cout << it->second;
		i_First = false;
		mstFirst = false;
		it++;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1232
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    n, m = map(int, readline().rstrip().split())
    a = list(map(int, readline().rstrip().split()))
    print(n - sum(a) if n - sum(a) >= 0 else -1)


if __name__ == '__main__':
    main()


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

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  VI a(n);
  rep(i,n) cin >> a[i];
  
  VI s(h*w);
  int id=0;
  rep(i,n){
    rep(_,a[i]){
      s[id] = i+1;
      id++;
    }
  }
  
  rep(i,h){
    rep(j,w){
      if(i%2==0) cout << s[i*w + j] << " ";
      else cout << s[i*w + (w-j-1)] << " ";
    }
    cout << endl;
  }
  
  
  return 0;
}

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

const ll INF = 1001001001;

//提出のときに言語がc＋＋似合っていることを確認する

//絶対値の関数
int z(int a,int b){
  if(a>b) return a-b;
  else return b-a;
}





int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll>a(m);
  ll sum=0;
  rep(i,m){
    cin>>a[i];
    sum+=a[i];
  }
  if(sum>n){
    cout<<-1<<endl;
  }else{
    cout<<n-sum<<endl;
  }

}



Measured memory_bytes: 3704
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
int main(){
	int n; cin >> n;
	for(int i=0;i<n;i++){
		int a,b; cin >> a >> b;
		int cur,ret = 0;
		while(1){
			cur = abs(a);
			for(int i=30;i>=0;i--){
				if(cur % (1<<i) == 0 && a+(1<<i) <= b){
					a += (1<<i);
					ret++;
					break;
				}
			}
			if(a==b){ cout << ret << endl; break; }
		}
	}
}

Measured memory_bytes: 1160
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[] number = new int[5];
    int cnt = 0;
    for(int i=a;i<=b;i++){
      int num=i;
      int j=0;
      while(num>0){
        number[j++] = num%10;
        num/=10;
      }
      if(number[0]==number[4]&&number[1]==number[3]) cnt++;
    }
    System.out.println(cnt);
  }
}

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

pair<int,int> range(pair<int, int> range1,pair<int, int> range2);
int MIN(int a,int b);
int MAX(int a,int b);

int main()
{
	int n, m, temp1, temp2;
	vector<pair<int,int> > gates;
	cin >> n >> m;
	pair<int,int> p(1,n);
	for (int i = 0; i < m; i++)
	{
		cin >> temp1 >> temp2;
		//gates.push_back(make_pair(temp1, temp2));
		p=range(p,make_pair(temp1, temp2));
	}
	cout<<p.second-p.first+1<<endl;
}

pair<int,int> range(pair<int, int> range1,pair<int, int> range2)
{
    if(range1.second<range2.first || range2.second<range1.first)
        return make_pair(0,-1);
    else
        return make_pair(MAX(range1.first,range2.first),MIN(range1.second,range2.second));
}

int MIN(int a,int b)
{
    if(a<=b)
        return a;
    else
        return b;
}

int MAX(int a,int b)
{
    if(a>=b)
        return a;
    else
        return b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<int> a(n);
  REP(i, 0, n) {
    cin >> a[i];
    --a[i];
  }
  VEC<bool> pushed(n, 0);
  int now = a[0];
  VEC<int> history(n, -1);
  history[0] = 0;
  pushed[0] = 1;
  int cnt = 1;
  REP(i, 1, n) {
    if (pushed[now])
      break;
    if (now == 1) {
      cout << cnt << endl;
      return 0;
    }

    history[i] = now;
    pushed[now] = 1;
    now = a[now];
    cnt++;
  }
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,W;
ll dp[100010];//dp[i]=価値iを手に入れるための最小重さ
int main(){
	scanf("%lld%lld",&n,&W);
	rep(i,1,100005)dp[i]=INF;
	rep(i,0,n){
		ll w,v;
		scanf("%lld%lld",&w,&v);
		for(int j=100005-v;j>=0;j--)dp[j+v]=min(dp[j+v],dp[j]+w);
	}
	ll ans=100000;
	while(dp[ans]>W)ans--;
	printf("%lld\n",ans);
	return 0;
}

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

int main(void)
{
	int n = 0;
	int m = 0;
	int result = 0;

	cin >> n >> m;

	result = n * (n - 1) / 2 + m * (m - 1) / 2;

	cout << result << endl;

	return 0;
}


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


int main(){
  int N;
  cin >> N;
  int counter = 0;
  for(int ii=1; ii<=N; ii++){
    int a;
    cin >> a;
    if(a!=ii) counter++;
    if(counter > 2){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii              pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define __              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,b) 		for(int i=a;i<b;i++)
#define repb(i,a,b) 	for(int i=a;i>=b;i--)
#define endl			"\n"
#define m(a)		    memset(a,0,sizeof(a))
#define all(x)                          begin(x), end(x)

void fastscan(int &x){
bool neg = false; register int c;
x = 0;c = getchar();
if(c=='-'){neg = true;c = getchar();}
for(; (c>47 && c<58); c=getchar()){x = x *10 + c - 48;}
if(neg){x *= -1;}}

void file(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt" , "r" , stdin);
	freopen("out.txt" , "w" , stdout);
	#endif
}

int bs(int a[] , int s , int e, int x){
	if(s<=e){
		int m = (s+e)/2;
		if(a[m]==x)
			return m;
		else if(a[m] > x)
			return bs(a,s,m-1,x);
		else return bs(a,m+1,e,x);
	}
	return -1;
}

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr5(v,w,x,y,z) cout<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr6(u,v,w,x,y,z) cout<<u<<" "<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define deb3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl

#define sd(x) cin >> x;
#define sd2(x,y) cin >> x >> y;
#define sd3(x,y,z) cin >> x >> y >> z;
#define sd4(w,x,y,z) cin >> w >> x >> y >> z;

bool is_pal(string s) {return equal(all(s), s.rbegin());}

int mypow(int a, int b){        //(logn) fast exponentiation
    int res = 1;            // call int x = mypow(2,5);
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return (res%mod);
}	

void A(){
	int n; sd(n);
	if(n%1000){
		cout << 1000-(n%1000) << endl;
	}
	else{
		cout << 0 << endl;
	}
}

int32_t main(){	
	__;
	file();
	int n; sd(n); map<string,int>m;
	m["AC"]=0;
	m["TLE"]=0;
	m["WA"]=0;
	m["RE"]=0;
	rep(i ,0,n){
		string s; cin>>s;
		m[s]++;
	}
	cout << "AC" << " x " << m["AC"] << endl; 
	cout << "WA" << " x " << m["WA"] << endl; 
	cout << "TLE" << " x " << m["TLE"] << endl; 
	cout << "RE" << " x " << m["RE"] << endl; 


	return 0;
}






Measured memory_bytes: 3520
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    int n;
    cin>>n;
    n=n%10;
    vector<int>hon={2,4,5,7,9};
    vector<int>pon={0,1,6,8};
    vector<int>bon={3};
    for(auto i:hon)
    if(i==n){
        cout<<"hon"<<endl;
        return 0;
    } 
    for(auto i:pon)
    if(i==n){
        cout<<"pon"<<endl;
        return 0;
    }
    for(auto i:bon)
    if(i==n){
        cout<<"bon"<<endl;
        return 0;
    }
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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 V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    //map<ll,set<ll>> mp;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    
    map<ll,ll> mp;
    for(ll i = 0; i < N;i++){
        
        ll X = i - A[i];
        res += mp[X];
        
        mp[A[i]+i]++;
    }
    
//    for(int i = 0; i < N;i++){
//        mp[A[i]].insert(i);
//    }
//
//    for(int j = 1; j < N;j++){
//        ll R = j - A[j];
//        for(auto& p:mp){
//            ll RR = R - p.first;
//            if(RR < 0) break;
//
//            auto& vs = p.second;
//            if(vs.find(RR) != vs.end()) res++;
//        }
//    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 27392
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def solve():
    a,b,c = getList()

    k = getN()
    ans = 0
    while(b <= a):
        b *= 2
        ans += 1
    while(c <= b):
        c *= 2
        ans += 1

    if ans <= k:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 67404
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define FOR(n) for (int _i = 0; _i < (n); _i++)
 
#define pb push_back
#define all(in) in.begin(),in.end()
 
using ll = long long;
using ull = unsigned long long;
using namespace std;
 
int main(){
    string s; cin >> s;
    ll n = s.length();
    ll ans = 0, save = 0;
    rep(i,n){
        int d = s[n-1-i] - '0';
        if(d + save <= 4){ ans += d + save; save = 0; }
      	else if(d + save == 5 && i < n-1 && s[n-2-i]-'0' <= 4){ ans += d + save; save = 0; }
      	else if(d + save == 5 && i == n-1){ ans += d + save; save = 0; }
        else { ans += 10 - d - save; save = 1; }
    }
    if(save) ans++;
    cout << ans << endl;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, count = 1, min;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; ++i){
cin >> a[i];
  }
  min = a[0];
for (int j = 1; j < n; ++j){
if (a[j] < min){
	++count;
	min = a[j];
}
}
cout << count << "\n";
return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;

double dp[3000][3000];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<double> p(n);
    for(int i=0;i<n;i++){
        cin >> p[i];
    }
    dp[0][0]=1.0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]+=dp[i][j]*p[i];
            dp[i+1][j]+=dp[i][j]*(1.0-p[i]);
        }
    }
    double res=0;
    for(int i=(n+1)/2;i<=n;i++){
        res+=dp[n][i];
    }
    printf("%.9f\n",res);
}


Measured memory_bytes: 49864
#include<cstdio>

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

using namespace std;

inline int f(const char *s){
	if(s[0]=='C' && s[1]=='\0') return 0;
	if(s[0]=='C' && s[1]=='#' ) return 1;
	if(s[0]=='D' && s[1]=='\0') return 2;
	if(s[0]=='D' && s[1]=='#' ) return 3;
	if(s[0]=='E' && s[1]=='\0') return 4;
	if(s[0]=='F' && s[1]=='\0') return 5;
	if(s[0]=='F' && s[1]=='#' ) return 6;
	if(s[0]=='G' && s[1]=='\0') return 7;
	if(s[0]=='G' && s[1]=='#' ) return 8;
	if(s[0]=='A' && s[1]=='\0') return 9;
	if(s[0]=='A' && s[1]=='#' ) return 10;
	return 11;
}

inline int dist(int t1,int t2){ return (t1-t2+12)%12; }

int main(){
	int T; scanf("%d",&T);
	while(T--){
		int n,m; scanf("%d%d",&n,&m);
		static int t[50000],s[50000];
		rep(i,n){ char in[3]; scanf("%s",in); t[i]=f(in); }
		rep(i,m){ char in[3]; scanf("%s",in); s[i]=f(in); }

		bool ok=false;
		rep(k,2){
			int pos=n-k-1;
			if(pos>=0 && (dist(s[m-1],t[pos])<=1 || dist(s[m-1],t[pos])==11)){
				int i;
				for(i=m-1;i>=0;i--){
					int d=dist(s[i],t[pos]);
					if     (d== 0) pos--;
					else if(d== 1) pos-=2;
					else if(d==11) pos++;
					else break;

					if(i==0 && (pos<-1 || n<=pos)
					|| i!=0 && (pos< 0 || n<=pos)) break;
				}

				if(i==-1 && pos==-1){ ok=true; break; }
			}
		}

		puts(ok?"Yes":"No");
	}

	return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> x(n), y(n), z(n);
	for (int i = 0;i < n;i++) {
		cin >> x[i] >> y[i] >> z[i];
	}
	vector<ll> score[2][2][2];
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			for (int k = 0;k < 2;k++) {
				score[i][j][k].resize(n);
			}
		}
	}
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			for (int k = 0;k < 2;k++) {
				for (int l = 0;l < n;l++) {
					score[i][j][k][l] = pow(-1, i)*x[l] + pow(-1, j)*y[l] + pow(-1, k)*z[l];
				}
			}
		}
	}

	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			for (int k = 0;k < 2;k++) {
				sort(score[i][j][k].begin(), score[i][j][k].end());
			}
		}
	}
	ll ans = -1e13;
	for (int i = 0;i < 2;i++) {
		for (int j = 0;j < 2;j++) {
			for (int k = 0;k < 2;k++) {
				ll sum = 0;
				for (int l = 0;l < m;l++) {
					sum += score[i][j][k][n - l - 1];
				}
				ans = max(ans, sum);
			}
		}
	}
	cout << ans << endl;





	return 0;
}

Measured memory_bytes: 384
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<climits>  
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;     
int read(){     
    int f=1,x=0;char c=getchar();        
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}       
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();     
    return x*f;    
}
#define MAXN 400
#define INF 0x3f3f3f3f
int H,W,dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
LL Ans,cnt1,cnt2;
bool vis[MAXN+5][MAXN+5];
char Map[MAXN+5][MAXN+5];
void BFS(int X,int Y){
	cnt1=0,cnt2=0;
	queue<pair<int,int> > Q;
	Q.push(make_pair(X,Y)),vis[X][Y]=1;
	while(!Q.empty()){
		int nx=Q.front().first,ny=Q.front().second;
		Q.pop();
		if(Map[nx][ny]=='.') cnt1++;
		else cnt2++;
		for(int i=0;i<4;i++){
			int x=nx+dx[i],y=ny+dy[i];
			if(x<1||y<1||x>H||y>W||vis[x][y]||Map[x][y]==Map[nx][ny]) continue;
			vis[x][y]=1,Q.push(make_pair(x,y));
		}
	}
	Ans+=cnt1*cnt2;
	return ;
}
int main(){
	H=read(),W=read();
	for(int i=1;i<=H;i++)
		scanf("%s",Map[i]+1);
	for(int i=1;i<=H;i++)
		for(int j=1;j<=W;j++)
			if(!vis[i][j]&&Map[i][j]=='.')
				BFS(i,j);
	printf("%lld\n",Ans);
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
		//order_of_key (k) : Number of items strictly smaller than k .
		//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)           


void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

class DSU
{
	public : 
	vector < int >  parent, sz;
	DSU(int n)
	{
		parent = vector < int > (n + 1); 
		sz = vector < int > (n + 1, 1); 
		iota(parent.begin(), parent.end(), 0);  
	}

	int find_set(int i)
	{
		if(i == parent[i])
			return i; 
		else return parent[i] = find_set(parent[i]); 
	}

	void union_sets(int i, int j)
	{ 
		i = find_set(i); 
		j = find_set(j);

		if(i  == j)
			return; 

		if(sz[i] > sz[j])
			swap(i, j);  
		
		parent[i] = j; 
		sz[j] += sz[i]; 
	}
}; 

int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	DSU d(n); 

	int m; 
	cin >> m; 
	for(int i = 0; i < m; ++ i)
	{
		int x, y; 
		cin >> x >> y; 
		d.union_sets(x, y); 
	}

	int ans = 0; 
	for(int i = 1; i <= n; ++ i)
		ans = max(ans, d.sz[i]); 

	cout << ans; 

	return 0;
}

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

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    ll n;
    cin >> n;
    ll ans = lINF;
    for (ll i=1;i<=sqrt(n);i++){
        if (n%i==0){
            ans = min(ans,(ll)(i-1)+(n/i-1));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 1000000000000
typedef long long ll;
using namespace std;

int main(){
  int n;
  int a;
  int sum=0;
  bitset<4000000> dp(1);

  cin>>n;
  for(int i=0;i<n;i++){
    scanf("%d",&a);
    sum+=a;
    dp |= (dp<<a);
  }
  for(int i=(sum-1)/2+1;i<2002000;i++){
    if(dp.test(i)){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1664
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

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

void solve() {
  int a, b;
  cin >> a >> b;
  if(a == b) cout << "Yes\n";
  else cout << "No\n";
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int k;
set<string> ss;
main()
{
    cin>>s>>k;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        string t;
        for(int j=i;j<min(i+5,n);j++)
        {
            t+=s[j];
            ss.insert(t);
        }
    }
    auto it=ss.begin();
    k--;
    while(k--)it++;
    cout<<*it;
    return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>c(m);
    rep(i,m)cin>>c[i];
    vector<int>t(n+1);

    rep(i,n+1)t[i]=inf;
    t[0]=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<m;j++){
            if(c[j]<=i){
                t[i]=min(t[i],t[i-c[j]]+1);
            }
        }
    }

    cout<<t[n]<<endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s = "";
  n--;
  while(n >= 0){
    s += 'a' + n % 26;
    n /= 26;
    n--;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

Measured memory_bytes: 3528
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>

using namespace std;

void solve(int A, int B, int C) {
  int ans = C - min(A - B, C);
  printf("%d\n", ans);
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  solve(A, B, C);
  return 0;
}

Measured memory_bytes: 888
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n=int(input())
count=[0]*n
a=list(map(int,stdin.readline().split()))
for i in a:
    count[i-1]+=1
for i in count:
    print(i)

Measured memory_bytes: 91892
void main()
{
    long n = rdElem;

    coord[] ab = new coord[n];
    foreach (i; 0 .. n)
    {
        long[] tmp = rdRow;
        ab[i].x = tmp[0], ab[i].y = tmp[1];
    }

    coord[] cd = new coord[n];
    foreach (i; 0 .. n)
    {
        long[] tmp = rdRow;
        cd[i].x = tmp[0], cd[i].y = tmp[1];
    }

    ab.sort!((x, y) => x.y > y.y);
    cd.sort!((x, y) => x.x < y.x);

    long cnt;
    bool[] rem = new bool[n];
    rem[] = true;
    foreach (x; cd)
    {
        foreach (i, y; ab)
        {
            if (y.x < x.x && y.y < x.y && rem[i])
            {
                ++cnt;
                rem[i] = false;
                break;
            }
        }
    }

    cnt.writeln;
}

alias Tuple!(long, "x", long, "y") coord;

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

using namespace std;

int main() {
    int A, B;
    cin >> A >> B;

    // int(x * 8 / 100) = A  -> x * 8  = A * 100 -> x = A * 100 / 8
    // int(x * 10 / 100) = B -> x * 10 = B * 100 -> x = B * 100 / 10

    // iの最大値は, max * 8 /100 = 100 -> max = 1250 -> max = 1500 0(N)
    int res = -1;
    for (int i = 1; i <= 1500; i++) {
        if (i * 8 / 100 == A && i * 10 / 100 == B) {
            res = i;
            break;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
n, m, q = map(int, input().split())

x = [[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    x[a-1][b-1] += 1

for j in range(1, n):
    for k in range(n-j):
        x[k][j+k] += x[k][j+k-1] + x[k+1][j+k] - x[k+1][j+k-1]

for i in range(q):
    a, b = map(int, input().split())
    print(x[a-1][b-1])

Measured memory_bytes: 74244
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ii pair<ll,ll>;
#define vi vector<int>;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fbo find_by_order
#define ook order_of_key
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define fo(i,a,b) for(i = a; i < b; i++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int main(){
    IOS
    //io_set();
    string s;
    cin >> s;
    ll i,c=0,n=s.size();
    fo(i,0,n){
        if(i%2 == 0 && s[i] == '1'){
            c++;
        }
        if(i%2 == 1 && s[i] =='0'){
            c++;
        }
    }
    cout<<min(c,n-c)<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define MOD (998244353)
using namespace std;

int main(void){
    int k,x;
    cin >> k >> x;
    for(int i=x-k+1;i<=x+k-1;i++){
        printf("%d ",i);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.readline

N, M = map(int, readline().split())
S = list(map(int, readline().split()))
T = list(map(int, readline().split()))

P = 10 ** 9 + 7

dp = [[0] * (M + 1) for i in range(N + 1)]

for x in range(1, N + 1):
    for y in range(1, M + 1):
        dp[x][y] = dp[x][y - 1] + dp[x - 1][y] - dp[x - 1][y - 1]
        if S[x - 1] == T[y - 1]:
            dp[x][y] += dp[x - 1][y - 1] + 1

        dp[x][y] = dp[x][y] % P

ans = dp[N][M] + 1
print(ans % P)


Measured memory_bytes: 72892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    string S;
    cin >> N >> K >> S;
    int unhappy = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'L') {
            if(i == 0 || S[i-1] == 'R') unhappy++;
        }
        else {
            if(i == N - 1 || S[i+1] == 'L') unhappy++;
        }
    }
    unhappy = max(1, unhappy - 2 * K);
    cout << N - unhappy << endl;
    return 0;
}


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

int main() {
	int a, b, c, d, sum = 0;;
	string s, ans = "";
	cin >> s;
	a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
	rep(i, 8) {
		sum = a;
		ans += a + '0';
		if (i & 1) {
			sum += b;
			ans += "+";
		}
		else {
			sum -= b;
			ans += "-";
		}
		ans += b + '0';
		if (i >> 1 & 1) {
			sum += c;
			ans += "+";
		}
		else {
			sum -= c;
			ans += "-";
		}
		ans += c + '0';
		if (i >> 2 & 1) {
			sum += d;
			ans += "+";
		}
		else {
			sum -= d;
			ans += "-";
		}
		ans += d + '0';
		ans += "=7";
		if (sum == 7) {
			cout << ans << endl;
			return 0;
		}
		else ans.clear();
	}
		return 0;
}

Measured memory_bytes: 256