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

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

    vector<vector<int>> truth(n, vector<int>(n, -1));
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        for (int j=0; j<a; j++){
            int x, y;
            cin >> x >> y;
            truth[i][x-1] = y;
        }
    }

    int ans = 0;
    for(int i=0; i<1<<n; i++){
        bool no = false;
        bitset<15> b(i);
        for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
                if(b[j]){
                    if(truth[j][k] != -1 && truth[j][k]!=b[k]){
                        // cout << b[j] << j << truth[j][k] << b[k] << endl;
                        no = true;
                        break;
                    }
                }
            }
            if (no){
                break;
            }
        }
        if(!no){
            // cout << b << endl;
            ans = max(ans, int(b.count()));
        }

    }

    cout << ans << endl;

    return 0;
}

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

int main(void){
    int n;
    int a, b;
    int sum = 0;

    cin >> n >> a >> b;
    sum = n * a;

    if (sum <= b){
        cout << sum << endl;        
    } else {
        cout << b << endl;
    }    
    return 0;
}

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

int main() {
    int a,b;
    cin >> a >>b;
    if((a*b) %2==0){
        cout <<"Even" << endl;
    }else{
        cout << "Odd" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
string S;
string T;
cin >> S;
cin >> T;

bool flag = true;


for (int i = 0; i < S.size(); i++)
{
    if(S[i] != T[i] ){
        flag = false;
    }

}

if(T.size() != S.size() +1){
    flag = false;
} 

if(S.size() > 10 || S.size() < 1){
    flag = false;
}

for (int i = 0; i < S.size(); i++)
{
    if(S[i] < 'a' && S[i] > 'z'){
        flag = false;
    }
    /* code */
}

for (int i = 0; i < T.size(); i++)
{
    if(T[i] < 'a' && T[i] > 'z'){
        flag = false;
    }
    /* code */
}

if(flag == false){
    cout << "No" << endl;
}
else{
    cout << "Yes" << endl;
}

return 0;
}

Measured memory_bytes: 3528
/*package whatever //do not write package name here */

import java.io.*;
import java.util.Scanner;


class Main {
	public static void main (String[] args) {
	    Scanner in = new Scanner(System.in);
	    int n = in.nextInt();

        char[] a = in.next().toCharArray();
        int red = 0,ans = 0;
        for(int i=0;i<n;i++) {
            if(a[i] == 'R') red++;
        }
        for(int i=0;i<red;i++) {
            if(a[i] == 'W') ans++;
        }

        System.out.println(ans);
	}
}

Measured memory_bytes: 40528
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int min = 100000;
    for (int i = 0; i < n; i++) {
      int m = sc.nextInt();
      x -= m;
      if (min > m) min = m;
    }
    System.out.println(n + x / min);
  }
}


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

#define N 500001
#define LARGE 1000000001

int n;
int swap_count = 0;
int L[N / 2 + 2], R[N / 2 + 2];


void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;

    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    L[n1] = LARGE;
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    R[n2] = LARGE;

    int i = 0;
    int j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] < R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
        swap_count++;
    }
}

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

int main() {
    cin >> n;

    int A[N];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    mergeSort(A, 0, n);

    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << swap_count<< endl;
}


Measured memory_bytes: 6984
n = int(input())
s = [input() for s in range(n)]
m = int(input())
t = [input() for i in range(m)]
plus = []
minus = []
total = []

for i in set(s):
    plus.append(s.count(i))
    minus.append(t.count(i))

for j in range(len(plus)):
    total.append(plus[j]-minus[j])
    
print(max(0,max(total)))

Measured memory_bytes: 9104
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, M;  
  cin >> N >> M;
  vector<int> v;
  for (int i = 1; i <= (int)sqrt(M); i++) {
    if (M % i != 0) continue;
    int j = M / i;
    if (i <= M / N) v.push_back(i);
    if (j <= M / N) v.push_back(j);
  }
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}


Measured memory_bytes: 256
from fractions import gcd
from functools import reduce

n, X = map(int, input().split())
x = list(map(int, input().split()))

