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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

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



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
        ll n, k;
        cin>>n>>k;
        vvi a(n, vi(n));
        vvi res(n, vi(n));
        for (int i = 0; i < n; ++i)
        {
            /* code */
            res[i][i] = 1;
            for(int j=0;j<n;j++){
                cin>>a[i][j];
            }
        }
        while(k){
            if(k&1){
                vvi x = vvi(n, vi(n));
                for(int i=0;i<n;i++)
                    for(int j=0;j<n;j++)
                        for(int l=0;l<n;l++)
                            x[i][j] = (x[i][j] + (res[i][l]*1ll*a[l][j])%mod)%mod;
                res = x;
            }
            vvi x = vvi(n, vi(n));
            for(int i=0;i<n;i++)
                for(int j=0;j<n;j++)
                    for(int l=0;l<n;l++)
                        x[i][j] = (x[i][j] + (a[i][l]*1ll*a[l][j])%mod)%mod;
            a = x;
            k /=2;
        }
        ll ans =0;
        for (int i = 0; i < n; ++i)
        {
            /* code */
            for (int j = 0; j < n; ++j)
            {
                /* code */
                ans = (ans + res[i][j])%mod;
            }
        }
        cout<<ans<<endl;

	}

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long
char dir[100005];


int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    int n, k;
    cin >> n >> k >> dir;
    char cur = dir[0];
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (dir[i] != cur) {
            cnt++;
            cur = dir[i];
        }
    }
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (dir[i] == dir[i-1]) ans++;
    }
    // if (cnt%2 == 0) {
    //     cout << ans + min(k, cnt/2)*2 << '\n';
    // } else {
    //     if ((cnt+1)/2 > k)
    // }
    while (k > 0) {
        if (cnt >= 2) {
            ans += 2;
            cnt -= 2;
            k--;
        } else if (cnt == 1) {
            ans++;
            break;
        } else {
            break;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 384
import numpy as np
N = int(input())
list_ai = list(map(int,input().split()))
list1 = [x-(i+1) for i,x in enumerate(list_ai)]
a1 = np.array(list1)
median1 = int(np.floor(np.median(a1)))
ans = np.sum(np.abs(a1-median1))
print(ans)

Measured memory_bytes: 34212
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

D = INT()
c = LIST()
s = [LIST() for _ in range(D)]

last = [0]*26
ans = 0
for i in range(D):
	t = INT()
	ans += s[i][t-1]
	last[t-1] = i+1
	decreasing = sum([c[j]*(i+1-last[j]) for j in range(26)])
	ans -= decreasing
	print(ans)


Measured memory_bytes: 10272
#include<stdio.h>

int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if((x+r)<=W && (x-r)>=0 && (y+r)<=H && (y-r)>=0){
	printf("Yes\n");
	}else{printf("No\n");}
	return 0;
}

Measured memory_bytes: 584
import sys
from collections import deque


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    S = list(map(int, list(input())))
    d_1 = deque(S[1:])
    d_2 = deque([S[0]])
    ans = 0
    for i in range(1, len(S)):
        if d_2:
            r = d_1.popleft()
            l = d_2.pop()
            if r != l:
                ans += 2
            else:
                d_2.append(l)
                d_2.append(r)
        else:
            d_2.append(d_1.popleft())
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11556
data_1 = [f'{s} {i}' for s in "SHCD" for i in range(1, 14)]
data_2 = []
n = int(input())
for x in range(1, n+1):
    y = input()
    data_2.append(y)
data_3 = []
for z in data_1 :
    if z not in data_2 :
        data_3.append(z)
for i in data_3 :
    print(i) 


Measured memory_bytes: 5616
import java.util.Scanner;
public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n];
        for (int i = 0; i < l.length; i++) {
            l[i] = sc.nextInt();
        }
        int d = 0;
        int counter = 1;
        for (int i = 0; i < l.length; i++) {
            d += l[i];
            if (d <= x) {
                counter++;
            }
        }
        System.out.println(counter);
        sc.close();
    }
}

