akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc126/tasks/abc126_e
import itertools
from collections import Counter
from collections import defaultdict
import bisect


# Union find
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _ in range(size)]  # 負の値の場合根を表す。正の値は次の要素を返す、根まで続く

    #集合の代表を求める
    def find(self,x):
        while self.table[x] >= 0:
            #根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            x = self.table[x]
        return x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def rewrite(self,x, p):
        while self.table[x] >= 0:
            #根に来た時,self.table[根のindex]は負の値なのでx = 根のindexで値が返される。
            tmp = x
            x = self.table[x]
            self.table[tmp] = p
        return

    #併合
    def union(self,x,y):
        s1 = self.find(x)#根のindex,table[s1]がグラフの高さ
        s2 = self.find(y)
        if s1 != s2:#根が異なる場合
            if self.table[s1] != self.table[s2]:#グラフの高さが異なる場合
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                    self.rewrite(y, s1)
                else:
                    self.table[s1] = s2
                    self.rewrite(x, s2)
            else:
                #グラフの長さが同じ場合,どちらを根にしても変わらない
                self.table[s2] = s1
                self.rewrite(y, s1)
        return

    def num_group(self):
        # print(self.table)
        return self.table.count(-1)


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)

    for _ in range(M):
        x, y, z = map(int, input().split())
        uf.union(x - 1, y - 1)
    print(uf.num_group())

