akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll era[1000001];    //era[i]=iを割り切る最小の素数
void era_init(){
    era[1]=1;
    rep(i,2,1000000){
        if(era[i]==0){
            era[i]=i;
            for(ll j=i*2;j<=1000000;j+=i){
                if(era[j]==0)era[j]=i;
            }
        }
    }
}
map<ll,ll> prime_fac(ll x){
    map<ll,ll> mp;
    while(x>1){
        ll d=era[x];
        auto itr=mp.find(d);
        if(itr==mp.end()){
            mp[d]=1;
        }else{
            mp[d]++;
        }
        x/=d;
    }
    return mp;
}
ll gcd(ll x,ll y){
    if(x<y) return gcd(y,x);
    if(y==0) return x;
    return gcd(y,x%y);
}


int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    era_init();
    set<ll> st;
    bool b[2];rep(i,0,1)b[i]=false;
    rep(i,0,n-1){
        map<ll,ll> mp=prime_fac(a[i]);
        for(auto itr=mp.begin();itr!=mp.end();++itr){
            if(st.find(itr->first)!=st.end()){
                b[0]=true;
            }
            st.insert(itr->first);
        }
    }
    ll g=a[0];
    rep(i,1,n-1){
        g=gcd(g,a[i]);
    }
    if(g!=1)b[1]=true;
    if(!b[0]){
        cout<<"pairwise coprime"<<endl;
    }else if(!b[1]){
        cout<<"setwise coprime"<<endl;
    }else{
        cout<<"not coprime"<<endl;
    }
    

    return 0;
}





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