Measured memory_bytes: 22732
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		if(Integer.parseInt(sc.next()) + Integer.parseInt(sc.next()) >= Integer.parseInt(sc.next())) ou.println("Yes");
		else ou.println("No");
		ou.flush();
	}
}

Measured memory_bytes: 27080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int a, b; cin >> a >> b;
    if(a <= 9 && b <= 9) cout << a * b << endl;
    else cout << -1 << endl;
}

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

int main() {
    int N,L;
    cin >> N >> L;
    int sum = 0;
    int mini = 1000000;
    for(int i = 0; i < N; i++){
        sum += L + i;
        if(abs(L + i) < abs(mini)){
            mini = L + i;
        }
    }
    cout << sum - mini << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long double ans=0;
	for(int i=1;i<=n;i++)
	{
		long double x;
		cin>>x;
		ans+=1.0/x;
	}
	ans=1.0/ans;
	printf("%.13Lf",ans);
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "Yes";
const string NO  = "No";

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



class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }

  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator <  (const Segment& s) const { return ( p2 == s.p2 ) ? p1 < s.p1 : p2 < s.p2; }
  bool operator == (const Segment& s) const { return ( s.p1 == p1 && s.p2 == p2 ) || ( s.p1 == p2 && s.p2 == p1 ); }

};

typedef Point Vector;
typedef Segment Line;
typedef vector<Point> Polygon;

ostream& operator << (ostream& os,const Point& a){ return os << "(" << a.x << "," << a.y << ")"; }

ostream& operator << (ostream& os,const Segment& a){ return os << "( " << a.p1 << " , " << a.p2 << " )"; }

double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }

double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }

double norm(Point a){ return a.x*a.x+a.y*a.y; }

double abs(Point a){ return sqrt(norm(a)); }

//rad は角度をラジアンで持たせること
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

// 度をラジアンに変換
double toRad(double agl){ return agl*M_PI/180.0; }

// a => prev, b => cur, c=> next
// prev から cur へ行って next へ行く際の角度を求める
double getArg(Point a,Point b,Point c){
  double arg1 = atan2(b.y-a.y,b.x-a.x);
  double arg2 = atan2(c.y-b.y,c.x-b.x);
  double arg = fabs( arg1 - arg2 );
  while( arg > M_PI ) arg -= 2.0 * M_PI;
  return fabs(arg);
}

int X;

void solve() {
  double rad = toRad(X);
  Point p = Point(0,0);
  int cnt = 1;
  Vector d = Vector(1,0);
  p = p + d;
  while( !( p == Point(0,0) ) ) {
    d = rotate(d,rad);
    ++cnt;
    p = p + d;
  }
  cout << cnt << endl;
}

int main() {
  cin >> X;
  solve();
  return 0;
}


Measured memory_bytes: 3908
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
#define accum(x) accumulate((x).begin(), (x).end(), 0)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

#define read_int(X) \
    ll X;           \
    scanf("%lld\n", &X);

#define read_two_int(X, Y) \
    ll X, Y;               \
    scanf("%lld %lld\n", &X, &Y);

#define read_three_int(X, Y, Z) \
    ll X, Y, Z;                 \
    scanf("%lld %lld %lld\n", &X, &Y, &Z);

#define read_four_int(X, Y, Z, W) \
    ll X, Y, Z, W;                \
    scanf("%lld %lld %lld %lld\n", &X, &Y, &Z, &W);

