akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_7 1000003
#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)1E17;

#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 fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

ll cal(vector<ll>v){
    ll res=0;
    ll n=v.size();
    ll c=0;
    rep(i,0,n-1){
        if(v[i]==0){
            c++;
        }else{
            res+=c;
        }
    }
    
    return res;
}

int main(){fastio
    string s;cin>>s;
    ll n=s.size();
    ll pos=0;
    ll ans=0;
    while(pos<=n-1){
        vector<ll>v;
        while(pos<=n-1){
            if(s[pos]=='A'){
                v.pb(0);
                pos++;
            }else if(pos+1<=n-1&&s[pos]=='B'&&s[pos+1]=='C'){
                v.pb(1);
                pos+=2;
            }else{
                pos++;
                break;
            }
        }
        ans+=cal(v);
    }
    cout<<ans<<endl;
    
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    //lol result{0};
    char ch;
    //lol n; cin >> n;
    //int k; cin >> k;
    /*
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    cin >> ch;
    if(islower(ch))
        cout << "a" << endl;
    else
    {
        cout << "A" << endl;
    }
    

    //cout << result << endl;
    return 0;
}

Measured memory_bytes: 3592
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    balls = [0 for _ in range(N)]
    for n in range(N, 0, -1):
        max_ratio = N // n
        if max_ratio == 1:
            balls[n - 1] = A[n - 1]
        else:
            filled_balls = sum([balls[r * n - 1] for r in range(2, max_ratio + 1)])
            balls[n - 1] = (filled_balls + A[n - 1]) % 2
    ball_cnt = sum(balls)
    print(ball_cnt)
    if ball_cnt > 0:
        ball_indices = [str(i + 1) for i in range(N) if balls[i] > 0]
        print(' '.join(ball_indices))


if __name__ == '__main__':
    main()

Measured memory_bytes: 17716
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  vector<ll> wa(N);
  map<ll, ll> mp{};
  wa[0] = A[0];
  mp[wa[0]]++;
  for (int i = 1; i < N; i++) {
    wa[i] = wa[i - 1] + A[i];
    mp[wa[i]]++;
  }
  ll ans = 0;
  mp[0]++;
  for (auto s : mp) {
    ans += (s.second * (s.second - 1)) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 18656
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

/////////////         modの計算

#define MOD_IS_PRIME
constexpr ll mod = 1000000007LL;

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

	constexpr int K = 16;

	vector<ll> v_e = { 0, 765144583, 346175634, 347662323, 5655049, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };
	vector<ll> v_o = { 539588932, 729548371, 700407153, 404391958, 962779130, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };

	int T; cin >> T;
	for (int _t = 0; _t < T; _t++) {
		ll N; cin >> N;
		if (N % 2 == 0) {// even
			ll ans = 0;
			ll x = 1;
			for (int i = 0; i < K; i++) {
				ans += (x * v_e[i]) % mod;
				x = (x * N) % mod;
			}
			cout << ans % mod << endl;
		}
		else {// odd
			ll ans = 0;
			ll x = 1;
			for (int i = 0; i < K; i++) {
				ans += (x * v_o[i]) % mod;
				x = (x * N) % mod;
			}
			cout << ans % mod << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3156
import math

S = input()
K = int(input())
l = len(S)

if l==1 :
  print(int(K/2))
  exit()
  
s0 = ""
c = 0
d = 1
idx = 0
for s in S:
  s1 = s
  if s0==s1:
    d += 1 
    if idx==l-1:
      c += int(d/2)
  else:
    c += int(d/2)
    d = 1
  s0 = s1
#  print(s0, s1, c, d, idx)
  idx = idx+1

c0 = c
#print(c)
if K==1:
  print(c0)
  exit()

s0 = ""
c = 0
d = 1
idx=0
for s in S*2:
  s1 = s
  if s0==s1:
    d += 1 
    if idx==l*2-1:
      c += int(d/2)
  else:
    c += int(d/2)
    d = 1
#  print(s0, s1, c, d, idx)
  s0 = s1
  idx = idx+1

#print(c)
c1 = c-c0
if K==2:
  print(c)
  exit()


s0 = ""
c = 0
d = 1
idx=0
for s in S*3:
  s1 = s
  if s0==s1:
    d += 1 
    if idx==l*3-1:
      c += int(d/2)
  else:
    c += int(d/2)
    d = 1
#  print(s0, s1, c, d, idx)
  s0 = s1
  idx = idx+1

if K==3:
  print(c)
  exit()
#print(c)
c2 = c-c1-c0
  
print(c1*math.ceil((K-1)/2)+c2*math.floor((K-1)/2)+c0)

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



int main(){	
	vector<string> text;
	string line;
	string buf;
	while(getline(cin,line)&&line!="END_OF_TEXT"){
		text.push_back(line);
	}
	char com;
	int row=0,col=0;
	while(cin>>com&&com!='-'){
		switch(com){
		case 'a':
			col=0;
			break;
		case 'e':
			col=text[row].size();
			break;
		case 'p':
			if(row)row--;
			col=0;
			break;
		case 'n':
			if(row+1<text.size())row++;
			col=0;
			break;
		case 'f':
			if(col<text[row].size())col++;
			else if(row+1<text.size())row++,col=0;
			break;
		case 'b':
			if(col)col--;
			else if(row){
				row--;
				col=text[row].size();
			}
			break;
		case 'd':
			if(col<text[row].size())text[row].erase(col,1);
			else if(row+1<text.size()){
				text[row]+=text[row+1];
				text.erase(text.begin()+row+1);
			}
			break;
		case 'k':
			if(col==text[row].size()){
				if(row+1<text.size()){
					text[row]+=text[row+1];
					text.erase(text.begin()+row+1);
					buf="\n";
				}
			}else{
				buf=text[row].substr(col);
				text[row].erase(col);
				col=text[row].size();
			}
			break;
		case 'y':
			if(buf=="\n"){
				text.insert(text.begin()+row+1,text[row].substr(col));
				text[row].erase(col);
				row++;
				col=0;
			}else if(!buf.empty()){
				text[row].insert(col,buf);
				col+=buf.size();
			}
		}
	}
	for(int i=0;i<text.size();i++)cout<<text[i]<<endl;
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int n, k;
int main(void) {
	cin >> n >> k;
	vector<int> x(n), y(n);
	vector<int> xary, yary;
	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
		xary.push_back(x[i]);
		yary.push_back(y[i]);
	}
	sort(begin(xary), end(xary));
	sort(begin(yary), end(yary));
	ll ans = 1LL * (xary[n - 1] - xary[0]) * (yary[n - 1] - yary[0]);
	for (int xi = 0; xi < n; ++xi) {
		for (int xj = xi + 1; xj < n; ++xj) {
			for (int yi = 0; yi < n; ++yi) {
				for (int yj = yi + 1; yj < n; ++yj) {
					int num = 0;
					ll lx = xary[xi], rx = xary[xj];
					ll by = yary[yi], uy = yary[yj];
					for (int i = 0; i < n; ++i) {
						if (lx <= x[i] && x[i] <= rx && by <= y[i] && y[i] <= uy) {
							++num;
						}
					}
					if (num >= k) {
						ans = min(ans, 1LL * (xary[xj] - xary[xi]) * (yary[yj] - yary[yi]));
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define int long long

int N, a[3005];
int dp[3005][3005]; // dp[head][tail]

int DP(int h, int t, int cur = 0)
{
	if (h == t) return cur % 2 == 0 ? a[h] : -a[h];
	if (dp[h][t] != -1) return dp[h][t];
	
	int &ret = dp[h][t];
	if (cur % 2 == 0) {
		ret = max(DP(h + 1, t, cur + 1) + a[h], DP(h, t - 1, cur + 1) + a[t]);
	} else {
		ret = min(DP(h + 1, t, cur + 1) - a[h], DP(h, t - 1, cur + 1) - a[t]);
	}

	return ret;
}

signed main()
{
	cin >> N;

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

	memset(dp, -1, sizeof dp);
	cout << DP(0, N - 1) << endl;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N; ll L; cin >>N >>L;
  vector<ll> A(N); rep(i, N) cin >>A[i];
  ll l2 = 0; int li = -1;
  rep(i, N-1){
    if (l2 < A[i]+A[i+1]){
      l2 = A[i]+A[i+1];
      li = i;
    }
  }
  if (l2 < L){ cout <<"Impossible" <<endl; return 0;}
  cout <<"Possible" <<endl;
  for (int i=0; i<li; i++){
    cout <<i+1 <<endl;
  }
  for (int i=N-2; i>li; i--){
    cout <<i+1 <<endl;
  }
  cout <<li+1 <<endl;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


const int inf = (int)1e9;

vector<vector<int> > shortest_path(vector<vector<int> > &g)
{
	vector<vector<int> > dist;
	const int n = g.size();

	dist = g;

	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j)
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	}

	return dist;
}

struct bi_graph {

	vector<vector<int> > g;

	void init(int n)
	{
		g.resize(n);
	}

	void add_edge(int from, int to)
	{
		g[from].push_back(to);
		g[to].push_back(from);
	}

	bool inner_dfs(int v, vector<bool> &used, vector<int> &match)
	{
		used[v] = true;

		for(int i = 0; i < g[v].size(); ++i) {
			int u = g[v][i], w = match[u];
			if(w < 0 || !used[w] && inner_dfs(w, used, match)) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}

		return false;
	}

	int bipartite_matching()
	{
		int res = 0;
		const int n = g.size();
		vector<int> match(n, -1);
		vector<bool> used(n, false);

		for(int v = 0; v < n; ++v) {
			if(match[v] < 0) {
				fill(used.begin(), used.end(), false);
				if(inner_dfs(v, used, match))
					res += 1;				
			}
		}

		return res;
	}
};

int main()
{
	while(true) {

		int n, m, l;
		vector<pair<int, int> > pt;
		vector<vector<int> > dist, g;
		bi_graph bg;

		scanf("%d%d%d", &n, &m, &l);
		if(n == 0)
			break;

		g.resize(n);
		for(int i = 0; i < n; ++i) {
			g[i].resize(n, inf);
			g[i][i] = 0;
		}
		for(int i = 0; i < m; ++i) {
			int u, v, d;
			scanf("%d%d%d", &u, &v, &d);
			g[u][v] = g[v][u] = d;
		}
		pt.resize(l);
		for(int i = 0; i < l; ++i)
			scanf("%d%d", &pt[i].first, &pt[i].second);

		dist = shortest_path(g);

		bg.init(l * 2);

		for(int i = 0; i < l; ++i) {
			for(int j = 0; j < l; ++j) {

				if(i == j)
					continue;

				int u = pt[i].first;
				int v = pt[j].first;
				int dt = pt[j].second - pt[i].second;

				if(dist[u][v] <= dt)
					bg.add_edge(i * 2, j * 2 + 1);
			}
		}

		int ans = l - bg.bipartite_matching();

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

	return 0;
}

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

using namespace std;

const int INF = 20;
int memo[1<<16];
int mask[3];

inline int color2idx(char c) {
    if(c == 'R') return 0;
    if(c == 'G') return 1;
    if(c == 'B') return 2;
    return -1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    vector<int> stamps;
    for(int i = 0; i < N; ++i) {
        int h, w;
        cin >> h >> w;
        for(int py = -h+1; py < 4; ++py) {
            for(int px = -w+1; px < 4; ++px) {
                int stamp = 0;
                for(int dy = 0; dy < h; ++dy) {
                    for(int dx = 0; dx < w; ++dx) {
                        const int x = px+dx;
                        const int y = py+dy;
                        if(0 <= x && x < 4 && 0 <= y && y < 4) {
                            stamp |= 1<<(y*4+x);
                        }
                    }
                }
                stamps.push_back(stamp);
            }
        }
    }
    for(int y = 0; y < 4; ++y) {
        for(int x = 0; x < 4; ++x) {
            char c;
            cin >> c;
            mask[color2idx(c)] |= 1<<(y*4+x);
        }
    }
    queue<pair<int,int> > q;
    q.push(make_pair(0, 0));
    fill_n(memo, 1<<16, INF);
    int ans = INF;
    while(!q.empty()) {
        const int turn = q.front().first;
        const int state = q.front().second;
        q.pop();

        if(memo[state] < turn) continue;
        memo[state] = turn;
        if(state == (1<<16)-1) {
            ans = turn;
            break;
        }

        for(vector<int>::const_iterator it = stamps.begin(); it != stamps.end(); ++it) {
            for(int color = 0; color < 3; ++color) {
                int next_state = state;
                for(int mc = 0; mc < 3; ++mc) {
                    if(color == mc) {
                        next_state |= *it & mask[mc];
                    } else {
                        next_state &= ~(*it & mask[mc]);
                    }
                }
                if(memo[next_state] > turn+1) {
                    memo[next_state] = turn+1;
                    q.push(make_pair(turn+1, next_state));
                }
            }
        }
    }

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

Measured memory_bytes: 1652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q,x;
  char com[20];
  list<int> v;
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      v.push_front(x);
    }else if(com[6]=='L'){
      v.pop_back();
    }else if(com[6]=='F'){
      v.pop_front();
    }else if(com[0]=='d'){
      scanf("%d",&x);
      for(list<int>::iterator it = v.begin();it!=v.end();it++){
        if(*it==x){
          v.erase(it);
          break;
        }
      }
    }
  }
  int i=0;
  for(list<int>::iterator it=v.begin();it!=v.end();it++){
    if(i++) printf(" ");
    printf("%d",*it);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 34432
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <sstream>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define sort_key(struct_name,key_name) [](const struct_name &x, const struct_name &y){return x.key_name < y.key_name;}
#define pb(x) push_back(x)
typedef long long ll;
const long long MOD = 1e9 + 7;
using namespace std;

//main
int main(){
    string S; cin >> S;
    if(S=="Sunny") cout << "Cloudy" << endl;
    else if(S=="Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans = 0;
int N,K;
vi d, cnt;

void solve(){
    rep(i, N){
        if(cnt[i+1] == 0) ans++;
    }
    cout << ans << endl;
}

int main(){
    cin >> N >> K;
    d.resize(K);
    cnt.resize(N+1, 0);

    rep(i, K){
        cin >> d[i];
        vi A;
        A.resize(d[i]);

        rep(j, d[i]) {
            cin >> A[j];
            cnt[A[j]]++;
        }
    }

    solve();
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define chmax(x, y) do { x = max(x, y);} while(0)
typedef long long int ll;

using namespace std;

ll N;
struct T{
  ll w, s, v;
};

vector<T> a;
ll dp[2000][30000]; // dp[i][j]: i番目のブロックまでみて、合計の重さがjのときの最大価値

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    ll w, s, v;
    cin >> w >> s >> v;
    a.push_back({w,s,v});
  }
  sort(begin(a), end(a), [](const T &l, const T &r) {
      return min(l.s, r.s - l.w) > min(r.s, l.s - r.w);
      });
  dp[0][a[0].w] = a[0].v;
  dp[0][0] = 0;
  for (int i=0; i<N-1; i++) for (int j=0; j<30000; j++) {
    int ni = i+1;
    // niを置かない
    chmax(dp[ni][j], dp[i][j]);
    // niを置く
    int nj = j + a[ni].w;
    if (nj < 30000 && j <= a[ni].s) {
      chmax(dp[ni][nj], dp[i][j] + a[ni].v);
    }
  }
  ll ans = -1;
  for (int j=0; j<30000; j++) {
    chmax(ans, dp[N-1][j]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 235520
//package com.javalesson.chapter1.task0;


import java.util.*;

/**
 * Создайте программу, которая будет принимать две группы параметров:
 * - количество циклов выполнения программы;
 * - 3 числа a, b, n
 * и выводить на экран последовательность результатов вычисления следующего выражения
 * (a + 2^0*b),(a + 2^0*b + 2^1*b),(a + 2^0*b + 2^1*b + 2^2*b)..., (a+2^0*b + 2^1*b + 2^2*b +...+ 2^(n-1)*b)
 * где ^ обозначает возведение в степень, и эта операция выполняется до умножения.
 * <p>
 * Пример:
 * Please enter the number of iterations
 * 2
 * Enter the group of 3 numbers
 * 0 2 10
 * Output:
 * 2 6 14 30 62 126 254 510 1022 2046
 * Enter the group of 3 numbers
 * 5 3 5
 * Output:
 * 8 14 26 50 98
 * <p>
 * Пример:
 * a=5, b=3, n=5
 * (5+2^0*3)=8,(5+2^0*3 + 2^1*3)=14,(5+2^0*3 + 2^1*3 + 2^2*3)=26,(5+2^0*3 + 2^1*3 + 2^2*3 + 2^3*3)=50,
 * (5+2^0*3 + 2^1*3 + 2^2*3 + 2^3*3 + 2^4*3)=98
 */
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a, b, x;
        a = in.nextLong();
        b = in.nextLong();
        x = in.nextLong();
        if (a == 0) {
            System.out.println(b / x + 1);
        } else {
            System.out.println((b / x) - (a - 1) / x);
        }

    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<cmath>
#define INF 1000000
using namespace std;

int main() {
	int n;
	while (cin >> n, n) {		
		int aa;
		long double sa = INF;

		for (int i = 0;i < n;i++) {
			long double a, b, c;
			cin >> a >> b >> c;
		long double bmi = c / (b*b / 10000);

			if (sa > abs(22 - bmi)) {
				aa = a;
				sa = abs(22 - bmi);
			}
		}

		cout << aa << endl;
	}
	return 0;
}

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

int main() {
  int R;
  cin >> R;
  if (R < 1200){
    cout << "ABC" << endl;
    return 0;
  }
  if (R < 2800){
    cout << "ARC" << endl;
    return 0;
  }
  cout << "AGC";
  return 0;
}


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

int main() {
	long long N, X, M;
	cin >> N >> X >> M;
	set<long long>s;
	map<long long, long long>p;
	vector<long long>Ans(M + 10);
	s.insert(X);
	p[X] = 0;
	Ans[0] = 0;
	Ans[1] = Ans[0] + X;
	for (long long i = 1; i < N; ++i) {
		X *= X;
		X %= M;
		Ans[i + 1] = Ans[i] + X;
		if (s.count(X)) {
			long long ans = 0;
			long long memo = N - i;
			memo %= (i - p[X]);
			ans += Ans[p[X]];
			ans += (Ans[i + 1] - Ans[p[X] + 1])*((N - p[X]) / (i - p[X]));
			ans += (Ans[p[X] + memo] - Ans[p[X]]);
			cout << ans << endl;
			return 0;
		}
		s.insert(X);
		p[X] = i;
	}
	cout << Ans[N] << endl;
	return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    if(a + b == 1+2) cout << 3 << endl;
    if(a + b == 1+3) cout << 2 << endl;
    if(a + b == 2 + 3) cout << 1 << endl;


    return 0;
}


Measured memory_bytes: 256
getFukuriOverYear :: Integer -> Integer -> Integer -> Integer
getFukuriOverYear yen limit year | yen >= limit = year
                                 | otherwise = do
                                     let fukuri = ((yen * 101) `div` 100)
                                     getFukuriOverYear fukuri limit (year+1)

main = do
    x <- getLine
    print (getFukuriOverYear 100 (read x) 0)

Measured memory_bytes: 4304
import Data.Functor ((<$>))

main :: IO ()
main = do
  [h, w] <- map (read :: String -> Int) . words <$> getLine
  if h == 0 && w == 0
    then return ()
    else do
      let xs = take w $ cycle "#."
          ys = take w $ cycle ".#"
      putStrLn . unlines $ take h $ cycle [xs,ys]
      main



Measured memory_bytes: 4076
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
   int n,b,f,r,v;
   int count[4][3][10]={{{}}};
   cin >> n;

   for(int i=0; i<n; i++){
      cin >> b >> f >> r >> v;
      count[b-1][f-1][r-1]=count[b-1][f-1][r-1]+v;
   }
   for(int i=0; i<4; i++){
      for(int j=0; j<3; j++){
         for(int k=0; k<10; k++){
            printf(" %d",count[i][j][k]);
         }
         printf("\n");
      }
      if(i<3){
         printf("####################\n");
      }
   }
}



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