x.append(X)
x = sorted(x)
diff_x = []
for i in range(len(x)-1):
    diff_x.append(x[i+ 1] - x[i])


ans = reduce(gcd, diff_x)

print(ans)




Measured memory_bytes: 16280
N = int(input())
s=[]
for i in range(N):
	s.append(input())

print('AC x {}'.format(s.count('AC')))
print('WA x {}'.format(s.count('WA')))
print('TLE x {}'.format(s.count('TLE')))
print('RE x {}'.format(s.count('RE')))

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

int main() {
  int year, month, day;
  char x, y;
  cin >> year >> x >> month >> y >> day;
  if (year > 2019) 
    cout << "TBD" << endl;
  else if (year < 2019)
    cout << "Heisei" << endl;
  else if (year == 2019) {
    if (month <= 4)
      cout << "Heisei" << endl;
    else if (month > 4)
      cout << "TBD" << endl;
  }
  return 0;
}
      

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str = lines[0];
        String[] str1 = str.split(" ");
        int W = Integer.parseInt(str1[0]);
        int H = Integer.parseInt(str1[1]);
        int x = Integer.parseInt(str1[2]);
        int y = Integer.parseInt(str1[3]);
        int r = Integer.parseInt(str1[4]);

        if (x <= 0 || y <= 0 || x + r <= 0 || y + r <=0){
            System.out.println("No");
            return;
        } else if (W >= x + r && H >= y + r){
            System.out.println("Yes");
            return;
        } else {
            System.out.println("No");
        }
    
    }

  
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
  
}



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

int A,B;

int main() {
    cin>>A>>B;
    if ((max(A,B)-min(A,B))%2==0) cout<<(max(A,B)+min(A,B))/2<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: March
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int M = 5;
const int K = 3;

const char cs[M + 1] = "MARCH";

/* typedef */

typedef long long ll;

/* global variables */

int cmap[26], es[M], ds[K];
bool used[M];

/* subroutines */

ll rec(int k, int i0) {
  if (k >= K) {
    ll p = 1;
    for (int i = 0; i < K; i++) p *= es[ds[i]];
    return p;
  }

  ll sum = 0;
  for (int i = i0; i < M; i++)
    if (! used[i]) {
      used[i] = true;
      ds[k] = i;
      sum += rec(k + 1, i + 1);
      used[i] = false;
    }
  return sum;
}

/* main */

int main() {
  memset(cmap, -1, sizeof(cmap));
  for (int i = 0; i < M; i++) cmap[cs[i] - 'A'] = i;

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    char s[16];
    scanf("%s", s);

    es[cmap[s[0] - 'A']]++;
  }

  ll ans = rec(0, 0);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 3010;

int dp[N][N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    s = '.' + s;
    t = '.' + t;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= m; j ++)
        {
            if (s[i] == t[j])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    string lcs;
    while (n && m)
    {
        if (s[n] == t[m])
        {
            lcs += s[n];
            n --; m --;
        }
        else
        {
            if (dp[n - 1][m] < dp[n][m - 1])
                m --;
            else
                n --;
        }
    }
    for (int i = (int)(lcs.size()) - 1; i > -1; i --)
        cout << lcs[i];
    return 0;
}


Measured memory_bytes: 35584
#include<iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	int count = 0;
	for (int i = 2; i < s.size() - 1; i++) {
		
		if(s[i]=='C'){
			count++;
		}
	}
	if (count == 0||count>=2) {
		cout << "WA" << endl;
		return 0;
	}
	int sum = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] < 97) {
			sum++;
		}
	}
	if (sum > 2) {
		cout << "WA" << endl;
		return 0;
	}
	cout << "AC" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, 0, n)cin >> a[i];
	int cnt = 0;
	int pre = a[0];
	rep(i, 1, n) {
		if (pre == a[i]) {
			cnt++;
			a[i] = -1;
		}
		pre = a[i];
	}
	cout << cnt;
	return 0;
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int result = 1;

			for (int i = 0; i < 3; i++) {
				result *= n;
			}
			System.out.println(result);
		}
	}
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
#define int ll
const int MOD = 1e9 + 7;

