akhauriyash/Code-Regression huggingface dataset:
import itertools
import math
import fractions
import functools
import copy
n = int(input())
t, a = map(int, input().split())
h  = list(map(int, input().split()))
minimum = 10**10
index = 0
for i in range(n):
    minimum = min(minimum,abs(a-(t-h[i]*0.006)))
    if minimum == abs(a-(t-h[i]*0.006)):
        index = i

print(index+1)

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

int main(){
  int h1,h2,k1,k2,a,b,c,d;
  cin >> h1 >> h2;
  cin >> k1 >> k2;
  cin >> a >> b >> c >> d;
  int hiro = h1*a + h1/10*c + h2*b + h2/20*d;
  int ken = k1*a + k1/10*c + k2*b + k2/20*d;
  if(hiro>ken)cout << "hiroshi" << endl;
  else if(ken > hiro)cout << "kenjiro" << endl;
  else cout << "even" << endl;
  return 0;
}

Measured memory_bytes: 3096
def actual(K, S):
    my_range = lambda n: range(n + 1)

    count = 0

    for x in my_range(K):
        for y in my_range(K):
            z = S - (x + y)
            if 0 <= z <= K:
                count += 1
    return count

  
K, S = map(int, input().split())

print(actual(K, S))

Measured memory_bytes: 3060
// 解二元一次方程组 
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	double a,b,c,d,e,f,x,y;
	while (cin >> a >> b >> c >> d >> e >> f) {
		y = (a*f - c*d)/(a*e - b*d);
		if (a != 0) 
			x = (c - b*y) / a;
		else 
			x = (f - e*y) / d;
		cout << fixed <<setprecision(3)<< x <<" " << y << endl;	
	}
} 


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <queue>
#include <string>
#include <algorithm>

/*
#include <atcoder/all>
using namespace atcoder;
*/

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, j, n) for (int i = j; i < n; i++)

typedef long long ll;
const ll MOD = 1000000007; // 10^9+7
const ll INF = 10000000000;

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

    vector<ll> a(n,0);
    rep(i,n) cin >> a[i];

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

    ll pre = a[0], cnt = 1, cnt2 = 0;
    ll l[2];
    l[0] = 0;
    l[1] = 0;

    rep1(i,n-1){
        if(cnt2 == 2) break;
        if(a[i] == pre){
            cnt++;
            if(cnt == 4){
                cout << a[i]*a[i] << endl;
                return 0;
            }
            if(cnt == 2){
                l[cnt2] = a[i];
                cnt2++;
            }
        }else{
            cnt = 1;
        }
        pre = a[i];
    }

    cout << l[0]*l[1] << endl;
    return 0;
}

Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main(){
  int a,b,c,count;
  cin >> a >> b >> c;
  for(;a <= b;a++){
    if(c%a==0){
      count++;
    }
  }
  cout << count << '\n';
  return 0;
}



