akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#include<random>
using namespace std;

vector<long long> a;

int root(int x, vector<int>& parent) {
    if (parent[x] == x) {
        return x;
    } else {
        int y = root(parent[x], parent);
        return parent[x] = y;
    }
}

bool same(int x, int y, vector<int>& p) {
    return root(x, p) == root(y, p);
}

void unite(int x, int y, vector<int>& parent) {
    x = root(x, parent);
    y = root(y, parent);
    if (x != y) {
        if (a[x] < a[y]) {
            parent[y] = x;
        } else {
            parent[x] = y;
        }
    }
}

long long merge(int x, int y, vector<int>& parent, int& min_index) {
    x = root(x, parent);
    y = root(y, parent);
    if (x != y) {
        long long x_cost = a[x];
        long long y_cost = a[y];
        a[x] = INT_MAX;
        a[y] = INT_MAX;
        unite(x, y, parent);

        //a[x],a[y]はもう使えないので繋がっているものの中でコスト最小のものに代表させる
        long long min_cost = INT_MAX;
        min_index = -1;
        for (int i = 0; i < parent.size(); i++) {
            if (same(i, y, parent)) {
                if (a[i] <= min_cost) {
                    min_cost = a[i];
                    min_index = i;
                }
            }
        }
        parent[y] = min_index;
        parent[min_index] = min_index;

        if (x_cost == INT_MAX || y_cost == INT_MAX) {
            return -1;
        }
        return x_cost + y_cost;
    } else {
        assert(false);
        return 0;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    
    vector<int> parent(N);

    for (int i = 0; i < N; i++) {
        parent[i] = i;
    }

    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        unite(x, y, parent);
    }

    int tree_num = 0;
    for (int i = 0; i < N; i++) {
        if (i == root(i, parent)) {
            tree_num++;
        }
    }

    //tree_num * 2 - 2個の頂点を選んでくっつける必要がある
    int need = 2 * tree_num - 2;
    if (need > N) {
        cout << "Impossible" << endl;
        return 0;
    } else if (need == 0) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 0;
    vector<bool> used(N, false);
    for (int i = 0; i < N; i++) {
        if (i == root(i, parent)) {
            used[i] = true;
            ans += a[i];
            need--;
        }
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0; i < N; i++) {
        if (!used[i]) {
            pq.push(a[i]);
        }
    }

    for (int i = 0; i < need; i++) {
        auto p = pq.top();
        pq.pop();
        ans += p;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2048
# コイン問題
# 個数制限なしナップサックで解く
N, M = map(int, input().split())  # N円, M種類の硬貨
C = list(map(int, input().split()))
dp = [[10**10]*(N+1) for _ in range(M+1)]  # m種類目までの硬貨を使ってn円払うときの最小枚数

dp[0][0] = 0
# M種類の中のi番目のコインを使う
for i in range(M):
    for j in range(N+1):
        # 使わない場合
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        # 使う場合
        if j + C[i] > N:  # 今i番目のコインを使った時にN円を超えるようならダメ
            continue
        # dp[i+1][j]+1は同じ段からの遷移を表している
        dp[i+1][j+C[i]] = min(dp[i][j]+1, dp[i+1][j]+1)
print(dp[M][N])



Measured memory_bytes: 43776
N = int(input())
str_N = str(N)
if len(str_N)%2 == 0:
  N = 10 ** (len(str_N))-1
k = len(str_N)//2
ans2 = 0
for i in range(k):
  ans2 = ans2 + 10 ** (2*i+1) - 10 **(2*i)
ans2 += N - (10**(2*k) -1)
print(ans2)

Measured memory_bytes: 3060
N,M = tuple(map(int,input().split()))
import numpy as np
like_array = np.zeros((N,M))
for i in range(N):
    _in_ =list(map(int,input().split()))
    K =_in_[0]
    A = _in_[1:]
    for j in A:
        like_array[i,j-1] = 1
print(int(np.sum(np.prod(like_array,axis=0))))

Measured memory_bytes: 12488
l=input()
num=[int(l[i]) for i in range(4)]
pm=['+','-']
for i in pm:
  a,b,c,d=num[0],num[1],num[2],num[3]
  for j in pm:
    for k in pm:
      if i=='-':
        b=b*(-1)
      if j=='-':
        c=c*(-1)
      if k=='-':
        d=d*(-1)
      if a+b+c+d==7:
        print(str(a)+i+str(abs(b))+j+str(abs(c))+k+str(abs(d))+'='+'7')
        exit()
      a,b,c,d=num[0],num[1],num[2],num[3]

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(v1, v2)     cout << v1 << " " << v2 << endl
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------

int main(void) {
  ll n, k, q;
  cin >> n >> k >> q;
  arr(a,q);

  vecll ans;
  ans.assign(n,0);
  rep(i,q){
    ans[a[i]-1]++;
  }

  rep(i,n){
    if(k-q+ans[i]>0){
      prt("Yes");
    } else {
      prt("No");
    }
  }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,j,n) for(ll i=j;i<n;i++ )
typedef pair<ll,ll> P;
const ll mod = 1000000007;
const ll INF = 1000000009;
ll i;

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

    cout<<N*(N-1)/2LL<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def doesOver(k):
    cnt = 0
    for a in A:
        cnt += N - bisect_left(A, k - a)
    return cnt >= M

overEq = 0
less = A[-1] * 2 + 100

while less - overEq > 1:
    mid = (less + overEq) // 2
    if doesOver(mid):
        overEq = mid
    else:
        less = mid

accA = [0] * (N + 1)
for i in range(1, N + 1):
    accA[i] = accA[i - 1] + A[i - 1]

ans = 0
cnt = 0
for a in A:
    left = bisect_left(A, overEq - a)
    ans += accA[N] - accA[left]
    ans += (N - left) * a
    cnt += N - left

ans -= (cnt - M) * overEq
print(ans)


Measured memory_bytes: 14268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int a[3],k,i,j,buff;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  a[0]=atoi(p);
  p=strtok(NULL," \n");
  a[1]=atoi(p);
  p=strtok(NULL," \n");
  a[2]=atoi(p);
  
  fgets(str,sizeof(str),stdin);
  k=atoi(str);
  
  for(i=0;i<2;i++){
   for(j=2;j>i;j--){
    if(a[j-1]<a[j]){
      buff=a[j-1],a[j-1]=a[j],a[j]=buff;
    }
   }
  }
  
  for(i=0;i<k;i++){
   a[0]*=2 ;
  }
  printf("%d\n",a[0]+a[1]+a[2]);
  
 return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N;
ll T[1010], A[1010];

signed main(){
    cin >> N;
    REP(i, N) cin >> T[i] >> A[i];
    REP(i, N - 1){
        ll d = max((T[i] + T[i + 1] - 1) / T[i + 1], (A[i] + A[i + 1] - 1) / A[i + 1]);
        T[i + 1] *= d; A[i + 1] *= d;
    }
    PRINT(T[N - 1] + A[N - 1]);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 2e5+5;
int ans[maxn];
bool vis[maxn];
vector<int>vec[maxn];

struct node{
	int x, d;
};

void bfs(int s){
	queue<node>q;
	q.push((node){s, 0});
	vis[s] = 1;
	while(!q.empty()){
		node now = q.front(); q.pop();
		for(int i = 0; i < vec[now.x].size(); i++){
			if(vis[vec[now.x][i]]) continue;
			ans[now.d+1]++;
			vis[vec[now.x][i]] = 1;
			q.push((node){vec[now.x][i], now.d+1});
		}
	}
}

int main(){
	int n, x, y; cin >> n >> x >> y;
	for(int i = 1; i <= n; i++){
		if(i != 1) vec[i].push_back(i-1);
		if(i != n) vec[i].push_back(i+1);
	}
	vec[x].push_back(y);
	vec[y].push_back(x);
	vis[0] = vis[n+1] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++) vis[j] = 0;
		bfs(i);
	}
	for(int i = 1; i < n; i++) cout << ans[i] / 2 << endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int a[2010];

int main() {
	int n;
	int m;

	cin >> n ;

	m=1e9+7;
	a[0]=1;
	a[1]=0;
	a[2]=0;
  	rep(i, n){
		a[i+3]=a[i+2]+a[i];
		a[i+3]%=m;
	}

	cout << a[n] << endl;
	return 0;
}

Measured memory_bytes: 3604
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k) {
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= MOD;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= MOD;
    }
    return x * modinv(y, MOD) % MOD;
}

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

    int n, k, c;
    string s;
    queue<int>que;
    stack<int>sta;

    cin >> n >> k >> c;
    cin >> s;

    int cnt = 0;
    rep(i, s.size()) {
        if (s[i] == 'o') {
            que.push(i);
            cnt++;
            i += c;
            if (cnt == k) break;
        }
    }

    cnt = 0;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'o') {
            cnt++;
            sta.push(i);
            if (cnt == k) break;
            i -= c;
        }
    }

    rep(i, k) {
        if (sta.top() == que.front()) {
            cout << sta.top() + 1 << endl;
        }
        sta.pop(); que.pop();
    }

    return 0;
}


