akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define ll long long
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    ll n,w;
    cin>>n>>w;
    vector<vector<ll>> knapsack(n);
    ll temp;
    ll total = 0;
    for(ll i=0; i<n; ++i)
    {
        cin>>temp;
        knapsack[i].push_back(temp);
        cin>>temp;
        total += temp;
        knapsack[i].push_back(temp);

    }

    vector<ll> *ptr1 = new vector<ll> (total+1, 1000000000+1);
    vector<ll> *ptr2 = new vector<ll> (total+1, 1000000000+1);

    sort(knapsack.begin(), knapsack.end());
    (*ptr1)[0] = 0;
    for(ll i=0; i<n; ++i)
    {
        (*ptr2)[0] = 0;
        for(ll j=1; j<=total; ++j)
        {
            if(knapsack[i][1] <= j)
            {
                if((*ptr1)[j-knapsack[i][1]] != 1000000000+1)
                {
                    (*ptr2)[j] = min((*ptr1)[j], knapsack[i][0] + (*ptr1)[j-knapsack[i][1]]);
                }
                else
                {
                    (*ptr2)[j] = (*ptr1)[j];
                }

            }
            else
            {
                (*ptr2)[j] = (*ptr1)[j];
            }
        }
        if(i != n-1)
        {
            vector<ll> *temp = ptr1;
            ptr1 = ptr2;
            ptr2 = temp;
        }
    }
    ll ans = 0;
    for(ll i=0; i<=total; ++i)
    {
        //cout<<(*ptr2)[i]<<endl;
        if((*ptr2)[i] <= w)
        {
            ans = i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
N,Q = map(int,input().split(' '))
S = input()

lr = []
for _ in range(Q):
    lr.append(list(map(int,input().split(' '))))

#index_list = []
index_list = [0] * N
start = 0
for i in range(1,N):
    if S[i-1] == 'A' and S[i] == 'C':
        index_list[i] = index_list[i-1] + 1
    else:
        index_list[i] = index_list[i-1]

for l,r in lr:
    print(index_list[r-1] - index_list[l-1])

Measured memory_bytes: 30656
#include <iostream>
#include <vector>
#include <queue>

struct N {
    N(int i, int c) : i(i), c(c) {}
    int i, c;
};

using vi = std::vector<int>;
using vvi = std::vector<vi>;

using qN = std::queue<N>;

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

    int n; std::cin >> n;
    vvi g(n + 1);
    int a, b;
    for (int i = 0; i < n - 1; i++) {
        std::cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vi marked(n + 1);
    vi c(2);
    qN q;
    q.emplace(1, 0);
    q.emplace(n, 1);

    while (!q.empty()) {
        auto e = q.front();
        q.pop();
        if (marked[e.i]) continue;
        marked[e.i] = 1;
        c[e.c]++;
        for (auto a : g[e.i]) {
            if (!marked[a]) q.emplace(a, e.c);
        }
    }

    std::cout << (c[0] > c[1] ? "Fennec" : "Snuke") << std::endl;
}


Measured memory_bytes: 6272
n,y=map(int,input().split())
for i in range(0,n+1):
    if i*10000>y:
        break
    for j in range(0,n+1-i):
        if i*10000+j*5000>y:
            break
        k=n-i-j
        if i*10000+j*5000+k*1000==y:
            print(i,j,k)
            exit()
print(-1,-1,-1)


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int c[5][5],sum=0;
int main(){
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++){
			cin>>c[i][j];
            sum+=c[i][j];
    }
	if(c[1][1]+c[3][3]==c[1][3]+c[3][1]&&sum%3==0)
    	printf("Yes");
    else
    	printf("No");
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;

	vector<lli> d(n);
	REP(i,0,n)cin>>d[i];

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

	cout<<d[n/2]-d[n/2-1]<<endl;

	return 0;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a != b && a != c && b != c){
        cout << "No" << endl;
    }else if(a == b && b == c && a == c){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int INF = INT_MAX / 4;

int calculateDist(vector<string>& tile, int y1, int x1, int y2, int x2)
{
    int h = tile.size();
    int w = tile[0].size();
    vector<vector<int> > minDist(h, vector<int>(w, INF));

    int dy[] = {0, 0, 1, -1};
    int dx[] = {1, -1, 0, 0};

    queue<pair<int, int> > q;
    q.push(make_pair(y1, x1));
    minDist[y1][x1] = 0;
    while(!q.empty()){
        int y0 = q.front().first;
        int x0 = q.front().second;
        q.pop();
        for(int i=0; i<4; ++i){
            int y = y0 + dy[i];
            int x = x0 + dx[i];
            if(tile[y][x] != 'x' && minDist[y][x] == INF){
                minDist[y][x] = minDist[y0][x0] + 1;
                if(y == y2 && x == x2)
                    return minDist[y][x];
                q.push(make_pair(y, x));
            }
        }
    }
    return INF;
}

int solve(vector<string>& tile)
{
    int h = tile.size();
    int w = tile[0].size();

    int sy, sx;
    vector<int> y, x;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(tile[i][j] == 'o'){
                sy = i;
                sx = j;
            }
            if(tile[i][j] == '*'){
                y.push_back(i);
                x.push_back(j);
            }
        }
    }

    int n = y.size();
    vector<vector<int> > dist(n, vector<int>(n, 0));
    for(int i=0; i<n; ++i){
        for(int j=i+1; j<n; ++j){
            dist[i][j] = dist[j][i] = calculateDist(tile, y[i], x[i], y[j], x[j]);
        }
    }

    vector<vector<int> > minDist(n, vector<int>(1<<n, INF));
    for(int i=0; i<n; ++i){
        minDist[i][1<<i] = calculateDist(tile, sy, sx, y[i], x[i]);
    }
    for(int i=0; i<(1<<n); ++i){
        bitset<10> bs(i);
        for(int j=0; j<n; ++j){
            for(int k=0; k<n; ++k){
                if(bs[k])
                    continue;
                bs[k] = true;
                minDist[k][bs.to_ulong()] = min(minDist[k][bs.to_ulong()], minDist[j][i] + dist[j][k]);
                bs[k] = false;
            }
        }
    }

    int ret = INF;
    for(int i=0; i<n; ++i){
        ret = min(ret, minDist[i][(1<<n)-1]);
    }
    if(ret == INF)
        return -1;
    return ret;
}

