akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
    using namespace std;
    int main(){
      int n;
      cin>>n;
      int a[n];
      for(int i=0;i<n;i++){
        cin>>a[i];
      }
      int b[100]={0};
      for(int i=0;i<n;i++){
        b[(a[i]-1)]+=1;
      }
      int cnt=0;
      for(int i=0;i<100;i++){
        if(b[i]>0)cnt++;
      }
      cout<<cnt<<endl;
      return 0;
    }

Measured memory_bytes: 256
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();
		long h[]=new long [n];
	      for(int i=0;i<n;i++){
			h[i] = sc.nextLong();
	      }
	      long x=0;
	      Arrays.sort(h);
	      for(int i=0;i<(n-k);i++) {
	    	  x+=h[i];
	      }

		  		System.out.print(x);

	}
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

int n;
string s; 

int main()
{
  fastio;
  int res = 0;
  cin >> n >> s;
  for (int i = 0; i < n - 2; i++){
    string cur = "";
    for (int j = 0; j < 3; j++) cur += s[i + j];
    res += (cur == "ABC");
  }
  cout << res;
  return 0;
}

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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b+c >= 22) cout << "bust\n";
    else cout << "win\n";
    return 0;
}



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

int main(){
    int result[26];
    for(int i=0;i<26;i++)result[i]=0;
    while(1){
        string str;
        cin>>str;
        if(str.length()==0)break;
        for(int i=0;i<str.length();i++){
            if((str[i]>='A')&&(str[i]<='Z')){
                result[str[i]-'A']++;
                continue;
            }
            if((str[i]>='a')&&(str[i]<='z')){
                result[str[i]-'a']++;
                continue;
            }
        }
    }
    for(char c='a';c<='z';c++){
            cout<<c<<" : "<<result[(int)(c-'a')]<<endl;
        }
    return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;
ll cnt[100];
ll ans = 0;//両端が同じ文字であるような部分文字列の数

int main() {
	cin >> s;
	rep(i, s.size())cnt[s[i] - 'a']++;
	rep(i, 26) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << s.size()*(s.size() - 1) / 2 - ans + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T, class T2> void smin(T& a, T2 val) {if (a > val) a = val;}template<class T, class T2> void smax(T& a, T2 val) {if (a < val) a = val;}
const int N = 2*(int)1e5 + 10;

int n;
vector<int> v[N];

struct UnionFind
{
   vector<int> parent, size;

   UnionFind(int n){
      parent.resize(n+1);
      iota(parent.begin(), parent.end(), 0);
      size.assign(n+1, 1);
   }

   int find(int x){
      while(x != parent[x]){
         parent[x] = parent[parent[x]];
         x = parent[x];
      }
      return x;
   }

   bool unite(int x, int y){
      x = find(x), y = find(y);
      if(x == y)
         return false;
      if(size[x] < size[y])swap(x, y);
      size[x] += size[y];
      parent[y] = x;
      return true;
   } 

   int getSize(int x){
      x = find(x);
      return size[x];
   }
};

#define greater dxedc
int greater[N];

int32_t main(){_
   
   cin>>n;

   for (int i = 0; i+1 < n; ++i)
   {
      int x, y;
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
      if (x < y){
         greater[x] += n-y+1;
      }
      else{
         greater[y] += n-x+1;
      }
   }

   // consider answer for only 1

   UnionFind S(n);
   int ret = 0;
   int ans = 1;

   int curr = 1;
   for (int i = 2; i <= n; ++i)
   {
      curr++;
      for(auto &it: v[i]){
         if (it <= i){
            if (S.unite(i, it)){
               curr--;  
            }
         }
      }
      ans += curr;
   }

   tr(ans);

   ret = ans;

   int ptr = n;
   for (int vertex = 2; vertex <= n; ++vertex)
   {
      int currans = ans + greater[vertex-1] - ptr;
      ret += (currans);
      tr(vertex, currans, greater[vertex-1], ans, ret);
      ans = currans;
      ptr--;
   }

   cout<<ret;

   return 0;
}

Measured memory_bytes: 20452
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int l, r, x;
	cin >> l >> r >> x;
	int ans = 0;
	for (int i = l; i <= r; i++) {
		if (i % x == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y){
    int c[N+1][N+1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' '+X;
    Y = ' '+Y;
    for(int i = 0;i <= m;i++) c[i][0] = 0;
    for(int j = 1;j <= n;j++) c[0][j] = 0;
    
    for(int i = 1;i <= m;i++){
        for(int j = 1;j <= n;j++){
            if(X[i] == Y[j]){
                c[i][j] = c[i-1][j-1]+1;
            }else{
                c[i][j] = max(c[i-1][j],c[i][j-1]);
            }
            maxl = max(maxl,c[i][j]);
        }
    }
    
    return maxl;
}

int main(){
    string s1,s2;
    int n; cin >> n;
    for(int i = 0;i < n;i++){
        cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }
    return 0;
}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=50001,INF=1<<30;

int main(){

    int N,W;cin>>N>>W;
    vector<int> v(N),w(N);
    vector<vector<int>> dp(N+1,vector<int>(W+1,0));
    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    
    for(int k=1;k<=N;k++){
        for(int i=0;i<=W;i++){
            dp[k][i]=max(dp[k-1][i],dp[k][i]);
            if(i-w[k-1]>=0) dp[k][i]=max(dp[k][i-w[k-1]]+v[k-1],dp[k][i]);
        }
    }
    
    int ans=0;
    
    for(int i=0;i<=W;i++){
        ans=max(ans,dp[N][i]);
    }
    
    cout<<ans<<endl;
}




Measured memory_bytes: 6776
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let n: usize = sc.read();
        let a: usize = sc.read();
        let b: usize = sc.read();
        let c: usize = sc.read();
        let mut x: usize = sc.read();
        if n == 0 { break; };
        let mut idx: usize = 0;
        let mut y: usize = sc.read();
        let mut fl = false;
        for i in 0..10001 {
            if x == y {
                idx += 1;
                if idx == n {
                    println!("{}", i);
                    fl = true;
                    break;
                } else {
                    y = sc.read();
                }
            }
            x = (a * x + b) % c;
        }
        if !fl {
            idx += 1;
            while idx < n {
                idx += 1;
                let _: usize = sc.read();
            }
            println!("{}", -1);
        }
    }
}



Measured memory_bytes: 5044
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
cnt = 0
for i in range(n):
    res = 0
    for j in range(m):
        res += a[i][j]*b[j]
    if res+c>0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			System.setIn(new FileInputStream("src/aoj0030/input.txt"));
			System.setOut(new PrintStream(new FileOutputStream("src/xxxyyyy/result.txt")));
		} catch (FileNotFoundException e) {
		}
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int s = sc.nextInt();
			if (n == 0 && s == 0)
				break;
			System.out.println(solve(n, s));
		}
	}

	int solve(int N, int sum) {
		int res = 0;
		for (int set = 0; set < 1 << 10; set++) {
			int temp = 0;
			int bit = 0;
			for (int k = 0; k < 10; k++)
				if ((set >> k & 1) == 1) {
					temp += k;
					bit++;
				}
			if( bit == N && temp == sum )
				res++;
		}
		return res;
	}

	void debug(Object... os) {
		System.err.println(deepToString(os));
	}
}

