akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

signed main(){
    int m;
    cin >> n >> m;
    vec(a,n);
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }
    UnionFind uf(n);
    REP(i,m){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x,y);
    }
    int ans = 0;
    REP(i,n){
        if(uf.same(a[i],i)){
            ans++;
        }
    }
    print(ans);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
bool is_prime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
  int n; cin >> n;
  vector<int> prime;
  
  for(int i = 0; i <= 55555; i++){
    if(i%5 == 1){
      if(is_prime(i)) prime.push_back(i);
    }
  }
  
  rep(i,n+1){
    if(i != n) cout << prime[i] << " ";
    else cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S, C = "CODEFESTIVAL2016";
    cin >> S;
    
    int ans = 0;
    for(int i=0;i<16;i++){
        if(S[i] != C[i])
            ans++;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	cout << 1LL*N*(N-1)/2 << "\n";

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
        public static void main(String[] arg) throws IOException {
                BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                String is;
                String[] ia;

                while(true){
                        ia = in.readLine().split("[ \t]");
                        int s = Integer.parseInt(ia[0]);
                        int d = Integer.parseInt(ia[1]);
                        if(s == 0 && d == 0){
                                break;
                        }
                        int[][] x = new int[s][d];
                        for(int i = 0;i < s; ++i){
                                ia = in.readLine().split("[ \t]");
                                for(int j = 0;j < d; ++j){
                                        x[i][j] = Integer.parseInt(ia[j]);
                                }
                        }
                        int[][] y = new int[d][d];
                        for(int i = 0;i < d-1; ++i){
                                ia = in.readLine().split("[ \t]");
                                for(int j = 0;j < d-i-1; ++j){
                                        y[i][i+j+1] = y[i+j+1][i] = Integer.parseInt(ia[j]);
                                }
                        }
                        boolean[] a = new boolean[d];
                        Arrays.fill(a,true);
                        int b = 0;
                        while(check(a)){
                                b += find_min(x,y,a);
                        }
                        System.out.println(b);
                }
        }

        static int find_min(int[][] x, int[][] y, boolean[] b){
                int next = -1;
                int c = Integer.MAX_VALUE;
                for(int i = 0;i < x.length; ++i){
                        for(int j = 0;j < x[i].length; ++j){
                                if(b[j] && 0 < x[i][j] && x[i][j] < c){
                                        c = x[i][j];
                                        next = j;
                                }
                        }
                }
                for(int i = 0;i < y.length; ++i){
                        if(!b[i]){
                                for(int j = 0;j < y[i].length; ++j){
                                        if(b[j] && 0 < y[i][j] && y[i][j] < c){
                                                c = y[i][j];
                                                next = j;
                                        }
                                }
                        }
                }
                b[next] = false;
                return c;
        }

        static boolean check(boolean[] a){
                for(int i = 0;i < a.length; ++i){
                        if(a[i]){
                                return true;
                        }
                }
                return false;
        }
}

Measured memory_bytes: 9908
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, K: int):
    def f():
        for i in range(1, 101):
            if A % i == 0 and B % i == 0:
                yield i
    return list(f())[-K]
        

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(A, B, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> r(n);
  rep(i,n) cin >> r[i];
  int minv,maxv = 0;
  maxv = -2000000000;
  minv = r[0];
  for(int i = 1; i < n; i++) {
    maxv = max(maxv,r[i]-minv);
    minv = min(minv,r[i]);
  }
  cout << maxv << endl;
  return 0;
}


Measured memory_bytes: 3568
#include <cstdio>
#include <cctype>
#include <utility>
#include <complex>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

using P = complex<double>;

P read() {
	return P(in(), in());
}

int main() {
	P p0 {read()}, v1 {read() - p0};
	for (int q {in()}; q; q--) {
		P v2 {read() - p0}, t = conj(v1) * v2;
		outl(imag(t) > 0 ?
			 "CLOCKWISE" : imag(t) < 0 ?
			 "COUNTER_CLOCKWISE" : real(t) < 0 ?
			 "ONLINE_BACK" : abs(v1) < abs(v2) ?
			 "ONLINE_FRONT" : "ON_SEGMENT");
	}
}


Measured memory_bytes: 2624
#include <iostream>
#include <cmath> 
#include <string>
using namespace std;