int main() {
  int S, hour, minute, second;
  cin >> S;

  hour = S / 3600;
  S %= 3600;
  minute = S / 60;
  S %= 60;
  second = S;

  cout << hour << ":" << minute << ":" << second << endl;
}

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

int main() {
    int n;
    int res;
    char c;
    int i = 0;

    cin >> res;

    while (1) {
        cin >> c;
        if (c == '=') break;
        cin >> n;

        if (c == '+') res += n;
        else if (c == '-') res -= n;
        else if (c == '*') res *= n;
        else if (c == '/') res /= n;
        c = c;
    }

    cout << res << endl;
}



Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main(){
 
  	int n;
	cin >> n;
  
  	string mark;
  	int number=0;
  	vector<vector<int> > card(5,vector<int>(14,0));
  
  	for(int i =0; i<n; i++){
  		cin >> mark >> number;
      	int mark_to=0;
      	if(mark== "S")
          mark_to = 1;
      	if(mark== "H")
          mark_to = 2;
      	if(mark== "C")
          mark_to = 3;
      	if(mark== "D")
          mark_to = 4;
      	
      	card.at(mark_to).at(number) = 1;
    }
  	
  	for(int j=1; j<5; j++){
    	for(int i=1; i<14; i++){
        	if(card.at(j).at(i)==0){
            	if(j==1)
                  mark = "S";
            	if(j==2)
                  mark = "H";
            	if(j==3)
                  mark = "C";
            	if(j==4)
                  mark = "D";
              
              cout << mark << " " << i << endl;
            }
        }  
    }
  
  return 0;
}


