akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
ll modpow(ll a, ll b)
{
    if (b == 0)
        return 1;
    else if (b % 2 == 0)
    {
        ll d = modpow(a, b / 2) % MOD;
        return (d * d) % MOD;
    }
    else
    {
        return (a * modpow(a, b - 1)) % MOD;
    }
}

const int MAX_N = 100010;

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r)
{
    if (n < r || r < 0)
        return 0;
    return fact[n] * finv[n - r] % MOD * finv[r] % MOD;
}

void calc(int n)
{
    fact[0] = finv[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD - 2);
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    V vec1(n);
    rep(i, n) cin >> vec1[i];
    V vec2(n);
    rep(i, n) cin >> vec2[i];
    V reg(n, -1);
    reg[0] = vec1[0];
    rep3(i,1,n){
        if(vec1[i]!=vec1[i-1]){
            reg[i] = vec1[i];
        }
    }
    if(reg[n-1]!=-1&&reg[n-1]!=vec2[n-1]){
        cout<<0<<endl;
        return 0;
    }
    reg[n-1]=vec2[n-1];
  //  rep(i,n)cout<<reg[i]<<" ";
  //  cout<<endl;
    for (int i = n - 2; i >= 0;i--){
        if(reg[i]!=-1){
            if(vec2[i]!=vec2[i+1]){
                if(reg[i]!=vec2[i]){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                if(vec2[i]<reg[i]){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }else{
            if(vec2[i]!=vec2[i+1]){
                reg[i] = vec2[i];
            }
        }
    }
  //  rep(i,n)cout<<reg[i]<<" ";
  //  cout<<endl;
    ll sum = 1;
    rep(i,n){
        if(reg[i]==-1){
            sum *= min(vec1[i], vec2[i]);
            sum %= MOD;
        }
    }
    cout << sum << endl;
}


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

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

    int n = s.length();
    if(n<=k)
    {
        cout<<s;
    }
    else
    {
        for(int i = 0;i<k;++i)
        {
            cout<<s[i];
        }
        cout<<"...";
    }

    return 0;
}


Measured memory_bytes: 3620
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static int N;
        static long mod = 1000000007;
        static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();
        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            //R = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var S = Console.ReadLine();

            var con = true;
            for (long h = 1;con && h <= 3500; h++)
            {
                for (long n = 1; con && n <= 3500; n++)
                {
                    long low = 1L;
                    long high = 3501L;
                    long w = (low + high) / 2;
                    while (high - low > 1)
                    {
                        w = (low + high) / 2;
                        if (4*h*n*w - N*(n*w+h*w+n*h) == 0)
                        {
                            Console.WriteLine(h+" "+n+ " " + w);
                            con = false;
                            break;
                        }
                        else if (4 * h * n * w - N * (n * w + h * w + n * h) > 0)
                        {
                            high = w;
                        }
                        else
                        {
                            low = w;
                        }
                    }
                }
            }
        }

    }
}


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

int main()
{
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++)
        cin >> s[i];

    long long ans[h][w];
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            ans[i][j] = 0;

    for (int i = 0; i < w; i++)
    {
        if (s[0][i] == '#')
            break;
        ans[0][i] = 1;
    }

    for (int i = 0; i < h; i++)
    {
        if (s[i][0] == '#')
            break;
        ans[i][0] = 1;
    }

    for (int i = 1; i < h; i++)
        for (int j = 1; j < w; j++)
            if (s[i][j] == '#')
                ans[i][j] = 0;
            else
                ans[i][j] = (ans[i][j - 1] + ans[i - 1][j]) % (1000000000+7);

    cout << ans[h - 1][w - 1];
    return 0;
}


Measured memory_bytes: 13348
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

char c[11] = {'a','b','c','d','e','f','g','h','i','j','k'};

int n;

