akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
import javax.xml.crypto.Data;
 
import java.math.*;
 
public class Main {
     
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[] {1,5,10,50,100,500};
        int sum = 0;
        for(int i = 0; i < a.length; i++) {
            sum += sc.nextInt() * a[i];
        }
        System.out.println((sum >= 1000)?"1":"0");
         
    }
     
}

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

int main() {
    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; ++i) cin >> d[i];

    int c[101] = {0};
    for (int i = 0; i < N; ++i) ++c[d[i]];
    int ans = 0;
    for (int i = 1; i <= 100; ++i) {
        if (c[i] != 0) ++ans;
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

/*

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}

int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}

int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	return B;
}

vector<ll> prime_factor(int64_t n) {
	//map< ll, ll > ret;
	vector<ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			//ret[i]++;
			ret.push_back(i);
			n /= i;
		}
	}
	if (n != 1)ret.push_back(n);// ret[n] = 1;
	return ret;
}

const int MAX = 1000000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct edge {
	ll to;
	ll cost;
};

*/

ll fact(ll x) {
	ll ans = 1;
	for (ll i = 1; i <= x; i++) {
		ans *= i;
		ans %= 1000000000 + 7;
	}
	return ans;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	


	ll N;
	cin >> N;
	cout << fact(N) << endl;


ProgramEndPointLabel:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG


	return 0;
}




Measured memory_bytes: 504
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

template <class T>
inline void relax(T &a, const T &b)
{
	if (b > a)
		a = b;
}

const int MaxN = 15;
const int INF = 0x3f3f3f3f;

int n, m;
int mat[MaxN][MaxN];

int sum[1 << MaxN];

int result = -INF;

int f[1 << MaxN][MaxN];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int u, v, w;
		cin >> u >> v >> w, --u, --v;

		mat[u][v] = w;
		mat[v][u] = w;
	}

	int all = 1 << n;
	for (int s = 1; s < all; ++s)
	{
		int u = __builtin_ctz(s);

		sum[s] = sum[s ^ (s & -s)];
		for (int v = u + 1; v < n; ++v)
			if (s >> v & 1)
				sum[s] += mat[u][v];
	}

	for (int s = 0; s < all; ++s)
		for (int u = 0; u < n; ++u)
			f[s][u] = -INF;
	f[1][0] = 0;

	for (int s = 1; s < all; ++s)
	{
		for (int u = 0; u < n; ++u)
		{
			if (f[s][u] < 0)
				continue;

			int ex = (all - 1) ^ s;
			for (int t = ex; t; --t &= ex)
				relax(f[s | t][u], f[s][u] + sum[t | 1 << u]);

			for (int v = 0; v < n; ++v)
				if (mat[u][v] && ~s >> v & 1)
					relax(f[s | 1 << v][v], f[s][u] + mat[u][v]);
		}

		relax(result, f[s][n - 1]);
	}

	cout << sum[all - 1] - result << endl;

	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll k;
    ll n;
    cin >> k >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }

    vector<ll> bd(n);
    bd[0] = k - a[n - 1] + a[0];
    FOR(i,1,n){
        bd[i] = a[i] - a[i - 1];
    }

    ll max_idx = max_element(all(bd)) - bd.begin();
    cout << k - bd[max_idx] << endl;

    return 0;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 

vector<ll> fact;

void init(ll N){
  fact.resize(N+1);
  fact[0]=1;
  rep(i,N)  fact[i+1]=((i+1)*fact[i])%lmod;
}

ll ppow(ll a,ll b){
  // aのb乗を求める
  ll res = 1;
  while(b){
    if(b%2) res=(res*a)%lmod;
    a=(a*a)%lmod;
    b>>=1;
  }
  return res;
}

ll imod(ll n){
  // nのmodの逆元を求める
  ll P=lmod;
  return ppow(n,P-2);
}

