akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans;}
   base *= base;pow/=2;}return ans;}
ll expo1(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}   
ll inv(ll x){return expo1(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){if(k == 0) return 1LL;
    ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};

ll val[123456], vis[123456];

int main(){
    int n, w;
    cin >> n >> w;
    vector <ll> W(n), V(n);
    for(int i = 0; i < n; i++) cin >> W[i] >> V[i];
    vis[0] = 1;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        vector <int> vis1;
        for(int j = w-W[i]; j >= 0; j--){
            if(vis[j]){
               val[j+W[i]] = max(val[j+W[i]],val[j]+V[i]);
               vis[j+W[i]] = 1;
               ans = max(ans,val[j+W[i]]);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
c = [False for i in range(200000)]
d = [False for i in range(200000)]
for i in range(m):
	a, b = map(int, input().split())
	if a == 1:
		c[b] = True
	if b == n:
		d[a] = True
for i in range(200000):
	if c[i] and d[i]:
		print ("POSSIBLE")
		exit()
print ("IMPOSSIBLE")

Measured memory_bytes: 6320
n = int(input())
num_list = list(map(int, input().split()))

tmp_list = []
cnt = 0
for i in range(0, n-2, 1):
    tmp = num_list[i:i+3]
    if tmp[0] < tmp[1] and tmp[1] < tmp[2]:
        cnt += 1
    elif tmp[2] < tmp[1] and tmp[1] < tmp[0]:
        cnt += 1

print(cnt)

Measured memory_bytes: 9208
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e3 + 10;
const int p = 1e9 + 7;

int a[maxn], b[maxn];
int dp[maxn][maxn], sum[maxn][maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    for (int i = 0; i <= m; i++) {
        sum[0][i] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            sum[i][j] = sum[i - 1][j] + (j == 0 ? 0 : sum[i][j - 1]) - (j == 0 ? 0 : sum[i - 1][j - 1]);
            if (a[i] == b[j]) sum[i][j] = (sum[i][j] + (j == 0 ? 0 : sum[i - 1][j - 1]) + p) % p;
            sum[i][j] = (sum[i][j] + p) % p;
        }
    }
    cout << sum[n][m] << "\n";

    return 0;
}


Measured memory_bytes: 35068
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int N;
	cin>>N;
	vector<int> A(N+2);
	A[0]=0;
	A[N+1]=0;
	REP(i,N){
		cin>>A[i+1];
	}
	int b=0;//全部行ったときの金額
	REP(i,N+1){
		b+=abs(A[i+1]-A[i]);
	}
	REP(i,N){
		int ans = b - abs(A[i+1]-A[i]) - abs(A[i+2]-A[i+1]) + abs(A[i+2]-A[i]);
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;


int main(){
    ll K; cin >> K;

    ll seven = 0;
    ll ans = -1;
    ll count = 0;
    set<ll> mods;
    while (true){
        seven = (seven*10 + 7) % K;
        if (seven == 0){
            ans = count+1;
            break;
        }
        else{
            auto it = mods.find(seven);
            if (it != mods.end()){
                break;
            }
            else{
                mods.insert(seven);
            }
        }
        
        count++;
    } 
    cout << ans << endl;
}

Measured memory_bytes: 50444
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

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

	cout<<((a*3)+b)/2<<endl;	

	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

bool used[100005];

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

    int n, m;
    cin >> n >> m;
    vector<P> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    vector<int> x;
    x.emplace_back(a[0].second);
    for(int i = 0; i < n - 1; ++i){
        x.emplace_back(a[i].second ^ a[i + 1].second);
    }
    x.emplace_back(a[n - 1].second);
    
    vector<vector<P>> graph(n + 1);
    for(int i = 0; i < m; ++i){
        int l, r;
        cin >> l >> r;
        l = lower_bound(a.begin(), a.end(), P(l, 0)) - a.begin();
        r = upper_bound(a.begin(), a.end(), P(r, 1)) - a.begin();
        graph[l].emplace_back(r, i + 1);
        graph[r].emplace_back(l, i + 1);
    }

    vector<int> ans;
    auto dfs = [&](auto&& self, int from) -> int {
        used[from] = true;
        int res = x[from];
        for(auto e : graph[from]){
            int to = e.first, idx = e.second;
            if(used[to])    continue;
            int r = self(self, to);
            if(r)   ans.emplace_back(idx);
            res ^= r;
        }
        return res;
    };

    for(int i = 0; i <= n; ++i){
        if(used[i]) continue;
        if(dfs(dfs, i)){
            cout << -1 << endl;
            return 0;
        }
    }

    sort(ans.begin(), ans.end());
    int sz = ans.size();
    cout << sz << '\n';
    for(int i = 0; i < sz; ++i){
        cout << ans[i];
        cout << ((i == sz - 1) ? '\n' : ' ');
    }
}

Measured memory_bytes: 20104
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
///                    BISMILLAHIR RAHMANIR RAHIM

int main()
{
 int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15,2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  k=k-1;
  cout<<a[k]<<endl;


}

/// A L H A M D U L I L L A H


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

int const MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    COMinit();
    int n, k; std::cin >> n >> k;
    std::vector<std::vector<ll>> s(1010, std::vector<ll>(1010, 0));
    s[0][0] = 1;
    repr(i, 1, 1010) repr(j, 1, 1010) {
        s[i][j] = s[i-1][j-1] + j*s[i-1][j];
        chmod(s[i][j]);
    }
    std::cout << s[n][k] << std::endl;
    
    return 0;
}


Measured memory_bytes: 57796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x=0;cin>>n;
  lvector A(n);rep(i,n) {cin>>A[i];x^=A[i];}
  rep(i,n) A[i]^=x;
  rep(i,n-1) cout<<A[i]<<' ';cout<<A[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 4744
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll x,a,b;
    cin >> x >> a >> b;
    cout << (x -a )%b << endl;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int N;
int F[100][14];
int P[100][15];

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < 10; j++) {
			cin >> F[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 11; j++) {
			cin >> P[i][j];
		}
	}
	int res = -(1 << 30); //1を30ビット左シフト(2進数)
	for (int b = 1; b <(1 << 10); b++) //全パターンの列挙
	{
		int cc = 0;
		for (int i = 0; i < N; i++)
		{
			int c = 0;
			for (int j = 0; j < 10; j++) {
				if ((b >> j & 1) && F[i][j]) c++;
			}
			cc += P[i][c]; //利益
		}
		if (res < cc) res = cc; //最大の利益
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	a := getInt()
	b := getInt()
	c := getInt()

	first := a % b
	if first == c {
		fmt.Println("YES")
		return
	}

	for x := a + a; ; x += a {
		if x%b == c {
			fmt.Println("YES")
			return
		} else if x%b == first {
			fmt.Println("NO")
			return
		}
	}
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
N, Y = map(int, input().split())

for i in range(N+1):
    for j in range(N+1-i):
            if 10000*i + 5000*j + 1000*(N-i-j) == Y:
                print(i, j, N-i-j)
                quit()
print(-1, -1, -1)

Measured memory_bytes: 3060
/**
 *    author:  zjsdut
 *    created: 2020/03/23 10:54:55
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define TOKENPASTE(x, y) x##y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#define rep(n)                                                                 \
  for (int TOKENPASTE2(_iter_, __LINE__) = 0,                                  \
                               TOKENPASTE2(_num_, __LINE__) = (int)(n);        \
       TOKENPASTE2(_iter_, __LINE__) < TOKENPASTE2(_num_, __LINE__);           \
       ++TOKENPASTE2(_iter_, __LINE__))
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL && !defined DUIPAI
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  int l; scan(l);
  double x = double(l) / 3;
  println(x * x * x);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int x,y,z,a,b;
  scanf("%d%d",&x,&y);
  if(x<y){
    a=x;
    b=y;
  }
  else{
    a=y;
    b=x;
  }
  while(x!=0){
    z=x;
    x=y%x;
    y=z;
  }
  printf("%d\n",z);
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_limit=(n); i<i##_limit; ++i)
#define FOR(i, a, b) for (int i=(a), i##_limit=(b); i<i##_limit; ++i)
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int X, Y;
    cin >> X >> Y;

    int ret = 0;
    switch (X)
    {
        case 1: ret += 300000; break;
        case 2: ret += 200000; break;
        case 3: ret += 100000; break;
    }
    switch (Y)
    {
        case 1: ret += 300000; break;
        case 2: ret += 200000; break;
        case 3: ret += 100000; break;
    }
    if (X == 1 && Y == 1) ret += 400000;

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=200005;
ll a[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	ll mid=a[(n+1)>>1];
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=abs(a[i]-mid);
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    ll n,x,m;cin >> n >> x >> m;
    ll ans = 0,cnt = 1,sum = 0,pos1 = 0,pos2 = 0;
    vector<ll>a;
    vector<ll>b(m,0);
    while(true){
        if(b[x%m]==0){
            b[x%m] = cnt;
            a.push_back(x%m);
            ans += (x%m);
        }
        else{
            pos1 = b[x%m];
            pos2 = cnt;
            break;
        }
        if(cnt==n){
            cout << ans;
            return;
        }
        x = (x%m)*(x%m);
        cnt++;
    }
    ans = 0;
    for(int i = 0;i<pos1-1;i++) ans += a[i];
    for(int i = pos1-1;i<pos2;i++) sum += a[i];
    ans += ((n-pos1+1)/(pos2-pos1))*sum;
    ll tp = (n-pos1+1)%(pos2-pos1);
    for(int i = pos1-1;i<pos1+tp-1;i++)
        ans += a[i];
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  rep(i, 0, N) cin >> a[i];
  vector<ll> D;
  rep(i, 0, N) {
    ll tmp = 0;
    rep(j, i, N) {
      tmp += a[j];
      D.push_back(tmp);
    }
  }
  ll mask = 0;
  ll ans = 0;
  for(int i = 50; i > -1; i--) {
    ll bit = 1LL << i;
    bit |= mask;
    int cnt = 0;
    rep(j, 0, D.size()) {
      if((D[j] | bit) == D[j]) cnt++;
    }
    if(cnt >= K) mask = bit;
  }
  cout << mask << endl;
  return 0;
}


Measured memory_bytes: 6260
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x,cnt,ans=1;
int main()
{
	cin>>x;
	while(x)
	{
		cnt++;
		x/=2;
	}
	for(int i=1;i<=cnt;i++)
		ans*=2;
	cout<<ans-1;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  char ch[1050];
  int a,b,c,d;
  int i, j,k,l;

  a = 0;
  while(1) {
 
    scanf("%c",&ch[a]);
   
   
    if(ch[a] == '\n') {
      break;
    }

    if(ch[a] ==  'A' || ch[a] == 'B' || ch[a] =='C') {
      ch[a] = ch[a] + 23;
    }  else {
      ch[a] = ch[a] -  3;
   
    }
    a = a + 1;
  }


  for(i = 0;i<a; i++) {
    printf("%c",ch[i]);
  }

  printf("\n");

  return 0;
}

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

namespace ABC172_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int count = 0;
            for (int i = 0; i < S.Length; i++)
            {
                if (!S[i].Equals(T[i]))
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27424
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
    int a,b;
    cin >> a >> b;
    if(a+b==15){
        cout <<"+" << endl;
    }else if(a*b==15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int dp[N],n;
vector<int>v;
int main()
{
	cin>>n;
	v.push_back(1);
	for(int i=6;i<=1e5;i*=6)v.push_back(i);
	for(int i=9;i<=1e5;i*=9)v.push_back(i);
	for(int i=1;i<=n;i++)dp[i]=1e9;
	for(int i=0;i<=n;i++)
		for(int j=0;j<v.size();j++)
			if(i+v[j]<=1e5)
				dp[i+v[j]]=min(dp[i+v[j]],dp[i]+1);
			else
				break;
	cout<<dp[n]<<endl;
	return 0;
}

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

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

    vector<int> ans(n);
    for(int i=0; i<n; i++) ans[a[i]-1] = i+1; 
    for(int i=0; i<n; i++) cout << ans[i] << " ";

    return 0;
}

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

using namespace std;

#define ll long long

int main() {
    int n, m;   cin >> n >> m;
    ll s = 0;
    vector <int> v(m);
    for (int &x:v)
        cin >> x, s += x;
    
    if (s <= n)
        cout << n - s;
    else 
        cout << -1 ;
}



// 5 3 1 1 4

// 1 2 3 4 5

// 4 100 1000

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n,h[100005];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)cin>>h[i];
	int p=0,ans=0;
	for(int i=n;i>=1;--i)
		if(h[i]<=h[i-1])++p,ans=max(ans,p);
		else p=0;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <list>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;


int main(){

    int n;
    int m;

    vector<int> arr;

    cin >> n >> m;

    int total = 0;
    while (n--){
        int a;
        cin >> a;
        total += a;
        arr.push_back(a);
    }

    if (m == 0){
        cout << "No" << endl;
    } else {

        float thres = 1 / float(4 * m);

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

        int counter = 0;
        for (int i = 0; i < m; i++) {
            if (arr[arr.size() - i - 1] >= (thres * float(total))) {
                counter++;
            }
        }
            if (counter >= m) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
    }

    return 0;
}

Measured memory_bytes: 256
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n;
pi A[56];
vector<pi>ans;
bool vis[56];
ll solve(pi x) {
	if(x.f==0&&x.s==0)return n;
	mmst(vis,0);
	ll ans=0;
	if(x.f>=0&&x.s>=0){
		sort(A,A+n);
	} 
	if(x.f>=0&&x.s<=0){
		sort(A,A+n,[](pi x, pi y){if(x.f!=y.f)return x.f<y.f;else return x.s>y.s;});
	}
	if(x.f<=0&&x.s>=0){
		sort(A,A+n,[](pi x, pi y){if(x.f!=y.f)return x.f>y.f;else return x.s<y.s;});
	}
	if(x.f<=0&&x.s<=0){
		sort(A,A+n,[](pi x, pi y){if(x.f!=y.f)return x.f>y.f;else return x.s>y.s;});
	}
	FOR(i,0,n){
		if(vis[i])continue;
		ans++;vis[i]=1; pi p=A[i];
		FOR(j,i+1,n)if(!vis[j]){
			if(p.f+x.f==A[j].f&&p.s+x.s==A[j].s){
				vis[j]=1;p=A[j];
			}
		}
	}
	if(ans==1){
		cerr<<x.f<<' '<<x.s<<'\n';
	}
	return ans;
}
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n){cin>>A[i].f>>A[i].s;}
	FOR(i,0,n){
		FOR(j,0,n){
			ans.pb(pi(A[i].f-A[j].f,A[i].s-A[j].s));
		}
	}
	ll anss=LLINF;
	for(auto i:ans)anss=min(anss,solve(i));
	cout<<anss;
}


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

using namespace std;

#define int long long

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

int32_t main()
{
   int n,m;
   cin>>n>>m;
   vector<pair<int,int>>v;
   for(int i=0;i<n;i++)
   {
       int a,b;
       cin>>a>>b;
       v.push_back({a,b});
   }
   sort(v.begin(),v.end());

   int rem_days=m+1;

   int i=0;

   priority_queue<int>p;

   int ans=0;

   for(int days=m;days>=1;days--)
   {
       while(i<n&&v[i].first<=(rem_days-days))
       {
           p.push(v[i].second);
           ++i;
       }
       if(!p.empty()){
       ans+=p.top();
       p.pop();
       }
   }
   cout<<ans<<endl;

}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  int ans = 0;
  cin >> S >> T;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == T.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
let N = stdin.ReadLine() |> int
let B = stdin.ReadLine().Split() |> Array.map int

[ 1..(N - 2) ]
|> List.map (fun i -> min B.[i - 1] B.[i])
|> List.sum
|> fun x -> B.[0] + x + B.[N - 2]
|> stdout.WriteLine

Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int H, W;
string S[3005];
int cntO[3005][3005] = {}, cntI[3005][3005] = {}; //OI
vector<P> jewel;
int main() {
	cin >> H >> W;
	rep(i, H) {
		cin >> S[i];
	}
	rep(i, H) rep(j, W) {
		if (S[i][j] == 'J') jewel.emplace_back(i, j);
		if (S[i][j] == 'O') {
			cntO[i][j]++;
		}
		if (S[i][j] == 'I'){
			cntI[i][j]++;
		}
	}
	for (int i = H - 1; i >= 0; i--) {
		for (int j = W - 1; j >= 0; j--) {
			cntO[i][j] += cntO[i][j + 1];
			cntI[i][j] += cntI[i + 1][j];
		}
	}
	ll ans = 0;
	rep(i, jewel.size()) {
		int x = jewel[i].first, y = jewel[i].second;
		ans += cntO[x][y] * cntI[x][y];
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 122384
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

A, B = LI()
if 0<A<10 and 0<B<10:
    print(A*B)
else:
    print(-1)
    


Measured memory_bytes: 66284
#include<iostream>
using namespace std;
int n, i, ii, j, x, nr, p, u, ok;
int v[205], c[205];
char a[205][205];
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> a[i] + 1;
    }
    nr = -1;
    for(ii = 1; ii <= n; ii++){
        for(i = 1; i <= n; i++){
            v[i] = 0;
        }
        v[ii] = p = u = 1;
        c[1] = ii;
        ok = 1;
        while(p <= u){
            x = c[p];
            for(i = 1; i <= n; i++){
                if(a[x][i] == '1'){
                    if(v[i] == 0){
                        v[i] = 1 + v[x];
                        c[++u] = i;
                    }
                    else{
                        if(v[i] != v[x] - 1 && v[i] != v[x] + 1){
                            ok = 0;
                        }
                    }
                }
            }
            p++;
        }
        if(ok == 1){
            for(i = 1; i <= n; i++){
                nr = max(nr, v[i]);
            }
        }
    }
    cout<< nr;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  vector<int> a1(N+1,0);
  vector<int> a2(N+1,0);


  REP(i,N){
    int t;
    cin >> t;
    a1[i+1] = a1[i] + t;
  }
  REP(i,N){
    int t;
    cin >> t;
    a2[i+1] = a2[i] + t;
  }

  int ans=0;
  REP(i,N){
    ans=max(ans, a1[i+1] + a2[N]-a2[i]);
  }
  cout << ans << endl;


}




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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (auto& e : h) cin >> e;

    h.push_back(0);

    int ans = 0;
    for (int i = 1, lim = *max_element(h.begin(), h.end()); i <= lim; i++) {
        for (int j = 0; j < n; j++) {
            if (h[j] >= i && h[j+1] < i) ans++;
        }
    }

    cout << ans << endl;
}


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

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

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2017/06/10  Problem: ABC 064 A / Link: http://abc064.contest.atcoder.jp/tasks/abc064_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N;

ll ans = 0LL;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int r, g, b;
  cin >> r>>g>>b;
  int x = 10 * g + b;
  if(x%4==0)
	  cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert
#define fh(x,v) for(auto x:v)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int ans;

main(){
    int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
    sort(a,a+n);
    if(n%2==0){
        vint v;
        rep(i,n)v.pb(abs(a[i]-a[n/2]));
        sort(all(v));
        fh(x,v)ans+=2*x;
        ans-=a[n/2]-a[n/2-1];
        dans;
    }else{
        vint v;
        rep(i,n)v.pb(abs(a[i]-a[n/2]));
        sort(all(v));
        fh(x,v)ans+=2*x;
        ans-=min(a[n/2]-a[n/2-1],a[n/2+1]-a[n/2]);
        dans;
    }
}









Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+'){
            ans++;
        }
        else ans--;
    }
    cout << ans << endl;
    


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	string s;

	cin>>s;

	rep(i,s.size()-1){
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}else if(s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3<<endl;
			return 0;
		}
	}
	cout<<"-1"<<" "<<"-1"<<endl;
	return 0;

}


Measured memory_bytes: 512
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define mod 1000000007
#define N 1000055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,fac[N*3],inv[N*3],x[10],y[10],ans,px;
int ksm(ll x,int k){
	int sum=1;
	while (k){
		if (k&1) sum=sum*x%mod;
		x=x*x%mod;k>>=1;
	}
	return sum;
}
int C(int n,int m){return (n<m||m<0)?0:1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;}
void init(int x){
	fac[0]=1;F(i,1,x) fac[i]=1LL*fac[i-1]*i%mod;
	inv[x]=ksm(fac[x],mod-2);D(i,x-1,0) inv[i]=1LL*inv[i+1]*(i+1)%mod;
}
inline void add(int &x,int k){x+=k;x-=(x>=mod)?mod:0;x+=(x<0)?mod:0;}
inline int ch(int a,int b,int c,int d){
	if (a<=c&&d>=b) return C(c-a+d-b+2,d-b+1);
	else return 0;
}
inline int gt(int a,int b){
	return ((ch(x[1],y[1],a,b)-ch(x[1],y[2]+1,a,b)-ch(x[2]+1,y[1],a,b)+ch(x[2]+1,y[2]+1,a,b))%mod+mod)%mod;
}
inline int gt2(int a,int b){
	return ((ch(a,b,x[6],y[6])-ch(a,b,x[5]-1,y[6])-ch(a,b,x[6],y[5]-1)+ch(a,b,x[5]-1,y[5]-1))%mod+mod)%mod;
}
signed main(){
	init(3000000);
	F(i,1,6) x[i]=read();
	F(i,1,6) y[i]=read();
	F(i,x[3]+1,x[4]){
		px=-gt(i,y[3]-1);
		px=1LL*px*gt2(i,y[3])%mod;
		px=1LL*px*(i+y[3])%mod;
		add(ans,px);
	}
	F(i,y[3]+1,y[4]){
		px=-gt(x[3]-1,i);
		px=1LL*px*gt2(x[3],i)%mod;
		px=1LL*px*(x[3]+i)%mod;
		add(ans,px);
	}
	px=-gt(x[3],y[3]);
	px=1LL*px*gt2(x[3],y[3])%mod;
	px=1LL*px*(x[3]+y[3])%mod;
	add(ans,px);
	F(i,x[3],x[4]-1){
		px=gt(i,y[4]);
		px=1LL*px*gt2(i,y[4]+1)%mod;
		px=1LL*px*(i+y[4]+1)%mod;
		add(ans,px);
	}
	F(i,y[3],y[4]-1){
		px=gt(x[4],i);
		px=1LL*px*gt2(x[4]+1,i)%mod;
		px=1LL*px*(x[4]+1+i)%mod;
		add(ans,px);
	}
	px=gt(x[4],y[4]);
	px=1LL*px*gt2(x[4],y[4])%mod;
	px=1LL*px*(x[4]+y[4]+1)%mod;
	add(ans,px);
	wrn(ans);
	return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
#ifdef PRAGMA
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#define fst first
#define snd second
#define fore(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define bs binary_search
#define mm(a,b) memset(a,b,sizeof(a))
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int) (n).size())
#define MAXI ((ll)1e16)
#define MINI ((ll)-1e16)
#define EPS 1e-9
using namespace std;
typedef long long ll; 
typedef long double ld;
const long long M = 1e9+7; 
const long long INF = 1e9;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b,a%b); } 
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
string s;
int main(){FIN;
	cin >> s;
	ll b = 0;
	ll r = 0;
	ll n = SZ(s);
	fore(i,0,n){
		if(s[i]=='B')b++;
		else r+=b;
	}
	cout << r;
	
}

Measured memory_bytes: 720
#include<stdio.h>
#define MAX 100000

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1){ printf("parent key = %d, ",A[parent(i)]); }
    if(left(i)<=H){ printf("left key = %d, ",A[left(i)]); }
    if(right(i)<=H){printf("right key = %d, ",A[right(i)]); }
    printf("\n");
  }
  return 0;
}



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

int main()
{ 
    ios_base::sync_with_stdio(0); 
    cin.tie(NULL);
    ll x,k,d; 
    cin>>x>>k>>d; 
    x=abs(x);  
    ll min=x/d; 
    if(k<=min) 
      x-=k*d,cout<<abs(x)<<"\n"; 
    else{  
      k-=min; 
      x-=min*d; 
      if(k&1)cout<<abs(x-d)<<"\n"; 
      else cout<<abs(x)<<"\n";
    } 
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    vector<int> v,oddv;
    for(ll i=1;;i++){
        if(i*(i+1)*(i+2)/6<=2000000){
            v.pb(i*(i+1)*(i+2)/6);
        }
        else break;
    }
    int ans1[1000010],ans2[1000010];
    rep(i,0,1000010) ans1[i]=ans2[i]=INF;
    ans1[0]=0; ans2[0]=0;
    rep(i,0,1000000){
        ans1[i]=i; ans2[i]=i;
        for(int j=0;i>=v[j];j++){
            ans1[i]=min(ans1[i-v[j]]+1,ans1[i]);
            if(v[j]%2==1)ans2[i]=min(ans2[i],ans2[i-v[j]]+1);
        }
    }

    int n;
    while(cin>>n&&n){
        cout<<ans1[n]<<" "<<ans2[n]<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 10900
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  string s;
  cin>>s;
  int x=0,y=0,z=0;
  for(int i=0;i<=2;i++){
    if(s[i]=='a')x++;
    else if(s[i]=='b')y++;
    else if(s[i]=='c')z++;
  }
  (x==1&&y==1&&z==1)?cout<<"Yes":cout<<"No";
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    int s = (a + b) * h / 2;
    System.out.println(s);
  }
}

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

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

    if(str[0] == 'A'){
        str[0] = 'a';
    }
    else{
        cout << "WA" << endl;
        return 0;
    }

    bool flag = false;
    for(int i = 2; i <= str.size() - 2; i++){
        if(str[i] == 'C'){
            if(flag){
                cout << "WA" << endl;
                return 0;
            }
            str[i] = 'c';
            flag = true;
        }
    }
    if(!flag){
        cout << "WA" << endl;
        return 0;
    }

    for(int i = 0; i < str.size(); i++){
        if('A' <= str[i] && str[i] <= 'Z'){
            cout << "WA" << endl;
            return 0;
        }
    }

    cout << "AC" << endl;

    return 0;
}

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

using namespace std;
typedef vector<int> VI;

int n;
bool illumination[100001];
VI v_illumination;
int main()
{
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> illumination[i];
  illumination[n] = illumination[n - 1];

  int sum = 1;
  for(int i = 1; i <= n; i++){
    if(illumination[i - 1] != illumination[i])
      sum++;
    else{
      v_illumination.PB(sum);
      sum = 1;
    }
  }

  if(v_illumination.size() <= 3)
    cout << n << endl;
  else{
    int part = 0;
    for(int i = 0; i <= 2; i++)
      part += v_illumination[i];
    int ans = part;
    for(int i = 3; i < v_illumination.size(); i++){
      part += - v_illumination[i - 3] + v_illumination[i];
      ans = max(ans, part);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
int main(){
int b;
cin>>b;int flag=1;
for(int i=1;i<=9;i++)
{//cout<<"hi"<<endl;
    if((b/i)/10==0 && b%i==0)
    {cout<<"Yes"<<endl;flag=0;break;}
}
if(flag==1)
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	c := make([][]int, 3)
	for i := 0; i < 3; i++ {
		c[i] = make([]int, 3)
	}

	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&c[i][j])
		}
	}

	for i := 0; i <= 100; i++ {
		for j := 0; j <= 100; j++ {
			for k := 0; k <= 100; k++ {
				if c[0][0]-i == c[1][0]-j && c[1][0]-j == c[2][0]-k &&
					c[0][1]-i == c[1][1]-j && c[1][1]-j == c[2][1]-k &&
					c[0][2]-i == c[1][2]-j && c[1][2]-j == c[2][2]-k {
					fmt.Println("Yes")
					return
				}
			}
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 512