Measured memory_bytes: 4508
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int r[5005][5005];
int n,k;
int pos[5005],a[5005];
bool ok(int a,int b)
{
if(b==0) return !a;
return (a%b==0);
}
int main()
{
	cin >> n >> k;
	for(int i=1;i<=n;i++) cin >> pos[i];
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=0;i<k;i++)
	{
		int x = (i>=pos[1] && ok(i-pos[1],a[1]));
		if(i==0) r[1][i] = x;
		else  r[1][i] = r[1][i-1]+x;
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<k;j++)
		{
			int x=0;
			if(j >= pos[i] && ok(j-pos[i],a[i])) x = r[i-1][j-1];
			if(j==0) r[i][j] = x;
			else  r[i][j] = (r[i][j-1]+x)%mod;
		}
	}
	ll res = 0;
	cout << r[n][k-1] << endl;
}

Measured memory_bytes: 98960
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<ll, int> ll_i;

string shift(string s){
    ll len = s.length();
    string ret;
    ret += s[len-1];
    for (int i = 0; i < len-1; ++i){
        ret += s[i];
    }
    return ret;
}

int main() {
    string s,t;
    cin >> s >> t;
    ll len = s.length();
    for(int i =0;i < len; i++){
        string ss = shift(s);
        if (ss == t){
            cout << "Yes" << endl;
            return 0;
        }
        s = ss;
    }
    cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return


# B
def B():
    a,b=LI()
    print(-(-(b-1)//(a-1)))
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    B()
    return


# Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 38384
<?php
  list($s) = explode(" ", trim(fgets(STDIN)));
  //$a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  if($s == 'abc' || $s == 'acb' || $s == 'bac' || $s == 'bca' || $s == 'cab' || $s == 'cba' ){
    echo "Yes";
  }else{
    echo "No";
  }

Measured memory_bytes: 16132
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const int MOD = 1000000007, MAXN = 100100;
int dp[MAXN][2][2];
string L;

int f(int i, int ls, int cp)
{
    if (i == L.size()) {
        return 1;
    }

    int& ans = dp[i][ls][cp];
    if (ans >= 0)
        return ans;

    ans = 0;
    FOR(a, 0, 2)
        FOR(b, 0, 2) {
            if (a == 1 && b == 1)
                continue;
            if (ls == 0 && (a + b) == 1 && L[i] == '0')
                continue;

            ans += f(i + 1, ls || (L[i] == '1' && a + b == 0), 
                        cp || (a < b));
            if (ans >= MOD)
                ans -= MOD;
        }

    return ans;
}

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    cin >> L;
    memset(dp, -1, sizeof dp);

    int ret = f(0, 0, 0);
    cout << ret << endl;
    return 0;
};


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

int gcd(int, int);

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

    int a_front[n], a_back[n];
    for(auto i = 0; i < n; i++)
    {
        if(i == 0){
            a_front[i] = 0;
            a_back[i] = 0;
        }else if(i == 1){
            a_front[i] = a[i - 1];
            a_back[i] = a[n - 1 - (i - 1)];
        }else{
            a_front[i] = gcd(a_front[i - 1], a[i - 1]);
            a_back[i] = gcd(a_back[i - 1], a[n - 1 - (i - 1)]);
        }
    }

    int max = -1;
    for(auto i = 0; i < n; i++)
    {
        int tmp = gcd(a_front[i], a_back[n - 1 - i]);
        if(tmp > max){
            max = tmp;
        }
    }

    cout << max << endl;

}