int main(){
    int n;
    int t,a,h;
    double m=100000;
    int tmp;
    cin >> n >> t >> a;
    for(int i=0; i<n; i++){
        cin >> h;
        m = min(m, abs(a-(t-h*0.006)));
        if(m == abs(a-(t-h*0.006)))tmp = i;
    }
    
    cout<<tmp+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, k) for (int i = (s); i < (int)(k); i++)

int main(){
    long long l[90];
    l[0] = 2;
    l[1] = 1;
    for(int i=2;i<90;i++){
        l[i] = l[i-1] +l[i-2];
    }
    int n;
    cin >> n;
    cout << l[n] << endl;
}

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

int n,cnt[6010];
string dp[6010];
string s;
vector<int> a,b;

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	cin>>s;
	for(int i=0;i<n*2;i++){
		if(s[i]=='a'){a.push_back(i);cnt[i]=a.size()-1;}
		else{b.push_back(i);cnt[i]=b.size()-1;}
	}
	for(int i=0;i<=2*n;i++) dp[i]="";
	for(int i=n-1;i>=0;i--){
		if(a[i]<b[i]){
			int maxv=i;
			for(int j=a[i];j<=b[i];j++){
				maxv=max(maxv,cnt[j]);
			}
			dp[i]="ab"+dp[maxv+1];
		}
		else{
			int cur=i;
			while(cur+1<n&&b[cur+1]<a[cur]) cur++;
			for(int j=b[i];j<2*n;j++){
				if(cnt[j]>=i&&cnt[j]<=cur){
					dp[i]+=s[j];
				}
			}
			dp[i]+=dp[cur+1];
		}
		dp[i]=max(dp[i],dp[i+1]);
	}
	cout<<dp[0]<<endl;
	return 0;
}

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