int main(){
    int n;
    cin >> n;
    int v[n],c[n];
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        cin >> c[i];
        int x=v[i]-c[i];
        if(x>=0)ans+=x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#61c
#import random #テスト用

N,K = map(int, input().split())#N,K<=10**5　#Nのループで考えないとTLEしそう
#N = 100000 #test

a_b_dict = dict()

#b_sum = 0 #test

for i in range(N):
    a,b = map(int, input().split())
    #a = random.randint(1, 100000) #test
    #b = random.randint(1, 100000) #test
    
    if a not in a_b_dict:
        a_b_dict[a] = 0
    
    a_b_dict[a] += b
    
    #b_sum += b #test
    
a_b_dict_sorted = sorted(a_b_dict.items(), key=lambda x:x[0])

#K = random.randint(1, b_sum)

position = 0
for ab in a_b_dict_sorted:
    b = ab[1]
    position += b
    
    if position >= K:
        print(ab[0])
        break

Measured memory_bytes: 15072
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
     
#define pb emplace_back
#define fi first
#define se second
     
using namespace std;
     
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
     
// head

struct Mod{
  unsigned n;
  Mod(){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }

int n, m;
Mod dp[310][310][310];

int main(){

  n = in();
  m = in();
  
  dp[0][1][0] = 1;
  REP( i , m ){
    REP( j , n+1 ){
      REP( k , n+1 ){
	Mod cur = dp[i][j][k];
	dp[i+1][j][k+1] += cur * ( n - k - j );
	dp[i+1][j][k] += cur * k;
	dp[i+1][j+k][0] += cur * j;
      }
    }
  }

  cout << dp[m][n][0].n << endl;

  return 0;
}


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

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int>> minHeap;
#define endl "\n"
#define int long long
#define MOD 1000000007
#define ump unordered_map
#define pb push_back
#define mp make_pair
#define pie acos(-1)
#define max(x, y) ((x > y) ? x : y)
#define min(x, y) ((x < y) ? x : y)
#define mid(s, e) ((s + (e - s) / 2))

bool test_cases;

struct precompute {
    void compute() {
    }
};

void init(bool k) {
    test_cases = k;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

struct test_cases {
    void test_case(int test) {
        int a, b, c;
        cin >> a >> b >> c;
        if(a % b == 0) {
            cout << (a/b)*c<<endl;
        } else {
            cout << ((a/b)+1)*c << endl;
        }
    }
};

int32_t main() {
    init(false);
    int tc;
    if (test_cases) {
        cin >> tc;
    } else {
        tc = 1;
    }
    struct precompute l;
    l.compute();
    for (int i = 0; i < tc; i++) {
        struct test_cases o;
        o.test_case(i + 1);
    }
    return 0;
};

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int total = a * x + b * y;
  while (true) {
    if (y > 0 || x > 0) {
      auto t = total;
      if (x > 0) t -= a;
      if (y > 0) t -= b;
      if (t + c * 2 < total) {
        total = t + c * 2;
        x --, y --;
      } else {
        break;
      }
    } else {
      break;
    }
  }
  // cout << x << " " << y << endl;

  cout << total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

string addString(string num1, string num2) {
	string ret, a = num1, b = num2;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (a.size() < b.size())
		swap(a, b);
	int carry = 0;
	for (int i = 0; i < a.size(); i++) {
		int aa = a[i] - '0';
		if (i < b.size()) {
			int bb = b[i] - '0';
			aa += bb;
		}
		aa += carry;
		if (aa >= 10) {
			aa -= 10;
			carry = 1;
		} else {
			carry = 0;
		}
		ret += aa + '0';
	}
	if (carry == 1)
		ret += '1';
	reverse(ret.begin(), ret.end());
	return ret;
}

string replaceX(string str, int num) {
	string ret = str;
	for (int i = 0; i < ret.size(); i++)
		if (ret[i] == 'X')
			ret[i] = num + '0';
	return ret;
}

bool solve(string str) {
	string num1, num2, ans;
	int i = 0;
	while (str[i] != '+')
		num1 += str[i++];
	i++;
	while (str[i] != '=')
		num2 += str[i++];
	i++;
	while (i < str.size())
		ans += str[i++];
//	cout << num1 << " " << num2 << " " << ans << endl;
	for (i = 0; i <= 9; i++) {
		string rep1 = replaceX(num1, i);
		string rep2 = replaceX(num2, i);
		string repans = replaceX(ans, i);
		string sum = addString(rep1, rep2);
//		cout << "rep1 = " << rep1  << ",rep2 = " << rep2  << ",sum = " << sum << endl;
		if (sum == repans) {
			cout << i << endl;
			return true;
		}
	}
	return false;
}

int main() {
	string str;
	while (cin >> str) {
		if (!solve(str))
			cout << "NA" << endl;
	}
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cin.sync();

    int n;
    cin>>n;
    int k;
    cin>>k;
    int x;
    cin>>x;
    int y;
    cin>>y;
    int ans =0;
    if(k<n)
    {
        ans = k*x + y*(n-k);
    }
    else if(k>=n)
    {
        ans = x*n;
    }
    cout<<ans;

    return 0;
}

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


int main(){
    string s;
    cin>>s;
    int n=s.size();
    long long ans=0;
    n--;

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        /* bit で表される集合の処理を書く */
        long long t=(long long)s[0]-'0';
        for(int i=0;i<n;i++){
            if((bit>>i&1)) {
                ans+=t;
                t=(long long)s[i+1]-'0';
            }
            else {
                t=t*10+s[i+1]-'0';
            }
        }
        ans+=t;

    }

    cout<<ans<<endl;

}

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

#define MAX 20000000
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()


typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> ii;

int main(){
	
	ll n,k,x,dp[MAX];
	vi v;
	cin>>n>>k;

	REP(i,n){
		cin>>x;
		v.pb(x);
	}
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	FOR(i,2,n){
		dp[i]=10000000000000000LL;
		for(int j=i-1; j>=max(i-k,0LL); j--){
			if(dp[i]>dp[j]+abs(v[i]-v[j])){
				dp[i]=dp[j]+abs(v[i]-v[j]);
			}
		}
	}
	
	/*REP(i,n){
		cout<<dp[i]<<" ";
	}
	*///cout<<dp[n-1]<<endl;

	
	cout<<dp[n-1]<<endl;

	return 0;
	
}

Measured memory_bytes: 3700
<?php
define('MOD', 10 ** 9 + 7);

fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $s);

if ($s[0] === 'W' || $s[2 * $n - 1] === 'W') {
    echo (0) . PHP_EOL;
    exit();
}
$l_cnt = 1;
$l = [0];
$x[0] = 'L';
$l_sum[0] = 0;
$l_sum[1] = 1;
$r_cnt = 0;
$y = 1;
for ($i = 1; $i < 2 * $n; $i++) {
    if ($s[$i] !== $s[$i - 1]) {
        if ($x[$i - 1] === 'L') $x[$i] = 'L';
        else $x[$i] = 'R';
    } else {
        if ($x[$i - 1] === 'L') $x[$i] = 'R';
        else $x[$i] = 'L';
    }
    if ($x[$i] === 'L') {
        $l_sum[$i + 1] = $l_sum[$i] + 1;
        $l_cnt++;
    } else {
        $y = $y * ($l_sum[$i] - $r_cnt) % MOD;
        $l_sum[$i + 1] = $l_sum[$i];
        $r_cnt++;
    }
}
if ($l_cnt !== $r_cnt) {
    echo (0) . PHP_EOL;
    exit();
}
$ans = $y * kaijou($n) % MOD;
echo $ans . PHP_EOL;

function kaijou($n) {
    return $n > 1 ? $n * kaijou($n - 1) % MOD : 1;
}

Measured memory_bytes: 45548
import sys
for s in map(lambda l: list(l.rstrip()), sys.stdin.readlines()):
    while True:
        for i, c in enumerate(s):
            char_code = ord(c)
            if 97 <= char_code <= 122:
                char_code = char_code+1 if char_code < 122 else 97
                s[i] = chr(char_code)

        _s = "".join(s)
        if "this" in _s or "the" in _s or "that" in _s:
            print(_s)
            break

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

#define ll long long

using namespace std;

int main()
{
    ll a, b, c, k, sum = 0, temp;

    cin >> a >> b >> c >> k;

    temp = min(a, k);

    sum = temp;

    k -= temp;

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

    temp = min(b, k);

    k -= temp;

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

    sum -= k;

    cout << sum << endl;

    return 0;
}


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

int main(){
    int n;

    cin >> n;

    vector<int> a(n);

    for(int i=0; i < n; i++){
        cin >> a.at(i);
    }

    int place = 1,amount=0;
    vector<int> q(n,0);

    for(int i=0; i<n && place != 2; i++){
        amount++;
        q.at(i) = place;
        place = a.at(place-1);
    }

/*
    while(place!=2 && place!=0){
        place = a.at(place-1);
        for(auto &num : q){
            if(num == place){
                place = 0;
                break;
            }
        }
        q.push_back(place);
    }
*/
    if(place == 2){
        cout << amount << endl;
    }else{
        cout << -1 << endl;
    }
    
}

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

//最小公倍数= a*b / 最大公約数
//最大公約数
int gcd(int C, int D){
    return D ? gcd(D, C % D) : C;
}

int gcd(vector<int> a){
    int ans = a[0];
    for (int i = 1; i < a.size(); ++i){
        ans = gcd(ans, a[i]);
    }
    return ans;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);

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

    cout << gcd(A) << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        
        int k = Integer.parseInt(sc.next());
        
        for(int i = 0; i < k; i++){
            if(i % 2 == 0){
                if(a % 2 != 0){
                    a--;
                }
                b+=a/2;
                a/=2;
            }else{
                if(b % 2 != 0){
                    b--;
                }
                a+=b/2;
                b/=2;
            }
        }
        System.out.println(a + " " + b);
    }
}


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

