akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int a,b;
    cin >> a >> b;
    if((a+b) % 2 == 0){
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())

if a < b:
    A = a
    B = b
else:
    A = b
    B = a

if (B - A) % 2 != 0:
	print("IMPOSSIBLE")
else: 
	K = int(B - (B - A) / 2)
	print(str(K))

Measured memory_bytes: 3060
s=[0]*4001
for i in range(2001):
    a=a+2*(i-999)*(i-1000) if i>1000 else 0
    s[i]=(i+3)*(i+2)*-~i//6-a
    s[4000-i]=s[i]
while 1:
    try:print(s[int(input())])
    except:break

Measured memory_bytes: 7704
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var dist1 = new int[num];
        var dist2 = new int[num];
        var ads = new List<int>[num];
        for (var i = 0; i < num; i++)
            ads[i] = new List<int>();
        for(var i = 0; i < num-1; i++)
        {
            var input = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
            ads[input[0] - 1].Add(input[1] - 1);
            ads[input[1] - 1].Add(input[0] - 1);
        }
        bfs(0, ads, dist1, new Queue<int>());
        bfs(num - 1, ads, dist2, new Queue<int>());
        var resfe = 0;
        var ressn = 0;
        for (var i = 1; i < num-1; i++)
            if (dist1[i] <= dist2[i]) resfe++;
            else ressn++;
        WriteLine(resfe > ressn ? "Fennec" : "Snuke");
    }
    private static void bfs(int st,List<int>[] ads,int[] dist,Queue<int> queue)
    {
        queue.Enqueue(st);
        while (queue.Count != 0)
        {
            var index = queue.Dequeue();
            foreach (var ad in ads[index])
                if (ad!=st&&dist[ad] == 0)
                {
                    dist[ad] = dist[index] + 1;
                    queue.Enqueue(ad);
                }
            
        }
    }
}


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

int main()
{
    cin.tie(0);

    int n; cin>>n;
    vector<int64_t> a(n);
    for (auto &r: a) {
        cin>>r;
    }

    multiset<int64_t> ss;

    for (auto &r: a) {
        // cout << "* " << ss.size() << endl;
        // for (auto &s: ss) {
        //     cout << "  * " << s << endl;
        // }

        auto it = ss.upper_bound(-r);
        if (it == ss.end()) {
            ss.insert(-r);
        } else {
            ss.erase(it);
            ss.insert(-r);
        }
    }

    cout << ss.size() << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int A[4] = {0};
    cin >> N >> A[1] >> A[2] >> A[3];
    int minVal = INF;
    vector<int> l(N);
    REP(i, N)
    {
        cin >> l[i];
    }
    REP(bitN, bit(2 * N))
    {
        vector<pair<int, int>> sumS(4);
        vector<int> p(N);
        REP(j, N)
        {
            int q = 0;
            q += (bitN & bit(2 * j)) ? 2 : 0;
            q += (bitN & bit(2 * j + 1)) ? 1 : 0;
            sumS[q].first += l[j];
            sumS[q].second++;
        }
        /*        cout << bitN << " ";
        REP(j, N)
        {
            cout << p[j];
        }*/
        int cost = 0;
        if (sumS[1].second == 0 || sumS[2].second == 0 || sumS[3].second == 0)
        {
            continue;
        }
        REPS(j, 3)
        {
            cost += (sumS[j].second - 1) * 10;
            cost += abs(sumS[j].first - A[j]);
        }
        minVal = min(cost, minVal);
    }
    cout << minVal << "\n";
}

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

int main(){

  int N; 
  int a[110];
  cin >> N;
  int i;
  int bobScore=0,aliceScore = 0;
  int answer;
  for(i = 0 ; i<N ;i++){
    cin >> a[i];
  }
  sort(a,a+N,greater<int>());
  i = 0;
  
  while( i < N ){
    if( i % 2 == 0)
      {
	aliceScore = aliceScore+a[i];
      }
    else
      {
	bobScore = bobScore+a[i];
      }
    i = i + 1;
  }
  
  answer = aliceScore-bobScore;
  cout << answer << endl;
}


Measured memory_bytes: 256
from itertools import accumulate

n = int(input())

a1 = [int(item) for item in input().split()]
a2 = [int(item) for item in input().split()][::-1]
cs1 = list(accumulate(a1))
cs2 = list(accumulate(a2))

max_value = 0
for i in range(n):
  max_value = max(max_value, cs1[i] + cs2[n-i-1])
  