int main()
{
    for(;;){
        int w, h;
        cin >> w >> h;
        if(w == 0)
            break;

        vector<string> tile(h+2);
        tile[0] = tile[h+1] = string(w+2, 'x');
        for(int i=1; i<=h; ++i){
            cin >> tile[i];
            tile[i] = 'x' + tile[i] + 'x';
        }
        cout << solve(tile) << endl;
    }
}

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

//#define int long long
#define X first
#define Y second
#define mp make_pair
#define pr pair
#define vc vector
#define sz(v) (int) v.size()

using namespace std;

typedef long long ll;
typedef long double ld;

signed main() {
#ifdef LOCAL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    cout << max(0, a - 2 * b) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, A[101];
//---------------------------------------------------------------------------------------------------
string solve() {
	rep(i, 0, N) if (A[i] % 2 == 0) if(A[i] % 3 != 0 && A[i] % 5 != 0) return "DENIED";
	return "APPROVED";
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	cout << solve() << endl;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define mod 1000000007
unordered_map<ll,vector<ll>> adj;
vector<ll> vis(300005,0);
vector<ll> p(100005,0);
ll c[100005];
ll cnt;
void dfs(ll node)
{
  if(vis[node])
    return;
  vis[node]=1;
  cnt++;
  for(auto i:adj[node])
    {
      dfs(i);
    }
}
ll modexpo(ll x,ll n,ll M){
    if(n==0)return 1;
    else if(n%2 == 0)return modexpo((x*x)%M,n/2,M);
    else return(x*modexpo((x*x)%M,(n-1)/2,M))%M;
}

int main()
{
  ll n;
  cin>>n;
  if(n==1)
  {
    cout<<"0";
    return 0;
  }
  ll ans=(modexpo(10,n,mod)+modexpo(8,n,mod))%mod;
  ans=(ans-modexpo(9,n,mod)+mod)%mod;
  ans=(ans-modexpo(9,n,mod)+mod)%mod;
  cout<<ans;


}


Measured memory_bytes: 6236
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
int k,x;
  cin>>k>>x;
  if(500*k>=x) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
n, k = map(int, input().split())

MOD = 10 ** 9 + 7

def calc(a):
	smallest = a * (a - 1) // 2
	largest = n * a - smallest
	return largest - smallest + 1

res = 0
for a in range(k, n + 2):
	res += calc(a)
	res %= MOD

print(res)

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

using namespace std;

//int a[100000], b[100000];
vector<int> graph[200000];
int gcol[200000];
int permutation[200000];
void labeling(int from, int v, int col);
int main() {
	
	int n;
	cin >> n;
	int i, a, b;
	for (i = 0; i < n-1; i++) {
		cin >> a >> b;
		graph[a - 1].push_back(b - 1);
		graph[b - 1].push_back(a - 1);
	}
	gcol[0] = 0;
	for (i = 0; i < graph[0].size(); i++) {
		labeling(0, graph[0][i], 1);
	}

	int counter[2] = {0, 0};

	for (i = 0; i < n; i++) {
		counter[gcol[i]]++;
	}

	int m;
	int indexm, revindex;
	if (counter[0] < counter[1]) {
		m = counter[0];
		indexm = 0;
		revindex = 1;
	}
	else {
		m = counter[1];
		indexm = 1;
		revindex = 0;
	}

	//mが3分の1以下ならばindexmの方には3を割り振る
	//mが3分の1より大きいならばindemの方に1を割り振る
	int index1 = 0;
	int index2 = 0;
	if (m <= n / 3) {
		index1 = 3;
		index2 = 1;
		for (i = 0; i < n; i++) {
			if (gcol[i] == indexm) {
				permutation[i] = index1;
				index1 = index1 + 3;
			}
			else {
				permutation[i] = index2;
				if (index2 % 3 == 1) {
					index2++;
				}
				else if (index2 % 3 == 2) {
					index2 = index2 + 2;
				}
				else {
					index2 = index2 - 3;
				}
				if (index2 > n) {
					index2 = n - (n % 3);
				}
			}
		}
	}
	else {
		index1 = 1;
		index2 = 2;
		for (i = 0; i < n; i++) {
			if (gcol[i] == indexm) {
				permutation[i] = index1;
				if (index1 % 3 == 1) {
					index1 = index1 + 3;
				}
				else {
					index1 = index1 + 3;
				}
				if (index1 > n) {
					index1 = 3;
				}

			}
			else {
				permutation[i] = index2;
				if (index2 % 3 == 2) {
					index2 = index2 + 3;
				}
				else {
					index2 = index2 - 3;
				}
				if (index2 > n) {
					index2 = n - (n % 3);
				}
			}
		}


	}

	for (i = 0; i < n; i++) {
		cout << permutation[i];
		cout << ' ';
	}
	cout << endl;
	return 0;



	//B
	/*
	int A, B, M;
	int x, y, c;
	cin >> A >> B >> M;
	int i;
	int amin = 100001, bmin = 100001, MIN = 200002;
	for (i = 0; i < A; i++) {
		cin >> a[i];
		if (a[i] < amin)amin = a[i];
	}
	
	for (i = 0; i < B; i++) {
		cin >> b[i];
		if (b[i] < bmin)bmin = b[i];
	}

	MIN = amin + bmin;

	for (i = 0; i < M; i++) {
		cin >> x >> y >> c;
		if (a[x - 1] + b[y - 1] - c < MIN)MIN = a[x - 1] + b[y - 1] - c;
	}

	cout << MIN << endl;
	return 0;
	*/

	//A
	/*
	string hi;
	cin >> hi;
	int i;
	int flag = 0;
	for (i = 0; i < hi.length(); i++) {
		if (hi[i] == 'h') {
			if (flag == 0) {
				flag = 1;
			}
			else {
				cout << "No\n";
				return 0;
			}
		}else if(hi[i] == 'i'){
			if (flag == 1) {
				flag = 0;
			}
			else {
				cout << "No\n";
				return 0;
			}
		}
		else {
			cout << "No\n";
			return 0;
		}

	}
	if (flag == 1) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
	return 0;*/

}
void labeling(int from, int v, int col) {
	int i;
	int revcol;
	gcol[v] = col;
	if (col == 0) {
		revcol = 1;
	}
	else {
		revcol = 0;
	}
	if (graph[v].size() > 1) {
		for (i = 0; i < graph[v].size(); i++) {
			if (graph[v][i] != from) {
				labeling(v, graph[v][i], revcol);
			}
		}
	}
}

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

using namespace std;

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

    vector<int> a(N);
    long long sum = 0; 
    for(int i=0; i < N; i++){
        cin >> a.at(i) ;
        sum += a.at(i);
    }

    
    string res = "Yes";
    double th = 1.0f/(4.0f * (double)M);
    double th_num = th * sum;

    sort(a.begin(),a.end(),greater<int>());


    for(int i=0;i<M;i++){
        if(th_num > a.at(i) ) {
            res = "No";
            break;
        }
    }

    cout << res << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>
 
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;
 
int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    cin>>str;
    ll r=0,g=0,b=0;
    for(i=0;i<n;i++){
        if(str[i]=='R') r++;
        if(str[i]=='G') g++;
        if(str[i]=='B') b++;
    }
    rep(i,n-2){
        for(j=i+2;j<n;j++){
            if((j-i)%2==0){
                if(str[i]=='R'){
                    if(str[j]=='B'&&str[(j+i)/2]=='G') sum--;
                    if(str[j]=='G'&&str[(j+i)/2]=='B') sum--;
                }else  if(str[i]=='B'){
                    if(str[j]=='R'&&str[(j+i)/2]=='G') sum--;
                    if(str[j]=='G'&&str[(j+i)/2]=='R') sum--;
                }else if(str[i]=='G'){
                    if(str[j]=='B'&&str[(j+i)/2]=='R') sum--;
                    if(str[j]=='R'&&str[(j+i)/2]=='B') sum--;
                }
            }
        }
    }
    //cout<<sum<<endl;
    //cout<<r<<g<<b<<endl;
    cout<<r*g*b+sum<<endl;
  return 0;
}

Measured memory_bytes: 9892
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
int main(){
    int n;
    cin>>n;
string s;
cin>>s;
int cnt=0,m=0;
for (int i=0;i<n;i++){
    if (s[i]=='I')
        cnt++;
        if (cnt>m)
            m=cnt;
   if (s[i]=='D')
        cnt--;


}
cout<<m<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a)  (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;


int main(){
  ll a,b; cin >> a >> b;
  ll g = gcd(a,b);

  int ans = 1;
  for (ll i = 2; i*i <= g; i++) {
    if (g%i == 0){
      ans++;
      while(g%i==0) g /= i;
    }
  }
  if(g != 1) ans++;
  std::cout << ans << '\n';
}


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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):
    print(YES if not N % sum(map(int,list(str(N)))) else NO )
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

int main(){
	int n,h[100],i,m=0,count=0;

	cin>>n;
	for(int i=0;i<n;i++)cin>>h[i];

	for(i=0;i<n;i++){
		if(h[i]>=m)count++;
		m=max(h[i],m);
	}
	cout<<count<<endl;	
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())

class UnionFind:
    def __init__(self, n):
        self.rank = [0] * n
        self.parent = [i for i in range(n)]
        self.num = [1] * n

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.num[y] += self.num[x]
        elif self.rank[x] > self.rank[y]:
            self.parent[y] = x
            self.num[x] += self.num[y]
        else:
            self.parent[x] = y
            self.rank[y] += 1
            self.num[y] += self.num[x]

uf = UnionFind(n)
friend = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.merge(a, b)
    friend[a] += 1
    friend[b] += 1


block = [0] * n
for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.find(c) == uf.find(d):
        block[c] += 1
        block[d] += 1

ans = [0] * n
for i in range(n):
    ans[i] = uf.num[uf.find(i)]-1 - friend[i] - block[i]
print(*ans)


Measured memory_bytes: 13372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    multiset<int> T;
    int cnt = 1;
    for(int i = 0; i < N; i++){
        cin >>A[i];
    }
    T.insert(A[0]);
    T.insert(INF);
    for(int i = 1; i < N; i++){
        if(*T.begin() >= A[i]) T.insert(A[i]);
        else{
            auto past = T.begin();
            auto it = T.lower_bound(A[i]);
            it--;
            T.erase(it);
            T.insert(A[i]);
            /*for(auto it = T.begin(); it != T.end(); it++){
                //cout << i << " " << *it << endl;
                if(*it >= A[i]){
                    T.erase(past);
                    T.insert(A[i]);
                    break;
                }
                past = it;
            }*/
        }
        /*cout << i << " ";
        for(auto it1 = T.begin(); it1 != (T.end()++); it1++) cout << " " << (*it1);
        cout << endl;*/
    }
    cout << T.size() - 1 << endl;
}