int main() {
	int N, D;
	cin >> N >> D;
	double X[N][D];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			double dist = 0;
			for (int k = 0; k < D; k++) {
				dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}
			if (sqrt(dist) == (int)sqrt(dist)) cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


int main(void) {
    int i,j;
    int n,m,q;
    while(cin >> n >> m >> q, n){
        vs s(q),b(q);
        rep(i,q)cin >> s[i] >> b[i];

        rep(i,m){//iに対応するswitchをさがす
            int t = -1;
            rep(j,n){//s[?][j]とb[?][i]が一致しているか？
                bool c = true;
                int l = 0;
                rep(k,q){
                    l += s[k][j]-'0';
                    l %= 2;
                    if(b[k][i] - l != '0')c = false;
                }
                if(c){
                    if(t == -1)t = j;
                    else{
                        t = -1;
                        break;
                    }
                }
            }
            if(t == -1){
                cout << "?";
            }else{
                if(t<10)cout << t;
                else cout << char('A' + t - 10);
            }
        }
        cout << endl;
    }
}



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

int main(){
    string s,t; cin >> s >> t;
    int n = t.size();
    if(s == t.substr(0,n-1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int n, nr1, nr2;
string s1, s2;
int main(){
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s1 >> s2;
		if (s1 > s2) {
			nr1 += 3;
		}
		if (s2 > s1) {
			nr2 += 3;
		}
		if (s1 == s2) {
			nr1++;
			nr2++;
		}
	}
	cout << nr1 << ' ' << nr2 <<'\n';
//	system("pause");
}


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
  
  int i = 0;
  int j = 0;
  int N,v,k;

  scanf("%d",&N);

  int A[N];

  for(i = 0 ; i < N ; i++)
    scanf("%d",&A[i]);
  
  for(i = 1 ; i <= N ; i++){
    v = A[i];
    j = i-1;
    
    for(k = 0 ; k < N-1 ; k++){
      printf("%d ",A[k]);
    }
    printf("%d",A[N-1]);
    printf("\n");

    
    while( j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
  }
  return 0;
}



Measured memory_bytes: 2076
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

long r2(long[] p1, long[] p2) {
    long[] d = [p1[0]-p2[0], p1[1]-p2[1]];
    return d[0]*d[0] + d[1]*d[1];
}

long dot(long[] x1, long[] x2) {
    return x1[0] * x2[0] + x1[1] * x2[1];
}

long[] sub(long[] x1, long[] x2) {
    return [x1[0]-x2[0], x1[1]-x2[1]];
}
long[] add(long[] x1, long[] x2) {
    return [x1[0]+x2[0], x1[1]+x2[1]];
}

double d2(long[] p1, long[] p2, long[] x) {
    long[] p21 = sub(p2, p1);
    long[] p1x = sub(p1, x);
    return (dot(p21, p21)*dot(p1x,p1x) - pow(dot(p21, p1x), 2))/to!double(dot(p21,p21));
}

long cross(long[] x, long[] y) {
    return x[0]*y[1] - x[1]*y[0];
}

bool inTriangle(long[] p1, long[] p2, long[] p3, long[] x) {
    auto u = sub(p1, x);
    auto v = sub(p2, x);
    auto w = sub(p3, x);
    
    auto a = cross(u, v);
    auto b = cross(v, w);
    auto c = cross(w, u);

    return a*b > 0 && b*c > 0 && c*a > 0;
}

bool hasIntersection(long[] p1, long[] p2, long[] r0, long r) {
    auto p21 = sub(p2, p1);
    auto p1r = sub(p1, r0);
    auto f0 = dot(p1r, p1r) - r*r;
    auto f1 = dot(add(p21, p1r), add(p21, p1r)) - r*r;
    if(f0 * f1 <= 0) {
        return true;
    }
    if(f0 < 0 && f1 < 0) {
        return false;
    }
    if(dot(p21, p1r) > 0 || abs(dot(p21, p1r)) > dot(p21, p21)) {
        return false;
    }
    return -pow(dot(p21, p1r), 2) + dot(p1r, p1r)*dot(p21, p21) - r*r*dot(p21, p21) <= 0;
}

string test(long[] p1, long[] p2, long[] p3, long[] p4, long r) {
    if(inTriangle(p1, p2, p3, p4) && min(d2(p1, p2, p4), d2(p2, p3, p4), d2(p3, p1, p4)) >= r*r) {
        return "a";
    }
    if(r2(p1, p4) <= r*r && r2(p2,p4) <= r*r && r2(p3,p4) <= r*r) {
        return "b";
    }
    if(hasIntersection(p1, p2, p4, r) || hasIntersection(p2, p3 ,p4, r) || hasIntersection(p3, p1, p4, r)) {
        return "c";
    }
    return "d";
}

void main(){
    while(true) {
        auto xy1 = readLongs();
        if(xy1[0] == 0 && xy1[1] == 0) {
            return;
        }
        auto xy2 = readLongs();
        auto xy3 = readLongs();
        auto xy4 = readLongs();
        auto r = readLong();
        writeln(test(xy1, xy2, xy3, xy4, r));
    }
}

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

int main() {
  int D,G,i,j,x=0,q=1000;
  cin >> D >> G;
  int nq=D;
  vector<int> p(D),c(D);

  for(i=0; i<D; i++)
    cin >> p.at(i) >> c.at(i);
  
  for(i=0; i<pow(2,D); i++) {
    bitset<10> pt(i);
    int tq=0, ts=0;
    string s=pt.to_string();
    for(j=9-D+1; j<10; j++) {
      int id=j-10+D;
      if(s.at(j)=='1') {
        tq+=p.at(id);
        ts+=p.at(id)*100*(id+1)+c.at(id);
      }
      if(ts>G)
        break;
    }
    
    if(j==10) {
      if(G>ts) {
        j=9;
        while(s.at(j)!='0') {
          j--;
          if(j<10-D)
            break;
        }
        if(j>=10-D) {
          int qq=p.at(j-10+D);
          while(G>ts) {
            ts+=100*(j-9+D);
            tq++;
            qq--;
            if(qq<1)
              break;
          }
        }
      }
    }
    if(ts>=G && tq<q)
      q=tq;
  }
  cout << q << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;

#define EPSILON 1.0e-12

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
};
//降順
bool compare_by_b_high(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }
};
bool compare_by_b_higheer(tuple<string, int, int> a, tuple<string, int, int> b) {
    if(get<0>(a) != get<0>(b)){
      return get<0>(a) <get<0>(b);
    }else{
        if(get<1>(a) != get<1>(b)){return get<1>(a) > get<1>(b);}
        else{return get<2>(a) > get<2>(b);}
    }
};


int main(){
  int n;cin>>n;
  VI b(n-1);
  REP(i,n-1){
    cin>>b[i];
  }
  VI a(n,0);
  a[n-1]=b[n-2];
  a[0]=b[0];
  for(int i=n-2;i>=1;i--){
    if(b[i]<b[i-1]){a[i]=b[i];}
    else{a[i]=b[i-1];}
  }
  ll sum=0;
  REP(i,n){
    sum+=a[i];
  }
  cout<<sum<<endl;

}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = 0
"""
一番大きい偶数を2で割る
それ以外は3倍
を繰り返す
奇数だけになったら終了
↓
各項が2で何回われるか の合計
"""
for i in range(n):
    cnt = 0
    tmp = a[i]
    while True:
        if tmp % 2 == 0:
            tmp = tmp // 2
            cnt += 1
        else:
            break
    ans += cnt
print(ans)

Measured memory_bytes: 42096
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(b == 0) {
        return 0;
    }
    return (a+b-1)/b;
}

int main() {
    ll n;
    cin >> n;
    out(ceil(n, 2));
    re0;
}

Measured memory_bytes: 256
#include <set>
#include <cstdio>
#include <vector>
 
using namespace std;
typedef long long ll;
ll a[5],ans,i;
inline ll gcd(ll a,ll b)
{
	if(!b) return a;
	return gcd(b,a % b);
}
inline ll get(ll l,ll r,ll b)
{
	ll delta = 0;
	if(l % b == 0) delta++;
	return (r / b - l / b + delta); 
}
int main()
{
    for(i = 1;i <= 4;i++)
    	scanf("%lld",&a[i]);
	ll GCD = gcd(a[3],a[4]);
	ll lcm = a[3] * a[4] / GCD;
	ans = a[2] - a[1] + 1 - get(a[1],a[2],a[3]) - get(a[1],a[2],a[4]) + get(a[1],a[2],lcm);
	printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n,d = readline() |> split |> parseMap
	k = 0
	for i in 1:n
		x,y = readline() |> split |> parseMap
		if x^2+y^2<=d^2
			k += 1
		end
	end
	println(k)
end

main()

Measured memory_bytes: 202936
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int a, b;
  cin >> a >> b;
  
  int cnt = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    string t = s;
    reverse(all(s));
    if (s == t)
      cnt++;
  }
  cout << cnt << endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    double ans=0;
    vector<double> v(N);
    vector<double> pow2(N);
    for(int64 i=0;i<N;i++){
        cin>>v[i];
        i==0?pow2[i]=2:pow2[i]=pow2[i-1]*2;
    } 
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    for(int64 i=0;i<N;i++){
        if(i!=N-1){
            ans+=v[i]/pow2[i];
        }else{
            ans+=v[i]/pow2[i-1];
        }
        
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll K;
  cin >> K;
  ll a = 7;
  vector<ll> memo(K);
  rep(i,K){
    a = a % K;
    if(a == 0){
      cout << i + 1 << endl;
      return 0;
    }
    if(memo.at(a) == 0){
      memo.at(a) ++;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
    a = a * 10 + 7;
  }
}

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

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

Measured memory_bytes: 256
using System.Text;
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        var b = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine().Trim());
            b[i] = a[i];
        }
        Array.Sort(a);
        var bmax = a[n - 1]; var bmax2 = a[n - 2];
        var bmaxs = bmax.ToString() + "\n";
        var bmax2s = bmax2.ToString() + "\n";
        var sb = new StringBuilder();
        for (int i = 0; i < n; i++)
            sb.Append(b[i] == bmax ? bmax2s : bmaxs);
        Console.WriteLine(sb);
    }
}