print(max_value)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll ;
using namespace std ;
const int maxn = 2e5 + 5 ;
int n , m ;
int a[85][85] , b[85][85] ;
bool dp[85][85][85 * 85 * 2] ;
int main()
{
	memset(dp , 0 , sizeof(dp)) ;
	scanf("%d%d" , &n , &m) ;
	for(int i = 1 ; i <= n ; i ++)
	  for(int j = 1 ; j <= m ; j ++)
	    scanf("%d" , &a[i][j]) ;
	for(int i = 1 ; i <= n ; i ++)
	  for(int j = 1 ; j <= m ; j ++)
	    scanf("%d" , &b[i][j]) ;
	dp[0][1][0] = dp[1][0][0] = 1 ;
	for(int i = 1 ; i <= n ; i ++)
	{
		for(int j = 1 ; j <= m ; j ++)
		{
			for(int k = 0 ; k <= 80 * 80 * 2 ; k ++)
			{
			   if(dp[i][j - 1][k])
			   {
			   	  dp[i][j][abs(k - (a[i][j] - b[i][j]))] = 1 ;
			      dp[i][j][abs(k - (b[i][j] - a[i][j]))] = 1 ;  
			   }
			   if(dp[i - 1][j][k])
			   {
			   	  dp[i][j][abs(k - (a[i][j] - b[i][j]))] = 1 ;
			      dp[i][j][abs(k - (b[i][j] - a[i][j]))] = 1 ;  
			   }
			}
		}
	}
	for(int i = 0 ; ; i ++)
	  if(dp[n][m][i])
	  {
	  	printf("%d\n" , i) ;
	  	return 0 ;
	  }
}

Measured memory_bytes: 102400
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

bool cul(pll A,pll B){
    return A.F+A.S<B.F+B.S;
}



int main(){
    ll n;
    cin>>n;
    vector<pll> HP(n);
    for(auto &I:HP){cin>>I.F>>I.S;}
    sort(HP.begin(),HP.end(),cul);
    vector<vector<ll>> dp(n+1,vector<ll>(n+2,E));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int t=0;t<=n;t++){
            if(HP[i].F>=dp[i][t]){
                dp[i+1][t+1]=min(dp[i+1][t+1],dp[i][t]+HP[i].S);
            }
            dp[i+1][t]=min(dp[i+1][t],dp[i][t]);
        }
    }
    ll ans=0;
    for(int i=0;i<=n;i++){
        if(dp.back()[i]!=E){ans=i;}
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 196096
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int n, T, a;
    cin>>n>>T>>a;
    vector<int> H(n);
    for (int i = 0; i < n; i++) {
        cin>>H[i];
    }

    double _t = 1.0*INF;
    int idx;
    for (int i = 0; i < n; i++) {
        double ave = T - H[i]*0.006;
        if(_t>abs(ave-1.0*a)){
            idx=i+1;
            _t=abs(ave-1.0*a);
        }
    }

    cout<<idx<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
 
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    rep(i,n-1) cin >> b[i];
    vector<int> a(n);
    a[0] = b[0];
    for(int i = 1; i < n-1; i++){
        a[i] = min(b[i], b[i-1]);
    }
    a[n-1] = b[n-2];
    int ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 3644
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

# Nまでの数の最小素因数を列挙
def smallest_prime_factors(N):
    spf = [i for i in range(N+1)]
    spf[0] = 0
    spf[1] = 1
    for i in range(2, N+1):
        # 素数のとき
        if spf[i] == i:
            j = i ** 2
            while (j <= N):
                # spfがまだ決まっていないなら
                if (spf[j] == j):
                    spf[j] = i
                j += i

    return spf

# 複数クエリに対する高速素因数分解
# spf配列を用いる（Q<=10**5, A[i]<=10**6程度）
# 出力は，[[(素因数,指数),...,(素因数,指数)],...,[(素因数,指数),...,(素因数,指数)]]
def fast_factorization(A, spf):
    ans = []
    for i in range(len(A)):
        dict = defaultdict(int)
        if A[i] == 1:
            dict[1] = 1
        else:
            x = A[i]
            while (x != 1):
                dict[spf[x]] += 1
                x //= spf[x]
        ans.append(list(dict.items()))
    return ans

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

spf = smallest_prime_factors(10**6)
f = fast_factorization(A, spf)

Primes = set()
SC = set()
sc_flag = 0
count = 0
first = 1
for ff in f:
    tmp = set()
    for fff in ff:
        if fff[0] != 1:
            Primes.add(fff[0])
            count += 1
            tmp.add(fff[0])
        else:
            sc_flag = 1
    if first == 1:
        SC = tmp
    else:
        SC = SC.intersection(tmp)
    first = 0

if len(Primes) == count:
    print("pairwise coprime")
elif sc_flag == 1 or len(SC) == 0:
    print("setwise coprime")
else:
    print("not coprime")



Measured memory_bytes: 351676
#include<iostream>
#define FOR(i,n) for(int i=0;(i)<(n);(i)++)
using namespace std;
int G[101][101] = {};

int main()
{
	int n;
	cin >> n;
	FOR(i, n)
	{
		int m,u;
		cin >> u >> m;
		FOR(j, m)
		{
			int l;
			cin >> l;
			G[u-1][l-1] = 1;
		}
	}
	FOR(i, n)
	{
		FOR(j, n)
		{
			cout << G[i][j];
			if (j != n - 1)cout << " ";
		}
		cout << endl;
	}
	return 0;
}

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

#define MAX_N 51000

int prime[MAX_N];
bool is_prime[MAX_N + 1];


void prime_generate(){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

	for(int i = 2; i <= MAX_N; i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j = 2 * i; j <= MAX_N; j += i) is_prime[j] = false;
		}
	}
}