Measured memory_bytes: 5760
N = int(input())
s = input()
s += s[:2]
rec = [[""] * (N + 2) for i in range(4)]
rec[0][0] = "S"
rec[0][1] = "S"
rec[1][0] = "S"
rec[1][1] = "W"
rec[2][0] = "W"
rec[2][1] = "S"
rec[3][0] = "W"
rec[3][1] = "W"
k = -1
for i in range(4):
    for j in range(1, N + 1):
        if s[j] == "o":
            if rec[i][j] == "S":
                rec[i][j + 1] = rec[i][j - 1]
            else:
                if rec[i][j - 1] == "S":
                    rec[i][j + 1] = "W"
                else:
                    rec[i][j + 1] = "S"
        else:
            if rec[i][j] == "S":
                if rec[i][j - 1] == "S":
                    rec[i][j + 1] = "W"
                else:
                    rec[i][j + 1] = "S"
            else:
                rec[i][j + 1] = rec[i][j - 1]

if rec[0][0] == rec[0][N] and rec[0][1] == rec[0][N + 1]:
    k = 0
elif rec[1][0] == rec[1][N] and rec[1][1] == rec[1][N + 1]:
    k = 1
elif rec[2][0] == rec[2][N] and rec[2][1] == rec[2][N + 1]:
    k = 2