int main()
{
    ll N;
    scanf("%lld", &N);

    ll count = 0;
    bool ans = false;
    for (ll i = 0; i < N; i++)
    {
        ll d1, d2;
        scanf("%lld", &d1);
        scanf("%lld", &d2);

        if (d1 == d2)
            count++;
        else
            count = 0;

        if (count >= 3)
        {
            ans = true;
            break;
        }
    }

    if (ans)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int main() {

	int N;
	cin >> N;

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

	sort(A.begin(), A.end());

	A.push_back(0);

	int ans = 0;
	int cnt = 1;

	for (int i = 0; i < N; i++) {
		if (A[i] == A[i + 1]) {
			cnt += 1;
		}
		else {
			if (cnt % 2 != 0) {
				ans += 1;
			}
			cnt = 1;
		}
	}

	cout << ans << endl;


	return 0;
}

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int h,a,cnt=0;
  cin>>h>>a;
  while(h>0){
    cnt++;
    h=h-a;
  }
  
  cout<<cnt;  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000
#define PI 3.141592653589793

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}
	vector<vector<int>> table(n+1, vector<int>(0));
	vector<int> order(0);
	order.push_back(1);
	vector<int> ans(n+1, 0);
	ans[1] = 1;

	for (int i = 0; i < m; i++) {
		table[a[i]].push_back(b[i]);
		table[b[i]].push_back(a[i]);
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < table[order[i]].size(); j++) {
			int point = table[order[i]][j];
			if (!ans[point]) {
				ans[point] = order[i];
				order.push_back(table[order[i]][j]);
			}
		}
	}

	if (order.size() == n) {
		cout << "Yes" << endl;
		for (int i = 2; i < n + 1; i++) {
			cout << ans[i] << endl;
		}
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 12124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

ll dp[305][305];
ll pre[305][305];
int main(){
    ll n,k; cin >> n >> k;
    vector<ll> h(n+1);
    for(int i=1; i<=n; i++) cin >>h[i];

    rep(i,305)rep(j,305) dp[i][j]=INF;
    rep(i,305)rep(j,305) pre[i][j]=0;
    dp[0][0] = 0;
    pre[0][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=n-k; j++){
            if(j+1>i) continue;
            // //i+1番目まで見てj個選ぶときの最小コストをi番目まで見てj個選ぶときの最小コストで更新。
            // //更新できたなら、i+1番目まで見てj個選ぶときに最小コストを叩き出す組み合わせで一番右にあるのはi番目まで見てj個選ぶときと同じ。（何も加えてないので）
            // if(chmin(dp[i+1][j], dp[i][j])) pre[i+1][j] = pre[i][j]; 
            // //i+1番目まで見てj+1個選ぶときの最小コストをi番目まで見てj個選んだときの最小コスト+その際の一番右の柱を参考にしたコストとして更新
            // if(chmin(dp[i+1][j+1], dp[i][j]+max(h[i+1]-pre[i][j],(ll)0))) pre[i+1][j+1] = h[i+1];
            rep(k,i){
                chmin(dp[i][j+1], dp[k][j]+max((ll)0, h[i]-h[k]));
            }

        }
    }
    ll ans = INF;
    rep(i,n+1) chmin(ans, dp[i][n-k]);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll A,N,M;
    cin >> A >> N >> M;
    cout << min(N,M) <<  " " << max(0LL,N+M-A) << endl;
}

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

signed main() {
  int n, d, ans;
  cin >> n >> d;
  ans = (n - 1) / (2 * d + 1) + 1;
  cout << ans << endl;
}

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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define let const auto
#define USE1(T) template <typename T>
#define USE2(T, U) template <typename T, typename U>
#define I_ inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