Measured memory_bytes: 3096
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef unsigned long long ll;

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

	vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    p.at(i) = make_pair(a, b);  // b, a の順でペアにする
  }
	int s,t;
	s = 0;
	t = N;1;
	rep(i,M){
		s = max(p[i].first,s);
		t = min(p[i].second,t);
	}
	if(t >= s) cout << t - s + 1 << endl;
	else cout << 0 << endl;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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(void){
  std::cout<<std::fixed<<std::setprecision(10);
  ll n,k; cin >> n >> k;
  double pnum[n];
  double psum = 0;
  // FOR(i,0,n-1){
  //   psum += i+1;
  //   pnum[i] = 
  // }
  double p[n];
  FOR(i,0,n-1) {
    int input;
    cin >> input;
    p[i] = 0.5 * (input+1);
  }
  double dicesum = 0;
  double max = 0;
  FOR(i,0,k-1){
    dicesum += p[i];
  }
  chmax(max,dicesum);

  FOR(i,k,n-1){
    dicesum += p[i];
    dicesum -= p[i-k];
    chmax(max,dicesum);
  }

  cout << max << endl;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcountll //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

signed main()
{
	rootdada;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
	int n;
	cin >> n; int ans = 0;

	for (int i = 1; i < n; i++)
	{
		for (int j = 1; j < n; j++)
		{
			if (n - i * j <= 0)
			{
				break;
			}
			else
				ans++;

		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

int main() {
    int N;
    int Z, W;
    cin >> N >> Z >> W;
    int A[N]; rep(i, N) cin >> A[i];
    if(N >= 2)cout << max(abs(A[N - 1] - W), abs(A[N - 2] - A[N - 1])) << endl;
    else cout << abs(A[N - 1] - W) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BRACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

//??¨??????????????????????????????

int next(int u) {
	for (int v = nt[u]; v < n; v++) {
		nt[u] = v + 1;
		if (M[u][v]) return v;
	}
	return -1;
}

//????????????????????£?????±???????????¢?´¢

void dfs_visit(int r) {
	for (int i = 0; i < n; i++) {//nt????????????
		nt[i] = 0;
	}

	stack<int> S;//int??????????????????S?????¨???
	S.push(r);
	color[r] = GRAY;
	d[r] = ++tt;

	while (!S.empty()) {//????????????????????????????????§??°?????????
		int u = S.top();
		int v = next(u);
		if (v != -1) {
			if (color[v] == WHITE) {
				color[v] = GRAY;
				d[v] = ++tt;
				S.push(v);
			}
		}
		else {
			S.pop();
			color[u] = BRACK;
			f[u] = ++tt;
		}
	}
}

void dfs() {
	//?????????
	for (int i = 0; i < n; i++) {
		color[i] = WHITE;
		nt[i] = 0;
	}
	tt = 0;

	//????¨???????u????§??????¨????????±???????????¢?´¢
	for (int u = 0; u < n; u++) {
		if (color[u] == WHITE) dfs_visit(u);
	}
	for (int i = 0; i < n; i++) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}

int main() {
	int u, k, v;

	cin >> n;
	for (int i = 0; i < n; i++) {//????±???¨?????????????????????
		for (int j = 0; j < n; j++) {
			M[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {//??????M????????????????´?
		cin >> u >> k;
		u--;//0?????????????????????
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;//0?????????????????????
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){

   int n,i,t,p,q,s,mm;
    cin>>t>>n;
    int a[t];
    for(i=0;i<t;i++){
         cin>>a[i];
   }
   s=0,mm=0;
   sort(a,a+t);
    for(i=0;i<n;i++){
      s+=a[i];
      
   }
   cout<<s<<endl;

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=105,INF=1<<30;
ll dp[MAX][MAX*MAX];
ll rui[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    ll ans=0;
    
    dp[N+1][0]=1;
    
    rui[1]=1;
    for(int i=2;i<=N;i++){
        rui[i]=rui[i-1]*(K+1);
        rui[i]%=mod;
    }
    
    for(int i=N;i>=1;i--){
        for(int j=0;j<=N*N;j++){
            if(dp[i+1][j]==0) continue;
            for(int k=0;k<=K;k++){
                if(k>i){
                    ans+=dp[i+1][j]*(j+k)%mod*rui[i];
                    ans%=mod;
                    
                    dp[i][j]+=dp[i+1][j];
                    dp[i][j]%=mod;
                }else{
                    int x=(j+k)/i,y=(j+k)%i;
                    ans+=dp[i+1][j]*y%mod*rui[i];
                    ans%=mod;
                    
                    dp[i][j+x]+=dp[i+1][j];
                    dp[i][j+x]%=mod;
                }
            }
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 6656
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
A = [(0,0,0)]
for i in range(N):
    a = tuple(map(int, input().split()))
    A.append(a)

flg = 1
for i in range(1,N+1):
    dist = abs(A[i][1]-A[i-1][1])+abs(A[i][2]-A[i-1][2])
    time = A[i][0]-A[i-1][0]
    if time < dist:
        flg = 0
    else:
        if dist%2 != time%2:
            flg = 0

if flg:
    print("Yes")
else:
    print("No")

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

int main(){
  string s,t;
  cin >> s >> t;
  ll ans = 99999999999;
  for(ll i=0;i<=(ll)s.size()-(ll)t.size();++i){
    string tmp = s.substr(i,(ll)t.size());
    ll cnt = 0;
    rep(j,t.size()){
      if( t.at(j) != tmp.at(j) ) ++cnt;
    }
    ans = min(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	int n;
	long k;
	void solve(){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		k=sc.nextLong();
		int[]a=new int[n];
		int[]b=new int[n];
		Pair[] p=new Pair[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			p[i]=new Pair(a[i],b[i]);
		}
		Arrays.sort(p);
		for(int i=0;i<n;i++){
			k-=p[i].b;
			if(k>0)continue;
			else{
				System.out.println(p[i].a);
				return;
			}
		}
	}
	class Pair implements Comparable<Pair>{
		int a;
		int b;
		Pair(int a,int b){
			this.a=a;
			this.b=b;
		}
		
		public int compareTo(Pair o){
			return this.a-o.a;
		}
	}
}


Measured memory_bytes: 90040
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


char S[103];
char ky[123] = "keyence";

int main() {
	cin >> S;
	int N = strlen(S);

	int i = 0;
	while (S[i] == ky[i] && i<7) i++;

	int j = 0;
	while (S[N-1-j] == ky[6-j] && j<7) j++;


	bool ans = i + j >= 7;
	puts(ans ? "YES" : "NO");


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

  string S, T, R;
  cin >> S;
  int N = S.size();
  T = S.substr((N+3)/2-1);
  R = S.substr(0, (N-1)/2);
  int M = T.size();
  int O = (N-1)/2;
  bool ok = true;
  rep(i,N){
    if(S[i] != S[N-i-1]) ok = false;
  }
  rep(i,O){
    if(R[i] != R[O-i-1]) ok = false;
  }
  rep(i,M){
    if(T[i] != T[M-i-1]) ok = false;
  }

  cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define ft first
#define sd second
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e6+10 ;
const int mod = 998244353  ;

// vl compute(string s){
//         vl has(s.length());
//         ll i;

//         for(i=0;i<s.length();i++){
//             if(i==0){
//                 has[i]=((s[i]-'a'+1))%mod;
//             }
//             else
//                 has[i]=(has[i-1]*p + (s[i]-'a'+1))%mod;
//         }
//         return has;
// }
vl a(N),b(N),col(N,0),vis(N,0);
ll n,m;
vll g[N];
void dfs(ll u){
    vis[u]=1;
    ll v,w;
    for(auto &it:g[u]){
        v=it.first;
        w=it.second;
        if(vis[it.first])
          continue;
        if(w&1)
          col[v]=1-col[u];
        else
          col[v]=col[u];
        dfs(v);
    }
}
int main(){
 ios_base::sync_with_stdio(0);
  ll i,n;
  cin >> n;
  for(i=0;i<n;i++){
    ll u,v,w;
    cin >> u >> v >> w;
    g[u].pb({v,w});
    g[v].pb({u,w});
  }
  dfs(1);
  for(i=1;i<=n;i++)
    cout << col[i] << endl;
 return 0;
}

Measured memory_bytes: 12672
#include <stdio.h>

void swap(int *a, int *b) {
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}

int main(void) {
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  if (a > b) {
    swap(&a, &b);
  }

  if (b > c) {
    swap(&b, &c);
  }

  if (a > b) {
    swap(&a, &b);
  }

  printf("%d %d %d\n", a, b, c);

  return 0;
}

Measured memory_bytes: 596
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 B = sc.nextInt();
		int C = sc.nextInt();
		String[] s = new String[N+1];
		for(int i = 0; i < N; i++)
			s[i] = sc.next();
		s[N] = "";
		StringBuilder ans = new StringBuilder();
		for(int i = 0; i < N; i++) {
			if(s[i].equals("AB")) {
				if(A <= 0 && B <= 0) {
					System.out.println("No");
					return;
				}
				if(A < B) {
					ans.append("A\n");
					A++;
					B--;
				}
				else if(B < A) {
					ans.append("B\n");
					B++;
					A--;
				}
				else {
					if(s[i+1].equals("BC")) {
						ans.append("B\n");
						B++;
						A--;
					}
					else {
						ans.append("A\n");
						A++;
						B--;
					}
				}
			}
			else if(s[i].equals("AC")) {
				if(A <= 0 && C <= 0) {
					System.out.println("No");
					return;
				}
				if(A < C) {
					ans.append("A\n");
					A++;
					C--;
				}
				else if(C < A) {
					ans.append("C\n");
					C++;
					A--;
				}
				else {
					if(s[i+1].equals("AB")) {
						ans.append("A\n");
						A++;
						C--;
					}
					else {
						ans.append("C\n");
						C++;
						A--;
					}
				}
			}
			else {
				if(B <= 0 && C <= 0) {
					System.out.println("No");
					return;
				}
				if(B < C) {
					ans.append("B\n");
					B++;
					C--;
				}
				else if(C < B) {
					ans.append("C\n");
					C++;
					B--;
				}
				else {
					if(s[i+1].equals("AC")) {
						ans.append("C\n");
						C++;
						B--;
					}
					else {
						ans.append("B\n");
						B++;
						C--;
					}
				}
			}
		}
		System.out.print("Yes\n"+ans);
	}

}


Measured memory_bytes: 65184
def findProductSum(A, n):

    array_sum = 0
    for i in range(0, n, 1):
        array_sum = array_sum + A[i]

    array_sum_square = (array_sum * array_sum)

    individual_square_sum = 0
    for i in range(0, n, 1):
        individual_square_sum += ((A[i] * A[i]))

    return ((array_sum_square -
             individual_square_sum) // 2) % (10**9+7)
n=int(input())
a=list(map(int,input().split()))
print(findProductSum(a,n))


Measured memory_bytes: 94124
#include <iostream>

using namespace std;

static const long MOD = 1000000007;

int main(int argc, char *argv[]) {
	int N;
	long power = 1;
	cin >> N;
	for (int i = 1; i <= N; i++)
		power = (power * i) % MOD;

	cout << power << endl;
	return 0;
}


Measured memory_bytes: 256
# ABC070-C
import fractions
from functools import reduce
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def lcm_base(x, y):
    return (x * y ) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers)
print(lcm_list(T))

Measured memory_bytes: 5304
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
int main() {
	int N, M;
	cin >> N >> M;
	string S, T;
	cin >> S >> T;
	ll L = lcm(N, M);
	for (int i = 0; i < N; i++) {
		ll x = i * (L / N);
		ll y = L / M;
		if (x%y == 0 && S[i] != T[x / y]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << L << endl;
}

Measured memory_bytes: 512
# coding: utf-8
"""
aizu 0001
"""

import sys

# @profile
def main():
    mountaines=[]
    for line in sys.stdin:
        mountaines.append(int( line ))
    mountaines.sort(reverse=True)
    for index,x in enumerate( mountaines ):
        print x
        if index >=2:
            break
if __name__ == '__main__':
    main()

Measured memory_bytes: 4212
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int c=0;
  string N;
  cin >> N;
  for (auto s:N) {
    int i = s - '0';
    c += i;
    c%=9;
  }
  if (c==0) cout << "Yes";
  else cout << "No";
  cout << endl;
}


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

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

    long long x[1010], y[1010], z[1010];

    for(int i = 0;i < n;i++){
        cin >> x[i] >> y[i] >> z[i];
    }

    long long ans = 0;
    for(int i = 0;i < (1 << 3);i++){
        vector<pair<long long, int> > vec;
        for(int j = 0;j < n;j++){
            long long tmp = 0;
            tmp += (i & 1) ? x[j] : -x[j];
            tmp += (i & 2) ? y[j] : -y[j];
            tmp += (i & 4) ? z[j] : -z[j];
            vec.push_back(make_pair(tmp, j));
        }

        sort(vec.begin(), vec.end(), greater<pair<long long, int> >());

        long long xx = 0, yy = 0, zz = 0;
        for(int j = 0;j < m;j++){
            xx += x[vec[j].second];
            yy += y[vec[j].second];
            zz += z[vec[j].second];
        }

        ans = max(ans, abs(xx) + abs(yy) + abs(zz));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N; 
  string S;
  cin >> N >> S;
  for (auto i : S) {
    int t = int(i) + N;
    if (t > 90) t -= 26;
    cout << char(t);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

struct mint
{
    ll x;
    mint(ll x = 0) : x(x % MOD) {}
    mint& operator+=(const mint rh) { if((x += rh.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(const mint rh) { if((x += MOD-rh.x) >= MOD) x -= MOD; return *this; }
    mint& operator*=(const mint rh) { (x *= rh.x) %= MOD; return *this; }
    mint operator+(const mint rh) const { return mint(*this) += rh; }
    mint operator-(const mint rh) const { return mint(*this) -= rh; }
    mint operator*(const mint rh) const { return mint(*this) *= rh; }
    mint pow(ll k) const
    {
        if(!k) return 1;
        mint a = x;
        mint res = 1;
        while(k)
        {
            if(k & 1) res *= a;
            k >>= 1;
            a *= a;
        }
        return res;
    }
    mint inv() const { return pow(MOD-2); }
    mint& operator/=(const mint rh) { return *this *= rh.inv(); }
    mint operator/(const mint rh) { return mint(*this) /= rh; }
};

int main()
{
    int s;
    cin >> s;
    vector<mint> dp(s+1);
    dp[0] = 1;
    rep(i,s+1)
    {
        if(i - 3 < 0) continue;
        dp[i] += dp[i-3] + dp[i-1];
    }
    cout << dp[s].x << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, m;
	cin >> n >> m;
	int in;
	for (int i = 0; i < m; ++i)
	{
		cin >> in;
		n -= in;
	}
	cout << (n>=0?n:-1) << endl;
	return 0;
}

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

#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl         "\n"
#define int          long long
#define all(v)       v.begin(),v.end()
#define sz(v)        (int)v.size()
#define pii          pair<int,int>
#define fi           first
#define se           second
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define deb(x)       cout << #x << ' ' << x << endl
#define clock        cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl;

void INPUT() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

const int N = 1e5 + 5;

int a[N], n;
int cache[N];
 
int dp(int idx) {
	if (cache[idx] != -1) return cache[idx];
	int ans = 0;
	if (idx + 1 < n && idx + 2 < n) {
		ans = min(abs(a[idx] - a[idx + 1]) + dp(idx + 1), abs(a[idx] - a[idx + 2]) + dp(idx + 2));
	}
	else if (idx + 1 < n) ans = abs(a[idx] - a[idx + 1]) + dp(idx + 1);
	cache[idx] = ans;
	return cache[idx];
}

int32_t main(){
    IOS //INPUT();
    cin >> n;
    forn(i, 0, n) cin >> a[i];
    memset(cache, -1, sizeof(cache));
    int ans = dp(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
n,m=map(int,input().split())
# 商品iをそれぞれN個入力
num=[int(i) for i in input().split()]
# 降順で並び替え
num=sorted(num,reverse=True)
# 総得票数
sum_num=sum(num)
# そう得票数の1/4Mは未満は人気商品と言えないNo
if num[m-1]<sum_num/(4*m):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 9148
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

const ll MOD = 1e9+7;

signed main(){
    ll n;
    scanf("%lld",&n);
    vector<ll> cnt(10000000);

    rep(i,1,n+1){
        ll temp = 1;
        while(i*temp <= n){
            cnt[i*temp++]++;
        }
    }

    ll sum = 0;
    rep(i,1,n+1){
        sum += i*cnt[i];
    }

    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 81392
//
//  abc152_AC_WA.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265


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

  if (m>=n) {
    std::cout << "Yes" << std::endl;
  }
  else {
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
input_line = map(int,raw_input().split(" "))
tmpMin = float("inf")
if tmpMin > input_line[0] + input_line[1]:
	tmpMin = input_line[0] + input_line[1]
if tmpMin > input_line[0] + input_line[2]:
	tmpMin = input_line[0] + input_line[2]
if tmpMin > input_line[1] + input_line[2]:
	tmpMin = input_line[1] + input_line[2]
print tmpMin

Measured memory_bytes: 2568
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=1e5+1;
int mm[N+100][3];
int L[N+100],R[N+100];


int main(){	
	fastio;
	int n;cin>>n;
	FER(i,0,n){
		int k;cin>>k;
		mm[k][i&1]++;
	}
	int ans=N;
	L[0]=mm[0][1];
	FER(i,1,N)L[i]=max(L[i-1],mm[i][1]);
	R[N-1]=mm[n-1][1];
	IFR(i,N-2,0)R[i]=max(R[i+1],mm[i][1]);
	FER(i,0,N){
		int val=mm[i][0];
		int go=0;
		if(i-1>=0)go=max(go,L[i-1]);
		if(i+1<N)go=max(go,R[i+1]);
		ans=min(ans,n-val-go);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
int main(){
stack<int> S;
string s;
while(cin>>s){
    int a,b;
    if(s[0]=='+'){
        a=S.top();S.pop();
        b=S.top();S.pop();
        S.push(a+b);
        
    }else if(s[0]=='*'){
        a=S.top();S.pop();
        b=S.top();S.pop();
        S.push(a*b);
    }else if(s[0]=='-'){
        a=S.top();S.pop();
        b=S.top();S.pop();
        S.push(b-a);
    }else {
        S.push(atoi(&s[0]));
    }
    
    
    
}
cout<<S.top()<<endl;
    
    
    
    
    
return 0;
}


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

int main()
{
	int a;  //tate
	int b;  //yoko
	cin >> a;
	cin >> b;
	
	int area, circuit;
	
	area = a * b;
	circuit = 2*a + 2*b;
	
	cout << area << " " << circuit << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  if(N%2==0)
  {
    cout << N << endl;
  }
  else
  {
    cout << 2*N << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tet"
using namespace std;
const ll N = 2e5 + 9;
const ll inf = 1e18;
typedef pair<ll,ll> LL;

ld a,b,p;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>a>>b;
    p = a*b;
    ll ans = p;
    cout<<ans;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;

const int MAXN = 200001;
const int LG = 18;
const ll INF = (1ll << 60);

using Val = pair<ll, int>;

vector <pair <int, int>> e[MAXN];

Val dv[MAXN];
ll cost[MAXN];
ll h[MAXN];

Val ad(Val v, ll x) {
    return { v.first + x, v.second };
}

int height[MAXN];
int maxto[MAXN];

void dfsinit(int v, int par, int ds) {
    auto it = find(e[v].begin(), e[v].end(), pair<int, int>{par, ds});
    if (it != e[v].end()) {
        e[v].erase(it);
    }

    height[v] = height[par] + 1;

    maxto[v] = height[v];
    h[v] = h[par] + ds;
    dv[v] = { cost[v], v};

    for (auto& ed : e[v]) {
        dfsinit(ed.first, v, ed.second);
        maxto[dv[ed.first].second] = height[v];
        dv[v] = min(dv[v], ad(dv[ed.first], ed.second));
    }
}

ll ans = 0;

Val mnval[MAXN];

Val bad = { INF,-1 };
void dfsdown(int v, ll modifier) {

    
    int m = e[v].size();
    vector<Val> l(m + 1);
    vector<Val> r(m + 1);
    l[0] = bad;
    r[m] = bad;

    for (int i = 0; i < m; ++i) {
        l[i + 1] = min(l[i], ad(dv[e[v][i].first], e[v][i].second));
    }

    for (int i = m - 1; i >= 0; --i) {
        r[i] = min(r[i + 1], ad(dv[e[v][i].first], e[v][i].second));
    }

    if (dv[1].second != v) {
        if (maxto[v] != height[v]) {
            ans += mnval[maxto[v] + 1].first + modifier + cost[v];
        } else {
            ans += min(mnval[height[v]].first + modifier, l[m].first) + cost[v];
        }
    }

    for (int i = 0; i < m; ++i) {
        Val curVal = min({ Val{ cost[v], v }, l[i], r[i + 1] });
        mnval[height[v] + 1] = min({ mnval[height[v]], ad(curVal, -modifier) });
        dfsdown(e[v][i].first, modifier + e[v][i].second);
    }
}



int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> cost[i];
    }


    for (int i = 1; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        e[a].emplace_back(b, c);
        e[b].emplace_back(a, c);
    }

    height[1] = -1;
    mnval[0] = bad;
    dfsinit(1, 1, 0);
    dfsdown(1, 0);

    cout << ans << "\n";
}

Measured memory_bytes: 68992
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	var count int
	fmt.Scan(&s)

	splitWord := strings.Split(s, "")

	for _, w := range splitWord {
		if w == "1" {
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 100000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll dp1[10005],dp2[INF];
int main(){
  ll N;cin>>N;
  ll g[2],s[2],b[2];
  ll i,j,k;
  rep(i,2) cin>>g[i]>>s[i]>>b[i];
  dp1[N]=N;
  for(i=N+1;i<=10005;i++) dp1[i]=-INF;
  for(i=N-1;i>=0;i--){
    dp1[i]=max(dp1[i+1], max( dp1[i+g[0]]+(g[1]-g[0]) , max( dp1[i+s[0]]+(s[1]-s[0]) , dp1[i+b[0]]+(b[1]-b[0]) ) ) );
  }
  //cout<<dp1[0]<<endl;
  for(i=dp1[0]+1;i<=INF;i++) dp2[i]=-INF;
  dp2[dp1[0]]=dp1[0];
  for(i=dp1[0]-1;i>=0;i--){
    dp2[i]=max(dp2[i+1], max( dp2[i+g[1]]+(g[0]-g[1]) , max( dp2[i+s[1]]+(s[0]-s[1]) , dp2[i+b[1]]+(b[0]-b[1]) ) ) );
    //if(dp2[i]>dp1[0]) cout<<i<<" "<<dp2[i]<<endl;
  }
  cout<<dp2[0]<<endl;
}


Measured memory_bytes: 781696
import sys
from collections import deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K = int(read())

cnt = 0

que = deque([i for i in range(1, 10)])

while len(que) != 0:
    acc = que.popleft()
    cnt += 1

    if cnt == K:
        ans = acc
        break
    acc_ = acc % 10
    if acc_ != 0:
        que.append(acc * 10 + acc_ - 1)
    que.append(acc * 10 + acc_)
    if acc_ != 9:
        que.append(acc * 10 + acc_ + 1)

print(ans)

Measured memory_bytes: 11936
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define one(x) cout<<#x<<" : "<<x<<endl;
#define two(x,y) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;


signed main()
{
    int a , b;
    cin >> a >> b;
    cout<< (a*(a-1))/2 + (b*(b-1))/2 <<endl;
}




Measured memory_bytes: 256
import java.util.*;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int A = sc.nextInt();
		final int B = sc.nextInt();

		long[] items = new long[N];
		HashMap<Long, Integer> itemCount = new HashMap<>();

		for (int i = 0; i < N; i++) {
			long v = sc.nextLong();
			items[i] = v;
			itemCount.put(v, itemCount.getOrDefault(v, 0) + 1);
		}

		Long[] uniqNums = itemCount.keySet().toArray(new Long[itemCount.size()]);
		Arrays.sort(items);
		Arrays.sort(uniqNums);

		int ai, ar, bi, br;
		ai = uniqNums.length - 1;
		ar = A;
		bi = uniqNums.length - 1;
		br = B;
		while (ar > itemCount.get(uniqNums[ai])) {
			ar -= itemCount.get(uniqNums[ai]);
			ai--;
		}
		while (br > itemCount.get(uniqNums[bi])) {
			br -= itemCount.get(uniqNums[bi]);
			bi--;
		}

		double maxAvg = 0;
		long patterns = 0;

		long sum = 0;
		for (int i = 1; i <= A; i++) {
			sum += items[items.length - i];
		}
		maxAvg = (double) sum / (double) A;

		if (ai == (uniqNums.length - 1)) {
			int bound = Math.max(ar, itemCount.get(uniqNums[uniqNums.length - 1]));
			if (bi == (uniqNums.length - 1)) {
				bound = br;
			}
			for (int i = ar; i <= bound; i++) {
				patterns += combination(itemCount.get(uniqNums[uniqNums.length - 1]), i);
			}
		} else {
			patterns = combination(itemCount.get(uniqNums[ai]), ar);
		}
		System.out.println(maxAvg);
		System.out.println(patterns);
		sc.close();
	}

	private long combination(long n, long r) {
		if (n <= r) {
			return 1L;
		}
		long c = 1L;
		for (long i = 1L; i <= r; i++) {
			c *= ((n - i) + 1);
			c /= i;
		}
		return c;
	}
}

Measured memory_bytes: 23380
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  string s;
  cin>>s;
  int n=s.size();
  int cnt=0;
  rep(i,n){
    if(s[i]=='g')++cnt;
  }
  cout<<cnt-(n+1)/2;
}

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


Measured memory_bytes: 512
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

'''
奇数の果実が有れば先行の勝ち。
初手で全ての果実の個数が偶数になるようにとれば、
あとは、後攻の真似をし続けることができる。

一方、全ての果実が偶数なら、後攻は先攻の真似をすれば良い。

'''

def main():
	n = int(input())
	#b , c = tin()
	#s = input()	
	for i in range(n):
		v = int(input())
		if v % 2 == 1:
			return 'first'
	return 'second'
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    LL bic[61] = {};
    for(int i = 0; i < n; ++i) {
        LL a;
        cin >> a;
        int bi = 0;
        while(a > 0) {
            bic[bi] += a & 1;
            a >>= 1;
            ++bi;
        }
    }

    LL res = 0;
    for(int i = 0; i <= 60; ++i) {
        res = res + ((bic[i] * (n - bic[i]) % MOD) * ((1ll << i) % MOD) % MOD) % MOD;

    }
    cout << res % MOD << endl;
    return 0;
}



Measured memory_bytes: 256
END { load __FILE__ unless $stdin.eof? }

x, k, d = gets.split.map!(&:to_i)
x = x.abs

s, t = x.divmod(d)

if s > k
  puts x - k * d
else
  if (s - k).even?
    puts t
  else
    puts (t - d).abs
  end
end


Measured memory_bytes: 14340
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


def calculate(a):
    s = 0
    for i in range(len(a)):
        for k in range(i+1,len(a)):
            s+=(a[i]*a[k])
    return s

n = ip()                              #入力整数1つ
#n,m= (int(i) for i in input().split())      #入力整数横2つ
#a,b,k = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
mx = 0
x = 0
for i in range(n):
    if a[i] == 'I':
        x+=1
        if mx < x:mx = x
    else: x-=1
print(mx)

Measured memory_bytes: 13636
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  string s;
  cin >> s;
  
  int begin,end;
  rep(i,s.size()){
    if(s[i] == 'A'){
      begin = i;
      break;
    }
  }
  rep(i,s.size()){
    if(s[i] == 'Z'){
      end = i;
    }
  }
  cout << end - begin + 1;
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
  ll i,j;
  ll n;
  cin>>n;
  string s;
  cin>>s;
  char c;
  ll r=0,b=0;
  for(i=0;i<n;i++){
      c=s[i];
      if(c=='R')r++;
      else b++;
  }
  if(r>b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


ll twocnt(ll n) {
  ll res=0;
  while(n%2==0) {res++; n>>=1;}
  return res;
}

ll a[MAX*10];
ll tc[MAX*10];

int main(void) {
  ll i, j, k, l;
  
  ll N;
  cin >> N;
  string s;
  cin >> s;
  
  for(i=0; i<N; i++) a[i]=s[i]-'0'-1;
  
  for(i=1; i<N; i++) tc[i]=tc[i-1]+twocnt(i);
  
  ll m=0;
  for(i=0; i<N; i++) {
    ll c=tc[N-1]-tc[i]-tc[N-1-i];
    m^=(a[i]&1)*(c==0);
  }
  
  
  if(m) {
    pt(1);
  }else {
    for(i=0; i<N; i++) {
      if(a[i]==1) {
        pt(0); return 0;
      }
    }
    
    for(i=0; i<N; i++) a[i]>>=1;
    
    m=0;
    for(i=0; i<N; i++) {
      ll c=tc[N-1]-tc[i]-tc[N-1-i];
      m^=(a[i]&1)*(c==0);
    }
    
    if(m) pt(2);
    else  pt(0);
    
  }
  
  
}




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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    char s;
    cin >> s;
    printf("%c", s+1);
    return 0;
}



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

int main() {
  int n; cin >> n;
  int fib[50];
  fib[0] = fib[1] = 1; //初期条件
  //n>=2のとき
  for ( int i = 2; i <= n; i++ ) {
    fib[i] = fib[i-2] + fib[i-1];
  }

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

Measured memory_bytes: 1164
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=lmp()
x=0
y=sum(a)
ans=abs(x-y)
for i in range(n):
    x+=a[i]
    y-=a[i]
    ans=min(ans,abs(x-y))
print(ans)

Measured memory_bytes: 27792
import java.util.*;
import java.io.*;

class Main{
  static boolean found = false;
  public static void main(String[] args) throws IOException {
    PrintWriter out = new PrintWriter(System.out);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    // StringTokenizer st  = new StringTokenizer(br.readLine());

    String s = br.readLine();

    long sum = 0;
    for (int i=0; i<s.length(); i++) {
      sum+= Character.getNumericValue(s.charAt(i));
      sum = sum%9;
    }
    if (sum%9==0) {
      out.println("Yes");
    }
    else {
      out.println("No");
    }
    out.close();
  }

  
}










Measured memory_bytes: 36048