elif rec[3][0] == rec[3][N] and rec[3][1] == rec[3][N + 1]:
    k = 3

if k == -1:
    print(-1)
else:
    print("".join(rec[k][:N]))


Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	cin>>n>>m;
	long long a,b;
	int cnt=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		long long c=a*a+b*b;
		if(m*m>=c)
			cnt++;
	}
	cout<<cnt;
	return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

class UnionFind {
    public:
        vector<int> rank, p;

        UnionFind() {}
        UnionFind(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            rep (i, size) makeSet(i);
        }

        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

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

        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
            } else {
                p[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }

        int findSet(int x) {
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    int ans = 0;
    cin >> n >> m;
    UnionFind uf = UnionFind(n);
    vector<int> p(n);
    rep (i, n) cin >> p[i];
    rep (i, m) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        uf.unite(x, y);
    }
    rep (i, n) {
        if (uf.same(i, p[i] - 1)) ans++;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 1408
if __name__ == '__main__':
    k, x = map(int, input().split())
    k = k-1
    max = k+x+1
    min = x -k
    a =range(min,max,1)
    ans = ""
    for i in a:
        if len(ans) > 0:
            ans = ans + " "+ str(i)
        else:
            ans = str(i)
    print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
/*
#include <ctime>
#define CLOCK_T(str) clock_t ## #str
#define SET_CLOCK(str) CLOCK_T(str) ## =cloxk();
*/
using namespace std;

int main() {
//	SET_CLOCK(Start);
	cin.tie(0);

	int x;
	static vector<int> V;

	while(cin>>x, x) {
		V.push_back(x);
	}
	ios::sync_with_stdio(false);
	for(int i = 0; i < V.size(); ++i) {
		cout << "Case " << (i+1) << ": " << V[i] << "" << '\n';
	}
	
//	SET_CLOCK(End);
//	cout << "????????????: " << (double)(End-Start) << endl;
	return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 7;
int n, k, val, res;
vector<int> a, b;
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &val);
		if (val < 0) a.push_back(val);
		else b.push_back(val);
	}
	reverse(a.begin(), a.end());
	res = oo;
	for (int i = 0; i <= k; i ++) {
		if (i <= a.size() && k - i <= b.size()) {
			int tmp1 = 0, tmp2 = 0;
			if (i > 0) tmp1 = abs(a[i - 1]);
			if (k - i > 0) tmp2 = abs(b[k - i - 1]);
			res = min(res, tmp1 + tmp2 + min(tmp1, tmp2));
		}
	}
	printf("%d", res);
}

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