if __name__ == '__main__':
    main()


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

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

    int abcd = 0;
    for(int i=0; i<4; i++){
        abcd += s[i] - '0';
    }

    vector<char> pm = {'+', '-'};
    for(int bit=0; bit<(1<<3); bit++){// 000, ..., 111
        int test = abcd;
        vector<int> sign(3);
        for(int i=0; i<3; i++){
            if(bit & (1<<i)){
                test -= 2 * (s[i+1] - '0');
                sign[i] += 1;
            }
        }
        //cout << test << " ";
        if(test == 7){
            for(int i=0; i<3; i++){
                cout << s[i] << pm[sign[i]];
            }
            cout << s[3] << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

int main() {
	int N;
	string ans = "APPROVED";
	cin >> N;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
		if (!(t%2)) {
			if (t%3 && t%5) {
				ans = "DENIED";
			}
		}
	}
	cout << ans << endl;
}


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

int main() {
  int N, M, temp, sum = 0;

  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    cin >> temp;
    sum += temp;
  }

  if (N >= sum) {
    cout << N - sum << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
#define FILENAME(x) \
freopen(x".in","r",stdin); \
freopen(x".out","w",stdout);
#define MAXIOLG 25
#define LOWBIT(x) ((x)&(-(x)))
#define MOD 998244353
#define MD(x) (((x)>=MOD)?((x)-=MOD):(0))
#define OPS "?+<?"
#define N 299
#define MXLG 60
using namespace std;

typedef long long ll;
typedef ll io_t;

io_t shin[MAXIOLG];
io_t seto(void);
void ayano(io_t x,char spliter='\n');

struct Ene{
    int op,x,y,z;
    Ene(void):op(0),x(0),y(0),z(0){}
    Ene(int tp,int tx,int ty,int tz):op(tp),x(tx),y(ty),z(tz){}
    Ene(const Ene& tc):op(tc.op),x(tc.x),y(tc.y),z(tc.z){}
};

vector<Ene> vec;

void make_pw(void);
void to_bin(int x,int l,int k);
void to_dec(int x,int l,int k);
void mult(int l1,int l2,int l3,int k);
void lmv(int x,int k);
void land(int x,int y,int z);

int main(void){
    make_pw();
    to_bin(0,30,30);
    to_bin(1,70,30);
    mult(30,70,110,30);
    to_dec(2,110,60);
    //vec.push_back(Ene());
    ayano(vec.size());
    for (auto v:vec){
        putchar(OPS[v.op]),putchar(' '),
        ayano(v.x,' '),ayano(v.y,' '),ayano(v.z);
    }
    return 0;
}

void mult(int l1,int l2,int l3,int k){
    for (int i=0;i<=k;i++){
        for (int j=0;j<=k;j++){
            int res=i+j;
            land(l1+i,l2+j,14);
            vec.push_back(Ene(1,14,l3+res,l3+res));
        }
    }
}
void to_dec(int x,int l,int k){
    for (int i=0;i<=k;i++){
        vec.push_back(Ene(1,3,l+i,15)); //arr[15]=0+arr[l+i];
        lmv(15,i);
        vec.push_back(Ene(1,x,15,x)); //arr[x]=arr[x]+arr[15];
    }
}
void to_bin(int x,int l,int k){
    vec.push_back(Ene(1,x,N,13)); //arr[13]=1+arr[x];
    vec.push_back(Ene(1,3,3,11)); //arr[11]=0+0;
    //Position 11 saves the certain sum
    //Position 12 is used to try
    //Position 13 saves arr[x]+1
    for (int tlg=k;tlg>=0;tlg--){
        vec.push_back(Ene(1,N-tlg,11,12)); //arr[12]=arr[11]+(1<<k);
        vec.push_back(Ene(2,12,13,12)); //arr[12]=(arr[12]<arr[13]);
        vec.push_back(Ene(1,12,3,l+tlg)); //arr[l+tlg]=arr[12]+0;
        lmv(12,tlg);
        vec.push_back(Ene(1,11,12,11)); //arr[11]=arr[11]+arr[12];
    }
}
void make_pw(void){
    vec.push_back(Ene(1,0,1,N));
    vec.push_back(Ene(2,3,N,N));
    for (int i=1;i<=MXLG;i++)
        vec.push_back(Ene(1,N-i+1,N-i+1,N-i));
}
void lmv(int x,int k){
    while (k--)
        vec.push_back(Ene(1,x,x,x));
}
void land(int x,int y,int z){
    vec.push_back(Ene(1,x,y,4)); //arr[4]=arr[x]+arr[y];
    vec.push_back(Ene(2,N,4,z)); //arr[z]=(1<arr[4]);
}

io_t seto(void){
    io_t x=0;
    char ch=getchar();
    int symbol=0;
    while (!isdigit(ch))
        (ch=='-')?(symbol=1):(0),
        ch=getchar();
    while (isdigit(ch))
        x=(x*10)+(ch-'0'),
        ch=getchar();
    return (symbol)?(-x):(x);
}
void ayano(io_t x,char spliter){
    if (!x){
        putchar('0'),putchar(spliter);
        return;
    }
    if (x<0)
        putchar('-'),x=-x;
    int ren=0;
    while (x){
        io_t d=x/10;
        shin[ren++]=x-d*10;
        x=d;
    }
    while (ren--)
        putchar(shin[ren]+'0');
    putchar(spliter);
}


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


int main(){
    string s,t;
    cin >> s;
    t = s;
    reverse(t.begin(),t.end());
    int a = t.size();
    int c = 0;
    rep(i,a){
        if(s[i] != t[i])c++;
    }
    c /= 2;
    cout << c << endl;
}

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

uint64_t scalc(int length, string S, bool *ps)
{
	uint64_t result = 0;
	uint64_t buf = S[0] - '0';
	for(int l=1; l<length; l++){
		if(ps[l-1]){
			result += buf;
			buf = S[l] - '0';
		} else {
			buf = buf * 10 + (S[l] - '0');
		}
	}
	return result + buf;
}

uint64_t ssearch(int length, int cur, string S, bool *ps)
{
	if(cur == length-1){
		return scalc(length, S, ps);
	} else {
		ps[cur] = false;
		uint64_t fr = ssearch(length, cur+1, S, ps);
		ps[cur] = true;
		uint64_t tr = ssearch(length, cur+1, S, ps);
		return tr + fr;
	}
}

uint64_t ssolve(string S)
{
	int length = S.length();
	bool *ps = new bool[length];
	return ssearch(length, 0, S, ps);
}

int main()
{
	string S;
	cin >> S;
	cout << ssolve(S) << endl;

	return 0;
}


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

int main() {
#ifdef PAUNSVOKNO
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20);
    int n;
    ll a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    n--;
    b = abs(b - a);
    for (int i = 0; i <= n; i++) {
        int j = n - i;
        if (c * i - d * j <= b && d * i - c * j >= b) {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let r: usize = sc.read();
    let d: usize = sc.read();
    let mut x: usize = sc.read();
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
//新幹線からAC

#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#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 RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n,0);
        inv = vector<int>(n,0);
        fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
	int n; cin >> n;
	int a[n]; REP (i, n) cin >> a[i];

	int last[n+1][20]; REP (i, n) REP (j, 20) last[i][j] = -1;
	int ans = 0;
	REP (i, n) {
		int tmp = INF;
		REP (j, 20) {
			last[i+1][j] = last[i][j];
			if (a[i]>>j & 1) {
				chmin(tmp, i - last[i][j]);
				last[i+1][j] = i;
			} else {
				if (last[i][j] != -1) {
					chmin(tmp, i - last[last[i][j]][j]);
				} else {
					chmin(tmp, i - last[i][j]);
				}
			}
		}
		ans += tmp;
	}

	cout << ans << endl;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();    
}


Measured memory_bytes: 33024
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
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 keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    if (n > 999) cout << "ABD" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector< ii > vii;
typedef long long LL;
int main()
{
	int n; scanf("%d", &n);
	int a = 0, b = 0, c = 0;
	for(int i = 0; i< n; i++)
	{
		int x; scanf("%d", &x);
		if(x%4 == 0) a++;
		else if(x%2 == 0) b++;
		else c++;
	}
	bool ok = 1;
	if(c> a+1) ok = 0;
	if(a == 0 && c) ok = 0;
	if(a == 0 && b == 1) ok = 0;
	if(c == a+1 && b) ok = 0;
	if(ok) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
S = input()
X,Y = map(int,input().split())
st = S.split('T')

X -= len(st[0])

xds = []
yds = []
for i,s in enumerate(st[1:]):
    if i%2:
        xds.append(len(s))
    else:
        yds.append(len(s))

def ok(to, ds):
    dp = set([0])
    for d in ds:
        tmp = []
        for v in dp:
            tmp.append(v+d)
            tmp.append(v-d)
        dp = set(tmp)
    return to in dp

print('Yes' if ok(X,xds) and ok(Y,yds) else 'No')

Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <climits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;
static const int INF = INT_MAX;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

static const int N = 2010;
int M[N][N];
int color[N];
int d[N];
int p[N];
int n;

void prim() {
  rep(u, n) {
    color[u] = WHITE;
    d[u] = INF;
  }
  d[0] = 0;
  p[0] = -1;

  while (true) {
    int mincost = INF;
    int u;
    rep(i, n) {
      if (color[i] != BLACK && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }

    if (mincost == INF) break;

    color[u] = BLACK;

    rep(v, n) {
      if (color[v] == BLACK || M[u][v] == INF) continue;
      if (M[u][v] < d[v]) {
        d[v] = M[u][v];
        p[v] = u;
        color[v] = GRAY;
      }
    }
  }
}

int main() {
  cin >> n;
  rep(y, n) rep(x, n) {
    int a;
    cin >> a;
    if (a != -1) M[y][x] = a;
    else M[y][x] = INF;
  }
  prim();
  cout << accumulate(d, d + n, 0) << endl;
  return 0;
}



Measured memory_bytes: 3480
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int e = 2*1e5 + 69;

ll cntr[e];
ll cntg[e];
ll cntb[e];

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    s =' ' + s;
    for(ll i=1; i<=n; i++)
    {
        cntr[i] = cntr[i-1];
        cntg[i] = cntg[i-1];
        cntb[i] = cntb[i-1];
        if(s[i] == 'R') cntr[i]++;
        else if(s[i] == 'G') cntg[i] ++ ;
        else cntb[i] ++;
    }
    ll ans = 0;
    for(ll i=1; i<n-1; i++)
    {
        for(ll j=i+1; j<n; j++)
        {
            bool r = false;
            bool g = false;
            bool b = false;
            if(s[i] == 'R')
                r = true;
            else if(s[i] == 'G')
                g = true;
            else
                b = true;
            if(s[j] != s[i])
            {
                if(s[j] == 'R') r = true;
                else if(s[j] == 'G') g = true;
                else b = true;
                ll cur = j - i;
                bool chk = true;
                if(s[j+cur] != s[j] && s[j+cur] != s[i] && j + cur <=n) chk = false;
                if(r == false) ans += max(0LL, cntr[n] - cntr[j] - (chk == false));
                else if(g == false) ans +=max(0LL, cntg[n] - cntg[j] - (chk == false));
                else ans += max(0LL, cntb[n] - cntb[j] - (chk == false));
            }
        }
    }
    cout << max(ans, 0LL);
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S,T[3];
int cnt[256];
int P[202020];
int cnt2[256];

int L[202020],R[202020];
vector<int> pos[256];
ll ret;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	V add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};

ll array_inv(vector<ll> V) {
	static BIT<int,18> bt;
	ZERO(bt.bit);
	int x=0,i;
	map<ll,int> M;
	vector<int> V2;
	
	M[-1LL<<60]=0;
	FORR(r,V) M[r]=0;
	FORR(r,M) r.second=x++;
	ll ret=0;
	for(i=V.size()-1;i>=0;i--) {
		ret += bt(M[V[i]]);
		bt.add(M[V[i]],1);
	}
	return ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	FORR(c,S) cnt[c]++;
	
	int id=-1;
	FOR(i,256) if(cnt[i]%2==1) {
		if(id!=-1) return _P("-1\n");
		id=i;
	}
	
	FOR(i,N) {
		cnt2[S[i]]++;
		if(cnt2[S[i]]*2-1==cnt[S[i]]) P[i]=1;
		else if(cnt2[S[i]]<=cnt[S[i]]/2) P[i]=0;
		else P[i]=2;
		T[P[i]]+=S[i];
	}
	
	int toswap=0;
	for(i=N-1;i>=0;i--) {
		if(P[i]==2) ret+=toswap;
		if(P[i]<=1) toswap++;
	}
	toswap=0;
	FOR(i,N) {
		if(P[i]==1) toswap++;
		if(P[i]==0) ret+=toswap;
	}
	
	int A=0;
	FOR(i,N) if(P[i]==0) pos[S[i]].push_back(A++);
	FOR(i,256) reverse(ALL(pos[i]));
	vector<ll> V;
	
	for(i=N-1;i>=0;i--) if(P[i]==2) {
		V.push_back(pos[S[i]].back());
		pos[S[i]].pop_back();
	}
	
	ret+=array_inv(V);
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 10764
let cs = stdin.ReadLine().ToCharArray()
let N = Array.length cs

[0..N-3]
|> List.map (fun i -> 
  sprintf "%c%c%c" cs.[i] cs.[i+1] cs.[i+2]
  |> int
  |> fun n -> abs (n - 753) )
|> List.min
|> printfn "%d"


Measured memory_bytes: 14300
#include<bits/stdc++.h>
using namespace std;
int main(void){
   string s1,s2;
   cin>>s1>>s2;
   s1+=s2;
   int a=stoi(s1);
    float f=sqrt(a);
    int b=(int) f;
    if(b==f) cout<<"Yes";
    else cout<<"No";
}

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

int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    for(int i = 0 ; i < b; i++){
        if(a*i % b == c)
            count++;
    }
    if(count != 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,result,count=0;
    scanf("%d",&n);
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            result=i*j;
            if(result==n) count++; 
        }
    }
    if(count>=1) printf("Yes\n");
    else printf("No\n");
    
    return 0;
}

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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

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

	int N, T; cin >> N >> T;
	
	int last = -1;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int t; cin >> t;
		
		if (last != -1) {
			ans += min(last + T, t) - last;
		}
		last = t;
	}
	ans += T;
	print(ans);
}

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


int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    // n%(a+b)
    ll per = n/(a+b);
    n %= (a+b);
    if(n <= a) cout << n+per*a << endl;
    else cout << a+per*a << endl;
    return 0;
}

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

