akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct UnionFind{
  vector<ll> par;
  vector<ll> rank;
  vector<ll> sizes;

  UnionFind(ll n){
    init(n);
  }

  void init(ll n){
    par.resize(n);
    rank.resize(n);
    sizes.resize(n);
    REP(i,n){
      par[i] = i;
      rank[i] = 0;
      sizes[i] = 1;
    }
  }

  ll find(ll x){
    if(par[x] == x){
      return x;
    }else{
      return par[x] = find(par[x]);
    }
  }

  void unite(ll x, ll y){
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(rank[x]<rank[y]){
      par[x] = y;
      sizes[y] += sizes[x];
    }else{
      par[y] = x;
      sizes[x] += sizes[y];
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

  bool same(ll x, ll y){
    return find(x)==find(y);
  }

  ll size(ll x){
    return sizes[find(x)];
  }
};

int main(){
  int n,m; cin >> n >> m;
  UnionFind uf(n);
  REP(i,m){
    int x,y,z;
    cin >> x >> y >> z;
    uf.unite(x-1,y-1);
  }
  set<ll> st;
  REP(i,n){
    st.insert(uf.find(i));
  }
  cout << st.size() << endl;
  return 0;
}


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

signed main() {
    string S; cin >> S;
    int N = S.size();
    if(N < 4) {
        cout << "No" << '\n';
        return 0;
    }
    cout << (S.substr(0, 4) == "YAKI" ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		int ans = 0;
		for(int i = 0 ; i < n ; i++) ans += a[i];
		Arrays.sort(a);
		for(int i = 0 ; i < n ; i++) {
			if(ans % 10 == 0) {
				for(int j = i ; j < n ; j++) {
					if((ans - a[j]) % 10 == 0) {
						continue;
					} else {
						ans -= a[j];
						break;
					}
				}
			} else {
				break;
			}
		}
		if(ans % 10 == 0) {
			System.out.println(0);
			return;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
def main():
    length = int(input())
    numbers = list(map(int, input().split()))
    count = [0] * 10 ** 5
    for num in numbers:
        count[num] += 1
    answer = 0
    for i in range(10 ** 5):
        answer = max(answer, sum(count[i:i + 3]))
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14004
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE     ;
#define dumpV(v);
#define STOP     ;
#endif
// #define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


ll SQ(ll x) {
    return x * x;
}

int main(){
    int n, k;
    cin >> n >> k;
    vl t(n), d(n);
    rep(i, n) cin >> t[i] >> d[i];

    using P = pair<ll, ll>;
    vector<P> v(n);
    rep(i, n) v[i] = P{t[i], d[i]};
    sort(all(v), [&](P a, P b) {return a.se > b.se;});
    priority_queue<ll,vector<ll>,greater<ll> > q;
    map<ll, ll> mp;
    ll tmp = 0LL;
    rep(i, k) {
        auto a = v[i].fi, b = v[i].se;
        tmp += b;
        if(mp.count(a)) {
            if(b > mp[a]) {
                q.push(mp[a]);
                mp[a] = b;
            }
            else q.push(b);
        }
        else mp[a] = b;
        dump(make_pair(a, b));
        dump(tmp);
    }
    ll ans = tmp + SQ(mp.size());
    dump(ans);
    REP(i, k, n) {
        if(q.empty()) break;
        auto a = v[i].fi, b = v[i].se;
        dump(make_pair(a, b));
        if(mp.count(a)) continue;
        tmp -= q.top();
        tmp += b;
        q.pop();
        mp[a] = b;
        ans = max(ans, tmp + SQ(mp.size()));
        dump(make_pair(tmp, mp.size()));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n,m; cin>>n>>m;
	vector<pair<int,int>> vp(n);
	rep(i,n){
		cin>>vp[i].first>>vp[i].second;
	}
	vector<pair<int,int>> pp(m);
	rep(i,m){
		cin>>pp[i].first>>pp[i].second;
	}
	//for(auto x:pp) cout<<x.first<<" "<<x.second<<endl;
	
	vector<int> a(m);
	rep(i,n){
		rep(j,m){
			a[j]=abs(vp[i].first-pp[j].first)+abs(vp[i].second-pp[j].second);
		}
		//for(auto x:a) {cout<<x;} cout<<endl;
		int itmn=min_element(a.begin(),a.end())-a.begin();
		cout<<itmn+1<<endl;
	}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  string s,t;
  cin >> s >> t;
  ll ans = 0;
  rep(i,3){
    if(s[i] == t[i]) ans++;
  }
  cout << ans;
 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define loop(n) for(int i=0;i<n;++i)
typedef long long ll;
typedef vector<int> vi;
ll i,j=0;

int main(){
    int k;cin>>k;
    queue<ll> q;
    for(i=1;i<10;++i)q.push(i);
    for(i=0;i<k-1;++i){
        ll x = q.front();
        q.pop();
        if(x%10!=0)q.push(10*x+x%10-1);
        q.push(10*x+x%10);
        if(x%10!=9)q.push(10*x+x%10+1);
    }
    cout << q.front() << endl;
}


Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
wa=[a[0]]
for i in range(1,n):
    wa.append(a[i]+wa[-1])
s=sum(a)

ans=float("inf")
for i in range(n):
    ans=min(ans,abs(s-wa[i]*2))
print(ans)


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

int main(){
  int n;
  set<pair<pair<string, int>, int>> S;
  cin >> n;
  for(int i = 0; i < n; i++){
  	string s;
    int r;
    cin >> s >> r;
    S.insert({{s, -r}, i+1});
  }
  for(auto r:S) cout << r.second << "\n";
}


Measured memory_bytes: 256
def main():
    S = input()

    editorial(S)


def editorial(S):
    """
    それぞれがそれ以外のprefixにならなければ良い
    """
    l = len(S)
    idx = 0
    ok = True
    rs = S[::-1]
    r7 = "dreamer"[::-1]
    r6 = "eraser"[::-1]
    r5_1 = "dream"[::-1]
    r5_2 = "erase"[::-1]

    while idx < l:
        if rs[idx:idx + 7] == r7:
            idx += 7
        elif rs[idx:idx + 6] == r6:
            idx += 6
        elif rs[idx:idx + 5] == r5_1 or \
                rs[idx:idx + 5] == r5_2:
            idx += 5
        else:
            ok = False
            break

    if ok:
        print("YES")
    else:
        print("NO")


def RE(S):
    l = len(S)
    if _dfs(S, l, 0):
        print("YES")
    else:
        print("NO")


def _dfs(S, l, idx, pattern=0):
    # print(l, idx, pattern)
    if idx == l:
        return True

    if S[idx:idx + 7] == "dreamer":
        ok = _dfs(S, l, idx + 7, 1)
        if ok:
            return True
    if S[idx:idx + 6] == "eraser":
        ok = _dfs(S, l, idx + 6, 2)
        if ok:
            return True
    if S[idx:idx + 5] == "dream" or \
            S[idx:idx + 5] == "erase":
        ok = _dfs(S, l, idx + 5, 3)
        if ok:
            return True

    return False


def WA(S):
    l = len(S)
    idx = 0
    ok = True
    while idx < l:
        if S[idx:idx + 7] == "dreamer":
            idx += 7
        elif S[idx:idx + 6] == "eraser":
            idx += 6
        elif S[idx:idx + 5] == "dream" or \
                S[idx:idx + 5] == "erase":
            # 評価順番注意
            idx += 5
        else:
            ok = False
            break

    if ok:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,ans=__INT32_MAX__;
    string S;
    cin>>N>>S;
    vector<int> E(N+1,0);
    vector<int> W(N+1,0);
    REP(i,N){
        E[i+1]+=E[i];
        W[i+1]+=W[i];
        if(S[i]=='E')E[i+1]++;
        if(S[i]=='W')W[i+1]++;
    }
    REP(i,N){
        int tmp = W[i]+(E[N]-E[i+1]);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int a, p; cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;
}


Measured memory_bytes: 504
#include<iostream>
using namespace std;
int main()
{
	int n,d,x,i,j,a[100],sum=0;
	cin>>n>>d>>x;
    for(i=0;i<n;i++)
    {
    	cin>>a[i];
    }
   
    for(i=0;i<n;i++)
    {
    	j=0;
    	while(j*a[i]+1<=d)
    	{
    		sum++;
    		j++;
    	}
    }
    cout<<(sum+x);

}

Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
    int X ;
    scanf("%d",&X);
    if(X==3)

        printf("YES\n");



    else if(X==5)

        printf("YES\n");




    else if(X==7)

        printf("YES\n");


    else

        printf("NO\n");




    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <queue>

#pragma GCC diagnostic ignored "-Wunused-result"

using namespace std;

typedef long long LL;

void solve(long long n, long long m, std::string s) {
	LL goal = n, prev = -1;
	vector<LL> ans(1, n);
	for (LL i = n - 1; i >= 0; --i) {
		if (i + m < goal) {
			if (prev < 0) {
				cout << -1 << endl;
				return;
			}
			goal = prev;
			prev = -1;
			ans.push_back(goal);
		}
		if (s[i] == '0') {
			prev = i;
		}
	}
	ans.push_back(0);
	reverse(ans.begin(), ans.end());
	for (LL i = 1; i < (LL)ans.size(); ++i) {
		if (i > 1) {
			cout << " ";
		}
		cout << (ans[i] - ans[i - 1]);
	}
	cout << endl;
}

int main() {
    long long N;
	scanf("%lld", &N);
	long long M;
	scanf("%lld", &M);
	std::string S;
	std::cin >> S;
	solve(N, M, S);
	return 0;
}


Measured memory_bytes: 4600
import 'dart:io';
main(List<String> args) {
  int N = int.parse(stdin.readLineSync());
  String aa = '';

  int ac = 0;
  int tle = 0;
  int wa = 0;
  int re = 0;
  
  for (int i = 0; i < N; i++) {
    aa = stdin.readLineSync();
    if (aa == 'AC') { ac += 1;} 
    else if (aa == 'TLE'){ tle += 1;} 
    else if (aa == 'WA'){ wa += 1;} 
    else { re += 1;}
  }
  print('AC x ${ac}');
  print('WA x ${wa}');
  print('TLE x ${tle}');
  print('RE x ${re}');
}

Measured memory_bytes: 17208
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <stack>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define pb push_back

typedef long long ll;
using namespace std;
void komma(int& nedan,int& omosa){
  char inputl[100];
  cin>>inputl;
  rep(i,0,100){
    if(inputl[i]==',') {
      inputl[i]=0;
      nedan=atoi(inputl);
      omosa=atoi(inputl+i+1);
      break;
    }
  }
  //  cout <<nedan<<endl<<omosa<<endl;
}
int main(){

  int W,N,nedan,omosa,maxne,maxomo,count,tmp;
 
  vector<vector<int> >hukuro(1010);
  rep(i,0,1010)
    hukuro[i]=vector<int>(1010,0);
  count=0;
  cin>>W>>N;
  //cout<<"??\n";
  while(W){
    maxne=maxomo=0;
    rep(i,0,1000)
      hukuro[0][i]=0;
    komma(nedan,omosa);
    //cout<<"otto?\n";  
    hukuro[0][omosa]=nedan;
    rep(i,1,N){
    komma(nedan,omosa);
    rep(j,0,W+1){
      if(j>=omosa)
	hukuro[i][j]=max(hukuro[i-1][j],hukuro[i-1][j-omosa]+nedan);
      else hukuro[i][j]=hukuro[i-1][j];
      // cout<<i<<" "<<j<<endl<<hukuro[i][j]<<endl;
    }
    }
    for(int i=W;i>=0;i--)
      if(maxne<=hukuro[N-1][i]){
	maxne=hukuro[N-1][i];
	maxomo=i;
      }
    cout<<"Case "<<++count<<":\n"<<maxne<<endl<<maxomo<<endl;
    cin>>W>>N;
    //    cout<<"???\n";
    }

  return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

const int INF = 1000000007;
const ll MOD = 1000000007;

ll dp[3005][3005][4];
ll grid[3005][3005];
ll r, c, k;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> r >> c >> k;
    for(int i=0; i<k; i++)
    {
        int r1, c1, v1;
        cin >> r1 >> c1 >> v1;
        r1--;
        c1--;
        grid[r1][c1] = v1;
    }
    dp[0][0][1] = grid[0][0];
    for(int i=0; i<r; i++)
    {
        for(int j=0; j<c; j++)
        {
            if(grid[i][j])
            {
                for(int k=1; k<=3; k++)
                {
                    if(i)
                    {
                        ll t = 0;
                        for(int x=0; x<=3; x++)
                        {
                            t = max(t, dp[i-1][j][x]);
                        }
                        dp[i][j][k] = max(dp[i][j][k], t + grid[i][j]);
                    }
                    if(j)
                    {
                        dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k-1] + grid[i][j]);
                    }
                }
            }
            for(int k=0; k<=3; k++)
            {
                if(i)
                {
                    ll t=0;
                    for(int x=0; x<=3; x++)
                    {
                        t = max(t, dp[i-1][j][x]);
                    }
                    dp[i][j][k] = max(dp[i][j][k], t);
                }
                if(j)
                    dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k]);
            }
        }
    }
    ll ans = 0;
//    for(int i=0; i<r; i++)
//    {
//        for(int j=0; j<c; j++)
//        {
//            for(int k=0; k<4; k++)
//            {
//                cout << i << " " << j << " " << k << " " << dp[i][j][k] << "\n";
//            }
//        }
//    }
    for(int i=0; i<=3; i++)
    {
        ans = max(ans, dp[r-1][c-1][i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 355748
#include<stdio.h>
#include <stdbool.h>

int main()
{
  int n;
  scanf("%d",&n);
  
  int a[n];
  int i;
  int ans=0;
  bool b=true;
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  
  while(1)
  {
    for(i=0;i<n;i++)
    {
      if(a[i]%2!=0)
      {
        b=false;
      }
    } 
    if(b==false)
    {
      break;
    }
      
    else if(b==true)
    {
      for(i=0;i<n;i++)
      {
        a[i]/=2;
      }
      ans++;
    }
  }
  
  printf("%d\n",ans);
  
  return 0;
}
        

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <complex>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef pair<int,int> pr;
int main() {
	int N,M,p;
	while(cin >> N >> M && N){
	vector<pr> vi;
	REP(i,M)
		vi.push_back(pr(0,i+1));
	REP(i,N)
		REP(j,M){
			cin >> p;
			vi[j].first-=p;	
		}
	sort(vi.begin(),vi.end());
	REP(i,M)
		cout << vi[i].second <<((i+1==M)?"":" ");
	
	cout << endl;
	}
	// your code goes here
	return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define sz(v) (int)(v.size())
#define all(v) v.begin(),v.end()

using namespace std;

int main()
{
    //freopen("test.in","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    int x,y,z; cin>>x>>y>>z;
    cout<<z<<' '<<x<<' '<<y;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pll pair<long long,long long>
#define ll long long
#define mp make_pair
ll n,k,a,b,ans,res;
long long sz;
priority_queue<pll>q;
ll num[100003];
vector<pll>v;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>a>>b,
		q.push(mp(b,--a));
	for(int i=0;i<k;i++){
		pll now=q.top();
		q.pop();
		num[now.y]++;
		res+=now.x;
		v.push_back(mp(now.x,now.y));
		sz+=(num[now.y]==1);
	}
	ans=res+sz*sz;
	while(k--){
	    if(num[v[k].y]>1)
			while(q.size()){
				pll now=q.top();q.pop();
				if(!num[now.y])
				{
					num[now.y]++,num[v[k].y]--,
					res=res+now.x-v[k].x,
					sz++;
					if(ans<res+sz*sz)ans=res+sz*sz;
					break;
				}
			}
	}
	cout<<ans;
}


Measured memory_bytes: 6128
input_one = input().split()
i = int(input_one[0])
two = input_one[1]
count = 0

#i = int(one)

while  i <= int(two):
    
    i = str(i)
    if i[0] == i[4]:
        if i[1] == i[3]:
            count += 1

    i = int(i) + 1
print(count)

Measured memory_bytes: 3060
s = input()
if 'SSS' == s:
    print(0)
elif 'RSS' == s:
    print(1)
elif 'RRS' == s:
    print(2)
elif 'RRR' == s:
    print(3)
elif 'SSR' == s:
    print(1)
elif 'SRR' == s:
    print(2)
elif 'SRS' == s:
    print(1)
elif 'RSR' == s:
    print(1)


Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

class UnionFind {
private:
  vector<int> parent;
  vector<int> rank;

public:
  UnionFind(int size) : parent(size), rank(size, 0) {
    for (int i = 0; i < size; i++) {
      parent[i] = i;
    }
  }

  int find(int x) {
    if (parent[x] == x) {
      return x;
    } else {
      return parent[x] = find(parent[x]);
    }
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      parent[x] = y;
    } else {
      parent[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  UnionFind uf(h*w+10);
  rep(i, h) rep(j, w) rep(k, 4) {
    int ni = i+dx[k];
    int nj = j+dy[k];
    if (0 <= ni && ni < h && 0 <= nj && nj < w && s[i][j] != s[ni][nj]) {
      uf.unite(i*w + j, ni*w + nj);
    }
  }

  //rep(i, h*w) {
  //  if (i%w == 0) cerr << endl;
  //  cerr << uf.find(i) << " ";
  //}
  //cerr << endl;

  vector<ll> black(h*w+10, 0), white(h*w+10, 0);
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#') black[uf.find(i*w + j)]++;
    else white[uf.find(i*w + j)]++;
  }

  ll ans = 0;
  rep(i, h*w) {
    ans += black[i] * white[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4224
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


class SparseTable:
    """
    構築 O(NlogN)、クエリ O(1)
    """

    def __init__(self, values, fn):
        """
        :param list values:
        :param callable fn: 結合則を満たす冪等な関数。min、max など。add はだめ
        """
        self._values = values
        self._fn = fn

        # SparseTable を構築
        # self._table[i][p]: [i, i+2^p) に fn を適用した結果の値のインデックス
        self._table = self._build(values, fn)

        # self._msb[i]: 最上位ビット; どの p を見るべきか
        self._msb = [0] * (len(values) + 1)
        for i in range(2, len(values) + 1):
            self._msb[i] = self._msb[i >> 1] + 1

    @staticmethod
    def _build(values, fn):
        # AtCoder の PyPy 2.4.0 では math.log2 が使えない
        size = int(math.log(len(values), 2)) + 1

        st = [[0] * size for _ in range(len(values))]
        for i in range(len(values)):
            st[i][0] = i
        for p in range(1, size):
            for i in range(len(values)):
                q = min(i + (1 << (p - 1)), len(values) - 1)
                l = st[i][p - 1]
                r = st[q][p - 1]
                if values[l] == fn(values[l], values[r]):
                    st[i][p] = l
                else:
                    st[i][p] = r
        return st

    def get(self, a, b):
        """
        半開区間 [a, b) に fn を適用した結果
        :param int a:
        :param int b:
        """
        if b <= a:
            return None
        p = self._msb[b - a]
        return self._fn(
            self._values[self._table[a][p]],
            self._values[self._table[b - (1 << p)][p]]
        )


N, K = list(map(int, sys.stdin.readline().split()))
P = list(map(int, sys.stdin.readline().split()))

dp = [1] * N
for i in range(1, N):
    if P[i - 1] < P[i]:
        dp[i] = dp[i - 1] + 1

# 全部昇順じゃない場合の答え
ans = N - K + 1

asc_cnt = 0
st_max = SparseTable(P, max)
st_min = SparseTable(P, min)
for r in range(K, N):
    l = r - K
    if st_min.get(l, r) == P[l] and st_max.get(l + 1, r + 1) == P[r]:
        # 出ていったのが最小値で、入ってきたのが最大値のとき、変わらない
        ans -= 1
    elif dp[r] >= K:
        # すでに昇順
        ans -= 1
        asc_cnt += 1
if dp[K - 1] >= K:
    # すでに昇順
    ans -= 1
    asc_cnt += 1

if asc_cnt > 0:
    # すでに昇順のやつは一度だけ数えていい
    ans += 1
print(ans)


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

typedef double D;
D EPS = 1e-10;

struct Point {
	D x, y;
	Point() {}
	Point (D _x, D _y) : x(_x), y(_y) {}
};
typedef Point Vector;	// typedef テ」ツ?ァテ」ツδ凖」ツつッテ」ツδ暗」ツδォテ」ツ?ォテ・ツッツセテ・ツソツ?

// operator
Point operator + (const Point& a, const Point& b) { return Point(a.x+b.x, a.y+b.y); }
Point operator - (const Point& a, const Point& b) { return Point(a.x-b.x, a.y-b.y); }
Point operator * (const Point& a, const Point& b) { return Point(a.x*b.x, a.y*b.y); }
Point operator / (const Point& a, const Point& b) { return Point(a.x/b.x, a.y/b.y); }
bool operator < (const Point& a, const Point& b) { return a.x != b.x ? a.x < b.x : a.y < b.y; }
bool operator > (const Point& a, const Point& b) { return b.x != a.x ? b.x < a.x : b.y < a.y; }
bool operator == (const Point& a, const Point& b) { return fabs(a.x-b.x)<EPS && fabs(a.y-b.y)<EPS; }

// テ・ツ淞コテヲツ慊ャテァツ堋?」ツ?ェテゥツ鳴「テヲツ閉ー
D norm(const Point& a) { return sqrt(a.x*a.x + a.y*a.y); }
D dot(const Vector& a, const Vector& b) { return a.x*b.x + a.y*b.y; }	// テ・ツ??ァツゥツ?
D cross(const Vector& a, const Vector& b) { return a.x*b.y - a.y*b.x; }	// テ・ツ、ツ姪ァツゥツ?
D dist(const Point& a, const Point& b) { return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); } // ティツキツ敕ゥツ崢「
bool isVertical(const Vector& a, const Vector& b) { return fabs(dot(a,b))<EPS; }	// テ・ツ楪づァツ崢エテ・ツ按、テ・ツョツ?
bool isParrallel(const Vector& a, const Vector& b) { return fabs(cross(a,b))<EPS; } // テ・ツケツウティツ。ツ古・ツ按、テ・ツョツ?

struct Line {
	Point s, e;
	Line (Point _s, Point _e) {
		s = _s; e = _e;
	}
};

bool PointOnLine(const Point& p, const Line& l) {
	int minx = min(l.s.x, l.e.x), maxx = max(l.s.x, l.e.x);
	int miny = min(l.s.y, l.e.y), maxy = max(l.s.y, l.e.y);
	if ( !(minx <= p.x && p.x <= maxx && miny <= p.y && p.y <= maxy) ) return false;
	Vector v1 = p - l.s, v2 = l.e - l.s;
	return isParrallel(v1, v2);
}

enum { IN, ON, OUT };
int PointInTri(const vector<Point>& tri, const Point& p) {
    int cnt = 0;
    for (int i=1; i<4; i++) {
        Point p0 = tri[i-1], p1 = tri[i%3];
        bool flag0x = (p.x <= p0.x), flag0y = (p.y <= p0.y);
        bool flag1x = (p.x <= p1.x), flag1y = (p.y <= p1.y);
        
        Line p0top1(p0, p1);
        if (PointOnLine(p, p0top1)) return ON;
         
        if (flag0y != flag1y) {
            if ( flag1x && flag0x) {
                cnt += flag0y ? -1 : 1;
            } else if (p.x <= ( p0.x+(p1.x-p0.x)*(p.y-p0.y)/(p1.y-p0.y) ) ) {
                cnt += flag0y ? -1 : 1;
            }
        }
    }
    return cnt!=0 ? IN : OUT;
}
 
int main() {
    int n; cin >> n;
     
    vector<Point> tri(3);
    for (int i=0; i<n; i++) {
        cin >> tri[0].x >> tri[0].y >> tri[1].x >> tri[1].y >> tri[2].x >> tri[2].y;
        Point p1; cin >> p1.x >> p1.y;
        Point p2; cin >> p2.x >> p2.y;
        bool flag1 = (PointInTri(tri, p1) == IN), flag2 = (PointInTri(tri, p2) == IN);
        if ( flag1 != flag2 ) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
     
    return 0;
}

Measured memory_bytes: 1224
using AtCoderBeginnerContest156.Questions;
using AtCoderBeginnerContest156.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest156.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nr = inputStream.ReadIntArray();
            var n = nr[0];
            var r = nr[1];

            if (n >= 10)
            {
                yield return r;
            }
            else
            {
                yield return r + 100 * (10 - n);
            }
        }
    }
}

namespace AtCoderBeginnerContest156
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest156.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest156.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
<?php
    while($hw = trim(fgets(STDIN))){
        $hws = explode(" ", $hw);
        if($hws[0] == $hws[1] && $hws[0] == 0) break;
        $line = '';
        for($i = 0;$i < $hws[1];$i++){
            $line = $line . '#';
        }
        for($k = 0;$k < $hws[0];$k++){
            print($line . "\n");
        }
        print("\n");
    };


Measured memory_bytes: 9224
import java.util.*;
import java.lang.*;

public class Main{
  
  public static int gcd( int x,int y ){
	if( y>0 ){
		return gcd(y,x%y);
	}else{
		return x;
	}
}
  
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int ans = 0;
		for( int i=1; i<=K; i++ ){
			for( int j=1; j<=K; j++ ){
				for( int k=1; k<=K; k++ ){
					ans += gcd( i, gcd(j,k) );
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 35812
program sample
    implicit none
    character(100)::s
    character(3)::ans
    integer(8) :: i,j,m,n,max
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*)n
    read(*,*)s
    m=0
    max=0
    do i=1,n
        if(s(i:i) .eq. 'I')then
            m=m+1
            if(m>max)then
                max=m
            end if
        else
            m=m-1
        endif
    end do
    
  
    write(*,*)max
    stop
end program sample
  



Measured memory_bytes: 2752
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val b = sc.next()


  var ans = ""
  if (b == "A") {
    ans = "T"
  }
  if (b == "T") {
    ans = "A"
  }
  if (b == "C") {
    ans = "G"
  }
  if (b == "G") {
    ans = "C"
  }


  println(ans)
}


Measured memory_bytes: 36240
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    long l;
    cin >> n >> l;

    vector<vector<int>> trie;
    trie.push_back({-1, -1, 0});

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int c = 0;
        for (int j = 0; j < s.length(); j++) {
            int x = s[j] - '0';
            if (trie[c][x] == -1) {
                trie.push_back({-1, -1, trie[c][2] + 1});
                trie[c][x] = trie.size() - 1;
            }
            c = trie[c][x];
        }
    }

    long res = 0;

    for (int i = 0; i < trie.size(); i++) {
        if ((trie[i][0] == -1) ^ (trie[i][1] == -1)) {
            long x = l - trie[i][2];
            x = x ^ (x - 1);
            x = x ^ (x >> 1);
            res = res ^ x;
        }
    }

    cerr << res << "\n";

    if (res == 0) {
        cout << "Bob";
    } else {
        cout << "Alice";
    }

    return 0;
}

Measured memory_bytes: 6788
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

/**
 * C - Multiplication 3
 * A×B  の小数点以下を切り捨て、結果を整数として出力してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        BigDecimal a = sc.nextBigDecimal();
        BigDecimal b = sc.nextBigDecimal();

        // 計算
        BigDecimal product = ( a.multiply( b ) );
        // 小数第一位を切り捨て
        System.out.println( product.setScale( 0, RoundingMode.DOWN ) );

        sc.close();
    }
}

Measured memory_bytes: 37548
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<ll> abc, abmc, ambc, ambmc, mabc, mabmc, mambc, mambmc;
	rep(i, n) {
		ll x, y, z;
		cin >> x >> y >> z;
		abc.pb(x + y + z);
		abmc.pb(x + y - z);
		ambc.pb(x - y + z);
		ambmc.pb(x - y - z);
		mabc.pb(-x + y + z);
		mabmc.pb(-x + y - z);
		mambc.pb(-x - y + z);
		mambmc.pb(-x - y - z);
	}
    sort(abc.begin(),abc.end());
  sort(abmc.begin(),abmc.end());
  sort(ambc.begin(),ambc.end());
  sort(ambmc.begin(),ambmc.end());
  sort(mabc.begin(),mabc.end());
  sort(mabmc.begin(),mabmc.end());
  sort(mambc.begin(),mambc.end());
  sort(mambmc.begin(),mambmc.end());
  
  
	ll ans = 0;
	ll ansi = 0;
	rep(i, m) {
		ansi += abc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += abmc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += ambc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += ambmc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += mabc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += mabmc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += mambc[n-1-i];
	}
	ans = max(ans, ansi);


	ansi = 0;
	rep(i, m) {
		ansi += mambmc[n-1-i];
	}
	ans = max(ans, ansi);

	cout << ans << endl;
}

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

using namespace std;

int main(){
    int K, N;
    cin >> K >> N;
    vector<int> pos(N), dist(N);
    for (auto &x : pos)
    {
        cin >> x;
    }
    int max = 0;
    for (int i = 1; i <= N; i++)
    {
        int tmp;
        if (i == N )
        {
            tmp = K - pos[i-1] + pos[0];
        }
        else
        {
            tmp = pos[i] - pos[i - 1];
        }
        if (tmp>max)
        {
            max = tmp;
        }
    }

    cout << K - max << endl;
}

Measured memory_bytes: 1792
#include<iostream>

int binarySearch(int key,int S[],int n){
	int left=0;
	int right=n;
	int mid=0;
	while(left<right){
		mid=(left+right)/2;
		if(key==S[mid]){
			return 1;
		}
		if(key<S[mid]){
			right=mid;
		}else if(key>S[mid]){
			left=mid+1;
		}
	}
	return 0;
}
                      


int main(){
  int n,q,count=0;

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

  std::cin>>q;
  int T[q];
  for(int i=0;i<q;i++){
    std::cin>>T[i];
  	if(binarySearch(T[i],S,n))count++;
  }

	
/*	int flag=0,search,searchF,searchE;
  for(int k=0;k<q;k++){
  	flag=0;
  	search=n/2;
  	searchF=0;
  	searchE=n-1;
  	*/
  	/*
  	while(flag==0){
  		
  		if(S[searchF]==S[searchE]){
  			flag=1;
  		}
  		if(S[search]==T[k]){
  			count++;
  			break;
  			
  		}else if(S[search]>T[k]){
  			searchE=search-1;
  			search=(searchF+searchE)/2;
  		}else{
  			searchF=search+1;
  			search=(searchF+searchE)/2;
  		}

  	}
  	
  	
  }
	*/
  std::cout<<count<<"\n";
  return 0;
}


Measured memory_bytes: 3644
N = int(input())
l = [list(map(int, input().split())) for l in range(N)]

for i in range(len(l)-2):
    if (l[i][0]==l[i][1])&(l[i+1][0]==l[i+1][1])&(l[i+2][0]==l[i+2][1]):
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 9192
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int A, B;
	cin >> A >> B;
	OUT(max({ A + B, A - B, A*B }));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int c=0;
    string w[7]={"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"},s;
    cin>>s;
    for(int i=0;i<7;i++)
    {
        if(s==w[i]) c=0;
        c++;
    }
    cout<<c;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define method(name,res,...) function<res (__VA_ARGS__) > name = [&](__VA_ARGS__) -> res
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

vector<int> func(vector<int> line){
  int n = line.size();
  vector<int> add(n+1,0);
  rep(i,n){
    int l = max(0,i-line[i]);
    int r = min(n,i+line[i]+1);
    ++add[l];
    --add[r];
  }
  int sum = 0;
  rep(i,n){
    sum += add[i];
    line[i] = sum;
  }
  return line;
}

bool check(vector<int> line){
  int n = line.size();
  foreach(i,line){
    if(i!=n)return false;
  }
  return true;
}

int main(){
  int n = in();
  int k = in();
  vector<int> line(n);
  foreach(i,line)i=in();
  rep(i,k){
    line = func(line);
    if(check(line))break;
  }
  foreach(i,line){
    output(i);
  }
  outendl();
  return 0;
}


Measured memory_bytes: 5656
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll f(ll b,ll n){
    if(n<b) return n;
    return n%b+f(b,n/b);
}
int main(){
    ll n,s;
    cin>>n>>s;
    if(n==s){
        cout<<n+1<<endl;
        return 0;
    }
    ll p=(ll)sqrt(n);
    FOR(i,2,p+1){
        if(f(i,n)==s){
            cout<<i<<endl;
            return 0;
        }
    }
    for(ll i=p;i>0;--i){
        ll j=(n-s)/i+1;
        if(j>=2&&f(j,n)==s){
            cout<<j<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <tuple>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    int Digit(int N); //桁和
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }

    int Digit(int N){
        if(N<10){
            return N;
        }
        int r = 0;
        while (N>=10)
        {
            r += (N%10);
            N /= 10;
        }
        r += N;
        return r;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define strcin(s) string (s); cin >> (s);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    #define back_sort(a) sort(all((a)),[](const int &p,const int &q){return p > q;})
    using intv = vector<int>;
    using douv = vector<double>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
    void YN (bool b){
        if(b){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin2(h,w);
    string edge(w+2,'.');
    strv canvas(h+2,edge);
    for(int i=1;i<=h;i++){
        strcin(s);
        for(int j=0;j<w;j++){
            canvas[i][j+1] = s[j];
        }
    }
    int flag = 0,count = 0;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(canvas[i][j]=='#'){
                count++;
                if(canvas[i-1][j]=='.' && canvas[i+1][j] == '.' && canvas[i][j-1] == '.' && canvas[i][j+1] == '.'){
                    flag = 1;
                }
            }
        }
    }
    if(flag == 1){
        if(count == 1){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
ll inf = (1LL << 50);

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

vector<pint> list;


bool compare(pint l, pint r) {

	return l.second < r.second;
}




ll sosuu[100005];

ll ans[100005];



ll C[505], S[505], F[505];

int main() {
	ll N;

	cin >> N;


	rep(i, N-1)
		cin >> C[i] >> S[i] >> F[i];

	ll ans = 0;
	rep(i, N-1) {
		ans += S[i] + C[i];
		for (int j = i+1; j < N-1; j++) {
			
			if (ans >= S[j] && ans % F[j] != 0)
				ans += F[j] - ans % F[j] + C[j];


			else if (ans < S[j]) {
				ans = S[j] + C[j];
			}

			else
				ans += C[j];


		}


		cout << ans << endl;
		ans = 0;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL <class T = int> inline T IN() { T x; cin >> x; return x; }
TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> vector<T> make_v(size_t a) { return vector<T>(a); }
TPL<TNM T, TNM... Ts> auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }

TPL<TNM T> using vec2 = decltype(make_v<T>(0, 0));
TPL<TNM T> using vec3 = decltype(make_v<T>(0, 0, 0));
TPL<TNM T> using vec4 = decltype(make_v<T>(0, 0, 0, 0));
TPL<TNM T> using vec5 = decltype(make_v<T>(0, 0, 0, 0, 0));


int main(void) {
	ll N, M;
	cin >> N >> M;
	if (N > M) {
		swap(N, M);
	}
	if (N == 1) {
		if (M == 1) {
			OUT(1);
			return 0;
		}
		if (M > 2) {
			OUT(M - 2);
			return 0;
		}
	}
	if (N == 2 || M == 2) {
		OUT(0);
		return 0;
	}
	OUT((N - 2)*(M - 2));
	return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n, k;
	while(cin >> n >> k) {
		map<int, int> cnt;
		REP(i,n) {
			int a;
			cin >> a;
			cnt[a]++;
		}
		vector<int> v;
		for(auto&& e : cnt) {
			v.push_back(e.S);
		}
		sort(ALL(v));
		dpite(ALL(v));

		int hoge = 0;
		int ans = 0;
		REP(i, SZ(v)-k) {
			ans += v[i];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 10744