int main(){
  
  int H,W,N,ans;
  cin >> H >> W >>N;
  
  ans=N/(max(H,W));
  if(N%(max(H,W))==0)
    cout << ans << endl;
  else
  cout << ans+1 << endl;

 
  
}

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


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

  vector<int> b(n+1,0);
  int m = 0;
  for(int i = n; i >= 1; i--){
    int sum = 0;
    for(int j = 2*i; j <= n; j += i) sum ^= b[j];
    if(b[i] != sum^a[i]) m++;
      b[i] = sum^a[i];
  }

  cout << m << endl;
  for(int i = 1; i <=n; i++){
    if(b[i] == 1) cout << i << " ";
  }
  cout << endl;
}


Measured memory_bytes: 4848
from collections import defaultdict

def solve():
    N = int(input())
    A = [sorted(list(input())) for _ in range(N)]
    d = defaultdict(int)
    for a in A:
        b = ''.join(a)
        d[b] += 1
    c = 0
    for v in d.values():
        if v == 1:
            continue
        for i in range(1, v):
            c += i
    
    return c

print(solve())

Measured memory_bytes: 39428
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

class CumulativeSum {
  private:
    std::vector<long long> s;

  public:
    explicit CumulativeSum (int N) {
      s.resize(N+1);
    }