long long n, m, s;
long long a[200000], b[200000];

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

	unsigned long long t = 2 * n * m;

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

	b[n - 1] = a[n - 1];

	for (long long i = 1; i < n; i++)
		b[n - 1 - i] = b[n - i] + a[n - 1 - i];

	t += 5 * b[0];

	for (long long k = 1; k < n; k++) {
		unsigned long long t1 = (n + k) * m;

		for (long long i = 1; i < n / k; i++)
			t1 += (2 * i + 3) * (b[n - (i + 1) * k] - b[n - i * k]);

		t1 += 5 * b[n - k] + (2 * (n / k) + 3) * (b[0] - b[n % k]);

		if (t1 < t)
			t = t1;
	}

	cout << t << endl;

	return 0;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	ll n,x[55],y[55];
	ll ans=0;
	cin>>n;
	vl xx,yy;
	rep(i,0,n)cin>>x[i]>>y[i];
	ll dp[55][55];
	rep(i,0,55)rep(j,0,55)dp[i][j]=1;
	ll cnt=0;
	rep(i,0,n)rep(j,0,n){
		if(i==j)continue;
		ll divx=x[i]-x[j];
		ll divy=y[i]-y[j];
		rep(k,0,n)rep(l,0,n){
			if(k==i||l==i||k==l)continue;
			if(divx==x[k]-x[l]&&divy==y[k]-y[l])
				dp[i][j]++;
//		if(i==2&&j==1)print("#"<<divx<<","<<x[k]-x[l]);
		}
		cnt=max(cnt,dp[i][j]);
	}
	ans=n-cnt;
	print(ans);
}