int gcd(int x, int y){
    int temp;
    if(x < y){
        swap(x, y);
    }
    while(y != 0){
        temp = y;
        y = x % y;
        x = temp;
    }
    return x;
}

Measured memory_bytes: 1408
n = gets.to_i
a = Array.new(n)
n.times do |i|
  ai = gets.to_i
  a[i] = ai.times.map {gets.split.map(&:to_i)}
end

ans = 0
(1 << n).times do |bit|
  flag = true
  n.times do |i|
    if bit[i] == 1
      a[i].each do |x, y|
        flag = false if bit[x - 1] != y
      end
    end
  end
  count = bit.to_s(2).count('1')
  ans = count if flag && ans < count
end
p ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    ll n,m;cin>>n>>m;
    ll ans = m*pow(m-1,n-1);
    co(ans);
}

Measured memory_bytes: 256
a = []
for i in range(5):
    a.append(int(input()))

moda = [a[i] % 10 for i in range(5)]
for num, i in enumerate(moda):
    if i == 0:
        moda[num] = 10
# print(moda)
print(sum(a)-sum(moda)+40+min(moda))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
  int main() {
    string s ;
    cin >> s ;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s.at(i) == '1'){
        ans += 1;
      }
  } 
    cout << ans << endl;
  }  

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