    // s0 = 0, s1 = a0, s2 = a0 + a1, ...
    void build ( const std::vector<long long> &a ) {
      s[0] = 0;
      for(int i=1; i<s.size(); i++) s[i] = s[i-1] + a[i-1];
    }

    // Get [ i, j )
    long long Get ( int i, int j ) {
      return s[j] - s[i];
    }
};


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

  int N; std::cin >> N;
  std::vector<ll> a(N); rep(i,N) std::cin >> a[i];

  CumulativeSum s(N); s.build(a);
  ll ans = 1e18;
  for(int i=1; i<=N-1; i++) ans = std::min(ans,std::abs(s.Get(0,i) - s.Get(i,N)));
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3456
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int *p = new int[n];

	for (int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	long max = 0;
	long sum = 0;

	for (int i = 0; i < n; ++i) {
		sum += p[i];

		if (i >= k) {
			sum -= p[i - k];
		}

		if (sum > max) {
			max = sum;
		}
	}


	max += k;

	cout << setprecision(8) << ((double)max / 2.00000000000);

	free(p);

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    int K;
    cin >> S >> K;
    char s = '1';
    int k = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != '1'){
            s = S[i];
            k = i + 1;
            break;
        }
    }
    if(K < k && S[k-1]){
        cout << "1" << endl;
    }
    else{
    cout << s << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int v=in.nextInt();
		int[] val=new int[n+5];
		int[] wei=new int[n+5];
		int[] dp=new int[v+5];
		for(int i=1;i<=n;i++){
			val[i]=in.nextInt();
			wei[i]=in.nextInt();
		}
		in.close();
		Arrays.fill(dp,0);
		for(int i=1;i<=n;i++)
			for(int j=v;j>=wei[i];j--)
				dp[j]=Math.max(dp[j],dp[j-wei[i]]+val[i]);
		System.out.println(dp[v]);
	}
}