ll comb_mod(ll n,ll k){
  return (fact[n] * imod(fact[k]) % lmod) * imod(fact[n-k]) % lmod ;
  //nCk % mod を返す
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,A,B,C,D; cin >> N >> A >> B >> C >> D;
  init(N+1);
  int s = B - A + 1;
  vvl dp(s+1,vl(N+1));
  dp[0][0] = 1LL;
  rep(i,s){
    rep(j,N+1){
      (dp[i+1][j] += dp[i][j]) %= lmod;
      if(dp[i][j]==0LL) continue;
      REP(k,C,D+1){
        int t = i + A;
        // t人グループをk個作る
        if(j+k*t>N) break;
        dp[i+1][j+k*t] += dp[i][j] * fact[k*t] % lmod *
                           imod(ppow(fact[t],k)*fact[k]%lmod*fact[N-j-k*t]%lmod*fact[k*t]%lmod) % lmod 
                           * fact[N-j] % lmod;
        dp[i+1][j+k*t] %= lmod;
      }
    }
    dump(i+1,dp[i+1]);
  }
  cout << dp[s][N] << endl;
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a, b, cnta=0, cntb=0;
    string s;
    cin >> n >> a >> b >> s;
    REP(i,n){
        if(s[i]=='a'){
            if(cnta+cntb<a+b){
                cout << "Yes" << endl;
                cnta++;
            }
            else cout << "No" << endl;
        }
        else if(s[i]=='b'){
            if(cntb+cnta<a+b && cntb<b){
                cout << "Yes" << endl;
                cntb++;
            }
            else cout << "No" << endl;
        }
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 896
import sys
n, y = map(int, input().split())
for a in range(n+1):
    for b in range(n+1-a):
        if 10000 * a + 5000 * b + 1000 * (n - a - b) == y:
            ans = [a, b, n - a - b]
            print(*ans, sep=" ")
            sys.exit()
    
print("-1 -1 -1")

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

int main(void) {
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  vector<long long> dp(100 * 1000 + 1, 1e18);
  dp[0] = 0;
  long long ret = 0;
  for (int i = 0; i < N; i++) {
    for (int vl = 100 * 1000; vl >= 0; vl--) {
      if (dp[vl] + w[i] > W) continue;
      dp[vl + v[i]] = min(dp[vl + v[i]], dp[vl] + w[i]);
      ret = max((long long)(vl + v[i]), ret);
    }
  }
  cout << ret << endl;
  return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;

  if (n >= k)
    n = n % k;

  while (true) {
    ll tmp = n;
    if (abs(n-k) < n)
      n = abs(n - k);
    if (tmp == n)
      break;
  }

  cout << n << endl;

  return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

// Binary Indexed Tree (1 indexed)
struct BIT {
  vector<int> data;
  BIT(){}
  void init(int n) {
    data.resize(n+1, 0);
  }
  int sum(int k) {
    int ret = 0;
    while(k > 0) {
      ret += data[k];
      k -= k & -k;
    }
    return ret;
  }
  void add(int k, int x) {
    while(k < (int)data.size()) {
      data[k] += x;
      k += k & -k;
    }
  }
};

int n;
vint w, b;
BIT bit;
int dp[2002][2002];

int solve(int i, int j) {
  if(i == n && j == n) return 0;
  int& res = dp[i][j];
  if(~res) return res;
  res = inf;
  if(i < n) {
    bit.add(w[i]+1, -1);
    chmin(res, solve(i+1, j)+bit.sum(w[i]+1));
    bit.add(w[i]+1, 1);
  }
  if(j < n) {
    bit.add(b[j]+1, -1);
    chmin(res, solve(i, j+1)+bit.sum(b[j]+1));
    bit.add(b[j]+1, 1);
  }
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> n;
  resz(w, n);
  resz(b, n);
  rep(i, n*2) {
    char c;
    int a;
    cin >> c >> a;
    --a;
    if(c == 'W') w[a] = i;
    else b[a] = i;
  }
  bit.init(n*2);
  rep(i, n*2) bit.add(i+1, 1);
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0) << endl;

  return 0;
}


Measured memory_bytes: 31744
from functools import reduce
import math
import fractions
N = int(input())
T_list = [ int(input()) for i in range(N)  ]
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print (lcm_list(T_list) )

Measured memory_bytes: 5512
import java.util.*;
    class Main
    {
      public static void main(String args[])
      {
        Scanner sc=new Scanner (System.in);
        int a,b,c,t;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        t=a;
        a=b;
        b=t;
        t=a;
        a=c;
        c=t;
        System.out.println(a+" "+b+" "+c);
      }
    }


Measured memory_bytes: 22484
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func printIntArray(array []int) {
	for i := 0; i < len(array); i++ {
		if i == 0 {
			fmt.Printf(strconv.Itoa(array[i]))
		} else {
			fmt.Printf(" " + strconv.Itoa(array[i]))
		}
	}
	fmt.Println()
}

func insertionSort(array []int) {
	printIntArray(array)
	for i := 1; i < len(array); i++ {
		key := array[i]
		j := i - 1
		for j >= 0 && array[j] > key {
			array[j+1] = array[j]
			j--
		}
		array[j+1] = key
		printIntArray(array)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	var array []int

	for i := 0; i < n; i++ {
		array = append(array, nextInt())
	}
	insertionSort(array)

}



Measured memory_bytes: 1128
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 3540
#include <stdio.h>

int main(void)
{
	int A,B,C;
	
	scanf("%d %d %d",&A,&B,&C);
	
	if(A==5 && B==5 && C==7){
		printf("YES\n");
	}else{
		if(A==5 && B==7 && C==5){
			printf("YES\n");
		}else{
			if(A==7 && B==5 && C==5){
				printf("YES\n");
			}else{
				printf("NO\n");
			}
		}
	}
	
		
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

// https://drken1215.hatenablog.com/entry/2020/04/05/150900
// こちらを参考にした

func main() {
	var K int
	lunlun := make([]int, 0)
	cur := make([]int, 0)
	fmt.Scan(&K)
	for i := 1; i <= 9; i++ {
		lunlun = append(lunlun, i)
		cur = append(cur, i)
	}
	for i := 1; i < 10; i++ {
		cur = calc_next(cur)
		lunlun = append(lunlun, cur...)
	}
	fmt.Println(lunlun[K-1])
}

func calc_next(cur []int) []int {
	res := make([]int, 0)
	for _, v := range cur {
		for i := -1; i <= 1; i++ {
			add := v%10 + i
			if add >= 0 && add <= 9 {
				res = append(res, v*10+add)
			}
		}
	}
	return res
}


Measured memory_bytes: 8460
#!/usr/bin/env python3
import sys


def solve(N: int, A: int):
    print(N * N - A)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt = 0
    for x in a:
        if (x >> i) & 1:
            cnt += 1
    ans += cnt * (n - cnt) * (1 << i)
print(ans % MOD)


Measured memory_bytes: 122936
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
    std::ios::sync_with_stdio(false);
     int n,m,mas;
  cin>>s;

  int len=s.size();
  s[len]='A';
  int sum=1;
  int ans=0;
  for(int i=1;i<=len;i++)
  {
      if(s[i]==s[i-1])
         sum++;
      else
      {
          if(s[i]=='A')
          {
                  int temp=sum/3;
                  int mod=sum%3;
                  ans+=temp*2;
                  if(mod!=0)
                    ans++;
                    continue;

          }
        if(sum==1)
            ans++;
           else
           {
               int temp=sum/3;
               int mod=sum%3;
               ans+=temp*2;
               if(mod!=0)
               {
                   ans++;
               }
               if(mod==2)
               {
                   ans++;
                   i++;
               }
           }
           sum=1;
      }
     // cout<<ans<<endl;

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


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

int main() {
  int N, a = -1, ans;
  cin >> N;
  vector<int> value(N), cost(N), dif(N);
  for (int i = 0; i < N; i++) cin >> value.at(i);
  for (int i = 0; i < N; i++) cin >> cost.at(i);
  for (int i = 0; i < N; i++) dif.at(i) = value.at(i) - cost.at(i);
  sort(dif.begin(), dif.end());
  reverse(dif.begin(), dif.end());
  for (int i = 0; i < N; i++) {
    if (dif.at(i) < 0) {
      a = i;
      break;
    }
  }
  if (a == 0) cout << 0 << endl;
  else {
    if (a < 0) a = N;
    for (int i = 0; i < a; i++) ans += dif.at(i);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int N; // # of sticks
int L[100]; // L[i]: the length of the (i + 1)-th stick

bool f(int a, int b, int c) {
    if (a == b || b == c || c == a) {
        return false;
    }

    if (
            a + b > c &&
            b + c > a &&
            c + a > b) {
        return true;
    }

    return false;
}

int main() {

    std::cin >> N;

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

    int count = 0;

    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            for (int k = j+1; k < N; ++k) {

                if (f(L[i], L[j], L[k])) {
                    std::cerr << L[i] << ", " << L[j] << ", " << L[k] << std::endl;
                    count++;
                }
            }
        }
    }

    std::cout << count << std::endl;

    return 0;

}


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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int x,y;
  cin>>x>>y;

  cout<<x+y/2<<endl;




return 0;}


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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
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;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

string S;

int main(){
    cin >> S;
    FOR(i,1,S.length()+1)
    {
        if(i%2==0)
        {
            if(S[i-1]=='R'){
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            if(S[i-1]=='L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
// 2019/07/02 Tazoe

#include <iostream>
using namespace std;

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

	int X[102];
	for(int i=1; i<=N; i++){
		cin >> X[i];
	}
	X[N+1] = 2020;

	int M;
	cin >> M;

	for(int j=0; j<M; j++){
		int A;
		cin >> A;

		if(X[A]==2019 || X[A+1]==X[A]+1)
			continue;

		X[A]++;
	}

	for(int i=1; i<=N; i++){
		cout << X[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

const int M   = 1000000007;
const int MOD = 1000000007;

int exp_mod(long long a, long long b, int m) {
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % m;
		a = (a * a) % m;
		b >>= 1;
	}
	return (int)res;
}

int fact_mod(int n, int m) {
	long long res = 1;
	for (int i = n; i > 0; --i)
		res = (res * i) % m;
	return (int)res;
}

int comb_mod(int n, int r) {
	long long res = 1;
	for (int i = 0; i < r; ++i)
		res = (res * (n - i)) % MOD;
	return (res * exp_mod(fact_mod(r, MOD), MOD - 2, MOD)) % MOD;
}


int main(){
	int n, m;
	cin >> n >> m;
	int mm = 100000;
	vector<int> table(mm, 0);

	vector<pair<int,int>> primes;
	int md = m;
	for (int i = 2; i < sqrt(m + 1); ++i) {
		if (table[i] == 0) {
			int j = i*2;
			while (j < sqrt(m+1)) {
				table[j] = 1;
				j += i;
			}

			int cnt = 0;
			while (md%i==0) {
				md /= i;
				cnt++;
			}
			if (cnt > 0) {
				primes.push_back(make_pair(i, cnt));
			}
		}
	}
	if (md != 1) {
		primes.push_back(make_pair(md, 1));
	}

	int64_t ans = 1;
	for (auto p : primes) {
		int c1 = p.second+n-1;
		int c2 = p.second;
		int val = comb_mod(c1, c2);
		ans = (ans * val) % MOD;
	}
	cout << ans%MOD << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;

int main() {
 	 vector<int>x(5);
  for(int i=0;i<5;i++){
    cin>>x[i];
    if(x[i]==0){cout<<i+1<<endl;return 0;}
  }
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    char c;
    cin >> c;
    if (c == 'o') {
      cnt++;
    }
  }
  
  cout << 700 + 100 * cnt << '\n';
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = Long.parseLong(sc.next());
		List<Long> list = new ArrayList();
		Map<Long,Long> map = new HashMap();
		Map<Long,Long> map2 = new HashMap();
		Map<Long,Long> map3 = new HashMap();
		for(long i=0;i<N;i++){
			long a = Long.parseLong(sc.next());
			if(map.containsKey(a)){
				map.put(a, map.get(a)+1);
			} else {
				map.put(a,  1l);
			}
			list.add(a);
		}
		for(Entry<Long, Long> a:map.entrySet()){
			map2.put(a.getKey(), keisan(a.getValue()));
			map3.put(a.getKey(), keisan(a.getValue()-1));
		}
		long total = 0;
		for(Long a: map2.values()){
			total += a;
		}
//		System.out.println(map);
//		System.out.println(map2);
//		System.out.println(map3);
		for(Long a:list){
			System.out.println(total-map2.get(a)+map3.get(a));
		}
	}
	public static long keisan(long a){
		long aa = 1;
		for(long i=a ; i>a-2 ; i--){
			aa *= i;
		}
		return aa/2;
	}
}


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

int main() {
	int n, k; cin >> n >> k;
    long long res = 0;
    for (int i = 1; i <= n; i++)
    {
        int a, b, c;
        a = i % k;
        b = c = k - a;
        if((b + c) % k == 0) {
            long long tmp = (n + k - b) / k;
            res += tmp * tmp;
        }
    }
    cout << res << endl;
	return 0;
}


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

int main(void){
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(b-a>k || c-a>k || d-a>k || e-a>k || c-b>k || d-b>k || e-b>k || d-c>k || e-c>k || e-d>k){
    cout << ":(" << endl;
  } else{
    cout << "Yay!" << endl;
  }
  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int K;
int A[100001];

int main() {
    int K;
    cin >> K;
    rep(i, K) cin >> A[i];
    reverse(A, A+K);
    if (A[0] >= 3) {
        cout << -1 << endl;
        return 0;
    }
    ll mi = 2, ma = max(2, A[0]*2-1);
    for (int i = 1; i < K; ++i) {
        if (ma < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        ll tmp = ma / A[i];
        ll tmp2 = tmp * A[i] + A[i]-1;
        if (mi <= A[i]) mi = A[i];
        else {
            ll tmp = (mi / A[i]) + bool(mi%A[i]);
            ll tmp2 = tmp * A[i];
            if (tmp*A[i] > ma) {
                cout << -1 << endl;
                return 0;
            }
            mi = tmp*A[i];
        }
        ma = tmp2;
    }
    cout << mi << ' ' << ma << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)
        cout<<(n-2)*(b-a)+1<<endl;
         else
        cout<<0<<endl; 
 } 

Measured memory_bytes: 256
import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')


Measured memory_bytes: 27964
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <tgmath.h>
#include <time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
#define nyan(i) for (int i = 1; i <= n; i++)
ll n, sum = 0;

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

main()
{
    scanf("%lld", &n);
    nyan(i)
    {
        nyan(j)
        {
            nyan(k)
            {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <map>


using namespace std;

using ull = unsigned long long int;
using pp = pair<ull, ull>;

int MAXN = 1e9 + 7; 
vector<pp> dp(1e5+1);


pp dfs(const vector<vector<int>>& G, int v, int p=0) {
    dp[v].first = 1;
    dp[v].second = 1;

    for (auto &&u : G[v])
    {
        if (u!=p) {
            auto u_info = dfs(G,u,v);
            dp[v].first *= (u_info.first + u_info.second) % MAXN;
            dp[v].second *= (u_info.first % MAXN);

            dp[v].first %= MAXN;
            dp[v].second %= MAXN;
        } 
    }

    return dp[v];
}


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

    int N;
    cin>>N;
    vector<vector<int>> G;
    G.resize(N+1);
    int x,y;
    for (size_t i = 0; i < N-1; i++)
    {
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    auto pp = dfs(G,1,0);
    cout << (pp.first + pp.second) % MAXN << "\n";
    
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, M, t; cin >> N >> M;
int A[N];
unsigned long long ans=0;
priority_queue<int> Item;
for(int i=0; i<N; i++){ cin >> A[i]; Item.push(A[i]); }
for(int i=0; i<M; i++){ t=Item.top(); Item.pop(); t=t/2; Item.push(t);  }
for(int i=0; i<N; i++){ t=Item.top(); Item.pop(); ans+=t; }
cout << ans << "\n";
}

Measured memory_bytes: 1148
def solve():
    text = input()
    longest, length = '', 0
    dic = {}
    for word in text.split():
        if word in dic.keys():
            dic[word] += 1
        else:
            dic[word] = 1
        
        if length < len(word):
            longest = word
            length = len(word)
    
    target, cnt = '', 0
    for k, v in dic.items():
        if v > cnt:
            target = k
            cnt = v
    print(target, longest)

if __name__ == "__main__":
    solve()



Measured memory_bytes: 5560
N = int(input())
S = [list(input()) for i in range(N)]
M = []
A = []
R = []
C = []
H = []
for j in range(N):
  if (S[j][0] == 'M'):
    M.append(S[j])
  elif (S[j][0] == 'A'):
    A.append(S[j])
  elif (S[j][0] == 'R'):
    R.append(S[j])
  elif (S[j][0] == 'C'):
    C.append(S[j])
  elif (S[j][0] == 'H'):
    H.append(S[j])
  else:
    None
print(len(M)*len(A)*len(R)+len(M)*len(A)*len(C)+len(M)*len(A)*len(H)+len(M)*len(R)*len(C)+len(M)*len(R)*len(H)+len(M)*len(C)*len(H)+len(A)*len(R)*len(C)+len(A)*len(R)*len(H)+len(R)*len(C)*len(H)+len(A)*len(C)*len(H))


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(n*a,b) << endl;
	return 0;
}


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

using namespace std;

int main() {
  vector<int> a;
  int val;
  cin >> val;
  a.push_back(val);
  cin >> val;
  a.push_back(val);
  cin >> val;
  a.push_back(val);
  sort(a.begin(), a.end());
  //cout << a[0] << endl;
  //cout << a[1] << endl;
  //cout << a[2] << endl;
  int cost = 0;
  cost += abs(a[1] - a[0]);
  cost += abs(a[2] - a[1]);
  cout << cost << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int S= 50;
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    int T=0;
  	while (true){
    	if( A%2 == 0 ){
          T++;
          A /= 2;
        }
    	else{
          break;
        }
    }
    if( S > T){
      S = T;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int K, A, B;
	scanf("%d %d %d", &K, &A, &B);
	if (A % K != 0 && A / K == B / K) printf("NG");
	else printf("OK");
	return 0;
}

Measured memory_bytes: 1732
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



n,p = list(map(int, input().split()))
s = input()
nums = []
numsinv = []

for i in range(n):
    nums.append(int(s[i]))
    numsinv.append(int(s[n-1-i]))
    
if(p==2):
    ans = 0
    for i in range(n):
        ans += (numsinv[i]+1)%2 * (n-i)
    print(ans)
    exit()
if(p==5):
    ans=0
    for i in range(n):
        if(numsinv[i]%5==0):
            ans += (n-i)
    print(ans)
    exit()


pows = [0 for i in range(n)]


pows[0] = 1

for i in range(n-1):
    pows[i+1] = (pows[i] * 10)%p

rights = [0]
now = 0
for i in range(n):
    rights.append((rights[-1] + numsinv[i] * pows[i])%p)

lefts = [0]
for i in range(n):
    lefts.append((lefts[-1] + nums[i] * pows[n-1-i])%p)

#print(lefts,rights)

total = lefts[-1]

timesL = [0 for i in range(p)]
timesR = [0 for i in range(p)]

for i in range(n+1):
    timesL[lefts[i]] += 1
    timesR[rights[i]] += 1
    
ans = 0

for i in range(p):
    ans += timesL[i] * timesR[(total-i+p)%p]
#print(timesL,timesR)
print((ans - (n+1))//2)

















Measured memory_bytes: 99084
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,m,i,j;
	cin>>n>>m;
	int syu[m]={0};
	for(i=0;i<n;i++){
		int num,tmp;
		cin>>num;
		for(j=0;j<num;j++){
			cin>>tmp;
			syu[--tmp]++;
		}
	}
	int ans=0;
	for(i=0;i<m;i++)if(syu[i]==n)ans++;
	cout<<ans<<endl;
	
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const ll infl = 1e17;

int main()
{
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();
    vll ss(n + 1, 0);
    vll ts(m + 1, 0);
    rep(i,n){
        if (s[i]=='A'){
            ss[i + 1] = (ss[i] + 1)%3;
        }
        else {
            ss[i + 1] = (ss[i] + 2) % 3;
        }
    }
    rep(i, m)
    {
        if (t[i] == 'A')
        {
            ts[i + 1] = (ts[i] + 1) % 3;
        }
        else
        {
            ts[i + 1] = (ts[i] + 2) % 3;
        }
    }
    ll q;
    cin >> q;
    ll a, b, c, d;
    rep(i,q){
        cin >> a >> b >> c >> d;
        ll si = (3 + ss[b] - ss[a - 1]) % 3;
        ll ti = (3 + ts[d] - ts[c - 1]) % 3;
        if (si==ti)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


Measured memory_bytes: 2432
/* Dynamic Programming implementation of LCS problem */
#include<bits/stdc++.h> 

using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
    that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
    for (int j=0; j<=n; j++) 
    { 
    if (i == 0 || j == 0) 
        L[i][j] = 0; 
    else if (X[i-1] == Y[j-1]) 
        L[i][j] = L[i-1][j-1] + 1; 
    else
        L[i][j] = max(L[i-1][j], L[i][j-1]); 
    } 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
    // If current character in X[] and Y are same, then 
    // current character is part of LCS 
    if (X[i-1] == Y[j-1]) 
    { 
        lcs[index-1] = X[i-1]; // Put current character in result 
        i--; j--; index--;     // reduce values of i, j and index 
    } 

    // If not same, then find the larger of two and 
    // go in the direction of larger value 
    else if (L[i-1][j] > L[i][j-1]) 
        i--; 
    else
        j--; 
} 

// Print the lcs
if(strlen(lcs)) 
cout  << lcs; 
else 
 cout<<" ";

} 

/* Driver program to test above function */
int main() 
{ 
string s,t;
cin>>s>>t;
int m = s.length(); 
int n = t.length(); 
lcs(s, t, m, n); 
return 0; 
} 


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

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

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	long long K;
	scanf("%lld",&K);

	if (K < 10)
	{
		cout << K << endl;
		return EXIT_SUCCESS;
	}
	K += 1;

	unordered_set<ll> s;
	vector<vector<vector<string>>> table;
	table.push_back(vector<vector<string>>(10));
	for (ll i = 0; i < 10; ++i)
	{
		table[0][i] = { to_string(i) };
		s.insert(i);
	}

	ll i = 1;
	while (true)
	{
		table.push_back(vector<vector<string>>(10));
		for (ll j = 0; j < 10; ++j)
		{
			const auto s_j = to_string(j);
			if (j != 0)
			{
				for (ll k = 0; k < table[i - 1][j - 1].size(); ++k)
				{
					table[i][j].push_back(s_j + table[i - 1][j - 1][k]);
				}
			}
			for (ll k = 0; k < table[i - 1][j].size(); ++k)
			{
				table[i][j].push_back(s_j + table[i - 1][j][k]);
			}
			if (j != 9)
			{
				for (ll k = 0; k < table[i - 1][j + 1].size(); ++k)
				{
					table[i][j].push_back(s_j + table[i - 1][j + 1][k]);
				}
			}
			for (ll k = 0; k < table[i][j].size(); ++k)
			{
				auto tmp = stoll(table[i][j][k]);
				if (s.insert(tmp).second) {
					// cerr << table[i][j][k] << " -> " << tmp << endl;
				}
				if (s.size() == K)
				{
					cout << tmp << endl;
					return EXIT_SUCCESS;
				}
			}
		}
		++i;
	}

	return 0;
}


Measured memory_bytes: 11172
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	
	int N;
	vector<int> arr;
	cin>>N;
	arr.resize(N);

	REP(i,N)cin>>arr[i];

	int index = 1;	
	int ans = 0;
	REP(i,N){
	
		if(arr[i] == index){
			index++;
		}
		else{
			ans++;
		}
	}

	if(ans == N){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	return 0;

}



Measured memory_bytes: 3992
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a*n < b ? a*n : b);
        sc.close();

    }

}


Measured memory_bytes: 23636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        //int[] a = new int[n+1];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0;i<q;i++) {
            int t = sc.nextInt();
            int count = map.getOrDefault(t, 0);
            map.put(t, ++count);
        }

        for (int i = 1; i <= n;i++) {
            int score = k - q + map.getOrDefault(i, 0);
            if (score > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 64144
#include <iostream>
#include <algorithm>

using namespace std;


int main(){
	/*input*/
	int n;
    cin >> n;
    int w[100];
    for(int i = 0;i < n; i++){
    	cin >> w[i];
    }

	/*calc*/
    int s1 = w[0];
    int s2 = w[n-1];
    int ans = 100;
    int sum_w = 0;

  for (int i = 0; i < n; i++){
    	sum_w += w[i];
    }
    for (int i = 1; i<n-1; i++){
    	s1 += w[i];
    	s2 = sum_w - s1;
    	int tmp = abs(s1 - s2);
    	if(ans > tmp){
    		ans = tmp;
    	}
    }
	/*output*/
   	cout<<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define INF 1e9
#define MAX 150
#define min(a,b) ((a) < (b) ? (a) : (b))

int main(){
  int n,i,u,k,j,v,c;
  int d[MAX][MAX];

  for(i = 0 ; i < MAX ; i++){
    for(j = 0 ; j < MAX ; j++){
      d[i][j] = INF;
    }
    d[i][i] = 0;
  }

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d%d" ,&u ,&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d%d" ,&v ,&c);
      d[u][v] = c;
    }
  }

  for(k = 0 ; k < n ; k++){
    for(i = 0 ; i < n ; i++){
      for(j = 0 ; j < n ; j++){
	d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }

  for(i = 0 ; i < n ; i++){
    printf("%d %d\n" ,i ,d[0][i]);
  }

  return 0;
}

Measured memory_bytes: 688
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	int n, m;
	int match[10] = { 0,2,5,5,4,5,6,3,7,6 };
	cin >> n >> m;

	vector<int> num(9, 0);
	for (int i = 0; i < m;i++)
	{
		int a;
		cin >> a;
		num[match[a]] = max(num[match[a]], a);
	}

	vector<string> dp(n + 1, "0");
	dp[0] = "";
	for (int i = 0; i < n;i++)
	{
		for (int j = 0;j < 9;j++)
		{
			if (i + j > n || num[j] == 0 || dp[i] == "0")
			{
				continue;
			}
			string s = dp[i];
			s.push_back(num[j] + '0');

			if (dp[i + j] == "" || dp[i + j] < s || (int)(dp[i + j]).size() < (int)(s).size())
			{
				dp[i + j] = s;
			}
		}
	}
	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 45056
def solve():
    N,M = map(int, input().split())
    H = list(map(int, input().split()))
    AB = [list(map(int, input().split())) for _ in range(M)]

    graph = [[] for _1 in range(N)]
    for a,b in AB:
        graph[a-1].append(b)
        graph[b-1].append(a)
    ans = 0
    #print(graph)

    for i in range(N):
        height = H[i]
        for j in graph[i]:
            if height <= H[j-1]:
                #print(height,H[j-1])
                break
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    solve()


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

vector <lli> stone(100009);
vector <lli> dp(100009,-1);
lli N,K;

lli solve(lli index){

    if(index == N-1)
        return 0;

    if(dp[index] != -1){
        return dp[index];
    }

    lli ans = INT_MAX;
    for(int i=1;i<=K;i++){

        if(i+index <= N-1)
        ans = min(ans, solve(index+i) + abs(stone[index+i] - stone[index]));
    }

    return dp[index] = ans;
}


int main(){
    cin >> N >> K;

    for(int i=0;i<N;i++){
        cin >> stone[i];
    }

    cout << solve(0) << endl;
}

Measured memory_bytes: 9528
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            String[] nm = sc.nextLine().split(" ");
            int n = Integer.parseInt(nm[0]);
            long k = Long.parseLong(nm[1]);
            
            String[] alist = sc.nextLine().split(" ");
            //Convert to binary string
            long[] aary = new long[n];
            for(int i=0;i<n;i++){
                aary[i] = Long.parseLong(alist[i]);
            }
            
            //Convert to binary string
            String[] bsary = new String[n];
            int maxbslen = 0;
            for(int i=0;i<n;i++){
                bsary[i] = Long.toBinaryString(aary[i]);
                maxbslen = Math.max(maxbslen,bsary[i].length());
            }
            
            //Count each bit in binary string
            long bitcount [] = new long[maxbslen];
            for(String bs:bsary){
                for(int j=bs.length() - 1; j >= 0;j--){
                    if(bs.charAt(j)=='1'){
                        bitcount[bs.length() - 1 - j]++;
                    }
                }
            }
            
            //Calculate digits of x in binary
            int xdigit = Long.toBinaryString(k).length();
            
            //Calculate x
            long x = 0;
            for(int i=xdigit - 1; i >= 0; i--){
                long next = x + (long)Math.pow(2,i);
                if(next <= k){
                    if(i >= bitcount.length){
                        x = next;                 
                    }else{
                        if(bitcount[i] <= n/2){
                            x = next;
                        }
                    }
                }
            }
            
            //Calculate f
            long f = 0;
            for(long a:aary){
                f += x^a;
            }
            System.out.println(f);
		}
    }
}

Measured memory_bytes: 56392
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll k;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>k;
		ll base = 1;
		for(ll i=1;i<=k;i++)
		{
			if(7*base%k==0){cout<<i;return;}
			base= (1 + base*10)%k;
		}
		cout<<-1;
}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 10672