int main(){
  int K;
  cin >> K;
  long long ans = 0;
  
  for (int i = 1; i <= K; i ++) {
    for (int j = 1; j <= K; j++) {
      for (int k = 1; k <= K; k++) {
        ans = ans + gcd(gcd(j, k), i);
      }
    }
  }
  cout << ans << endl;
}

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

int main() {

  int N;
  string S;
  
  cin >> N;
  
  for (int i=0; i<N; i++){
    
    cin >> S;
    
    if (i < N  && S == "Y"){
     cout << "Four" << endl;
     break;
    }
    
    else if (i == N-1){
      
      if ( S == "Y"){
       cout << "Fore" << endl;
      }

      else{
       cout << "Three" << endl;
      }
     
    }
    
  }
  
  
  
  
}


Measured memory_bytes: 3624
#include<stdio.h>
typedef long long ll;
ll solve(ll x,ll n)
{
    ll ans;
    if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+solve(n%x,x);
    return ans;
}
int main()
{
    ll n,x;
    ll ans;
 
    scanf("%lld%lld",&n,&x);
    ans=solve(x,n-x)+n;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
let ans, n = ref 0, Scanf.scanf " %d" (+) 0
let ps = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = for i = 1 to n - 2 do if ps.(i - 1) < ps.(i) && ps.(i) < ps.(i + 1) || ps.(i - 1) > ps.(i) && ps.(i) > ps.(i + 1) then incr ans done; Printf.printf "%d\n" !ans

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



int main(){
	int N;
	cin>>N;
	char c[N];
	bool flag=false;
	for (int i = 0; i < N; i++){
		cin>>c[i];
		if(c[i]=='Y'){
			flag=true;
		}
	}

	if(flag)
		cout<<"Four"<<endl;
	else
		cout<<"Three"<<endl;

}


Measured memory_bytes: 256
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main() {
  size_t n;
  scanf("%zu", &n);
  uint_fast32_t a[n];
  for (size_t i = 0; i < n; ++i) {
    scanf("%" SCNuFAST32, &a[i]);
  }

  size_t l = 0;
  uint_fast32_t sum = 0, ans = 0;
  for (size_t r = 0; r < n; ++r) {
    while (l < r && sum & a[r]) {
      sum ^= a[l];
      ++l;
    }
    sum ^= a[r];
    ans += (uint_fast32_t)(r - l) + 1;
  }

  printf("%" PRIuFAST32 "\n", ans);
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for (int i = 1; i <= n; i++) {
			int[][] map = new int[8][8];
			for (int j = 0; j < 8; j++) {
				String line = scanner.next();
				for (int k = 0; k < 8; k++) {
					if (line.charAt(k) == '1') {
						map[j][k] = 1;
					}
				}
			}
			int xbom = scanner.nextInt() - 1;
			int ybom = scanner.nextInt() - 1;

			bom(ybom, xbom, map);
			
			System.out.println(String.format("Data %d:", i));
			for(int j =0;j<8;j++){
				for(int k=0;k<8;k++){
					System.out.print(map[j][k]);
				}
				System.out.println();
			}
		}
	}

	private static void bom(int y, int x, int[][] map) {
		if (y < 0 || 8 <= y || x < 0 || 8 <= x || map[y][x] == 0) {
			return;
		}
		int[] py = { -3, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, 3 };
		int[] px = { 0, 0, 0, -3, - 2, -1, 1, 2, 3, 0, 0, 0 };
		map[y][x] = 0;
		for (int i = 0; i < 12; i++) {
			int ny = y + py[i];
			int nx = x + px[i];
			bom(ny, nx, map);
		}

	}
}