Measured memory_bytes: 24156
n,m,k = (int(x) for x in input().split())
y = 0
a = [0]
for x in input().split():
    y += int(x)
    a.append(y)
y = 0
b = [0]
for x in input().split():
    y += int(x)
    b.append(y)
    
ans = 0
j = m
for i in range(n+1):
    if a[i]>k:
        break
    while j >= 0:
        if a[i]+b[j]<=k:
            ans = max(ans,i+j)
            break
        j -= 1
print(ans)

Measured memory_bytes: 45988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	string s[7]{"SUN","MON","TUE","WED","THU","FRI","SAT"},t;
	cin>>t;
	for(int i=0;i<7;i++)
	{
		if(s[i]==t)cout<<7-i<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[100];
    for(int i=0;i<N;i++)
        cin >> a[i];
    //-100~100に書き換える場合を全て試す
    int cost = 0, min_cost = 2147483647; //仮の最小コスト
    for(int i=-100;i<=100;i++){
        for(int j=0;j<N;j++){
            cost += (a[j] - i)*(a[j] - i);
        }
        if(cost < min_cost)
            min_cost = cost;
        cost = 0;
    }
    cout << min_cost << endl;
    return 0;
}

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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int a, b, N;
    cin >> a >> b >> N;
    vector<int> use(1010, 0);
    for(int i = 0; i < N; i++){
        int s, f;
        cin >> s >> f;
        for(int j = s; j < f; j++){
            use[j]++;
        }
    }
    for(int i = a; i < b; i++){
        if(use[i]){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}




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

int main(){
	int H, A, B, count = 0;
	
	cin>>H>>A>>B;
	
	for(int i = A; i <= B; i++){
		if(H%i == 0)count++;
	}
	
	cout<<count<<endl;
	
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vecctor<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

constexpr ll mod = 1e9+7;

int main(){
    string L;
    cin >> L;
    ll N = L.size();
    VVL dp(N+10, VL(2, -1));
    dp[1][0] = 2; dp[1][1] = 1;
    rep(d, 1, N){
        // smaller -> smaller
        dp[d+1][1] = 3*dp[d][1];
        dp[d+1][1] %= mod;
        // exact -> smaller (L_i = 1 and a_i = 0 and b_i = 0)
        if(L[d] == '1'){
            dp[d+1][1] += dp[d][0];
            dp[d+1][1] %= mod;
        }
        // exact -> exact L_i = a_i XOR b_i
        if(L[d] == '1'){
            dp[d+1][0] = 2*dp[d][0];
        }else{
            dp[d+1][0] = dp[d][0];
        }
        dp[d+1][0]  %= mod;
    }
    cout << (dp[N][0] + dp[N][1]) % mod << endl;
    return 0;
}

Measured memory_bytes: 5760
package main

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

func main() {
	sc := newScanner(os.Stdin)
	N, K := sc.i(), sc.i()
	moves := make([]int, N)
	for i := 0; i < N; i++ {
		moves[i] = sc.i()
	}
	graph := make([]int, N)
	//graph[0] = 0
	arrived := make([]int, N)
	for i := 0; i < N; i++ {
		arrived[i] = -1
	}
	loopStart := 0
	loopEnd := N + 1
	for i := 0; i < N; i++ {
		arrived[graph[i]] = i
		next := moves[graph[i]] - 1
		ok := arrived[next]
		if ok != -1 {
			loopStart = ok
			loopEnd = i + 1
			break
		}
		graph[i+1] = next
	}
	loop := loopEnd - loopStart
	goalIndex := K
	if loopStart < K {
		goalIndex = (K-loopStart)%loop + loopStart
	} 
	
	goal := graph[goalIndex] + 1
	fmt.Println(goal)

}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

func Pow(x, y int) int {
	fx := float64(x)
	fy := float64(y)
	z := math.Pow(fx, fy)
	return int(z)
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 8020
#include<bits/stdc++.h>
#define endl '\n'
#define mod (int)(1e9+7)
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;
int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
int ncr(int n, int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}
int fibonacci(int n){
    double phi = (1 + sqrt(5))/(double)2;
    int nth_fib = round(pow(phi,n)/sqrt(5));
    return nth_fib;
}
int modularExponentiation(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
int modInverse(int A,int M)
{
    return modularExponentiation(A,M-2,M);
}

int lcm_matrices[1000007];
void solve(int n){
    int num = 2;
//    cout << "1--n = " << n << endl;
    while(num*num <= n){
       if(n%num == 0) {
           int cnt = 1;
           while ((n /= num) % num == 0) ++cnt;
//        cout << "1-n = " << n << " num = " << num << endl;
           lcm_matrices[num] = max(lcm_matrices[num], cnt);
       }
        num++;
    }
    if(n > 1) lcm_matrices[n] = max(lcm_matrices[n], 1LL);
}
signed main(){

#ifndef ONLINE_JUDGE
   // freopen("input.txt","r", stdin);
#endif
    fastIO

    int n;
    cin >> n;
//    cout << "here\n";
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0;i < 1000000; i++){
        lcm_matrices[i] = 0;
    }
//    cout << "after initialize\n";
    for(int i = 0 ; i < n; i++){
//        cout << " i = " << i << endl;
        solve(a[i]);
    }
//    cout << "after solve\n";
    int mul = 1;
    for(int i = 0; i <= 1000000; i++){
        mul = ((((mul)%mod)*(modularExponentiation(i,lcm_matrices[i],mod))%mod))%mod;
    }
   // cout << "mul = " << mul << endl;
//    cout << "lcm = " << (lcm(lcm(1000000,999999),999998))%mod << endl;;
    int ans = 0;
    for(int i = 0; i < n ; i++){
        ans =((ans)%mod + (((mul)%mod)*(modInverse(a[i],mod)%mod))%mod)%mod;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 8192
x, y = map(int, input().split())

diff_abs = abs(abs(x) - abs(y))

ans = diff_abs
if x * y > 0:
  if x > y:
    ans += 2
elif x * y == 0:
  if x > y:
    ans += 1
else:
  ans += 1

print(ans)

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

#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(var,start,end) for(int var=start; var<end; var++)
#define repr(var,start,end) for(int var=start; var>=end; var--)
#define repi(var,start,end) for(int var=start; var<=end; var++)
#define debg(var) cerr<<#var<<" : "<<var<<" "
#define pb push_back
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

void solve() {
    int X;
    cin>>X;
    if(X>=30)
        cout<<"Yes";
    else
        cout<<"No";
}

int main() {
    fastio
   
    int t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(m,1);

	rep(i,0,n){
		int k;
		cin >> k;
		vector<int> b(m,0);

		rep(j,0,k){
			int num;
			cin >> num;
			b[num-1] = 1;
		}

		rep(j,0,m) a[j] *= b[j];
	}
	int ans = 0;
	rep(i,0,m) if(a[i]) ans++;
	cout << ans << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, Q; cin >> N >> Q;
  string S; cin >> S;

  int num[N] = {};
  for (int i=1; i<N; i++) {
    num[i] = num[i-1];
    if (S[i-1]=='A'&&S[i]=='C') num[i]++;
  }

  rep(i, Q) {
    int l, r; cin >> l >> r; l--; r--;
    int result = num[r]-num[l];
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
import sys

n = int(sys.stdin.readline())
h = list(map(int, sys.stdin.readline().split()))

ans = 'Yes'
h[0] -= 1
for i in range(n - 1):
    if h[i + 1] < h[i]:
        ans = 'No'
        break
    elif h[i + 1] > h[i]:
        h[i + 1] -= 1
print(ans)


Measured memory_bytes: 14252
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    ans += min(a, k);
    k -= ans;
    k -= min(b, k);
    ans -= min(c, k);
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;
  cin>>N;
  vector<int> R,G,B;
  for (int i = 0; i < N; i++)
  {
    char X; cin>>X;
    if(X == 'R') R.push_back(i+1);
    if(X == 'G') G.push_back(i+1);
    if(X == 'B') B.push_back(i+1);
  }
  int ANS = R.size()*G.size()*B.size();
  for (int i = 0; i < R.size(); i++)
  {
    for (int j = 0; j < G.size(); j++)
    {
      int xR = R[i];
      int xG = G[j];
      if((find(ALL(B),(xR+xG)/2) != B.end())&&(xR+xG)%2 == 0)
      {
        ANS--;
      }
      if((find(ALL(B),max(xR,xG) + abs(xR - xG)) != B.end()))ANS--;
      if((find(ALL(B),min(xR,xG) - abs(xR - xG)) != B.end()))ANS--;
    }
    
  }
  cout<<ANS<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	bool f = false;
	for (int i = 0; i < 300; i++) {
		if ((a*i) % b == c)f = true;
	}
	cout << (f == true ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define endl "\n"
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define ss second
#define ff first
#define vpii vector<pii>
#define vvi vector<vi >
#define vs vector<string>
#define all(x) x.begin(),x.end()
#define mii map<int,int>
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
#define M 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int arr[n][3],dp[n][3];
        rep(i,n)
        {
            cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
        }
        dp[0][0]=arr[0][0],dp[0][1]=arr[0][1],dp[0][2]=arr[0][2];
        rep1(i,n-1)
        {
            dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
            dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
            dp[i][2]=max(dp[i-1][1],dp[i-1][0])+arr[i][2];
        }
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    }
}


Measured memory_bytes: 2560
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#define Long long long int
#define For(i,a,b) for(Long i=a;i<=b;i++)
#define ForR(i,a,b) for(Long i=a;i>=b;i--)
#define maxSNT 1000002
#define vc 1000000
using namespace std;

int Min[100],sl[100];
main(){
	int n;
	string s;
	cin >> 	n;
	For(i,0,'z'-'a'){
		Min[i] = vc;
	}
	For(i,1,n){
		For(i,0,'z'-'a'){
			sl[i] = 0;
		}
		cin >> s;
		For(i,0,s.length()-1){
			sl[s[i]-'a']++;
		}
		For(i,0,'z'-'a'){
			Min[i] = min(Min[i],sl[i]);
		}
	}
	For(i,0,'z'-'a'){
		For(j,1,Min[i]){
			printf("%c",i+'a');
		}		
	}
	printf("\n");
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll=long long;
const int Nmax=110;
const int Wmax=100010;
int N,W; 
ll dp[Nmax][Wmax];
ll v[Nmax];
ll w[Nmax];
const ll INF=1LL<<60;


int main(){
  cin >> N >> W;
  for (int i=1;i<=N;i++)
      cin >> w[i] >> v[i];
  
  for (int j=0;j<=W;j++){
    for (int i=0;i<N;i++){
      if (j+w[i+1]<=W) chmax(dp[i+1][j+w[i+1]],dp[i][j]+v[i+1]);
      chmax(dp[i+1][j],dp[i][j]);
    }
  }
  
  cout << dp[N][W] << endl;
  
}

Measured memory_bytes: 79360
//2018年  3月 21日 水曜日 17:17:06 JST - 17:28:41
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, MA, MB;
int A[41], B[41], C[41];
ll dp[2][410][410];

void solve() {
	cin >> N >> MA >> MB;
	rep(i, 0, N) {
		cin >> A[i] >> B[i] >> C[i];
	}
	rep(i, 0, 401) {
		rep(j, 0, 401) {
			dp[0][i][j] = inf;
		}
	}
	dp[0][0][0] = 0;
	int now = 0, nex = 1;
	rep(i, 0, N) {
		rep(j, 0, 401) {
			rep(k, 0, 401) {
				dp[nex][j][k] = inf;
			}
		}
		rep(j, 0, 401) {
			rep(k, 0, 401) {
				if(dp[now][j][k] == inf) continue;
				MIN(dp[nex][j + A[i]][k + B[i]], dp[now][j][k] + C[i]);
				MIN(dp[nex][j][k], dp[now][j][k]);
			}
		}
		swap(now, nex);
	}
	ll ans = inf;
	// rep(i, 0, 15) {
	// 	rep(j, 0, 15) {
	// 		debug(i, j, dp[now][i][j]);
	// 	}
	// }
	rep(i, 1, 401) {
		int ma = MA * i, mb = MB * i;
		if(ma > 400 || mb > 400) break;
		MIN(ans, dp[now][ma][mb]);

	}
	if(ans == inf) {
		cout << "-1\n";
	}
	else cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 2816
def celling(A, B):
    return (A + B - 1) // B

N, K = map(int,input().split())

ans = 0
flipnum = 0
facepossibility = 1

targetMax = N
targetMin = K
if K > 1:
    while targetMax > 0:
        targetMin = celling(K, 2**flipnum)
        if targetMin > targetMax:
            flipnum += 1
            continue
        ans += (targetMax - targetMin + 1) / (N * 2 ** flipnum)
        targetMax = targetMin - 1
        flipnum += 1
    print(ans)
else:
    print("1")


Measured memory_bytes: 3060