USE1(T) using duo = std::pair<T, T>;
USE1(T) using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE2(T,U) I_ bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U) I_ bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int) I_ T in(){T x;std::cin>>x;return x;}
USE1(T=int) I_ vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE1(T) vec<T> ndvec(T v,int n){return vec<T>(n, v);}
USE2(T,...Ts) auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T) I_ void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts) I_ void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
I_ int re(){int x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
I_ void wr(int x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
struct IoSetup {
  IoSetup(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<setprecision(10);
    cerr<<setprecision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

ll digitsum(ll b, ll n) {
  ll tot = 0;
  while (n) {
    tot += n % b;
    n /= b;
  }
  return tot;
}

signed main() {
  ll N = in<ll>(), S = in<ll>();
  if (N == S) {
    pr(N + 1);
    return 0;
  }
  for (ll b = 2; b < 1000000; b++) {
    if (digitsum(b, N) == S) {
      pr(b);
      return 0;
    }
  }
  ll ans = infll;
  for (ll p = 1; p < 1000000; p++) {
    ll b = (N - S) / p + 1;
    if (b < 2) continue;
    if (p + N % b == S) { chmin(ans, b); }
  }
  if (ans == infll) {
    pr(-1);
  } else {
    pr(ans);
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

signed main(void) {
	int i, j, k, l;
	string s[3];
	rep(i, 3) cin >> s[i];

	rep(i, 3) reverse(ALL(s[i]));
	int cur_turn = 0;
	while (1) {
		if (s[cur_turn].size() == 0) {
			cout << (char)('A' + cur_turn) << endl;
			return 0;
		}
		char c = s[cur_turn][s[cur_turn].size()-1];
		s[cur_turn].pop_back();
		cur_turn = c - 'a';
	}

	return 0;
}

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

int main() {
    
    long long int num,x=7,i=1,flag=0;
    cin>>num;
    
    if (num==1 || num==7){
    	cout<<1<<endl;
    	return 0;
	}
    if (num%2==0){
    	cout<<-1<<endl;
    	return 0;
	}
    for(i=1;i<=num;i++){
    	if (x%num==0){
    		cout<<i<<endl;
    		flag=1;
    		break;
		}
    	x=(x*10+7)%num;
	}
	if (flag==0){
		cout<<-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 3632
from collections import deque

INF = 10 ** 5
direct1 = ((-1, 0), (1, 0), (0, -1), (0, 1), (1, -1), (1, 1))
direct2 = ((-1, -1), (0, -1), (1, 0), (0, 1), (-1, 1), (-1, 0))

def search(p, mp):
  que = deque()
  que.append((0, p))
  visited = [[False] * (m + 2) for _ in range(n + 2)]
  visited[p[1]][p[0]] = True
  mp[p[1]][p[0]] = 0
  while que:
    dist, point = que.popleft()
    px, py = point
    if py % 2 == 0:
      direct = direct1
    else:
      direct = direct2
    for dx, dy in direct:
      nx, ny = px + dx, py + dy
      if not visited[ny][nx] and mp[ny][nx] != -1:
        visited[ny][nx] = True
        if mp[ny][nx] > dist + 1:
          mp[ny][nx] = dist + 1
        que.append((dist + 1, (nx, ny)))

def count(p, mp):
  que = deque()
  que.append((0, p))
  visited = [[False] * (m + 2) for _ in range(n + 2)]
  visited[p[1]][p[0]] = True
  ans = 1
  while que:
    dist, point = que.popleft()
    px, py = point
    if py % 2 == 0:
      direct = direct1
    else:
      direct = direct2
    for dx, dy in direct:
      nx, ny = px + dx, py + dy
      if not visited[ny][nx] and mp[ny][nx] != -1:
        visited[ny][nx] = True
        if mp[ny][nx] > dist + 1:
          ans += 1
        que.append((dist + 1, (nx, ny)))
  return ans


while True:
  m, n = map(int, input().split())
  if m == 0:
    break

  mp = [[-1] + [INF] * m + [-1] for _ in range(n)] 
  mp.insert(0, [-1] * (m + 2))
  mp.append([-1] * (m + 2))
  
  s = int(input())
  for _ in range(s):
    x, y = map(int, input().split())
    search((x, y), mp)
  
  ans = 0
  t = int(input())
  for _ in range(t):
    x, y = map(int, input().split())
    z = count((x, y), mp)
    ans = max(ans, z)
  
  print(ans)


Measured memory_bytes: 6080
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  string S;
  cin >> S;
  int ans = 0;
  map<string, int> anss = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1}
  };
  cout << anss.at(S) << endl;

  return 0;
}


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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int A, B, C;
	cin >> A >> B >> C;
	int f = 0, s = 0;
	(A == 5 ? f++ : s++);
	(B == 5 ? f++ : s++);
	(C == 5 ? f++ : s++);
	(f == 2 && s == 1 ? cout << "YES" : cout << "NO");
	return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

class ModInt():
    def __init__(self, n):
        self.n = n

    def __add__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n+x) % mod)

    def __sub__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n-x) % mod)

    def __mul__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n*x) % mod)

    def __truediv__(self, x):
        x = ModInt.xn(x)
        return ModInt(self.n * pow(x, mod-2, mod) % mod)

    @classmethod
    def xn(cls, x):
        if isinstance(x, ModInt):
            return x.n
        return x

    def __str__(self):
        return str(self.n)