Measured memory_bytes: 17300
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define lli int
int const maxlen = 2e5 +7;
vector<int> adjlist[maxlen];
bool visited[maxlen];
int req = 0;
void dfs(int u){
  visited[u] =1 ;
  req++;
  for(int v: adjlist[u]){
    if(visited[v])
      continue;
    dfs(v);
  }
}
void solve(){

  int N;
  cin>>N;
  int M;
  cin>>M;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    adjlist[a].push_back(b);
    adjlist[b].push_back(a);
  }

  int cnt = 0;
  for(int i=1;i<=N;i++){
    if(visited[i])
      continue;
    dfs(i);
    cnt = max(cnt, req);
    req = 0;
  }
  cout<<cnt<<endl;
}
signed main(){
  // int t;
  // cin>>t;
  // while(t--)
  solve();
}


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

int main(){
  int n, q;
  cin >> n;
  vector<long> v(n,0);
  r(i,n) cin>>v.at(i);
  cin>>q;
  while(q--){
    int a, b, c;
    cin >> a >> b >> c;
    if(!a)cout << *min_element(v.begin()+b, v.begin()+c) << endl;
    else cout << *max_element(v.begin()+b, v.begin()+c) << endl;
  }
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int N;
double dp[301][301][301];
double solve(int n3, int n2, int n1) {
	if (dp[n3][n2][n1] < -0.5) {
		dp[n3][n2][n1] = 0;
		if (n3 > 0)dp[n3][n2][n1] += ((double)n3 / N) * (1 + solve(n3 - 1, n2 + 1, n1));
		if (n2 > 0)dp[n3][n2][n1] += ((double)n2 / N) * (1 + solve(n3, n2 - 1, n1 + 1));
		if (n1 > 0)dp[n3][n2][n1] += ((double)n1 / N) * (1 + solve(n3, n2, n1 - 1));
		dp[n3][n2][n1] += 1;
		dp[n3][n2][n1] *= (N / (double)(n1 + n2 + n3));
		dp[n3][n2][n1] -= 1;

	}
	return dp[n3][n2][n1];
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	int n3 = 0;
	int n2 = 0;
	int n1 = 0;
	int res = 0;
	int a;
	for (int i = 0; i < 301; i++) {
		for (int j = 0; j < 301; j++) {
			for (int k = 0; k < 301; k++) {
				dp[i][j][k] = -1;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> a;
		if (a == 3)n3++;
		if (a == 2)n2++;
		if (a == 1)n1++;
	}

	cout << fixed << setprecision(15) << solve(n3, n2, n1) << endl;
}

Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i ,j ;
int main ()
{
    int n;
    cin >> n;
    while ( n >= 0 )
    {
        if ( n % 7 == 0 )
        {
            cout << "Yes" << endl;
            return 0;
        }
        n -=4;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    if (n%2!=0)
    {
        cout<<"No";
    }
    else
    {
        string temp = s.substr(0,n/2);
        if (s==temp+temp)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
    }
}


Measured memory_bytes: 3576
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		String S = sc.next();
		int x = 0;
		int answer = 0;
		for(int i = 0;i < N;i++){
			char word = S.charAt(i);
			if(word == 'I'){
				x++;
				if(answer <= x){
					answer = x;
				}
			}
			else if(word == 'D'){
				x--;
				
			}
		}
		System.out.println(answer);	
	}
}

Measured memory_bytes: 9680
#pragma GCC target("avx")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

int_fast32_t n, h, w, a, b, ans;
int main(){
	scanf("%ld %ld %ld", &n, &h, &w);
	while(n--){
		scanf("%ld %ld", &a, &b);
		ans += (a>=h && b>=w);
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int r, c;
	int values[101][101];
	
	cin >> r >> c;

	//??\???
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> values[i][j];
		}
	}

	//???????¨????
	//???
	for (int i = 0; i < r; i++) {
		//?????????
		values[i][c] = 0;
		for (int j = 0; j < c; j++) {
			values[i][c] += values[i][j];
		}
	}
	//???
	for (int j = 0; j < c; j++) {
		//?????????
		values[r][j] = 0;
		for (int i = 0; i < r; i++) {
			values[r][j] += values[i][j];
		}
	}

	//??????
	values[r][c] = 0;
	for (int i = 0; i < r; i++) {
		values[r][c] += values[i][c];
	}

	//??¨???
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			cout << values[i][j];
			if (j < c) {
				cout << " ";
			}
			else if (j == c) {
				cout << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3092
N = int(input())
X = list(map(int, input().split()))
Y = X[:]
Y = sorted(Y)

med1 = Y[N // 2 - 1]
med2 = Y[N // 2]

for x in X:
    if x < med2:
        print(med2)
    else:
        print(med1)

Measured memory_bytes: 25224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int ans = 0,n;
		int[] a,b,c;
		String str;
		String[] s;
		str = bf.readLine();
		n = Integer.parseInt(str);
		a = new int[n];
		b = new int[n];
		c = new int[n];
		str = bf.readLine();
		s = str.split(" ");
		for(int i = 0;i < n;++i) {
			a[i] = Integer.parseInt(s[i]);
		}
		str = bf.readLine();
		s = str.split(" ");
		for(int i = 0;i < n;++i) {
			b[i] = Integer.parseInt(s[i]);
		}
		str = bf.readLine();
		s = str.split(" ");
		for(int i = 0;i < n-1;++i) {
			c[i] = Integer.parseInt(s[i]);
		}
		for(int i = 0;i < n;++i) {
			ans += b[a[i]-1];
			if(i > 0) {
				if(a[i-1]+1 == a[i]) {
					ans += c[a[i-1]-1];
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;
    set<string> S;
    rep(i, N) {
        string s;
        cin >> s;
        S.insert(s);
    }

    cout << S.size() << endl;

    return 0;
}


Measured memory_bytes: 19124
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N, M; cin >> N >> M; int X[M], d[M], moves = 0;
    for (int i = 0; i < M; i++) cin >> X[i];
    sort(X  , X+M);
    for (int i = 1; i < M; i++) d[i] = X[i]-X[i-1];
    sort(d+1, d+M);
    for (int i = 1; i < M+1-N; i++) moves += d[i];
    cout << moves << endl;
    return 0;
}


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

int main(){
  int n;
  int g[101][101];
  fill(g[0],g[101],0);
  cin >> n;
  for(int i = 0;i < n;i++){
    int u,k;
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      int v;
      cin >> v;
      g[u][v] = 1;
    }
  }
  for(int i = 1;i <= n;i++){
    cout << g[i][1];
    for(int j = 2;j <= n;j++){
      cout << ' ' << g[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1200
#include <utility>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include <limits>
#include <set>
#include <map>
#include <string>
#include <sstream>
#include <stdio.h>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
ull gcd(ull a, ull b){return b? gcd(b, a%b):a;}
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;

	int plug = 1;
	int ans = 0;
	for(; plug < B;){
		plug--;
		plug += A;
		ans++;
	}
	cout << ans << endl;

    return 0;
}


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

int main(){
	string str;
	int cnt[30];
	memset(cnt,0,sizeof(cnt));
	while(cin >> str){
		for(int i=0;i<str.size();i++){
			if(str[i] >= 'a' && str[i] <= 'z') {
				cnt[str[i]-'a']++;
			} else if(str[i] >= 'A' && str[i] <= 'Z'){
				cnt[str[i]-'A']++;
			}
		}
	}
	for(int i=0;i<26;i++){
		cout << (char)('a'+i) << " : " << cnt[i] << endl;
	}
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int n;
char s[200010];
int a[200010],ans;

int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++){
		if(s[i]=='.') a[i]=a[i-1]+1;
		else a[i]=a[i-1]; 
	}
	ans=a[n];
	for(int i=1;i<=n;i++){
		ans=min(ans,i-a[i]+a[n]-a[i]);
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 998244353;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
vector<ll> F(3e5+1);
const int MAX = 510000;
const ll MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    COMinit();
    ll N,A,B,K;
    ll ans = 0;
    cin >> N >> A >> B >> K;
    for(int i=0;i<=N;i++){
        ll sum = A*i;
        ll left = K - sum;
        if(left%B!=0)continue;
        if(left/B>N)continue;
        //N個のうちi個をAで塗る
        //N個のうちJ個をBで塗る
        ans += COM(N,i)*COM(N,left/B);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14592
def main():
    num = int(input())
    data = list(map(int, input().split()))
    data = [0] + data + [0]

    count = 0
    for i in range(num + 1):
        count += abs(data[i + 1] - data[i])

    for i in range(1, num + 1):
        print(count - abs(data[i] - data[i - 1]) - abs(data[i] - data[i + 1]) + abs(data[i - 1]- data[i + 1]))


if __name__ == '__main__':
    main()



Measured memory_bytes: 64748
w, h, t = gets.chomp.split.map(&:to_i)
p = gets.to_i
arr, map = [], []
p.times{arr << gets.chomp.split.map(&:to_i)}
h.times{map << gets.chomp.split.map(&:to_i)}
sum = 0
arr.sort_by{|x, y, t| t}.each{|x, y, tm|
    break if tm > t
    sum += 1 if map[y][x] == 1
}
puts sum


Measured memory_bytes: 8916
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long N, long long R) {
  // solver code

  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long R;
  scanf("%lld", &R);
  solve(N, R);
  return 0;
}


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

int main(int argc, const char *argv[]) {
  string s, ans;
  cin >> s;
  if (s == "Sunny") {
    ans = "Cloudy";
  } else if (s == "Cloudy") {
    ans = "Rainy";
  } else {
    ans = "Sunny";
  }
  cout << ans;
  return 0;
}


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

int main(){
    int N;
    string S;
    map<string,int> m;

    cin>>N;
    for(int i=0;i<N;i++){
        cin>>S;
        m[S]++;
    }
    
    int max=0;
    for(const auto& x:m){
        if(x.second>max){
            max=x.second;
        }
    }

    for(const auto& x:m){
        if(x.second==max){
            cout<<x.first<<'\n';
        }
    }

}

Measured memory_bytes: 25216
#include<cstdio>
#include<iostream>

using namespace std;

long int  a, b;
long int gcd, lcm;

void GCD(){

	int big, small;

	big = a;
	small = b;

	while (big) {
		if (small > big) swap(big, small);
		big = big % small;
	}
	gcd = small;

}

void LCM() {
	lcm = a * b / gcd;
}




int main(){
	while (cin >> a >> b) {

		GCD();
		LCM();
		cout << gcd << " " << lcm << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			int n = sc.nextInt();
			int m = sc.nextInt();
			
			if ( n == m ) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int a, b;
  cin >> a >> b;

  if (a > 0) {
    cout << "Positive" << endl;
  } else if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;    
  } else {
    if ((b-a+1) % 2 == 0) {
      cout << "Positive" << endl;
    } else {
      cout << "Negative" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int x = sc.nextInt();
		int y = sc.nextInt();

		int result = 0;

		Boolean h = false;

		if (a + b > 2 * c) {
			h = true;
		} else {
			h = false;
		}

		int low = Math.min(x, y);
		int high = Math.max(x, y);

		int sub = high - low;

		if (h) {
			if(low == x) {
				if(b > 2 * c) {
					result = 2 * high * c;
				} else {
					result = 2 * low * c + sub * b;
				}

			} else if(low == y){
				if(a > 2 * c) {
					result = 2 * high * c;
				} else {
					result = 2 * low * c + sub * a;
				}
			}
		} else {
			result = a * x + b * y;
		}

		System.out.println(result);

		sc.close();

	}
}

Measured memory_bytes: 21844
while(1):
    try:
        a = [int(i) for i in input().split(",")]
        a.sort()
        pairs = []
        for i in set(a):
            count = 0
            for j in a:
                if j == i:
                    count += 1
            pairs.append(count)
        if 5 in pairs:
            print("full house")
        elif 4 in pairs:
            print("four card")
        elif 3 in pairs and 2 in pairs:
            print("full house")
        elif 3 in pairs:
            print("three card")
        elif pairs.count(2) == 2:
            print("two pair")
        elif 2 in pairs:
            print("one pair")
        elif [a[i+1] - a[i] for i in range(4)] == [1 for i in range(4)] or a == [1,10,11,12,13]:
            print("straight")
        else:
            print("null")
    except EOFError:
        break


Measured memory_bytes: 5600
#include <iostream>
typedef long long ll;
using namespace std;

ll MOD=1e9+7;

int main() {
    ll n, ans=1;
    cin >> n;
    for(int i=0; i<n; i++) {
        ans = (ans*(i+1))%MOD;
    }
    cout << ans << endl;

    return 0;
}

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

int n, ma, mb, m, a, b, c;
std::vector<std::vector<std::vector<int>>> dp;
std::vector<int> A, B, C;
int inf = 3000000;

int main() {
    std::cin >> n >> ma >> mb;
    A.assign(n+1, 0);
    B.assign(n+1, 0);
    C.assign(n+1, 0);
    for (int i = 1; i <= n; i++) {
        std::cin >> A[i] >> B[i] >> C[i];
    }
    dp.assign(n+1, std::vector<std::vector<int>>(401, std::vector<int>(401, inf)));
    dp[0][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int p = 0; p <=400; p++) {
            for (int k = 0; k <= 400; k++) {
                dp[i][p][k] = std::min(dp[i-1][p][k], dp[i][p][k]);
                if (dp[i-1][p][k] != inf) {
                    dp[i][p+A[i]][k+B[i]] = std::min(dp[i][p+A[i]][k+B[i]], dp[i-1][p][k] + C[i]);
                }
            }
        }
    }
    int ans = inf;
    for (int i = 1; i <= 400; i++) {
        for (int p = 1; p <= 400; p++) {
            if (i*mb == p*ma) {
                if (dp[n][i][p] < ans) {
                    ans = dp[n][i][p];
                }
            }
        }
    }
    if (ans == inf) {
        ans = -1;
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 27264
n,k=list(map(int,input().split()))
As=list(map(int,input().split()))
root=[1]
count=[0]*n
count[0]+=1

cnt=0
for _ in range(k):
    dis=As[root[-1]-1]-1
    if count[dis]!=0:
        cnt+=1
        break
    else:
        root.append(dis+1)
        count[dis]+=1
if cnt==1:
    first=root.index(As[root[-1]-1])
    print(root[(k-first)%(len(root)-first)+first])
else:
    print(root[-1])

Measured memory_bytes: 32376
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    S = list(input())
    ret = 0
    for i, a in enumerate(S):
        if i%2==0:
            #jibunnha g
            if a=='p':
                ret -= 1
        else:
            if a=='g':
                ret += 1
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9764
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local K, N = read.nn()
local A = {}
for i=0,N-1 do
    A[i] = read.n()
end
local ans = 10^7
for i=0,N-1 do
    local ed = i
    local st = (i+1)%N
    local d
    if st == 0 then
        d = K - ((A[st]) + (K - A[ed]))
    else
        d = K - (A[st] - A[ed])
    end
    ans = math.min(ans, d)
end
print(ans)

Measured memory_bytes: 22392
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
int main(void) {
  
  int k;
  string s;
  cin >> k >> s;
  
  s = (s.size() > k) ? s.substr(0, k) + "..." : s;
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	map<int, int> mp;
	string ans = "YES\n";
	for(int i=0, x; i<n; i++)
		cin >> x, (++mp[x] > 1? ans="NO\n": ans=ans);
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 9600
#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() {
  string s;
  cin >> s;

  // 1つ目
  int count = 1;
  vector<char> current = {s[0]};
  vector<char> tmp;
  // 2つ目以降
  for (int i = 1; i < s.size(); i++) {
    tmp.push_back(s[i]);
    // 同じなら区別ここで区切れないから次へ
    if (current.size() == tmp.size() && equal(current.begin(), current.end(), tmp.begin())) {
      continue;
    } else {
      current = tmp;
      tmp.clear();
      count++;
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 640
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=max(a[0]-x,0)
a[0]-=ans
for i in range(n-1):
  if a[i]+a[i+1]>x:
    ans+=a[i+1]+a[i]-x
    a[i+1]=x-a[i]
print(ans)

Measured memory_bytes: 85828
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
if int(math.sqrt(1+8*n))**2 == 1+8*n:
    for num in [i+1 for i in range(int(-1+math.sqrt(1+8*n))//2)]:
        print(num)
else:
    k = int((-1+math.sqrt(1+8*n))/2)
    tmp = k*(k+1)//2
    jud = n-tmp
    rem = k-jud+1
    ans = []
    for i in range(1,k+2):
        if i != rem:
            ans.append(i)
    for num in ans:
        print(num)

Measured memory_bytes: 79644
#include <algorithm>
#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main(){
 int N;
 cin>>N;
 N%=10;
 if(N==2||N==4||N==5||N==7|N==9) cout<<"hon"<<endl;
 else if(N==3) cout<<"bon"<<endl;
 else cout<<"pon"<<endl;
}

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

int main() {
    long long int a, b, c;
    cin >> a >> b >> c;
    if (c-a-b>0 && 0<(a*a+b*b+c*c-2*a*c-2*a*b-2*b*c)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll tmp = (c - a - b);
  if (tmp < 0) {
    cout << "No" << endl;
    return 0;
  }
  
  if ((tmp * tmp) > (4 * a * b)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3644
s =input()
r =int(s[0:2])
l =int(s[2:4])

if 0 <r <13:
    if 0 <l <13:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif 0 <l <13:
    if 0 <r <13:
        print('AMBIGUOUS')
    else:
        print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060