void dfs(string s){
    if(s.size() == n){
        cout << s << endl;
        return;
    }
    set<char> se;
    int nex = 0;
    rep(j,s.size()){
        if(se.find(s[j]) != se.end()) continue;
        nex++;
        se.insert(s[j]);
        dfs(s+s[j]);
    }
    dfs(s + c[nex]);
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    dfs("a");
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define lowbit(x) ((x) & -(x))

typedef long long ll;
const int N = 100054, Z = N * 2;

ll L;
int n, cnt = 1, d[Z][2];
char s[N];

void append(char *s) {
	char *p = s; int t = 1, id;
	for (; *p; ++p)
		id = *p & 1, t = (d[t][id] ? d[t][id] : (d[t][id] = ++cnt));
}

ll dfs(int t, ll dep) {return t ? dfs(d[t][0], dep - 1) ^ dfs(d[t][1], dep - 1) : lowbit(dep + 1);}

int main() {
	scanf("%d%lld", &n, &L);
	for (int i = 0; i < n; ++i) scanf("%s", s), append(s);
	puts(dfs(1, L) ? "Alice" : "Bob");
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include<string>
using namespace std;
int main() {
	int n;
	string w[100];
	bool a = true;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	for (int i = 0; i < n; i++) {
		if (i) {
			if (w[i].front() != w[i - 1].back())a = false;
		}
		for (int j = 0; j < i; j++) {
			if (w[i] == w[j])a = false;
		}
	}
	if (a)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
const int INF = 1e9+50;
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
/*----------------------------------------------*/
int dp[110][101010]; 
int w[110],v[110];

signed main(){
  int n,W;
  cin>>n>>W;
  rep(i,n) cin>>w[i]>>v[i];
  rep(i,110)rep(j,101010) dp[i][j]=INF;
  
  dp[0][0]=0;
  rep(i,n+1)rep(j,101010){
    if(j>=v[i]) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
    chmin(dp[i+1][j],dp[i][j]);
  }

  int ans=0;
  rep(j,101010) if(dp[n][j]<=W) ans=j;
  cout<<ans<<endl;
  // rep(i,n+1){
  //   rep(j,101010) if(dp[i][j]<INF) cout<<dp[i][j]<<"/"<<j<<" ";
  //   cout<<endl;
  // }
  return 0;
}


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

long long int max(long long int a,long long int b){
	if(a>=b) return a ;
	else return b ;
}

int main(){
	using ll = long long int ;
	ll a,b ;
	cin >> a >> b ;
	cout << max(a+b,max(a-b,a*b)) << endl ;
}


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

int main() {
  int n; cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  
  sort(L.begin(), L.end());
  int ans = 0;
  for(int i=0; i<n-2; i++){
    for(int j=i+1; j<n-1; j++){
      int k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
      ans += max(k - (j+1), 0);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
#include<random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const int MOD=1e9+7;

int main(){

  static const double pi = 3.141592653589793;
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double theta1, theta2, theta;
  theta1 = h / 12 * 360 + m / 60 * 30;
  theta2 = m / 60 * 360;
  theta = abs(theta1 - theta2) * pi / 180;
  cout << setprecision(10) << endl;
  double ans = sqrt(a*a + b*b -2*a*b*cos(theta));
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4200
n,a,b,c,d=map(int,input().split())
s=input()
if s[b:d].count('##')>0:
    print('No')
    exit()

if c>d:
    flg=True
    if s[b-2:d+1].count('...')>0:
        flg=False
    if flg:
        print('No')
        exit()

if s[a:c].count('##')>0:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>

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

int a[212345];

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
//    vector<int> a(n);
    rep(i, n) cin >> a[i];
//    sort(a.begin(), a.end());
    sort(a, a+n);
    int ans;
    double half_num = a[n-1] * 1.000 / 2;
    double dist = 1e9;
    rep(i, n) {
        if ( abs(half_num - a[i]) < dist ) {
            dist = abs(half_num - a[i]);
            ans = a[i];
        }
    }
    cout << a[n-1] << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
// ll mod = 998244353;
 ll mod = 1000000007;
  
ll mypow(ll number1,ll number2, ll mod){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
bool multicase = false;

ll n,m,num,sum,a,b,c,d,e,h,q;
ll w, ans;
ll k;
char s[500005], t[500005];

void solve(){
    string s;
    cin >> s;
    Yes(s != "AAA" && s != "BBB");
    return;
}

int main(){
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q;
    if(multicase){
        cin >> q;
    }else{
        q = 1;
    }
    while(q--){
        solve();
    }
    return 0;

}


















Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const int INF = 2e9;
int H, W, K;
char S[11][1001];
typedef pair<int, int> P;

int calc(vector<P> kugiri) {
  int ret = 0;
  int left = 0;
  int right = 0;
  vector<int> V(kugiri.size());
  while (right<=W-1) {
    bool end_flag = true;
    rep(j, kugiri.size()) {
      int cnt = 0;
      for(int k=kugiri[j].first; k<=kugiri[j].second; k++) cnt+=S[k][right]-'0';
      V[j]+=cnt;
      if (V[j]>K) {
        if (cnt>K) return INF; // 見込みなし
        else { // 区切って再計算
          ret++;
          left=right;
          end_flag = false;
          rep(i, V.size()) V[i] = 0; 
          break;
        }
      }
    }
    // 縦列は最後まで捜査した
    if (end_flag) right++;
  }
  return ret;
}

int main() {
  INCANT;
  cin >> H >> W >> K;
  rep(i, H) rep(j, W) cin >> S[i][j]; 
  int ans = INF;
  rep(i, pow(2,H-1)) {
    int cnt = 0;
    bitset<9> b(i);
    vector<P> kugiri;
    int top = 0;
    int bottom = 0;
    rep(j, H-1) { // 区切り線
      if (b[j]) {
        cnt++;
        kugiri.push_back(P(top, bottom));
        top = bottom+1;
        bottom = top;
      } else bottom++;
    }
    kugiri.push_back(P(top, H-1));
    ans = min(ans, calc(kugiri)+cnt);
  }
  cout << ans << "\n";
  return 0;
}

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

using namespace std;

typedef tuple<int,int,int> ti;

int main()
{
  int n,x,y,z;
  
  cin >> n;
  
  int limit = sqrt(n);
  map<int, int> mp;
  for(x = 1; x <= limit; x++){
   	for(y = 1; y <= limit; y++){
    	for(z = 1; z <= limit; z++){
       		int p = x*x+y*y+z*z+x*y+y*z+z*x;
            mp[p]++;
     	}
	 }
  }
  
  for(int i = 1; i <= n; i++){
	cout << mp[i] << endl;
  }
  
  
  
  return 0;
}



Measured memory_bytes: 5420
N, M, X = map(int, input().split())
C = [(list(map(int, input().split()))) for _ in range(N)]

# bit全探索を行い、参考書に関する全ての組みについて、値段と理解度を求める
val = []
for i in range(2**N):
  U = [0]*(M+1)
  for j in range(N):
    if ((i >> j) & 1):
      for k in range(M+1):
        U[k] += C[j][k]
  
  # ある組みが条件を満たすなら、その値段をvalに追加
  if sum([u >= X for u in U[1:]]) == M:
    val.append(U[0])

# 条件を満たす組みの中で、値段が最小のものを出力し、組みが無ければ-1を出力する
ans = 0
if len(val) == 0: ans = -1
else: ans = min(val)
print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include <math.h>
int n,m,i,j,k,count1=0,count2=0;
using namespace std;
void ABC120(void);
void ABC121(void);
void ABC122(void);
void ABC123(void);
void ABC124(void);
void ABC125(void);
void ABC126(void);
void ABC127(void);
void ABC128(void);
void ABC129(void);

int main(void){
    ABC124();
}

void ABC124(){
    cin>>n;
    int max=0,h;
    for(i=0;i<n;i++){
        cin>>h;
        if(h>=max){
            max=h;
            count1++;
        }
    }
    cout<<count1<<endl;
}

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

ll func(ll x) {
	if (x % 2 == 0) return x / 2;
	else  return 3 * x + 1;
}

int main() {

	ll s; cin >> s;
	const ll p = 1000001;
	vector<ll> num(p, 0);
	ll a = s;
	ll cnt = 1;
	while (true) {
		num[a]++;
		if (num[a] == 2) {
			break;
		}
		ll tmp = a;
		a = func(tmp);
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 11168
#include<iostream>
#include<math.h>
using namespace std;
int v[1000][1000] , ans=0;
int main()
{
	int n,d;	cin>>n>>d;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			cin>>v[i][j];
	
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			double dis=0;
			for(int k=1;k<=d;k++)
				dis+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			//cout<<dis<<endl;
			int bo=sqrt(dis);
			dis=sqrt(dis);
			//cout<<dis<<endl;
			if(bo==dis)
				ans++;
		}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import itertools

def main():
    N, M, Q = map(int, input().split())
    a = [0 for _ in range(Q)]
    b = [0 for _ in range(Q)]
    c = [0 for _ in range(Q)]
    d = [0 for _ in range(Q)]

    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())

    seq = [i for i in range(1, min(11, M+1))]

    max_point = 0

    for e in list(itertools.combinations_with_replacement(seq, N)):
        point = 0
        for i in range(Q):
            if e[b[i]-1] - e[a[i]-1] == c[i]:
                point += d[i]
        if point >= max_point:
            max_point = point

    print(max_point)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21520
import java.util.Scanner;
import java.util.Arrays;

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

        String str = sc.nextLine();

        int num = 0;

        for(int i = 0; i < str.length()/2; i ++) {
            char char1 = str.charAt(i);

            char char2 = str.charAt(str.length()-i-1);

            if(!(str.charAt(i)==str.charAt(str.length()-i-1))) {
                num++;
            }
        }

        System.out.print(num);

    }
}

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

using namespace std;

int main()
{
    long long n;
    cin>>n;
    long long rez=0, d=2;
    while(d*d<=n){
        int ans=0, cnt=1;
        while(n%d==0){
            ans++;
            if(ans==cnt){
                rez++;
                ans=0;
                cnt++;
            }
            n/=d;
        }
        d++;
    }
    if(n!=1){
        rez++;
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 3640
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n;
        cin>>n;
        cout<<(n*(n-1))/2;
    }
    return 0;
}

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

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
typedef pair<int , int>  PII;
typedef pair<long long , long long>  PLL;

bool Comp(const PLL& a, const PLL& b) {
	return a.second > b.second;
}

int n, m;
string s;

int main() {
	cin >> n>>m;
	if (m>((n - 1)*(n - 2))/2) {
		cout << -1 << endl;return 0;
	}
	cout << n - 1 + (n - 1)*(n - 2) / 2 - m<<endl;
	for (int i = 0; i < n-1; i++)
	{
		cout << i + 1 << " " << n<<endl;
	}
	int cnt = (n - 1)*(n - 2) / 2 - m;
	for (int i = 0; i < n-1; i++)
	{
		for (int j = i+1; j < n-1; j++)
		{
			if (!cnt)return 0;
			cout << i + 1 << " " << j + 1<<endl;
			cnt--;
		}
	}
}

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

int a[100010], p[100010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", &a[i]);
		if(a[i] >= 1)p[a[i]-1]++;
		p[a[i]]++;p[a[i]+1]++;
	}
	int ans = 0;
	for(int i = 0;i < 100010;i++){
		ans = max(ans, p[i]);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for (int i = 0; i < n; i++){
            String s = sc.next();
            if (s.equals("AC"))
                ac++;
            else if (s.equals("WA"))
                wa++;
            else if (s.equals("TLE"))
                tle++;
            else 
                re++;
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
    }
    
}

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

vector <int> train[501];

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

	int n,m,q,a,b;

	cin >> n >> m >> q;

	for(int i=0;i<m;i++)
	{
		cin >> a >> b;
		train[a].push_back(b);
	}

	for(int i=1;i<=n;i++)
	{
		sort(train[i].begin(),train[i].end());
	}

	for(int i=0;i<q;i++)
	{
		cin >> a >> b;
		int res = 0;
		for(int j=a;j<=n;j++)
		{
			if(train[j].size()==0)
			{
				continue;
			}

			int idx = upper_bound(train[j].begin(),train[j].end(),b) - train[j].begin();
			//cout << j << ' ' << idx << ' ' << train[j][idx] << ' ' << b << '\n';
			res += (idx);
		}

		cout << res << '\n';
	}

	return 0;	
}


Measured memory_bytes: 2176
<?php

fscanf(STDIN, "%s", $s);
$S = str_split($s);
$n = strlen($s);

// 黒白黒....
$cnt1 = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($i % 2 === 0) {
        // $S[$i] === 1である必要がある
        if ($S[$i] != 1) ++$cnt1;
    } else {
        if ($S[$i] != 0) ++$cnt1;
    }
}

// 白黒黒....
$cnt2 = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($i % 2 === 0) {
        // $S[$i] === 1である必要がある
        if ($S[$i] != 0) ++$cnt2;
    } else {
        if ($S[$i] != 1) ++$cnt2;
    }
}

/* echo "cnt1: $cnt1, cnt2: $cnt2", PHP_EOL; */
echo min($cnt1, $cnt2);


Measured memory_bytes: 10744
import sys

readline = sys.stdin.readline


def ns(): return readline().rstrip()


def ni(): return int(readline().rstrip())


def nm(): return map(int, readline().split())


def nl(): return list(map(int, readline().split()))


N, D = nm()
ans = 0
for i in range(N):
    X, Y = nm()
    if X ** 2 + Y ** 2 <= D ** 2:
        ans += 1
print(ans)


Measured memory_bytes: 9188
from collections import defaultdict
from itertools import product as pd

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

l = list(map(int,list(input())))

bitAll = pd([0,1],repeat=3)
for i in bitAll:
	t = l[0]
	for j in range(3):
		if i[j]==1:
			t+=l[j+1]
		else:
			t-=l[j+1]
	if t==7:
		tar = "".join([str(j) for j in list(i)])
		break

l = [str(i) for i in l]
tar = tar.replace("1","+")
tar = tar.replace("0","-")
print(l[0]+tar[0]+l[1]+tar[1]+l[2]+tar[2]+l[3]+"=7")

Measured memory_bytes: 9364
#include <bits/stdc++.h>
#define rep1(i,s,e,c) for(int i=s;i<e;i=i+c)
#define rep2(i,s,e,c) for(int i=s;i<=e;i=i+c)
#define rep3(i,e,s,c) for(int i=e;i>=s;i=i-c)
using namespace std;
typedef long long ll;
const int MAX=1e3+1;
const int MOD=1e9+7;
int Map[MAX][MAX];
int xx[]={0,0,1,-1};
int yy[]={1,-1,0,0};
struct node{
	int x,y,s;
}no,no1; 
int main()
{
	int n,m,ans=0,num=0;
	cin>>n>>m;
	queue<node> q;
	rep2(i,1,n,1){
		rep2(j,1,m,1){
			char ch;
			cin>>ch;
			if(ch=='#')
			{
				Map[i][j]=1;
				no.x=i;
				no.y=j;
				no.s=0;
				q.push(no);
				num++;
			}
			else
				Map[i][j]=0;
		}
	}
	int sign=0;
	while(!q.empty()){
		no=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int tex=no.x+xx[i],tey=no.y+yy[i];
			if(tex>=1&&tex<=n&&tey>=1&&tey<=m&&!Map[tex][tey]){
				no1.x=tex;
				no1.y=tey;
				no1.s=no.s+1;
				q.push(no1);
				Map[tex][tey]=1;
				num++;
				ans=max(ans,no1.s);
				if(num==n*m){
					sign=1;
					break;
				}
			}
		}
		if(sign==1) break;
	}
	cout<<ans<<endl;
    return 0;
}    
         

Measured memory_bytes: 16272
#include <iostream>
#include <complex>

using namespace std;

#define COMP complex<int>
int abs(int a) {return (a<0) ?-a:a;}

char *p, buf[11000];

COMP expr();

COMP fact(){
	COMP ret;
	if(*p == '('){
		p++;
		ret=expr();
		p++;
	}else if(*p == 'i'){
		ret=COMP(0,1);
		p++;
	}else{
		while(isdigit(*p)){
			ret = ret * 10 + int(*p - '0');
			p ++;
			if(abs(ret.real()) > 10000 || abs(ret.imag()) > 10000) throw 0;
		}
	}
	
	return ret;
}

COMP term(){
	COMP ret = fact();
	while(*p=='*'){
		p++;
		ret *= fact();
		if(abs(ret.real()) > 10000 || abs(ret.imag()) > 10000) throw 0;
	}
	return ret;
}

COMP expr(){
	COMP ret = term();
	while(*p=='+' || *p=='-'){
		char ope = *p++;
		if(ope=='+') ret += term();
		if(ope=='-') ret -= term();
		if(abs(ret.real()) > 10000 || abs(ret.imag()) > 10000) throw 0;
	}
	return ret;
}

int main(){
	COMP ret;
	while(cin>>buf){
		p = buf;
		try{
			ret = expr();
			if(ret.real() || !ret.imag()) cout << ret.real();
			if(ret.imag()>0 && ret.real()) cout << '+';
			if(ret.imag()) cout<<ret.imag()<<"i";
			cout << endl;
		}catch(...){
			cout<<"overflow"<<endl;
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int H, W, ans=1; cin >> H >> W; string A[H];
REP(i, H){ cin >> A[i]; }
int B[H][W]={}; vector< pair<int, int> > C;
REP(i, H){ REP(j, W){ 
  if(A[i][j]=='#'){  B[i][j]=1; C.push_back(make_pair(i, j)); } 
} }
REP(i, H*W){
if((int)C.size()==H*W){ cout << ans-1 << "\n"; return 0; }
int a=C[i].first, b=C[i].second, c=B[a][b]+1;
if(a>0&&!B[a-1][b]){ B[a-1][b]=c; C.push_back(make_pair(a-1, b)); }
if(b>0&&!B[a][b-1]){ B[a][b-1]=c; C.push_back(make_pair(a, b-1)); }
if(a<H-1&&!B[a+1][b]){ B[a+1][b]=c; C.push_back(make_pair(a+1, b)); }
if(b<W-1&&!B[a][b+1]){ B[a][b+1]=c; C.push_back(make_pair(a, b+1)); }
ans=c;
}
}

Measured memory_bytes: 17448
#include<stdio.h>
int main(){
    long long x;
    scanf("%lld",&x);

    long long a = 100;
    int i;
    for(i = 0;1;i++){
        if (a >= x)
        {
            /* code */
            printf("%d\n",i);
            break;
        }
        a = a * 1.01;
    }

    return 0;
    }

Measured memory_bytes: 1732
N, K = map(int, input().split())
A = [int(i) for i in input().split()]

AA = A[:] + A[:]
mod = 10**9 + 7

def bubble_sort(L: list) -> int:
    A = L[:]
    count = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                count += 1
    return count


ans1 = bubble_sort(A)
ans2 = bubble_sort(AA) - 2 * ans1
ans = (K * ans1 + (K * (K - 1) // 2) * ans2) % mod

print(ans)


Measured memory_bytes: 3316
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cini(N);
    vector<int> x(N);
    rep(i,N)cin>>x[i];
    int minPoint = INF;
    rep(i,100){
        int nowX = i+1;
        int tempPoint = 0;
        rep(j,N)tempPoint+=pow(nowX-x[j],2);
        minPoint = min(minPoint,tempPoint);
    }
    cout << minPoint <<nn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

template<typename value_type>
class extended_euclidean
{
public:
	value_type gcd;
	value_type lcm;
	value_type x0;
	value_type y0;

public:
	extended_euclidean(value_type a, value_type b)
		: gcd(0), lcm(0), x0(0), y0(0)
	{
		tie(gcd, x0, y0) = process(a, b);
		lcm = a * b / gcd;
	}

public:
	tuple<value_type, value_type, value_type> process(value_type a, value_type b)
	{
		if (a == 0) return make_tuple(b, 0, 1);

		value_type g, x, y;
		tie(g, x, y) = process(b % a, a);

		return make_tuple(g, y - (b / a) * x, x);
	}
};

//extended_euclidean<long long> ee(a, b);
//long long gcd = ee.gcd;
//long long lcm = ee.lcm;

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

	int N, X;
	cin >> N >> X;

	vector<int> x_list(1, X);
	for (int i = 0; i < N; i++)
	{
		int x;
		cin >> x;

		x_list.push_back(x);
	}

	sort(x_list.begin(), x_list.end());

	vector<int> diff_list;
	for (int i = 1; i < x_list.size(); i++)
	{
		diff_list.push_back(x_list[i] - x_list[i - 1]);
	}

	int curr_gcd = diff_list[0];
	for (int i = 1; i < diff_list.size(); i++)
	{
		extended_euclidean<long long> ee(curr_gcd, diff_list[i]);
		curr_gcd = ee.gcd;
	}

	cout << curr_gcd;

	return 0;
}


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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=1e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);


int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0,x=d;
    while(x<=r)
        {if(x>=l)
        ans++;
    x+=d;}
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3592
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    println!("{:?}", n - k + 1);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

double T, x;
cin >> T >> x;
double ans = T / x;
cout << fixed << setprecision(7) << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	int D1[101];
	int D2[101];
	for(int i = 0; i < N; i++){
		cin >> D1[i] >> D2[i];
	}
	
	int flag = false;
	for(int i = 0; i < N-2; i++){
		if(D1[i] == D2[i] && D1[i+1] == D2[i+1] && D1[i+2] == D2[i+2]){
			flag = true;
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  10005

double dp[3005][2*N];  // [ idx ] [ heads - tails ]

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int n;
		cin>>n;
		double p[n+1];
		for(ll int i=1;i<=n;i++)
		{
			cin>>p[i];
		}
		memset(dp,0.0,sizeof(dp));
		dp[1][N+1]=p[1];
		dp[1][N-1]=1-p[1];
		for(ll int i=2;i<=n;i++)
		{
			for(ll int j=-n;j<=n;j++)
			{
				dp[i][N+j]=p[i]*dp[i-1][N+j-1]+(1-p[i])*(dp[i-1][N+j+1]);
				// cout<<dp[i][j+N];
			}
		} 
		double ans=0;
		for(ll int i=0;i<=n;i++) ans+=dp[n][N+i];
		cout<<setprecision(15)<<ans;
	}
	return 0;
}

Measured memory_bytes: 470016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define INF (1LL<<31)-1
//#define MOD 998244353
#define MOD 1000000007

int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int x=c/b,y=a/d;
    if(c%b!=0)x++;
    if(a%d!=0)y++;
    if(x<=y)printf("Yes");
    else printf("No");
}

Measured memory_bytes: 3748
#include<iostream>
using namespace std;
int main()
{
	int A,B;
	cin>>A>>B;
	for(int C=1;C<=3;C++)
	  if(A*B*C%2==1)
	  {
	  	  cout<<"Yes";
	  	  return 0;
	  }
	cout<<"No";
}

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


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

	vector<int> a(100001, 0), b(100001, 0);

	for(int i = 0; i < n / 2; i++) {
		int c, d;
		cin >> c >> d;
		a[c]++;
		b[d]++;
	}

	priority_queue<pair<int, int>> qa, qb;

	for(int i = 1; i <= 100000; i++) {
		qa.push(make_pair(a[i], i));
		qb.push(make_pair(b[i], i));
	}

	auto aa = qa.top(), bb = qb.top();

	if(aa.second == bb.second) {
		qa.pop();
		qb.pop();
		auto aa2 = qa.empty() ? make_pair(0, 0) : qa.top();
		auto bb2 = qb.empty() ? make_pair(0, 0) : qb.top();
		if(aa2.first + bb.first > aa.first + bb2.first) aa = aa2;
		else bb = bb2;
	}

	cout << n - aa.first - bb.first << endl;
}


Measured memory_bytes: 2804
// Petr's solution.
// http://petr-mitrichev.blogspot.com/2017/07/a-week-with-two-trees.html
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> treeA, treeB;
vector<bool> visited;
vector<vector<int>> unpaired;
vector<vector<int>> pairs;
vector<int> color;

void visit(int v, int p, vector<vector<int>> &tree) {
  visited[v] = true;
  for (int w : tree[v]) {
    if (!visited[w]) {
      visit(w, v, tree);
    }
  }
  // If this is an odd vertex, add it to the unpaired vector.
  if (!(tree[v].size() & 1)) {
    unpaired[v].push_back(v);
  }
  // Greedy pairing.
  for (int i = 0; i + 1 < (int)unpaired[v].size(); i += 2) {
    pairs[unpaired[v][i]].push_back(unpaired[v][i + 1]);
    pairs[unpaired[v][i + 1]].push_back(unpaired[v][i]);
  }
  // If there is a vertex left unpaired, push it to the parent.
  if (p != -1 && unpaired[v].size() & 1) {
    unpaired[p].push_back(unpaired[v].back());
  }
}

void bicolor(int v, int c) {
  color[v] = c;
  for (int w : pairs[v]) {
    if (color[w] == -2) {
      bicolor(w, -c);
    }
  }
}

int main() {
  // Reads both trees.
  int n;
  scanf("%d", &n);
  treeA.resize(n);
  treeB.resize(n);
  int rootA, rootB;
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    if (p != -1) {
      p--;
      treeA[p].push_back(i);
    } else rootA = i;
  }
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    if (p != -1) {
      p--;
      treeB[p].push_back(i);
    } else rootB = i;
  }

  // Check for impossible case with not matching parities.
  for (int i = 0; i < n; i++) {
    if ((treeA[i].size() & 1) != (treeB[i].size() & 1)) {
      printf("IMPOSSIBLE\n");
      return 0;
    }
  }
  printf("POSSIBLE\n");

  // Pair odd vertices on both trees.
  visited.assign(n, false);
  unpaired.assign(n, vector<int>());
  pairs.resize(n);
  visit(rootA, -1, treeA);
  visited.assign(n, false);
  unpaired.assign(n, vector<int>());
  visit(rootB, -1, treeB);

  // Assign -1 & 1 as a bicoloring.
  color.assign(n, -2);
  for (int i = 0; i < n; i++) {
    if (treeA[i].size() & 1) {
      color[i] = 0;
    } else if (color[i] == -2) {
      bicolor(i, -1);
    }
  }

  //Print the result.
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", color[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 21376
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 1e6;
char str[N];


int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    scanf("%s", str);
    int n = strlen(str);

    vector <int> st;
    for (int i = 0; i < n; i++)
    {
        if (!st.empty() && st.back() == 'S' && str[i] == 'T')
            st.pop_back();
        else
            st.push_back(str[i]);
    }
    printf("%d\n", (int) st.size());




	return 0;
}




Measured memory_bytes: 1528
#include<cstdio>
#include<algorithm>

using namespace std;

int n,m,c;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (m - i - j <= n && m - i - j >= 0) {
				c++;
			}
		}
	}
	printf("%d\n",c);
}