Measured memory_bytes: 256
a = int(input())
b = list(map(int,input().split()))
 
for i in range(a):
	b[i] -= i + 1
 
b.sort()
su = 0
c = b[(a - 1) // 2]

for i in range(a):
	su += abs(b[i] - c)

print(su)

Measured memory_bytes: 26180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long[] a = new long[n-1];
		for(int i = 0; i < n-1; i++)
			a[i] = sc.nextLong();
		long an = a[n-2];
		for(int i = n-2; i > 0; i--)
		{
			an += Math.min(a[i], a[i-1]);
		}
		an += a[0];
		
		System.out.println(an);
	}

}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
using namespace std;
int main() {
    long n;
    cin>>n;
    vector<long long> a(n);
    for (long i = 0; i < n; i++)
        cin>>a[i];
    long long sum = 0;
    long mx = a[0];
    for (long i = 1; i < n; i++) {
        if (a[i] > mx) {
            mx = a[i];
        } else {
            sum += mx - a[i];
            a[i] = mx;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 4808
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char a[500][500];
char b[500][500];
int n,m;
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	cin>>n>>m;
	repd(i,1,n)
	{
		cin>>a[i];
	}
	repd(i,1,m)
	{
		cin>>b[i];
	}
	int la=strlen(a[1]);
	int lb=strlen(b[1]);
	repd(i,1,n-m+1)
	{
		repd(j,1,la-lb+1)
		{
			int flag=1;
			repd(k,1,m)
			{
				rep(z,0,lb)
				{
					// cout<<k+i-1<<" "<<z+j<<endl;
					if(a[k+i-1][z+j-1]!=b[k][z])
					{
						flag=0;
						break;
					}
				}
			}
			if(flag)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}

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

inline void getInt(int* p) {char ch;do {ch = getchar();} 
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') 
{*p = *p * 10 + ch - '0';}}}

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

using I = long long;

I Grundy(auto n) {
  if(n == 0) return 0;
  for(auto i=0; i<60; ++i) if((n>>i) & 1) return 1ll << i;
  assert(false);
}

#include<memory>
#include<unordered_map>
template<typename T> class Trie {
 public:
  bool solve(auto L) {
    return traverse(root_, L+1);
  }
  I traverse(const auto& n, auto L) {
    if(!n) return Grundy(L);
    if(n->value) return 0;
    return traverse(n->child['0'], L-1) ^ traverse(n->child['1'], L-1);
  }
  void insert(const std::string& s, const T& value) {insert(root_, s, 0, value);}
 private:
  struct Node {
    T value;
    std::unordered_map<T, std::unique_ptr<Node>> child;
  };
  void insert(std::unique_ptr<Node>& node, const std::string& s, int i, const T& v) {
    if(!node) node = std::make_unique<Node>();
    if(i == s.size()) node->value = v;
    else insert(node->child[s[i]], s, i + 1, v);
  }
  std::unique_ptr<Node> root_;
};

int main() {
  I N, L;
  cin >> N >> L;
  vector<string> S(N);
  for(auto& i: S) cin >> i;
  Trie<int> T;
  for(auto i: S) T.insert(i, 1);
  cout << (T.solve(L) ? "Alice" : "Bob") << endl;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1005, K = 21, MOD = 1e9 + 7;
int c[N][N];
ll dp[K][N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k;
    cin >> n >> k;

    for (int i = 0; i <= n; i++) {
        c[i][0] = 1;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
        }
    }

    dp[0][0] = 1;

    for (int i = 0; i < k; i++) {
        int x;
        cin >> x;

        for (int j = 0; j <= n; j++) {
            if (dp[i][j]) {
                for (int h = 0; h <= min(x, n - j); h++) {
                    dp[i + 1][j + h] = (dp[i + 1][j + h] 
                        + dp[i][j] * c[n - j][h] % MOD * c[n - h][x - h]) % MOD;
                }
            }
        }
    }

    cout << dp[k][n] << "\n";

    return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    rep(i,n) cin >> a[i+1];
    vector<int> b(n+1);
    for(int i = n; i >= 1; i--){
        int sum=0;
        for(int j = i+i; j <= n; j += i){
            sum ^= b[j];
        }
        b[i] = sum^a[i];
    }
    vector<int> ans;
    for(int i = 1; i <= n; i++){
        if(b[i]) ans.push_back(i);
    }
    cout << ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    private static int INF = 10000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] s = new char[H][W];
        for (int i = 0; i < H; i++) {
            String S = sc.next();
            for (int j = 0; j < W; j++) {
                s[i][j] = S.charAt(j);
            }
        }

        int[][] dp = new int[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                dp[i][j] = INF;
            }
        }

        dp[0][0] = s[0][0] == '.' ? 0 : 1;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                // right
                if (j < W-1) {
                    int nextVal = dp[i][j];
                    if (s[i][j] == '.' && s[i][j+1] == '#') {
                        nextVal++;
                    }
                    dp[i][j+1] = Math.min(dp[i][j+1], nextVal);
                }
                // down
                if (i < H-1) {
                    int nextVal = dp[i][j];
                    if (s[i][j] == '.' && s[i+1][j] == '#') {
                        nextVal++;
                    }
                    dp[i+1][j] = Math.min(dp[i+1][j], nextVal);
                }
            }
        }

        System.out.println(dp[H-1][W-1]);
    }
}