Measured memory_bytes: 12000
import math

N, A, B = map(int, input().split())

h = []
min_h = 10 ** 10
max_h = 0
for _ in range(N):
    hi = int(input())
    if hi < min_h:
        min_h = hi
    if hi > max_h:
        max_h = hi
    h.append(hi)
    
min_K = math.ceil(min_h / A)
max_K = math.ceil(max_h / B)
K = min_K
while(min_K != max_K):
    x = [math.ceil((n - K * B) / (A - B)) for n in h]
    sum_x = sum([xi for xi in x if xi > 0])
    if sum_x <= K:
        max_K = K
        K = math.floor((min_K + K) / 2)
    else:
        min_K = K + 1
        K = math.floor((K + max_K) / 2) + 1

print(min_K)

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

int main(){
  string s,t;
  cin>>s>>t;
  bool a=true;
  int b=s.size();
  for(int i=0;i<b;i++){
    if(s.at(i) != t.at(i))
      a=false;
  }
  if(a)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define p first
#define d second
using namespace std;
int par[100001],D[100001],sum[100001];

int find(int x){
  if(par[x]!=x){
    int px=par[x];
    par[x]=find(par[x]);
    D[x]+=D[px];
    return par[x];
  }
  return x;
}

void Union(int x,int y,int c){
  int rx=find(x);
  int ry=find(y);
  if(rx==ry)return;
  par[rx]=ry;
  D[rx]=c+D[y]-D[x];
}

void IN(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  sum[a]+=c;
  sum[b]+=c;
  Union(a,b,c-sum[b]+sum[a]);
}

void COMP(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(find(a)!=find(b))printf("WARNING\n");
  else printf("%d\n",D[a]-D[b]+sum[b]-sum[a]);
}
int main(){
  int n,q;
  cin>>n>>q;
  for(int i=1;i<=n;i++)par[i]=i;
  while(q--){
    char s[10];
    scanf("%s",s);
    if(s[0]=='I')IN();
    else COMP();
  }
  return 0;
}

Measured memory_bytes: 2404
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize, a: usize, b: usize};
    let mut result = 0;

    for i in 1..n + 1 {
        let i_s = i.to_string();
        let mut sum = 0;
        for i_num in i_s.as_str().chars() {
            sum += i_num as usize - 48;
        }

        if sum >= a && b >= sum {
            result += i;
        }
    }

    println!("{}", result);
}