Measured memory_bytes: 3088
def function(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1

s = int(input())
a = []
a.append(s)
i = 1
while len(set(a)) == len(a):
    a.append(function(a[i-1]))
    i += 1
print(len(a))

Measured memory_bytes: 3064
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
	double a, r, s;
	cin >> a;
	r = a * a * 3.141592653589;
	s = 2 * a*3.141592653589;
	printf("%.6f %.6f\n", r, s);
	return 0;
}


Measured memory_bytes: 3200
import sys
from math import gcd
input = sys.stdin.readline
def main():
    K = int(input())
    total = 0
    for a in range(1,K+1):
        for b in range(1,K+1):
            tmp = gcd(a,b)
            for c in range(1,K+1):
                total+=gcd(tmp,c)
    print(total)
if __name__ == '__main__':
    main()

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

int main(){
	int N,ans=0;
	cin>>N;
	
	int d[N];
	for(int i=0;i<N;i++)
		cin>>d[i];
	
	int num[110]={0};
	for(int i=0;i<N;i++){
		num[d[i]]++;
	}	
	
	for(int i=1;i<=100;i++){
		if(num[i]>0)
			ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    int area = 2*D + 1;
    cout << (N + (area - 1)) / area << endl;
}

Measured memory_bytes: 888
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,string> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const ll inf=1e16+7;
const double eps=1e-8;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
//const double pi=acos(-1);

int fa[102030];
int find(int x){
    return fa[x]==x? x:(fa[x]=find(fa[x]));
}
int join(int x,int y){
    fa[find(x)]=find(y);
    return 0;
}
int main()
{
    TB
    int n,m;
    cin>>n>>m;
    fd(n+1) fa[i]=i;
    fd(m){
        int x,y;
        cin>>x>>y;
        join(x,y);
    }
    int flag=0;
    for(int i=2;i<=n;i++){
        if(find(1)!=find(i)){
            join(i,1);
            flag++;
        }
    }
    cout<<flag<<'\n';
    return 0;

}

Measured memory_bytes: 4032
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
struct Process{
    int x;
    int y;
};
signed main(){
    int n,m;cin>>n>>m;
    vector<Process> p(m);
    int res=0;
    vector<int> a(n+1,1);
    vector<bool> b(n,false);
    b[1]=true;
    rep(i,m){
        int x,y;cin>>x>>y;
        if(b[x]){
            b[y]=true;
        }
        a[x]--;
        a[y]++;
        if(a[x]==0){
            b[x]=false;
        }
    }
    rep1(i,n){
        if(b[i])res++;
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 2560
# coding: utf-8
# Your code here!
n=int(input())
s=input()
MOD = 10**9+7

dp = [1]*n

for i,c in enumerate(s):
    if c == "<":
        ssum = sum(dp[1:n-i])
        ssum %= MOD
        for j in range(n-i-1):
            dp[j] = ssum
            ssum -= dp[j+1]
            ssum %= MOD

    else:
        ssum = dp[0]
        for j in range(n-i-1):
            dp[j] = ssum
            ssum += dp[j+1]
            ssum %= MOD

#    print(dp)


print(dp[0])
        






Measured memory_bytes: 44280
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    ll n;cin>>n;
    vll a(5);
    rep(i,5)cin>>a[i];
    ll m=1000000000000001;
    rep(i,5)if(a[i]<m)m=a[i];
    rep(i,5){
        if(m==a[i]){
            cout<<(n+a[i]-1)/a[i]+4<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  
  vector<int> dp(N, INF);
  dp.at(0) = 0;
  
  for (int i = 1; i < N; i++) {
    if (i >= 2) dp.at(i) = min(dp.at(i), dp.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
    dp.at(i) = min(dp.at(i), dp.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
  }
  
  cout << dp.at(N - 1) << endl;
  
  return 0;
}

Measured memory_bytes: 1024
i,c,a[2000];
main(n,m){
	for(;scanf("%d%d",&n,&m),n;i=c=0){
		for(;n+m-i;scanf("%d",a+i++));
		for(i=0;c<n-1?(c+=a[c])<n-1:0;c+=a[n+i++]);
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b),d(b);
  rep(i,b)
    cin>>c[i]>>d[i];
  if(a==1&&b==0)
    cout<<0;
  else{
  if(a==1){
    int k=-1;
    int g=0;
  bool t=1;
    rep(i,b){
    if(k!=-1&&d[i]!=k){
      t=0;
      }
      else{
        k=d[i];
        }
    }
    if(!t){
      cout<<-1;
      }
    else
      cout<<k;
  }
  else{
  bool ans=0;
  vector<int> e(a);
  rep(i,a)
    e[i]=-1;
  rep(i,b){
  if(c[i]==1&&d[i]==0)
    ans=1;
  else if(e[c[i]-1]!=-1&&e[c[i]-1]!=d[i])
    ans=1;
  else
    e[c[i]-1]=d[i];
  }
  if(ans)
    cout<<-1;
  else{
  rep(i,a){
    if(i==0){
    if(e[i]==-1)
      cout<<1;
      else
        cout<<e[i];
    }
    else{
  if(e[i]!=-1)
    cout<<e[i];
    else
      cout<<0;
     }
  }
  }
    }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int factorial(int n)
{
    if (n == 0) {return 1;}
    return n * factorial(n - 1);
}
int main(){
    int i,a,j,x[8],y[8],n;
    double s=0;
    cin>>n;         //cout<<factorial(n)<<endl;
    a=(n-1)*factorial(n-2)*2;   //cout<<a;
    for(i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            s=s+sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
        }
    }
    printf("%0.10lf\n",(s*a)/factorial(n));
    return 0;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            int ans = B % A == 0 ? A + B : B - A;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
c = Counter(A)

ans = 0
flag = False
for i in range(n):
    if c[A[i]] == 0:
        continue

    pow_2 = 2 ** len(format(A[i], "b"))
    if c[pow_2 - A[i]] > 0 and pow_2 - A[i] != A[i]:
        c[pow_2 - A[i]] -= 1
        c[A[i]] -= 1
        ans += 1
    elif c[pow_2 - A[i]] > 1 and pow_2 - A[i] == A[i]:
        if flag is True:
            c[A[i]] -= 2
            ans += 1
            flag = False
        else:
            flag = True

print(ans)

Measured memory_bytes: 33296
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k;
    cin >> n >> k;
    vpii v;
    rep(i,0,n){
        ll x,y;
        cin >> x >> y;
        v.push_back({x,y});
    }
    sort(all(v));
    ll sum=0;
    for(ll i=0; i<v.size(); i++){
        sum+=v[i].second;
        if(sum>=k){
            cout << v[i].first;
            return 0;
        }
    }
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 2420
import java.util.HashMap;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    HashMap<Integer, Long> map = new HashMap<>();
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      map.put(A[i], map.getOrDefault(A[i], 0L) + 1);
    }
    long sum = 0;
    for (Long val : map.values()) {
      sum += val * (val - 1) / 2;
    }
    for (int i = 0; i < N; i++) {
      long sum1 = sum;
      long val = map.get(A[i]);
      sum1 -= val * (val - 1) / 2;
      if (val > 2) {
        sum1 += (val - 1) * (val - 2) / 2;
      }
      System.out.println(sum1);
    }
  }
}


Measured memory_bytes: 98556
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n, cnt=0, a, b, c;
  string s;
  cin >> n;
  vector<int> l(n);
  	for(int i=0; i<n; i++) cin >> l.at(i);
  	sort(l.begin(), l.end());
  	for(int i=0; i<n-2; i++){
      for(int j=i+1; j<n-1; j++){
        for(int k=j+1; k<n; k++){
          if(l[k]-l[j]<l[i] && l[i]<l[j]+l[k]){
            /*
            if(a==l[i] && b==l[j] && c==l[k]){
              continue;
            }else{
              cout << l[i] << l[j] << l[k] << endl;
              cnt += 1;
              a = i;
              b = j;
              c = k;
            }*/
            cnt += 1;
          }else{
            break;
          }
        }
      }
    }
  cout << cnt << endl;

}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n;
		int a, b, c;
		int x, y[];

		while (true) {
			n = sc.nextInt();
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			x = sc.nextInt();
			if ((n | a | b | c | x) == 0) {
				break;
			}
			y = new int[n];
			for (int i = 0; i < n; i++) {
				y[i] = sc.nextInt();
			}

			int cnt = 0;
			int l = 0;
			boolean f = false;
			while (true) {
				if (10000 < cnt) {
					f = false;
					break;
				}
				if (y[l] == x) {
					l++;
				}
				x = (a * x + b) % c;
				if (l == n) {
					f = true;
					break;
				}
				cnt++;
			}

			if (f) {
				System.out.println(cnt);
			} else {
				System.out.println("-1");
			}
		}
	}
}

Measured memory_bytes: 31776
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);

void Main() {
  // 配列に１〜１２が属するグループ番号を記録
  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int x, y;
  cin >> x >> y;
  cout << ((a[x] == a[y]) ? "Yes" : "No") << endl;
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

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

using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b == 2 ? a : gcd(b, a % b);};
ll poww(ll a, ll b, ll md) {
   return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
const long long MOD = 1e9+7;
const int SIZE = 1e5+10;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    long long n,m,n1,m1;
    cin>>n>>m>>n1>>m1;
    long long v = n*n1;
    long long v1 = n*m1;
    long long v2 = m*n1;
    long long v3 = m*m1;
    cout<<max(max(v,v1),max(v2,v3))<<endl;











    return 0;
}




Measured memory_bytes: 3616
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
for n in range(N):
	A.append(list(map(int, input().split())))
x = 0
for i in range(N):
	y = 0
	for k in range(M):
		y = y + A[i][k] * B[k]
	if y + C > 0:
		x = x + 1
print(x)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x-a) % b << endl;
    return 0;
}




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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9 + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> w(n + 1);
  rep(i, n) cin >> w[i];

  int minv = INF;

  for (int t = 1; t < n; ++t) {
    int S1 = 0, S2 = 0;
    for (int i = 0; i < n; ++i) {

      if (i <= t) S1 += w[i];
      else S2 += w[i];

    }

    chmin(minv, abs(S1 - S2));
  }

  cout << minv << "\n";

  return 0;
}

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

