akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll> 
#define ALL(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,x,ans=1e9,ans_;cin>>n>>m>>x;
  lvector price(n,0),understood(m,0);
  vector<lvector> V(n,lvector(m,0));
  rep(i,n) {
    cin>>price[i];
    rep(j,m) cin>>V[i][j];
  }
  for(ll b=0;b<(1<<n);++b) {
    ans_=0;
    fill(ALL(understood),0);
    for(ll t=0;t<n;++t) {
      if(b&(1<<t)) {
        ans_+=price[t];
        rep(i,m) understood[i]+=V[t][i];
      }
    }
    if(*min_element(ALL(understood))>=x) ans=min(ans,ans_);
  }
  print((ans!=1e9)?ans:-1);
  return 0;
}

Measured memory_bytes: 3668
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
vector<vector<bool>> seat;

int main() {
	int n;
	cin >> n;
	int a[n];
	int ans = 0;
	rep(i, n) {
		cin >> a[i];

		if ((i + 1) % 2 == 1 && a[i] % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3192
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
constexpr int inf = (1 << 30) - 1;
constexpr lint linf = (1ll << 60) - 1;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

namespace FastFourierTransform
{
  using C = complex< double >;

  void DiscreteFourierTransform(vector< C > &F, bool rev)
  {
    const int N = (int) F.size();
    const double PI = (rev ? -1 : 1) * acos(-1);
    for(int i = 0, j = 1; j + 1 < N; j++) {
      for(int k = N >> 1; k > (i ^= k); k >>= 1);
      if(i > j) swap(F[i], F[j]);
    }
    C w, s, t;
    for(int i = 1; i < N; i <<= 1) {
      for(int k = 0; k < i; k++) {
        w = polar(1.0, PI / i * k);
        for(int j = 0; j < N; j += i * 2) {
          s = F[j + k];
          t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
                F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
          F[j + k] = s + t, F[j + k + i] = s - t;
        }
      }
    }
    if(rev) for(int i = 0; i < N; i++) F[i] /= N;
  }

  vector< long long > Multiply(const vector< int > &A, const vector< int > &B)
  {
    int sz = 1;
    while(sz < A.size() + B.size() - 1) sz <<= 1;
    vector< C > F(sz), G(sz);
    for(int i = 0; i < A.size(); i++) F[i] = A[i];
    for(int i = 0; i < B.size(); i++) G[i] = B[i];
    DiscreteFourierTransform(F, false);
    DiscreteFourierTransform(G, false);
    for(int i = 0; i < sz; i++) F[i] *= G[i];
    DiscreteFourierTransform(F, true);
    vector< long long > X(A.size() + B.size() - 1);
    for(int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
    return (X);
  }
};

int main() {

    int N; lint M;
    cin >> N >> M;
    vector<int> cnt(100001, 0);
    rep(i, N) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    vector<lint> use = FastFourierTransform::Multiply(cnt, cnt);
    lint done = 0, ans = 0;
    for(lint i = 200000; i >= 0; --i) {
        if(done + use[i] > M) {
            lint canuse = M - done;
            ans += canuse * i;
            done = M;
            break;
        }
        ans += use[i] * i;
        done += use[i];
    }
    cout << ans << '\n';
    return 0;

}


Measured memory_bytes: 10624
h,w,k=map(int,input().split())
board=[list(input()) for _ in range(h)]
ans=0
for paint_h in range(2**h):
  for paint_w in range(2**w):
    cnt=0
    for i in range(h):
      for j in range(w):
        if (paint_h>>i)&1==0 and (paint_w>>j)&1==0:
          if board[i][j]=='#':
            cnt+=1
    if cnt==k:
      ans+=1
print(ans)

Measured memory_bytes: 9104
#include <stdio.h>

int main(void)
{
	int r, c, graph[101][101], count_1, count_2;

	scanf("%d %d", &r, &c);

	for (count_1 = 0; count_1 < r; count_1++)
	{
		for (count_2 = 0; count_2 < c; count_2++)
		{
			scanf("%d", &graph[count_1][count_2]);
		}
	}

	for (count_1 = 0; count_1 < r; count_1++)
	{
		for (count_2 = 0, graph[count_1][c] = 0; count_2 < c; count_2++)
		{
			graph[count_1][c] = graph[count_1][c] + graph[count_1][count_2];
		}
	}

	for (count_1 = 0; count_1 < (c + 1); count_1++)
	{
		for (count_2 = 0, graph[r][count_1] = 0; count_2 < r; count_2++)
		{
			graph[r][count_1] = graph[r][count_1] + graph[count_2][count_1];
		}
	}

	for (count_1 = 0; count_1 < (r + 1); count_1++)
	{
		for (count_2 = 0; count_2 < (c + 1); count_2++)
		{
			printf("%d", graph[count_1][count_2]);
			if (count_2 < c)
			{
				printf(" ");
			}
		}

		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>

 using namespace std;

int main()
{
  int inputA, inputB;
  cin >> inputA >> inputB;
  if(inputA > inputB){
      cout << "a > b" << endl;
  }else if (inputA < inputB){
      cout << "a < b" << endl;
  }else if(inputA == inputB){
      cout << "a == b" << endl;
  }
   return 0;
}
// comments for human
// 1 min = 60 sec
// 1 hour = 60 min = 3600 sec


Measured memory_bytes: 3092
#include <bits/stdc++.h>
/*
                 ,,ggddY888Ybbgg,,
          ,agd8""'   .d8888888888bga,
       ,gdP""'     .d88888888888888888g,
     ,dP"        ,d888888888888888888888b,
   ,dP"         ,8888888888888888888888888b,
  ,8"          ,8888888P"""88888888888888888,
 ,8'           I888888I    )88888888888888888,
,8'            `8888888booo8888888888888888888,
d'              `88888888888888888888888888888b
8                `"8888888888888888888888888888
8                  `"88888888888888888888888888
8                      `"8888888888888888888888
Y,                        `8888888888888888888P
`8,                         `88888888888888888'
 `8,              .oo.       `888888888888888'
  `8a             8888        88888888888888'
   `Yba           `""'       ,888888888888P'
     "Yba                   ,88888888888'
       `"Yba,             ,8888888888P"'
          `"Y8baa,      ,d88888888P"'
               ``""YYba8888P888"'
*/
using namespace std;
#define int long long
#define KOD ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define sz size()
#define S second
#define X(a,b) a = ((b) > (a)) ? (b) : (a);
#define N(a,b) a = ((b) > (a)) ? (a) : (b);
#define F first
#define SORT(x) sort(x.begin(),x.end())
#define Rev(a) reverse(a.begin() , a.end());
#define pb push_back
#define pre(x) cout.precision(0);
#define bit(x) __builtin_popcount(x)
#define is(a) insert(a);
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef unordered_map<int,int> wi;
typedef unordered_set<int> si;
const int M = 1e5+2;
const int inf = 1e18;
main(){
	int a , b;
	cin >> a >> b;
	if(a <= b) cout <<"unsafe";
	else cout << "safe";
}


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

int mypow(int x, int y);

int main(){
    int a, b;
    int ans_a = 0, ans_b = 0;

    std::cin >> a >> b;

    for(int i = 0; i < b; i++){
        ans_a = a * mypow(10,i) + ans_a;
    }

    for(int i = 0; i < a; i++){
        ans_b = b * mypow(10,i) + ans_b;
    }

    //std::cout << ans_a << "\n";
    //std::cout << ans_b << "\n";

    if(a < b){
        std::cout << ans_a;
    }else{
        std::cout << ans_b;
    }

}

int mypow(int x, int y){
    int ans = 1;
    for(int i = 0; i < y; i++){
        ans = ans * x;
    }
    return ans;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    string s;cin >> s;

    map<string,int> m;

    for(int i = 0 ; i < s.size() ; i++){
        string tmp = s.substr(i,1);
        m[tmp]+=1;
    }

    for(int i = 0 ; i < s.size() ; i++){
        string tmp = s.substr(i,1);
        if(m[tmp]%2!=0) {
            Yes(0);
            return 0;
        }
    }
    Yes(1);
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	string s; cin>>s;
	ll L=s.sz;
	//ans=dp[L-1][5]
	vector<vector<ll>> dp(L,vector<ll>(13,0));

	vector<vector<ll>> P(13,vector<ll>(13,0));
	rep(i,13)rep(j,13){
		rep(k,10){
			if((i*10+k)%13==j){
				P[i][j]=1;
				break;
			}
		}
	}

	if(s[0]=='?'){
		rep(i,10) dp[0][i]=1;
	}
	else{
		ll tmp=s[0]-'0';
		dp[0][tmp]=1;
	}
	rep1(i,L-1){
		if(s[i]=='?'){
			//あまりをjにする
			rep(j,13)rep(k,13){
				dp[i][j]+=dp[i-1][k]*P[k][j];
			}
			rep(j,13) dp[i][j]%=MOD;
		}
		else{
			ll tmp=s[i]-'0';
			rep(j,13){
				ll jj=j-tmp;
				if(jj<0) jj+=13;
				//?*10%13==jjとなるか
				rep(k,13){
					if((k*10)%13==jj){
						dp[i][j]=dp[i-1][k];
						break;
					}
				}
			}
			rep(j,13) dp[i][j]%=MOD;
		}
	}
	cout<<dp[L-1][5];
}

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

using namespace std;
#define lint long long

const lint MAX_H = 1000000;

lint gcd(lint a, lint b){
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}


int main() {
    lint N, X;
    cin >> N >> X;
    
    if(X > N / 2){
        X = N - X;
    }
    
    
    
    lint g;
    g = gcd(N, X);
    
    X /= g;
    N /= g;
    
    cout << 3 * (N - 1) * g << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) ans+=i*(n-i+1);
    for(int i=0;i<n-1;i++){
        ll u,v;
        cin>>u>>v;
        ans-=min(u,v)*(n-max(u,v)+1);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n; cin>>n;
  bool ans = false;
  for (int i=0; i<n; i++){
    for (int j=0; j<n; j++){
      if (i*4+j*7==n) ans=true;
    }
  }
  cout<<(ans ? "Yes":"No")<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = 1 << 61;
    static int[] x4 = {-1, 0, 0, 1};
    static int[] y4 = {0, -1, 1, 0};
    static int[] x8 = {-1, -1, 0, 1, 1, 1, 0, -1};
    static int[] y8 = {0, -1, -1, -1, 0, 1, 1, 1};

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        List<P> p = new ArrayList<>();
        for(int i = 0; i < m; i++) {
            p.add(new P(in.nextInt(), in.nextInt()));
        }
        p.sort((P a, P b) -> {return a.y-b.y;});

        int ans = 1;
        int cut = p.get(0).y;
        for(int i = 1; i < m; i++) {
            if(p.get(i).x < cut) continue;
            ans++;
            cut = p.get(i).y;
        }

        System.out.println(ans);
    }

    static public void printArray2D(char[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%c\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }

    static public void printArray2D(int[][] map) {
        for(int i = 0; i < map.length; i++) {
            for(int j = 0; j < map[i].length; j++) {
                System.out.format("%d\t", map[i][j]);
            }
            System.out.print("\n");
        }
    }
}

class P {
    int x, y;
    P(int x, int y) {
        this.x = x;
        this.y = y;
    }
}


Measured memory_bytes: 93804
package main

import (
	"fmt"
)

//最大値
func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("min() requires at least one arguments.")
	}
	res := nums[0]
	for _, val := range nums {
		if res < val {
			res = val
		}
	}
	return res
}


func main() {
	var k, n int
	fmt.Scan(&k, &n)
	a := make([]int, n)
	dist := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	var ans int
	for i := 0; i < n-1; i++ {
		dist[i] = a[i + 1] - a[i]
		ans += dist[i]
	}
	dist[n] = a[0] + k - a[n - 1]
	ans += dist[n]
	fmt.Println(ans - Max(dist...))
}


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


int main ()
{
    int a, b, c, x, i, j, k, cnt=0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for (i=0; i <= a && 500*i<=x; i++)
    {
        for (j=0; j <= b && 100*j+500*i<=x; j++)
        {
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
            {
                if (500*i+100*j+50*k==x)
                {
                    cnt++;
                }
            }
        }
    }

    printf("%d", cnt);

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp.chars
dp = Array.new(s.size, 0)
if s[0] == "B"
  dp[0] += 1
end
idx = []
1.step(s.size - 1) do |i|
  if s[i] == "B"
    dp[i] = dp[i - 1] + 1
  else
    dp[i] = dp[i - 1]
    idx << i
  end
end

res = 0
idx.each do |i|
  res += dp[i]
end
puts res

Measured memory_bytes: 33352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF=(1LL<<60);

int main(void){
    int x,y; cin >> x >> y;
    cout << x+y/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

ll mod = 1000000007;

struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod) {}
    mint& operator+=(const mint a) {
        (x += a.x) %= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        (x += mod - a.x) %= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
};

const int MAX = 510000;
const int MOD = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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;
}

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

    ll n, k;
    cin>>n>>k;

    if (n - 1 <= k) cout<<COM(2 * n - 1, n - 1)<<endl;
    else {
        mint ans(0);
        rep(i, k + 1) {
            ans += (COM(n, i) * COM(n - 1, i)) % mod;
        }
        cout<<ans.x<<endl;
    }
}

Measured memory_bytes: 12160
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x,long long int y) {
	return(x + y-1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

int main() {
	int N;
	cin >> N;
	int n[100];
	int value[100];
	int purasu[100];
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		n[i] = a;
	}
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		value[i] =a;
	}
	for (int i = 0; i < N-1; i++) {
		int a;
		cin >> a;
		purasu[i] = a;
	}
	for (int i = 0; i < N; i++) {
		int a = n[i];
		sum = sum + value[a-1];
		if (i > 0) {
			if (n[i] == n[i - 1] + 1) {
				sum = sum + purasu[n[i-1]-1];
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, m;std::cin >> n >> m;
  vvl d = vv(m, 2, 0, ll);
  re(i, m) std::cin >> d[i][0] >> d[i][1];
  ll ans = 10000000000;
  if(n==1){
    for(int i=9;i>=0;i--){
      bool flag = true;
      string now = to_string(i);

      for(int j=0;j<m;j++){
        if(now[d[j][0]-1]-'0'!=d[j][1]) flag = false;
      }
      if(flag) ans = i;
    }
  }else if(n==2){
    for(int i=99;i>=10;i--){
      bool flag = true;
      string now = to_string(i);

      for(int j=0;j<m;j++){
        if(now[d[j][0]-1]-'0'!=d[j][1]) flag = false;
      }
      if(flag) ans = i;
    }
  }else{
    for(int i=999;i>=100;i--){
      bool flag = true;
      string now = to_string(i);

      for(int j=0;j<m;j++){
        if(now[d[j][0]-1]-'0'!=d[j][1]) flag = false;
      }
      if(flag) ans = i;
    }
  }
  std::cout << (ans==10000000000?-1:ans) << '\n';
  return 0;
}


Measured memory_bytes: 888
N,M = map(int,input().split())
C = {i:[0,0] for i in range(1,N+1)}
for _ in range(M):
    p,S = input().split()
    p = int(p)
    if C[p][0]==0 and S=="WA":
        C[p][1] += 1
    elif C[p][0]==0 and S=="AC":
        C[p][0] = 1
numA = 0
numB = 0
for i in range(1,N+1):
    numA += C[i][0]
    if C[i][0]==1:
        numB += C[i][1]
print(numA,numB)

Measured memory_bytes: 59236
#include <iostream>
using namespace std;
int main()
{
	int n,m,c;
	cin>>n>>m>>c;
	int b[m+1];
	for(int i=1;i<=m;i++)
		cin>>b[i];
	int a[n+1][m+1];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	int s=0;
	for(int i=1;i<=n;i++){
		int n=0;
		for(int j=1;j<=m;j++){
			n+=a[i][j]*b[j];
		}
		n+=c;
		if(n>0)
			s++;
	}
	cout<<s<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

// http://algoogle.hadrori.jp/algorithm/segment-tree.html
struct SegTreeMin {
    ll N, dat[4 * 1000];

    SegTreeMin() {}

    SegTreeMin(ll n) {
        N = 1;
        while (N < n) N *= 2;
        for (ll i = 0; i < 2 * N - 1; i++)
            dat[i] = INF;
    }

    // update k th element
    void update(ll k, ll a) {
        k += N - 1; // leaf
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    // min [a, b)
    ll query(ll a, ll b) { return query(a, b, 0, 0, N); }

    ll query(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a or b <= l) return INF;
        if (a <= l and r <= b) return dat[k];
        ll m = (l + r) / 2;
        return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
    }
};


struct SegTreeMax {
    ll N, dat[4 * 1000];

    SegTreeMax() {}

    SegTreeMax(ll n) {
        N = 1;
        while (N < n) N *= 2;
        for (ll i = 0; i < 2 * N - 1; i++)
            dat[i] = -INF;
    }

    // update k th element
    void update(ll k, ll a) {
        k += N - 1; // leaf
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    // max [a, b)
    ll query(ll a, ll b) { return query(a, b, 0, 0, N); }

    ll query(ll a, ll b, ll k, ll l, ll r) {
        if (r <= a or b <= l) return -INF;
        if (a <= l and r <= b) return dat[k];
        ll m = (l + r) / 2;
        return max(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
    }
};

typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    a.erase(unique(a.begin(), a.end()), a.end());

    print_line(a);

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,i;cin>>N;
  vector<string>A(N),B(N);
  for(i=0;i<N;i++){
    cin>>A.at(i);
    if(count(A.begin(),A.end(),A.at(i))==2)break;
    if(i!=0&&A.at(i-1).at(A.at(i-1).size()-1)!=A.at(i).at(0))break;
  }
  if(i==N)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input())
ls = []
for i in range(n):
    ls.append(int(input()))
lighted = [False for i in range(n)]
inx = 1
lighted[0] = True
cnt = 0
while 1:
    dest = ls[inx - 1]
    if not lighted[dest - 1]:
        if dest == 2:
            cnt += 1
            break
        else:
            lighted[dest - 1] = True
    else:
        cnt = -1
        break
    inx = dest
    cnt += 1
    
print(cnt)



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

int main() {
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	if(s[k-1]=='A'){
		s[k-1]='a';
	}
	else if(s[k-1] == 'B'){
		s[k-1]='b';
	}
	else s[k-1]='c';

	cout<<s<<endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
using namespace std;
long long a[1005],b[1005];
vector <long long> v;
string ans[1005];
int main(int argc, char** argv) {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i] >> b[i];
	for(int i=2;i<=n;i++)
	{
		if((a[i]+b[i]&1)!=(a[i-1]+b[i-1]&1))
		{
			puts("-1");
			return 0;
		}
	}
	if(!(a[1]+b[1]&1))
	{
		v.push_back(1);
		for(int i=1;i<=n;i++)
		{
			ans[i]+='L';
			++a[i];
		}
	}
	int now=1;
	for(int i=1;i<=30;i++)
	{
		v.push_back(now);
		for(int j=1;j<=n;j++)
		{
			if(a[j]&now)
			{
				if((b[j]&(now<<1))==(a[j]&(now<<1)))
				{
					a[j]+=now;
					ans[j]+='L';
				}
				else
				{
					a[j]-=now;
					ans[j]+='R';
				}
			}
			else
			{
				if((a[j]&(now<<1))==(b[j]&(now<<1)))
				{
					b[j]+=now;
					ans[j]+='D';
				}
				else
				{
					b[j]-=now;
					ans[j]+='U';
				}
			}
		}
		now<<=1;
	}
	v.push_back(now);
	for(int i=1;i<=n;i++)
	{
		if(a[i]<0) ans[i]+='L';
		if(a[i]>0) ans[i]+='R';
		if(b[i]<0) ans[i]+='D';
		if(b[i]>0) ans[i]+='U';
	}
	cout << v.size() << "\n";
	for(auto x:v) cout << x << " ";
	puts("");
	for(int i=1;i<=n;i++) cout << ans[i] << "\n";
	return 0;
}

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

int main(){
    int m, n;
    cin >> m >> n;
    vector<int> p(m);
    for(int i = 0; i < m; i++)  cin >> p[i];
    sort(p.rbegin(), p.rend());
    for(int i = 1; i < m; i++)  p[i] += p[i-1];
    vector<int> c(n), e(n);
    for(int i = 0; i < n; i++)  cin >> c[i] >> e[i];
    vector<int> dp(20002, 1<<30);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 20000-c[i]; j >= 0; j--){
            dp[j+c[i]] = min(dp[j+c[i]], dp[j]+e[i]);
        }
    }
    for(int i = 20000; i >= 0; i--) dp[i] = min(dp[i], dp[i+1]);
    int ans = 0;
    for(int i = m; i > 0; i--){
        ans = max(ans, p[i-1]-dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3248
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local ret = 0
local right = {}
for i = n, 1, -1 do
  local tgt = -a[i] - i
  if right[tgt] then
    ret = ret + right[tgt]
  end
  local add = a[i] - i
  if not right[add] then
    right[add] = 1
  else
    right[add] = right[add] + 1
  end
end
local left = {}
for i = 1, n do
  local tgt = i - a[i]
  if left[tgt] then
    ret = ret + left[tgt]
  end
  local add = a[i] + i
  if not left[add] then
    left[add] = 1
  else
    left[add] = left[add] + 1
  end
end
print(math.floor(ret / 2))


Measured memory_bytes: 20484
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
inline int rd()
{
    static int x,f;
    x=0,f=1;
    char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}
const int N=200010,Inf=1000000000;
struct edge{
    int v,next;
    edge(int v=0,int next=0):v(v),next(next){}
}e[N<<1];
int n;ll ans=0;
int head[N],tot=0;
int mx[N],sx[N],mn[N],siz[N];
char s[N];

inline void add(int u,int v){e[++tot]=edge(v,head[u]);head[u]=tot;}

void dfs1(int u,int fat)
{
    if(s[u]=='1')mn[u]=0,siz[u]=1;
    else mn[u]=Inf;
    fe(i,u){
        int v=e[i].v;
        if(v==fat)continue;
        dfs1(v,u);siz[u]+=siz[v];
        int dis=mx[v]+1;
        if(mx[u]<dis)sx[u]=mx[u],mx[u]=dis;
        else sx[u]=max(sx[u],dis);
        if(siz[v])mn[u]=min(mn[u],dis);
    }
}
void dfs2(int u,int fat)
{
    int mxd=min(mx[u]-1,sx[u]+1);
    if(mxd>=mn[u])ans+=(ll)mxd-mn[u]+1;
    fe(i,u){
        int v=e[i].v;
        if(v==fat)continue;
        int dis=mx[u]==mx[v]+1?sx[u]+1:mx[u]+1;
        if(mx[v]<dis)sx[v]=mx[v],mx[v]=dis;
        else sx[v]=max(sx[v],dis);
        if(siz[v]<siz[1])mn[v]=min(mn[v],dis);
        dfs2(v,u);
    }
}

int main()
{
    n=rd();
    fo(i,1,n-1){
        int x=rd(),y=rd();
        add(x,y);add(y,x);
    }
    scanf("%s",s+1);
    dfs1(1,0);dfs2(1,0);
    printf("%lld\n",ans+1ll);
    return 0;
}

Measured memory_bytes: 14592
from math import factorial


def nCr(n, r):
    if r <= 0:
        return 0

    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0

N = input()
K = int(input())

def rec(n, k, smaller):
    n = n.lstrip('0')

    if k == 0:
        return 1

    if len(n) < k:
        return 0

    if k == 1:
        if len(n) == 1:
            return int(n)


    if smaller:
        return nCr(len(n), k) * 9 ** k


    ret = 0
    ret += rec(n[1:], k-1, False)
    ret += rec('9'*(len(n)-1), k-1, True) * (int(n[0]) - 1)
    ret += rec('9'*(len(n)-1), k, True)

    return ret
    
ans = rec(N, K, False)
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#define US unsigned short
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long
using namespace std;

int main(int argc, char const *argv[])
{
    short a, h;
    float x;
    cin >> a >> h >> x;
    // b = (2 * x) / (a * a) - h;
    // cout << atan2(a * sqrt(2), 2 * h - ((2 * x) / (a * a))) * 180.0 / M_PI << endl
    //      << b << endl;
    if (a * a * h / 2.0 >= x)
        cout << fixed << setprecision(10) << atan2(h, (2 * x) / (h * a)) * 180.0 / M_PI << endl;
    else
        cout << fixed << setprecision(10) << atan(2 * (a * a * h - x) / (a * a * a)) * 180.0 / M_PI << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	string s;
	cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC");





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int h,w,ans=0;
    cin>>h>>w;
    vector<vector<int>> cost(10,vector<int>(10,0));
    vector<int> wall(10,0);

    rep(i,10)rep(j,10)cin>>cost[i][j];
    rep(i,h*w){
        int n; cin>>n;
        if(n!=-1) wall[n]++;
    }

    rep(i,10)rep(j,10)rep(k,10)
        if(cost[j][k]>cost[j][i]+cost[i][k])
            cost[j][k]=cost[j][i]+cost[i][k];
    
    rep(i,10)ans+=cost[i][1]*wall[i];
    cout<<ans;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i, j, k, w, n, num[30], tmp;
	
	scanf("%d %d", &w, &n);
	
	for(i = 0; i < w; i++) num[i] = i + 1;
	
	for(i = 0; i < n; i++){
		scanf("%d,%d", &j, &k);
		tmp = num[j - 1];
		num[j - 1] = num[k - 1];
		num[k - 1] = tmp;
	}
	
	for(i = 0; i < w; i++) printf("%d\n", num[i]);
	
	return 0;
}

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

int n,dis[250010],x,ans,a[250010][5],an[250010],q[250010],l,r,bo[250010];

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++)
		{
			int nw=(i-1)*n+j;
			dis[nw]=min(min(i-1,n-i),min(j-1,n-j)),bo[nw]=1;
			if (i!=1) a[nw][++an[nw]]=nw-n;
			if (i!=n) a[nw][++an[nw]]=nw+n;
			if (j!=1) a[nw][++an[nw]]=nw-1;
			if (j!=n) a[nw][++an[nw]]=nw+1;
		}
	for (int qaq=1; qaq<=n*n; qaq++)
	{
		scanf("%d",&x),ans+=dis[x];
		q[l=r=1]=x,bo[x]=0;
		while (l<=r)
		{
			x=q[l++];
			for (int i=1; i<=an[x]; i++)
				if (dis[x]+bo[x]<dis[a[x][i]]) dis[a[x][i]]=dis[x]+bo[x],q[++r]=a[x][i];
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

const int MAX_N=100001;
char str[MAX_N];
int person[MAX_N];

int getLen(int here, char match, int dir)
{
	if (here < 0 || str[here] == '\0') return 0;
	if (str[here] != match) return 0;
	return 1 + getLen(here + dir, match, dir);
}

int main()
{
	scanf("%s", str);
	for (int i=1; str[i]; i++)
	{
		if (str[i-1] == 'R' && str[i] == 'L')
		{
			int left = getLen(i-1, 'R', -1);
			int right = getLen(i, 'L', 1);
			left--, right--;
			person[i-1] = (left/2 + right/2 + right%2) + 1;
			person[i] = (left/2 + right/2 + left%2) + 1;
		}
	}

	for (int i=0; str[i]; i++)
		printf("%d ", person[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 2048
from itertools import product

N = int(input())
c = product(range(2), repeat=N)
d = [[] for _ in range(N)]

for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        d[i].append((x, y))


ans = 0
for l in c:
    is_conflict = False
    for i, j in enumerate(l):
        if j==0:continue
        for x, y in d[i]:
            if l[x-1]!=y:
                is_conflict = True
                break
        if is_conflict == True:
            break
    else:
        ans = max(ans, sum(l))

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  if(s.length() < 4) {
    puts("No");
  }
  else {
    if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
      puts("Yes");
    } else {
      puts("No");
    }
  }
  return 0;
}

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

typedef long long int ll;


int main()
{
    ll n;
    string s;
    bool f = true;
    cin >> n >> s;
    if(n % 2 != 0){
        f = false;
    }
    string t, t2;
    for(ll i = 0;i < n / 2;i++){
        t.push_back(s[i]);
    }
    t2 = t + t;
    if(t2 != s){
        f = false;
    }

    if(f){
        cout << "Yes";
    }
    else{
        cout << "No";
    }


    return 0;
}

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

int main(){

  long int n;
  string x,y,z;
  while(cin >> n, n){

    long int m;
    map < string,string > a;

    for(int i=0;i<n;i++){
      cin >> x >> y;
      a[x] = y;
    }

    cin >> m;

    for(int i=0;i<m;i++){
      cin >> z;
      if(a[z].empty() == false) cout << a[z];
      else cout << z;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1212
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int a[3];
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]==a[1]&&a[0]!=a[2])
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(a[1]==a[2]&&a[0]!=a[2])
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,l,r,mid,flag,a[500010],ans,po;
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n*2;i++)scanf("%d",&a[i]);
	sort(a+1,a+n*2+1);
	l=0;r=n;
	while(l<r){
		mid=(l+r)/2;
		flag=0;
		for(i=mid*2+1;i<=n*2;i++)if(a[i]+a[n*2+mid*2+1-i]<m){
			flag=1;break;
		}
		if(!flag)r=mid;
		 else l=mid+1;
	}
	po=r*2;
	for(i=1;i<=po;i++)ans=max(ans,a[i]+a[po-i+1]);
	for(i=po+1;i<=n*2;i++)ans=max(ans,(a[i]+a[n*2-i+po+1])-m);
	printf("%d",ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
bool used[100005];
ll ans[100005];
vvc<ll> D(100005);

int main() {
    init();
    ll N,M;
    cin >> N >> M;

    rep(i,M){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        D[a].eb(b);
        D[b].eb(a);
    }

    queue<pair<ll,ll>> q;
    q.emplace(0, 0);

    while(!q.empty()){
        ll now, c;
        tie(now, c) = q.front(), q.pop();
        if (used[now]) continue;
        used[now] = true;
        ans[now] = c;
        repa(to, D[now]){
            if (!used[to]) q.emplace(to, now);
        }
    }

    cout << "Yes" << '\n';
    repe(i, 1, N) cout << ans[i]+1 << '\n';
}

Measured memory_bytes: 14364
#include<bits/stdc++.h>
using namespace std;
string Replace(string s,int a,int b,string t){
    for(int i=a;i<=b;i++){
        s[i]=t[i-a];
    }
    return s;
}
string Reverse(string s,int a,int b){
    int i=a,j=b;
    while(i<j){
        swap(s[i],s[j]);
        i++;
        j--;
    }
    return s;
}void Print(string s,int a,int b){
    for(int i=a;i<=b;i++){
        cout<<s[i];
    }
    cout<<endl;
}
int main(){
    string str,command,t;
    cin>>str;
    int q,a,b;
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>command;
        cin>>a>>b;
        if(command=="replace"){
            cin>>t;
            str=Replace(str,a,b,t);
        }else if(command=="reverse"){
            str=Reverse(str,a,b);
        }else if(command=="print"){
            Print(str,a,b);
        }
    }
    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a>c){
     cout << "NO" << endl;
    return 0;
    }
    if(a+b>=c) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

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

int N;
vector<int> a;
vector<int> an;

int main(){
  cin >> N;

  a.resize(N+1);  int v;
  for(int i = 1; i <= N; i++){
    cin >> v;
    a[i] = v;
  }

  for(int j =1; j <= N; j++){
    if(a[j] == j) a[j] = 1;            //番号と値が同じなら1を導入
    else a[j] = 0;
  }

  int i = 1; int j = 0; int n = 1;
  while(i+j <= N){                        //1の連続数を配列anに入れる
    while(a[i+j] == n) j++;
      if(j > 0) an.push_back(j);  //j == 0は処理対象じゃない
      i += j + 1;
      j = 0;
  }

  int sum = 0;
  for(int i = 0; i < an.size(); i++)   //1がk個連続していると、すべて処理するには(k+1)/2回
    sum += (an[i]+1)/2;
  cout << sum << endl;
  return 0;
}
    
    

  

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

int main() {
  int n,m;
  cin >> n >> m;
  if(n/2<m) {
    cout << -1 << endl;
    return 0;
  }
  int a[n];
  for(int i=0; i<n; i++) a[i]=i+1;
  while(m--) {
    for(int i=0; i<n/2; i++) {
      cout << a[i] << " " << a[n-i-1] << endl;
      if(n%2||i!=n/2-1) cout << a[n-i-1] << " " << a[i+1] << endl;
    }
    if(!m) break;
    cout << endl;
    rotate(a,a+1,a+n);
  }
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define FOR(i,n,m) for(int i=n; i<(int)m; i++)
#define ROF(i,n,m) for(int i=n; i>(int)m; i--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define ri(a) scanf("%d",&a)
#define rii(a,b) ri(a),ri(b)
#define riii(a,b,c) rii(a,b),ri(c)
#define lri(a) scanf("%lld",&a)
#define lrii(a,b) lri(a),lri(b)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define all(x) x.begin(),x.end()
#define debug true
#define dprintf debug && printf

const int INF = 0x3f3f3f3f;
const ll INFLL = 1e18;
const int MOD = 1e9+7;
const int MAXN = 2e6+5;

int fact2(int n){
    int ret = 0;
    for(int i = 1; (1<<i) <= n; i++)
        ret += (n>>i);
    return ret;
}

int comb2(int n, int k){
    int cnt = fact2(n) - fact2(n-k) - fact2(k);
    return cnt == 0;
}

char s[MAXN];
int a[MAXN];
int n;

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

    ri(n);
    scanf("%s", s);
    FOR(i,0,n) a[i] = s[i] - '1';

    int par = 0;
    FOR(i,0,n) par ^= ((a[i]&1) & (comb2(n-1, i)));
    if(par){
        printf("1\n");
    }
    else{
        FOR(i,0,n) {
            if(a[i] == 1) {printf("0\n"); return 0;}
            a[i] >>= 1;
        }
        par = 0;
        FOR(i,0,n) par ^= ((a[i]&1) & (comb2(n-1,i)));
        printf(par ? "2\n" : "0\n");
    }

    return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include <string>
using namespace std;

int main()
{
    int N,M;
     cin>>N>>M;
     if(M<N)
     {
         for(int i=0;i<N;i++)
            printf("%d",M);
     }
     else
     {
         for(int i=0;i<M;i++)
            printf("%d",N);
     }

    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <regex>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
const long long INF =  999999999;

ll h[200010];

int main(){
    ll n,k,ans=0;
    cin>>n>>k;
    REP(i,n)cin>>h[i];
    sort(h,h+n);
    REPR(i,n-k-1){
      ans+=h[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
        vector<string> s(3);
        REP(i,3) cin>>s[i];
        int pos[3]={0};
        int cur=0;
        while(true){
                if(pos[cur]==s[cur].size()){
                        cout<<(char)('A'+cur)<<endl;
                        return 0;
                }
                cur=s[cur][pos[cur]++]-'a';
        }
}


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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(n);
	get(k);
	std::vector<int> v;	

	for (int i = 0; i < n; ++i)
	{
		get(ni);
		v.push_back(ni);
	}

	// now I just have to check from Kth term onwards

	for(int i = k ; i<n ; i++)
	{
		if(v[i] > v[i-k])
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 4252
S=input()
MOD=2019
dp=[0]*MOD
dp[0]=1
r=0
t=1
for c in reversed(S):
    r+=int(c)*t
    r%=MOD
    t*=10
    t%=MOD
    dp[r]+=1
print(sum(i*(i-1)//2 for i in dp))

Measured memory_bytes: 9192
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()
	s := map[string]int{}
	for i := 0; i < n; i++ {
		sc.Scan()
		s[sc.Text()] = 1
	}
	fmt.Println(len(s))

}


Measured memory_bytes: 18308
def ten_to_n(X, n):
    i = X // n
    s = str(X % n)
    if (i):
        return ten_to_n(i, n) + s
    return s

def solve():
    N, M = map(int, input().split())
    return len(str(ten_to_n(N, M)))

print(solve())

Measured memory_bytes: 3060