def M(n): return ModInt(n)

class RollingHash():
    def __init__(self, s):
        self.N = n = len(s)
        a = [ord(c) for c in s]
        self.A1 = a1 = [M(a[0])]
        self.A2 = a2 = [M(a[0])]
        for c in a[1:]:
            a1.append(a1[-1] * 997 + c)
            a2.append(a2[-1] * 991 + c)

    def get(self, l, r):
        if l == 0:
            return (self.A1[r].n, self.A2[r].n)
        t1 = (self.A1[r] - self.A1[l-1] * pow(997, r-l+1, mod)).n
        t2 = (self.A2[r] - self.A2[l-1] * pow(991, r-l+1, mod)).n
        return (t1, t2)

def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n = I()
    s = S()
    rh = RollingHash(s)

    def f(i):
        s = set()
        for j in range(i,n-i+1):
            t = rh.get(j-i,j-1)
            s.add(t)
            k = rh.get(j,j+i-1)
            if k in s:
                return True
        return False

    r = bs(f,1, n)

    return r - 1


print(main())





Measured memory_bytes: 8468
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll a, b, c, x, y, ans = 0;
  cin >> a >> b >> c >> x >> y;
  if (a > 2 * c) a = 2 * c;
  if (b > 2 * c) b = 2 * c;
  ll lowerPrice = min(a + b, 2 * c);
  ll lessPizza = min(x, y);
  ll morePizza = max(x, y);
  ans += lowerPrice * lessPizza;
  if (lessPizza == x) ans += b * (morePizza - lessPizza);
  if (lessPizza == y) ans += a * (morePizza - lessPizza);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
