akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,num[N];
int main(){
	ll i,x;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>x;
		num[x]++;
	}
	for(i=1;i<=n;i++)
	{
		cout<<num[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 5144
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

min = as.min
as.push(min)
mins = []
(N+1).times do |i|
    mins.push(i) if as[i] == min
end

comp = -1
ans = 0
mins.each do |m|
    next if m <= comp + 1
    add = (m - comp - 3) / (K - 1) + 1
    ans += add
    comp += (K - 1) * add 
end

puts ans

Measured memory_bytes: 8068
import java.util.*;
import java.io.*;
class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String input = br.readLine();
    String[] split = input.split(" ");
    int a = Integer.parseInt(split[0]);
     int b = Integer.parseInt(split[1]);
    int x = 0;
    int y =0;
    if(a==b) {
      x=a;
      y=b;
    }
    else if(a>b) {
       x=a;
      y=b;
    } else {
      x=b;
      y=a;
    }
    int number =0;
    for(int i=1;i<=x;i++){
      number = number*10 + y;
    }
    System.out.println(number);
    
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<int,int>> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i].first >> v[i].second;
	}
	int res=0;
	for(int i=0;i<4;i++){
		vector<int> vv;
		for(int j=0;j<n;j++){
			int s=(i%2?1:-1);
			int t=(i>=2?1:-1);
			vv.push_back(v[j].first*s+v[j].second*t);
		}
		sort(vv.rbegin(), vv.rend());
		res=max(res,vv[0]-vv.back());
	}
	cout << res << endl;
}

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