Measured memory_bytes: 22996
odds = %w[R U D]
evens = %w[L U D]
S = gets.strip.split('')
result = 'Yes'
S.each_with_index do |s, i|
  r = (i+1).odd? ? odds.include?(s) : evens.include?(s)
  unless r
    result = 'No'
    break
  end
end
puts result

Measured memory_bytes: 1916
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var NQ = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NQ[0];
        var Q = NQ[1];
        var s = ReadLine();
        var t = new char[Q];
        var d = new char[Q];
        for (int i = 0; i < Q; i++)
        {
            var line = ReadLine();
            t[i] = line[0];
            d[i] = line[2];
        }

        var min = N / 2;
        var max = N / 2;
        var ng = 0;
        var ok = N;
        while (ok - ng != 1)
        {
            var r = Alive(min, s, Q, t, d);
            if (r == 'L')
            {
                ng = min;
            }
            else
            {
                ok = min;
            }
            min = (ng + ok) / 2;
        }
        min = ng;
        ok = 0;
        ng = N;
        while (ng - ok != 1)
        {
            var r = Alive(max, s, Q, t, d);
            if (r == 'R')
            {
                ng = max;
            }
            else
            {
                ok = max;
            }
            max = (ng + ok) / 2;
        }
        max = ng;
        WriteLine(max - min - 1);
    }

    static char Alive(int idx, string s, int Q, char[] t, char[] d)
    {
        for (int i = 0; i < Q; i++)
        {
            if (s[idx] == t[i])
            {
                if (d[i] == 'R') idx++;
                else idx--;
                if (idx == s.Length) return 'R';
                if (idx == -1) return 'L';
            }
        }
        return 'A';
    }
}


Measured memory_bytes: 18784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