void solve(int n){
	for(int i = 0; i < MAX_N; i++){
		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i-1] << " " << prime[i] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	prime_generate();

	int n;
	while(cin >> n){
		solve(n);
	}
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define CTOI(x) (x - 'A') 
#define ctoi(x) (x - 'a')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int N;
    int M;
    cin >> N >> M;
    vector<int> fast(N, 0);
    vector<vector<PII > > node(N);
    vector<int> have(N, 0);
    REP(i, M){
        int a, b, c;
        cin >> a >>b >> c;
        node[a].push_back(PII(b, c));
        ++have[b];
    }
    stack<int> st;
    st.push(0);
    while(!st.empty()){
        int d = st.top();
        st.pop();
        REP(i, node[d].size()){
            int nep = node[d][i].first;
            fast[nep] = max(fast[nep], fast[d] + node[d][i].second);
            if(--have[nep]==0)st.push(nep);
        }
    }
    cout << fast.back() << endl;
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, c, k, ans = 1;
    cin >> n >> c >> k;
    int T[n];
    rep(i, n) {
        cin >> T[i];
    }
    sort(T, T+n);

    int firstIndex = 0;
    int firstTime = T[0];
    for(int i = 1; i < n; i++) {
        if(firstIndex + c <= i || firstTime + k < T[i]) {
            firstIndex = i;
            firstTime = T[i];
            ans++;
        }
    }

    cout << ans;

    cout << endl;
    return 0;
}

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

const int N = 1000000;
int dp[2][N+1];

int main(){
  for(int i=0;i<=N;i++)dp[0][i] = dp[1][i] = N;
  dp[0][0] = dp[1][0] = 0;

  int val = 1;
  for(int i=1;val<=N;i++){
    for(int j=0;j+val<=N;j++){
      int nxt = j+val;
      if(dp[0][nxt]>dp[0][j]+1)dp[0][nxt] = dp[0][j] + 1;
      if( (val&1) && (dp[1][nxt]>dp[1][j]+1))dp[1][nxt] = dp[1][j] + 1;
    }
    val = i*(i+1)*(i+2)/6;
  }

  int n;
  while(scanf("%d",&n),n)printf("%d %d\n",dp[0][n],dp[1][n]);
}

Measured memory_bytes: 8840
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std; using ll=long long; const int INF=1e9; using P=pair<int,int>;

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

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
using CostType = long long int;
const CostType INF = 1LL << 60;

struct Elem {
  CostType pos, tic, cost;
  Elem(CostType a, CostType b, CostType c) : pos(a), tic(b), cost(c) {}
  bool operator<(const Elem &e) const {
    return cost > e.cost;
  }
};

int solve() {
  CostType rec[110][15];
  vector< pair<int, int> > G[110];
  
  int C, N, M, S, D; cin >> C >> N >> M >> S >> D;
  if(C == 0) return 1;
  
  for(int i=0; i<N; i++) G[i].clear();
  
  for(int i=0; i<M; i++) {
    CostType u, v, cost; cin >> u >> v >> cost;
    u--; v--;
    G[u].emplace_back(v, cost);
    G[v].emplace_back(u, cost);
  }

  S--; D--;
  priority_queue<Elem> que;
  fill(rec[0], rec[N+1], INF);
  rec[S][0] = 0;
  que.emplace(S, 0, 0);

  while(que.size()) {
    auto cur = que.top(); que.pop();
    if(cur.cost > rec[cur.pos][cur.tic]) continue;
    CostType mon = cur.cost;
    for(auto e : G[cur.pos]) {
      CostType u = cur.pos, v = e.first, c = e.second;
      if(cur.tic + 1 <= C) {
        int nt = cur.tic + 1, nc = mon + c / 2;
        if(rec[v][nt] > nc) {
          rec[v][nt] = nc;
          que.emplace(v, nt, nc);
        }
      }

      {
        int nt = cur.tic, nc = mon + c;
        if(rec[v][nt] > nc) {
          rec[v][nt] = nc;
          que.emplace(v, nt, nc);
        }
      }
    }
  }

  CostType ans = INF;
  for(int i=0; i<=C; i++) {
    ans = min(ans, rec[D][i]);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  while(!solve());
}



Measured memory_bytes: 3152
n=int(input())
a=[int(input()) for _ in range(n)]
ch=[0]*n
now=1
ans=0
ch[0]=1

while 1:
    now=a[now-1]
    ans+=1
    
    if now==2:
        print(ans)
        exit()
    else:
        if ch[now-1]==1:
            print("-1")
            exit()
        else:
            ch[now-1]=1
        

Measured memory_bytes: 7852
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
ll N, X, Y;
ll ans;

int main() {
	scanf("%lld%lld", &N, &X);
	X = min(X, N - X);
	Y = N - X;
	while(X) {
		if(Y % X == 0) {
			ans += (Y / X) * 2 * X - X;
			break;
		}
		else {
			ans += (Y / X) * 2 * X;
			swap(X, Y); X %= Y;
		}
	}
	printf("%lld\n", N + ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  int n,p[100],sum = 0;
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> p[i];
  
  for(int i = 1; i < n-1; i++) {
    if(p[i-1] < p[i] & p[i] < p[i+1]) sum++;
    else if(p[i+1] < p[i] & p[i] < p[i-1]) sum++;
  }
  cout << sum << endl;
}

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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

bool check(vector<string> &picture, vector<string> &peace, int i, int j, int m) {
    for (int k = 0; k < m; k++) {
        if (picture[i + k].substr(j, m) != peace[k]) {
            return false;
        }
    }
    return true;
}

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

    vector<string> picture(n);
    rep(i, n) cin >> picture[i];

    vector<string> peace(m);
    rep(i, m) cin >> peace[i];

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

            bool b = check(picture, peace, i, j, m);
            if (b) {
                cout << "Yes" << endl;
                ret();
            }
        }
    }
    cout << "No" << endl;
}

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

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

  string S;
  cin >> S;

  long long cntR = 0, cntG = 0, cntB = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'R')
      cntR++;
    else if (S.at(i) == 'G')
      cntG++;
    else
      cntB++;
  }

  long long cntFirst = cntR * cntG * cntB;

  long long cntSecond = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S.at(i) == S.at(j)) continue;
      int k = j * 2 - i;
      if (k >= N || S.at(k) == S.at(i) || S.at(k) == S.at(j)) continue;
      ++cntSecond;
    }
  }

  cout << cntFirst - cntSecond << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 2000001

