akhauriyash/Code-Regression huggingface dataset:
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define SCIN(x) string x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);
    V p(n);
    REP(i,n){int j;cin>>j;p[i]=--j;}
    vector<bool> v(n);
    REP(i,n)v[i]=(i==p[i]);
    int cou=0;
    REP(i,n){
        if(v[i]){
            cou++;
            if(i!=n-1){v[i]=0;v[i+1]=0;}
            else v[i]=0;
        }
    }
    
    COUT(cou);
    return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

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


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


ll f(ll b, ll n) {
    if (n < b) return n;
    return f(b, n / b) + n % b;
}


int main() {

    int n;
    cin >> n;
    int ans = n * (n + 1) / 2;
    cout << ans << endl;
}

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

using namespace std;

using int64 = long long;
const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


// 競技プログラミングを引退します
// いままでありがとうございました

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


  vector< int > d(N + 1, inf);
  d[N] = 0;
  int cur = N, add = 0;
  while(cur > 0) {
    int last = inf;
    for(int k = 1; k <= M; k++) {
      if(cur - k < 0) continue;
      if(S[cur - k] == '0') last = cur - k;
    }
    if(last == inf) {
      cout << -1 << endl;
      return 0;
    }
    cur = last;
    ++add;
    d[cur] = add;
  }

  for(int i = 1; i < N; i++) {
    chmin(d[i], d[i - 1]);
  }


  cur = 0, add = 0;
  while(cur < N) {
    int last = 0;
    for(int k = 1; k <= M; k++) {
      if(cur + k > N) continue;
      if(S[cur + k] == '0' && add + 1 + d[cur + k] == d[0]) {
        cout << k << " ";
        last = cur + k;
        break;
      }
    }
    cur = last;
    ++add;
  }
  cout << endl;
}