ll gcd(ll a, ll b) {
  while (b) {
    ll A = a;
    (a = b), (b = A % b);
  }
  return a;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main(){
  ll N, M; cin >> N >> M;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  ll lcm_ = A[0]/2;
  rep(i,N){
    if(i==0) continue;
    lcm_ = lcm(lcm_, A[i]/2);
    if(lcm_ > M){
      cout << 0 << endl;
      return 0;
    }
  }
  cerr << lcm_ << endl;
  rep(i,N){
    if((lcm_/A[i]) * A[i] == lcm_){
      cout<< 0 << endl;
      return 0;
    }
  }
  cout << (M / lcm_ + 1)/2 << endl;
  return 0;
}


Measured memory_bytes: 1024
while True:
    nums = [int(e) for e in input().split()]
    if nums[0] == 0 and nums[1] == 0:
        break
    for i in range(nums[0]):
        if i == 0 or i == nums[0]-1:
            print("#"*nums[1])
        else:
            print("#"+"."*(nums[1]-2)+"#")
    print ("")
    


Measured memory_bytes: 5624
#include <iostream>
using namespace std;
int main(){
  int H,W,h,w;
  cin >> H >> W >> h >> w;

  int ans = H * W - (h * W + w * H - h * w);
  /*
3 2
2 1

1 1
1 1
1 0
  */
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def solve():
    A, B = map(int, input().split())
    x = A * B
    if A < B:
        tmp = A
        A = B
        B = tmp
    
    r = A % B
    while(r!=0):
        A = B
        B = r
        r = A % B
    
    print(int(x/B))

if __name__ == '__main__':
    solve()

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

int main(){
  int n, m, sum=0;
  
  cin >> n >> m;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  if(a.at(m-1)<(sum/(4.0*m))){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    if (s.length() == 1) cout << '0';
    else
    {
        int d = 1;
        for (int i = 1; i < s.length(); i++)
            if (s[i] != s[i - 1]) d++;
        cout << d - 1;
    }
}

Measured memory_bytes: 3724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            long K = in.Long();
            Map<Integer, Long> map = new TreeMap<>();
            for (int i = 0; i < N; i++) {
                int a = in.Int();
                int b = in.Int();
                map.put(a, map.getOrDefault(a, 0L) + b);
            }
            long cnt = 0;
            for (Map.Entry<Integer, Long> e : map.entrySet()) {
                cnt += e.getValue();
                if (cnt >= K) {
                    out.println(e.getKey());
                    return;
                }
            }
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public long Long() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 48092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	int a, b, t;
	cin >> a >> b >> t;

	printf("%d", t / a * b);

	return 0;
}

Measured memory_bytes: 256
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


int arr[2002];

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

    int n, a, b;
    cin>>n>>a>>b;

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

    if(n == 1){
    	cout<<abs(arr[1]-b);
    	return 0;
    }

    int ans = max(abs(arr[n]-b), abs(arr[n-1]-arr[n]));
    cout<<ans;
    return 0;
}











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

#define FAST_IO                       \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;

using namespace std;

using ll = long long;

const int MOD = 998244353;
const ll INF_LLONG = 1e18 + 9;
const int INF_INT = 1e9 + 9;

template<typename T>
unsigned int index_of_max(vector<T>& arr) {
	unsigned int idx = 0;
	for (int i = 0; i < arr.size(); ++i) {
		if (arr[i] > arr[idx])
			idx = i;
	}
	return idx;
}

template<typename T>
unsigned int index_of_min(vector<T>& arr) {
	unsigned int idx = 0;
	for (int i = 0; i < arr.size(); ++i) {
		if (arr[i] < arr[idx])
			idx = i;
	}
	return idx;
}

bool isPalindrome(string s, int l, int r) {
	for (; l <= r; ++l, --r) {
		if (s[l] != s[r])
			return false;
	}
	return true;
}

int main()
{
	//	#ifndef ONLINE_JUDGE
	//		(void)freopen("input.txt", "r", stdin);
	//		(void)freopen("output.txt", "w", stdout);
	//	#endif	
	FAST_IO;
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int& x : a)
		cin >> x;
	vector<bool> dp(k + 1);
	for (int stones = 0; stones <= k; ++stones) {
		for (int x : a) {
			if (stones >= x && !dp[stones- x])
				dp[stones] = true;
		}
	}

	if (dp[k])
		cout << "First";
	else
		cout << "Second";
	return 0;
}




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

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)

#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
// #define LREP(i,n) LFOR(i,0,(ll)(n)-1)
// #define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;


ll gcd(ll a, ll b){
  if(b==0) return a; else return gcd(b,a%b);
}

ll prim(ll n){
  for(ll i=2; i*i<=n;i++){
    if(n%i==0) return i;
  }
  return n;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c;
  vector<ll> cd;
  cin >> a >> b;
  c = gcd(a,b);
  cd.push_back(1);
  while(c>1){
    ll d = prim(c);
    cd.push_back(d);
    while(c%d==0) c /= d;
  }
  cout << cd.size() << endl;
}


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

using namespace std;

int N, L;
int a[100001];
int dp[1000001];

int solve(int idx)
{
  int ret = 0;
  if(idx > 0 && a[idx - 1] > a[idx]) ret = max(ret, solve(idx - 1));
  if(idx < N-1 && a[idx + 1] > a[idx]) ret = max(ret, solve(idx + 1));
  ret += L - a[idx];
  return dp[idx] = ret;
}