int main(){
    int k,a,b; cin >> k;
    cin >> a >> b;
    bool ok = false;
    for(int i = a; i <= b; i++){
        if( i % k == 0 ){
            ok = true;
            break;
        }
    }
    if(ok)
        cout << "OK";
    else
        cout << "NG";
    return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

#define rep(i,n) for (long long int i = 0; i < (n); i++)

using namespace std;

int main(int argc, char* argv[]){
  long long int N;
  vector<string> S;
  cin >> N;

  string Si;
  rep(i,N){
    cin >> Si;
    S.push_back(Si);
  }
  
  long long int ans = 0;

  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  ans = S.size();
  cout << ans << endl;
  return 0;
}


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

#define     int          long long int
#define     fast() 	     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     F            first
#define     S            second

const int inf=1e18,M=1e9+7;

const int N=1e5+5;

vector<pair<int,int>> v[N];
vector<int> clr(N),vis(N,0);

void dfs(int x,int par,int dist)
{
 for(auto u:v[x])
 {
  if(vis[u.F])
  continue;
  
  vis[u.F]=1;
  if(u.S%2==0)
  clr[u.F]=clr[x];
  else
  {
   if(par!=-1 && (dist+u.S)%2==0)
   clr[u.F]=clr[par];
   else
   clr[u.F]=1-clr[x];
  }
  
  dfs(u.F,x,u.S);
 }
}

void solve()
{
 int n;
 
 cin>>n;
 
 int a,b,w;
 
 for(int i=1;i<n;++i)
 {
  cin>>a>>b>>w;
  v[a].pb({b,w});
  v[b].pb({a,w});
 }
 
 clr[1]=0;
 vis[1]=1;
 dfs(1,-1,0);
 
 for(int i=1;i<=n;++i)
 cout<<clr[i]<<"\n";
}

int32_t main()
{
    fast();
    
	int t=1;
	//cin>>t;
	while(t--)
    {
     solve();
	}

    return 0;
}


Measured memory_bytes: 12544
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int gcd(int a, int b) {
    if (a < b)swap(a, b);
    int r = a % b;
    if (r == 0)return b;
    return gcd(b, r);
}

void solve() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A <= B - 1) {
        cout << "No" << endl;
        return;
    }
    A -= ((A - C - 1) / B) * B;
    int g = gcd(A, B);
    g = gcd(g, C);
    g = gcd(g, D);
    A /= g;
    B /= g;
    C /= g;
    D /= g;
    //C+1<=A<=C+B
    if (A <= B - 1) {
        cout << "No" << endl;
        return;
    }
    if (D <= B - 1) {
        cout << "No" << endl;
        return;
    }
    //以下A>=B,D>=B
    if (C >= B - 1) {
        cout << "Yes" << endl;
        return;
    }
    //以下A>=B,A<=B+C,D>=B,C<=B-2
    //if C+1<=購入後の残り<=B-1 then No
    if (gcd(B, D) == 1) {
        cout << "No" << endl;
        return;
    }
    int delta = D - B;
    if (delta == 0) {
        cout << "Yes" << endl;
        return;
    } else if (delta <= B - C - 1) {
        cout << "No" << endl;
        return;
    }
    int s = A - B;
    int l = B - 1;
    int x = s + (l - s) / delta;
    if (C + 1 <= x) {
        cout << "No" << endl;
        return;
    }
    if (gcd(delta, B) <= B - C - 1) {
        cout << "No" << endl;
        return;
    }
    cout << "Yes" << endl;
    return;
}