int main(){
    int n,m;
    cin >>n>>m;
    int a;
    for(int i=0;i<m;i++){
        cin >>a;
        n -= a;
    }
    if(n<0){
        cout <<-1<<endl;
        return 0;
    }
    cout <<n<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

bool dp[10010] = {};

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

	dp[0] = true;
	
	rep(i, n) {
		int s;
		cin >> s;
		for (int j = 10000; j >= 0; j--) {
			if (dp[j]) dp[j + s] = true;
		}
	}
	
	for (int j = 10000; j >= 0; j--) {
		if (dp[j] && j % 10) {
			cout << j << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter
n,k=map(int,input().split())
num=list(map(int,input().split()))

dic=Counter(num)
d=sorted(dic.items(),key=lambda x:x[1])
l=len(d)
if l<=k:
  ans=0
else:
  ans=sum([d[i][1] for i in range(l-k)])
print(ans)

Measured memory_bytes: 39336
N, D = map(int, input().split())
l = [list(map(int, input().split())) for i in range(N)]

ans=0
s=0
for i in range(N):
  for j in range(i+1,N):
    s=0
    for d in range(D):
      s+=(l[i][d]-l[j][d])**2
    if s**(1/2)%1==0:
      ans+=1
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

#define SENTINEL -100000000

int merge(int A[], int left, int mid, int right) {
	int L[mid-left+1];
	int R[right-mid+1];
	int n1 = mid - left;
	int n2 = right - mid;
	int count = 0;
	int i,j,k;

	for(i=0;i<n1;i++) {
		L[i] = A[left+i];
	}
	L[i] = SENTINEL;
	for(i=0;i<n2;i++) {
		R[i] = A[mid+i];
	}
	R[i] = SENTINEL;
	for(k=left,i=0,j=0;k<right;k++) {
		if(L[i] == SENTINEL && R[j] == SENTINEL) {
			break;
		} else if(L[i] == SENTINEL && R[j] != SENTINEL) {
			A[k] = R[j];
			j++;
			count++;
		} else if(R[j] == SENTINEL && L[i] != SENTINEL) {
			A[k] = L[i];
			i++;
			count++;
		} else if(L[i] <= R[j]) {
			A[k] = L[i];
			i++;
			count++;
		} else if(R[j] != -1){
			A[k] = R[j];
			j++;
			count++;
		}
	}
	return count;
}
	
int merge_sort(int A[], int left, int right) {
	int mid;
	int count = 0;
	if(left+1 < right) {
    	mid = (left + right)/2;
        count += merge_sort(A, left, mid);
        count += merge_sort(A, mid, right);
        count += merge(A, left, mid, right);
	}
	
	return count;
}

int main(void) {
	int i,n;
	int A[500000+1];
	int count;
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &A[i]);
	}

	count = merge_sort(A, 0, n);
	
	for(i=0;i<n;i++) {
		printf("%d", A[i]);
		if(i<n-1) {
			printf(" ");
		} else {
			printf("\n");
		}
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 4508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	cout<<a*b/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define endl        "\n"
#define si(a)       scanf("%d",&a)
#define si2(a,b)    scanf("%d%d",&a,&b)
#define sl(a)       scanf("%lld",&a)
#define sl2(a,b)    scanf("%lld%lld",&a,&b)
#define pb          push_back
#define mk          make_pair
#define loop(n)     for(int i=0; i<n; i++)
#define FOR(a,b)    for(int i=a; i<=b; i++)
#define sz          size()
#define ff          first
#define ss          second
#define mem(a,val)  memset(a, val, sizeof(a))
#define md          998244353
#define pi          acos(-1.0)

ll f[200010], sum[200010], l[20],r[20];
int main()
{
    ll t,n,i,j,k,lf, rt;
    sl2(n,k);
    for(int i=0; i<k; i++)
    {
        sl2(l[i],r[i]);

    }
    sum[1]=f[1]=1;
    for(int j=2; j<=n; j++)
    {
        for(int i=0; i<k; i++)
        {
            lf=max(1LL, j-r[i]);
            rt=j-l[i];
            if(rt<1)
                continue;
            f[j]=((f[j]+sum[rt]-sum[lf-1])%md+md)%md;
        }
        sum[j]= (sum[j-1]+f[j])%md;
    }
    cout<<f[n];//%md;
}




Measured memory_bytes: 6812
N = input()
H = list(map(int, input().split()))

yes = True
for i in range(len(H) - 1, 0, -1):
    if H[i] < H[i -1] - 1:
        yes = False
        break
    elif H[i] < H[i - 1]:
        H[i - 1] -= 1
    
if yes:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14396
k = list(map(int, input().split()))
n = k[ 0 ]
m = k[ 1 ]

bigArray = []
smallArray = []
for i in range ( n ) :
    bigArray.append( list(map(int, input().split())) )
for i in range ( m ) :
    smallArray.append( int(input()) )

for i in range ( n ) :
    answerPerRow = 0
    for j in range ( m ) :
        answerPerRow += bigArray[ i ][ j ] * smallArray[ j ]
    print( answerPerRow )

Measured memory_bytes: 8016
R,G,B,N = map(int,input().split())

ans = 0
for b in range(N+1):
    for g in range(N+1):
        if N-B*b-G*g < 0:
            break
        if (N-B*b-G*g)%R == 0:
            ans += 1
print(ans)


Measured memory_bytes: 40684
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    int p=0;
    int g;
    for(int i=0;i<s.length();i++){
      if(s.charAt(i)=='p'){
        p++;
      }
    }
    g=s.length()-p;
    g=s.length()%2==1?g-1:g;
    System.out.println((g-p)/2);
  }
}

Measured memory_bytes: 25684