akhauriyash/Code-Regression huggingface dataset:
SA = list(input())
SB = list(input())
SC = list(input())
turn = "a"
for i in range(300):
    if turn == "a":
        if not SA:
            print("A")
            exit()
        turn = SA[0]
        SA.pop(0)
    elif turn == "b":
        if not SB:
            print("B")
            exit()
        turn = SB[0]
        SB.pop(0)
    else:
        if not SC:
            print("C")
            exit()
        turn = SC[0]
        SC.pop(0)

Measured memory_bytes: 8956
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF = 1e17+7;
const long long MOD = 1e9+7;
const double PI=acos(-1);

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]--;
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]==i){
			cnt++;
			if(a[i+1]==i+1)i++;
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3700
N,K = map(int,input().split())
A = [0]+list(map(int,input().split()))
dp = [False]*(N+1)
tele = 0
for i in range(10**6):
    if i==0:
        tele = 1
        dp[tele]=True
    else:
        tele = A[tele]
        if dp[tele]==True:
            finish = i
            tele1 = tele
            break
        else:
            dp[tele]=True
#print(finish)
#print(tele)
tele = 0
for i in range(10**6):
    if i == 0:
        tele = 1
        if tele == tele1:
            start = i
            break
    else:
        tele = A[tele]
        if tele == tele1:
            start = i
            break
#print(start)
loop = finish-start
if K<=start:
    ans = 1
    for i in range(K):
        ans = A[ans]
    print(ans)
else:
    ans = 1
    for i in range(start+(K-start)%loop):
        ans = A[ans]
    print(ans)

Measured memory_bytes: 99888
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>


#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

const int mod = 998244353;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};