int H, A[MAX];

void maxHeapify(int i){
  int l, r, largest, t;
  l = 2*i;
  r = 2*i+1;
  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest = r;
  if(largest != i){
    t = A[i];
    A[i] = A[largest];
    A[largest] = t;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for (i = 1;i <= H;i++)scanf("%d",&A[i]);
  
  for (i = H/2;i >= 1;i--)maxHeapify(i);

  for (i = 1;i <= H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  

  
  return 0;
}



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

int main(){
    int a,b,c,ans;
    cin >> a >> b >> c;
    ans=c-(a-b);
    ans=max(0,ans);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  char b;
  cin >> b;

  map<char, char> mp;
  mp['A'] = 'T';
  mp['T'] = 'A';
  mp['C'] = 'G';
  mp['G'] = 'C';

  cout << mp[b] << endl;
}

Measured memory_bytes: 256
#!/user/bin/env python
#pythonプログラムであることを示している

# -*- coding: utf-8 -*-
"""
このプログラムはPythonを書く際のテンプレとなっています。これをコピペしてコーディングを行なってください。
なお字下げしないこと！！
"""

__author_ = 'Maruta Yuzuha'
__version_ = '1.0.0'
__date__ = '2019/12/25'

def main():
    """
    ここでプログラムの解説を行う
     >>main()
    Hello world.
    0
    """
    s = input()
    t = 0
    for i in s:
        if t == 0:
            t = 'x'
        else:
            t += 'x'
    print(t)
    return 0

if __name__ == '__main__':
    #上記のifの記述によってこのスクリプトファイルが起動された時だけ実行する部分になる。
    #ちなみにスクリプトが "モジュールとして"インポートされた時には実行されない、

    #単体テスト:モジュールのdocstring(ドキュメンテーション文字列)に記載された全ての対話実行例が書かれている通りに動作するかを確認
    #python ファイル名 -v
    import doctest
    doctest.testmod()

    #実際にmain()を呼び出して、結果を得て、その結果でPythonシステムを終える
    import sys
    sys.exit(main())

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    int N;
    cin>>N;
    vector<int> A(N+1);
    for (int n = 1; n <= N; n++) cin>>A[n];

    int cur = 1;
    int count = 0;
    set<int> prev;
    while (prev.count(cur) == 0) {
        prev.insert(cur);
        cur = A[cur];
        count++;
        if (cur == 2) {
            cout<<count<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 5376
def m(L,R):
 global c
 T=[];i=j=0
 for _ in L[:-1]+R[:-1]:
  if L[i]<R[j]:T+=[L[i]];i+=1
  else:T+=[R[j]];j+=1
  c+=1
 return T
def d(A):s=len(A)//2;return m(d(A[:s])+[1e9],d(A[s:])+[1e9]) if len(A)>1 else A
c=0
input()
print(*d(list(map(int,input().split()))))
print(c)


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

int main() {
    int n;
    cin >> n;
    n--;
    vector<int> c(n), s(n), f(n);
    rep(i,n) cin >> c[i] >> s[i] >> f[i];
    rep(i,n) {
        int ans = 0;
        for(int j = i; j < n; ++j) {
            ans = max(ans, s[j]);
            int d = ans-s[j];
            if(d%f[j]==0) d = 0;
            else d = f[j]-(d%f[j]);
            ans+=d+c[j];
        }
        cout << ans << endl;
    } 
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
//#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
#include <unordered_map>
//#include <stack>
#include <queue>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
	int n;
	cin >> n;
	unordered_map<int, int> um[2];
	REP(i, n) {
		int v;
		cin >> v;
		um[i & 1][v]++;
	}
	vector<pair<int, int>> v[2];
	REP(j, 2)
		for (const auto &pair : um[j]) {
			v[j].emplace_back(pair.second, pair.first);
		}
	REP(j, 2)
		sort(v[j].rbegin(), v[j].rend());
	int ans;
	if (v[0][0].second != v[1][0].second) {
		ans = n - (v[0][0].first + v[1][0].first);
	}
	else {
		ans = n - max(v[0][0].first + v[1][1].first, v[0][1].first + v[1][0].first);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5524
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,x,y,z,a,b,c,cc[300000],dd[300000];
int main(){
	scanf("%d %d %d %d",&n,&m,&a,&b);
	for (int i=0;i<n;i++) scanf("%d",&cc[i]);
	for (int i=0;i<m;i++) scanf("%d",&dd[i]);	
	sort(cc,cc+n);
	sort(dd,dd+m);
	if (cc[n-1]<dd[0] && dd[0]>a && dd[0]<=b) printf("No War\n");
	else printf("War\n");
	return 0;
}

Measured memory_bytes: 128
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,K = II()
x = [0]*N
y = [0]*N
z = ['0']*N
for i in range(N):
    a,b,c = input().split()
    x[i],y[i],z[i] = int(a),int(b),c

x,y = y,x

for i in range(N):
    if z[i]=='B':
        x[i] = (2*K-1)-x[i]%(2*K)
        y[i] = y[i]%(2*K)
    else:
        x[i] += K
        x[i] = (2*K-1)-x[i]%(2*K)
        y[i] = y[i]%(2*K)

kukan = []
for i in range(N):
    if x[i]+K-1<=2*K-1:
        if y[i]-K+1>=0:
            kukan.append([x[i],x[i]+K-1,y[i]-K+1,y[i]])
        else:
            kukan.append([x[i],x[i]+K-1,0,y[i]])
            kukan.append([x[i],x[i]+K-1,K+y[i]+1,2*K-1])
    else:
        if y[i]-K+1>=0:
            kukan.append([0,x[i]-K-1,y[i]-K+1,y[i]])
            kukan.append([x[i],2*K-1,y[i]-K+1,y[i]])
        else:
            kukan.append([0,x[i]-K-1,0,y[i]])
            kukan.append([0,x[i]-K-1,K+y[i]+1,2*K-1])
            kukan.append([x[i],2*K-1,0,y[i]])
            kukan.append([x[i],2*K-1,K+y[i]+1,2*K-1])

tiles = [[0]*(2*K+1) for _ in range(2*K+1)]
for k in kukan:
    tiles[k[0]][k[2]] += 1
    tiles[k[0]][k[3]+1] -= 1
    tiles[k[1]+1][k[2]] -= 1
    tiles[k[1]+1][k[3]+1] += 1

for i in range(2*K):
    for j in range(1,2*K):
        tiles[i][j] += tiles[i][j-1]

for i in range(1,2*K):
    for j in range(2*K):
        tiles[i][j] += tiles[i-1][j]

ans = 0
for i in range(2*K):
    for j in range(2*K):
        if tiles[i][j]+tiles[(i+K)%(2*K)][(j+K)%(2*K)]>ans:
            ans = tiles[i][j]+tiles[(i+K)%(2*K)][(j+K)%(2*K)]

print(ans)

Measured memory_bytes: 116652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 1<<30

int main(){
	int n, m, a, b;
	cin >> n >> m;
	vector<int> per;
	int G[10][10] = {0};
	for(int i = 0;i < n; i++){
		per.pb(i);
	}
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		a--;b--;
		G[a][b] = 1;
		G[b][a] = 1;
	}
	int cnt = 0;
	do{
		if(per[0] != 0) break;
		int flag = 1;
		for(int i = 0; i < n-1; i++){
			if(G[per[i]][per[i+1]])continue;
			flag = 0;
			break;
		}
		if(flag) cnt++;
	}while(next_permutation(all(per)));
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
  int n;
  int m;
  int i;
  
  scanf("%d %d", &n, &m);
  
  int homework[m];
  
  for (i=0; i<m; i++) {
    scanf("%d", &homework[i]);
    n -= homework[i];
  }
  
  if (n >= 0)
    printf("%d",n);
  
  else
    printf("-1");
  
  return 0;
}

Measured memory_bytes: 1712
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int leftSpaceInA = a - b;
		if(leftSpaceInA > c) {
			System.out.println(0);
		}else {
			System.out.println(c - leftSpaceInA);
		}


		

		
		

		
		
	}	

}



Measured memory_bytes: 23764
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
min_a = min(a)
max_a = max(a)
res = mod
for i in range(min_a, max_a + 1):
    cost = 0
    for j in a:
        cost += abs(i-j) ** 2
    res = min(res, cost)
print(res)

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

    int N; cin >> N;

    while( N >= 0 )
        if ( N % 4 == 0 )
        {
            cout << "Yes"; return 0;
        }
        else
            N -= 7;

    cout << "No";
}


Measured memory_bytes: 256
def main():
    N, M, D = map(int, input().split())

    if D:
        ans = (max(0, N - D * 2) * 2 + min(N, D * 2))
    else:
        ans = N
    ans *= (M - 1) / N / N

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8884
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >>a[i];
  }
sort(a,a+n);int ans=0;int c=1;
for(int i=0;i<n-1;i++){
  if(a[i]==a[i+1]){
    c++;
    if(i==n-2){
      if(c%2==1) ans++;
    }
  }
  else{
    if(c%2==1) ans++;
    if(i==n-2) ans++;
    c=1;
  }
}
cout << ans<<endl;
}