Measured memory_bytes: 2140
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

map <int, int> Mx;
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		Mx[t]++;
	}

	int ans = 0;
	for (auto it : Mx) {
		int t1 = it.first, t2 = it.second;
		if (t1 <= t2) ans += t2 - t1;
		else ans += t2;
	}
	return !printf("%d\n", ans);
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define repr(i,n) for(int i=(n)-1;i>=0;i--)
#define repra(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define sortn(a) sort((a).begin(),(a).end())
#define sortr(a) sort((a).begin(),(a).end(),greater<int>())
#define MOD 1000000007

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

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

    vvi dp(n+1,vi(n+1));

    repr(i,n){
        repra(j,i+1,n){
            if(s[i] != s[j])dp[i][j] = 0;
            else dp[i][j] = min(j-i, dp[i+1][j+1] + 1);
            //cout << "i,j=" << i << "," << j << "  dp=" << dp[i][j] << endl;
        }
    }

    rep(i,n){
        rep(j,n){
            ans = max(ans,dp[i][j]);
        }
    }

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



Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
ll cst[26], sat[366][26], last[26];
int main(){
	scanf("%d", &n);
	memset(last, 0ll, sizeof(last));
	for(int i=0; i<26; i++) scanf("%lld", &cst[i]);
	for(int i=0; i<n; i++) for(int j=0; j<26; j++)
		scanf("%lld", &sat[i][j]);
	ll res = 0ll;
	for(int nw, i=0; i<n; i++){
		scanf("%d", &nw);
		res += sat[i][nw-1];
		last[nw-1] = i+1;
		for(int j=0; j<26; j++)
			res -= cst[j]*(i+1-last[j]);
		printf("%lld\n", res);
	}
	return 0;
}

