akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
 
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;
 
template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}
 
// ------------------------------------------------------------------------------------------
 
struct edge { int to, cost; };
struct P { 
   int dist, number; 
   bool operator<(const P &p) const {
      return dist < p.dist;
   }
};
 
const int INF = 1e8;
int n;
vec<vec<edge>> G;
int d[111];

void printDist() {
   rep (i, n) { printf("%d %d\n", i, d[i]); }
}
 
void dijkstra(int s) {
   fill(d, d + n, INF);
   d[s] = 0;
   priority_queue<P> Q;
   Q.push({0, s});
   while (Q.size()) {
      P p = Q.top(); Q.pop();
      int v = p.number;
      if (d[v] < p.dist) continue;
      for (int i = 0; i < G[v].size(); i++) {
         edge e = G[v][i];
         if (d[e.to] > d[v] + e.cost) {
            d[e.to] = d[v] + e.cost;
            Q.push({d[e.to], e.to});
         }
      }
      // printDist();
      // line()
   }
}
 
int main() {
   // 入力
   cin >> n;
   G = vec<vec<edge>>(n);
   rep (i, n) {
      int u, k;
      cin >> u >> k;
      rep (j, k) {
         int v, c;
         cin >> v >> c;
         G[u].push_back({v, c});
      }
   }
 
   // ダイクストラ法
   dijkstra(0);
 
   // 出力
   printDist();
 
   return 0;
}


Measured memory_bytes: 3332
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
}


Measured memory_bytes: 256
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _s(): return sys.stdin.readline().strip()


def _i(): return int(sys.stdin.readline().strip())


def main():
    n = _i()
    s = set()
    for _ in range(n):
        s.add(_s())
    return len(s)


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 85540
import sys
import fractions
import numpy as np


def main():
    n, k = [int(e) for e in input().split()]
    an = [int(e) for e in input().split()]
    an.sort(reverse=True)
    gcd = an[0]
    for a in an:
        gcd = fractions.gcd(a, gcd)
    if an[0] < k or (an[0] - k) % gcd != 0:
        print("IMPOSSIBLE")
    else:
        print("POSSIBLE")


main()


Measured memory_bytes: 24056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
#define ull unsigned long long
#define ld long double
#define uint unsigned int
struct debug {
~debug() {cerr << "\n";}template<class C> debug& operator<<(C c) {cerr << c;return *this;}
};
#define var(x) " [" << #x << ": " << x << "]"

int n, a[100][2];