int add(int a, int b) {
	a += b;
	if (a >= MOD) 
		a -= MOD;
	return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0) 
        a += MOD;
    return a;
}

int mul(int a, int b) {
	return (ll) a * b % MOD;
}

const int MAXN = 2e5 + 10;

int pows[MAXN];

void build() {
	pows[0] = 1;
	for (int i = 1; i < MAXN; i++)
		pows[i] = mul(pows[i - 1], 2);
}

int sign(int x) {
	if (x > 0) return 1;
	if (x < 0) return -1;
	return 0;
}

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

struct fraction{
	int p, q;
	bool flag;
	fraction() {}
	
	fraction(int _p, int _q) {
		p = _p, q = _q;
		if (sign(p) * sign(q) < 0) flag = true;
		else flag = false;
		p = abs(p);
		q = abs(q);
		int g = gcd(p, q);
		p /= g;
		q /= g;
	}
};

bool operator<(const fraction & a, const fraction & b) {
	return tie(a.p, a.q, a.flag) <  tie(b.p, b.q, b.flag);
}

int n;
int add0, cnt1, cnt2;
map<fraction, int> have;

void read() {
	add0 = 0, cnt1 = 0, cnt2 = 0;	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 0 && b == 0) add0++;
		else if (a == 0) cnt1++;
		else if (b == 0) cnt2++;
		else {
			have[{a, b}]++;
		}
	}
}

int ans;

void run() {
	ans = 1;
	//cerr << "have = " << endl;
	//for (auto i : have) {
	//	cerr << i.first.flag << " " << i.first.p << " " << i.first.q << " " << i.second << endl;
	//}
	for (auto i : have) {
		auto x = i.first;
		int cnt = i.second;
		int fadd = pows[cnt];
		//cerr << "cnt = " << cnt << endl;
		if (!have.count({(x.flag ? 1 : -1) * x.q, x.p})) {
			ans = mul(ans, fadd);
			continue; 
		}
		if (x < fraction((x.flag ? 1 : -1) * x.q, x.p)) continue;
		fadd = add(fadd, pows[have[{(x.flag ? 1 : -1) * x.q, x.p}]]);
		ans = mul(ans, sub(fadd, 1));
	}
	//cerr << "ans = " << ans << endl;
	ans = mul(ans, add(sub(pows[cnt1], 1), pows[cnt2]));
	ans = add(ans, add0);
}

void write() {
	cout << sub(ans, 1) << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	build();
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 20792
module Main where

import Numeric
import Data.Functor

main :: IO ()
main = do
{ [a,b] <- getInts
; let (q,r) = divMod a b
; let s = fromIntegral a / fromIntegral  b
; putStrLn . unwords $ [show q, show r, showFFloat Nothing s ""]
}

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

done :: IO ()
done = return ()

Measured memory_bytes: 3972
#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>;
#define MP make_pair

const ll INF = 1e18;

int a, b, c, d;
map<ll, ll> dp;

ll dist(ll k) {
  if (dp[k]) return dp[k];
  if (k == 0) return dp[0] = 0;
  if (k == 1) return dp[1] = d;
  ll res = d * k;
  if (INF / d < k) res = INF;
  if (k%2 == 0) res = min(res, dist(k/2)+a);
  else res = min({res, dist(k/2)+a+d, dist(k/2+1)+a+d});
  for (int i = -1; i <= 1; ++i) {
    if ((k+i)%3 == 0) res = min(res, dist((k+i)/3)+b+d*abs(i));
  }
  for (int i = -2; i <= 2; ++i) {
    if ((k+i)%5 == 0) res = min(res, dist((k+i)/5)+c+d*abs(i));
  }
  return dp[k] = res;
}

int main() {
  int t;
  cin >> t;
  rep(_, t) {
    ll n;
    cin >> n >> a >> b >> c >> d;
    dp.clear();
    cout << dist(n) << endl;
  }
  return 0;
}

Measured memory_bytes: 4408
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
int n;
int main() 
{
    scanf("%d",&n);
    int nowx=0;
    int nowy=0;
    int lt=0;
    int flag=1;
    for(int i=1;i<=n;i++)
    {
        int x,y,t;
        scanf("%d%d%d",&t,&x,&y);
        x=abs(x-nowx);
        y=abs(y-nowy);
        if (x+y>t-lt)flag=0;
        if ((t-lt-x-y)%2)flag=0; 
    }
    if (flag)puts("Yes");else puts("No");
}

Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))
#hi=h[i-1]
h.reverse()