Measured memory_bytes: 26888
function Main(input){
    r=[["A\n","T\n"],["C\n","G\n"]];
    for(i=0;i<2;i++){
        if(input==r[i][0])console.log(r[i][1]);
        if(input==r[i][1])console.log(r[i][0]);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

[<EntryPoint>]
let main _ =
    let sum =
        stdin.ReadLine().Split(' ')
        |> Array.map int
        |> Array.sum
    if sum >= 10 then
        printfn "error"
    else
        printfn "%d" sum
    0

Measured memory_bytes: 13916
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	ll A, B;
	cin >> A >> B;
	string S = (A*B % 2LL == 1) ? "Odd" : "Even";
	cout << S << endl;	
	return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
//#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

int us[N], d[N];
vector <int> g[N];
int n,m;

void dfs(int v){
	us[v] = 1;
	for (auto to: g[v]){
		if (!us[to]){
			dfs(to);
		}
	}
	int mx = 0;
	for (auto to: g[v]){
		mx = max(mx, d[to] + 1);
	}
	d[v] = mx;
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		g[x].pb(y);
	}
	int mx = 0;
	for (int i = 1; i <= n; i++){
		if (!us[i]){
			dfs(i);
		}
		mx = max(mx, d[i]);
	}
	cout << mx;
	return 0;
}












Measured memory_bytes: 13824
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define INF 1LL << 61
#define MAX (1LL << 31) -1
#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> pi;
//typedef pair<pair<int,int>,ll> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
template<class T,class U>bool inline chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool inline chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

int N;
vector<int> a,b;
int C[100010];

signed main(){
    cin>>N;
    a.resize(N); b.resize(N);
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<N;i++){
        C[a[i]]++;
        C[b[i]+1]--;
    }
    for(int i=1;i<=N+1;i++){
        C[i]+=C[i-1];
    }
    int ans=0;
    for(int i=1;i<=N+1;i++){
        if(C[i]>=i-1) chmax(ans,i-1);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 4076
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;
 
#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end
 
typedef long long ll;
 
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};
 
// const int C = 1e6+10;
// const ll M = 1000000007;
 
int N, M;
int a[100];
int b[100];
 
int main () {
  cin >> N >> M;
  for (auto i = 0; i < M; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  int ans = 0;
  for (auto k = 0; k < M; ++k) {
    vector<int> V[100];
    for (auto i = 0; i < M; ++i) {
      if (i == k) continue;
      V[a[i]].push_back(b[i]);
      V[b[i]].push_back(a[i]);
    }
    bool visited[100];
    fill(visited, visited+N, false);
    stack<int> S;
    S.push(0);
    int cnt = 0;
    while (!S.empty()) {
      int now = S.top();
      S.pop();
      if (!visited[now]) {
        ++cnt;
        visited[now] = true;
        for (auto x : V[now]) {
          if (!visited[x]) {
            S.push(x);
          }
        }
      }
    }
    if (cnt < N) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve [a, _, c] | a == c    = "Yes"
                | otherwise = "No"

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll dp[3005][3005];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t; cin >> s >> t;
  ll ss = s.size();
  ll st = t.size();
  REP(i,ss+st+1){
      REP(j,i+1){
          if(j<s.size() && i-j<t.size()){
              if(s[j] == t[i-j]){
                  dp[j+1][i-j+1] = dp[j][i-j] + 1;
              }else{
                  dp[j+1][i-j+1] = max(dp[j][i-j+1], dp[j+1][i-j]);
              }
          }

      }
  }
  vector<char> ans;
  queue<pair<ll,ll>> q;
  q.push(mp(ss,st));
  while(q.size()){
      auto pos = q.front();
      q.pop();
      ll spos = pos.first;
      ll tpos = pos.second;
      if(dp[spos][tpos]==0){
          continue;
      }
      if(s[spos-1] == t[tpos-1]){
          q.push(mp(spos-1, tpos-1));
          ans.push_back(s[spos-1]);
      }else{
          if(dp[spos-1][tpos]> dp[spos][tpos-1]){
              q.push(mp(spos-1, tpos));
          }else{
              q.push(mp(spos, tpos-1));
          }
      }
  }
  auto it = ans.rbegin();
  while(it!=ans.rend()){
      cout << *it;
      it++;
  }
  cout << endl;
}

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    for(int i=0; i<S.size(); i++)
    {
        if(S[i]+N>='[')
        {
        cout << char(S[i]+N-26);
        }
        else
        cout << char(S[i]+N);
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <functional>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>

template <class Integer>
auto boost_irange(Integer last) { return boost::irange(static_cast<Integer>(0), last); }
template <class Integer>
auto boost_irange(Integer first, Integer last) { return boost::irange(first, last); }

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { cout << std::endl; }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << val << ' ';
            return *this;
        }
    };

public:
    output() : cout(std::cout) {}
    template <class T>
    proxy operator<<(T&& val)
    {
        cout << val << ' ';
        return {};
    }
};

template <class T, std::size_t n>
class StaticVector : public boost::container::static_vector<T, n>
{
    using Parent = boost::container::static_vector<T, n>;

public:
    // is_constructible_v >= C++17
    template <class... Args, std::enable_if_t<std::is_constructible<Parent, Args&&...>::value, std::nullptr_t> = nullptr>
    StaticVector(Args&&... args) : Parent(std::forward<Args>(args)...) {}
    StaticVector(input& in, std::size_t n_) : Parent(n_)
    {
        for (std::size_t i = 0; i < n_; ++i) in >> static_cast<Parent&>(*this)[i];
    }
};

template <class Integer>
Integer ceil(Integer x, Integer y)
{
    return (x + y - 1) / y;
}

int main()
{
    input in;
    output out;

    int a, b;
    in >> a, b;

    out << ceil(b - 1, a - 1);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        int biscuit = 0;

        for (int time = A; time <= T; time += A) {
            biscuit += B;
        }
        System.out.println(biscuit);
    }
}

Measured memory_bytes: 23124
using System;


class A {
    int N;
    long x;
    long[] a,aa;
    long[] bf;
    public A() {
        a = new long[2002];
        aa = new long[2002];
        bf = new long[2002];
        
    }
    public void run(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        x = long.Parse(str[1]);
        str =  Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            aa[i] = a[i] = long.Parse(str[i]);
            bf[i] = 100000000000;
        }
        
        long an = -1;
        for(int maxC = 0; maxC<N+1;maxC++){
            long ans=0;
            for(int i=0;i<N;i++){
                int now = (i+maxC)%N;
                bf[i] = Math.Min(bf[i], aa[now]);
                ans += bf[i];
            }
            ans += x* maxC;
            if(an==-1) an = ans;
            an = Math.Min(an, ans);
        }
        Console.WriteLine(an);
    }
}

class Program {
    static void Main(string[] args){
        A a = new A();
        a.run();
    }
}

Measured memory_bytes: 3032
S = input()
T = input()

# bfで行ける
size = len(T)
ans = float("inf")
for i in range(len(S)-size+1):
    if S[i:i+size] == T:
        ans = 0
    else:
        cnt = 0
        sub_S = S[i:i+size]
        for t, s in zip(T, sub_S):
            if t != s:
                cnt += 1
        ans = min(ans, cnt)