void solve() {
    cin >> n;
    for(int i=0; i<n; ++i) {
        cin >> a[i][0] >> a[i][1];
    }
    for(int i=0; i+2<n; ++i) {
        if(a[i][0]==a[i][1]&&a[i+1][0]==a[i+1][1]&&a[i+2][0]==a[i+2][1]) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

bool weekdayOK[7];
bool hourOK[24];

int cnt[100];

int main() {
  int s,n,t;
  string weekday, time;
  int p, m;
  while(cin>>s>>n>>t>>weekday>>time>>p>>m, s) {
    string wdstr[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    REP(i,7) {
      if (weekday == "All" || weekday == wdstr[i]) weekdayOK[i] = 1;
      else weekdayOK[i] = 0;
    }
    REP(i,24) hourOK[i] = 0;
    if (time == "All") {
      REP(i,24) hourOK[i] = 1;
    } else if (time == "Day") {
      for (int i=6; i<18; ++i) hourOK[i] = 1;
    } else {
      for (int i=0; i<6; ++i) hourOK[i] = 1;
      for (int i=18; i<24; ++i) hourOK[i] = 1;
    }
    double ans = 0;
    REP(stime,7*24*60) {
      int acc = 0;
      double tmp = 1;
      REP(_,m) {
        if (stime == 0) {
          cnt[_] = 0;
          REP(i,s+1) {
            int cwd = (stime+acc)/(24*60)%7;
            int chour = (stime+acc)%(24*60)/60;
            if (!weekdayOK[cwd] || !hourOK[chour]) {
              cnt[_]++;
            }
            acc++;
          }
        } else {
          int cwd_s = (stime+acc+7*24*60-1)/(24*60)%7;
          int chour_s = (stime+acc+7*24*60-1)%(24*60)/60;
          int cwd_t = (stime+acc+s)/(24*60)%7;
          int chour_t = (stime+acc+s)%(24*60)/60;
          if (!weekdayOK[cwd_s] || !hourOK[chour_s]) cnt[_]--;
          if (!weekdayOK[cwd_t] || !hourOK[chour_t]) cnt[_]++;
          acc += s+1;
        }
        
        if (cnt[_] == 0) {
          REP(i,n)
            tmp *= (1.0-1.0/p);
        }
        acc += (t-s)-1;
      }
      chmax(ans, 1-tmp);
    }
    printf("%.10f\n", ans);
  }
}

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

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

  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int cnt = 0;
  rep(i, n) {
    if (a[i] % 2 != 0)
      ++cnt;
  }

  if (cnt % 2 == 0)
    puts("YES");
  else
    puts("NO");
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n; cin >> n;
    vpl v(n);
    rep(i,n) cin >> v[i].first >> v[i].second;
    sort(all(v));
    cout << v.back().first + v.back().second << endl;
}

Measured memory_bytes: 4804
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000

int n;
long a[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++) scanf("%ld", &a[i]);
	return 1;
}

void init() {
}

long solve() {
	int i=0, j=0;
	long x=0, y=0;
	long r = 0;
	while (i<n) {
		while (x==y && j<n) {
			long x2 = x + a[j];
			long y2 = y ^ a[j];
			if (x2 != y2) break;
			x = x2;
			y = y2;
			j++;
		}
		//p(i,j,':',a[i],a[j],'=',x,y);
		r += j-i;
		if (j>i) {
			x -= a[i];
			y ^= a[i];
			i++;
		}
		else {
			//p(i,j,x,y); assert(x==y);
		}
	}
	return r;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int n[2000000][2],r[2000],c[2000],H,W,R,K,S,i,j;
int main(){
	while(true){r[0]=0;c[0]=0;S=0;memset(n,0,sizeof(n));
	cin>>H>>W;if(H==0 && W==0){break;}
	for(i=1;i<=H;i++){cin>>R;r[i]=r[i-1]+R;}
	for(i=1;i<=W;i++){cin>>R;c[i]=c[i-1]+R;}
	for(i=0;i<=H;i++){for(j=i+1;j<=H;j++){n[r[j]-r[i]][0]++;}}
	for(i=0;i<=W;i++){for(j=i+1;j<=W;j++){n[c[j]-c[i]][1]++;}}
	for(i=1;i<2000000;i++){S+=n[i][0]*n[i][1];}
	cout<<S<<endl;}
}

Measured memory_bytes: 16808
#include<bits/stdc++.h>
using namespace std;
long long int f(long long int n){
   long long  int s=0;
    while(n>0){
        //n/=pow(5,i);
        n/=5;
        s += n;
        //i++;
    }
    return s;
} 
int main(){
   long long int n;
   cin>>n;
   /*int num=f(n);
   //cout<<num<<endl;
  long long  int c=0;
    while(num>0){
        num%=10;
        if(num==0) c++;
        else break;
        num/=10;
    }
    cout<<c<<endl;*/
    if(n%2) cout<<0<<endl;
    else{
        n/=2;
        cout<<f(n)<<endl;
    }    
    return 0;
}

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

int cnt[2];
vector<int> G[100000];
bool used[100000];

void dfs(int v,int par){
	used[v] = true;
	cnt[par]++;
	for(int to : G[v]){
		if(!used[to]) dfs(to,par);
	}
}

signed main(){
	int n,m;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,0);
	dfs(1,1);
	if(cnt[0] > cnt[1]) swap(cnt[0],cnt[1]);
	cout << cnt[0] * (cnt[0] - 1) / 2 + (n - cnt[0]) * (n - cnt[0] - 1)/ 2 - m << endl;
	return 0;
}

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

vector<int>v,dp;

void solve(){
	int n;cin>>n;
	dp.resize(n,-1);
	v.resize(n);
	
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	dp[0]=0;
	dp[1]= abs(v[1]-v[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<dp[n-1]<<"\n";

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

Measured memory_bytes: 1024
n = int(input())
list_F = [ list(map(int,input().split(" "))) for i in range(n)]
list_P = [ list(map(int,input().split(" "))) for i in range(n)]
ans = (-1)*pow(10, 9)
a = 0
for i in range(1, 2**10):
    value = 0
    for k in range(n):
        l = list_F[k]
        cnt = 0
        for j in range(10):
            if ((i >> j) & 1):
                if l[j] == 1:
                    cnt += 1
        value += list_P[k][cnt]
    ans = max(ans, value)

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

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

  int N, M; cin >> N >> M;
  int S[M]; char C[M]; REP(i, M) cin >> S[i] >> C[i];

  // N = 1   0〜  9
  // N = 2  10〜 99
  // N = 3 100〜999

  int si[3] = {0, 10, 100}, ei[3] = {9, 99, 999};
  for (int i = si[N - 1]; i <= ei[N - 1]; i++) {
    string si = to_string(i);

    bool ok = true;
    for (int mi = 0; mi < M; mi++) {
      ok &= si[S[mi] - 1] == C[mi];
    }

    if (ok) {
      cout << i << endl;
      return 0;
    }
  }

  cout << "-1" << endl;
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int a,v;cin >> a >> v;
    int b,w;cin >> b >> w;
    int t;cin >> t;
    if(a <= b){
        b += w*t;
        a += v*t;
        if(a >= b)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else{
        b -= w*t;
        a -= v*t;
        if(a <= b)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
while 1:
    try:
        l=map(int,raw_input().split(','))
        l.sort()
        if l.count(l[2])==4:
            print 'four card'
        elif len(set(l))==2:
            print 'full house'
        elif l[0]==(l[1]-1)==(l[2]-2)==(l[3]-3)==(l[4]-4) or  (l[0]+9)==(l[1])==(l[2]-1)==(l[3]-2)==(l[4]-3):
            print 'straight'
        elif l.count(l[2])==3:
            print 'three card'
        elif len(set(l))==3:
            print 'two pair'
        elif len(set(l))==4:
            print 'one pair'
        else:
            print 'null'
    except:
        break

Measured memory_bytes: 6476
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    vector<ll> A(N);

    ll one_pos = -1;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 1) {
            one_pos = i;
            break;
        }
    }

    //1の左にある個数
    ll left = one_pos;

    //1の右にある個数
    ll right = N - 1 - one_pos;

    //左から処理するとあまりが出て,その分を右から引ける
    right -= (left % (K - 1) == 0 ? 0 : K - 1 - left % (K - 1));

    right = max(right, (ll)0);

    ll ans = 0;
    ans += (left % (K - 1) == 0 ? left / (K - 1) : left / (K - 1) + 1);
    ans += (right % (K - 1) == 0 ? right / (K - 1) : right / (K - 1) + 1);

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define NIL -1
#define MAX 25

struct Node{
    int p,lc,rc;
};

Node T[MAX];
int DEP[MAX],H[MAX];

int setH(int u){
    int hl=0,hr=0;
    if(T[u].lc!=NIL) hl=setH(T[u].lc)+1;
    if(T[u].rc!=NIL) hr=setH(T[u].rc)+1;
    return H[u]=max(hl,hr);
}

void setDEP(int u,int p){
    DEP[u]=p;
    if(T[u].lc!=NIL) setDEP(T[u].lc,p+1);
    if(T[u].rc!=NIL) setDEP(T[u].rc,p+1);
}

int setDeg(int u){
    int c=0;
    if(T[u].lc!=NIL) c++;
    if(T[u].rc!=NIL) c++;
    return c;
}

int getSibling(int u){
    if(T[u].p==NIL) return NIL;
    if(T[T[u].p].lc!=NIL&&T[T[u].p].lc!=u) return T[T[u].p].lc;
    if(T[T[u].p].rc!=NIL&&T[T[u].p].rc!=u) return T[T[u].p].rc;
    return NIL;
}

void print(int u){
    cout<<"node "<<u<<": ";
    cout<<"parent = "<<T[u].p<<", ";
    cout<<"sibling = "<<getSibling(u)<<", ";
    cout<<"degree = "<<setDeg(u)<<", ";
    cout<<"depth = "<<DEP[u]<<", ";
    cout<<"height = "<<H[u]<<", ";
    if(T[u].p==NIL) cout<<"root";
    else if(T[u].lc==NIL&&T[u].rc==NIL) cout<<"leaf";
    else cout<<"internal node";
    cout<<endl;
}

int main(){
    int n,v,l,r,root;
    cin>>n;
    for(int i=0;i<MAX;i++){
        T[i].p=T[i].lc=T[i].rc=NIL;
    }
    for(int i=0;i<n;i++){
        cin>>v>>l>>r;
        T[v].lc=l;
        T[v].rc=r;
        if(l!=NIL) T[l].p=v;
        if(r!=NIL) T[r].p=v;
    }

    for(int i=0;i<n;i++){
        if(T[i].p==NIL) root=i;
    }
    setH(root);
    setDEP(root,0);

    for(int i=0;i<n;i++) print(i);
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

// a^n mod を計算する
//ただしmとaが互いにその時のみ
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
    ll N;
    cin >> N;
    vector<ll> C(N,0);
    for(ll i=0;i<N;i++){
        cin>>C[i]
    ;}
    sort(C.begin(), C.end());
    ll ans=0;
    for(ll i=0;i<N;i++){
        ans+=(N+1-i)*C[i];
        ans%=MOD;
    ;}
    ans*=modpow(2,2*N-2,MOD);
    ans%=MOD;


    cout<<ans<<endl;
    


    return 0;
}


Measured memory_bytes: 1792
f=[True]*(10**5+10000)
f[0]=False
f[1]=False
for i in range(2,len(f)):
  if f[i]:
    for j in range(i*2,len(f),i):
      f[j]=False
for i in range(int(input()),len(f)):
  if f[i]:
    print(i)
    break


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long int INT;

INT pow(int n,int k)
{
    INT a=1;
    for (int i=1;i<=k;i++){
        a*=n;
    }
    return a;
}

int main()
{
    INT n;
    int k;
    cin>>n>>k;
    int i=0;
    while(1){
        if(n<pow(k,i)){
            cout<<i<<endl;
            break;
        }
        ++i;
    }
}

Measured memory_bytes: 3560
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
int main() {
	int nichinoken, wasedaakademi, sundai, yotsuyaotuka, schoolIE;
	std::cin >> nichinoken >> wasedaakademi >> sundai >> yotsuyaotuka >> schoolIE;
	int p = (nichinoken+9) % 10;
	int q = (wasedaakademi +9) % 10;
	int r = (sundai+9) % 10;
	int s = (yotsuyaotuka +9) % 10;
	int t = (schoolIE +9) % 10;
	int seg = std::min({ p, q, r, s, t })+1;
	int sapix = 0;
	sapix += (nichinoken + 9) / 10 * 10;
	sapix += (wasedaakademi + 9) / 10 * 10;
	sapix += (sundai + 9) / 10 * 10;
	sapix += (yotsuyaotuka + 9) / 10 * 10;
	sapix += (schoolIE + 9) / 10 * 10;
	int eikozeminaru = 10 - seg;
	std::cout << sapix - eikozeminaru << std::endl;
	return 0;
}

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

int main(){
    int a[3][3];
    bool ok=1;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(a[i][j]-a[i][(j+1)%3]!=a[(i+1)%3][j]-a[(i+1)%3][(j+1)%3]){
                cout<<"No\n";
                return 0;
            }
            if(a[j][i]-a[(j+1)%3][i]!=a[j][(i+1)%3]-a[(j+1)%3][(i+1)%3]){
                cout<<"No\n";
                return 0;
            }
        }
    }
    cout<<"Yes\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans=0;

    ans = b / c;
    if(a == 0)
        ans += 1;
    else if(a % c ==0)
        ans -= a/c - 1;
    else
        ans -= a/c;

    cout << ans << endl;

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
int main(){
	int n;
    cin>>n;
    ll ar[n];
    for(int i=0;i<n;i++){
     cin>>ar[i];
    }
   vector<ll>suffix(n);
   suffix[n-1]=ar[n-1]%mod;
  for(int j=n-2;j>=0;j--){
     suffix[j]=(suffix[j+1]%mod+ar[j]%mod)%mod;
   }
  ll sum=0;
    for(int i=1;i<n;i++){
      ll k=(ar[i-1]%mod)*(suffix[i]%mod);
       sum=sum+(k)%mod;
  }
 cout<<sum%mod<<endl;
	return 0;
}

Measured memory_bytes: 6428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Intrinsics.X86;

namespace KCLC
{
    class Program
    {
        static void Main()
        {
            string Input = Console.ReadLine();
            if (Input == "SSS") { Console.WriteLine("0"); }
            if (Input == "SSR") { Console.WriteLine("1"); }
            if (Input == "SRS") { Console.WriteLine("1"); }
            if (Input == "SRR") { Console.WriteLine("2"); }
            if (Input == "RSS") { Console.WriteLine("1"); }
            if (Input == "RSR") { Console.WriteLine("1"); }
            if (Input == "RRS") { Console.WriteLine("2"); }
            if (Input == "RRR") { Console.WriteLine("3"); }
        }
    }
}

Measured memory_bytes: 25876
def actual(N, A, B):
    satisfied_nums = []

    for i in range(1, N + 1):
        sum_of_digits = 0
        num = i
        for _ in range(5):
            sum_of_digits += num % 10
            num //= 10

        if A <= sum_of_digits <= B:
            satisfied_nums.append(i)

    return sum(satisfied_nums)

N, A, B = map(int, input().split())
print(actual(N, A, B))

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


int main() {
  int N;
  cin >> N;
  
  if(N<1200){
    cout << "ABC" << endl;
  }
  else if(1200 <= N && N <2800){
    cout << "ARC" << endl;
  }
  else{
    cout << "AGC" << endl;
  }
    
}

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

int main() {
  size_t N;
  std::cin >> N;

  std::vector<long> A(N);
  for (size_t i=0; i<N; i++) {
    std::cin >> A[i];
  }

  std::sort(A.begin(), A.end());

  long const max = A[N-1];
  long const half = (max+1)/2;

  long small;
  auto p_cand_a = std::lower_bound(A.begin(), std::prev(A.end()), half);
  if (p_cand_a == A.begin()) {
    small = *p_cand_a;
  } else {
    auto p_cand_b = std::prev(p_cand_a);
    auto cand_a = *p_cand_a;
    auto cand_b = *p_cand_b;
    if (std::abs(cand_a - half) < std::abs(cand_b - half))
      small = cand_a;
    else
      small = cand_b;
  }

  std::cout << max << ' ' << small << std::endl;

  return 0;
}


Measured memory_bytes: 1024
r,c  = gets.chomp.split(" ").map{|item| item.to_i}
table = Array.new(r+1).map{ Array.new(c+1,0) }
r.times do |y|
    table[y] = gets.chomp.split(" ").map{|item| item.to_i}
    table[y][c]=0
    
    c.times do |x|
        table[y][c]+=table[y][x]
        table[r][x]+=table[y][x]
    end
    table[r][c]+=table[y][c]
end

(r+1).times do |y|
    (c+1).times do |x|
        if x!=0 
            print(" ")
        end
        print(table[y][x])
    end
    puts
end

Measured memory_bytes: 8968
#include<bits/stdc++.h>
#define ll long long int
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace std;

int main()
{
	 
   boost
   #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int t=1;
// 	cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    if(n%1000)
	    cout<<((n/1000)+1)*1000 - n;
	    else 
	    cout<<"0";
	    cout<<endl;
	}
    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <sysexits.h>
#include <math.h>

int main(void){
  int b,i,j,num,N,M;
  char S[1],c;
  int a[4];
  if(scanf("%d %d",&N,&M)>2){
    printf("error");
   exit(0);
  }
  if(M+1>N){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int k;
    cin >> k;
    --k;
    char ch = s[k];
    rep(i,n){
        if(s[i] != ch) s[i] = '*';
    }
    cout << s << endl;
    return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-8;
////////////////////////////////////////



int main(){
    ll n,m;cin>>n>>m;
    vector<ll>chi[n+1];
    ll tosize[n+1];memset(tosize,0,sizeof(tosize));
    rep(i,1,n+m-1){
        ll a,b;cin>>a>>b;
        chi[a].pb(b);
        tosize[b]++;
    }
    queue<ll>q;
    ll ans[n+1];
    rep(i,1,n){
        if(tosize[i]==0){
            q.push(i);
            ans[i]=0;
        }
    }
    while(!q.empty()){
        ll t=q.front();q.pop();
        for(auto x:chi[t]){
            tosize[x]--;
            if(tosize[x]==0){
                ans[x]=t;
                q.push(x);
            }
        }
    }
    rep(i,1,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}




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

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n){
        cin >> v[i];
    }
    int cnt = 0;
    rep(i, n){
        if ((i+1)%2 == 1 && v[i]%2 == 1) cnt ++;
    }
    cout << cnt << endl;
}


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

using namespace std;

typedef long long int lli;

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

    int n;
    lli c;
    vector<lli> x(100002, 0), v(100001), R(100001, 0), L(100001, 0), Rm(100001, 0), Lm(100001, 0);

    cin >> n >> c;
    for (int i=0; i<n; i++) cin >> x[i+1] >> v[i+1];
    x[n+1] = c;
    for (int i=0; i<n; i++) {
        R[i+1] = R[i] + v[i+1] - (x[i+1]-x[i]);
        L[i+1] = L[i] + v[n-i] - (x[n-i+1]-x[n-i]);
        Rm[i+1] = max(R[i+1], Rm[i]);
        Lm[i+1] = max(L[i+1], Lm[i]);
    }

    lli ans = 0;
    for (int l=0; l<=n; l++) {
        int r = n-l;
        lli tmp = Rm[r]+Lm[l] - min(x[r], c-x[n-l+1]);
        ans = max(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct R{string word;
int nl;int ty;

};

int main(){

	struct R RR[1001]={};
	int i=0;
	string str;
	while(cin>>str){
		RR[i].word=str;RR[i].nl=str.size();RR[i].ty=0;
	i++;
	}
	
	for(int I=0;I<i;I++)
		for(int J=0;J<i;J++)
			if(RR[I].word==RR[J].word)RR[I].ty++;

	string x,y;
	int max1=0,max2=0;

	for(int I=0;I<i;I++)
	{//cout<<RR[I].ty<<endl;
		if(RR[I].nl>max1){x=RR[I].word;max1=RR[I].nl;}
		if(RR[I].ty>max2){y=RR[I].word;max2=RR[I].nl;}}

	cout<<y<<" "<<x<<endl;
return 0;

}

Measured memory_bytes: 1208
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using static System.Console;
using static System.Math;

namespace abc84_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] dis = new int[n,3];
            for(int i=0; i<n-1; i++){
                int[] input = ReadLine().Split().Select(int.Parse).ToArray();
                dis[i,0] = input[0];
                dis[i,1] = input[1];
                dis[i,2] = input[2];
            }

            for(int i=0; i<n-1; i++){
                int time=0;
                time += dis[i,0] + dis[i,1];

                for(int j=i+1; j<n-1; j++){
                    if(time < dis[j,1]) time = dis[j,1]; //次の駅の最初の電車がまだ出発していなかった場合
                    else if (time % dis[j,2] == 0); //次の駅でちょうど乗れた場合
                    else time += dis[j,2]-(time%dis[j,2]); // 次の駅でちょうど乗れなかった場合
                    time += dis[j,0];
                }
                WriteLine(time);
            }
            //n番目の駅
            WriteLine(0);

        }
    }
}

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

int main(void){
    string s;
    ll k;
    std::cin >> s;
    std::cin >> k;
    
    ll n = s.length();
    
    for (int i = 0; i < n; i++) {
        // a,b,c,d,,,,,,,,x,y,z
        // 0,1,2,3,,,,,23,24,25

        if( s[i] == 'a' ){
            continue;
        }
        if( k >= 26-(s[i]-'a') ){
            k -= 26-(s[i]-'a');
            s[i] = 'a';
        }else{
            continue;
        }
    }
    
    if(k>0){
        s[n-1] = (char) ( (k + (s[n-1]-'a'))%26 )+'a';
    }
    
    
    std::cout << s << std::endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=k;i<=n;i++)
    {   
        ll mn=(ll)(i*(ll)(i-1))/2;

        double mx=((double(i/double(2.0)))*((2*(n-i+1)+(i-1))));
         ll mxx=mx;
        //cerr<<mxx<<" "<<mn<<endl;
        ans=((ans+(mxx%mod-mn%mod+mod)) + 1);
        //cout<<ans<<endl;
    }
    cout<<(ans%mod+1%mod)%mod<<endl;
    
}
return 0;
}