int A[N], B[N];
V<int> v;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n) cin >> A[i];
  FOR(i, 0, n) cin >> B[i];
  ll s = 0;
  int ans = 0;
  FOR(i, 0, n){
    if(A[i] < B[i]){
      s += B[i]-A[i];
      ans++;
    }else{
      v.pb(A[i]-B[i]);
    }
  }
  sort(all(v));
  int idx = sz(v)-1;
  while(s > 0){
    if(idx < 0){
      cout << -1 << endl;
      return 0;
    }
    s -= v[idx];
    ans++;
    idx--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1660
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n;
ll a[100111],b[100111];
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)getii(a[i],b[i]);
	ll dlt=0;
	for(int i=n;i>=1;i--)
	{
		a[i]+=dlt;
		dlt+=(a[i]+b[i]-1)/b[i]*b[i]-a[i];
	}
	cout<<dlt<<endl;
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    long long res = 0;
    vector<long long> sums(N);
    for (int i = 0; i < N; i++) {
        long long a, b;
        cin >> a >> b;
        res += b;
        sums[i] = a + b;
    }

    sort(sums.begin(), sums.end(), greater<long long>());
    res = -res;

    for (int i = 0; i < N; i += 2) {
        res += sums[i];
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <assert.h>
#include <queue>
#include <string.h>
#include <string>
#include <set>
#include <memory.h>
#include <functional>
#include <bitset>
using namespace std;
#define ll long long

const int N = 4005;
const int mod = 998244353;
int combi[N][N],two[N];
int add(int x,int y) {
    int ret = x+y;
    while(ret-mod>=0) {
        ret -= mod;
    }
    return ret;
}
int mul(int x,int y) {
    return (ll)x*y%mod;
}
void init() {
    for(int i=0;i<N;++i) {
        combi[i][0] = combi[i][i] = 1;
        for(int j = 1;j<i;++j) {
            combi[i][j] = add(combi[i-1][j],combi[i-1][j-1]);
        }
        if(i==0) {
            two[i] = 1;
        } else {
            two[i] = mul(two[i-1],2);
        }
    }
}

void solve() {
    init();
    int k,n;
    scanf("%d %d",&k,&n);
    for(int i=2;i<=k*2;++i) {
        int special = 0;
        int u = (i-1)/2;
        for(int j=1;j<=u;++j) {
            if(i-j<=k) {
                ++special;
            }
        }
        int ret = 0;
        int normal = k - special*2;
        if(i%2==0) {
            --normal;
        }
        for(int j = 0;j<=min(n,special);++j) {
            // 현재 n-j 개가 있다 이 중에서 현재 special 개 중에서 j개를 뽑을거임.
            //그리고 n-j 개를 normal 개에게 배치하는 경우의 수는 combi(n-j + normal -1,normal-1)
            int tmp = mul(two[j],mul(combi[n-j+normal+j-1][normal+j-1], combi[special][j]));
            ret = add(ret,tmp);
        }
        if(i%2==0) {
            for(int j = 0;j<=min(n-1,special);++j) {
                int tmp = mul(two[j],mul(combi[n-j+normal-2 + j][normal-1+j], combi[special][j]));
                ret = add(ret,tmp);
            }
        }
        printf("%d\n",ret);
    }
}

int main() {
    //freopen("/Users/gotop/Documents/ps_practice/ps_practice/input.txt", "r", stdin);
    solve();
}


Measured memory_bytes: 61440
def main():
    N = int(input())
    A_list = list(map(int, input().split()))
    mod = 10**9 + 7

    ans = 0
    A_ = sum(A_list) % mod
    for i in range(N-1):
        A = A_list[i]
        A_ = A_ - A
        ans = (ans + (A * A_) % mod) % mod
    print(ans)
    return


if __name__ == '__main__':
    main()
    

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

int main(){
  int N;cin>>N;
  int ans=0;
  bool ncan=true;
  while(ncan){
    ans++;
    if(ans*108/100==N) ncan=false;
    if(ans==50000) break;
  }
  if(ncan) cout<<":("<<endl;
  else cout<<ans<<endl;
}
  


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

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < 2; i++)
    {
        if (s[i] != s[i+1]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::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;};

int d[30];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int W, N;
	scanf("%lld%lld", &W, &N);
	rep(i, W) d[i] = i + 1;
	rep(i, N) {
		int a, b;
		scanf("%lld,%lld", &a, &b);
		a--; b--;
		swap(d[a], d[b]);
	}

	rep(i, W) cout << d[i] << endl;
	return 0;
}


Measured memory_bytes: 3184
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int color[N],d[N],f[N],tt;
int n,M[N][N];

 
void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++)
  {
    if(M[u][v]==0) continue;
    if(color[v]==WHITE) dfs_visit(v);
  }
  color[u]=BLACK;
  f[u]=++tt;
}
 