Measured memory_bytes: 1104
#include<bits/stdc++.h>
#define mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e5 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
int main(){
	int n,m;cin >> n >> m;
	for(int i = 1;i <= m;i++){
		int x;cin >> x;n -= x;
	}
	if(n < 0) puts("-1");else printf("%d\n",n);
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int 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()
{
    ll n,k,q;
    map<ll,ll> mp;
    cin >> n >> k >> q;
    ll a[q];
    rep(i,q){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(ll i=1;i<=n;i++){
        if(k-(q-mp[i])>0) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 9472
a = [0]*3

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

n = int(n)
b_ = [0]*n
for i in range(0,n):
  b_[i] = input()
 
b = [int(i) for i in b_]

for i in range(0,3):
  for j in range(0,3):
    if(a[i][j] in b):
      a[i][j] = 10000
    else:
      continue

if(sum(a[0])==30000 or sum(a[1])==30000 or sum(a[2])==30000):
  print("Yes")
  exit()
elif(a[0][0] + a[1][1] + a[2][2] ==30000 or a[0][2] + a[1][1] + a[0][2]== 30000):
  print("Yes")
  exit()
elif(a[0][0] + a[1][0] + a[2][0] == 30000 or a[0][1] + a[1][1] + a[2][1] == 30000 or a[0][2] + a[1][2] + a[2][2] == 30000):
  print("Yes")
  exit()
else:
  print("No")


Measured memory_bytes: 38256
N = int(input())
c = list(input())
cd = c[::-1]

rs = [0]*(N+1)
ws = [0]*(N+1)
ws[0]= 0
rs[0] = 0

for i in range(N):
    if(c[i]=="W"):
        rs[i+1]=rs[i]+1
    else:
        rs[i+1]=rs[i]

    if(cd[i]=="R"):
        ws[i+1]=ws[i]+1
    else:
        ws[i+1]=ws[i]
    
ws.reverse()

m = 1000000000
for i in range(N+1):
    M = max(rs[i],ws[i])
    if m>M:
        m = M
    
print(m)


Measured memory_bytes: 21704
import math

mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
    ai, bi = map(int, input().split())
    idx = (ai, bi)
    if ai < 0:
        ai, bi = -ai, -bi
    if idx == (0, 0):
        zero += 1
    elif idx[0] == 0:
        dic[(0, 1.5)] += 1
    elif idx[1] == 0:
        dic[(1.5, 0)] += 1
    else:
        g = math.gcd(abs(ai), abs(bi))
        ai = ai // g
        bi = bi // g
        idx = (ai, bi)
        if idx in dic:
            dic[idx] += 1
        else:
            dic[idx] = 1

ans = 1
already = set([])
for key, value in dic.items():
    if key in already: continue
    a, b = key
    if a == 1.5 or b == 1.5:
        pair1 = dic[(0, 1.5)]
        pair2 = dic[(1.5, 0)]
        ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
        already.add((0, 1.5))
        already.add((1.5, 0))
    else:
        if b > 0: idx = (b, -a)
        else: idx = (-b, a)
        if idx in dic:
            pair1 = dic[key]
            pair2 = dic[idx]
            ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
            already.add(key)
            already.add(idx)
        else:
            pair1 = dic[key]
            ans = (ans * pow(2, pair1, mod)) % mod
            already.add(key)

ans = (ans + zero - 1) % mod
print(ans)

Measured memory_bytes: 137644
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll x,y;
	cin>>x>>y;
	cout<<(abs(x-y)<=1?"Brown":"Alice")<<endl;

	return 0;
}

Measured memory_bytes: 764
N = int(input())
a = list(map(int,input().split()))
count4 = 0
count2 = 0

for i in range(N):
  if a[i]%4 == 0:
    count4 += 1
  elif a[i]%2 == 0:
    count2 += 1


if count2 == 0:
  ans = 2*count4 + 1
else:
  ans = 2*count4 + count2

if ans >= N:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14252
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int  main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
     IOS
     int n,m;
     ll k;
     cin >> n >> m >> k;
     vector<ll> a,b;
     for(int i = 0; i < n; i++){
     	ll x;
     	cin >> x;
     	a.pb(x);
     }
     for(int i = 0; i < m; i++){
     	ll x;
     	cin >> x;
     	b.pb(x);
     }
     vector<ll> a1(n + 1), b1(m + 1);
     a1[0] = 0;
     b1[0] = 0;
     for(int i  = 1, j = 0; i <= n; i++, j++){
     	a1[i] = a1[i - 1] + a[j];
     }
     for(int i  = 1, j = 0; i <= m; i++, j++){
     	b1[i] = b1[i - 1] + b[j];
     }
     //ll cnt1 = (upper_bound(b1.begin(), b1.end(), k) - b1.begin());
     ll cnt1 = 0;
     for(int i = 0; i <= n; i++){
     	ll rem = k - a1[i];
     	if(rem < 0)
     		break;
     	ll ans = i + (upper_bound(b1.begin(), b1.end(), rem) - b1.begin()) - 1;
     	cnt1 = max(cnt1, ans);
     }
     //ll cnt2 = (upper_bound(a1.begin(), a1.end(), k) - a1.begin());
     ll cnt2 = 0;
     for(int i = 0; i <= m; i++){
     	ll rem = k - b1[i];
     	if(rem < 0)
     		break;
     	ll ans = i + (upper_bound(a1.begin(), a1.end(), rem) - a1.begin()) - 1;
     	cnt2 = max(cnt2, ans);
     }
     cout << max(cnt1, cnt2);
     return 0;
}

Measured memory_bytes: 9508
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
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; }

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    ll n;
    cin >> n;
    ll cnt = 0;
    vector<ll> h(n, 0);
    REP(i, n) {
        cin >> h.at(i);
    }
    REP(i, n - 1)
    {
        ll tmp = 0;
        FOR(j, n-1, i) {
            if (h.at(j) >= h.at(j + 1))
            {
                tmp++;
                cnt = max(cnt, tmp);
            }
            else
            {
                i = i + tmp;
                break;
            }
        }
        if(cnt > n - i) {
            break;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1152
/*
AIZU ONLINE JUDGE ??????
Official House
---------------------------------------*/

/*????????????????????????????????????*/
#include<iostream>//???????????????<iostream>?????????????????????
using namespace std;


/*???????????¢??°*/
int main(){

	/*??°?????????????????°??????*/
	int house[5][4][11]={};//???????????°?????????(????£?????????????10??¨?±?)
	
	/*??\???*/
	int b,f,r,v;//??\???????¨???????????????°?????????
	int alter;
	cin>>alter;//??\???????????°????¨????
	for(int i=0;i<alter;i++){
	
		cin>>b>>f>>r>>v;
		house[b][f][r]+=v;
	
	}
	
	/*??????*/
	for(int j=1;j<=4;j++){
	
		for(int k=1;k<=3;k++){
		
			for(int l=1;l<=10;l++){
			
				cout<<" "<<house[j][k][l];
			
			}
		
			cout<<"\n";
			
		}
	
		if(j<4){cout<<"####################"<<"\n";}//????£????????£??????????"####################"?????????
		
	}
	
	
	return 0;//??????
	
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

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

int main() {
    string n;
    cin >> n;
    int sum = 0;
    for (auto t : n) {
        sum += (t - '0');
    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;

    return 0;
}

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

vector<double> a(82);
long long r, n;
int fl(int x) { return x + 40; }
int fr(int x) { return x + 41; }
bool g(double t) {
  for (int i = -r; i < r; i++) {
    if (a[fr(i)] < sqrt(r * r - i * i) + t - r) {
      return false;
    }
  }
  for (int i = -r + 1; i <= r; i++) {
    if (a[fl(i)] < sqrt(r * r - i * i) + t - r) {
      return false;
    }
  }
  return true;
}

int main() {
  while (true) {
    cin >> r >> n;
    if (r == 0)
      break;
    for (int i = 0; i < 82; i++)
      a[i] = 0;
    for (int i = 0; i < n; i++) {
      int b, c, h;
      cin >> b >> c >> h;
      for (int j = fr(b); j <= fl(c); j++) {
        a[j] = max(a[j], (double)h);
      }
    }
    double tmin = 0, tmax = 1000;
    for (int l = 0; l < 3000; l++) {
      double t = (tmin + tmax) / 2;
      if (g(t)) {
        tmin = t;
      } else {
        tmax = t;
      }
    }
    printf("%.9lf\n", tmin);
  }
  return 0;
}



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

namespace AtCoder.Abc
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            
            // 整数の入力
            long n = long.Parse(Console.ReadLine());

            long result = 0;
            if(n < 10)
            {
                result = n;
            }
            else
            {
                for (long i = 0; i <= n; i++)
                {
                    result += Count(i);
                }
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }

        public static long Count(long n)
        {
            string str = n.ToString();
            if(str.EndsWith("0"))
            {
                return 0; //0で終わっている数は、解がゼロ
            }

            long result = 0;

            // 左側がn (a...z) の場合、右側は(z...a)になる

            if(str[0] == str[str.Length - 1])
            {
                //最初と最後が同じ場合、その数字1桁のものがOKになる
                result = 1;
            }
            for(int i = 2; i < str.Length; i++) //nと桁数と同じ場合、途中からnを超える場合があるので、別で計算
            {
                //i桁の場合を数える (10^桁数-2)
                result += (long)Math.Pow(10, i - 2);
            }

            //右側の個数は、10^桁数-2
            //ただし、nを超えてしまうとアウトなので、その検出
            long max = long.Parse(str[str.Length - 1].ToString().PadRight(str.Length - 1, '9') + str[0]); //最大の値
            long min = long.Parse(str[str.Length - 1].ToString().PadRight(str.Length - 1, '0') + str[0]); //最大の値
            if(n < min)
            {
            }
            else if(max <= n)
            {
                result += (long)Math.Pow(10, str.Length - 2);
            }
            else
            {
                long diff = long.Parse(str.Substring(1, str.Length - 2));
                result += diff + 1;
            }

            //左右入れ替えたパターンを含めるので、二倍にする
            result *= 2;

            //入れ替えられないパターンを除外
            if (str[0] == str[str.Length - 1])
            {
                result--;
            }

            Console.Error.WriteLine(n + " : " + result);

            return result;
        }
    }
}


Measured memory_bytes: 15456
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>
//#include <boost/integer/common_factor_rt.hpp> // gcd, lcm
//#include <bits/stdc++.h>

using namespace std;

int main()
{
	int s,w;
	cin >> s >> w;
	if (s <= w)
		cout << "unsafe" << endl;
	else
		cout << "safe" << endl;
}


Measured memory_bytes: 3632
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s, w = LI()
    if w >= s:
        print("unsafe")
    else:
        print("safe")

main()



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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define rep0(i,n) for (int i=0; i<(n); i++)
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; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#define FAST_IOSTREAM() do{}while(0);
#else
#define debug(...) do{}while(0)
#define FAST_IOSTREAM() do{std::ios::sync_with_stdio(false); std::cin.tie(nullptr);}while(0)
#endif

int main() {
    FAST_IOSTREAM();

    int N;
    cin >> N;
    string s;
    cin >> s;

    s = " " + s;
    map<char, ll> count;
    rep1(i,N) {
        count[s[i]]++;
    }
    ll ans = count['R'] * count['B'] * count['G'];

    // 条件2を満たすものから条件1を満たさない数を出し、全体から引く
    rep1(w,N) {
        // w = i-j = k-j
        for(int k=w+1; k+w<=N; k++) {
            if (s[k-w] != s[k+w] && s[k-w] != s[k] && s[k+w] != s[k]) ans--;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 100050;
long long N;
long long X[MAX_N];

std::vector<long long> yakusu (const long long num) {
    std::vector<long long> ret;
    for (long long i = 1; i <= num; i++) {
        if (i*i > num) {
            break;
        }
        if (num % i == 0) {
            if (num / i == i) { 
                ret.push_back(i);
            } else {
                ret.push_back(i);
                ret.push_back(num/i);
            }
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}

bool is_possible(const long long num, const std::vector<long long>& vec) {
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] % num != 0) { return false; }
    }
    return true;
}

int main(int argc, char **argv) {
    std::cin >> N >> X[0];

    for (int i = 1; i <= N; i++) {
        std::cin >> X[i];
    }

    std::vector<long long> vec;
    for (int i = 0; i <= N; i++) {
        vec.push_back(X[i]);
    }

    std::sort(vec.begin(), vec.end());
    long long min = vec[0];
    for (int i = 0; i <= N; i++) {
        vec[i] -= min;
    }

    std::vector<long long> cand = yakusu(vec[1]);

    for (int i = cand.size() - 1; 0 <= i; i--) {
        if (is_possible(cand[i], vec)) { 
            std::cout << cand[i] << std::endl;
            return 0;
        }
    }

    std::cout << 1 << std::endl;
    return 0;
}

Measured memory_bytes: 2168
// 2020-07-17 07:13:11
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
struct mint {
  ll divisor = 1000000007;
  ll val;
  constexpr mint(ll v = 0) noexcept : val(v % divisor) {
    if (val < 0) val += divisor;
  }
  constexpr mint operator + (const mint& rhs) const noexcept {
    return mint(*this) += rhs;
  }
  constexpr mint operator - (const mint& rhs) const noexcept {
    return mint(*this) -= rhs;
  }
  constexpr mint operator * (const mint& rhs) const noexcept {
    return mint(*this) *= rhs;
  }
  constexpr mint operator / (const mint& rhs) const noexcept {
    return mint(*this) /= rhs;
  }
  constexpr mint operator ~ () const noexcept {
    ll a = this->val, b = divisor, u = 1, v = 0;
    while (b > 0) {
      ll t = a / b;
      a -= t * b;
      u -= t * v;
      ll c = a; a = b; b = c;
      ll w = u; u = v; v = w;
    }
    if (u < 0) u += divisor;
    u %= divisor;
    return u;
  }
  constexpr mint& operator += (const mint& rhs) noexcept {
    val += rhs.val;
    if (val >= divisor) val -= divisor;
    return *this;
  }
  constexpr mint& operator -= (const mint& rhs) noexcept {
    if (val < rhs.val) val += divisor;
    val -= rhs.val;
    return *this;
  }
  constexpr mint& operator *= (const mint& rhs) noexcept {
    val = val * rhs.val % divisor;
    return *this;
  }
  constexpr mint& operator /= (const mint& rhs) noexcept {
    val = val * (~(mint(rhs))).val % divisor;
    return *this;
  }
  friend mint modpow (mint a, ll n) noexcept {
    auto res = mint(1);
    while(n > 0) {
      if(n&1) res *= a;
      a *= a;
      n >>= 1;
    }
    return res;
  }
  friend std::ostream& operator << (std::ostream& os, const mint& a) noexcept {
    return os << a.val;
  }
  friend std::string debug_s (mint a) noexcept {
    return std::to_string(a.val);
  }
};

void answer() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  vector<int> t(m);
  rep(i, m) cin >> t[i];
  vector<vector<mint> > dp(n+1, vector<mint>(m+1, 1));
  rep(i, n) rep(j, m) {
    dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1];
    if(s[i] != t[j]) dp[i+1][j+1] -= dp[i][j];
  }
  cout << dp[n][m] << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

#define fi first
#define se second
#define all(X) X.begin(),X.end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int maxn = 1e5 +5;
const int lg = 20;
const int mod = 1e9 + 7;

template<class T>
void smin(T &_x, const T &_y){
	_x = min(_x, _y);
}
template<class T>
void smax(T &_x, const T &_y){
	_x = max(_x, _y);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie();
	ll a, b, c;
	cin>>a>>b>>c;
	if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
		cout<<0<<endl;
		return 0;
	} 
	cout<<min(a * b, min(a * c , b * c))<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 1000000007
#define double long double
#define INF LLONG_MAX/1000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, w[110];
signed main() {
	cin >> n;
	int a = 0, b = 0, ans = INF;
	rep(i, n) {
		cin >> w[i];
		b += w[i];
	}
	rep(i, n) {
		b -= w[i];
		a += w[i];
		ans = min(ans, abs(a - b));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(l[k-1])


Measured memory_bytes: 2940
local n = io.read("*n")
local edge = {}
local z = 0
for i = 1, n do
  edge[i] = {}
  local v = (i * (i + 1)) // 2
  z = z + v
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  if b < a then a, b = b, a end
  z = z - a * (n + 1 - b)
end
print(z)


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

function main()
	mod = 10^9+7
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	x = zeros(Int,n)
	y = zeros(Int,n)
	for i in 1:n
		for j in 1:n
			if j<i
				if a[i]>a[j]
					x[i]+=1
				end
			elseif i<j
				if a[i]>a[j]
					y[i]+=1
				end
			end
		end
	end
	z = 0
	for i in 1:n
		z = (z+(k*y[i])%mod+div(k*(k-1),2)%mod*(x[i]+y[i])%mod)%mod
	end
	println(z)
end

main()

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

int n;
vector<int> a;

int solve(int x){
	if(n-x<=2)return 1;
	int s=a[x+1]>a[x];
	for (int i = x; i < n-1; i++) {
		if(s && a[i+1]<a[i]){
			return solve(i+1)+1;
		}
		else if( !s && a[i+1]>a[i]){
			return solve(i+1)+1;
		}
	}
	return  1;
}

int main(void)
{
	int prev=1e9+7;
	cin>>n;
	for (int i = 0; i < n; i++) {
		int b;
		cin>>b;
		if(b!=prev){
			a.push_back(b);
		}
		prev=b;
	}
	n=a.size();
	int ret=solve(0);
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}

Measured memory_bytes: 8244
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int k;cin>>k;
    string s;cin>>s;
    if(s.size()>k) cout<<s.substr(0,k)<<"..."<<endl;
    else cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

class node {
public:
  int location;
  int P,l,r;
  node(){}
};

class point{
public:
  int id,x,y;
  point(){}
  point(int id,int x,int y): id(id), x(x), y(y) {}
  bool operator < ( const point &p) const {
    return id < p.id;
  }

  void print(){
    printf("%d\n",id);
  }

};

static const int MAX=1000000;
static const int NIL=-1;

int n;
point p[MAX];
node T[MAX];
int np;

bool lessx(const point &p1, const point &p2){return p1.x < p2.x;}
bool lessy(const point &p1, const point &p2){return p1.y < p2.y;}

int make2Dtree(int l,int r,int depth){
  if(!(l<r)){
    return NIL;
  }
  int mid=(l+r)/2;
  int t=np++;
  if(depth%2==0){
    sort(p+l,p+r,lessx);
  }else{
    sort(p+l,p+r,lessy);
  }
  T[t].location=mid;
  T[t].l=make2Dtree(l,mid,depth+1);
  T[t].r=make2Dtree(mid+1,r,depth+1);

  return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<point> &ans){
  int x=p[T[v].location].x;
  int y=p[T[v].location].y;

  if(sx<=x&&x<=tx&&sy<=y&&y<=ty){
    ans.push_back(p[T[v].location]);
  }

  if(depth%2==0){
    if(T[v].l!=NIL){
      if(sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
    }
     if(T[v].r!=NIL){
      if(x<=tx) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
    }
  }else{
     if(T[v].l!=NIL){
      if(sy<=y) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
    }
     if(T[v].r!=NIL){
      if(y<=ty) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
    }
  }
}

int main(){
  int x,y;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d %d",&x,&y);
    p[i]=point(i,x,y);
    T[i].l=T[i].r=T[i].P=NIL;
  }

  np=0;

  int root=make2Dtree(0,n,0);

  int q;
  scanf("%d",&q);
  int sx,tx,sy,ty;
  vector<point> ans;
  for(int i=0;i<q;i++){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    for(int j=0;j<ans.size();j++){
      ans[j].print();
    }
    printf("\n");
  }

  return 0;
}







Measured memory_bytes: 16468
#include <iostream>
#include <vector>
#include <string>

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(void)
{
    int N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    std::vector<int> leftCumE(N, ((S[0] == 'E') ? 1 : 0));
    for (int i = 1; i < N; ++i) {
        leftCumE[i] = leftCumE[i - 1] + ((S[i] == 'E') ? 1 : 0);
    }
    std::vector<int> rightCumW(N, ((S[N-1] == 'W') ? 1 : 0));
    for (int i = N-2; i >= 0; --i) {
        rightCumW[i] = rightCumW[i + 1] + ((S[i] == 'W') ? 1 : 0);
    }

    int maxNbGuys = 0;
    // first
    chmax(maxNbGuys, rightCumW[1]);

    // middle
    for (int i = 1; i < N-1; ++i) {
        chmax(maxNbGuys, leftCumE[i -1] + rightCumW[i+1]);
    }
    // last
    chmax(maxNbGuys, leftCumE[N-2]);

    const int res = N - maxNbGuys -1;

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 3076
using System;
using System.Linq;

namespace ITP1_7_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] size = Console.ReadLine().Split(' ');              
            int n = int.Parse(size[0]);
            int m = int.Parse(size[1]);
            int l = int.Parse(size[2]);
            long[,] vectorA = new long[n, m];
            long[,] vectorB = new long[m, l];
            long[,] vectorC = new long[n, l];
            
            MyVector.SetVector(n, m, vectorA);
            MyVector.SetVector(m, l, vectorB);

            for (int i = 0; i < n; i++)
                for (int j = 0; j < l; j++)
                    for (int k = 0; k < m; k++)
                        vectorC[i, j] += vectorA[i, k] * vectorB[k, j];
                                             
            MyVector.ShowVector(n, l, vectorC);
        }
    }
    class MyVector
    {
        static public void SetVector(int a,int b,long[,] data)
        {
            for (int i=0;i< a; i++)
            {
                int[] input = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
                for (int j = 0; j < b; j++)
                {
                    if (0 <= input[j] && input[j] <= 10000) data[i, j] = input[j];
                    else {
                        Console.WriteLine("Too Large");
                        Environment.Exit(0);
                    }
                }                   
            }
        }
        static public void ShowVector(int a,int b,long[,] data)
        {
            for (int i = 0; i < a; i++)
            {
                string s;
                for (int j = 0; j < b; j++)
                {
                    Console.Write(data[i, j]);
                    s = j == (b - 1) ? "\n" : " ";
                    Console.Write(s);
                }
            }
        }
    }
}

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

#define LEN 100005

//プロセスを表す構造体
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN; 
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}


int main(){
    int q, c;
    int elaps  = 0;
    P a;
    scanf("%d %d", &n, &q);
    for(int i = 0; i < n; i++){
        scanf("%s %d",Q[i].name, &Q[i].t);
    }
    head = 0; tail = n;

    while(head != tail){
        a = dequeue();
        c = min(a.t, q);
        elaps += c;
        a.t -= c;
        if(0 < a.t){
            enqueue(a);
        }else{
            printf("%s %d\n",a.name, elaps);
        }
    }

    return 0;
}


Measured memory_bytes: 13272
/*input
6
30 10 60 10 60 50
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	int n, i;
	cin >> n;
	vector<int> a(n);
	for(auto &x : a)
		cin >> x;
	vector<int> dp(n, 1.5e9);
	dp[0] = 0;
	for(i=1; i<n; i++) {
		if(i >= 1)
			dp[i] = min(dp[i], dp[i-1] + abs(a[i] - a[i-1]));
		if(i >= 2)
			dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout << dp[n-1] << endl;
}

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


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int occur[26];

int main()
{
  string s;
  int i,j;
  cin>>s;
  for (i=0;i<s.length();i++)
    occur[s[i]-'a']++;
  for (i=0;i<26;i++)
    if (occur[i]==0)
      break;
  if (i!=26){
    cout<<s<<(char)(i+'a')<<endl;
    return 0;
  }
  for (i=s.length()-1;i>=0;i--){
    for (j=0;j<26;j++){
      if (occur[j]==0 && (char)(j+'a')>s[i])
	break;
    }
    if (j!=26)
      break;
    occur[s[i]-'a']--;
  }
  if (i==-1){
    cout<<-1<<endl;
    return 0;
  }
  for (int k=0;k<i;k++)
    cout<<s[k];
  cout<<(char)(j+'a')<<endl;
  return 0;
}


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

int getH(int cx, int cy, int x, int y, int h) {
  return h + abs(x - cx) + abs(y - cy);
}

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

  int n;
  cin >> n;

  int idx;

  vector<int> x(n), y(n), h(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> h[i];

    if (h[i] != 0) idx = i;
  }

  int cx, cy, H;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      cx = i;
      cy = j;
      int hi = h[idx];
      int xi = x[idx];
      int yi = y[idx];

      bool ok = true;
      H = getH(cx, cy, xi, yi, hi);
      for (int k = 0; k < n; k++) {
        if (h[k] == max(0, H - abs(x[k] - cx) - abs(y[k] - cy))) continue;

        ok = false;
        break;
      }

      if (ok) {
        cout << cx << " " << cy << " " << H << endl;

        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
bool prime(int x)
{
	if(x<2) return false;
	else if(x==2) return true;
	else if(x%2==0) return false;
	double sx=sqrt(x);
	
	for(int i=3;i<=sx;i+=2){
		if(x%i==0){
			return false;
		}
	}
	return true;
}
int main()
{
	int n,a,s,cnt=0,j;
	cin>>n;
	for(int i=0;i<n;i++){
	   cin>>a;
		if(prime(a)==true) cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}


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

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

    if(abs(a-c)<=d){
        cout << "Yes" << endl;
    }
    else if((abs(a-b)<=d) && abs(b-c)<=d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int main(void){
  vector<int> v(5);
  int i,x;
  REP(i,5) cin >> v[i];
  cin >> x;
  REP(i,4){
    if(v[i+1] - v[0] > x){
      cout << ":(" << endl;
      return 0;
    }
  }
  cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
(* O(4^n) *)
let n, a, b, c = Scanf.scanf " %d %d %d %d" @@ fun n a b c -> n, a, b, c
let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let to_s = Array.make n 0
let rec loop mp i a' b' c' =
  if i >= n then
    if a' > 0 && b' > 0 && c' > 0 then mp - 30 + abs (a - a') + abs (b - b') + abs (c - c')
    else max_int
  else
    let l = ls.(i) in
    min (loop (mp + 10) (i + 1) (a' + l) b' c') @@
      min (loop (mp + 10) (i + 1) a' (b' + l) c') @@
        min (loop (mp + 10) (i + 1) a' b' (c' + l)) @@ loop mp (i + 1) a' b' c'
let _ = loop 0 0 0 0 0 |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define x first
#define y second
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pie   3.141592653589793238462643383279502884L
ll mod = 998244353;
ll powerMod(ll a,ll n){
  if(n==0)
    return 1;
  ll res = powerMod((a%mod*a%mod)%mod,n/2)%mod;
  if(n%2)
  return (a%mod*res%mod)%mod;
  return res; 
} 

int main(){
  string s;
  cin >> s;
  ll ans = 1;
  ll h[26] = {0};
  for(ll i = 0; i < s.size(); i++){
    for(ll j = 0; j < 26; j++)
      if(s[i]!=j+'a' && h[j])
        ans+=h[j];
      h[s[i] - 'a']++;
  }
  cout << ans;



  return 0;   
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main()
{
    char str[101];
    scanf("%s", str);
    int len = strlen(str);
    for (int i = 0; i < len; i++) {
		if(i == 5 || i == 13) {
			printf(" ");
		}
		else {
			printf("%c", str[i]);
		}
	}

    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

int main(){
  string s; cin >> s;
  cout << "2018" + s.substr(4) << endl;
}


Measured memory_bytes: 3624
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

int ans[N];

int main(){
	fastio;
	int n, x, y; cin>>n>>x>>y;
	For(i,1,n+1){
		For(j,i+1,n+1){
			ans[min(j-i,abs(i-x)+abs(y-j)+1)]++;
		}
	}
	For(i,1,n) cout << ans[i] << endl;
	return 0;
}



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

int main(){
  int A, B;
  cin >> A >> B;

  if(A==1){
    A=14;
  }
  if(B==1){
    B=14;
  }
  
  if(A==B){
    cout << "Draw" << endl;
  }
  if(A > B){
    cout << "Alice" << endl;
  }
  if(A < B){
    cout << "Bob" << endl;
  }
}

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

int main() {
    int n;
    cin >> n;
    priority_queue<int, vector<int>, greater<int>> a;
    rep(i, n) {
        int ai;
        cin >> ai;
        a.push(ai);
    }

    int ans = a.top();
    a.pop();
    while (a.size() > 0) {
        int rem = a.top() % ans;
        a.pop();
        if (rem == 0) {
            continue;
        } else {
            a.push(ans);
            ans = rem;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  int N, M; cin >> N >> M;
  set<pair<int,int>> Se;
  for (int i = 0; i < M; i++) {
    pair<int,int> p;
    cin >> p.first >> p.second;
    Se.insert(p);
  }
  set<int> S2;
  for (auto it = Se.begin(); it != Se.end(); ++it) {
    if ((*it).first == 1)
      S2.insert((*it).second);
  }
  vector<int> V;
  for (int i = 1; i <= N; i++)
    V.push_back(i);
  int countOk = 0;
  do {
    if (V[0] != 1) {
      break;
    }
    if (S2.count(V[1]) == 1) {
      /*for (int i = 0; i < M-1; i++) {
        cout << V[i] << " ";
      }
      cout << V[M-1] << endl;*/
      int countPath = 0;
      for (int i = 0; i < N-1; i++) {
        int f = min(V[i],V[i+1]);
        int s = max(V[i],V[i+1]);
        countPath += Se.count(make_pair(f, s));
      }
      countOk += (countPath == N-1);
      //cout << countOk << endl;
    }
  } while (next_permutation(V.begin(), V.end()));
  cout << countOk << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int INF = 1e9;
