akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 1e6 + 5;

int n;

int spf[N];

void sieve() {
	for (int i = 1; i < N; i ++) {
		spf[i] = i;
	}
	for (int i = 4; i < N; i += 2) {
		spf[i] = 2;
	}
	for (int i = 3; i * i < N; i ++) {
		if (spf[i] == i) {
			for (int j = i * i; j < N; j += i) {
				if (spf[j] == j) {
					spf[j] = i;
				}
			}
		}
	}
}

int main() {

	FAST;

	sieve();
	cin >> n;
	vector <int> a(n + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	vector <int> cnt(N), maxcnt(N);
	for (int i = 1; i <= n; i ++) {
		int x = a[i];
		int cur = 0, curcnt = 0;
		while (x != 1) {
			if (spf[x] == cur) {
				curcnt ++;
			}
			else {
				maxcnt[cur] = max(maxcnt[cur], curcnt);
				cur = spf[x];
				curcnt = 1;
			}
			cnt[spf[x]] ++;
			x /= spf[x];
		}
		maxcnt[cur] = max(maxcnt[cur], curcnt);
		// cur = spf[x];
		// curcnt = 1;
	}
	/* for (int i = 1; i <= 5; i ++) {
		cout << i << ' ' << cnt[i] << ' ' << maxcnt[i] << '\n';
	} */
	bool flag = true;
	for (int i = 2; i < N; i ++) {
		if (cnt[i] != maxcnt[i]) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "pairwise coprime\n";
		return 0;
	}
	int gcd = a[1];
	for (int i = 2; i <= n; i ++) {
		gcd = __gcd(gcd, a[i]);
	}
	if (gcd == 1) {
		cout << "setwise coprime\n";
	}
	else {
		cout << "not coprime\n";
	}
	return 0;
}

Measured memory_bytes: 18720
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct {
    char suit;
    int value;
}Card;

Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i = 0; i < n1; i++) L[i] = A[left + i];
    for(i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = 0, j = 0;
    for(k = left; k < right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card A[], int n, int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(Card A[], int n, int p, int r){
    int i, j;
    Card x, tmp;
    x = A[r];
    i = p - 1;
    for(j = p; j < r; j++){
        if(A[j].value <= x.value){
            i++;
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp; 
        }
    }
    tmp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp;
    return i + 1;
}

void quickSort(Card A[], int n, int p, int r){
    if(p < r){
        int q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main(){
    int n, i, v;
    Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for(i = 0; i < n; i++){
        //マージソートとクイックソートの結果を比べる
        if(A[i].suit != B[i].suit) stable = 0;
    }
    if(stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i = 0; i < n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 4024
n,m,R = gets.split.map(&:to_i)
r = gets.split.map(&:to_i)

dp = Array.new(n+1).map{Array.new(n+1,10**9)}
m.times do
    a,b,c = gets.split.map(&:to_i)
    dp[a][b] = c
    dp[b][a] = c
end

1.upto(n) do |k|
    1.upto(n) do |s|
        1.upto(n) do |f|
            if dp[s][f] > dp[s][k] + dp[k][f]
                dp[s][f] = dp[s][k] + dp[k][f]
            end
        end
    end
end

ans = 10**9
r.permutation do |arr|
    count = 0
    (R-1).times do |i|
        count += dp[arr[i]][arr[i+1]]
    end
    ans = count if ans > count
end

puts ans

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

int main(){
    int n;
    cin >> n;
    
    int count = 0, ans = 0;
    rep(i, n){
        rep(j, n){
            if((i+1)%(j+1) == 0){
                count++;
            }
        }
        if(count == 8) ans++;
        count = 0;
    }

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

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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=2e5+10;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

i32 N;
ar Cnt;

int main(){
    N=read();
    f(i,2,I,N) Cnt[ read() ]++;
    f(i,1,I,N) print(Cnt[i]),print('\n');
    output();
    return 0;
}

Measured memory_bytes: 4632
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 19:31:10 2019
ABC118B
@author: maezawa
"""

n, m = list(map(int, input().split()))
a0 = list(map(int, input().split()))
k = a0.pop(0)
common = set(a0)
for i in range(1, n):
    ai = list(map(int, input().split()))
    k = ai.pop(0)
    common = common & set(ai)
    
print(len(common))


Measured memory_bytes: 3064
let find x a =
  let n = Array.length a in
  let rec doit i =
    if i = n then exit 1
    else if a.(i) = x then i
    else doit (i + 1)
  in
  doit 0

let () =
  let n = read_int () in
  let preorder = Queue.create () in
  let rec read i =
    if i < n then begin
      Queue.add (Scanf.scanf "%d " (fun i -> i)) preorder;
      read (i + 1)
    end
  in
  read 0;
  let inorder = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let postorder = Queue.create () in
  let rec doit l r =
    if l < r then begin
      let root = Queue.take preorder in
      let m = find root inorder in
      doit l m;
      doit (m + 1) r;
      Queue.add root postorder
    end
  in
  doit 0 n;
  print_int (Queue.take postorder);
  Queue.iter (fun e -> Printf.printf " %d" e) postorder;
  print_newline ()

Measured memory_bytes: 2428
import Control.Applicative
import Control.Monad

-- TSEWNB
roll [] d = d
roll (o:os) d 
  | o == 'N' = roll os $ [d!!1,d!!5,d!!2,d!!3,d!!0,d!!4]   -- 0->4->5->1->0
  | o == 'E' = roll os $ [d!!3,d!!1,d!!0,d!!5,d!!4,d!!2]   -- 0->2->5->3->0
  | o == 'W' = roll os $ [d!!2,d!!1,d!!5,d!!0,d!!4,d!!3]   -- 0->3->5->2->0
  | o == 'S' = roll os $ [d!!4,d!!0,d!!2,d!!3,d!!5,d!!1]   -- 0->1->5->4->0

main = do
  label <- words <$> getLine
  order <- getLine
  let d = roll order [0..5]
  putStrLn $ label!!(d!!0)

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

int ls = 2;

template<class T>
struct EdmondsKarp{
	struct Edge{
		int to,rev;
		T cap;
		Edge(int to,T cap,int rev) : to(to),rev(rev),cap(cap){}
	};

	vector<vector<Edge>> G;

	EdmondsKarp(int n) : G(n){}

	void addEdge(int from,int to,T cap,bool isDirected = true){
		G[from].emplace_back(to,cap,G[to].size());
		G[to].emplace_back(from,isDirected ? 0 : cap,G[from].size() - 1);
	}

	T flow(int s,int t){
		T ret = 0;
		while(1){
			queue<int> que;
			vector<int> prevv(G.size(),-1),preve(G.size(),-1);
			vector<T> aug(G.size(),numeric_limits<T>::max());
			que.push(s);
			while(!que.empty()){
				int v = que.front();que.pop();
				if(v == t) break;
				for(int i = 0;i < G[v].size();i++){
					const auto &e = G[v][i];
					if(prevv[e.to] < 0 && e.cap){
						prevv[e.to] = v;
						preve[e.to] = i;
						aug[e.to] = min(aug[v],e.cap);
						que.push(e.to);
					}
				}
			}
			if(prevv[t] < 0) return ret;
			for(int v = t;v != s;v = prevv[v]){
				G[prevv[v]][preve[v]].cap -= aug[t];
				G[v][G[prevv[v]][preve[v]].rev].cap += aug[t];
			}
			ret += aug[t];
		}
	}
};

signed main(){
	int h,w,sx,sy,tx,ty;
	string field[300];
	int num[300][300];
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++) num[i][j] = -1;
	}
	for(int i = 0;i < h;i++) {
		cin >> field[i];
		for(int j = 0;j < w;j++){
			if(field[i][j] == 'S'){
				sx = i;
				sy = j;
				num[i][j] = 0;
			}else if(field[i][j] == 'T'){
				tx = i;
				ty = j;
				num[i][j] = 1;
			}
			else if(field[i][j] == 'o') num[i][j] = ls++;
		}
	}
	if(sx == tx || sy == ty){
		cout << -1 << endl;
		return 0;
	}
	EdmondsKarp<int> ek(ls * 2);
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(num[i][j] != -1){
				for(int k = 0;k < h;k++){
					if(num[k][j] != -1 && k != i) ek.addEdge(num[i][j] + ls,num[k][j],5000);
				}
				for(int k = 0;k < w;k++){
					if(num[i][k] != -1 && k != j) ek.addEdge(num[i][j] + ls,num[i][k],5000);
				}
				if(num[i][j] >= 2) ek.addEdge(num[i][j],num[i][j] + ls,1);
			}
		}
	}
	cout << ek.flow(ls,1) << endl;
	return 0;
}


Measured memory_bytes: 62752
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll a; string b; cin >> a >> b;
    string c; for(auto i:b) if(i!='.') c+=i;
    int d = stoi(c);
    ll e = a * d;
    cout << e/100 << endl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	long double a, b;
	cin >> a >> b;

	for (long double x = 1; x < 10000000; x += 1.0) {
		long double xa = floor(x * 0.08);
		long double xb = floor(x * 0.1);
		if (xa == a && xb == b) {
			cout << (int)x << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,k;
    cin>>n>>k;
    int h[n];
    rep(i,n){
        cin>>h[i];
    }
    int cnt=0;
    rep(i,n){
        if(h[i]>=k)cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 3960
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<string> w(n);
  map<string, int> wc;
  for (int i = 0; i < n; i++) {
    cin >> w[i];
    if (wc[w[i]] > 0 ) {
      cout << "No" << endl;
      return 0;
    }
    wc[w[i]]++;
    if (i > 0 && w[i - 1][w[i - 1].size() - 1] != w[i][0]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc149/tasks/abc149_b
# math
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
a, b, k = map(int, input().split())

if a <= k:
    k -= a
    a = 0
    b -= k
    if b < 0:
        b = 0
else:
    a -= k
print(a, b)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <utility>
#include <numeric>
#include <functional>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define INF 1e9
#define MOD 1e9+7
#define ll long long

using namespace std;
int main(void){
    vector<int> v(26,0);
    string s;
    cin>>s;
    rep(i,0,s.length()){
        v[s[i]-'a']++;
    }
    
    rep(i,0,26){
        if(v[i]>1){
            cout<<"no"<<endl;
            return 0;
        }
    }
   cout<<"yes"<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long ul;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef set<int> si;
typedef multiset<int> mi;
 
const ll INF = 1e18;
const int MOD = 1e9+7;

int main() {
	
	ll X, K, D;
	cin>>X>>K>>D;
	
	X=abs(X);
	
	ll steps=X/D;
	
	if(steps>K) {
		cout<<X-K*D<<"\n";
	}
	
	else {
		if( (K-steps)%2==0 ) cout<<X-D*steps<<"\n";
		else cout<<D*(steps+1)-X<<"\n";
	}
	
	return 0;
	
}




Measured memory_bytes: 3680
# C

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

if K == 0:
    print(N**2)
    quit()

ans = 0
for i in range(1, N - K + 1):
    b = K + i
    x = int((N - K) / b)
    M = min(N, K + x*b + i - 1)

    ans += i*x + M - (K + x*b) + 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


int main() {
    int a, b;
    char op;
    
    while (cin >> a >> op >> b)
    {
        switch (op)
        {
        case '+':
            cout << a + b << endl;
            break;
        case '-':
            cout << a - b << endl;
            break;
        case '*':
            cout << a * b << endl;
            break;
        case '/':
            cout << a / b << endl;
            break;
        case '?':
            goto LOOPEND;
            break;
        default:
            break;
        }
    }
    LOOPEND:


    return 0;
} 

Measured memory_bytes: 3100
#include<iostream>
#define loop(i,start,end) for(int i=start;i<end;i++)
using namespace std;
int main(){
    int n,n_h;
    cin>>n>>n_h;
    int arr[n_h],sum=0;
    loop(i,0,n_h){
    	cin>>arr[i];
    	sum+=arr[i];
	}
	int ans=0;
	if(sum>n) ans=-1;
	else ans=n-sum;
	cout<<ans;
    
}

Measured memory_bytes: 3636
/*ICGNYN 17D8103016H */
import java.util.Scanner;


 class  Main {
     private static int a[];
      private  static int n;
    static public  void  main (String[] av){
     int  b;
     int ans=0;
    int ol=0;
    int mx=0;
        Scanner sc =new Scanner(System.in);
        n =sc.nextInt();
        int k= sc.nextInt();
         a= new int[n];
        int v=0;
        for(int  i=0;i<n;i++){
            v=sc.nextInt();
            if (mx<v){
mx=v;
            }
            a[i]=v;
            ol+=v;
        }
        ol/=k;
if (ol<mx){
    ol=mx;
}
ol--;
//System.out.println(ol+"   aaaa");
while (true){
    ol++;
if(k3(ol,k)){
    break;
}

}

System.out.println(ol);


        }
        public static boolean k3(int ol,int k){
            int ck=1;int sum=ol;
for(int i=0;i<n;i++){
    if(sum==0){
        ck++;
        sum=ol;
    }
if ( a[i]>sum){
    ck++;
    sum=ol-a[i];
}

else{
    sum= sum-a[i];
}

}
if ( k>=ck){
    return true;
}

return false;
        }

}


Measured memory_bytes: 70316
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>

using namespace std;

int P[100000];
int S[100000];

int U[100000];
int V[100000];

long long curr;
long long ans[100000];

int find(int u) {
    if (P[u] == u) return u;
    return P[u] = find(P[u]);
}

void unite(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return;
    curr -= (long long)S[u] * S[v];
    S[u] += S[v];
    P[v] = u;
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        P[i] = i;
        S[i] = 1;
    }
    curr = (long long)n * (n - 1) / 2;
    for (int i = 0; i < m; i++) {
        cin >> U[i] >> V[i];
        U[i]--;
        V[i]--;
    }
    for (int i = m - 1; i >= 0; i--) {
        ans[i] = curr;
        unite(U[i], V[i]);
    }
    for (int i = 0; i < m; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int mat[3000][3000];

void mark(int sx, int sy, int K)
{
	int ex = min(sx + K, 2 * K);
	int ey = min(sy + K, 2 * K);
	sx = max(sx, 0);
	sy = max(sy, 0);
	++mat[sy][sx];
	--mat[ey][sx];
	--mat[sy][ex];
	++mat[ey][ex];
}

int main()
{
	int N, K;
	cin >> N >> K;
	memset(mat, 0, sizeof(mat));

	for (auto i = 0; i < N; ++i)
	{
		long long tempX, tempY;
		char c;
		cin >> tempX >> tempY >> c;

		if (c == 'W')
		{
			tempY += K;
		}

		auto x = (int)(tempX % (2 * K));
		auto y = (int)(tempY % (2 * K));

		for (auto j = -1; j < 2; ++j)
		{
			for (auto k = -1; k <= 2; ++k)
			{
				auto sx = x + 2 * K * j + 1;
				if (k % 2 == 0)
				{
					sx = x - K + 1 + 2 * K * j;
				}
				if (sx <= -K || sx >= 2 * K)
				{
					continue;
				}

				auto sy = y - K + 1 + K * k;
				if (sy <= -K || sy >= 2 * K)
				{
					continue;
				}

				mark(sx, sy, K);
			}
		}
	}

	for (auto i = 0; i <= 2 * K; ++i)
	{
		for (auto j = 1; j <= 2 * K; ++j)
		{
			mat[i][j] += mat[i][j - 1];
		}
	}

	for (auto i = 0; i <= 2 * K; ++i)
	{
		for (auto j = 1; j <= 2 * K; ++j)
		{
			mat[j][i] += mat[j - 1][i];
		}
	}

	auto result = 0;
	for (auto i = 0; i < 2 * K; ++i)
	{
		for (auto j = 0; j < 2 * K; ++j)
		{
			result = max(result, mat[i][j]);
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 35456
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を配列として読み込み
    # s = list(input().rstrip())
    # N, A = [int(_) for _ in input().split()]
    # X = [int(_) for _ in input().split()]
    s = input().rstrip().split(' ')
    N = int(s[0])
    T = int(s[1])
    A = [int(_) for _ in input().split()]
    min_a = A[0]
    max_cost = 0
    ans = 0
    for a in A:
        if(min_a > a):
            min_a = a
        if(a-min_a > max_cost):
            max_cost = a-min_a
            ans = 1
        elif(a-min_a == max_cost):
            ans = ans + 1
    print(ans)
if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1223372036854775807;
const ll mod = 1000000007;		




int main() {

	
	int n, m;
	cin >> n >> m;

	VVLL a(n, VLL(2));
	REP(i, n)cin >> a[i][0] >> a[i][1];

	sort(ALL(a));

	ll ans = 0;

	REP(i, n) {
		ans += a[i][0] * a[i][1];
		m -= a[i][1];
		if (m == 0)break;
		else if (m < 0) {
			m = abs(m);
			ans -= a[i][0] * m;
			break;
		}
	}

	cout << ans << endl;


	return 0;


}

Measured memory_bytes: 5760
def main():
    n = int(input())
    a = [None]*n
    b = [None]*n
    for i in range(n):
        a[i],b[i] = map(int, input().split())
    a.sort()
    b.sort()    
    if n&1:
        print(b[n//2]-a[n//2]+1)
    else:
        print(b[n//2-1]+b[n//2]-a[n//2]+1-a[n//2-1])
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 25324
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

"""
それぞれの隣接2列ごとに、可能な摩擦の最小値を実現する → 小問題に分割。
"""

buffer = sys.stdin.buffer
H,W = map(int,buffer.readline().split())
C = np.frombuffer(buffer.read(),dtype='S1').reshape(H,-1)[:,:W].T

dp_1 = np.zeros((W-1,H+H+1,H+1),dtype=np.int64)
for r in range(H):
    dp_1[:,r+2:r+H+2,r+1] = (C[:-1] == C[1:,r][:,None])

INF = 10**18
# R-L+H -> min cost
dp = np.full((W-1,H+1),INF,dtype=np.int64)
dp[:,0] = 0
for n in range(1,H+H+1):
    if n >= 2:
        dp_1[:,n,1:] += dp_1[:,n-2,:-1]
    # n個目を置く
    prev = dp
    dp = np.full((W-1,H+1),INF,dtype=np.int64)
    dp[:,1:] = np.minimum(dp[:,1:],prev[:,:-1])
    dp[:,:] = np.minimum(dp[:,:],prev[:,:])
    dp += dp_1[:,n,:]
answer = dp[:,H].sum()
print(answer)

Measured memory_bytes: 439364
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        Map<Integer,Deque<Long>> Stack = new HashMap<>();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<n;i++){
            Deque<Long> L = new ArrayDeque<>();
            Stack.put(i,L);
        }
        for(int i=0;i<q;i++){
            int cmd = sc.nextInt();
            int t = sc.nextInt();
            if(cmd==0) Stack.get(t).push(sc.nextLong());
            else if(cmd==1 && Stack.get(t).size()!=0) sb.append(Stack.get(t).getFirst()+"\n");
            else if(cmd==2 && Stack.get(t).size()!=0) Stack.get(t).pop();
        }
        System.out.print(sb);
    }
}


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

// #define multitest 1
#define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int h, w;
	cin >> h >> w;
	vector<string> S(h);
	vector<vector<int>> Count(h, vector<int>(w));
	for (auto &x : S)
		cin >> x;
	for (int i = 0; i < h; ++i)
	{
		int j, prevcnt = 0;
		for (j = 0; j < w; ++j)
		{
			if (S[i][j] == '#')
			{
				int j1 = j - 1, cnt = prevcnt;
				while (cnt--)
					Count[i][j1--] = prevcnt;
				prevcnt = 0;
			}
			else
				prevcnt++;
		}
		int j1 = j - 1, cnt = prevcnt;
		while (cnt--)
			Count[i][j1--] = prevcnt;
		// prevcnt = 0;
	}
	ll answer = 0;
	for (int i = 0; i < w; ++i)
	{
		int j, prevcnt = 0;
		for (j = 0; j < h; ++j)
		{
			if (S[j][i] == '#')
			{
				int j1 = j - 1, cnt = prevcnt;
				while (cnt--)
					answer = max(answer, (ll)prevcnt + Count[j1--][i]);
				prevcnt = 0;
			}
			else
				prevcnt++;
		}
		int j1 = j - 1, cnt = prevcnt;
		while (cnt--)
			answer = max(answer, (ll)prevcnt + Count[j1--][i]);
		prevcnt = 0;
	}
	cout << max(0LL, answer - 1);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

// AtCoder Educational DP -E Knapsack 2
// 解説見た。ヘナチョコだね。

// dp[N, V]。
// N個までの範囲で、Vに出来る重量最小値を求める。
// Nは最大100、Vは最大値1kの100倍で100k

// treasure[i].weightが指定重量Wを超えない場合かつ、ループVの価値を超えない場合、dpの計算を行う。
// dp[N, V]は、Min(dp[N-1, V], (dp[N-1, V - treasure[i].value] + treasure[i].weight <= W) ? go : long.MaxValue)で求められる。
// （今回はピックしない場合）、1個少ない場合の重量最小値と等価である。
// （今回はピックする場合）、1個少なく、かつ価値が(今回価値-ピック価値)のときの最小値に合算で重量が求まる。
//  							→ただし、それによって重量がWを超えない場合。超えるならinfとする。
// infでない値が代入されるたび、Vの値の最大値を記録する。
//  
// dp計算後、infでない値が入っている最も大きいVが解答となる。



public class Program{

	public static void Main(){
		//int a = int.MaxValue;
		
		
		
		var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
		var N = input[0];
		var W = input[1];
		
		long totalValue = 0;
		
		
		var listR = new List<Prize>();

		
		Prize temp;
		for(long i = 0; i < N; i++){
			temp = new Prize(Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse));
			listR.Add(temp);
			totalValue += temp.price;
		}
		
		var dp = new long[N+1,totalValue+1];
		
		for(long i = 0; i < N+1; i++){
		
			for(long k = 0; k <= totalValue; k++){
				if(k == 0){
					dp[i,k] = 0;
				}else{
					dp[i,k] = long.MaxValue;
				}
			}
		
		}
		var list = listR.ToArray();
		
		Prize currentPrize;
		long replaceDp;
		long maxValue = long.MinValue;
		
		for(long NL = 1; NL <= N; NL++){
		
			currentPrize = list[NL-1];
			for(long VL = 1; VL <= totalValue; VL++){
			
				
				if(currentPrize.weight <= W){
				
					
					//
					replaceDp = long.MaxValue;
					if(VL - currentPrize.price >= 0){
						if(dp[NL-1, VL - currentPrize.price] != long.MaxValue){
							replaceDp = dp[NL-1, VL - currentPrize.price] + currentPrize.weight;
							replaceDp = (replaceDp <= W) ? replaceDp : long.MaxValue;
						}
					}
					dp[NL,VL] = Math.Min(dp[NL-1,VL], replaceDp);
					if(dp[NL,VL] != long.MaxValue && dp[NL,VL] <= W){
						maxValue = Math.Max(maxValue, VL);
					}
				
				}
				
				
			
			}
		
		
		}
		for(long i = 0; i < N+1; i++){
			/*
			for(long k = 0; k <= totalValue; k++){
				Console.Write((dp[i,k] == long.MaxValue ? 0 : dp[i,k]) + ",");
			}
			*/
			Console.WriteLine();
		}
		
		
		Console.WriteLine(maxValue);
	
	
	}
	
	
	class Prize{
	
		public long weight{get;set;}
		public long price{get;set;}
		
		public Prize(long[] input){
		
			this.weight = input[0];
			this.price = input[1];
		}
	
	
	}




}

Measured memory_bytes: 89184
package main
import "fmt"


func main(){
        var N int
        var monsters, killers []int
        fmt.Scan( &N )
        for i := 0; i <= N; i ++{
                var monster int
                fmt.Scan( &monster )
                monsters = append( monsters, monster )
        }

        for i := 0; i < N; i ++{
                var killer int
                fmt.Scan( &killer )
                killers = append( killers, killer )
        }
        ret := 0
        prev_remain_killer := 0
        for i := 0; i < len( killers ); i ++ {
                monster_remain := monsters[ i ] - prev_remain_killer

                if monster_remain > 0{
                        monster_remain -=  killers[ i ]
                        if monster_remain <= 0{
                                prev_remain_killer = -monster_remain
                                monster_remain = 0
                        }else{
                                prev_remain_killer = 0
                        }
                }else{
                        prev_remain_killer = killers[ i ]
                        monster_remain = 0
                }
                ret += monsters[ i ] - monster_remain
        }

        last :=  prev_remain_killer

        if monsters[ len(monsters)-1 ] < prev_remain_killer{
                last = monsters[ len(monsters)-1 ]
        }

        fmt.Println( ret + last )
}


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

int main(){
    int a;
    cin >> a;
    map<int,int> A;
    rep(i,a){
        int b;
        cin >> b;
        A[b]++;
    }
    int sskey = 0;
    for(auto p:A){
        auto key = p.first;
        auto value = p.second;
        if(value > 1){
            cout << "NO" << endl;
            sskey = 1;
            break;
        }
    }
    if(sskey == 0)
        cout << "YES" << endl;
}
    

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

static class RomanFigure
{
    static void Main()
    {
        var dig = new Dictionary<char, int>()
        {
            { 'I', 1 },
            { 'V', 5 },
            { 'X', 10 },
            { 'L', 50 },
            { 'C', 100 },
            { 'D', 500 },
            { 'M', 1000 },
        };

        var indata = Console.In.ReadToEnd()
            .Split( 
                new[] { '\r', '\n' },
                StringSplitOptions.RemoveEmptyEntries );
        var q =
            from roman in indata
            select roman
                .Reverse()
                .Aggregate( 
                    new { acc = 0, post = dig['I'] }, 
                    (x, y) => dig[y] < x.post
                        ? new { acc = x.acc - dig[y], post = dig[y] }
                        : new { acc = x.acc + dig[y], post = dig[y] },
                    x => x.acc );
        foreach ( var num in q )
            Console.WriteLine( num );
    }
}

Measured memory_bytes: 6416
#include <iostream>

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
	if (x == 0) {
		return y;
	}
	return gcd(y % x,x);
}
int main() {
	int x, y;
	cin >> x >> y;
	cout << gcd(x, y) << endl;
}

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

int cont_idx(int start_idx, int n, char s[100001]){
  int idx = start_idx + 1;
  for(; idx<n; idx++){
    if (s[start_idx] != s[idx]) break;
  }
  return idx;
}

int main(){
  int n, k;
  scanf("%d %d", &n, &k);
  char s[100001];
  scanf("%s", s);

  
  vector<int> vc;
 
  // 1の数、0の数、1の数・・・の順にしたい
  if(s[0] == '0') vc.push_back(0);
 
  for(int i=0; i<n; i++){
    int next_idx = cont_idx(i, n, s);
  	vc.push_back(next_idx - i);
    i = next_idx-1;
  }
  
  
  int max_size = max(0, int(vc.size())/2+1-k);
  if(max_size == 0) {
    // 全部逆立ちできる
    printf("%d\n", n);
    return 0;
  }
  int result = 0;
  for(int i=0; i<max_size; i++){
    int count = vc[i*2];
    for(int j=0; j<k; j++){
      count += vc[i*2+j*2+1] + vc[i*2+j*2+2];
    }
    // if(i>30000) printf("%d %d\n", i, count);
    result = max(result, count);
  }
  
  printf("%d\n", result);
  return 0;
}

Measured memory_bytes: 1020
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


int main()
{
    //ios::sync_with_stdio(0);cin.tie(0);
    
    
    int a;
    cin >> a;
    if(a >=30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int n;

int g(string o) {
  char c = s[0];
  ll ss = 1;
  ll sum = 0;

  FOR(i, 1, o.length()) {
    if(o[i] == c) {
      ss++;
    } else {
      if(ss > 1) sum += ss / 2;
      c = o[i];
      ss = 1;
    }

    if(i + 1 == o.length()) {
      if(ss > 1) sum += ss / 2;
    }
  }

  return sum;
}


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

  cin >> s >> n;

  ll sum = g(s);
  ll sum2 = g(s + s);
  ll sum3 = g(s + s + s);
  ll su = sum2 - (sum * 2);
  ll susu = sum3 - (sum * 3);

  ll ans;
  if(su != susu) {
    ans = (sum * n) + ((n - 1) * su);
  } else {
    ans = (sum * n) + ((n / 2) * su);
  }
  cout << ans << endl;
}


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

using namespace std;

const long long int INF = 1LL<<60;
const long long int mod = 1e9 + 7;

double solve(vector<vector<vector<double>>> &dp, int i, int j, int k) {
  if(dp[i][j][k] >= 0) return dp[i][j][k];

  int N = dp.size() - 1;

  double res = 0.0;
  if (i > 0) res += solve(dp, i-1, j, k) * i;
  if (j > 0) res += solve(dp, i+1, j-1, k) * j;
  if (k > 0) res += solve(dp, i, j+1, k-1) * k;
  res += (double)N;
  res = res / (double)(i + j + k);

  return dp[i][j][k] = res;
}

int main() {
  int N;
  cin >> N;
  int one=0, two=0, three=0;
  for(int i=0; i<N; i++) {
    int a;
    cin >> a;
    if(a == 1) one++;
    else if(a == 2) two++;
    else three++;
  }

  vector<vector<vector<double>>> dp(N+1, vector<vector<double>>(N+1, vector<double>(N+1, -1)));
  dp[0][0][0] = 0.0;

  double res = solve(dp, one, two, three);
  printf("%.10f\n", res);

  return 0;
}

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

int main(){
  long long n;
  map<long long,int> mp;
  bool flag = true;

  cin >> n;
  long long tmp = n;
  if(n==1){
    cout << 0;
    return 0;
  }
  for(long long i=2;i*i<=n;i++){
    while(tmp%i==0){
      tmp/=i;
      mp[i]++;
      flag = false;
    }
  }
  if(tmp!=1)mp[tmp]++;
  
  if(flag){
    cout << 1;
    return 0;
  }
  
  int ans = 0;
  for(auto a:mp){
    int num = a.second;
    // cout << "[" << a.first << " " << a.second << "]"; 
    
    int tmp=1;
    while(num>=tmp){
      num-=tmp;
      tmp++;
      ans++;
    }
  }

  cout << ans;
  return 0;
}


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

int main(){
  int n;
  cin>>n;
  map<char,int> mp;
  rep(i,n){
    string s;
    cin>>s;
    map<char,int> now;
    rep(si,s.size()){
      if(i==0) mp[s[si]]++;
      now[s[si]]++;
    }
    for(auto x : mp){
      mp[x.first]=min(now[x.first],x.second);
    }
  }
  string ans;
  for(auto x : mp){
    rep(i,x.second){
      ans+=x.first;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

using namespace std;
unsigned long long int newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main()
{
	int N,M;
	string s;
	string t;
	cin >> N >> M;
	cin >> s;
	for(int i=0; i< N; ++i)
	{
		if(i == M-1)
			t += s[i]-'A'+'a';
		else
			t += s[i];
	}
	cout << t << endl;

	return 0;
}









Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	vector<int>V(3);
	rep(i, 3) {
		cin >> V[i];
	}
	sort(V);
	if (V[0] == V[1] && V[1] != V[2]) {
		cout << "Yes" << endl;
	}
	else if (V[0] != V[1] &&V[1] == V[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long n = sc.nextLong();
			long result = 0;

			for (long i = 1; i < n; i++) {
				result += i;
			}

			System.out.println(result);
		}
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string.h>
#include<set>
using namespace std;
#define PB push_back
inline int in() {
	int temp;
	scanf("%d", &temp);
	return temp;
}

int main() {
	string s;
	int g = 0, p = 0, ag, ap, ans = 0, lose, win;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'g')
			g++;
		else
			p++;
	}
	ag = s.size();
	for (int i = 0; i < s.size(); i++) {
		if (ag - i < i)
			break;
		lose = ag - g;
		win = min(g, i);
		ans = max(ans, win - lose);
	}
	cout << ans << endl;
}



Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
using namespace std;



int main() {
	//cout << fixed << setprecision(10);
	long long int a, b, c, d, n, m;
	cin >> a >> b;
	if (b%a == 0) {
		cout << a + b;
	}
	else {
		cout << b - a;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main () {

  ll N, M;
  cin >> N;
  cin >> M;

  if ( N == M ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  long long int n,k;
  cin>>n>>k;
  long long int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(long long int i = k;i<n;i++)
  {
    if(a[i] > a[i-k]){cout<<"Yes\n";}
    else{cout<<"No\n"<<endl;}
  }
}

Measured memory_bytes: 5164
from itertools import product

a = list(str(input()))


for bit in product([0,1],repeat=3): # 01の組み合わせ
    x = ["+","+","+"]
    for i,j in enumerate(bit): 
        #print(bit,i,j)
        if j == 1:
            x[i] = "-"
    if eval(a[0]+x[0]+a[1]+x[1]+a[2]+x[2]+a[3]) == 7:
        print(a[0]+x[0]+a[1]+x[1]+a[2]+x[2]+a[3]+"=7")
        break 


"""       i j
(0, 0, 0) 0 0
(0, 0, 0) 1 0
(0, 0, 0) 2 0

(0, 0, 1) 0 0
(0, 0, 1) 1 0
(0, 0, 1) 2 1

(0, 1, 0) 0 0
(0, 1, 0) 1 1
(0, 1, 0) 2 0

(0, 1, 1) 0 0
(0, 1, 1) 1 1
(0, 1, 1) 2 1

(1, 0, 0) 0 1
(1, 0, 0) 1 0
(1, 0, 0) 2 0

(1, 0, 1) 0 1
(1, 0, 1) 1 0
(1, 0, 1) 2 1

(1, 1, 0) 0 1
(1, 1, 0) 1 1
(1, 1, 0) 2 0

(1, 1, 1) 0 1
(1, 1, 1) 1 1
(1, 1, 1) 2 1
"""
            

Measured memory_bytes: 3064
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
  ll k;
  cin>>k;
  ll ans=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int p=1;p<=k;p++){
        ans+=__gcd(i,__gcd(j,p));
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    string a;
    string b;

    cin>>a>>b;
    int lena = a.length();
    int lenb = b.length();

    if(lena > lenb)
        cout<<"GREATER";
    else if (lena < lenb)
        cout<<"LESS";
    else {
        if(a.compare(b) == 0) {
            cout<<"EQUAL";
        } else if(a.compare(b) > 0) {
            cout<<"GREATER";
        } else {
            cout<<"LESS";
        }
    }

return 0;
}

Measured memory_bytes: 3648
k,a,b = map(int,input().split())
if a >= b or a + 2 >= b:
    print(k+1)
else:
    if k+1 <= a:
        print(k+1)
    else:
        k = k-a+1
        c = k%2
        d = k//2
        print(a+(b-a)*d+c)

Measured memory_bytes: 9164
#include <iostream>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;

const int NMAX = 100005;
ll h[NMAX], d[NMAX];
ll poz, n;

int main()
{
    int i;
    cin >> n >> h[1]; h[0] = INT_MAX;
    for(i = 2; i <= n; i++) {
        cin >> h[i];
        d[i] = INT_MAX;
        int ok = 0;
        for(int j = 1; j <= 2 && i >= j; j++) {
            int x = abs(h[i] - h[i - j]);
            d[i] = min(d[i], d[i - j] + x);
        }
    }
    cout << d[n];
    return 0;
}


Measured memory_bytes: 5140
import java.util.Scanner;


public class Main{
	static int[] dx={1,1,0,-1,-1,-1,0,1};
	static int[] dy={0,-1,-1,-1,0,1,1,1};

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);

		while(true){
			int w=sc.nextInt();
			int h=sc.nextInt();
			if(w==0) break;

			int[][] B=new int[h][w];
			for(int i=0;i<h;i++) for(int j=0;j<w;j++) B[i][j]=sc.nextInt();

			int ans=0;
			for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(B[i][j]==1) {
				B[i][j]=0;

				int head=0,tail=0;
				int[] Q=new int[h*w];
				Q[tail++]=i*w+j;
				while(head<tail){
					int y=Q[head]/w,x=Q[head]%w; head++;
					for(int k=0;k<8;k++){
						int yy=y+dy[k],xx=x+dx[k];
						if(0<=yy && yy<h && 0<=xx && xx<w && B[yy][xx]==1){
							B[yy][xx]=0;
							Q[tail++]=yy*w+xx;
						}
					}
				}
				ans++;
			}
			System.out.println(ans);
		}

		return;
	}
}

Measured memory_bytes: 53580
N = int(input())
S = input()

def pcnt(x):
    return str(bin(x)).count("1")

dpl = 5*10**5
dp = [0] * dpl
for i in range(1, dpl):
    dp[i] = dp[i % pcnt(i)]+1

c = S.count("1")
a = int(S, 2) % (c+1)
 
def f():
    if c == 1:
        for i in range(N):
            if S[i] == "0":
                print(dp[(a + pow(2, N-i-1, c+1)) % (c+1)] + 1)
            else:
                print(0)
        return
    
    b = int(S, 2) % (c-1)
    for i in range(N):
        if S[i] == "0":
            print(dp[(a+pow(2, N-i-1, c+1))%(c+1)]+1)
        else:
            print(dp[(b-pow(2, N-i-1, c-1))%(c-1)]+1)

f()

Measured memory_bytes: 13432
#include <stdio.h>

int main(void)
{
    int n, d;
    int ans;
    scanf("%d%d", &n, &d);

    for (ans = 0; ans < n; ans++)
        if ((d * 2 + 1) * ans >= n)
            break;

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep( i, n ) for (ll i = 0; i < ( ll )(n); i++)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;



int main(){
    int s,w;
    cin>>s>>w;

    if(s>w) cout<<"safe";
    else cout<<"unsafe";
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - ABD
            int n = int.Parse(Console.ReadLine());

            if (n <= 999)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ABD");
            }
        }
    }
}

Measured memory_bytes: 13140
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# ac_py.main
# Date: 2020/06/08
# Filename: main 
# Author: acto_mini

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    print(sum(a[::2]) - sum(a[1::2]))
    return


if __name__ == '__main__':
    main()


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

int main()
{
    int n,i,j;cin>>n;int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n;i++)  a[i]-=(i+1);
    sort(a,a+n);
    ll s=0;
    for(i=0;i<n;i++) s+=abs(a[i]-a[n/2]);
    cout<<s;


    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println(a + b == c || b + c == a || c + a == b ? "Yes" : "No");
	}
}


Measured memory_bytes: 35636