void dfs()
{
  int u;
  for(u=0;u<n;u++) color[u]=WHITE;
  tt=0;
 
  for(u=0;u<n;u++)
  {
    if(color[u]==WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++)
  {
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
 
int main()
{
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    for(j=0;j<n;j++) M[i][j]=0;
  }
  for(i=0;i<n;i++)
  {
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++)
    {
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
 
  return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for (int i = 0; i < M; i++)
        cin >> X[i];
    sort(X.begin(), X.end());

    vector<int> v(M - 1);
    for (int i = 0; i < M - 1; i++)
        v[i] = X[i + 1] - X[i];
    sort(v.begin(), v.end());

    int res = 0;
    for (int i = 0; i < M - N; i++)
        res += v[i];

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
const int N=1e5+10;
int n,m,r,s,p,ans;
char a[N],f[N];
int main()
{
	scanf("%d%d%d%d%d%s",&n,&m,&r,&s,&p,a+1);
	for(int i=1;i<=m;i++)
		if(a[i]=='r')
		{
			f[i]='p';
			ans+=p;
		}
		else if(a[i]=='s')
		{
			f[i]='r';
			ans+=r;
		}
		else
		{
			f[i]='s';
			ans+=s;
		}
	for(int i=m+1;i<=n;i++)
		if(a[i]=='r')
		{
			if(f[i-m]=='p')continue;
			f[i]='p';
			ans+=p;
		}
		else if(a[i]=='s')
		{
			if(f[i-m]=='r')continue;
			f[i]='r';
			ans+=r;
		}
		else
		{
			if(f[i-m]=='s')continue;
			f[i]='s';
			ans+=s;
		}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
// ABC 065 B- Trained?
// 配列の練習

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

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

  // とりあえず格納
  vector<int> vec(N);
  rep(i, N) {
    cin >> vec.at(i);
  }
  // N回だめだったらなんかいやっても２にならない
  int n = 1, count = 0;
  rep(i, N) {
    n = vec.at(n-1);
    count++;
    if (n == 2) {
      break;
    }
  }
  // 光っているかの判断
  if (count < N) {
    cout << count << endl;
  }
  else {
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 3784
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
$c = array_count_values($a);
$x = 0;
foreach ($c as $k => $v) {
	if ($k == $v) continue;
	if ($k < $v) {
		$x += $v - $k;
	} else {
		$x += $v;
	}
}
echo $x;

Measured memory_bytes: 19188
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        long X = sc.nextLong();
        long K = sc.nextLong();
        long D = sc.nextLong();
        BigInteger[] B = new BigInteger[4];
        B[0] = BigInteger.ZERO;
        B[1] = BigInteger.valueOf(K);
        BigInteger[] divideAndRemain = BigInteger.valueOf(X).add(BigInteger.valueOf(K).multiply(BigInteger.valueOf(D))).divideAndRemainder(BigInteger.valueOf(2L * D));
        B[2] = divideAndRemain[0];
        B[3] = B[2].add(BigInteger.ONE);
        BigInteger result = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(Long.MAX_VALUE));
        for (int i = 0; i < B.length; i++) {
            if (B[i].compareTo(BigInteger.valueOf(K)) > 0 || B[i].compareTo(BigInteger.ZERO) < 0) {
                continue;
            }
            BigInteger candidate = BigInteger.valueOf(X).add(BigInteger.valueOf(K).subtract(BigInteger.valueOf(2L).multiply(B[i])).multiply(BigInteger.valueOf(D)));
            if (candidate.abs().compareTo(result.abs()) < 0) {
                result = candidate;
//                System.out.println(B[i]);
            }
        }
        pw.println(result.abs());
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


Measured memory_bytes: 36048
#include <bits/stdc++.h>
#define MAX_V 100000
using namespace std;

int V;                //????????°
vector<int> G[MAX_V]; //??°???????????£??\??????????????¨???
int ord[MAX_V];       //???????????????
int parent[MAX_V];    //???
int low[MAX_V];       //
set<int> AP;          //??¢?????? 

void dfs(int u,int p,int &c){

  ord[u] = low[u] = c++;
  for(int i=0; i<G[u].size(); i++){
    int v=G[u][i];
    if(ord[v] == -1){
      parent[v] = u;
      dfs(v, u, c);
      low[u] = min(low[u], low[v]);
    } 
    else if(v != p) low[u] = min(low[u], ord[v]);
  }
}

void art_points(){
  memset(ord,-1,sizeof(ord));
  int c=1;
  dfs(0, -1, c);

  int np=0;
  for(int i=1; i<V ;i++){
    int p = parent[i];
    if(p == 0 ) np++;
    else if(ord[p] <= low[i]) AP.insert(p);
  }
  if(np > 1) AP.insert(0);
}


int main(){
  int E;
  cin>>V>>E;
  for(int i=0;i<E;i++){
    int s,t;
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  art_points();
  set<int>::iterator it=AP.begin();
  while(it!=AP.end())cout<<*(it++)<<endl;

  return 0;
}

Measured memory_bytes: 7320
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vl p(n);
	rep(i, n) cin >> p[i];
	
	int ans = 0;
	Rep(bit, (1 << n)) {
		ll m = 1;

		rep(i, n) {
			if (bit & (1 << i)) m = LCM(m, p[i]);
		}

		bool flg = true;

		rep(i, n) {
			if (!(bit & (1 << i)) && m % p[i] == 0) flg = false;
		}

		if (flg) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3092
A,B,C,X,Y=map(int,input().split())
 
if A+B>2*C:
  if X>Y:
    print(min(A*abs(X-Y)+ min(X,Y)*C*2, max(X,Y)*C*2))
  else:
    print(min(B*abs(X-Y)+ min(X,Y)*C*2, max(X,Y)*C*2))
else:
  print(A*X+B*Y)

Measured memory_bytes: 9080
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var HList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var output = 0;
            var h = 0;
            foreach (var H in HList)
            {
                if (H >= h)
                {
                    output++;
                }

                h = Math.Max(H, h);
            }

            Console.Write(output);
        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
typedef vector<vector<int>> Graph;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
vector<LL> make_divisors(LL n){vector<LL> divisors;for(int i = 1; i <= sqrt(n); i++) {if(n%i == 0){divisors.push_back(i);if(i != n/i){divisors.push_back(n / i);}}}return divisors;}
const LL MOD = 1e9 + 7;
const int INF = 1 << 30;
const LL LLINF = 1LL << 60;
using namespace std;


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

    if(A > 9 or B > 9)
        cout << -1 << endl;
    else
        cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = N
while True:
    ans = str(ans)
    for num in D:
        if ans.find((str(num))) != -1:
            break
    else:
        break
    ans = int(ans) + 1

print(ans)


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

int main() {
  string str;
  cin >> str;
  long long ans=0;

  for(int i=0;i<(1<<(str.size()-1));i++){
    string now="";
    now+=str[0];
    for(int j=0;j<str.size()-1;j++){
      if(i&(1<<j)){
        now+="+";
      }
      now+=str[j+1];
    }
    //cout<<now<<endl;

    long long sum=0;
    int pos=0;

    while(now.find("+",pos)!=string::npos){
      int nextpos=now.find("+",pos);
      //cout<<now.substr(pos,nextpos-pos)<<endl;
      sum += stoll(now.substr(pos,nextpos-pos));
      pos=nextpos+1;
    }
    sum+=stoll(now.substr(pos));
    ans+=sum;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3548
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    for(int i = 0; i < n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }

    int px = 0, py = 0;
    for(int i = 0; i < n; i++){
        int tmp;
        if(i == 0){
           tmp = t[i] - abs(px - x[i]) - abs(py - y[i]); 
        }
        else{
            tmp = (t[i]- t[i - 1]) - abs(px - x[i]) - abs(py - y[i]);
        }
        //int tmp = (t[i + 1]- t[i]) - abs(px - x[i]) - abs(py - y[i]);
        //cout << "tmp:" << tmp << endl;
        if(tmp >= 0 && tmp % 2 == 0){
            px = x[i];
            py = y[i];
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1408
taro=0
hanako=0
time=int(input())
for i in range(time):
    lst=input().split()
    if lst[0]==lst[1]:
        taro+=1
        hanako+=1
    #card_t=lst[0]
    #card_h=lst[1]
    else:
        sort_lst=sorted(lst)
        if lst[0]==sort_lst[1]:
            taro+=3
        elif lst[1]==sort_lst[1]:
            hanako+=3
print(taro,hanako)
            
        
    


Measured memory_bytes: 5592