const long double PI = 3.1415926535;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	if (y1 > y2) {
		swap(x1, x2);
		swap(y1, y2);
	}
 
	bool flag = false;
	if (x1 > x2) {
		flag = true;
		x1 = -x1;
		x2 = -x2;
	}
 
	int n;
	cin >> n;
	vector<int> X(n), Y(n), idxs;
	int hogex = INF, hogey = INF;
	for (int i = 0; i < n; i++) {
		cin >> X[i] >> Y[i];
		if (flag) X[i] = -X[i];
		if (Y[i] < y1 || Y[i] > y2) continue;
		if (X[i] < x1 || X[i] > x2) continue;
		if (Y[i] == y1){
			hogex = X[i];
		} 
		if (X[i] == x1) {
			hogey = Y[i];
		}
		idxs.push_back(i);
	}
	sort(idxs.begin(), idxs.end(), [&](const int& i1, const int& i2){return X[i1] < X[i2];});
 
	long double ans = (y2 - y1) + (x2 - x1);
	ans *= 100;
	if (x1 == x2) {
		if (hogey != INF) ans += (PI - 2) * 10;
	} else if (y1 == y2) {
		if (hogex != INF) ans += (PI - 2) * 10;
	} else if (!idxs.empty()) {
		vector<int> dp(idxs.size(), INF);
		for (int idx : idxs) {
			*lower_bound(dp.begin(), dp.end(), Y[idx]) = Y[idx];
		}
		int foo = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
		if (foo == min(x2 - x1, y2 - y1) + 1) {
			foo -= 1;
			ans += (PI - 2) * 10;
		}		
		ans -= (2 - PI / 2) * 10 * foo;
	}
	cout << fixed << setprecision(15) << ans << endl;
	return 0;
}

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

int main(){int a,b,c,d,x,y;
           cin>>a>>b>>c>>d;
           if(a>=b){x=a-b;}
           else{x=b-a;}
           if(b>=c){y=b-c;}
           else{y=c-b;}
           if(a>=c&&a-c<=d){
             printf("Yes");}
           else if(a<=c&&c-a<=d){
             printf("Yes");}
           else if(x<=d&&y<=d){
             printf("Yes");}
           else{
             printf("No");}}
             

Measured memory_bytes: 256
#!/usr/bin/env python3
#Tenka1 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(input())
s = input()
d = [0]+[1 if s[i] == "#" else 0 for i in range(n)]
d = list(accumulate(d))
ans = float('inf')
for i in range(1,n+1):
    ans = min(ans,d[i-1]+(n-i)-(d[-1]-d[i]))
print(ans)


Measured memory_bytes: 58036