Measured memory_bytes: 3880
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define FORD(i, a, b) for (int i=(a); i>(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define SZ(x) ((int)(x).size())
#define BACK(x) prev((x).end())
#define HASK(x, y) ((x).find(y) != (x).end())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 19, mod = 1000000007;
struct FFT //maxN - potega2
{
	#define CMPX complex <double>	//long double - mozliwe tle
    CMPX A[maxN], B[maxN], C[maxN], omega[maxN + 1];
    unsigned int bitrev[maxN];
    unsigned int builtin_bitrev(unsigned int M)
    {
        static unsigned int m[5] =
        {0xFFFF0000, 0xFF00FF00, 0xF0F0F0F0, 0xCCCCCCCC, 0xAAAAAAAA};
        for (int i=0, d=16; i<5; i++, d>>=1)
            M = ((M & m[i]) >> d) | ((M & ~m[i]) << d);
        return M;
    }
    void init()
    {
    	FOR(i, 0, maxN)	bitrev[i] = builtin_bitrev(i);
    	for (int d=1; d<maxN; d*=2)
    	{
    		double ang = M_PI / (maxN / (d*2));
    		for (int i=1; d*i<maxN; i+=2)
    			omega[d*i] = CMPX(cos(ang*i), sin(ang*i));
    	}
    	omega[0] = omega[maxN] = CMPX(1, 0);
    }
    void fft_iter(CMPX* a, CMPX* res, int n, int dir)
    {
        int w = __builtin_clz(n) + 1;
        FOR(i, 0, n)	res[bitrev[i] >> w] = a[i];
        for (int len=2, lg=1; len<=n; len*=2, lg++)
        {
            int d = (maxN >> lg) * dir;
            for (CMPX* t = res; t != res + n; t += len)
            {
                int j = dir == 1 ? 0 : maxN;
                FOR(i, 0, len/2)
                {
                    CMPX x = t[len/2 + i] * omega[j];
                    t[len/2 + i] = t[i] - x;
                    t[i] += x;	j += d;
                }
            }
        }
    }
    void mult_polys_fft(vector <long long>& a, vector <long long>& c)
    {
        int g = 1, n = a.size(), m = a.size(); c.resize(n + m);
        while (g < c.size())   g *= 2;
        FOR(i, 0, n)    A[i] = CMPX(a[i], 0);
        FOR(i, n, g)    A[i] = CMPX(0, 0);
        fft_iter(A, B, g, 1);
        FOR(i, 0, g)    B[i] *= B[i];
        fft_iter(B, A, g, -1);
        FOR(i, 0, c.size())	c[i] = A[i].real() / g + 0.5;
    }
}alg;

vector <long long> A, B;

void solve()
{
	int n;
	long long m;
	scanf ("%d%lld", &n, &m);
	A.resize(maxN / 2, 0);
	FOR(i, 0, n)
	{
		int a;
		scanf ("%d", &a);
		A[a]++;
	}
	
	alg.init();
	alg.mult_polys_fft(A, B);
	long long res = 0;
	
	FORD(i, SZ(B)-1, -1)
	{
		long long mn = min(m, B[i]);
		m -= mn, B[i] -= mn;
		res += mn * i;
	}
	
	printf("%lld\n", res);
}
 
int main()
{
	int t = 1;
	//scanf ("%d", &t);
	FOR(tid, 1, t+1)
	{
		//printf("Case #%d: ", tid);
		solve();
	}
	return 0;
}
 





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

int main()
{
  int a,b,c,flg;
  cin >> a >> b >> c;
  flg=0;
  
  for(int i=1; i<=b; i++){
    if(a*i%b == c){
      flg = 1;
      break;
    }
  }
  
  if(flg==1) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]


from collections import Counter


INF = float("inf")
MOD = 10**9 + 7


def main():
    N = INT()
    S = [input() for i in range(N)]
    c = Counter(S)
    print("AC x "+str(c["AC"]))
    print("WA x "+str(c["WA"]))
    print("TLE x "+str(c["TLE"]))
    print("RE x "+str(c["RE"]))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 16604
K, A, B = map(int,input().split())
if B-A <= 2:
    print(K+1)
    exit(0)
elif A-1 >= K:
    print(K+1)
else:
    t = (K-A+1)//2
    print(A + (B-A)*t + K-A+1-2*t)


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

template<typename T>
void read(T &ans){T f = 1; char c = getchar();ans = 0;while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}while( isdigit(c)){ans = ans*10 + c - '0';c = getchar();}ans *= f;}

int fa[100001], n, m, a[100001];
int find(int u){
    return (u == fa[u]) ? u : fa[u] = find(fa[u]);
}
signed main(){
    read(n), read(m);
    for(int i = 1;i <= n; i++){
        read(a[i]);
        fa[i] = i;
    }
    for(int i = 1; i <= m; i++){
        int u, v;
        read(u), read(v);
        if(find(u) == find(v))continue;
        fa[find(u)] = find(v);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(find(i) == find(a[i])) ans++;
    }
    cout<<ans<<endl;
//    printf("%d %d", find(1), find(5)); 
    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8

# ??\???
s = input()
p = input()

s_length = len(s)
ans = False

# s???????????????????§????????????????????¬?????´¢
for s_index in range(len(s)):
    flag = True
    for p_index in range(len(p)):
        target_index = (s_index + p_index) % len(s)
        if s[target_index] != p[p_index]:
            flag = False
            break
    if flag:
        ans = True
        break

if ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 7448
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor:GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)
def lcm(x, y):
    return (x * y) // gcd(x, y)

MOD = int(1e9 + 7)

N = int(input())
A = list(map(int, input().split()))

LCM = 1

for i in range(N):
    LCM = lcm(LCM, A[i])
ans = 0
for i in range(N):
    ans += LCM * pow(A[i], MOD - 2, MOD)
print(ans%MOD)

Measured memory_bytes: 72024
#include <iostream>
#include <queue>

using namespace std;

typedef long long ll;
typedef queue<ll> ql;

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

    ll n;
    cin >> n;

    ll ans = 0;

    // pk + 1 == n
    for (int i = 1; 1ll * i * i <= n - 1; i++) {
        if ((n - 1) % i == 0) {
            if (i != 1) {
                ans++;
            }
            if (1ll * i * i != n - 1) {
                ans++;
            }
        }
    }

    // k^t * (pk + 1) == n, t >= 1, k != n
    for (int i = 2; 1ll * i * i <= n; i++) {
        for (ll j = i; n % j == 0; j *= i) {
            if (n / j % i == 1) {
                ans++;
            }
        }
    }

    // k == n
    ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int Q;
    cin>>Q;
    while(Q--){
        int a,b;
        cin>>a>>b;
        long long s = 1LL*a*b;

        long long root = (long long)floor(sqrt(s)+1e-12);
        // cout<<a*b<<' '<<root<<' ';
        if(a==b){
            cout<<root*2-2<<'\n';
        }
        else if(root*root == s){
            cout<<root*2-3<<'\n';
        }
        else if(s <= root*(root+1)){
            cout<<root*2-2<<'\n';
        }
        else{
            cout<<root*2-1<<'\n';
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
// Union-Find with potential
//https://qiita.com/drken/items/cce6fc5c579051e64fab

struct Potential_UnionFind {
    vector<int> par;
    vector<long long> diff_weight;
    Potential_UnionFind(int n = 1, long long SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, long long SUM_UNITY = 0) {
        par.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = -1, diff_weight[i] = SUM_UNITY;
    }

    int root(int x){
        if (par[x] < 0) {
            return x;
        }else{
            //path compression
            int rt = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = root(par[x]);
        }
    }

    int size(int x){
        return -par[root(x)];
    }

    int weight(int x){
        root(x);
        return diff_weight[x];
    }

    int diff(int x,int y){
        return weight(y) - weight(x);
    }

    bool isConnect(int x,int y){
        return root(x) == root(y);
    }

    bool connect(int x , int y, long long w){
        //weight(y) - weight(x) = w
        //xとyの差を無理やりwにするために現状の親からのpotentialの差をキャンセルする．
        w += weight(x); w-= weight(y);
        x = root(x);
	    y = root(y);
	
        if(x==y) return false;
        
        //if rank[x] < rank[y]
        if(par[x] > par[y]){
            x ^= y;
            y ^= x;
            x ^= y;
            w = -w;
        }
        
        par[x] = par[x] + par[y]; // membersize++
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
};

Potential_UnionFind U(100002);

int main(){
    int n,q; SCD2(n,q);
    REP(i,q){
        int k; SCD(k);
        if (k == 0){
            int x,y,z;
            SCD3(x,y,z);
            U.connect(x,y,z);
        }else{
            int x,y;
            SCD2(x,y);
            if (U.isConnect(x,y)){
                PRINTD(U.diff(x,y));
            }else{
                printf("?\n");
            }
        }
    }
}





Measured memory_bytes: 3732
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;
using System.Text.RegularExpressions;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long Gcd(long x,long y)
        {
            if (x < y) Gcd(y, x);
            while (y > 0)
            {
                var z = x;
                x = y;
                y = z % y;
            }
            return x;
        }

        public static long Lcm(long x,long y)
        {
            return x * y / Lcm(x, y);
        }

        public static bool IsLowercaseAlphabet(char target)
        {
            return new Regex("^[a-z]+$").IsMatch(target.ToString());
        }

        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var q = Reads();
            var k = q[0];
            var a = q[1];
            var b = q[2];
            if (b - a >= 2)
            {
                if ((k - (a - 1)) % 2 == 0) WriteLine(a+(k-(a-1)) / 2 * (b - a));
                else WriteLine(a+(k - (a - 1)) / 2 * (b - a) + 1);
            }
            else
                WriteLine(1 + k);
            

            
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 18848
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

//absolute_mod
int abs_mod(int x){
    x%=mod;
    return (x<0?x+mod:x);
}

//power_mod
inline int Pow_mod(int x, int pow){
    if(pow==0) return 1;
    int a=Pow_mod(x, pow/2);
    a=a*a%mod;
    if(pow%2==1) a*=x;
    return a%mod;
}

//factorial_mod
int* fact_mod;
void init_fact_mod(int x){
    fact_mod = new int[x];
    fact_mod[0]=1;
    rep(i,x-1)fact_mod[i+1]=fact_mod[i]*(i+1)%mod;
}

//permutation_mod
int nPr_mod(int n, int r){
    return fact_mod[n]*Pow_mod(fact_mod[n-r]%mod, mod-2)%mod;
}

//combination_mod
int nCr_mod(int n, int r){
    if(n<r or n<0 or r<0)return 0;
    return fact_mod[n]*Pow_mod(fact_mod[n-r]*fact_mod[r]%mod, mod-2)%mod;
}

signed main(void){
    int n; cin>>n;
    vector<int> a(n+1); rep(i,n+1)cin>>a.at(i);
    vector<int> cnt(n); int num=-1;
    rep(i,n+1)if(cnt.at(a.at(i)-1)++==1)num=a.at(i);
    int x=-1, y=-1; bool b=false;
    rep(i,n+1){
        if(a.at(i)==num and b){y=n-i; break;}
        if(a.at(i)==num and !b){x=i; b=true;}
    }
    init_fact_mod(100010);
    for(int i=1; i<=n+1; i++){
        int ans=nCr_mod(n+1, i);
        int tmp=nCr_mod(x+y, i-1);
        cout<<abs_mod(ans-tmp)<<endl;
    }
}

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

int main()
{
    long long  n,a,m=1;
    cin>>n;
    while(n--)
    {
        cin>>a;
        m=((m)/__gcd(m,a)*a);
    }
    cout<<m<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl "\n"
#define rep(i , a , b) for (int i=a; i<(b); i++)
#define re0(i , a)     for (int i=0; i<(a); i++)
using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
typedef long double ld;

const int mod=7+1e9;
const int inf=1e9;
const int N=1e5+5;
ii a[N],b[N];
int main()
{
#ifndef ONLINE_JUDGE
   //freopen("input.in", "r", stdin);
#endif // ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    rep(i,1,n+1)
    {
        int x;
        cin>>x;
        if(i%2)a[x].F++,a[x].S=x;
        else b[x].F++,b[x].S=x;
    }
    sort(a,a+N,greater<ii>());
    sort(b,b+N,greater<ii>());
    if(a[0].S!=b[0].S)cout<<n-(a[0].F+b[0].F)<<endl;
    else
    {
        cout<<min((n-(a[0].F+b[1].F)),(n-(a[1].F+b[0].F)))<<endl;
    }
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	char n[3];
	for(int i=0; i<3; i++){
		cin >> n[i];
    }

  	if(n[0]==n[2]){
		cout << "Yes" << endl;
    }else{
		cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;



signed main() {
int N,K,min=10000000,mini,ans;
cin >> N >> K;
vector<int> A(N);
REP(i,N){
    cin >> A[i];
    if(min>A[i]){
        min = A[i];
        mini= i;
    }
}
int flag =0,ite=0,len;
len=N;
while(flag==0){
    if(A[ite]== min){
        len--;
        ite++;
    }
    else flag=1;
}
flag=0;
ite=N-1;
while(flag==0){
    if(A[ite]== min){
        len--;
        ite--;
    }
    else flag=1;
}
ans = (len-1+(K-2))/(K-1);

answer(ans);

return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    long long all = 0;
    for (int i = 0; i < n; i++) all += a[i];
    queue<int> candidate;
    for (int i = 1; i * i <= all; i++){
        if (all % i) continue;
        candidate.push(i);
        if (i * i != all) candidate.push(all / i);
    }
    int ans = 1;
    while (candidate.size()){
        int x = candidate.front();
        candidate.pop();
        vector<int> b(n);
        int tmp = 0;
        for (int i = 0; i < n; i++){
            b[i] = a[i] % x;
            tmp += b[i];
        }
        sort(b.begin(), b.end(), greater<int>());
        int cnt = tmp / x;
        for (int i = 0; i < cnt; i++) tmp -= b[i];
        if (0 <= tmp && tmp <= k) ans = max(ans, x);
    }
    cout << ans << endl;
}

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

int main() {
    int A,B,K;
    cin >> A >> B >> K;
    int N=min(A,B);
    int M=max(A,B);
    int ans;
    for(int i=1; i<N+1; i++){
        if(M%(N-i+1)==0 && N%(N-i+1)==0) K--;
        if(K==0){
            ans=N-i+1;
            break;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int a2,b2;
	int aa;
	
    while(scanf("%d %d",&a,&b) == 2){
        a2 = a;
        b2 = b;
        while(1){
            c = a % b;
            if(c == 0){
                break;
            }
            a = b;
            b = c;
        }
        aa = a2 / b * b2;

		printf("%d %d\n",b, aa);
    }

	return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(X)<<Y<<endl
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int N;
	cin>>N;
	if(N%2==0){
		cout<<N/2-1<<endl;
	}
	else{
		cout<<N/2<<endl;
	}
	return 0;
}


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

int main()
{
    int N = 0;
    cin >> N;
    vector<int> arr(N);
    for (int i = 0; i < N; i++)
    {
        cin >> arr.at(i);
    }
    for (int i = 0; i < N; i++)
    {
      	if (i == N - 1)
        {
          cout << arr.at(N - 1 - i);
          break;
        }
        cout << arr.at(N - 1 - i);
        cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000000
#define MOD 1000000007
#define ll long long
using namespace std;
int n,m;
string s;
ll ac[3001];
int l[3000],r[3000];
vector<ll> dp(1000,0),_dp(1000,0),dc(1000,0);
void accum(){
    ac[0]=0;
    rep(i,n){
        ac[i+1]=ac[i]+(s[i]-'0');
    }
}
int pow(ll x){
    return x*x%MOD;
}
int modpow(ll x,ll y){
    if (y==0){
        return 1;
    }else if (y==1){
        return x%MOD;
    }else if (y%2==0){
        return pow(modpow(x,y/2));
    }else{
        return pow(modpow(x,y/2))*x%MOD;
    }
}
int inv(ll x){
    return modpow(x,MOD-2);
}
int nck(ll x,ll y){
    if (y<0 || y>x) return 0;
    y=min(y,x-y);
    ll ret=1;
    rep(i,y){
        ret=ret*(x-i)%MOD;
        ret=ret*inv(i+1)%MOD;
    }
    return ret;
}
int main(){
    cin>>n>>m;
    cin>>s;
    accum();
    int cnt=0;
    rep(i,m){
        int le,rr;
        cin>>le>>rr;
        le-=1;rr-=1;
        if (cnt==0){
            l[cnt]=le;r[cnt]=rr;
            cnt+=1;
        }else if (rr>r[cnt-1]){
            l[cnt]=le;r[cnt]=rr;
            cnt+=1;
        }
    }
    m=cnt;
    l[m]=INF,r[m]=INF;
    int its;
    dp[0]=1;
    rep(i,m){
        int pits=its;
        int x=ac[r[i]+1]-ac[l[i]+pits];
        its=max(0,r[i]-l[i+1]+1);
        _dp=dc;
        rep(j,pits+1){
            rep(k,its+1){
                _dp[k]=(_dp[k]+dp[j]*nck(r[i]-l[i]+1-its,x+j-k))%MOD;
            }
        }
        dp=_dp;
    }
    cout<<dp[0]%MOD<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a;
    cin>>a;
    if(a==22)
        cout<<"Christmas Eve Eve Eve"<<endl;
    else if(a==23)
        cout<<"Christmas Eve Eve"<<endl;
    else if(a==24)
        cout<<"Christmas Eve"<<endl;
    else if(a==25)
        cout<<"Christmas"<<endl;


    return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int D, G;
  cin >> D >> G;

  vector<int> p(D), c(D);
  rep(i, D) cin >> p[i] >> c[i];

  int ans = INF;
  rep(i, 1 << D) {
    vector<int> comp;
    vector<int> not_comp;

    rep(j, D) {
      if (i >> j & 1) {
        comp.pb(j + 1);
      } else {
        not_comp.pb(j + 1);
      }
    }

    int score = 0;
    int solve = 0;

    rep(j, comp.size()) {
      int id = comp[j];
      score += 100 * id * p[id - 1] + c[id - 1];
      solve += p[id - 1];
    }

    vector<int> not_comp_score;
    repr(j, not_comp.size() - 1, 0) {
      int id = not_comp[j];
      rep(k, p[id - 1] - 1) { not_comp_score.pb(100 * id); }
    }

    rep(j, not_comp_score.size()) {
      if (score >= G) {
        chmin(ans, solve);
        break;
      } else {
        score += not_comp_score[j];
        solve++;
      }
    }
    if (score >= G) {
      chmin(ans, solve);
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  string P;
  cin >> P;
  for(int i = 0; i < (int)P.size(); i++) {
    if(P[i] == '?') P[i] = -1;
    else P[i] -= '0';
  }
  int idx = -1;
  for(int i = 0; i < 10; i++) {
    string p = P;
    for(int j = 0; j < (int)P.size(); j++) {
      if(P[j] == -1) P[j] = i;
    }
    int chk = 0;
    for(int j = 0; j < 11; j++) {
      int n = 11-j;
      chk += P[j]*(n < 7 ? n+1 : n-5);
    }
    chk %= 11;
    if(chk <= 1) chk = 0;
    else chk = 11-chk;
    if(chk == P[11]) {
      if(idx == -1) idx = i;
      else {
	cout << "MULTIPLE" << endl;
	return 0;
      }
    }
    P = p;
  }
  assert(idx != -1);
  cout << idx << endl;
  return 0;
}

Measured memory_bytes: 3216
function main()
    N = parse(Int, readline())
    d = zeros(Int, (N,))
    for i = 1:N 
        d[i] = parse(Int, readline())
    end

    num = zeros(Int, (100,))
    for i = 1:N 
        num[d[i]] += 1
    end

    res = 0
    for i = 1:100
        if num[i] > 0
            res += 1
        end
    end

    println(res)
end

main()

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

using namespace std;
typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef map<ll,ll> mpll;
typedef set<ll> setll;
typedef multiset<ll> msetll;

#define F first
#define S second
#define pb push_back
#define mp make_pair

const ll mod = 1e9 + 7;

ll d,n;
vector<ll> v;
ll memo[10001][101][2];

ll func(ll i,int rem,int tt){
	if(i==n-1){
		ll temp = v[i];
		if(tt==1)
			temp=9;
		ll cnt =0;
		while(temp>=0)
		{
			if((temp+rem) % d == 0)
				cnt++;
			temp--;
		}
		return cnt;
	}
	if(memo[i][rem][tt]!=-1)
		return memo[i][rem][tt];
	ll temp = v[i];
	if(tt==1)
		temp=9;
	ll cnt = 0;
	if(tt==1)
	{
	while(temp>=0)
	{
		
		cnt+=func(i+1,(temp+rem)%d,tt);
		//cout<<temp<<" "<<cnt<<"\n";
		cnt = cnt%mod;
		temp--;
	}
	}
	else{
		cnt+=func(i+1,(temp+rem)%d,0);
		//cout<<temp<<" "<<cnt<<"\n";
		cnt = cnt%mod;
		temp--;
		while(temp>=0)
		{
		
			cnt+=func(i+1,(temp+rem)%d,1);
			//cout<<temp<<" "<<cnt<<"\n";
			cnt = cnt%mod;
			temp--;
		}
	}
	return memo[i][rem][tt]=cnt;
}

int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifdef DEBUG_
		freopen("input.txt","r",stdin);
	#endif
	cout.setf(ios::fixed), cout.precision(20);

	string k;
	cin >> k ;
	cin >> d ;

	for(int i=0;i<(int)k.size();i++){
		v.push_back((int)(k[i]-'0'));
	}
	n = k.size();
	for(int i=0;i<10001;i++){
		for(int j=0;j<101;j++){
			memo[i][j][0]=-1;
			memo[i][j][1]=-1;
		}
	}
	cout<<(func(0,0,0)- 1 + mod)%mod<<"\n";

	return 0;
}

Measured memory_bytes: 17024
#include <stdio.h>

int main(void){
  int i, sx, sy, tx, ty, x, y;
  scanf("%d %d %d %d", &sx, &sy, &tx, &ty);
  x = tx - sx;
  y = ty - sy;
  if(x < 0) x = -x;
  if(y < 0) y = -y;
  for(i=0; i<y; i++){
    printf("U");
  }
  for(i=0; i<x; i++){
    printf("R");
  }
  for(i=0; i<y; i++){
    printf("D");
  }
  for(i=0; i<x; i++){
    printf("L");
  }
  printf("L");
  for(i=0; i<y+1; i++){
    printf("U");
  }
  for(i=0; i<x+1; i++){
    printf("R");
  }
  printf("DR");
  for(i=0; i<y+1; i++){
    printf("D");
  }
  for(i=0; i<x+1; i++){
    printf("L");
  }
  printf("U");
  return 0;
}

Measured memory_bytes: 128
''' Hey stalker :) '''
INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    n, k, s = get_list()
    junk = 10**9 if s!=10**9 else 10**9 - 1
    res = [s]*k + [junk]*(n-k)
    print(" ".join(map(str, res)))


''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


Measured memory_bytes: 65868
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



int main() {
	int N, Q;
	cin >> N >> Q;
	vector<tuple<ll, ll, ll>>li(N);
	rep(i, 0, N)cin >> get<1>(li[i]) >> get<2>(li[i]) >> get<0>(li[i]);
	sort(all(li));

	vector<ll>ans(Q,-1);
	vector<ll>D(Q);
	set<ll>st;
	rep(i, 0, Q) {
		ll d;
		cin >> d;
		st.insert(d);
		D[i] = d;
	}

	rep(i, 0, N) {
		auto t = li[i];
		ll X = get<0>(t);
		ll S = get<1>(t);
		ll T = get<2>(t);
		vector<ll>temp;
		auto it = st.lower_bound(S-X);
		while (it != st.end() && *it < T - X) {
			auto it2 = it;
			++it2;
			temp.pb(*it);
			st.erase(it);
			it = it2;
		}
		rep(i, 0, temp.size()) {
			int ind = lower_bound(all(D),temp[i])-D.begin();
			ans[ind] = X;
		}
	}

	rep(i, 0, Q) {
		cout << ans[i] << endl;
	}


	
	return 0;
}


Measured memory_bytes: 19072
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;

int main()
{
  int N;
  cin >> N;
  int A[N];
  rep(i, N) cin >> A[i];

  int idx = 1;
  int cnt = 0;
  rep(i, N) {
    if (idx == A[i]) idx++;
    else cnt++;
  }
  if (idx == 1) cout << -1 << endl;
  else cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
  switch = {i:0 for i in range(1, N+1)}
  for j in range(N):
    if (i>>j)&1:
      switch[j+1] += 1    
  flag = True
  for i in range(M):
    k = ks[i][0]
    s = ks[i][1:]
    pp = p[i]
    cnt = 0
    for ss in s:
      if switch[ss] == 1:
        cnt += 1
    if cnt % 2 != pp:
      flag = False

  if flag:
    ans += 1

print(ans)



Measured memory_bytes: 3064