int main()
{
  cin >> N >> L;
  for(int i = 0; i < N; i++) cin >> a[i];
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  for(int i = 0; i < N; i++){
    ans = max(ans, solve(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6832
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))
"""
N = num()
A = nums()
print(A.index(min(A))+1)
"""
"""
N = num()
A =  set(nums())
print(len(A))
"""

def get_near_index(sorted_l,val,last):
    left = 0
    right = len(sorted_l) - 1
    while left <= right:
        mid = (right + left) // 2
        if sorted_l[mid] == val:
            return mid if last else mid
        elif sorted_l[mid] > val:
            right = mid -1
        else: 
            left = mid + 1
    return right if last else left 

N,Q = nums()
A = nums()
A.sort()
L,R = [],[]

for i in range(Q):
    li,ri = nums()
    L.append(li)
    R.append(ri)
for l,r in zip(L,R):
    l_idx = get_near_index(A,l,0)
    r_idx = get_near_index(A,r,1)
    print(r_idx-l_idx+1)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll n,m;
ll sum[101000];

int main(){
	cin >> n >> m;
	rep(i,m){
		ll a,b;
		cin >> a >> b;
		a--; b--;
		sum[a]++;
		sum[b+1]--;
	}
	rep(i,101000)sum[i+1] += sum[i];
	ll ans = 0;
	rep(i,n)ans += (sum[i] == m);
	cout << ans << endl;
}

Measured memory_bytes: 1024
INF = float('inf')
N = int(input())
h = list(map(int, input().split()))

dp = [INF for i in range(N)]
dp[0] = 0
for i in range(N):
    if i - 1 >= 0:
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
    if i - 2 >= 0:
        dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[N - 1])


Measured memory_bytes: 55496
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		
		int com;
		
		for ( com = M/N ; com > 0 ; com--){
			if( M%com == 0){	
				break;
			}
		}
		if(com != 1){
			System.out.println(com);
		}
		else{
			System.out.println(1);
		}
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool era[10000000]={false};
 
 
void makeERA(){
    for(int i=2;i<1000001;i++){
        if(era[i]!=true)continue;
        for(int j=2;;j++){
            if(i*j<=1000000)
                era[i*j]=false;
            else break;
        }
    }
    era[2]=true;
}
int main(){
    rep(i,10000000)era[i]=true;
    era[0]=false;era[1]=false;
	makeERA();
	int n;
	while(cin>>n){
		if(n==0)break;

		int sum=0;

		rep(i,n+1){
			if(era[i])sum++;
		}
		cout<<sum<<endl;
	}
}

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

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

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String o=sc.nextLine();
    String e=sc.nextLine();
    sc.close();
    if(o.length()==e.length()){
      for(int i=0;i<o.length();i++){
        System.out.print(o.substring(i,i+1)+e.substring(i,i+1));
      }
    }else{
      for(int i=0;i<o.length()-1;i++){
        System.out.print(o.substring(i,i+1)+e.substring(i,i+1));
      }
      System.out.print(o.substring(o.length()-1,o.length()));
    }
    System.out.println();
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  char a, b, s;
  in2(a, b);
  if(a == b)
    s = 'H';
  else
    s = 'D';
  out(s);
  memi;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define f first
#define s second
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%I64d",&x)
#define CLR(x)  memset(x,0,sizeof(x))
#define RESET(x,a) memset(x,a,sizeof(x))
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;

char s[100005];

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    int t,n,m,i,j;
    scanf("%s",s);
    n=strlen(s);
    int p=0;
    int g=0;
    int ans=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='p')
        {
            p++;
        }
        if(s[i]=='g')
        {
                g++;
        }
    }
    ans=(g-p)/2;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    ll H, W;
    cin >> H >> W;
    if (H > W) swap(H, W);

    if(H == 1 && W == 1){
        cout << 1 << endl;
    }else if(H == 1){
        cout << W - 2 << endl;
    }else{
        cout << (H - 2) * (W - 2) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        PriorityQueue<Integer> que = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            que.add(sc.nextInt());
        }
        
        int[][] array = new int[m][2];
        for (int i = 0; i < m; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }
        Arrays.sort(array, (a, b) -> Integer.compare(b[1], a[1]));
        
        for (int j = 0; j < m; j++) {
            int k = array[j][0];
            int v = array[j][1];
            
            int c = 0;
            for (int i = 0; i < k; i++) {
                int num = que.peek();
                if (num < v) {
                    que.poll();
                    c++;
                } else {
                    break;
                }
            }
            for (int i = 0; i < c; i++) {
                que.add(v);
            }
        }
        
        long ans = 0;
        while (!que.isEmpty()) {
            ans += que.poll();
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 100856
#include <bits/stdc++.h>
#define ll  long long

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, "\e[31;1m"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\e[0m")
#else
    #define eprintf(...) 42
#endif

std::string solve(const int A, const int B, const int C)
{
    if (A + B + C == std::max({A, B, C}) * 2)
    {
        return "Yes";
    }
    return "No";
}

int main(void)
{
    int A, B, C;
    std::cin >> A >> B >> C;
    std::cout << solve(A, B, C) << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static int w, h;
	static int[][] map;
	
	public static void main(String[] args)
	{
		
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			w = sca.nextInt();
			h = sca.nextInt();
			if(w == 0) break;
			
			int x, y;
			
			map = new int[h][w];
			for(y = 0;y < h;y++)
			{
				String text = sca.next();
				for(x = 0;x < w;x++)
				{
					switch(text.charAt(x))
					{
					case '.': map[y][x] = 0; break;
					case 'B': map[y][x] = 1; break;
					case 'W': map[y][x] = 2; break;
					}
				}
			}
			
			Boolean modify = true;
			while(modify)
			{
				modify = false;
				
				for(y = 0;y < h;y++)
				{
					for(x = 0;x < w;x++)
					{
						if(map[y][x] == 1 || map[y][x] == 2 || map[y][x] == 5) continue;
						
						int black = 0, white = 0, brank = 0;
						
						if(0 < x)
						{
							switch(map[y][x-1])
							{
							case 1:
							case 3:
								black++;
								break;
							case 2:
							case 4:
								white++;
								break;
							case 5:
								brank++;
								break;
							}
						}
						
						if(0 < y)
						{
							switch(map[y-1][x])
							{
							case 1:
							case 3:
								black++;
								break;
							case 2:
							case 4:
								white++;
								break;
							case 5:
								brank++;
								break;
							}
						}
						
						if(x < w-1)
						{
							switch(map[y][x+1])
							{
							case 1:
							case 3:
								black++;
								break;
							case 2:
							case 4:
								white++;
								break;
							case 5:
								brank++;
								break;
							}
						}
						
						if(y < h-1)
						{
							switch(map[y+1][x])
							{
							case 1:
							case 3:
								black++;
								break;
							case 2:
							case 4:
								white++;
								break;
							case 5:
								brank++;
								break;
							}
						}
						
						
						if(brank > 0)
						{
							map[y][x] = 5;
							modify = true;
						}
						else if(black == 0 && white > 0 && map[y][x] != 4)
						{
							map[y][x] = 4;
							modify = true;
						}
						else if(black > 0 && white == 0 && map[y][x] != 3)
						{
							map[y][x] = 3;
							modify = true;
						}
						else if(black > 0 && white > 0 && map[y][x] != 5)
						{
							map[y][x] = 5;
							modify = true;
						}
					}
				}
			}
			
			int black=0, white=0;
			for(y = 0;y < h;y++)
			{
				for(x = 0;x < w;x++)
				{
					if(map[y][x] == 3)
						black++;
					else if(map[y][x] == 4)
						white++;
				}
			}
			
			System.out.println(black + " " + white);
		}
	}
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    cout << accumulate(a.begin(), a.begin() + k, 0) << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = false;


struct Monster{
    ll position;
    ll hp;
};

bool cmp( Monster &a, Monster &b ){
    return a.position < b.position;
}

// H以上である最初のあれ
int my_binary_search( vector<ll> &v, ll H){

    ll left = 0;
    ll right = v.size();

    while (right - left > 1)
    {
        ll mid = (left + right) / 2;
        if( v[mid] <= H ) left = mid;
        else right = mid; 
    }    
    return right;
}

int main(){

    ll N, D, A;
    cin >> N >> D >> A;

    vector<Monster> m(N);
    for(int i = 0; i < N; i++) cin >> m[i].position >> m[i].hp;
    sort( all(m), cmp );

    vector<ll> hp(N);
    for(int i = 0; i < N; i++) hp[i] = m[i].hp;

    vector<ll> position(N);
    for(int i = 0; i < N; i++) position[i] = m[i].position;


    ll lastIndex = 0;
    ll ans = 0;
    ll tmp_power = 0;
    vector<ll> endIndex(N + 1); //爆弾の効果範囲

    for (size_t i = 0; i < N; i++)
    {
        tmp_power -= endIndex[i] * A;

        // 倒すべき敵のHPから減らすHPを計算
        ll times = max( (hp[i] - tmp_power + A - 1) / A, 0ll );
        tmp_power += A * times;
        ans += times;

        // 倒すべき敵の位置から右のインデックスを計算
        ll id = my_binary_search( position, position[i] + 2 * D );
        if(DEBUG) cout << "id:" << id << endl;
        endIndex[id] += times;

    }
    
    cout << ans << endl;

}

Measured memory_bytes: 8064