/*#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  if(n==1){
      cout <<1<<endl;
      return 0;
  }
  sort(a,a+n);
  int cnt=1;
  int ans=0;
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]) cnt++;
    if(a[i]!=a[i+1]){
      //cout<<cnt<<endl;
      if(cnt%2==1) ans++;
      cnt=1;
      if(i==n-2){
        ans++;
        break;
      }
    }
  }
  cout <<ans<<endl;
}*/


Measured memory_bytes: 640
using System;

using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int kaisu = 0;
        int heikinnogoukei = 0;
        int goukei = 0;
        //  int heikin=0;
        while (true)
        {
            string gh = Console.ReadLine();
            if (gh == null) { break; }
            int[] a = gh.Split(',').Select(int.Parse).ToArray();
            goukei += a[1] * a[0];
            heikinnogoukei += a[1];
            kaisu++;
        }
        Console.WriteLine(goukei);
        // Console.WriteLine(heikinnogoukei % kaisu != 0 ? ""+heikinnogoukei / kaisu + 1+"":""+ heikinnogoukei / kaisu+"");
        if (heikinnogoukei % kaisu != 0) { Console.WriteLine(heikinnogoukei / kaisu + 1); }
        else { Console.WriteLine(heikinnogoukei/kaisu); }
        Console.ReadLine();
    }
}

    