print(ans)



Measured memory_bytes: 67996
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int absp(int x)
{
	if (x > 0)return x;
	else return -x;
	
}
const int inf = 1e9;
int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int>a(n), b(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	b[1] = absp(a[1] - a[0]);
	b[2] = absp(a[2] - a[0]);
	if (n == 2) {
		cout << b[1];
		return 0;
	}
	else if (n == 3)
	{
		cout << b[2];
		return 0;
	}
	for (int i = 3; i < n; i++) {
		b[i] = min((b[i - 1] + absp(a[i - 1] - a[i])), (b[i - 2] + absp(a[i - 2] - a[i])));
	}
	cout << b[n - 1];
}

Measured memory_bytes: 1024
n, k = map(int, input().split())
ps = list(map(int, input().split()))
cs = list(map(int, input().split()))
ps = [p-1 for p in ps]
# doubling使う
vers = []   # vers[b][i] 頂点iから2^b回移動した時にどの頂点にいるか
score = []  # score[b][i]頂点iから2^b回移動した時に何点もらえるか
vers.append(ps)
score.append(cs)

m = 31
# ダブリング
for b in range(1, m+1):
    p_bth = [0] * n
    c_bth = [0] * n
    for i in range(n):
        p_bth[i] = vers[b-1][vers[b-1][i]]
        c_bth[i] = score[b-1][i] + score[b-1][vers[b-1][i]]
    vers.append(p_bth)
    score.append(c_bth)

# 桁DP
MIN = -(1 << 63) 
prv = [[MIN, 0] for _ in range(n)]
nxt = [[MIN, MIN] for _ in range(n)] 
for b in range(m, -1, -1):
    for i in range(n):
        if (k >> b) & 1:
            nxt[vers[b][i]][0] = max(nxt[vers[b][i]][0], prv[i][0] + score[b][i])
            nxt[vers[b][i]][1] = max(nxt[vers[b][i]][1], prv[i][1] + score[b][i])
            nxt[i][0] = max(nxt[i][0], prv[i][0], prv[i][1])
        else:
            nxt[vers[b][i]][0] = max(nxt[vers[b][i]][0], prv[i][0] + score[b][i])
            nxt[i][0] = max(nxt[i][0], prv[i][0])
            nxt[i][1] = max(nxt[i][1], prv[i][1])
    prv, nxt = nxt, prv

ans = max(max(x) for x in prv)
if ans == 0:
    ans = max(cs)
print(ans)

Measured memory_bytes: 80168
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n, d;
	int i, j, k;
	int x[20][20];

	cin >> n >> d;
	for (i = 0; i < n; i++) {
		for (j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	int distInt;
	double distDouble;

	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			distInt = 0;
			distDouble = 0.0;
			for (k = 0; k < d; k++) {
				distInt += pow((x[i][k] - x[j][k]), 2);
			}
			distDouble = pow(distInt, 0.5);
//			cout << "distDouble = " << distDouble << endl;
			distInt = (int)distDouble;
			if ( distInt == distDouble) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
using namespace std;
long long a[50];
int main()
{
    long long k,i;
    while(~scanf("%lld",&k))
    {
        memset(a,0,sizeof(a));
        printf("50\n");
        if(k<50)
        {
                for(i=0;i<k;i++)
                    a[i]=50-i;
        }
        else
        {
            for(i=49;i>=0;i--)
                a[i]=i+k/50;
            long long b=k%50;
            for(i=1;i<=b;i++)
            {
                a[50-i]++;
            }
        }
        for(i=0;i<=49;i++)
            printf("%lld ",a[i]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
    int i,j,num,array[5];
    num=0;
    for(i=0;i<6;i++){
        scanf("%d",&array[i]);
    }
    for(i=0;i<5;i++){
        for(j=i+1;j<5;j++){
            if(array[j]-array[i]>num) num = array[j]-array[i];
        }
    }
    if(num>array[5]) printf(":(\n");
    else printf("Yay!\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#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)

int main(){
    int N;
    cin >> N;
    int a[N];
    REP(i,N){
        cin >> a[i];
    }
    int cnt=0;
    int x=1;
    bool flag = false;
    REP(i,N){
        x = a[x-1];
        cnt += 1;
        if(x==2){
            flag = true;
            break;
        }
    }
    if(flag){
        cout << cnt;
    }else{
        cout << -1;
    }

}


Measured memory_bytes: 640