for i in range(1,N):
    d=h[i-1]-h[i]
    if d<=-2:
        print("No")
        break
    else:
        if d==-1:
            h[i]=h[i]-1
        else:
            pass
        if i==N-1:
            print("Yes")
if N==1:
    print("Yes")
    

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

int main(){
    int N,count = 0;
    int A[200];
    bool flag = true;

    cin >> N;

    for(int i = 0;i < N;i++)
    scanf("%d",&A[i]);
    
    while(true){
        for(int i = 0;i < N;i++){
            if(A[i]%2 != 0){
                flag = false;
                break;
            }
        }

        if(flag == false)
        break;

        for(int i = 0;i < N;i++){
            A[i] /= 2;
        }

        count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3696
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int vs[3001][3001];
i64 dp[3005][3005][4];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, H, W, N);

    rep(i, 0, N) {
        var(int, y, x, v);
        --y, --x;
        vs[y][x] = v;
    }

    rep(y, 0, H) rep(x, 0, W) rep(k, 0, 4) {
        chmax(dp[y + 1][x][0], dp[y][x][k]);
        chmax(dp[y][x + 1][k], dp[y][x][k]);
        if (k < 3) {
            chmax(dp[y + 1][x][0], dp[y][x][k] + vs[y][x]);
            chmax(dp[y][x + 1][k + 1], dp[y][x][k] + vs[y][x]);
        }
    }

    print(dp[H][W - 1][0]);

    return 0;
}


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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if(H==0 && W==0){break;}
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


int main(int argc, char **argv) {
    i64 n;
    cin >> n;
    vector<i64> as(n);

    for (int i=0; i<n; ++i) {
        cin >> as[i];
    }
    sort(as.begin(), as.end(), greater<i64>());

    priority_queue<P> q;

    i64 ans{0};

    for (auto a: as) {
        if (q.empty()) {
            q.push(make_pair(a, a));
            continue;
        }
        P p = q.top(); q.pop();
        ans += p.first;

        q.push(make_pair(min(a,p.first), max(a, p.first)));
        q.push(make_pair(min(a,p.second), max(a, p.second)));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8972
n = int(input())
a = list(map(int,input().split()))
d = {}
for ai in a:
  for x in [-1,0,1]:
    if ai+x in d:
      d[ai+x] += 1
    else:
      d[ai+x] = 1
d = sorted(d.items(),key = lambda x:x[1], reverse = True)
print(d[0][1])

Measured memory_bytes: 69740
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

struct mint {

  ll x; 

  mint(ll x=0):x((x%mod+mod)%mod){} //コンストラクタを呼んで自動的にmodを取っている。

  mint operator-() const { return mint(-x);}

  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    //メンバ関数にはthisポインタがある。メンバ変数の値を返す。
    return *this;
  }

  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }

  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }

  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }

  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }

  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1); //a=x/2
    a *= a; //繰り返し二乗法
    if (t&1) a *= *this; //tが奇数のときはxを1回かける
    return a;
  }



  // for prime mod

  mint inv() const {
    return pow(mod-2);
  }

  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }

  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
    
};

vector<mint> f;
mint choose(ll n,ll r){
  return f[n]/(f[n-r]*f[r]);
}