int main(){
  string a,b;
  cin >> a >> b;
  vector<vector<int>> dp(a.size()+1, vector<int>(b.size()+1));

  for(int i=0; i <= a.size(); i++){
    dp[i][0] = 0;
  }
  for(int i=0; i <= b.size(); i++){
    dp[0][i] = 0;
  }

  for(int i=0; i < a.size(); i++){
    for(int j=0; j < b.size(); j++){
      if(a[i] == b[j]){
        dp[i+1][j+1] = dp[i][j] + 1;
      }else{
        dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
      }
    }
  }
  // cout << dp[a.size()][b.size()] << endl;

  int lcs = dp[a.size()][b.size()];
  string ans;
  int c = a.size(), d = b.size();
  while(c && d){
    if(a[c-1] == b[d-1]){
      ans.push_back(a[c-1]);
      c--;
      d--;
    }else if(dp[c-1][d] > dp[c][d-1]){
      c--;
    }else{
      d--;
    }
  }
  for(int i=lcs-1; i >=0; i--){
    cout << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 35584
// Crt. 2020-01-13  15:18:08

// C: Cookie Distribution
// 思维好题..
// 直接计算并不好算.考虑转化一下方法.
// 由于是将所有的c_i乘起来,所以我们可以考虑它的组合意义,即对于所有人,我选一个cookie作为它的`chosen cookie`,然后所有选择的方案数.
// 那么我们可以枚举每一天,有多少人将这一天分配的cookie作为他的`chosen cookie`,设有x_i个.
// 那么其他的反正也没有被选中,所以我可以随便给其他人,并且不用担心会有一个人拿到同一天的两个,方案数为:$\pro_{i=1}^{k}{C_{n-x_i}^{a_i-x_i}}$.
// 就可以用DP来解决.我们可以先将人的标号去掉,设f[i][j]表示前i天选了j个cookie.
// 最后的答案乘上$N!/\{\pro{x!}}$即可.

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 1003
using namespace std;
const int Mod = 1e9 + 7;

inline int MOD(int x) {
    return x >= Mod ? x - Mod : x;
}

inline int fsp(int x, int p = Mod - 2) {
    int res = 1;
    while (p) {
        if (p & 1) res = 1ll * res * x % Mod;
        x = 1ll * x * x % Mod, p >>= 1;
    } return res;
}

int n, K, a[N], f[30][N], fac[N], ifac[N];

inline int C(int x, int y) {
    return x < y ? 0 : 1ll * fac[x] * ifac[y] % Mod * ifac[x - y] % Mod;
}

int main() {
#ifdef LOCAL_JUDGE
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    cin >> n >> K;
    for (int i = 1; i <= K; ++i)
        scanf ("%d", a + i);

    for (int i = fac[0] = 1; i <= n; ++i)
        fac[i] = 1ll * fac[i - 1] * i % Mod;
    ifac[n] = fsp(fac[n]);
    for (int i = n; i >= 1; --i)
        ifac[i - 1] = 1ll * ifac[i] * i % Mod;

    f[0][0] = 1;
    for (int i = 1; i <= K; ++i)
        for (int j = 0; j <= n; ++j) if (f[i - 1][j])
            for (int k = 0; j + k <= n && k <= a[i]; ++k)
                f[i][j + k] = (1ll * f[i - 1][j] * C(n - k, a[i] - k) % Mod * ifac[k] + f[i][j + k]) % Mod;

    cout << 1ll * f[K][n] * fac[n] % Mod << endl;

	return 0;
}


Measured memory_bytes: 384
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define pll pair<ll , ll >
#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back

using namespace std;
const int maxn = 1000*100+5 ;
const ll inf = 9223372036854775807 ;

ll n , dp[101][maxn] , w[maxn] , v[maxn] , W , ans; 

int main()
{
	migmig ;
	cin>>n>>W ; 
	for(int i = 1 ; i <= n ; i ++ )
	{
		cin>>w[i]>>v[i] ; 
	}
	for(int i = 1 ; i  <= n ; i ++ )
	{
		for(int j = 1 ; j  <= W ; j ++ )
		{
			dp[i][j] = dp[i-1][j] ; 
			if(w[i] <= j)
			{
				dp[i][j] = max(dp[i][j] , v[i] + dp[i-1][j-w[i]]) ; 
			}
			ans = max(ans , dp[i][j]) ; 
			//cout<<"i = "<< i << " j = "<< j << " dp = "<<dp[i][j]<<endl ; 
		}
	}
	cout<<ans ; 
	

}
//////
////////
///////////




Measured memory_bytes: 78720
#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 = 1e9;

int main() {
  ll n, ans = 0, a, b, c, q;
  cin >> n;
  unordered_map<ll, ll> mp;
  rep(i, n) cin >> a, mp[a]++;
  cin >> q;

  for (auto m : mp) ans += m.second * m.first;

  rep(i, q) {
    cin >> b >> c;
    mp[c] += mp[b];
    ans += (c - b) * mp[b];
    mp.erase(b);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 6680
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#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; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M) {
      cin >> A[i][j];
    }
  }
  ll ans = inf;
  rep(i, 1 << N) {
    ll cost = 0;
    vector<ll> B(M, 0);
    rep(j, N) {
      if (i & (1 << j)) {
        cost += C[j];
        rep(k, M) {
          B[k] += A[j][k];
        }
      }
    }
    ll flag = 1;
    rep(j, M) {
      if (B[j] < X) {
        flag = 0;
        break;
      }
    }
    if (flag) ans = min(ans, cost);
  }
  ans = ans == inf? -1 : ans;
  cout << ans << endl;
}


Measured memory_bytes: 3644
h, w, d = map(int, input().split())
a=[list(map(int, input().split())) for i in range(h)]
q=int(input())
pos=[0]*(h*w)
cost=[[0]*(h*w//d+1) for i in range(d)]

for i in range(h):
    for j in range(w):
        pos[a[i][j]-1]=(i, j)
for i in range(d):
    j=0
    while (j+1)*d+i<w*h:
        p0=pos[j*d+i]
        p1=pos[(j+1)*d+i]
        cost[i][j]=abs(p0[0]-p1[0])+abs(p0[1]-p1[1])
        j+=1

sum_cost=[[0]*(h*w//d+2) for i in range(d)]
for i in range(d):
    for j in range(1, h*w//d+2):
        sum_cost[i][j]=sum_cost[i][j-1]+cost[i][j-1]

for i in range(q):
    l, r = map(int, input().split())
    li=(l-1)//d
    ri=(r-1)//d
    amari=(l-1)%d
    print(sum_cost[amari][ri]-sum_cost[amari][li])
   


Measured memory_bytes: 74204
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();

		// CとDの最大公約数
		long gcd = gcd(C, D);
		// CとDの最小公倍数
		long lcm = (C * D) / gcd;
		// System.out.println("gcd=" + gcd + " lcm=" + lcm);

		// B以下のCまたはDで割り切れる個数からCとDで割り切れる重複個数を引く
		// B以下の割り切れる個数を求める
		long bCnt = (B / C) + (B / D) - (B / lcm);
		
		// A未満のCまたはDで割り切れる個数からCとDで割り切れる重複個数を引く
		// A未満の割り切れる個数が求められる
		long a = A - 1;
		long aCnt = (a / C) + (a / D) - (a / lcm);
		// System.out.println("bCnt=" + bCnt + " aCnt=" + aCnt);

		// BからB以下の割り切る個数を引く = B以下の割れない個数
		// A未満の割り切れる個数を引く = A未満の割れない個数
		// B以下の割れない個数からA未満の割れない個数を引く
		System.out.println((B - bCnt) - (a - aCnt));
	}

	// 最大公約数
    public static long gcd(long x, long y) {
        // System.out.println("x = " + x + " y = " + y);
        if(y == 0) return x;
        else return gcd(y, x % y);
	}

	// 最小公倍数
    public static long lcm(long x, long y) {
        return (x * y) / gcd(x, y);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

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

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll dp[62][3];

int main(void){
	ll n;
	int i,j,v,d;
	fill(dp[0],dp[62],0ll);
	dp[61][0] = 1ll;
	cin >> n;
	for(i=60; i>=0; --i){
		for(j=0; j<3; ++j){
			v = ((n >> i) % 2) + j * 2;
			for(d=0; d<3; ++d){
				if(v<d){
					continue;
				}
				add_mod(dp[i][min(v-d,2)],dp[i+1][j]);
			}
		}
	}
	cout << ((dp[0][0]+dp[0][1]+dp[0][2])%MOD) << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{

    class Program
    {

        static void Main(string[] args)
        {
            
            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int a = int.Parse(str[1]);
            int b = int.Parse(str[2]);

            int sum = 0;

            string val;
            long ans = 0;

            for(int i = 1; i <= n; i++)
            {
                val = i.ToString();
                sum = 0;                
                for(int j = 0; j < val.Length; j++)
                {
                    sum += int.Parse(val[j].ToString());   
                    
                    if(sum > b)
                    {
                        break;
                    }
                    
                    if(j == val.Length - 1 && sum >= a && sum <= b)
                    {                       
                        ans += i;
                    }
                }              
            }


            Console.WriteLine(ans);



        }

    }

}
    


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

#define R register
#define ll long long
#define sum(a, b, mod) (((a) + (b)) % mod)

const int mod = 1e9 + 7;
const int MaxN = 3e5 + 10;

char s[MaxN];
ll n, f[MaxN][3][3];
void add(ll &a, ll b) {a += b, ((a > mod) ? (a -= mod) : 0); }

int main()
{   
    f[0][0][0] = 1;
    scanf("%s", s + 1), n = strlen(s + 1);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(s[i + 1] != '0')
                {
                    if(k)
                        add(f[i + 1][j][k - 1], f[i][j][k]);
                    else add(f[i + 1][std::min(j + 1, 2)][k], f[i][j][k]);
                }
                if(s[i + 1] != '1')
                {
                    if(k == 2)
                        add(f[i + 1][j][1], f[i][j][k]);
                    else add(f[i + 1][j][k + 1], f[i][j][k]);
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 0; i < 3; i++)
        for(int j = 0; j <= i; j++)
            add(ans, f[n][i][j]);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 21632
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main{
    public static void main(String[] args){
        Scanner sc1 = new Scanner(System.in);
        int n = sc1.nextInt();
        String a = sc1.next();
        String b = sc1.next();
        String c = sc1.next();
        
        int count = 0;
        for(int i = 0; i < n; i++){
            Set<String> set = new TreeSet<>();
            set.add(a.substring(i, i + 1));
            set.add(b.substring(i, i + 1));
            set.add(c.substring(i, i + 1));
            count += set.size() - 1;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
    int N;
    // 2乗の和と和
    int sum2=0,sum=0;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i< N; i++) {
        cin >> a.at(i);
        sum2 += a.at(i)*a.at(i);
        sum += a.at(i);
    }
    int p = floor((double)sum/N);
    cout << sum2+min(p*p*N-2*p*sum,(p+1)*(p+1)*N-2*(p+1)*sum) << endl;
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		//
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		String[] inputStr = null;
		int[] inputInt = null;
		try {
			while(true) {
				inputStr = (input.readLine()).split("\\s");
				inputInt = new int[inputStr.length];
				for (int index = 0; index < inputInt.length; index++) {
					inputInt[index] = Integer.parseInt(inputStr[index]);
				}
				if(inputInt[0] == 0 && inputInt[1] == 0) {
					break;
				}
				for (int row = 0; row < inputInt[0]; row++) {
					for (int col = 0; col < inputInt[1]; col++) {
						if (row != 0 && row != (inputInt[0] -1) && col != 0 && col != (inputInt[1] -1)) {
							System.out.print(".");
						} else {
						    System.out.print("#");
						}
					}
					System.out.println();
				}
				System.out.println();
			}

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}


	}

}



Measured memory_bytes: 30968
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define maxn 8000
using namespace std;
long long mod=1000000007;
long long a[maxn];
long long b[maxn];
int n;
int p[maxn];
bool vis[maxn];
int inc[maxn];
vector<int> c[maxn];
long long step[maxn];
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        c[i].push_back(i);
        inc[i]=i;
    }
    for(int i=1;i<=n;i++) {
        scanf("%d",&p[i]);
        if(p[i]!=-1) {
            int x=inc[i];
            int y=inc[p[i]];
            if(x!=y) {
                for(auto t:c[x]) {
                    c[y].push_back(t);
                    inc[t]=y;
                }
                c[x].clear();
            }
        }
    }
    long long ck=0;
    for(int i=1;i<=n;i++) {
        if(inc[i]==i && p[i]!=-1) {
            ck++;
        }
    }
    long long k=0;
    a[0]=1;
    step[0]=1;
    long long ans=1;
    for(int i=1;i<=n;i++) {
        if(p[i]==-1) {
            k++;
            step[k]=(step[k-1]*(n-1))%mod;
            for(int j=0;j<=n;j++) {
                b[j]=(b[j]+a[j])%mod;
                b[j+1]=(b[j+1]+1ll*c[i].size()*a[j])%mod;
            }
            for(int j=0;j<=n;j++) {
                a[j]=b[j];
                b[j]=0;
            }

        }
    }
    ans=(step[k]*(n-ck))%mod;
    for(int i=1;i<=n;i++) {
        if(p[i]==-1) {
            long long tp=c[i].size()-1;
            ans=(ans-tp*step[k-1])%mod;
            ans+=mod;
            ans%=mod;
        }
    }
    long long fac=1;
    for(int i=2;i<=k;i++) {
        fac=fac*(i-1)%mod;
        long long tp=(a[i]*fac)%mod;
        ans=(ans-step[k-i]*tp)%mod;
        ans+=mod;
        ans%=mod;
    }
    printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 4332
#include<stdio.h>

typedef struct tree{
  int p,l,r;
}t;
t T[100000];
 
int main(){
  int n,i,j,k,id,c,a,b;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    for(j=0;j<k;j++){
      scanf("%d",&c);
      T[c].p=id;
      if(j==0)
    T[id].l=c;
      else
    T[a].r=c;
      a=c;
    }
  }
  for(i=0;i<n;i++){
    id=0;
    k=0;
    a=T[i].p;
    b=T[i].l;
    while(a!=-1){
      k++,a=T[a].p;
    }
    printf("node %d: parent = %d, depth = %d, ",i,T[i].p,k);
    if(T[i].p==-1)
      printf("root, [");
    else if(T[i].l!=-1)
      printf("internal node, [");
    else
      printf("leaf, [");
    while(b!=-1){
      if(id==0){
    printf("%d",T[i].l);
    id=1;
      }
      else
    printf(", %d",b);
      b=T[b].r;
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 1784
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()

MP={}
for i in LI():
    if not i in MP: MP[i] = 0
    MP[i] += 1

Q=II()

res = 0
for i, j in MP.items():
    res += i*j

arr = []
for _ in range(Q):
    B, C = LI()
    if not B in MP: MP[B] = 0
    if not C in MP: MP[C] = 0
    diff = MP[B]*C - MP[B]*B
    MP[C] += MP[B]
    MP[B] = 0
    res += diff
    arr.append(res)

for i in arr: print(i)


Measured memory_bytes: 24156
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iomanip>
#include <string>
#include <sstream>
#include  <list>
//#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
/*
int cmp(shi a,shi b)
{
    return a.x<b.x;
}
long long cmd(long long a, long long  b)
{
    return a > b;
}*/


int main()
{
    int a,b,c;
    while(cin >>a >>b>>c){
        int ma =max(a,max(b,c));
        if(ma==b){
            if(a<=c)
                cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }

    return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        string S = cin.next();

        char a = S[0];
        int aCount = 1;

        char b = '\0';
        int bCount = 0;

        bool flag = true;

        for (int i = 1; i < 4; ++i)
        {
            if (S[i] != a)
            {
                if (b == 0)
                {
                    b = S[i];
                    ++bCount;
                }
                else
                {
                    if (S[i] != b)
                    {
                        flag = false;
                        break;
                    }
                    else
                    {
                        ++bCount;
                    }
                }
            }
            else
            {
                ++aCount;
            }
        }

        bool ansFlag = flag;

        if (ansFlag)
        {
            ansFlag = (aCount == 2 && bCount == 2);
        }

        WriteLine(ansFlag? "Yes" : "No");
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N;
    cin >> N;
    FOR(h, 3501, 1)
    {
        FOR(n, 3501, 1)
        {
            ll A = N * h * n;
            ll B = 4 * h * n - N * (n + h);
            if (B <= 0)
                continue;
            if (A % B == 0)
            {
                cout << h << " " << n << " " << A / B << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
N, WW = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]
W, V = zip(*l)
M = [{} for i in range(N + 1)]
def cal(i, w):
  if w in M[i]:
    return M[i][w]
  if i == N:
    v = 0
  elif w < W[i]:
    v = cal(i + 1, w)
  else:
    v = max(cal(i + 1, w), cal(i + 1, w - W[i]) + V[i])
  M[i][w] = v
  return v

print(cal(0, WW))

Measured memory_bytes: 10932
#include<bits/stdc++.h>
using namespace std;
string s;
int Array[26];
int main(){
	cin>>s;
	int l=s.size();
	for(int i=0;i<l;i++)
		Array[s[i]-'a']=1;
	for(int i=0;i<26;i++){
			if(Array[i]==0){
				s+=('a'+i);
				cout<<s<<"\n";
				return 0;
			}
	}
	int i=l-1;
	while(i>=0){
		for(int j=s[i]-'a'+1;j<26;j++){
			if(Array[j]==0){
				char c='a'+j;
				s=s.substr(0,i)+c;
				cout<<s<<"\n";
				return 0;
			}
		}
		Array[s[i]-'a']=0;
		i--;
	}
		cout<<-1<<"\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct Node {
    Node* parent;
    Node* left;
    Node* right;
    int key;
};

Node * NIL = NULL;
Node * ROOT = NIL;

void Inorder (Node* n) {
    if (n == NIL) return;
    Inorder(n->left);
    printf(" %d", n->key);
    Inorder(n->right);
}
void Preorder (Node* n) {
    if (n == NIL) return;
    printf(" %d", n->key);
    Preorder(n->left);
    Preorder(n->right);
}

void insert (Node* n) {
    Node * r = ROOT;
    Node * t;
    while (r != NIL) {
        t = r;
        if (n->key < r->key) {
            r = r->left;
        }
        else {
            r = r->right;
        }
    }
    n->parent = t;

    if (ROOT == NIL) {
        ROOT = n;
    }
    else if(n->key < t->key) {
        t->left = n;
    }
    else {
        t->right = n;
    }
}

bool find(int key) {
    Node* t = ROOT;
    while (t != NIL) {
        if ( t->key == key) {
            return true;
        }
        else if (key < t->key) {
            t = t->left;
        }
        else {
            t = t->right;
        }
    }
    return false;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        char s[100];
        scanf("%s", s);
        if (s[0] == 'i') {
            int key;
            scanf("%d", &key);
            Node* n = (Node *) malloc(sizeof(Node));
            n->key = key;
            n->parent = n->left = n->right = NIL;
            insert(n);
        }
        else if (s[0] == 'p') {
            Inorder(ROOT);
            printf("\n");
            Preorder(ROOT);
            printf("\n");
        }
        else if (s[0] == 'f') {
            int key;
            scanf("%d", &key);
            if (find(key)) {
                printf("yes\n");
            }
            else {
                printf("no\n");
            }
        }
    }
}

Measured memory_bytes: 21324
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<ll,ll> mp;
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    rep(i,6){
        cin>>a;
        mp[a]++;
    }
    rrep(i,1,5){
        if(mp[i]>=3){
            Cout("NO");
            return 0;
        }
    }
    Cout("YES");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=1e6+69;
const int BASE=2e3;
const int mod = 998244353;
const int INF = 1e9;
int m,k,n,l,q;
map<int,int> check;
int a[MAXN];
int ans[MAXN];
string s;
int luythua(int x, int y){
    if(y==0)return 1;
    if(y==1)return x%mod;
    int k = luythua(x,y/2);
    if(y%2==1)return k*k%mod*(x%mod)%mod;
    return k*k%mod;
}
signed main(){                                                                                                                                                                                                                                                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>k;
    if(m%n==0||k%n==0){
        cout<<"OK";
        return 0;
    }
    m/=n;
    k/=n;
    if(m==k){
        cout<<"NG";
            return 0;
    }
    cout<<"OK";
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n;
  cin >> n;
  vector<double> v(n);
  rep(i,n){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double temp = v[0];
  rep(i,n-1){
    temp = ((temp + v[i+1])/2);
  }
  
  cout << fixed << setprecision(10) << temp;
  
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};

int main(){
  ll N,K,r,s,p,sum=0;
  string S;
  cin>>N>>K>>r>>s>>p>>S;
  vector<string> ans(K,"");
  for(ll i=0;i<N;i++){
    ans[i%K]+=S[i];
  }
  for(ll i=0;i<K;i++){
    for(ll j=0;j<ans[i].size();j++){
      if(ans[i][j]=='r'){
        sum+=p;
        if(ans[i][j+1]=='r') j++;
      }else if(ans[i][j]=='s'){
        sum+=r;
        if(ans[i][j+1]=='s') j++;
      }else{
        sum+=s;
        if(ans[i][j+1]=='p') j++;
      }
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
using namespace std;
const int mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll a,b;
	while(cin >> a >> b){
		ll g = __gcd(a,b);
		int ans = 1;
		for(int i=2;i<=sqrt(g);i++){
			if(g%i==0){
				ans++;
				while(g%i==0)
					g /= i;
			}
		}
		if(g>1)ans++;
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define INF INT_MAX
#define INFLL _I64_MAX
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
int main(void)
{
	string s;

	cin>>s;

	s[3]='8';

	cout<<s<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
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; }

int main() {
	
	
	
	int n,w_max; cin >> n >> w_max;
	
	vector<ll> w(n),v(n);
	rep(i,n) cin >> w[i] >> v[i];
	//sort(a.begin(),a.end());
	
	
	vector<vector<ll>> val(n+1,vector<ll>(w_max+1,0));
	
	
	
	rep(i,n){
		rep(j,w_max+1){
			
			if(j-w[i]>=0){ //想定の容量より重さが軽ければ
				chmax(val[i+1][j],val[i][j-w[i]]+v[i]); //入れるものの重さ分軽い袋から引き継ぎ
			}
			chmax(val[i+1][j],val[i][j]); //同じ重さの袋から引き継ぎ
			
		}
	}

	cout << val[n][w_max] << '\n';
	return 0;

}

Measured memory_bytes: 80256
n,k = map(int, input().split())
A = list(map(int, input().split()))
a = 0
for i in range(k):
    a += A[i]
ans = a
for i in range(k,n):
    a = a-A[i-k] + A[i]
    if ans < a: print("Yes")
    else: print("No")
    ans = a

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

#define mod 1000000007
#define limit 200001
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i = 0; i < n; i++)
#define max(a,b) {if(a>b){return a;}return b;}
#define min(a,b) {if(a<b){return a;}return b;}
int up_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_int(const void *a, const void *b){return *(int*)b - *(int*)a;}
int up_char(const void *left, const void *right) {return strcmp((char *)left,(char *)right);}
int down_char(const void *left, const void *right) {return strcmp((char *)right,(char *)left);}

int main(){
    ll ans = 0;
    int flag = 0;
    int i,j,n,q,a[200000],b[200000],c[200000];
    ll times[200000];
    
    scanf("%d",&n);
    for(i = 0; i < n; i++) scanf("%d",&a[i]);
    scanf("%d",&q);
    for(i = 0; i < q; i++) scanf("%d %d",&b[i],&c[i]);
    
    for(i = 0; i < n; i++) times[a[i]]++; // 個数を数える
//    for(i = 1; i <= n; i++) printf("times %d ... %d\n",i,times[i]);
    for(i = 1; i <= 100000; i++) ans += (times[i] * i);
    
    for(i = 0; i < q; i++){
        if(times[b[i]] * (c[i] - b[i]) != 0){
            ans += (times[b[i]] * c[i]);
            ans -= (times[b[i]] * b[i]);
            times[c[i]] += times[b[i]];
            times[b[i]] = 0;
            printf("%lld\n",ans);
        }else{
            printf("%lld\n",ans);
        }
    }
    // for(i = 1; i <= n; i++) ans += (times[i] * i);
    // for(i = 1; i <= n; i++) printf("times %d ... %d\n",i,times[i]);
    // printf("%lld\n",ans);
    return 0;
}




Measured memory_bytes: 3708
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s1, s2, s3;
	char x, y, z;
	cin >> s1 >> s2 >> s3;

	x = s1[0] - 32;
	y = s2[0] - 32;
	z = s3[0] - 32;

	cout << x << y << z << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	String [] digit = {"0111111","0000110","1011011","1001111","1100110",
			"1101101","1111101", "0100111","1111111","1101111"};
	
	private void doit() {
		while (true) {
			int n = sc.nextInt();
			if(n == -1) break;
			StringBuilder nowstate = new StringBuilder("0000000");
			while(n-- > 0){
				int num = sc.nextInt();
				String numstr = digit[num];
				StringBuilder sb = new StringBuilder();
				for(int i = 0; i < numstr.length(); i++){
					if(numstr.charAt(i) == nowstate.charAt(i)){
						sb.append(0);
					}
					else{
						sb.append(1);
					}
				}
				System.out.println(sb.toString());
				nowstate = new StringBuilder(numstr);
			}
		}
	}


	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 20724
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[123456] = {};

    Scs(s);

    int cnt = 0;
    for( int i = 0; s[i]; i++ ){
        cnt += ( s[i] == '0' ? 1 : -1 );
    }

    printf("%d\n", strlen(s) - abs(cnt) );

    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <numeric>

using namespace std;

int main(int argc, char** argv){
    int N;
    cin >> N;
    vector<int> p;
    vector<int> n;
    int zeros = 0;
    long long sum = 0;
    for (int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        if (tmp > 0){
            p.push_back(tmp);
            sum += tmp;
        }
        if (tmp < 0){
            n.push_back(tmp);
            sum -= tmp;
        }
        if (tmp ==0) zeros++;
    }

    int M = n.size();

    if (M%2 == 1 && zeros == 0){
        sort(p.begin(), p.end());
        sort(n.begin(), n.end());
        if (!p.empty()){
            long long tmp = p[0] + n[M-1];
            if (tmp < 0) sum -= 2*p[0];
            else sum += 2*n[M-1];
        } else {
            sum += 2*n[M-1];
        }
    }

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 1020
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
  X = []
  X.append(A[i])
  X.append(B[i])
  X.append(C[i])
  X = set(X)
  ans += len(X) - 1
  
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
 
int main() {
	int n; cin >> n;
	int s, l;
	char c;
   
  while(n--) {
     cin >> s >> c >> l;
    double h = s*30.0 + l/2.0, m = l*6;
     
    int ang = abs(h - m);
    if(ang > 180) ang = 360 - ang;
    if(0 <= ang && ang < 30) {
      cout << "alert" << endl;
    }
    else if(90 <= ang && ang <= 180) {
      cout << "safe" << endl;
    }
    else cout << "warning" << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3076
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

# reffer to: https://qiita.com/dn6049949/items/afa12d5d079f518de368
class SegmentTree:
    # 初期化処理
    # f : SegmentTreeにのせるモノイド
    # default : fに対する単位元
    def __init__(self, size, f=lambda x,y : x+y, default=0):
        self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする
        self.default = default
        self.data = [default]*(self.size*2) # 要素を単位元で初期化
        self.f = f

    def update(self, i, x):
        i += self.size
        self.data[i] = x
        while i > 0:
            i >>= 1
            self.data[i] = self.f(self.data[i*2], self.data[i*2+1])

    # [l, r)
    def query(self, l, r):
        l += self.size
        r += self.size
        lres, rres = self.default, self.default
        while l < r:
            if l & 1:
                lres = self.f(lres, self.data[l])
                l += 1

            if r & 1:
                r -= 1
                rres = self.f(self.data[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res


def main():
    N = I()
    A = IR(N)

    LDS = [-A[0]]
    for ai in A[1:]:
        if -LDS[-1] >= ai:
            LDS.append(-ai)
        else:
            LDS[bisect_right(LDS, -ai)] = -ai

    print(len(LDS))

if __name__ == '__main__':
    main()

Measured memory_bytes: 87604
n,h = map(int,input().split())
A = []
B = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

#aの最大値を求める。
maxa = max(A)

#maxaのうち、bが最小の刀を求める。これを刀ｓとする。刀ｓを取り除く
minb = 10**10
s = 0
for i in range(n):
    if A[i] == maxa and B[i] < minb:
        minb = B[i]
        s = i
B.pop(s)

#bを降順に並べ、maxaより大きいbは投げつける
B.sort(reverse = True)
for i in range(len(B)):
    if B[i] > maxa:
        h = h - B[i]
        ans += 1
        if h <= 0:
            print(ans)
            exit()
    else:
        break

#まずsを投げてからaで割る
h = h - minb
ans += 1
if h <= 0:
    print(ans)
else:
    ans += (h+(maxa-1)) // maxa
    print(ans)

Measured memory_bytes: 11380
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1):
  for g in range(N//G + 1):
    b = max(0, (N - r*R - g*G) // B)
    if r*R + g*G + b*B == N:
      ans += 1
print(ans)


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

/*
 * */
int main() {
    int N;
    cin >> N;
    int L[N];
    rep(i, N) cin >> L[i];
    sort(L, L + N, greater<int>());

    int sum = 0;
    int max;
    rep(i,N){
        if(i == 0){
            max = L[0];
        }else{
            sum += L[i];
        }
    }
    string ans;
    if(max < sum){
        ans = "Yes";
    }else{
        ans = "No";
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int point = 0;
		for (int i = 0; i < arr.length; i++) {
			char me;
			if (i % 2 == 0) {
				me = 'g';
			} else {
				me = 'p';
			}
			if (arr[i] < me) {
				point++;
			} else if (arr[i] > me) {
				point--;
			}
		}
		System.out.println(point);
	}
}


Measured memory_bytes: 27208
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAX 100010

int N;
vector< pair<int, int> > G[MAX];
vector<int> visited(MAX, 0);

int main(){
  cin >> N;
  vector<int> node(N,0);
  vector<int> edge(N-1);
  int maxNode = 0;
  for(int i = 0; i < N-1; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    node[a]++;
    node[b]++;
    G[a].push_back(make_pair(i, b));
    G[b].push_back(make_pair(i, a));
    int tmpMax = max(node[a], node[b]);
    maxNode = max(maxNode, tmpMax);
  }
  int K = maxNode;
  visited[0] = 1;
  queue<int> q;
  q.push(0);
  int color = 1;
  node[0] = 0;
  while(!q.empty()){
    int u = q.front();
    q.pop();
    int tmpColor = node[u];
    int i = 1;
    for(auto x: G[u]){
      int num = x.first;
      int next = x.second;
      if(visited[next] == 1){
	continue;
      }
      edge[num] = tmpColor + i;
      if(edge[num] > K){
	edge[num] -= K;
      }
      node[next] = edge[num];
      visited[next] = 1;
      q.push(next);
      i++;
    }
  }
  cout << K << endl;
  for(int i = 0; i < N-1; i++){
    cout << edge[i] << endl;
  }
}


Measured memory_bytes: 7808
import java.util.*;
import java.lang.*;
import java.math.*;
public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			int q = sc.nextInt();

			if ((n | q) == 0) {
				break;
			}

			String era[] = new String[n];
			int eb[] = new int[n];
			int w[] = new int[n];

			for (int i = 0; i < n; i++) {
				era[i] = sc.next();

				eb[i] = sc.nextInt();
				w[i] = sc.nextInt();
			}
			
			for(int i = 0; i< q;i++){
				int query = sc.nextInt();
				
				int m = -1;
				for(int j = 0; j < n ; j++){
					if(w[j]>=query && query>w[j] - eb[j]){
						m = j;
						break;
					}
				}
				if(m == -1){
					System.out.println("Unknown");
				}
				else{
					System.out.println(era[m] + " "+-(w[m]-eb[m]-query));
				}
			}

		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int N;
  string s;
  cin >> N >> s;
  int ans = 1;
  char key = s[0];
  rep(i, s.size()) {
    if(i == 0) continue;
    if(s[i] == key) {
      continue;
    } else {
      ans++;
      key = s[i];
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3716
n = int(input())
lst = [0 for _ in range(n)]

for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            num = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + i * k
            try:
                lst[num - 1] += 1
            except IndexError:
                pass
for num in lst:
    print(num)

Measured memory_bytes: 9296
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int A = sc.nextInt();

        int x = N%500;
        if(x <= A){
            System.out.println("Yes");
        }else{
            System.out.print("No");
        }
    }
}

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

int main() {
  int a,b;
  cin >> a >>b;
  if(a >b){
  for(int i=0; i<a ;i++){
    cout << b;
    if(i==a-1) cout <<""<<endl;
  }
  }
  else{
  for(int i=0; i<b ;i++){
    cout << a;
    if(i==b-1) cout <<""<<endl;
  }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};



int main(){
    Stream io;

    ll a, b, c, d;
    io.read(a, b, c, d);

    ll ans = a * c;
    if(ans < b * c) ans = b * c;
    if(ans < a * d) ans = a * d;
    if(ans < b * d) ans = b * d;

    cout << ans;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl;
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl; 
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(v.begin(),v.end());
    double now = v[0];
    for(int i=1; i<n; i++){ 
        now += v[i];
        now /= 2.0;
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 3808
#include <stdio.h>
 
int main (void) {
  int i, a[100], count=0;
  int N;
  
  scanf("%d", &N);
  for(i=0; i<N; i++) {
    scanf("%d", &a[i]);
  }

  
  for(i=0; i<N; i += 2) {
    if (a[i] % 2 == 1) {
      count += 1;
    }
  }
  
  printf("%d", count);
  
  return 0;
}

Measured memory_bytes: 1732
n=int(input())
s=[0 if i=='W' else 1 for i in input()]
a=[0]*n
#print(s)
a[0]=sum(s[1:])
for i in range(n-1):
  if s[i+1]==1 and s[i]==1:
    a[i+1]=a[i]-1
  elif s[i+1]==1 and s[i]==0:
    a[i+1]=a[i]
  elif s[i+1]==0 and s[i]==1:
    a[i+1]=a[i]
  elif s[i+1]==0 and s[i]==0:
    a[i+1]=a[i]+1
print(min(a))

Measured memory_bytes: 17936
import sys
S = input()
T = input()
a = []
b = []
i = 0
while i < len(S):
  if S[i] in a:
    if T[i] in b and a.index(S[i]) == b.index(T[i]):
      pass
    else:
      print('No')
      sys.exit()
  else:
    if T[i] in b:
      print('No')
      sys.exit()
    else:
      a.append(S[i])
      b.append(T[i])
  i += 1
print('Yes')

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {


	public static void main (String[] args)  {

		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int n = sc.nextInt();
		
		
		int sum = 0;
		for (int i=0;i<n;i++) {
			sum+=sc.nextInt();
		}
		
		System.out.println(sum>=h ? "Yes" : "No");
		
	}
	
	
}


Measured memory_bytes: 46884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll n,k; cin >> n >> k;
    vector<ll> a(n+1,0);
    REP(i,n) cin >> a[i+1];
    FOR(i,k+1,n){
        if (a[i-k]<a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4840