void solution()
{
    int n,k;
    cin >> n >> k;
    vector<pair<int,int>> s(k);
    rep(i,k){
        cin >> s[i].first >> s[i].second;
    }

    vector<mint> patterns(n);
    vector<mint> patsum(n+1);
    patterns.back() = 1;
    patsum[n] = 0;
    patsum[n-1] = 1;
    for(int i = n-2; i >= 0; --i){
        if(i < n-2){
            patsum.at(i+1) = patsum.at(i+2) + patterns.at(i+1);
        }
        for(const auto& p : s){
            const int b = i + p.first;
            if(b < n){
                const int e = min(n, i + p.second + 1);
                patterns.at(i) += patsum.at(b) - patsum.at(e);
            }
        }
    }
    cout << patterns[0] << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 6344
[N,M]=list(map(int,input().split()
              )
          )
XYZ=[[int(i) for i in input().split()] for i in range(N)] 
maxabs=0

for i in range(8):
  pm=list(map(int,format(i, 'b')))
  pm=[0,]*(3-len(pm))+pm
  pm=[(-1)**item for item in pm]
  
  newXYZ=sorted([[item[0]*pm[0],item[1]*pm[1],item[2]*pm[2]] for item in XYZ],
                key=lambda x:sum(x),
                reverse=True)
  
  maxabs=max(sum([abs(sum([newXYZ[m][j] for m in range(M)]
                             )
                         ) for j in range(3)
                 ]
                ),
             maxabs
            )


print(maxabs)


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

int main(){
  string s;
  cin >> s;
  int cont = 0;
  int first = 0, last = s.length() - 1;
  while(first < last)
  {
    if (s[first] == s[last]) ++first,--last;
    else if (s[first] == 'x') ++first,++cont;
    else if (s[last] == 'x') --last,++cont;
    else {
      cont = -1;
      break;
    }
  }
  cout << cont << endl;
  return 0;
}

Measured memory_bytes: 764
from collections import *
n=int(input())
d=list(map(int,input().split()))
dc=Counter(d)
m=int(input())
t=list(map(int,input().split()))
tc=Counter(t)
s=set(d)|set(t)
for i in s:
  if dc[i]<tc[i]:
    print('NO')
    exit()
print('YES')

Measured memory_bytes: 89824
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[100100][3];

// 0: r; 1: s; 2: p;

int main(void){
	int n,k,i,j,l,c;
	ll p[3],ans=0ll;
	string t;
	cin >> n >> k;
	cin >> p[0] >> p[1] >> p[2];
	cin >> t;
	for(i=0; i<k; ++i){
		switch(t[i]){
			case 'r':
			dp[i][0] = 0ll;
			dp[i][1] = 0ll;
			dp[i][2] = p[2];
			break;
			case 's':
			dp[i][0] = p[0];
			dp[i][1] = 0ll;
			dp[i][2] = 0ll;
			break;
			case 'p':
			dp[i][0] = 0ll;
			dp[i][1] = p[1];
			dp[i][2] = 0ll;
			break;
		}
	}
	for(i=k; i<n; ++i){
		for(j=0; j<3; ++j){
			switch(t[i]){
				case 'r':
				if(j!=0){
					dp[i][0] = max(dp[i][0],dp[i-k][j]);
				}
				if(j!=1){
					dp[i][1] = max(dp[i][1],dp[i-k][j]);
				}
				if(j!=2){
					dp[i][2] = max(dp[i][2],dp[i-k][j]+p[2]);
				}
				break;
				case 's':
				if(j!=0){
					dp[i][0] = max(dp[i][0],dp[i-k][j]+p[0]);
				}
				if(j!=1){
					dp[i][1] = max(dp[i][1],dp[i-k][j]);
				}
				if(j!=2){
					dp[i][2] = max(dp[i][2],dp[i-k][j]);
				}
				break;
				case 'p':
				if(j!=0){
					dp[i][0] = max(dp[i][0],dp[i-k][j]);
				}
				if(j!=1){
					dp[i][1] = max(dp[i][1],dp[i-k][j]+p[1]);
				}
				if(j!=2){
					dp[i][2] = max(dp[i][2],dp[i-k][j]);
				}
				break;
			}
		}
	}
	for(i=n-k; i<n; ++i){
		ans += max({dp[i][0],dp[i][1],dp[i][2]});
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2816
class EightQueen
  SUCCESS = 0
  FAIL = 1
  FREE = 0
  NOT_FREE = 1
  N=8
 
  def initialize
    @row = []
    @col = Array.new(N, FREE)
    @down = Array.new(2*N-1, FREE) # x - y + (N - 1)
    @up = Array.new(2*N-1, FREE)   # x + y
    @x = Array.new(8).map { Array.new(8, false) }
 
    gets.to_i.times do
      i, j = gets.split.map &:to_i
      @x[i][j] = true
    end
  end
 
  def print_queen
    (0...N).each do |i|
      (0...N).each do |j|
        if @x[i][j] && @row[i] != j
          return FAIL
        end
      end
    end
 
    (0...N).each do |i|
      (0...N).each do |j|
        print @row[i] == j ? 'Q' : '.'
      end
      puts
    end
    return SUCCESS
  end
 
  def solve(i)
    (0..7).each do |j|
      if @col[j] == FREE && @down[i-j+(N-1)] == FREE && @up[i+j] == FREE
        @row[i] = j
        @col[j] = @down[i-j+(N-1)] = @up[i+j] = NOT_FREE
 
        if (i == 7)
          return if print_queen == SUCCESS
        else
          solve(i + 1)
        end
        @row[i] = nil
        @col[j] = @down[i-j+(N-1)] = @up[i+j] = FREE
      end
    end
  end
end
 
eq = EightQueen.new
eq.solve(0)

Measured memory_bytes: 8748
Public Class Program
  Shared Sub Main()
    Dim md1 As Integer() = Cin.IntArr()
    Dim md2 As Integer() = Cin.IntArr()
    Dim ans As String = "0"
    If md2(1) = 1 Then ans = "1"
    Console.WriteLine(ans)
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100005
using namespace std;
typedef long long ll;
struct edge{
	int k,w,next;
}e[N<<1];
int n,home[N],cnt=-1;
void add(int x,int y,int w){
	cnt++;
	e[cnt].k=y;
	e[cnt].w=w;
	e[cnt].next=home[x];
	home[x]=cnt;
}
int siz[N],g,gg;
ll ans=0;
void dfs(int k,int F){
	siz[k]=1;
	bool t=1;
	int w=-1;
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs(e[i].k,k);
		siz[k]+=siz[e[i].k];
		if(siz[e[i].k]+siz[e[i].k]>n) t=0;
		if(siz[e[i].k]*2==n) w=e[i].w;
	}
	if(t&&siz[k]+siz[k]>n){
		g=k;
		if(w>=0) gg=1;
	}
}
ll d[N];
void dfs1(int k,int F){
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		d[e[i].k]=d[k]+e[i].w;
		dfs1(e[i].k,k);
	}
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	for(int i=1,x,y,w;i<n;i++){
		scanf("%d%d%d",&x,&y,&w);
		add(x,y,w);add(y,x,w);
	}
	dfs(1,0);
	dfs1(g,0);
	ll ans=0;
	sort(d+1,d+n+1);
	for(int i=1;i<=n;i++) ans+=d[i]+d[i];
	if(!gg) ans-=d[2]+d[1];
	else for(int i=home[g];~i;i=e[i].next) if(siz[e[i].k]*2==n) ans-=e[i].w;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using ll = long long;

int main() {
    int n;
    scanf("%d", &n);

    ll arr[3*n];
    for (int i = 0; i < 3*n; i ++)
        scanf("%lld", arr+i);

    sort(arr, arr+3*n);

    ll ans = 0;
    int idx = 3*n-1;
    while (n--) {
        idx --;
        ans += arr[idx];
        idx --;
    }

    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 6120
#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    ll n, k, c = 1, t = 0;
    cin >> n >> k;
    vector<ll> a(n + 1), d(n + 1, -1);
    for (ll i = 1; i <= n; ++i) cin >> a.at(i);
    while (true) {
        if (d.at(c) >= 0) break;
        d.at(c) = t;
        if (k == t) {
            cout << c << endl;
            return 0;
        }
        ++t;
        c = a.at(c);
    }
    cout << find(d.begin(), d.end(), (k - t) % (t - d.at(c)) + d.at(c)) - d.begin() << endl;
    return 0;
}


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

int main(){
  int n,m;
  int cnt=0;
  cin>>n>>m;
  for(int i=0; i<m; i++){
    int t;
    cin>>t;
    if(t>m){
      cnt++;
    }
  }
  cout<<cnt<<endl;
}



Measured memory_bytes: 3136
import java.util.Scanner;

public class Main{

	public static void main (String[] args) {

		Main main = new Main();
		main.solve();
	}

	private void solve() {

		Scanner scanner = new Scanner (System.in);

		int height = scanner.nextInt();
		int width = scanner.nextInt();
		int heightNum = scanner.nextInt();
		int widthNum = scanner.nextInt();

		char[][] hyou = new char [height][width];

		for (int index=0; index<height; index++) {
			for (int index2=0; index2<width; index2++) {
				hyou[index][index2]='o';
			}
		}

		for (int index=0; index<heightNum; index++) {
			for (int index2=0; index2<width; index2++) {
				hyou[index][index2]='x';
			}
		}

		for (int index=0; index<widthNum; index++) {
			for (int index2=0; index2<height; index2++) {
				hyou[index2][index]='x';
			}
		}
		int count=0;

		for (int index=0; index<height; index++) {
			for (int index2=0; index2<width; index2++) {
				if (hyou[index][index2]=='o') {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

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

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

int main() {
    int N;
    int H;
    cin >> N;
    int maxHeight = 0;
    int count=0;
    rep(i,N){
        cin >> H;
        if(maxHeight <= H){
            count++;
        }
        maxHeight = max(maxHeight, H);
    }
    cout << count << endl;
}

Measured memory_bytes: 256
r = []
n  = gets.to_i
n.times { r << gets.to_i}
maxv = -2000000000
minv = r[0]
(1..n-1).each do |i|
    maxv = [maxv,r[i]-minv].max
    minv = [minv,r[i]].min
end
puts maxv


Measured memory_bytes: 8556
require 'prime'

n =  10 ** 4
table = Array.new(n+1, false)
Prime.each(n) {|prime| table[prime] = true }
ps = (1...10000).select { |i| i % 5 == 1 && table[i] }

n = gets.to_s.to_i

puts ps[0...n].join(" ")


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s; cin >> s;
    vector<int> c(s.size(), 0);
    int i = 0;
    while(i<s.size()){
        int r = 0, l = 0;
        int rp, lp;
        while(s[i]=='R'){r++; i++;}
        if(s[i]=='L'){lp = i; rp = lp-1;}
        while(s[i]=='L'){l++; i++;}
        c[rp] += (r+1)/2;
        c[lp] += r/2;
        c[lp] += (l+1)/2;
        c[rp] += l/2;
    }
    for(int i=0; i<s.size(); ++i){cout << c[i] << endl;}
    return 0;
}

Measured memory_bytes: 3812
#include<iostream>
#include<string.h>
#define ll long long
using namespace std;
int main(){
    string s1,s2,s3="";
    cin>>s1>>s2;
    ll lcs[s1.length()+1][s2.length()+1]={0};
    for (ll i = 0; i <= s1.length(); ++i)
    {
        for (ll j = 0; j <= s2.length(); ++j)
        {
            if(i==0 || j==0)
                lcs[i][j]=0;
            else if(s1[i-1]==s2[j-1])
                lcs[i][j]=1+lcs[i-1][j-1];
            else
                lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
    }
    ll i=s1.length(),j=s2.length();
    while(i>0 && j>0){
        if(s1[i-1]==s2[j-1]){
            s3+=s2[j-1];
            i--;
            j--;
        }
        else if(lcs[i-1][j]>=lcs[i][j-1])
            i--;
        else
            j--;
    }
    for ( i = s3.length()-1; i >= 0; --i)
    {
        cout<<s3[i];
    }
    return 0 ;
}

Measured memory_bytes: 70656
//
//  main.c
//  AtCoderProblems
//
//  Created by Gaska Wojtek on 2020/05/21.
//  Copyright © 2020 Gaska Wojtek. All rights reserved.
//

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

void ReadInput(char * inputString)
{
    //printf("Enter your ID: \n");
    scanf("%s", inputString);
    
    /* while (strlen(inputString) > 10)
    {
        //printf("Wrong input \n");
        ReadInput(inputString);
        if(strlen(inputString) < 10)
        {
          break;
        }
    } */
}

void CheckLength(char* firstString, char* secondString)
{
    for(int i = 0; i < strlen(firstString); i++)
    {
        if(firstString[i] != secondString[i])
        {
            printf("No \n");
            return;
        }
    }
    
    if(strlen(secondString) == (strlen(firstString) + 1))
    {
        printf("Yes \n");
    }
    else
    {
        printf("No \n");
    }
        
}

int main(int argc, const char * argv[])
{

    char *firstString = malloc(10 * sizeof(char));
    char *secondString = malloc(10 * sizeof(char));
    
    ReadInput(firstString);
    //printf("ID is already taken...\n");
    ReadInput(secondString);

    CheckLength(firstString, secondString);
    
    return 0;
}


Measured memory_bytes: 1644
from collections import deque

n,p=map(int ,input().split())
que=deque([])

for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])

t=0
while len(que)>0:
    atop=que.popleft()
    spend=min(atop[1],p)
    atop[1]-=spend
    t+=spend
    if(atop[1]==0):
        print(atop[0],t)
    else:
        que.append(atop)



Measured memory_bytes: 13272
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int,input().split()))
rate_bucket = [0] * 9
ret = 0
for a in an:
    rate_bucket[min(a//400,8)]+=1
for i in rate_bucket[0:-1:]:
    if i > 0:
        ret+=1
print("{} {}".format(max(ret,1),ret+rate_bucket[-1]))


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, K;
bool rec[110][110];

signed main() {
    while(cin >> N, N) {
        memset(rec, false, sizeof(rec));
        rep(i,0,N) {
            int M; cin >> M;
            rep(j,0,M) {
                int inp; cin >> inp; inp--;
                rec[i][inp] = true;
            }
        }
        cin >> K;
        vector<int> vs(K);
        rep(i,0,K) cin >> vs[i], vs[i]--;

        int cnt = 0, ans = -1;
        rep(i,0,N) {
            bool ok = true;
            rep(j,0,K) {
                int v = vs[j];
                if(!rec[i][v]) ok = false;
            }
            if(ok) {
                cnt++;
                ans = i+1;
                // printf("ok: %lld\n", i+1);
            }
        }
        if(cnt != 1) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
int main(void)
{
    int n,x,i,j,k,a=0,sum;
    while(1){
        scanf("%d %d",&n,&x);
        if(n==0&&x==0){
            break;
        }
        sum=0;
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                for(k=1;k<=n;k++){
                    if(i==j||j==k||i==k){

                    }
                    else{
                        a=i+j+k;
                        if(a==x){
                            sum++;
                        }
                    }
                }
            }
        }
    printf("%d\n",sum/6);
    }
    return 0;
}


Measured memory_bytes: 2100
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vvvd vector<vector<vector<double>>>


//#define int long long

using namespace std;

signed compare_ll(const void *a, const void *b)
{
	ll *A = (ll *)a;
	ll *B = (ll *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}


struct pque_t{
	int pos;
	int cost;
};

int search(int p,vvi& graph,vi& vans,vi& come){
	int i;
	int c;
	queue<pque_t> que;
	pque_t pque;

	pque.pos=p;
	pque.cost=0;
	que.push(pque);
	come[p]=1;

	while(1==1){
		pque=que.front();
		p=pque.pos;
		c=pque.cost;

		vans[c]++;
		for(i=0;i<graph[p].size();i++){
			if(come[graph[p][i]]!=0) continue;
			come[graph[p][i]]=1;
			pque.pos=graph[p][i];
			pque.cost=c+1;
			que.push(pque);
		}

		que.pop();
		if(que.empty()==1) break;
	}

	return 0;
}

signed main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	int x,y;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	vector<int> vec;
	vector<int> vtemp;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	vvi graph;
	
	//データの読み込み


	scanf("%d %d %d",&n,&x,&y);
//	scanf_s("%d %d %d",&n,&x,&y);


//	scanf("%s",&s);
//	scanf_s("%s",&s,20);


/*	//scanf("%c",&dummy);
	scanf_s("%c",&dummy);
	for(i=0;i<n;i++){
//		scanf("%c",&s[i]);
		scanf_s("%c",&s[i]);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();
	for(i=0;i<=n;i++){
		graph.push_back(vtemp);
	}


	for(i=1;i<n;i++){
		graph[i].push_back(i+1);
		graph[i+1].push_back(i);
	}
	graph[x].push_back(y);
	graph[y].push_back(x);

	vi vans(n+1,0);
	vi come(n+1,0);

	for(i=1;i<=n;i++){
		fill(come.begin(),come.end(),0);
		search(i,graph,vans,come);
	/*	printf("i=%d\n",i);
		for(j=1;j<n;j++){
			printf("%d\n",vans[j]);
		}
		printf("\n");*/
	}

	for(i=1;i<n;i++){
		printf("%d\n",vans[i]/2);
	}

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
int n,i=1;
main(){
    std::cin>>n;
    while((i*i+i)/2<n)i++;
    while(i){
        if(n-i>=0){
            std::cout<<i<<'\n';
            n-=i;
        }
        i--;
    }
}

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


int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    for (int a = 1; a<=n; a++){
        ans += (n-1)/a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    string a, b, c;
    cin >> a >> b >> c;
    if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
puts gets.scan(/(?:[0-4]|5(?![5-9]))++|(?:[5-9]|4(?![0-4]|\Z))++/).inject(0) { |j,s| d = s.each_char.map(&:to_i); j + (d[0] < 5 || d[0] == 5 && d[1].to_i < 5 ? d.inject(0, :+) : d.inject(2) { |k,x| k + 9 - x }) }


Measured memory_bytes: 83832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int R;
    cin >> R;
    double ans = R * 2 * 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
    printf("%.20f\n", ans);

    return 0;
}

Measured memory_bytes: 3768
program exception_handling
  implicit none
  integer :: n, a(200000) = 0, i, fv = 0, sv = 0, fi = -1
  read(*,*) n
  do i = 1, n
    read(*,*) a(i)
    if (fv < a(i)) then
      fv = a(i)
      fi = i
    end if
  end do
  do i = 1, n
    if (sv < a(i) .and. i /= fi) then
      sv = a(i)
    end if
  end do
  do i = 1, n
    if (i == fi) then
      write(*,'(i0)') sv
      cycle
    end if
    write(*,'(i0)') fv
  end do
  stop
end program exception_handling

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return (ans.x+m)%m;
}
int fact[N];
void calfac(int n ){
fact[0] = 1;
for(int i = 1 ; i <= n+2; i++){
 fact[i] = (((fact[i-1]%mod)*(i%mod))%mod + mod)%mod;
}
 }
int calc(int n , int r){
 if(r > n)return 0;
 if(r == n)return 1;
 int ans = 1;
 ans = ((ans%mod)*(fact[n])%mod + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[n-r] , mod)%mod) + mod)%mod;
 ans = ((ans%mod)*(mmInverse(fact[r] , mod)%mod) + mod)%mod;
 return (ans+mod)%mod;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, upto;
cin>>n>>upto;
int arr[n];
for(int i = 0 ; i  < n;i++){
	cin>>arr[i];
	arr[i] = arr[i]/2;
}
int dp[n];
for(int i = 0 ; i <  n;i++){
 int val = arr[i];
 int cnt = 0;
 while(val%2 == 0){
  val=val/2;
  cnt++;
  if(val == 0)break;
 }
 dp[i] = cnt;
}
map<int , int> m;
int odd = 0;
for(int i = 0 ; i < n ;i++){
  if(dp[i] > 0){
   m[dp[i]]++;
  }
  else{
      odd++;
  }
}
if(odd == 0 && (int)m.size() == 1){
	int lcm = arr[0];
	for(int i = 1 ; i < n; i++){
	     lcm = lcm*arr[i]/(__gcd(lcm , arr[i]));
	}
  cout<<((upto/lcm) + 1)/2<<endl;
   return 0;
}
if(m.size()){
   cout<<0<<endl;
   return 0;
}
// only odd values , 
int lcm = arr[0];
	for(int i = 1 ; i < n; i++){
	     lcm = lcm*arr[i]/(__gcd(lcm , arr[i]));
	}
   cout<<((upto/lcm) + 1)/2<<endl;
   return 0;
	
}


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

namespace Cs
{
    class Program
    {
        static void Main(string[] args)
        {
            long r = long.Parse(Console.ReadLine());
            long kos = (long)Math.Sqrt(r);
            for (long i = kos; i > 0; i--)
            {
                if(r%i==0)
                {
                    long h = r / i;
                    int keta = Math.Max((int)Math.Log10(h), (int)Math.Log10(i));

                    Console.WriteLine(keta+1);
                    return;
                }
            }


        }
    }
}


Measured memory_bytes: 11092
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]

ab = A - B


def check(t):
    cnt = 0
    bt = B * t
    for hi in h:
        r = hi - bt
        if r <= 0:
            continue
        cnt += r // ab
        if r % ab:
            cnt += 1
    return cnt <= t


left = 1
right = max(h)
while right - left > 1:
    mid = (left + right) // 2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int x, y, z; cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
  
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

    ll ans = 0;
    while(N) {
        N /= K;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

    H, W, K = map(int, input().split())
    grid = []
    for _ in range(H):
        line = input().rstrip('\n')
        grid.append([int(s) for s in line])

    ans = 10**9
    for i in range(2**(H-1)):
        tmp = 0
        h_list = [[0]]
        for j in range(H-1):
            if i >> j & 1:
                tmp += 1
                h_list.append([j+1])
            else:
                h_list[-1].append(j+1)
        L = len(h_list)
        white = [0] * L
        ok = 1
        for w in range(W):
            white_new = [0] * L
            for l in range(L):
                for h in h_list[l]:
                    if grid[h][w] == 1:
                        white_new[l] += 1
            if max(white_new) > K:
                ok = 0
            flg = 0
            for l in range(L):
                if white[l] + white_new[l] > K:
                    flg = 1
            if flg:
                tmp += 1
                white = white_new
            else:
                for l in range(L):
                    white[l] += white_new[l]
        if ok:
            ans = min(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

struct UnionFind {
    public:
    vector<int> par;
    UnionFind(int n){
        par=vector<int>(n,-1);
    }
    int root(int x){
        if(par[x]<0)return x;
    return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return false;
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};

struct Edge{
    ll from, to, cost;
    Edge(ll from, ll to,ll cost):from(from), to(to), cost(cost){}
    bool operator < (const Edge& a) const{
        return cost < a.cost;
    }
};
using Edges = vector<Edge>;
Edges E;
 
ll kruscal(ll n, Edges E){
    ll res = 0;
    sort(all(E));
    UnionFind uf(n);
    for(auto v:E) if(uf.merge(v.from, v.to)) res += v.cost; 
    return res;
}

using P = pair<ll, ll>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    V<P> xv(n), yv(n);
    REP(i, n){
        ll x, y; cin >> x >> y;
        xv[i] = {x, i};
        yv[i] = {y, i};
    }
    sort(rall(xv));
    sort(rall(yv));
    REP(i, n-1){
        E.pb({xv[i].second, xv[i+1].second, xv[i].first - xv[i+1].first});
        E.pb({yv[i].second, yv[i+1].second, yv[i].first - yv[i+1].first});
    }
    cout << kruscal(n, E) << '\n';
}

Measured memory_bytes: 16012
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    if(s[2] == s[3]){
        if(s[4] == s[5]){
            cout << "Yes" <<endl;
        }
        else cout << "No" <<endl;
    }
    else cout << "No" <<endl;



    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

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

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int hit = 0, out = 0, point = 0;
		string event;
		while( cin >> event ){
			if( event == "HIT" ){
				hit++;
				if( hit == 4 ){
					point++;
					hit--;
				}
			}else if( event == "HOMERUN" ){
				point += hit+1;
				hit = 0;
			}else if( event == "OUT" ) out++;
			
			if( out == 3 ) break;
		}
		cout << point << endl;
	}
}

Measured memory_bytes: 1212
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
s = I()
dp = [0] * (2001)
dp[3] = 1
dp[4] = 1
dp[5] = 1
for i in range(6,s+1):
    dp[i] = (dp[i-1] + dp[i-3])%mod
print(dp[s])


Measured memory_bytes: 10340
#include <iostream>

using namespace std;

int main()
{
 int n;
 cin >> n;
 for (int i = 1; i <= n; i++)
 {
  int x = i;
  if (x % 3 == 0)
  {
   cout << " " << i;
  }
  else
  {
   while(1)
   {
    if (x % 10 == 3)
    {
     cout << " " << i;
     break;
    }
    else
    {
     x /= 10;
     if (x == 0)
     {
      break;
     }
    }
   }
  }
 }
 cout << endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { printf("ERROR%d!\n",num); }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

  ll X;
  cin >> X;

  map<ll,int> Map;
  vector<ll> vec;

  ll front = 0;
  for(ll i = 0; ; i++){
    ll v = pow(i,5);
    if(i>0 && v-front>X) break;
    Map[v] = 1;
    vec.pb(v);
    front = v;
  }


  ll A=-33, ans_B=-33;
  for(ll i = 0; i < vec.size(); i++){
    ll v = vec[i];
    ll res1 = X + v;
    ll res2 = X - v;
    if(res2 < 0) res2 = res2 * (-1);
    
    if(Map[res1]==1){
        A = res1;
        ans_B = i;
        //cout << "B1 " << ans_B << endl;
        break;
    }
    else if(Map[res2]==1){
        A = res2; 
        ans_B = -(i);
        //cout << "B2 " << ans_B << endl;
        break;
    }
  } 

  //cout << A << endl;
  for(ll i = 0; i < vec.size(); i++){
    if(vec[i] == A){
        cout << i << " ";
        break;
    }
  }
  cout << ans_B << endl;
    
}


Measured memory_bytes: 4104
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

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

    int ans = 0;
    for(int i=0; i<n; ++i){
        cout << "lst " << i << endl;
        int k;
        cin >> k;
        vector<int> v(k);
        for(int j=0; j<k; ++j)
            cin >> v[j];
        ans += k * (k - 1);
    }
    cout << "ans " << ans << endl;

    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll a,b,n;cin>>a>>b>>n;
    ll q=min(n,b-1);
    cout<<((a*q)/b)-a*(q/b)<<endl;
    
    return 0;
}


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