Measured memory_bytes: 3660
# パスカルの三角形
N, K = map(int, input().split())

m = 1000000007

n = max(K, N - K + 1)
c = [[0] * (n + 1) for _ in range(n + 1)]
c[0][0] = 1
for i in range(1, n + 1):
    c[i][0] = 1
    for j in range(1, i + 1):
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % m

result = []
for i in range(1, K + 1):
    result.append(c[K - 1][i - 1] * c[N - K + 1][i] % m)
print('\n'.join(str(i) for i in result))
#print(*result, sep='\n')


Measured memory_bytes: 103972
#include <bits/stdc++.h>
using namespace std;
typedef  long long int  ll ;
#define len(x)            x.length()
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define M                 1000000007
#define MM                998244353
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define mem0(x)           memset(x, 0, sizeof (x))
#define mem1(x)           memset(x, -1, sizeof (x))
#define forn(i, n)        for (int i = 0; i < int(n); i++)

ll su1(ll n){
  return (n*(n+1))/2;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main()
{
  ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
  vector<int> a(3);
  forn(i,3)cin>>a[i];
  swap(a[0],a[1]);
  swap(a[0],a[2]);
  forn(i,3)cout<<a[i]<<" ";
  cout<<"\n";


}

Measured memory_bytes: 256
n = int(input())
S = input().split(" ")
arr = [int(s) for s in S]
def calculate(n,arr):
    ans = 0
    for i in range(len(arr)):
        if i == 0:
            ans += arr[i]
        else:
            if arr[i] > arr[i-1]:
                ans += (arr[i] - arr[i-1])
    return ans

result = calculate(n,arr)

print(result)


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

using namespace std;

int main(){

  int n,w;
  cin>>n>>w;

  int x,y;
  int k[n][2];

  for(int i=0;i<n;i++)
    scanf("%d %d",&k[i][0],&k[i][1]);

  long long ans[n+1][w+1];

  for(int i=0;i<=n;i++){
    for(int j=0;j<=w;j++){
      if(i==0 || j==0){
        ans[i][j]=0;
        continue;
      }
      else{
        if(j>=k[i-1][0])
          ans[i][j]=max(ans[i-1][j-k[i-1][0]]+1ll*k[i-1][1],ans[i-1][j]);
        else
          ans[i][j]=ans[i-1][j];
      }
    }
  }
  printf("%lld\n",ans[n][w]);

  return 0;
}


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

int main(){
    int larger=0,smaller=0, n,p1,p2, ans=0;
    cin >> n;


    cin >> p1;
    for( int i = 0; i < n-1; i++ ){
        cin >> p2;
        if( p1 < p2 ){
            larger++;
            smaller = 0;
        } else {
            smaller++;
            larger = 0;
        }

        p1 = p2;
        if( larger == 2 ){
            ans++;
            larger = 1;
        }
        if( smaller == 2 ){
            ans++;
            smaller = 1;
        }
    }



    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


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

const int N=1000005;


void solve()
{
   
    int n,x,m;
    cin>>n>>x>>m;
    if(!x)
    {
        cout<<0<<endl;
        return;
    }
    vi a;
    a.pb(x);
    int cnt=n-1;int last=x;
    map<int,int>mp;
    mp[x]=1;int k=2;int start= -1,len;
    while(cnt)
    {
        last=(last*last)%m;
        cnt--;
        if(mp.find(last)!=mp.end())
        {
            start=mp[last];
            len=k-mp[last];
            break;
        }
        else
        {
            mp[last]=k++;
            a.pb(last);
        }
    }
    //cout<<start<<endl;
    int ans=0;
    if(start== -1)
    {
        for(int j:a)
            ans+=j;
        cout<<ans<<endl;
        return;
    }
    for(int i=0;i<start-1;i++)
    {  ans+=a[i];
        n--;
    }
    int z=n/len;int Z=0;
    for(int i=start-1;i<a.size();i++)
        Z+=a[i];
    Z=Z*z;
    ans+=Z;
    Z=n%len;
    for(int i=start-1;i<(start-1+Z);i++)
        ans+=a[i];
    cout<<ans<<endl;
    
        
    
    
}

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



Measured memory_bytes: 6764
/**
 * author:    Ziel
 * created:   12.04.2020 18:09:43
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin, x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define bpc __builtin_popcountl
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const db EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
#ifdef ZVER
	cerr << "Ready\n";
#endif
	fre("");
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	ll ans = 0;
	for (int j = 0; j < n; j++) {
		vector<int> ri, gi, bi;
		for (int i = 0; i < j; i++) {
			if (s[i] == 'R' && s[i] != s[j]) ri.pb(i);
			if (s[i] == 'B' && s[i] != s[j]) bi.pb(i);
			if (s[i] == 'G' && s[i] != s[j]) gi.pb(i);
		}
		vector<int> rk, gk, bk;
		for (int k = j + 1; k < n; k++) {
			if (s[k] == 'R' && s[k] != s[j]) rk.pb(k);
			if (s[k] == 'B' && s[k] != s[j]) bk.pb(k);
			if (s[k] == 'G' && s[k] != s[j]) gk.pb(k);
		}
		
		if (s[j] == 'R') {
			ans += sz(gi) * sz(bk);
			ans += sz(bi) * sz(gk);
		} else if (s[j] == 'G') {
			ans += sz(ri) * sz(bk);
			ans += sz(bi) * sz(rk);
		} else {
			ans += sz(ri) * sz(gk);
			ans += sz(rk) * sz(gi);
		}
		
		for (int d = 1; d < n; d++) {
			if (j - d >= 0 && j + d < n) {
				if (s[j - d] != s[j] && s[j] != s[j + d] && s[j - d] != s[j + d]) ans--;
			}
		}
	}
	
	cout << ans;
	return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation


Measured memory_bytes: 3660
import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		System.out.println(ncr(m, 2) + ncr(n, 2));
	}
	static int ncr(int n, int r)
	{
		if(n < r)
			return 0;
		r = Math.min(n - r, r);
		int ans = 1;
		for(int i = 1; i <= r; ++i)
		{
			ans *= (n - r + i);
			ans /= i;
		}
		return ans;
	}
}


Measured memory_bytes: 23892
#include <iostream>
#include <climits>
using namespace std;
int min_arr(int arr[],int len){
  int ans=arr[0];
  for(int i=1;i<len;i++){
    ans=min(ans,arr[i]);
  }
  return ans;
}
int main(){
  int n,k,i;
  cin>>n>>k;
  int h[n];
  for(i=0;i<n;i++){
    cin>>h[i];
  }
  int dp[n],tmp[k+1];
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(i=2;i<n;i++){
    tmp[0]=INT_MAX;
    for(int j=1;j<=k;j++){
      if(j>i){
        tmp[j]=INT_MAX;
        continue;
      }
      tmp[j]=dp[i-j]+abs(h[i]-h[i-j]);
    }
    dp[i]=min_arr(tmp,k+1);
  }
  cout<<dp[n-1];
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
	int N, M;
	int Ball[201];

	//freopen("input.txt", "r", stdin);

	scanf("%d %d", &N, &M);

	int BallCnt = 0;
	for (int n = 1; n <= N; n++) // even
		Ball[BallCnt++] = 2 * n;

	for (int m = 0; m < M; m++) // odd
		Ball[BallCnt++] = 2 * m + 1;

	int ResultCnt = 0;
	for (int b = 0; b < BallCnt; b++)
		for (int t = 0; t < BallCnt; t++)
			if (b != t)
				if ((Ball[b] + Ball[t]) % 2 == 0)
					ResultCnt++;
		
	printf("%d", ResultCnt / 2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

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

    ll a=100;
    int i=1;
    while(true)
    {
        a*=1.01;
        if(X<=a)
        {
            cout << i << endl;
            return 0;
        }
        ++i;
    }

    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 100000
using namespace std;

int main(){
  int n;  cin >> n;
  if(n==1)  cout << "Hello World" << endl;
  else if(n==2){
    int a, b; cin >> a >> b;
    cout << (a+b) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <utility>
#include <algorithm>
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector <int> m[103];
int kakunin[103]={0};
int d[103];
int f[103];
int cnt=0;
void dfs(int num){
    d[num]=cnt++;
    for(int i=0;i<m[num].size();i++){
        if(kakunin[m[num][i]]==0){kakunin[m[num][i]]=1;dfs(m[num][i]);}}
    f[num]=cnt++;
}
int main() {
    int n,a,tmp,id;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>id;
        cin>>a;
        for(int j=0;j<a;j++){
            scanf("%d",&tmp);
            m[id].push_back(tmp);
        }
    }
    for(int i=0;i<102;i++){m[0].push_back(i);}
    dfs(0);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]-1<<" "<<f[i]-1<<endl;}
}

Measured memory_bytes: 1272
import java.util.HashSet;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        HashSet<Integer> list = new HashSet<>();
        for (int i = 0; i < n; i++) {
            list.add(Integer.parseInt(sc.next()));
        }
        System.out.print(list.size());
    }
}

Measured memory_bytes: 22740
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top+1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];
	
	while(scanf("%s", s) != EOF ) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		} else if ( s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		} else if ( s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		} else {
			push(atoi(s));
		}
	}
	
	printf("%d\n", pop());
	
	return 0;
}




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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll cnt = 1;
    ll d = 0;
    while(cnt < 1000010) {
        d = (d * 10 + 7) % K;
        if(d == 0) break;
        ++cnt;
    }
    if(cnt < 1000010) PR(cnt);
    else PR(-1);

    return 0;
}

/*



*/

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

using namespace std;

int main()
{
    int x,a;

    for(int i=1;i<6;i++)
    {

        cin >> x;

        if(x == 0)
        {
            a = i;
        }
    }

    cout << a;
    return 0;
}



Measured memory_bytes: 3636
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

s, c = map(int, stdin.readline().strip().split())

base = min(s, c // 2)
s -= base
c -= 2*base
rr = base

four = c // 4
c -= 4*c
rr += four

print rr


Measured memory_bytes: 2568