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

const int nMax = 1e6;
const int mod = 1e9 + 7;

struct Sieve
{
	int n;
	vector<int> f, primes;
	Sieve(int n = 1) :n(n), f(n + 1)
	{
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; ++i) {
			if (f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if (!f[j]) f[j] = i;
			}
		}
	}
	bool isPrime(int x) { return f[x] == x; }
	vector<int> factorList(int x)
	{
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<pair<int,int>> factor(int x)
	{
		vector<int> fl = factorList(x);
		if (fl.size() == 0) return {};
		vector<pair<int,int>> res(1, pair<int,int>(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

ll modPow(ll a, ll x, ll mod)
{
	ll res = 1;
	while (0 < x) {
		if (x & 1) res = res * a%mod;
		a = a * a%mod;
		x >>= 1;
	}
	return res;
}

int main()
{

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

	Sieve sieve(nMax);
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		vector<pair<int, int>> f = sieve.factor(a[i]);
		for (const auto& item : f) mp[item.first] = max(mp[item.first], item.second);
	}

	ll lcm = 1;
	for (const auto& item : mp) {
		for (int i = 0; i < item.second; i++) {
			lcm *= item.first % mod;
			lcm %= mod;
		}
	}

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll b = lcm * modPow(a[i], mod - 2, mod) % mod;
		ans = (ans + b) % mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000




int main(){
    
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	for(int i=0;i<4;i++){
		string ans;
		if(i==0)ans="SS";
		if(i==1)ans="WW";
		if(i==2)ans="SW";
		if(i==3)ans="WS";
		
		for(int j=1;j<N+1;j++){
			char c = S[j%N];
			if(ans.back()=='W'){
				if(c=='o')c='x';
				else c='o';
			}
			if(c=='o'){
				ans += ans[ans.size()-2];
			}
			else{
				if(ans[ans.size()-2]=='W')ans+='S';
				else ans+='W';
			}

		}
		if(ans[0]==ans[N]&&ans[1]==ans[N+1]){
			cout<<ans.substr(0,N)<<endl;
			return 0;
		}
	}
	
	cout<<-1<<endl;
		
	
    return 0;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

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

int main() {
  string s;
  cin >> s;
  int cnt0 = 0, cnt1=0;
  for(char c: s){
    if (c=='0') cnt0++;
    if (c=='1') cnt1++;
  }
  
  cout << min(cnt0, cnt1)*2 << endl;

}


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

using namespace std;

int main() {
    
    long long x;
    cin >> x;

    long long a = x / 500;
    x %= 500;
    long long b = x / 5;

    cout << a * 1000 + b * 5 << "\n";
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}


int main(){
  int N; cin >> N;
  string S, T; cin >> S >> T;
  for (int i = 0; i < N; i++){
    cout << S[i] << T[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define LL long long
#define db double

using namespace std;


typedef pair<int, int> pii;
#define X first
#define Y second
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool fg = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            fg = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (fg) {
        x = -x;
    }
}

const int MAXN = 100100;
const int MAXE = 400;
const int INF = 0x3f3f3f3f;

int n, T, m;
double A;
double h[MAXN];
const double eps = 0.006;

int p[MAXN], s[MAXN], out[MAXN];

#define chk(x) (x >= 1 && x <= n)

int change(string S) {
	int len = (int) S.size();
	int x = 0;
	for(int i = 0; i < len; i++) {
		x = x * 10 + S[i] - '0';
	}
	return x;
}

string v[MAXN], ans[MAXN];
vector<pii> city;
map<pii, int> mmp; 
int tot[MAXN]; 

signed main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++) {
		read(p[i]), read(s[i]);
		city.push_back(make_pair(s[i], p[i])); 
		mmp[make_pair(s[i], p[i])] = i;
	}
	sort(city.begin(), city.end());
	for(int i = 0; i < (int) city.size(); i++) {
		string str = "";
		int y = city[i].Y;
		int cnt = 0;
		while(y) {
			str += (char) (y % 10 + '0');
			y /= 10;
			cnt++;
		}
		cnt = 6 - cnt;
		while(cnt--) v[i] += '0';
		reverse(str.begin(), str.end());
		v[i] += str;
		y = ++tot[city[i].Y];
		cnt = 0;
		str = "";
		while(y) {
			str += (char) ((y % 10) + '0');
			y /= 10;
			cnt++;
		}
		cnt = 6 - cnt;
		while(cnt--) v[i] += '0';
		reverse(str.begin(), str.end());
		v[i] += str;
		ans[mmp[city[i]]] = v[i];
	}
	for(int i = 1; i <= m; i++) cout << ans[i] << endl;
	return 0;
}
/*
2 3
1 32
2 63
1 12
*/

Measured memory_bytes: 17140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final Deque<String> numbers = new ArrayDeque<String>(1000000);
 
        final int n = Integer.parseInt(reader.readLine());
 
        String line;
        for (int i = 0; i < n; ++i) {
            line = reader.readLine();
            if ('i' == line.charAt(0)) {
                numbers.offerFirst(line.substring(7));
 
            }else if ('F' == line.charAt(6)) {
                numbers.remove();
 
            } else if ('L' == line.charAt(6)) {
                numbers.removeLast();
 
            } else {
                numbers.removeFirstOccurrence(line.substring(7));
            }
        }
 
        final StringBuilder answer = new StringBuilder();
        answer.append(numbers.poll());
        while (numbers.size() != 0) {
            answer.append(" ").append(numbers.poll());
        }
 
        System.out.println(answer.toString());
    }
}


Measured memory_bytes: 163104
#include<stdio.h>
int n,m,d[110];
int f(int l,int r){//printf("%d %d ",l,r);
  if(r-l<1)return l;
  int mid=(l+r)/2,c=1,i,s=0;
  for(i=0;i<n;i++){
    if(s+d[i]>mid){
      s=0;
      c++;
    }
    s+=d[i];
    if(mid<d[i]){
      c=1000;
      break;
    }
  }//printf("%d\n",c);
  return c>m?f(mid+1,r):f(l,mid);
}
int main(){
  int i;
  while(scanf("%d %d",&m,&n),m||n){
    for(i=0;i<n;i++)scanf("%d",&d[i]);
    printf("%d\n",f(0,1500000));
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int M=200010;
int a[M],b[M],n,i,l,r;

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

signed main(){
    n=read();
    
    for(i=1;i<=n;i++)
        a[i]=read(),b[i]=read();
        
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    
    if(n%2==1){
        l=a[(n+1)/2];
        r=b[(n+1)/2];
    }
    else{
        l=a[n/2]+a[n/2+1];
        r=b[n/2]+b[n/2+1];
    }
    
    writeln(r-l+1);
	
	return 0;
}

Measured memory_bytes: 6724
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>


#define ll long long
//#define int ll
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

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

const int N = 600 + 1;

int n ;
int d[N];
ll ans = 0;
main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 1 ;i <= n;i++){
		cin >> d[i];
		for(int j = 1 ; j < i ; j++){
			ans += d[i] * d[j];
		}
	}	
	cout << ans;
}

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

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

  sort(a.rbegin(), a.rend());
  ll ans = 0;
  int t = n - 1;
  rep(i, n) {
    int lim = 2;
    if (i == 0) lim = 1;
    rep(j, lim) {
      if (t > 0) {
        ans += a[i];
        t--;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4008
fn main() {
    let input = read::<String>();
    let expr: Vec<&str> = input.split_whitespace().collect();
    let result: i32 = rpn(&expr);
    println!("{}", result);
}

fn rpn(expr: &[&str]) -> i32 {
    let mut stack: Vec<i32> = Vec::new();
    for e in expr {
        match e.parse::<i32>() {
            Ok(n) => {
                stack.push(n);
            },
            Err(_) => {
                let right = stack.pop().unwrap();
                let left  = stack.pop().unwrap();
                if *e == "+" {
                    stack.push(left + right);
                } else if *e == "-" {
                    stack.push(left - right);
                } else if *e == "*" {
                    stack.push(left * right);
                } else if *e == "/" {
                    stack.push(left / right);
                };
            },
        }
    }
    stack[0]
}

fn read<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<T>().ok().unwrap()
}


Measured memory_bytes: 5032
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string O;
    cin >> O;
    string E;
    cin >> E;

    int A=O.size();
    int B=E.size();

    for(int i=0; i<B; i++){
         cout << O.at(i) << E.at(i);
     }

    if(A!=B)cout<< O.at(B);

    cout << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int num;
	cin >> num;
	string str = to_string(num);
	int total = 0;
	for (int i = 0; i < str.size(); ++i) {
		char c = str[i];
		total += (c - '0');
	}
	if (num%total == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	system("pause");
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,t,a[100000],now_min=INF;
map<int,int> m;

signed main() {
    cin >> n >> t;
    rep(i,n) {
        cin >> a[i];
        now_min = min(now_min,a[i]);
        m[a[i]-now_min]++;
    }
    cout << m.rbegin()->se << endl;
}

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

typedef long long ll_t;

int N;
ll_t T, A;

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

    T = A = 1;
    for (int i = 0; i < N; i++) {
        int t, a;
        scanf("%d%d", &t, &a);
        ll_t x = max((T + t - 1) / t, (A + a - 1) / a);
        T = x * t, A = x * a;
    }
    printf("%lld\n", T + A);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    int64 X;
    cin >> X;

    map<int64, int64> pow5_map;   // (n^5, n)
    for (int64 n = -5000; n <= 5000; n++) {
        pow5_map[n * n * n * n * n] = n;
    }

    for (const auto& mp : pow5_map) {
        int64 A5 = mp.first,
              A  = mp.second;
        if (pow5_map.count(A5 - X)) {
            int64 B = pow5_map[A5 - X];
            cout << A << " " << B << endl;
            return 0;
        }
    }

    assert(false);

    return 0;
}



Measured memory_bytes: 3792
N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(1, N-1):
    if P[i] != max(P[i-1], P[i], P[i+1]) and P[i] != min(P[i-1], P[i], P[i+1]):
        cnt += 1
print(cnt)


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

vector<vector<pair<int, int>>> v(100000);
int Q, K, N;
ll cost[100000];

void culc(int pos, ll c)
{
	if (cost[pos]) return;
	cost[pos] = c;
	for (auto x : v[pos]) {
		culc(x.first, c + x.second);
	}
}


int main()
{
	cin >> N;
	rep(i, N-1) {
		CIN(int, a);
		CIN(int, b);
		CIN(int, c);
		v[a-1].PB(MP(b-1, c));
		v[b-1].PB(MP(a-1, c));
	}
	cin >> Q >> K;
	culc(K-1, 1);
	rep(i, Q) {
		CIN(int, x);
		CIN(int, y);
		cout << cost[x-1] + cost[y-1] - 2 << endl;
	}
}


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

const int MOD = 1000000007;
int main(void){
    int N, Abuf;
    long long sumA = 0LL;
    long long sumsqA = 0LL;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        sumA += Abuf;
        sumA %= MOD;
        sumsqA += (long long)Abuf * Abuf;
        sumsqA %= MOD;
    }
    cout << (sumA*sumA%MOD + MOD-sumsqA)%MOD * 500000004 % MOD << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

int main() {
	// your code goes here
    long long n,i,a[100005],c[100005]={0},ans=1;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        c[a[i]]++;
        if(a[i]==0){
            ans=ans*(4-c[a[i]])%mod;
        } else {
            ans=ans*min(4-c[a[i]],c[a[i]-1]-(c[a[i]]-1))%mod;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int f(long long a, long long b) {
    int ca = 0;
    int cb = 0;
    while(a > 0 || b > 0) {
        if (a != 0) ca++;
        if (b != 0) cb++;
        a /= 10;
        b /= 10;
    }

    return max(ca, cb);
}

int main() {
    long long n;
    cin >> n;

    int minval = 20;
    for (long long a=1; a<=sqrt(n); a++) {
        if (n % a != 0) {
            continue;
        } else {
            long long b = n / a;
            minval = min(minval, f(a, b));
        }
    }
    cout << minval << endl;

    return 0;
}


Measured memory_bytes: 256
arr=[]
n=int(raw_input())
for i in range(n):
	arr.append(raw_input())
b=[arr[0]]
t=True
for i in range(1,len(arr)):
	if arr[i] not in b and b[-1][-1]==arr[i][0]:
		b.append(arr[i])
	else:
		t=False
		break
print "Yes" if t else "No"

Measured memory_bytes: 2568
n=int(input())
s=[input()]
count=1
for i in range(n-1):
    w=input()
    s.append(w)
    if s[i][-1]==s[i+1][0]:
        count=count+1
if count==n and len(s)==len(set(s)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
N = int(input())
W = list(map(int, input().split()))
w = 0
s = 0
for n in range(N):
  w += W[n]
min = w
for n in range(N):
  s += W[n]
  w -= W[n]
  if abs(s - w) < min:
    min = abs(s - w)
print(min)

Measured memory_bytes: 3064
// Problem : D - .. (Double Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 100005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub uppper_bound
using namespace std;
int n,m;
vector<int> adj[maxn];
int vist[maxn];
void solve()
{
	cin >> n >> m;
	rep(i,0,m)
	{
		int x,y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	queue<pp> q;
	q.push({1,0});
	q.push({-1,-1});
	while(q.size())
	{
		pp x=q.front();
		q.pop();
		if(x.ff == -1)
		{
			if(q.size()==0 || q.front().ff==-1)
			break;
			q.push({-1,-1});
			x=q.front();
			q.pop();
		}
		vist[x.ff]=x.ss; 
		for(auto l:adj[x.ff])
		{
			if(vist[l]==0)
			{ 
				vist[l]=1;
				q.push({l,x.ff});
			}
		}
	}
	repe(i,2,n)
	{
		if(vist[i]==0)
		{
			cout <<"No";
			return;
		}
	}
	cout << "Yes"<<"\n";
	repe(i,2,n)
	{
		cout << vist[i]<<"\n";
	}
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 13616
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//大文字から小文字へ変換する
void A2a(char T[1000]){
    for(int i=0; T[i]!='\0'; i++){
        if(isalpha(T[i])){
            T[i] = tolower(T[i]);
        }
    }
}

int main(){
    char W[11];
    char T[1000];
    llong ans=0;

    scanf("%s", W);

    while(scanf("%s", T)!=EOF){
        if(strcmp(T, "END_OF_TEXT")==0){
            break;
        }   
        A2a(T);
        if(strcmp(W, T)==0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

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

  ll ans = 1e18;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ll cur = (i - 1) + (n / i - 1);
      ans = min(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
/* ITP1_9-B */
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
	public static void main(String[] args) throws IOException {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int count = 1;
		while(!str.equals("0")) {
			System.out.println( "Case " + count + ": " + str );
			count++;
			str = br.readLine();
		}
	}
}

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

typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
ll l;
int ch[N][2],tot;

void ins()
{
	string s;cin>>s;
	int i=0;
	for(auto j:s)
	{
		int c=j-'0';
		i=ch[i][c]?ch[i][c]:ch[i][c]=++tot;
	}
}

ll ans;
ll sg(const ll &x)
{
	return x&-x;
}
void dfs(int x,int dep)
{
	rep(i,0,1)
	if(ch[x][i])dfs(ch[x][i],dep+1);
	else ans^=sg(l-dep);
}

int main()
{
//	freopen("1.in","r",stdin);
	int n;
	cin>>n>>l;
	rep(i,1,n)ins();
	dfs(0,0);
	if(ans)puts("Alice");
	else puts("Bob");
}

Measured memory_bytes: 5788
N = int(input())
M = 18
left = 0
right = N-1
print(left)
l = input()
if l != "Vacant":
  print(right)
  r = input()
  if r != "Vacant":
    notOK = True
    while notOK:
      middle = (right+left)//2
      print(middle)
      s = input()
      if s == "Vacant":
        notOK = False
        break
      elif (middle-left)%2 == 0 and l != s:
        right = middle
        r = s
      elif (middle-left)%2 == 1 and l == s:
        right = middle
        r = s
      else:
        left=middle
        l = s


Measured memory_bytes: 38852
//ITP1_9_C_19140837_Ojima_Yukiya.cpp
//提出日 2020/6/17 wednesday
//プログラミング基礎演習2 CS 第６回課題 ITP1_9_C
//学修番号 19140837　小島優希也

#include <iostream>
using namespace std;

int main(void) {
    int taro = 0;
    int hana = 0;
    int n;
    cin >> n;
    for (int count = 0; count < n; count++) {
        string s1, s2;
        cin >> s1 >> s2;
        if (s1 > s2) {
            taro += 3;
        }
        else if (s1 == s2) {
            taro++;
            hana++;
        }
        else {
            hana += 3;
        }
    }
    cout << taro << " " << hana << endl;
    return 0;
}



Measured memory_bytes: 3212
//ProblemA

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemA

class Solve {
private:

	void solve() {
		string s;
		cin >> s;
		if (s == "zyxwvutsrqponmlkjihgfedcba") {
			cout << "-1" << endl;
			return;
		}

		set<char> notused;
		for (char c = 'a'; c <= 'z'; c++) notused.insert(c);

		for (char c : s) notused.erase(c);
		if (!notused.empty()) {
			cout << s << *notused.begin() << endl;
		}
		else {
			notused.insert(s.back());
			s.pop_back();
			while (true)
			{
				if (s.back() < *notused.rbegin()) {
					s.back() = *notused.lower_bound(s.back());
					break;
				}
				else {
					notused.insert(s.back());
					s.pop_back();
				}
			}
			cout << s  << endl;
		}


	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
struct coo{

	int x;

	int y;

	int h;

}c[110];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c[i].x;

		cin>>c[i].y;

		cin>>c[i].h;

	}
	int ch;
	int p=0;
	while(c[p].h==0) p++;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++)
		{
			int ch=c[p].h+abs(i-c[p].x)+abs(j-c[p].y);
			int f=0;
			for(int k=0;k<n;k++)
			{
				int hh=ch-abs(i-c[k].x)-abs(j-c[k].y);
				if(hh<0) hh=0;
				if(hh!=c[k].h)
				{
					f=1;
					break;
				}
			}
			if(!f)
			{
				cout<<i<<' '<<j<<' '<<ch<<endl; return 0;
			} 
		}
	}
} 


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

class Solve {
private:
	using vi = std::vector<int>;
	using pii = std::pair<int, int>;
public:
	bool is_last_query{};
	Solve()
	{
		int n;
		scanf("%d", &n);
		if (!n)
		{
			is_last_query = true;
			return;
		}
		std::vector<std::array<bool, 31>> is_free(n);
		for (int n_i{}; n_i < n; n_i++)
		{
			int f;
			scanf("%d", &f);
			for (int f_i{}; f_i < f; f_i++)
			{
				int day;
				scanf("%d", &day);
				day--;
				is_free[n_i][day] = true;
			}
		}
		for (int i{}; i < n; i++) is_free[i][30] = true;

		std::vector<vi> min_day(n, vi(n, 30));
		for (int from{}; from < n; from++)
		{
			std::priority_queue<pii, std::vector<pii>, std::greater<pii>> dij;
			dij.push({0, from});
			min_day[from][from] = 0;
			while (!dij.empty())
			{
				auto now{dij.top()};
				dij.pop();
				if (min_day[from][now.second] < now.first) continue;
				for (int to{}; to < n; to++)
				{
					int encount_day{min_day[from][now.second]};
					while (!is_free[now.second][encount_day] || !is_free[to][encount_day]) encount_day++;
					if (encount_day >= min_day[from][to]) continue;
					min_day[from][to] = encount_day;
					dij.push({encount_day, to});
				}
			}
		}
		int min{1 << 30};
		for (int to{}; to < n; to++)
		{
			int max{};
			for (int from{}; from < n; from++)
				max = std::max(max, min_day[from][to]);
			min = std::min(min, max);
		}
		if (min == 30) puts("-1");
		else printf("%d\n", min + 1);
		return;
	}
};

int main()
{
	while (!Solve().is_last_query);

	return 0;
}


Measured memory_bytes: 3168
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))



def solve():
	n = int(input()); x = 100
	y = 0
	while x < n:
		x += (x)//100
		y += 1
	print(y)


	





		

if __name__ == "__main__":
	solve()

Measured memory_bytes: 66256
#include <iostream>
#include <bitset>

using namespace std;
int main() {
  bitset<101> ok;

  for(int f = 0; f <= 100 / 4 ; f++) {
    for(int s = 0; s <= 100 / 7; s++) {
      if(4 * f + s * 7 > 100) continue;
      ok.set(4 * f + s * 7);
    }
  }

  int n;
  cin >> n;
  cout << (ok[n] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 888
import sys


def func(N, K):
    if K == N:
        return 1
    elif K - 1 == 1:                                                                                                                                  
        return N - 1
    else:
        r = N // (K - 1)                                                                                                                              
        m = N % (K - 1)
        if m == 0 or m == 1:
            return r
        return r + 1

if __name__ == '__main__':
    N, K = map(int, sys.stdin.readline().split())
    A = map(int, sys.stdin.readline().split())
    print(func(N, K))

Measured memory_bytes: 10484
import sys
import itertools


sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]


def calsScore(lst):
    s = 0
    for a, b, c, d in ABCD:
        if (lst[b - 1] - lst[a - 1]) == c:
            s += d
    return s


import copy


def dfs(i, lst, N):
    ans = 0
    lst.append(i)
    N -= 1

    if N == 0:
        return calsScore(lst)
    else:
        for j in range(i, M + 1):
            nlst = copy.copy(lst)
            ans = max(dfs(j, nlst, N), ans)

    return ans


ans = dfs(1, [], N)
print(ans)


Measured memory_bytes: 9236
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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 r; cin >> r;
    cout << 3*r*r << endl;
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    string s;
    cin >> s;
    REP(i, s.size()) cout << "x";
    cout << endl;
}


Measured memory_bytes: 256
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a1 = sorted(a)
c1 = sorted(c)
count = 0

for i in b:
    count += bisect.bisect_left(a1,i) * (n - bisect.bisect_right(c1,i))
    
print(count)

Measured memory_bytes: 106340
N = int(input())

ans = 0
cnt = 0
add = []
sum = []
while ans < N:
    add.append(ans)
    sum.append(ans**(cnt+1))
    cnt += 1
    ans += (26**cnt)


A = N - add[cnt-1]
name =[]
for i in reversed(range(cnt)):
    if i == 0:
        div = A
    else:
        div = (A-1) // (26**i)

    if i == 0 or div == 26:
        name.append(div-1)
        A -= (div-1) * (26**i)
    else:
        name.append(div)
        A -= div * (26**i)



name_a =''
for i in range(cnt):
    name_a += chr(name[i]+97)
print(name_a)

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

struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node tSearch(Node u, int k){

}

Node tSuccessor(Node x){

}


Node trMinimum(Node x){

}

void tDelete(Node z){
  Node y; 
  Node x;
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->l != NIL){
    preorder(u->l);
  }
  if(u->r != NIL){
    preorder(u->r);
  }
}


void inorder(Node u){
  if(u->l != NIL){
    inorder(u->l);
  }
  printf(" %d",u->key);
  if(u->r != NIL){
    inorder(u->r);
  }			
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key){
      x = x->l;
    }
    else{
      x = x->r;
    }
  }
  z->p = y;

  if(y == NIL){
    root=z;
  }
  else if(z->key < y->key){
    y->l = z;
  }
  else y->r = z;
}

int main(){
  int n, i, x;
  char c[20];
  scanf("%d", &n);

  for (i = 0; i < n; i++){
    scanf("%s", c);
    if (c[0] == 'f'){
      scanf("%d", &x);
      Node t = tSearch(root, x);
      if(t != NIL){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
    else if(c[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }
    else if( c[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(c[0] == 'd'){
      scanf("%d", &x);
      tDelete(tSearch(root, x));
    }
  }

  return 0;
}




Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N], n;
map<int,int> mp;
int main() {
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i], mp[a[i]]=1;
	int ans = 0, cnt = 1;
	for(int i = 1; i < n; i ++) {
		if(a[i] == a[i+1]) {
			while(mp[cnt] == 1) cnt++;
			a[i+1] = cnt;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a, b = map(int,input().split())
num = (b-a)+1
if a > 0:
  print("Positive")
elif b < 0 and num%2==0:
  print("Positive")
elif b < 0 and num%2!=0:
  print("Negative")
elif a <= 0 and b >= 0:
  print("Zero")

Measured memory_bytes: 3060
N, Y = map(int, input().split())
match = ""
matchs = []

for i in range(N+1):
    for j in range(N+1-i):
        k = N - i -j
        if (10000*i + 5000*j + 1000*k) == Y:
            match = str(i) + " " + str(j) + " " + str(k)
            matchs.append(match)
        else:
            continue

if matchs == []:
    print("-1 -1 -1")
else:
    print(matchs[0])

Measured memory_bytes: 3064
l = map(int, raw_input().split())
H = l[0]
W = l[1]

s = []
for i in range(H):
    s.append(raw_input())

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            if i > 0:
                if s[i-1][j] == '#':
                    continue
            if i < H - 1:
                if s[i+1][j] == '#':
                    continue
            if j > 0:
                if s[i][j-1] == '#':
                    continue
            if j < W - 1:
                if s[i][j+1] == '#':
                    continue
            print('No')
            exit(0)

print('Yes')


Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

ll n,m,ans=0;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	
	cin >> n >> m;
	
	if(n==1 && m==1){
		ans+=1;
	}
	else if(n==1){
		ans+=m-2;
	}
	else if(m==1){
		ans+=n-2;
	}
	else{
		ans+=(n-2)*(m-2);
	}
	
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int i,j,backup,Height[10];
		for(i=0;i<10;i++){
			scanf("%d",&Height[i]);
		}
		for(j=0;j<10;j++){
			for(i=0;i<9;i++){
				if(Height[i]>Height[i+1]){
					backup=Height[i+1];
					Height[i+1]=Height[i];
					Height[i]=backup;
				}
			}
		}
		for(i=0;i<3;i++){
			printf("%d\n",Height[9-i]);
		}
	return 0;
}

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

bool has3(int x){
    while(x){
        if(x % 10 == 3) return true;
        x /= 10;
    }
    return false;
}

void call(int n){
    for(int x = 1; x <= n; x++){
        if(x % 3 == 0 || has3(x)){
            cout << " " << x;
        }
    }
    cout << endl;
}

int main(){
    int n;
    cin >> n;
    call(n);
    return 0;
}


Measured memory_bytes: 3084
import sys
from bisect import bisect_left, bisect_right


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    count = 0
    for j in range(1, N - 1):
        for i in range(j):
            if L[i] == L[j]:
                break
            count += bisect_left(L, L[i] + L[j]) - bisect_right(L, L[j])
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9068
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, r;
  vector<int> vec;
  
  scanf("%d", &n);
  r = n;
  
  for(int i=2;i*i<=n;i++){
    if(n%i==0) vec.push_back(i);
    while(n%i==0) n/=i;
  }

  if(n > 1) vec.push_back(n);

  ll ans = 0;
  
  for(int i=0;i<(1 << vec.size()); i++){
    ll s = 1;
    for(int j=0;j<vec.size();j++)
      if(i & (1 << j)) s *= vec[j];

    ll add = r / s;
    ans += add * (__builtin_popcount(i) % 2 ? -1 : 1);
  }

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



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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  vector<bool> sim(100005,false);
  vector<bool> prime(100005,true);
  for(ll i = 2; i < 100005; i++){
    if(prime[i]) {
      for(ll j = 2; i*j<100005; j++) prime[i*j] = false;
    }
  }
  prime[0] = prime[1] = false;
  rep(i,100005){
    if(i%2==1&&prime[i]&&prime[(i+1)/2]) sim[i] = true;
  }
  vector<ll> S(100005,0);
  rep(i,100005){
    if(i==0) continue;
    if(sim[i]) S[i] = S[i-1] + 1;
    else S[i] = S[i-1]; 
  }
  ll Q;
  cin>>Q;
  rep(i,Q){
    ll l,r;
    cin>>l>>r;
    cout<<S[r]-S[l-1]<<endl;
  }
}

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

using namespace std;

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

#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple

#define iv inline void
#define ii inline int
#define ill inline ll

template <typename S, typename T>
inline bool smin(S &l, T r) {
  return r < l ? l = r, 1 : 0;
}
template <typename S, typename T>
inline bool smax(S &l, T r) {
  return l < r ? l = r, 1 : 0;
}

constexpr int MOD = 1e9 + 7;  // 998244353;

template <typename S>
inline S mod(S &l) {
  return l = (l % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}
ill po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

constexpr int inf = MOD;
constexpr int N = 400 + 10;
constexpr int M = 1e5 + 10;

int n, m, a[M], b[M];
vi vec[N];

int res[N][N], del[N];
bitset<M> mark;

bool dfs(int v, int val) {
  del[v] = val;
  for (auto e : vec[v]) {
    if (e >= val) break;
    int u = a[e] ^ b[e] ^ v;
    if (~del[u]) {
      if (del[u] != e) return false;
    } else if (!dfs(u, e))
      return false;
  }
  return true;
}

int main() {
#ifndef LOCAL
  // fileIO("");
#endif

  cin >> n >> m;
  rep(i, 0, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    vec[a[i]].pb(i);
    vec[b[i]].pb(i);
  }

  int ptr = 0;
  rep(i, 0, n) {
    memset(del, -1, sizeof(del));
    if (dfs(i, inf)) {
      memcpy(res[ptr++], del, sizeof(del));
    }
  }

  int ans = 0;
  rep(i, 0, ptr) {
    mark.reset();
    rep(j, 0, n) if (~res[i][j] && res[i][j] != inf) mark[res[i][j]] = true;
    rep(j, i + 1, ptr) {
      bool flag = true;
      rep(z, 0, n) if ((~res[j][z] && res[j][z] != inf && mark[res[j][z]]) ||
                       (~res[i][z] && ~res[j][z] && res[i][z] != res[j][z]))
          flag = false;

      if (flag) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
using namespace std;
int arr[100];
int main() {
    int cnt = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = n - 1; j >= i + 1; --j) {
            if (arr[j] < arr[j - 1]) {
                swap(arr[j], arr[j - 1]);
                ++cnt;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout <<arr[i]<< ((i == n - 1) ? "\n" : " ");
    }
    cout<<cnt<<endl;
}


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

int main() {
  string s;cin>>s;
  ll g=0,p=0,w=0;
  for(char& ch : s) {
    if(ch=='g') {
      if(p+1<=g) {
	w++;p++;
      } else g++;
    } else {
      if(p+1<=g) {
	p++;
      } else {
	g++;w--;
      }
    }
  }
  cout << w << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,n;cin>>a>>b>>n;
  ll x;
  if(b==1){
  cout<<0;
  return 0;}
  if(n>=b)x=b-1;
  else x=n;
  cout<<a*x/b;
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

  vector<string> t(n), h(n);
  rep(i, n) cin >> t[i] >> h[i];

  int score_t = 0, score_h = 0;
  rep(i, n) {
    if (t[i] == h[i])
      score_t++, score_h++;
    if (t[i] > h[i])
      score_t += 3;
    if (t[i] < h[i])
      score_h += 3;
  }

  cout << score_t << " " << score_h << endl;
}


Measured memory_bytes: 3224
n = int(input())
h = list(map(int, input().split()))
h = h[::-1]

for i in range(1,n):
    if h[i] > h[i-1]:
        h[i] -= 1
        if h[i] < 1 or h[i] > h[i-1]:
            print('No')
            exit()
print('Yes')

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

int main()
{
    ll n,w;
    cin>>n>>w;
    ll weight[n+5],value[n+5];
    for(int i=1; i<=n; i++)
        cin>>weight[i]>>value[i];
    ll dp[n+5][w+5];
   /* for(int i=1; i<=n; i++)
        for(int j=1; j<=w; j++)
            dp[i][j]=1e10;*/
    for(int i=0; i<=n; i++)
        dp[i][0]=0;
    for(int i=0; i<=w; i++)
        dp[0][i]=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if(weight[i]>j)
                dp[i][j]=dp[i-1][j];
            else
            {
             dp[i][j]=max(dp[i-1][j],value[i]+dp[i-1][j-weight[i]]);
            }
        }
    }
   /* for(int i=0;i<=n;i++)
    {
        for (int j=0;j<=w;j++)
        {
            cout << dp[i][j]<<" " ;
        }
        cout << endl;
    }*/
    cout << dp[n][w];

    return 0;
}


Measured memory_bytes: 80000
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
using namespace std;
const int MOD = 1e9 +7;

int main(){
    int N,M;
    string s[110],t[110];
    cin >>N;
    rep(i,N) cin >>s[i];
    cin >>M;
    rep(i,M) cin >>t[i];
    map<string,int> mp;
    rep(i,N){
        mp[s[i]]++;
    }
    rep(i,M){
        mp[t[i]]--;
    }
    int ans=0;
    map<string,int>::iterator it;
    for(it = mp.begin(); it!=mp.end(); it++ ) {
        ans =max(ans,it->second);
    }
    cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  ll tmp;
  vector<ll> arr;
  map<ll, ll> amap;
  for(ll i=0;i<N;++i) {
    cin>>tmp;
    if(amap[tmp]==0) arr.push_back(tmp);
    amap[tmp]++;
  }
  ll ans = 0;
  for(ll i=0;i<arr.size();++i) {
    if(arr[i]>amap[arr[i]]) ans += amap[arr[i]];
    else if(arr[i]<amap[arr[i]]) ans += amap[arr[i]] - arr[i];
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 9992
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <string>
using namespace std;
int judge(char,char);
int main(){
    int N,ans = 0;
    cin >> N;
    string S;
    cin >> S;
    for(int i = 0;i < N-1;i ++){
        int count = 0;
        for(int j = 0;j < 26;j++){
            bool X = 0,Y = 0;
            for(int k = 0;k < i+1;k ++){
                if(S.at(k) == 'a' + j) X = true;
            }
            for(int k = i+1;k < N;k ++){
                if(S.at(k) == 'a' + j) Y = true;
            }
            if(X && Y) count ++;
        }
        if(count > ans) ans = count;
    }
    cout << ans << endl;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll r,n;
  cin >> n >> r;

  ll ans;
  if(n<10) ans = r + 100 * (10-n);
  else ans = r;
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define mod 1000000000000000000
    #define MOD 		1000000007
    #define ll long long
    #define mp 		make_pair
    #define pb 		push_back
    #define forn(i,n) 	for(ll i=0;i<n;i++)
    #define for1(i,n) 	for(ll i=1;i<=n;i++)
    #define forn1(i,n) 	for(int i=1;i<n;i++)
    #define rep(i,x,n)  for(ll i=x;i<=n;i++)
    #define repr(i,x,j) for(ll i=x;i>=j;i--)
    #define vi vector<ll>
    #define mii map<int,int>
    #define vii vector<pair<int,int>>
    #define vvi vector<vector<int>>
    #define pii pair<int,int>
    #define F first
    #define S second
    #define fill(a,x) memset(a,x,sizeof a);
    #define all(x) x.begin(),x.end()
    #define test ll t;cin>>t;while(t--)
    #define yes cout<<"YES"<<endl
    #define no cout<<"NO"<<endl
    #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define R return 0
    int main()
    {
    	IOS;
        ll n;
        cin>>n;
        if(n>=30)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
        R;
    }

Measured memory_bytes: 3628
#include "math.h"
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
int main()
{
    lli n, a, b, c, d;
    cin >> n;
    cin >> a >> b >> c >> d;
    lli left = a - (n - 1) * d;
    lli right = a - (n - 1) * c;
    bool flag = false;
    rep(i, n)
    {
        if (left <= b && right >= b)
            flag = true;
        left += c + d;
        right += c + d;
    }
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int n,m;
	cin>>n>>m;
	long long int c=0,l=n;
	long long int arr[m+1];
	memset(arr,0,sizeof(arr));
	while(n--){
		long long int x;
		cin>>x;
		while(x--){
			long long int i;
			cin>>i;
			arr[i]++;
		}
	}
	for(long long int k=1;k<=m;k++){
		if(arr[k]==l){
			c++;
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 764