signed main() {
    int T;
    cin >> T;
    rep(i, T) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int i,j;
		String[] rc=br.readLine().split(" ");
		int r=Integer.parseInt(rc[0]);
		int c=Integer.parseInt(rc[1]);
		
		int[][] sheet=new int[r+1][c+1];
		
		for(i=0;i<r;i++){
			String[] num=br.readLine().split(" ");
			for(j=0;j<c;j++){
				sheet[i][j]=Integer.parseInt(num[j]);
				sheet[i][c]+=sheet[i][j];
				sheet[r][j]+=sheet[i][j];
			}
			sheet[r][c]+=sheet[i][c];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				System.out.print(sheet[i][j]);
				if(j==c){
					System.out.println();
				}
				else{
					System.out.print(" ");
				}
			}
		}
	}
}

Measured memory_bytes: 32996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//std::cout << std::setfill('0') << std::right << std::setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  int N; cin>>N;
  int h[N]; CINA(h,N);
  int r = 0;
  REP(t,101){
    bool tuna = false;
    REP(i,N){
      if(h[i]>t){
        if(!tuna){ tuna = true;}
      }
      else{
        if(tuna){ r++; tuna=false;}
      }
    }
    if(tuna){r++;}
  }
  cout << r;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long int MOD=1e9+7;