Measured memory_bytes: 128
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

struct LazySegmentTree {
	int n;
	vector<LL> node, lazy, flag;
public:
	LazySegmentTree(int sz, LL init) {
		n = 1;
		while (n<sz)n *= 2;
		node.resize(2 * n - 1, init);
		lazy.resize(2 * n - 1, INF<LL>());
	}

	void eval(int k, int l, int r) {
		if (lazy[k] != INF<LL>()) {
			node[k] = lazy[k];
			if (r - l>1) {
				lazy[2 * k + 1] = lazy[k] / 2;
				lazy[2 * k + 2] = lazy[k] / 2;
			}
		}
		lazy[k] = INF<LL>();
	}
	//[a,b)にxを加算
	void update(int a, int b, LL x, int k = 0, int l = 0, int r = -1) {
		if (r<0)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			lazy[k] = x*(r - l);
			eval(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];
		}
	}
	//[a,b)での和を返す
	LL getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r<0)r = n;
		eval(k, l, r);
		if (r <= a || b <= l)return 0;
		if (a <= l&&r <= b)return node[k];
		LL xl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
		LL xr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
		return xl + xr;
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	LazySegmentTree sg(n, 0);
	REP(i, q) {
		int t; cin >> t;
		if (t) {
			int a, b;
			cin >> a >> b;
			b++;
			cout << sg.getsum(a, b) << endl;
		}
		else {
			int a, b, c;
			cin >> a >> b >> c;
			sg.update(a, b + 1, c);
		}
	}
}