int main()
{
    ll h,w,a,b;
    cin >> h >> w >> a >> b;
    f.resize(200000);
    f[0]=1;
    for(ll i=1;i<=200000;i++){
        f[i]=f[i-1]*i;
    }
    ll ans=0;
    for(ll i=b;i<=w-1;i++){
        mint p=choose(h-a-1+i,i);
        mint q=choose(w-i-1+a-1,a-1);
        mint r=p*q;
        ans+=r.x;
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
} 

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

int main(){
  using pint = pair<ll, ll>;
  ll N, D;
  cin >> N >> D;
  vector<pint> v(N);
  for (int i = 0; i < N; ++i)cin >> v[i].first >>v[i].second;
  ll cnt = 0;
  for (int i = 0; i< N; i++){
    if (v[i].first * v[i].first + v[i].second * v[i].second <= D * D) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 6384
#include <iostream>
#include <string>
#include <sstream>

using namespace std;
char str[600];
char *sp;

int cat(){
	char c;
	c=*sp++;
	if(c!='m'){
		sp--;
		return 1;
	}
	if(!cat())return 0;
	c=*sp++;
	if(c!='e') return 0;
	if(!cat())return 0;
	c=*sp++;
	if(c!='w') return 0;
	return 1;
}

int main(){
	cin>>str;
	sp = str;
	cout<<(cat()&&!*sp?"Cat":"Rabbit")<<endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define print(v); for(auto x:v) cout<<x<<" "; cout<<endl;
typedef long long int ll;
int main()
{
    fast;
    ll n, m;
    cin >> n >> m;
    ll sum = 0; ll arr[n + 1];
    for(ll i = 0; i < n; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    ll big = ceil((long double)sum /(long double) (4 * m));
    ll count = 0;
    for(ll i = 0; i < n; i++){
        if(arr[i] >= big){
            count++;
        }
    }
    if(count >= m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P; 
typedef tuple<ll,ll,ll> T;
const ll INF = 1e8;

int main(){
	ll H,W,h,w;
	cin >> H >> W >> h >> w;
	if(H%h == 0 && W%w == 0)
		cout << "No" << endl;
	else{
		cout << "Yes" << endl;
		for(int y=1;y<=H;y++)
			for(int x=1;x<=W;x++){
				if(y%h == 0 && x%w == 0)
					cout << -INF;
				else if ((y%h == 1 || y == 1 || h==1 ) && (x%w == 1 || x == 1 || w == 1)){
					cout << INF-1;
				}else
					cout << 0;

				if(x==W)
					cout << endl;
				else
					cout << " ";
			}
	}
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

struct union_find {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    union_find(int n) : par(n), rank(n), siz(n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
            siz[y] += siz[x];
        } else {
            par[y] = x;
            siz[x] += siz[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

struct edge{
    int u, v, cost;
};

bool comp(const edge &e1, const edge &e2){
    return e1.cost < e2.cost;
}

int kruskal(int v, vector<edge> &es){
    sort(es.begin(), es.end(), comp);
    union_find u(v);
    int ans = 0;
    for (int i = 0; i < es.size(); ++i) {
        edge ei = es[i];
        if(!u.same(ei.u, ei.v)){
            u.unite(ei.u, ei.v);
            ans += ei.cost;
        }
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    vector<pii> x(n);
    vector<pii> y(n);
    int a, b;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        x[i] = pii(a, i);
        y[i] = pii(b, i);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<edge> e;
    for (int i = 1; i < n; ++i) {
        e.push_back(edge{x[i].second, x[i-1].second, x[i].first - x[i-1].first});
        e.push_back(edge{y[i].second, y[i-1].second, y[i].first - y[i-1].first});
    }

    cout << kruskal(n, e) << endl;
}







Measured memory_bytes: 6516
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();
        long th = (long) Math.pow(10, 18);
        if (k % 2 == 0) {
            long ans = a-b;
            if (ans > th || -ans > th) {
                System.out.println("Unfair");
            } else {
                System.out.println(ans);
            }
        } else {
            long ans = b-a;
            if (ans > th || -ans > th) {
                System.out.println("Unfair");
            } else {
                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 21844
// resubmission for after contest tedtcase
fun main(args: Array<String>) {
    abc143e()
}

private data class Distance(val from: Int, val to: Int, val cost: Int)
private data class Query(val from: Int, val to: Int)

fun abc143e() {
    val (n, m, l) = readLine()!!.split(" ").map { it.toInt() }
    val lines = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }
        .map { Distance(it[0] - 1, it[1] - 1, it[2]) }
    val q = readLine()!!.toInt()
    val queries = (1..q).map { readLine()!!.split(" ").map { it.toInt() - 1 } }
        .map { Query(it[0], it[1]) }

    // 町iから町jへの移動距離
    val distances = Array(n) { IntArray(n) { Int.MAX_VALUE / 2 } }

    lines.forEach { line ->
        distances[line.from][line.to] = line.cost
        distances[line.to][line.from] = line.cost
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                distances[i][j] = Math.min(distances[i][j], distances[i][k] + distances[k][j])
            }
        }
    }

    // 町iから町jへ移動するための最低燃料補給回数
    val fuelRefills = Array(n) { IntArray(n) { Int.MAX_VALUE / 2 } }

    distances.forEachIndexed { from, tos ->
        tos.forEachIndexed { to, cost ->
            if (cost <= l) fuelRefills[from][to] = 1
        }
    }

    for (k in 0 until n) {
        for (i in 0 until n) {
            for (j in 0 until n) {
                fuelRefills[i][j] = Math.min(fuelRefills[i][j], fuelRefills[i][k] + fuelRefills[k][j])
            }
        }
    }

    val answer = queries.map { query ->
        fuelRefills[query.from][query.to].let { if (it == Int.MAX_VALUE / 2) -1 else it - 1 }
    }.joinToString(System.lineSeparator())

    println(answer)
}


Measured memory_bytes: 76612
# coding: utf-8

def main():
    n = int(input())
    lines = []
    for i in range(0, n):
        lines.append(input())

    dct = {}
    for l in lines:
        if l in dct:
            dct[l] += 1;
        else:
            dct[l] = 1;

    cmax = max(dct.values())

    print('\n'.join(sorted([k for k,v in dct.items() if v == cmax])))

if __name__ == '__main__':
    main()


Measured memory_bytes: 35600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_150A
{
    class Program
    {
        static void Main(string[] args)
        {
            int K, X;
            var word = Console.ReadLine().Split(' ');
            K = int.Parse(word[0]);
            X = int.Parse(word[1]);

            if(500*K>=X)
                Console.Write("Yes");
            else
                Console.WriteLine("No");
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[510][510];
ll U[510][510];
ll D[510][510];

ll dp[2][510][510];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		rep(j, 0, N) {
			if(i == j) continue;
			cin >> A[i][j];
		}
	}
	rep(i, 0, N) {
		rep(j, 0, i) {
			U[i][j + 1] = U[i][j] + A[j][i];
		}
	}
	rep(i, 0, N) {
		rep(j, 0, i) {
			D[i][j + 1] = D[i][j] + A[i][j];
		}
	}
	rep(i, 0, 2) {
		rep(j, 0, N + 1) {
			rep(k, 0, N + 1) {
				dp[i][j][k] = linf;
			}
		}
	}
	dp[1][0][0] = 0;
	int now = 1, nex = 0;
	rep(i, 1, N) {
		rep(j, 0, N) {
			rep(k, 0, N) {
				dp[nex][j][k] = linf;
			}
		}
		rer(j, N, 0) {
			rer(k, N, 0) {
				if(dp[now][j][k] == linf) continue;
				MIN(dp[now][k][i], dp[now][j][k]);
			}
		}
		rep(j, 0, N) {
			rep(k, 0, N) {
				// debug(i, j, k, dp[i][j][k], U[i][i] - U[i][k], D[i][j]);
				MIN(dp[nex][j][k], dp[now][j][k] + (U[i][i] - U[i][k]) + D[i][j]);
			}
		}
		swap(now, nex);
	}
	ll res = linf;
	rep(j, 0, N) {
		rep(k, 0, N) {
			// debug(N, j, k, dp[N][j][k]);
			MIN(res, dp[now][j][k]);
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, s.size()) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, csize; cin >> n >> csize;
  vvi d(csize);
  REP(i, csize) {
    d[i].resize(csize);
    REP(j, csize) {
      cin >> d[i][j];
    }
  }
  vvi c(n);
  REP(i, n) {
    c[i].resize(n);
    REP(j, n) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }

  vvi s(3);
  REP(i, 3) s[i].resize(csize, 0);
  REP(i, n) {
    REP(j, n) {
      REP(k, csize) {
        s[(i+j)%3][k] += d[c[i][j]][k];
      }
    }
  }

  int mi = 1000000000;

  REP(i, csize) {
    REP(j, csize) {
      REP(k, csize) {
        if(i != j && j != k && k != i) {
          mi = min(mi, s[0][i] + s[1][j] + s[2][k]);
        }
      }
    }
  }

  cout << mi << endl;
}


Measured memory_bytes: 1280
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m,k=nm()
a=nl()
b=nl()

aa,bb=[0],[0]
for i in range(n):
  aa.append(a[i]+aa[i])
for i in range(m):
  bb.append(b[i]+bb[i])

ans,j=0,m
for i in range(n+1):
  if aa[i]>k:
    break
  while bb[j]>k-aa[i]:
    j-=1
  ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 134256
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B;
    cin >> A >> B;

    if (A > 9 || B > 9) {
        cout << "-1" << endl;
    }
    else {
        cout << (A * B) << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
// B. 

#include <iostream>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	long long N, prev = 0, ans = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		long long a;
		cin >> a;
		if (a > 0) {
			ans += (a + prev) / 2;
			prev = (a - prev) % 2;
		} else {
			prev = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int a,b;
    char op;

    while( op != '?' ){
    cin >> a >> op >> b;
    int ans;

    if ( op == '+') ans = a + b;
    else if ( op == '-') ans = a - b;
    else if ( op == '*') ans = a * b;
    else if ( op == '/') ans = a / b;
    else break;
    cout << ans << endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    vector<pair<int, bool>> plus;
    priority_queue<int> minus;
    ll mcnt = 0, psum = 0, msum = 0;
    int pos = 0, ans = 0;
    rep(i, n) {
        int d = a[i] - b[i];
        if (d < 0) {
            d *= -1;
            msum += d;
            mcnt++;
            minus.emplace(d);
        }
        else {
            psum += d;
            plus.emplace_back(d, false);
        }
    }
    if (mcnt == 0) {
        cout << 0 << endl;
        return 0;
    }
    if (msum > psum) {
        cout << -1 << endl;
        return 0;
    }
    sort(all(plus));
    reverse(all(plus));
    while(!minus.empty()) {
        int m = minus.top(); minus.pop();
        if (plus[pos].first > m) {
            plus[pos].first -= m;
            plus[pos].second = true;
        }
        else {
            m -= plus[pos].first;
            minus.emplace(m);
            pos++;
        }
    }
    ans = mcnt;
    rep(i, sz(plus)) {
        if (plus[i].second) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
use std::io::*;
use std::str::*;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    pub fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {
            cin: cin,
        }
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace() || c.is_control())
            .take_while(|c| c.is_alphanumeric())
            .collect::<String>();
        s.parse::<T>().ok().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    
    let r: i32 = sc.read();
    let g: i32 = sc.read();

    println!("{}", g * 2 - r);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  string s;
  cin >> s;

  int N = sz(s);
  string t(N, 'g');
  rep(i, N) {
    if (i % 2)
      t[i] = 'p';
  }

  int ans = 0;
  rep(i, sz(s)) {
    if (s[i] == 'g' && t[i] == 'p')
      ans++;
    else if (s[i] == 'p' && t[i] == 'g')
      ans--;
  }
  cout << ans << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
vector<int> v(n+1,0);
    
   for(int i=1;i*i<=n;i++)
   {   
       
       for(int j=1;j*j<=n;j++)
       {   
           for(int l=1;l*l<=n;l++)
           {  
               
              long long  sq=i+j+l;
                sq*=sq;
                int val = sq-i*j-j*l-i*l;
                if(val<=n)
                v[val]++;
                 
               // cout<<val<<endl;
                
           }
       }
   }
   
 for(int i=1;i<=n;i++)
     cout<<v[i]<<endl;
  
    return 0;
    
}


Measured memory_bytes: 3560
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

void solve(long long a_I, long long a_O, long long a_T, long long a_J, long long a_L, long long a_S, long long a_Z){
	LL yu=(a_I%2+a_J%2+a_L%2)%3;
	if (yu==2 && a_I>0 && a_J>0 && a_L>0) yu=1;
	cout<<a_O+a_I+a_L+a_J-yu<<endl;	
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long a_T;
	long long a_O;
	long long a_L;
	long long a_I;
	long long a_Z;
	long long a_J;
	long long a_S;
	scanf("%lld",&a_I);
	scanf("%lld",&a_O);
	scanf("%lld",&a_T);
	scanf("%lld",&a_J);
	scanf("%lld",&a_L);
	scanf("%lld",&a_S);
	scanf("%lld",&a_Z);
	solve(a_I, a_O, a_T, a_J, a_L, a_S, a_Z);
	return 0;
}



Measured memory_bytes: 256
d = input().split(" ")
n = int(d[0])
k = int(d[1])
h = input().split(" ")
for i in range(n):
	h[i] = int(h[i])
if k >= n:
	print(0)
else:
	s = 0
	h.sort()
	for i in range(n-k):
		s += h[i]
	print(s)

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

using namespace std;

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

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define f first
#define s second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;



int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(5) << fixed;

	ll n, a, b;
	cin >> n >> a >> b;

	if(a > b){
		cout << 0;
		return 0;
	}

	if(n == 1){
		cout << (a == b);
		return 0;
	}

	n -= 2;
	cout << n * b - n * a + 1;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr long long MAX = 1e15;

vector<long long> dijkstra(const vector<vector<pair<int, long long>>> &G, int s){
    struct RadixHeap {
        inline int bsr(long long x){ return (x == 0) ? -1 : 63-__builtin_clz(x); }
        vector<pair<long long, int>> v[65];
        long long last, sz;
        RadixHeap() : last(0), sz(0) { }
        bool empty () { return (sz == 0); }
        void push(long long x, int u) { sz++; v[bsr(x^last)+1].emplace_back(x, u); }
        inline pair<long long, int> pop () {
            if (!v[0].size()) {
                int i = 1;
                while (!v[i].size()) { i++; }
                last = min_element(v[i].begin(), v[i].end())->first;
                for (auto x : v[i]) { v[bsr(x.first^last)+1].emplace_back(x); }
                v[i].clear();
            }
            pair<long long, int> res = v[0].back();
            sz--;
            v[0].pop_back();
            return res;
        }
    };
    const long long inf = INT64_MAX;
    vector<long long> ret(G.size(), inf); ret[s] = 0;
    RadixHeap rh; rh.push(ret[s], s);
    while (!rh.empty()) {
        long long dist; int node;
        tie(dist, node) = rh.pop();
        if (ret[node] < dist) continue;
        for (auto &e : G[node]) {
            int next_node; long long next_dist;
            tie(next_node, next_dist) = e;
            if (ret[next_node] > ret[node] + next_dist){
                ret[next_node] = ret[node] + next_dist;
                rh.push(ret[next_node], next_node);
            }
        }
    }
    return ret;
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<pair<int, long long>>> g1(n), g2(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        long long c1, c2;
        cin >> a >> b >> c1 >> c2;
        a--; b--;
        g1[a].emplace_back(b, c1);
        g1[b].emplace_back(a, c1);
        g2[a].emplace_back(b, c2);
        g2[b].emplace_back(a, c2);
    }
    
    vector<long long> d1 = dijkstra(g1, s); // yen
    vector<long long> d2 = dijkstra(g2, t); // snuuk
    vector<long long> d(n);
    for (int i = 0; i < n; i++) d[i] = d1[i] + d2[i];
    for (int i = n-1; i > 0; i--) d[i-1] = min(d[i-1], d[i]);
    
    for (auto& ans : d) cout << MAX - ans << '\n';
    return 0;
}

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

#define  optimize   ios::sync_with_stdio(0); cin.tie(0);
#define PI  acos(-1.0)
#define RESET(a, b) memset(a, b, sizeof(a))
#define pb push_back
int main()
{
    optimize
    string s1,s2;
    cin>>s1>>s2;
    int cnt=0;
    int n=s1.length();
    for(int i=0;i<n;i++) if(s1[i]!=s2[i]) cnt++;
    cout<<cnt<<endl;
}


Measured memory_bytes: 3804