#define int long long int
int32_t main() {
	int n;
	cin>>n;
	int arr[n];
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	int cur=0;
	int mn=INT_MAX;
	for(int i=0;i<n-1;i++){
		cur+=arr[i];
		mn=min(mn,abs(sum-2*cur));
	}
	cout<<mn;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

ld n,t[105]={0},v[105]={0},dp[40005][205]={0};
int s[105]={0};

int main()
{ios_base::sync_with_stdio(false);

cin>>n;

rep(i,1,n)cin>>t[i];
rep(i,1,n)cin>>v[i];
rep(i,0,40004)rep(j,0,204)dp[i][j]=-1;
dp[0][0]=0;
int nn=0;
rep(i,1,n)
{
	nn+=t[i];
	s[i]=t[i]+s[i-1];
}

int ptr=1;

rep(i,1,2*nn)
{
	int kkk=v[ptr];
	ld x=i;
	x/=2;
	if(abs(x-s[ptr])<1e-9)
	{
		ptr++;
		kkk=min(kkk,(int)v[ptr]);
	}
	//o2(x,kkk);on;
	rep(vel,0,2*kkk)
	{
		ld kk=vel;
		if(dp[i-1][vel+1]>=0)
		dp[i][vel]=max(dp[i][vel],dp[i-1][vel+1]+0.5*(2*kk+1));
		if(dp[i-1][vel]>=0)
		dp[i][vel]=max(dp[i][vel],dp[i-1][vel]+kk);
		if(vel>0)
		{
			if(dp[i-1][vel-1]>=0)
			dp[i][vel]=max(dp[i][vel],dp[i-1][vel-1]+0.5*(2*kk-1));
		}
	}
}
cout<<fixed<<setprecision(10)<<(dp[2*nn][0]*0.25);
return 0;
}



Measured memory_bytes: 128512
import sys
input = sys.stdin.readline

n = int(input())
a = [0] * n
b = [0] * n
c = [0] * n
for i in range(n):
    a[i], b[i], c[i] = list(map(int, input().split()))

dp = [[0 for i in range(3)] for j in range(n)]
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

for i in range(1, n):
    dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2])
    dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2])
    dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1])