#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int T = 1e5 + 3;
vector<ll> g[T];

int main() {
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    for(int i = 0; i < n; i++) {
        int a,b; cin >> a >> b;
        if(a <= m) g[a].pb(b);
    }

    ll ans = 0;
    priority_queue<ll, vector<ll> > pq;

    for(int i = 0; i <= m; i++) {
        for(int j = 0; j < g[i].size(); j++) pq.push(g[i][j]);
        if(pq.size()) ans += pq.top(), pq.pop();
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5760
N, M, C = map(int, input().split())
Bi = list(map(int, input().split()))
count = 0
for i in range(N):
    Ai = list(map(int, input().split()))
    t = C
    for i in range(M):
        t += Ai[i] * Bi[i]
    if t > 0:
        count += 1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<algorithm>
#include<utility>
#include<sstream>
using namespace std;
int main(){
	int a, b;cin >> a >> b;string s,t;
	ostringstream ss;
	ostringstream st;ss << a; st << b;
	for (int i = 0;i < a;i++) s += st.str();
	for (int i = 0;i < b;i++) t += ss.str();
	if (s <= t)
		cout << s << endl;
	else
		cout << t << endl;
}

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

int main(){

 int n,p[30],ans=0;
  
  cin>>n;
  
  for(int i=0;i<n;i++){
  cin>>p[i];
  }
  
  for(int j=1;j<n-1;j++){
   if(p[j]>p[j-1]&&p[j+1]>p[j]||
     		p[j]<p[j-1]&&p[j+1]<p[j]){
   ans++;
   }
  }
  cout<<ans;
}

Measured memory_bytes: 256
s = str(input())
start = 0
end = 0
#for i in range(len(s)):
#    if s[i]=='A' and start==0:
#        start = i
#    if s[-(i+1)]=='Z' and end==0:
#        end = len(s)-i
#    if start != 0 and end != 0:
#        break
for i in range(len(s)):
    if s[i]=='A':
        start = i
        break
for i in range(len(s)):
    if s[i]=='Z':
        end = i
print(end-start+1)

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

int main(){
  int k,n,i,a,ans=0;
  cin >> n >> k;
  int count[n]={0};
  for(int i=0;i<n;i++){
    cin >> a;
    count[a]++;
  }
  sort(count,count+n);
  for(i=0;i<k;i++){
    ans+=count[n-1-i];
  }
  cout << n-ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using L = long long;

struct Tree {
	int size = 1;
	vector<L> tree;

	Tree(int n) {
		while(size < n)
			size *= 2;
		tree.resize(size * 2);
	}

	void set(int pos, L val) {
		tree[pos += size] = val;
		while(pos >>= 1)
			tree[pos] = max(tree[pos * 2], tree[pos * 2 + 1]);
	}

	L get(int l, int r) {
		L ans = max(tree[l += size], tree[r += size]);
		while(l / 2 != r / 2) {
			if(~l & 1)
				ans = max(ans, tree[l ^ 1]);
			if(r & 1)
				ans = max(ans, tree[r ^ 1]);
			l >>= 1;
			r >>= 1;
		}
		return ans;
	}
};

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

	int n;
	cin >> n;
	vector<int> h(n), a(n);
	for(int &hi : h)
		cin >> hi;
	for(int &ai : a)
		cin >> ai;

	Tree dp(n + 1);

	for(int i = 0; i < n; ++i)
		dp.set(h[i], dp.get(0, h[i] - 1) + a[i]);

	cout << dp.get(1, n) << '\n';
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

constexpr int max_n = 18;

int N;
int t[max_n][max_n];

void solve(){
    rep(i,N) rep(j,N+1) cin >> t[i][j];

    vi dp(1<<N,INF);
    dp[0] = 0;
    for(int state=0;state<(1<<N);state++){
        for(int i=0;i<N;i++){   // try stage i
            if(state & (1<<i)) continue;    // already cleared
            int nxt = state | (1<<i);
            chmin(dp[nxt],dp[state]+t[i][0]);
            for(int j=0;j<N;j++){ // use item j
                int cost = t[i][j+1];
                if(state & (1<<j)){         // stage j is cleared
                    chmin(dp[nxt],dp[state]+cost);
                }
            }
        }
    }
    cout << dp[(1<<N)-1] << endl;
}

int main(){
    while(1){
        cin >> N;
        if(N==0) break;
        solve();
    }
}

Measured memory_bytes: 3324
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(3 <= n && n <= 10000){
		int x;
		
		for(x = 3; x <= n; x++){
			
			int y = x;
			int z = 0;
			
			if(0 == y % 3){
				System.out.print(" " + x);
				z++;
			}
			
			else 
			{
				while(z == 0)
				{
					if(3 == y % 10)
					{
						System.out.print(" " + x);
						z++;
					}
					y = y / 10;
					if(y < 3){
						z++;
					}
				}
			}
	  }
		System.out.println("");
    }
	}		
}

Measured memory_bytes: 28860
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            res += a[i] * a[j];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxs 2020202
#define ll long long
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;
int ans[200];
string s1,s2;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        fill(ans,ans+100,INT_MAX);
        int b[130];
        for(int i=1;i<=n;i++){
            cin>>s1;
            mme(b,0);
            int id,sz = s1.size();
            for(int j=0;j<sz;j++){
                id =s1[j]-'a';
                b[id]++;
            }
            for(int k=0;k<26;k++){
                ans[k]=min(ans[k],b[k]);
            }
        }

        for(int i=0;i<26;i++){
            for(int k=0;k<ans[i];k++){
                char c=(i+'a');
                printf("%c",c);
            }
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 256