Measured memory_bytes: 7068
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    ld a, b;
    cin >> a >> b;
    ld res = a * b + 1e-3;
    ll ans = res;
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;

typedef long long ll;
ll INF = 1LL << 60;

int
main() 
{
  int N, M; cin >> N >> M;
  vector<int> arr(M);
  rep(i, 0, M) cin >> arr[i];
  sort(arr.begin(), arr.end());
  vector<int> diff(M - 1);

  if(M == 1 || N >= M){
    cout << 0 << endl;
    return 0;
  }else if(M == 2){
    cout << abs(arr[1] - arr[0]) << endl;
    return 0;
  }

  vector<int> original(M - 1);
  rep(i, 0, M - 1){
    int tmp =  arr[i + 1] - arr[i];
    diff[i] = tmp;
    original[i] = tmp;
  }
  
  sort(diff.begin(), diff.end(), greater<int>());

  vector<int> positions(N -1);
  rep(i, 0, N - 1){
    auto index = find(original.begin(), original.end(), diff[i]);
    positions[i] = distance(original.begin(), index);
  }
  
  int ans = *(arr.end() - 1) - *arr.begin();
  rep(i, 0, N - 1){
    ans -= original[positions[i]];
  }

  cout << ans << endl;

}




Measured memory_bytes: 1792
n,*t=map(int,open(0).read().split());A=t[:n];B=t[n:];r=0
while 1:
 c=0
 for i in range(n):
  b=B[~-i%n]+B[-~i%n]
  if A[i]<B[i]>b:t=(B[i]-A[i])//b;c+=t;B[i]-=t*b
 r+=c
 if c==0:break
print([-1,r][A==B])

Measured memory_bytes: 122168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int min,sum,N;
  double x,K;
  cin >> N;
  cin >> K;
  for(int i=0;i<N;i++){
    cin  >> x;
    if(x>=K/2){
      if(K>=x)
        sum+=2*(K-x);
      else
        sum+=2*(x-K);
    }
    else{
      sum+=2*x;
    }
  }
  cout << sum << endl;
}

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



int main() {
	int a, p;
	cin >> a >> p;
	p += a * 3;
	for (unsigned long long i = 0; i < 500000000; i++) {
		p++;
	}
	p -= 500000000;
	cout << p / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   ll a,b,x;
   cin >> a >> b >> x;

   ll tmpmin = 0;
   ll tmpmax = 0;

   if(a%x >0 ) tmpmin = a/x + 1;
   else if( a%x == 0) tmpmin = a/x ;

   tmpmax = b/x;

   ll ans = 0;
   ans = tmpmax - (tmpmin - 1);
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256