print(max(dp[-1]))


Measured memory_bytes: 36212
N = int(input())
a_list = [int(input()) for i in range(N)]

ans = 0
for i in range(N):
    p = a_list[i] // 2
    ans += p
    a_list[i] -= 2*p
    if i < N-1 and a_list[i] == 1 and a_list[i+1] > 0:
        a_list[i] -= 1
        a_list[i+1] -= 1
        ans += 1
print(ans)

Measured memory_bytes: 7072
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#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 <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = 1e9;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 500005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

typedef unsigned int uint;

int dp[1 << 13];

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

    int n, m;
    cin >> n >> m;
    for( int i = 0; i < (1 << 13); ++i ) dp[i] = INF;
    vector< pair< int, uint > > v;
    
    for( int i = 0; i < m; ++i ) {
        int a, b;
        cin >> a >> b;
        uint u = 0;
        for( int j = 0; j < b; ++j ) {
            int c;
            cin >> c;
            u |= (1 << (c - 1));

        }
        v.pb( MP( a, u ) );

    }

    dp[0] = 0;
    for( int i = 0; i < m; ++i ) {
        for( int j = 0; j < (1 << n); ++j ) {
            dp[j | v[i].S] = min( dp[j | v[i].S], dp[j] + v[i].F );

        }
    }

    if( dp[(1 << n) - 1] == INF ) cout << -1;
    else cout << dp[(1 << n) - 1];
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