Measured memory_bytes: 9488
#include <iostream>
#include <string>
int main()
{
	std::string str;
	std::getline(std::cin, str);

	int count = 0;
	int countMax = 0;
	for (auto c : str)
	{
		if (c == 'R')
		{
			count++;
			if (count > countMax)
			{
				countMax = count;
			}
		}
		else
		{
			count = 0;
		}
	}

	std::cout << countMax << std::endl;
}


Measured memory_bytes: 3624
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main() {
ll n;
   cin>>n;
   string s="";
  while(n>0)
  {
   char ch='a'+(n-1)%26;
   s=ch+s;
   if(n%26==0)n--;
   n/=26;
  }
   cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}

void solve(){
    int k;
    cin>>k;
    for(int i{};i<(k);++i){
        cout<<"ACL";
    }
    cout<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define INF 1000000000
#define endl "\n"
#define all(s) s.begin(),s.end()
#define pb push_back
#define uno unordered_map
#define pi 3.1415926536
#define dig(a) fixed<<setprecision(a)
#define test(zz) int zz; cin>>zz; while(zz--)
#define foreach(var,i) for(auto i = var.begin();i!=var.end();i++)
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll power(ll a, ll n) {ll res = 1; while (n) {if (n % 2) {res *= a;} n >>= 1; a *= a;} return res;}
ll powerm(ll a, ll n, ll m) {ll res = 1; while (n) {if (n % 2) {res = (res * a) % m;} n >>= 1; a = (a * a) % m;} return res;}
using namespace std;
int main(){
	fast();
	
	//test(t){}
	float d,t,s;
	cin>>d>>t>>s;
	//cout<<(d/s)<<endl;
	cout<<((d/s)<=t?"Yes":"No")<<endl;
	
	return 0;
}


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

int main() {
    int q;
    cin >> q;
    
    priority_queue<lint> front_queue;
    priority_queue<lint, vector<lint>, greater<lint>> back_queue;
    long long front_sum = 0, back_sum = 0, b_sum = 0;
    
    auto queue_size = [&] () { return (int)front_queue.size() + back_queue.size(); };
    auto queue_empty = [&] () { return (front_queue.empty() and back_queue.empty()); };
    auto balance = [&] () {
        if (queue_size() % 2 == 0) {
            if (front_queue.size() == back_queue.size()) return;
            if (front_queue.size() < back_queue.size()) {
                while (front_queue.size() != back_queue.size()) {
                    front_queue.emplace(back_queue.top());
                    back_sum -= back_queue.top();
                    front_sum += back_queue.top();
                    back_queue.pop();
                }
            } else {
                while (front_queue.size() != back_queue.size()) {
                    back_queue.emplace(front_queue.top());
                    front_sum -= front_queue.top();
                    back_sum += front_queue.top();
                    front_queue.pop();
                }
            }
        } else {
            if ((int)front_queue.size() == (int)back_queue.size()+1) return;
            if (front_queue.size() < back_queue.size()+1) {
                while (front_queue.size() < back_queue.size()) {
                    front_queue.emplace(back_queue.top());
                    back_sum -= back_queue.top();
                    front_sum += back_queue.top();
                    back_queue.pop();
                }
            } else {
                while (front_queue.size() > back_queue.size()+1) {
                    back_queue.emplace(front_queue.top());
                    front_sum -= front_queue.top();
                    back_sum += front_queue.top();
                    front_queue.pop();
                }
            }
        }
    };
    
    auto add = [&] (lint a, lint b) {
        b_sum += b;
        if (queue_empty()) { front_queue.emplace(a); front_sum += a; return; }
        balance();
        lint med = front_queue.top();
        if (med < a) { back_queue.emplace(a); back_sum += a; }
        else { front_queue.emplace(a); front_sum += a; }
    };
    
    auto answer = [&] () {
        balance();
        lint a = front_queue.top();
        lint s = (long long)front_queue.size();
        lint t = (long long)back_queue.size();
        lint ans = b_sum;
        ans += abs(a * s - front_sum);
        ans += abs(a * t - back_sum);
        cout << a << " " << ans << '\n';
    };
    
    while (q--) {
        int op;
        cin >> op;
        if (op == 1) {
            lint a, b;
            cin >> a >> b;
            add(a, b);
        } else {
            answer();
        }
    }
    return 0;
}

Measured memory_bytes: 3828
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
#define lp(i,n) for(ll i = 0;i < ll(n);i++)
#define rlp(i,n) for(ll i = ll(n);i >= 0;i--)
#define rg(i,a,b) for(ll i = ll(a);i <= ll(b);i++)
#define wh(t) while(t)
#define re return
#define pb push_back
#define sz(s) (ll)(s.size())
#define fx(n) fixed<<setprecision(n)
#define NeverGiveUp ios::sync_with_stdio(0), ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
/*freopen("input.txt","r", stdin);
	freopen("output.txt","w", stdout);*/
using namespace std;
/*ll mx = INT_MIN;
ll mn = INT_MAX;*/
/*ll xd,dx[4]={1,0,-1,0};
ll yd,dy[4]={0,1,0,-1};
bool valid(ll xd,ll yd,ll n,ll m){return xd>-1&&xd<n&&yd>-1&&yd<m;}*/
const int sz = 2e6+5;
const ll md = 1e9+7;
ll n,v[sz];
int main()
{
    NeverGiveUp
    cin>>n;
     rg(i,2,n+1){
        if (!v[i]){
			for(ll j=2*i;j<=n*10;j+=i)
			v[j]=1;
		}
	}
	v[0]=v[1]=1;
	for(ll i=n;;i++){
        if(!v[i])re cout<<i,0;
	}
    re 0;
}


Measured memory_bytes: 11436
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

enum type{
    TYPE_EAST,
    TYPE_WEST,
    TYPE_ALL
};

int main(void) {
    int num;
    cin >> num;
    string str;
    cin >> str;

    vector<int> table(256);
    table['W'] = TYPE_WEST; table['E'] = TYPE_EAST;
    // EEE[*]WW
    vector<vector<int>> cum(num+1, vector<int>(2));
    for(int i = 1; i <= num; i++) {
        char ch = table[str[i-1]];
        for(int k = 0; k < 2; k++) {
            cum[i][k] = cum[i-1][k] + (k == ch);
        }
    }

    int ans = 0;
    for(int i = 0; i < num; i++) {
        debug("%d %d\n", cum[i][TYPE_EAST], (cum[num][TYPE_WEST] - cum[i+1][TYPE_WEST]));
        // [0, i) + [i+1, num) = [0, i) + [0, num) - [0, i+1)
        ans = max(ans, cum[i][TYPE_EAST] + (cum[num][TYPE_WEST] - cum[i+1][TYPE_WEST]));
    }
    cout << (num-1)-ans << endl;
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> v;
    REP(i, N) {
        cin >> A[i];
        v.push_back(A[i]);
    }
    sort(v.begin(), v.end());
    REP(i, N) {
        A[i] = lower_bound(v.begin(), v.end(), A[i]) - v.begin();
    }

    ll cnt = 0;
    REP(i, N) {
        if (i % 2 != A[i] % 2)
            cnt++;
    }
    cout << cnt / 2 << endl;
    return 0;
}

Measured memory_bytes: 1912
#include<cstdio>
#include<deque>
#define m (100000)
#define intq deque<int>

using namespace std;

int main(void) {
  int n;
  char s[m + 2];

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

  s[n] = s[0];

  intq a(n + 2);

  int r = 0;
  int i;

  a[0] = 1;
  a[1] = 1;

  for (int i = 1; i < n+1; i++) {
    if (a[i]) {
      if (s[i] == 'o') {
        a[i+1] = a[i-1];
      } else {
        a[i+1] = 1 - a[i-1];
      }
    } else {
      if (s[i] == 'o') {
        a[i+1] = 1 - a[i-1];
      } else {
        a[i+1] = a[i-1];
      }
    }
  }


  if (a[n] == a[0] && a[n+1] == a[1])
    r = 1;

  if (!r) {
    a[1] = 0;
    for (int i = 1; i < n+1; i++) {
      if (a[i]) {
        if (s[i] == 'o') {
          a[i+1] = a[i-1];
        } else {
          a[i+1] = 1 - a[i-1];
        }
      } else {
        if (s[i] == 'o') {
          a[i+1] = 1 - a[i-1];
        } else {
          a[i+1] = a[i-1];
        }
      }
    }
    if (a[n] == a[0] && a[n+1] == a[1])
      r = 1;

    if (!r) {
      a[0] = 0;
      for (int i = 1; i < n+1; i++) {
        if (a[i]) {
          if (s[i] == 'o') {
            a[i+1] = a[i-1];
          } else {
            a[i+1] = 1 - a[i-1];
          }
        } else {
          if (s[i] == 'o') {
            a[i+1] = 1 - a[i-1];
          } else {
            a[i+1] = a[i-1];
          }
        }
      }
      if (a[n] == a[0] && a[n+1] == a[1])
        r = 1;

      if (!r) {
        a[1] = 1;
        for (int i = 1; i < n+1; i++) {
          if (a[i]) {
            if (s[i] == 'o') {
              a[i+1] = a[i-1];
            } else {
              a[i+1] = 1 - a[i-1];
            }
          } else {
            if (s[i] == 'o') {
              a[i+1] = 1 - a[i-1];
            } else {
              a[i+1] = a[i-1];
            }
          }
        }
        if (a[n] == a[0] && a[n+1] == a[1])
          r = 1;
      }
    }
  }

  if (r) {
    for (i = 0; i<n;i++) {
      if (a[i])
        printf("S");
      else
        printf("W");
    }
    printf("\n");
  } else
    printf("-1\n");

  return 0;

}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector <int> h(n);
  rep(i,n)cin >> h[i];
  map <int,queue <int>> ab;
  int a,b;
  rep(i,m){
    cin >> a >> b;
    ab[a-1].push(b-1);
    ab[b-1].push(a-1);
  }
  int ans =0;
  rep(i,n){
    bool flag= true;
    while(!ab[i].empty()){
      if(h[ab[i].front()]>=h[i]){flag=false;break;}
      ab[i].pop();
    }
    if(flag==true)ans++;
    //cout <<"ans " << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 75828
#include<cstdio>
#include<cstring>
#define N 120300
char s[N];
int main()
{
	int n,now=2;
	scanf("%s",s+1);n=strlen(s+1);
	if (s[1]=='0'||s[n]=='1') return !printf("-1");
	for (int i=1;i<n;++i)
		if (s[i]!=s[n-i]) return !printf("-1");
	printf("1 2\n");
	for (int i=2;i<n;++i)
	{
		printf("%d %d\n",now,i+1);
		if (s[i]=='1') now=i+1;
	}
	return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX / 2)

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    ll d;
    ll max_v=-INF;
    ll max_i=0;
    cin>>d;
    vector<ll>c(26);
    vector<vector<ll>>s(d,vector<ll>(26));
    vector<ll> ans;
    rep(i,26){
        cin>>c[i];
    }
    rep(i,d){
        max_v=-INF;
        rep(j,26){
            cin>>s[i][j];
            if(max_v<s[i][j]){
                max_v=s[i][j];
                max_i=j+1;
            }
        }
        ans.push_back(max_i);
    }
    rep(i,d){
        cout<<ans[i]<<endl;
    }
}
/*




*/


Measured memory_bytes: 3688
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 100007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

vector<ll> minFactor;
void sieve2(ll max)
{
    if (max+1 > minFactor.size())
        minFactor.resize(max+1,0);
    std::iota(minFactor.begin(), minFactor.end(), 0);
    for (ll i=2; i*i<=max; ++i)
        if (minFactor[i] >= i)
            for (ll j=i*i; j<=max; j += i)
                if (minFactor[j] == j) minFactor[j] = i;
}

void factor(ll n, map<ll,ll>& res)
{
    while (n > 1) {
        res[minFactor[n]]++;
        n /= minFactor[n];
    }
}

void solve()
{
    sieve2(1000005);
    IN(n);
    VIN(ll, a, n);
    map<ll,ll> pri;
    map<ll,ll> temp;
    factor(a[0], pri);
    reps(i, 1, n) {
        temp.clear();
        factor(a[i], temp);
        for (auto&& [p, q] : temp) {
            if (pri[p] > 0) goto end;
            pri[p] = q;
        }
    }
    cout << "pairwise coprime" << endl;
    return;
    end:;
    ll s = a[0];
    reps(i, 1, n) {
        s = gcd(s, a[i]);
    }
    if (s == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

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

void add_edge(vector<int> graph[], int a, int b) {
  graph[a].push_back(b);
  graph[b].push_back(a);
}

int main() {
  int n, m, h, s, d, count = 0;
  scanf("%d", &n);
  scanf("%d", &m);
  vector<int> graph[n];
  vector<int> heights(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &h);
    heights[i] = h;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d", &s);
    scanf("%d", &d);
    add_edge(graph, s-1, d-1);
  }
  for (int i = 0; i < n; i++) {
    bool add = true;
    for (int j = 0; j < graph[i].size(); j++) {
      if(heights[i] <= heights[graph[i][j]]) {
        add = false;
        break;
      }
    }
    if(add || graph[i].size() == 0) count++;
  }
  printf("%d\n", count);
}

Measured memory_bytes: 8424