typedef long long ll;

ll n;
ll x[1005], y[1005];
vector<ll> z;

int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++) scanf("%lld%lld", &x[i], &y[i]);
    for(ll i = 1; i < n; i++)
    {
        if(((x[i] + y[i] - x[0] - y[0]) & 1) == 1)
        {
            printf("-1");
            return 0;
        }
    }
    if(((x[0] + y[0]) & 1) == 0)
    {
        printf("37\n");
        for(ll i = 35; i >= 0; i--) z.push_back(1ll << i), printf("%lld ", 1ll << i);
        z.push_back(1), printf("%lld ", 1);
    }
    else
    {
        printf("36\n");
        for(ll i = 35; i >= 0; i--) z.push_back(1ll << i), printf("%lld ", 1ll << i);
    }
    puts("");
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < z.size(); j++)
        {
            if(abs(x[i]) < abs(y[i]))
            {
                if(y[i] > 0) printf("U"), y[i] -= z[j];
                else printf("D"), y[i] += z[j];
            }
            else
            {
                if(x[i] > 0) printf("R"), x[i] -= z[j];
                else printf("L"), x[i] += z[j];
            }
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

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

int main(void){
  int N,M;
  scanf("%d%d",&N,&M);

  int left,right,L,R;
  for (int i = 0; i < M; i++) {
    scanf("%d%d",&L,&R);
    if(i == 0){
      left = L;
      right = R;
    }
    left = max(left,L);
    right = min(right,R);
  }

  printf("%d\n",max(0,right-left+1));

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==1 && b==2 || a==2 && b==1) printf("3");
    else if(a==1 && b==3 || a==3 && b==1) printf("2");
    else if(a==2 && b==3 || a==3 && b==2) printf("1");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, 0, n)
        cin >> v[i];
    sort(rbegin(v), rend(v));
    int sum = 0;
    rep(i, 0, k)
        sum += v[i];
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# define MOD 1000000000+7
# define INF 1000000000
using namespace std;

int main() {
	int a[100];
	for (int i = 0; i < 100; i++) {
		a[i] = 0;
	}
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		a[s[i] - 'a']++;
	}
	bool b = true;
	for (int i = 0; i < 100; i++) {
		if (a[i] % 2 == 1)b = false;
	}
	if (b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
	if (a < b) return euclidean_gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

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

	ll ans = 0;
	int cb = 0;
	rep(i, n) {
		if (s[i] == 'B') {
			cb++;
		}
	}

	rep(i, n) {
		rep(j, n) {
			if (s[i] == 'R' && s[j] == 'G') {
				ans += cb;
				if (i < j) {
					if (2 * i - j >= 0 && s[2 * i - j] == 'B') {
						ans--;
					}
					if ((i + j) % 2 == 0 && s[(i + j) / 2] == 'B') {
						ans--;
					}
					if (2 * j - i  < n && s[2 * j - i] == 'B') {
						ans--;
					}
				}
				else if(j < i){

					if (2 * j - i >= 0 && s[2 * j - i] == 'B') {
						ans--;
					}
					if ((i + j) % 2 == 0 && s[(i + j) / 2] == 'B') {
						ans--;
					}
					if (2 * i - j < n && s[2 * i - j] == 'B') {
						ans--;
					}
				}
			}
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 3732
#!/usr/bin/env ruby

require 'bigdecimal'
require 'bigdecimal/math'
include BigMath

a, b, h ,m = gets.chomp.split(' ').map(&:to_s)
a = a.to_i
b = b.to_i

rad_a = -(BigDecimal(h) + BigDecimal(m) / 60) / 12 * ( 2 * Math::PI)
rad_b = -(BigDecimal(m) / 60) * ( 2 * Math::PI)

prec = 10
a_x = cos(rad_a, prec) * 0 - sin(rad_a, prec) * a
a_y = sin(rad_a, prec) * 0 + cos(rad_a, prec) * a

b_x = cos(rad_b, prec) * 0 - sin(rad_b, prec) * b
b_y = sin(rad_b, prec) * 0 + cos(rad_b, prec) * b

puts sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2, prec)


Measured memory_bytes: 14564
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)
#define foreach(a) for (auto it = a.begin(); it != a.end(); ++it)
#define foreach_r(a) for (auto it = a.rbegin(); it != a.rend(); ++it)

typedef long long ll;
typedef unsigned long long ull;

unsigned n, m, r;

vector<vector<ull>> costs;

// Floyd-Warshall's algorithm
void fw(void)
{
    for (unsigned k = 0; k < n; ++k) {
        for (unsigned i = 0; i < n; ++i) {
            for (unsigned j = 0; j < n; ++j) {
				if (i == j || i == k || k == j) continue;
				if (costs[i][k] == UINT_MAX || costs[k][j] == UINT_MAX) continue;
                if (costs[i][j] > costs[i][k] + costs[k][j]) {
					costs[i][j] = costs[i][k] + costs[k][j];
                }
            }
        }
    }
}

ull calc_len(const vector<unsigned> &rs) {
	ull total = 0;
	//cout << "rs=" << rs << endl;
	forn(i, rs.size() - 1) {
		unsigned r1 = rs[i];
		unsigned r2 = rs[i + 1];
		//cout << "r1=" << r1 << " r2=" << r2 << " " << costs[r1][r2] << endl;
		total += costs[r1][r2];
	}
	return total;
}

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

    cin >> n >> m >> r;

    vector<unsigned> rs;

    forn(i, r) {
		unsigned ri;
		cin >> ri;
		rs.push_back(--ri);
    }

	costs.resize(n);	
	forn(i, n) {
		costs[i].resize(n);
	}
	forn(i, n) {	
		forn(j, n) {
			if (i == j) {
				costs[i][j] = 0;
			} else {
				costs[i][j] = UINT_MAX; // -1ull / 2 - 1000000;
			}
		}
	}

	forn(i, m) {
		unsigned a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;

		//cout << "connect " << a << " " << b << endl;
		costs[a][b] = c;
		costs[b][a] = c;
	}

	fw();

    ull minlen = -1ull;
	sort(rs.begin(), rs.end());
    do {
		ull len = calc_len(rs);
		//len = (1ull << 44);
		//cout << "len=" << len << endl;
		minlen = min(len, minlen);
    } while (next_permutation(rs.begin(), rs.end()));

    cout << minlen << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    int ans=0;
    ans=max(ans,A+A-1);
    ans=max(ans,A+B);
    ans=max(ans,B+B-1);
    cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,M;
    cin >> N;
    map<string,int> mp;
    rep(i,N) {
        string s;cin >> s;
        ++mp[s];
    }
    cin >> M;
    rep(i,M) {
        string s;cin >> s;
        --mp[s];
    }
    
    int ans = 0;
    for(auto e:mp){
        ans = max(ans,e.second);
    }
    cout << ans << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
ll divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res.size();
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  ll ans=0;
  irep(i,1,n){
    for(ll j=1; j*i<n; j++){
      ans++;
      // cout<<i<<' '<<j<<endl;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int A, B, C; cin >> A >> B >> C;
  cout << A*B/2 << endl;
}

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

int main(void){
    long long n;
    cin >> n;
    
    long long ans = 1;
    long long i;
    for(i = 1; i <= n; i++){
        ans *= i;
        ans %= 1000000000 + 7;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 200007
using namespace std;
ll addmod(ll a, ll b) {
  if (0 == b)
    return a;
  b = mod - b;
  if (a >= b)
    return a - b;
  else
    return mod - b + a;
}
ll mulmod(ll a, ll b) {
  ll res = 0;
  a = a % mod;
  while (b > 0) {
    if (b % 2 == 1)
      res = (res + a) % mod;
    a = (a * 2) % mod;
    b /= 2;
  }
  return res % mod;
}
int main() {
  fastio;
  ll n = 0, s = 0;
  cin >> n;
  ll ar[n];
  for (ll i = 0; i < n; ++i)
    cin >> ar[i], s += ar[i];
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    s -= ar[i];
    ans = addmod(ans, mulmod(ar[i], s));
  }
  cout << ans;
}

Measured memory_bytes: 5168