akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll n; cin >> n;
  ll a_max = 0;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a.at(i);
    if(a.at(i) > a_max) a_max = a.at(i);
  }
  //sort(a.begin(),a.end());

  unordered_map<ll,int> check{};

  rep(i,n) {
    ll k_c = a.at(i);
    ll kaisu = 2;
    ll k_c_tmp = k_c;
    if(check[k_c] != 0) {
      check[k_c]++;
      continue;
    }
    
    while(k_c_tmp <= a_max) {
      if(kaisu == 2){
        check[k_c_tmp]++;
      }
      else {
        check[k_c_tmp]++;
        check[k_c_tmp]++;
      }
      k_c_tmp = k_c * kaisu;
      kaisu++;
    }
  }

  ll count = 0;

  for(int ddd = 0; ddd <= a_max; ddd++) {
    if(check[ddd] == 1){
      count++;
    }
  }

  cout << count << endl;
}


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

/*string NEXT(string str) {

	int M = str.size();

	if (M == 0) { return "a"; }

	if (str[M - 1] != 'z') {
		str[M - 1]++;
		return str;
	}
	else {
		int q= M - 1;
		while (str[q] == 'z' && q>=0) { q--; }
		cout << "q= " << q << endl;

		if (q < 0) { string ret; for (int i = 1; i <= M + 1; i++) { ret += "a"; } return ret; }

		string ret;
		ret = str.substr(0, q + 1); str[q]++; for (int i = M - 1; i > q; i--) { str += "a"; } return ret;
	}
	return "---";
}*/

string A;
int N;
int dp[200005][30];

int D[200005];

vector<int> V[26];

int main(void) {

	cin >> A;

	N = (int) A.size();
	int q = 0;

	for (int i = N - 1; i >= 0; i--) {
		for (int k = 0; k <= 25; k++) { dp[i][k] = dp[i + 1][k]; }
		 dp[i][A[i] - 'a'] = q+ 1; 

		 int sign = 1;
		 for (int k = 0; k <= 25; k++) { if (dp[i][k] != q + 1) { sign = 0; } }
		 if (sign == 1) { q++; }
	}

	int Km=300005;
	for (int k = 0; k <= 25; k++) { Km = min(Km, dp[0][k]); }
	Km++;
	//cout << "Km= " << Km << endl;

	int K = 300005;

	for (int i = 0; i < N; i++) {
		K = 300005;
		for (int k = 0; k <= 25; k++) {
			K = min(K, dp[i][k]);
		}
		D[i] = K+1;
	}
	D[N] = 1;

	/*for (int i = 0; i <= N; i++) {
		cout << "D[" << i << "]= " << D[i] << endl;
	}*/
	

	for (int i = 0; i < N; i++) {
		char c = A[i];
		V[c - 'a'].push_back(i);
	}
	for (int i = 0; i < 26; i++) { V[i].push_back(N+1); }

	/*for (int i = 0; i < 26; i++) {
		char c = i+'a';
		cout << c ;
		for (int j = 0; j < (int)V[i].size(); j++) {
			cout << " " << V[i][j];
		}cout << endl;
	}*/

	int pos = -1;
	string ans; for (int i = 0; i < Km; i++) {ans += "?";}

	K = Km;
	q = 0;
	int tmp;

	while (pos < N) {
		//cout << "pos= " <<pos<< endl;
		for (int k = 0; k < 26; k++) {
			int cand=lower_bound(V[k].begin(), V[k].end(), pos+1) - V[k].begin();
			//cout << "cand= " << cand;
			tmp = V[k][cand];
			//cout << "  tmp= " << tmp << endl;
			if (D[tmp + 1] == K - 1 || tmp>=N) { pos = tmp;  /*cout << "find: pos= " << pos<<" D[pos+1]= " <<D[pos+1] << endl;*/  ans[q] = (char)k + 'a'; q++; K--; break; }
		}
		
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 25604
/* 
	Author: ankrypt
*/
 
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
 
ll N, T, A;
double ans = 1e9;
ll heights[1005];
double diff[1005];
ll ind;
 
int main() {
	scanf("%lld %lld %lld", &N, &T, &A);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &heights[i]);
	}
	for(int i = 0; i < N; i++) {
		diff[i] = T - heights[i] * 0.006;
	}
	for(int i = 0; i < N; i++) {
		if(abs(diff[i] - A) < ans) {
			ind = i + 1;
			ans = abs(diff[i] - A);
		}		
	}
	cout << ind;
	return 0;
}
/*
	Powered by Buggy Plugin
*/

Measured memory_bytes: 256
#include <stdio.h>

int era_transformation(int, int, int);

int main(void)
{
	int year, month, day;
	while (scanf("%d %d %d", &year, &month, &day) != EOF) {
		era_transformation(year, month, day);
	}
	return 0;
}

int era_transformation(int y, int m, int d)
{
	if (y > 1989 || 
		(y == 1989 && m > 1) ||
		(y == 1989 && m == 1 && d >= 8)) {
		printf("heisei %d %d %d\n", y - 1989 + 1, m, d);
	} else if (y > 1926 || 
		       (y == 1926 && m == 12 && d >= 25)){
		printf("showa %d %d %d\n", y - 1926 + 1, m, d);
	} else if (y > 1912 ||
		       (y == 1912 && m > 7) ||
		       (y == 1912 && m == 7 && d >= 30)) {
		printf("taisho %d %d %d\n", y - 1912 + 1, m, d);
	} else if (y > 1868 ||
		       (y == 1868 && m > 9) || 
		       (y == 1868 && m == 9 && d >=8)) {
		printf("meiji %d %d %d\n", y - 1868 +1, m, d);
	} else {
		printf("pre-meiji\n");
	}
	return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#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()
using namespace std;
typedef long long ll;

int h,w;
void disp(vector<vector<char>> &M, int x, int y){
    cout << "=================== " << endl;
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            if(x==i&&y==j)cout << '@'<<' ';
            else cout << M[i][j]<<" ";
        }
        cout  << endl;
    }
    cout << "=================== " << endl;


}

int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
int main(){
    
    cin >> h >> w;
    vector<vector<char>> M(h+2, vector<char>(w+2));
    REP(j,w+2) M[0][j]='.';
    REP(i,h){
        M[i+1][0]='.';
        REP(j,w) cin >> M[i+1][j+1];
        M[i+1][w+1]='.';
    }
    REP(j,w+2) M[h+1][j]='.';



    bool can_solve=true;
    for(int x=1; x<=h;x++){
        for(int y=1; y<=w; y++){
            if(M[x][y]=='.')continue;
            bool exist = false;
            // disp(M,x,y);
            for(int i=0; i<4; i++)
                {
                    // cout << "target is "<< M[x+dx[i]][y+dy[i]] << endl;
                    if(M[x+dx[i]][y+dy[i]]=='#'){
                        exist=true;
                        break;
                    } 
                    
                }
            // if(exist) cout << "OK" << endl;
            // else cout << "No" << endl;
            if(!exist) can_solve=false;
        }
    }
    cout << (can_solve?"Yes":"No") << endl;
    return 0;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){

  string S;
  cin>>S;
  bool flag=0;
  for(int i=1;i<=(int)(S.length()-1);i++){
  
    for(int j=0;j<=i-1;j++){
    
      if(S[j]==S[i]){
      
        flag=1;
        break;
      }
    }
    if(flag==1)break;
  }
  if(flag==1)cout<<"no";
  else cout<<"yes";
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}
template <typename T, typename... Args>
inline void read(T &t, Args &... args)
{
    read(t);
    read(args...);
}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 9;

vector<pll> v;

struct node
{
    int x, y;
} p[200200], s[200200];

int n, sz;

inline int cmp(node a, node b)
{
    double k1, k2;
    k1 = atan2((a.y - p[1].y), (a.x - p[1].x));
    k2 = atan2((b.y - p[1].y), (b.x - p[1].x));
    if (k1 == k2)
        return a.x < b.x;
    return k1 < k2;
}

inline int getdis(node a, node b)
{
    //return 1ll * (a.x - b.x) * (a.x - b.x) + 1ll * (a.y - b.y) * (a.y - b.y);
    return abs(a.x - b.x) + abs(a.y - b.y);
}

inline int getcj(node a, node b, node c)
{
    return 1ll * (b.x - a.x) * (c.y - a.y) - 1ll * (b.y - a.y) * (c.x - a.x);
}

inline int bj(node a, node b)
{
    return (a.y > b.y || (a.y == b.y) && (a.x > b.x));
}

inline void gettb() //这一部分的代码注释最好在我的凸包讲解那里看（不过我还是复制粘贴了过来）
{
    p[0].x = p[0].y = 0x3f3f3f3f;
    register int i, j;
    for (i = 1; i <= n; i++)
        if (bj(p[0], p[i]))
            p[0] = p[i], j = i; //找到最小边的点，并且把他放到第一位
    swap(p[j], p[1]);
    sort(p + 2, p + n + 1, cmp); //对后面的点极点排序
    s[++sz] = p[1];
    s[++sz] = p[2]; //让前两个点入栈（他们一定是在凸包上）
    for (i = 3; i <= n;)
    {
        if (sz >= 2 && getcj(s[sz - 1], p[i], s[sz]) >= 0)
            sz--; //就是上面说的 (这里的上图在凸包的那里)
        else
            s[++sz] = p[i++];
    }
    s[0] = s[sz]; //记得凸包要首尾相连
}

inline int getmmx()
{
    int ans = 0;
    if (sz == 2)
        return getdis(s[0], s[1]); //只有两个点的时候不能构成三角形，所以要特判
    int j = 2;
    for (int i = 0; i < sz; i++)
    {
        while (getcj(s[i], s[i + 1], s[j]) < getcj(s[i], s[i + 1], s[j + 1]))
            j = (j + 1) % sz;
        if (max(getdis(s[i], s[j]), getdis(s[i + 1], s[j])) > ans)
        {
            ans = max(getdis(s[i], s[j]), getdis(s[i + 1], s[j]));
        }
    }
    return ans; //最后就是直径了
}

signed main()
{
    int bb;
    read(bb);
    pll tmp;
    for (int i = 1; i <= bb; ++i)
    {
        read(tmp.first, tmp.second);
        v.emplace_back(tmp);
    }
    sort(v.begin(), v.end());
    unique(v.begin(), v.end());
    if (v.size() <= 1)
    {
        cout << 0 << endl;
        return 0;
    }
    n = v.size();
    for (int i = 1; i <= n; ++i)
    {
        p[i].x = v[i - 1].first;
        p[i].y = v[i - 1].second;
    }
    gettb();
    cout << getmmx() << endl;
    return 0;
}


Measured memory_bytes: 9952
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
using std::swap;
vector <int> d;

int main() {
	int N,s,t;
	cin >> N;
	d.resize(N);
	for (int i = 0; i < N; ++i)cin >> d[i];
	sort(d.begin(), d.end());
	t = d[N / 2] - d[(N / 2) - 1];
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>

using namespace std;

int main()
{
	int n,sum;
	while(~scanf("%d",&n))
	{
		sum=(24-n)+24;
		printf("%d\n",sum);
	}
	return 0;
}


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

int main()
{
    while (true)
    {
        double x[4];
        double y[4];
        if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
                x+0, y+0, x+1, y+1, x+2, y+2, x+3, y+3) != 8)
            break;

        complex<double> c[4];
        for (int i=0; i<4; i++)
            c[i] = complex<double>(x[i], y[i]);

        int l = 0;
        int r = 0;
        for (int i=0; i<4; i++)
        {
            complex<double> a = c[(i+2)%4] - c[(i+1)%4];
            complex<double> b = c[(i+1)%4] - c[(i+0)%4];
            (arg(a/b)>0 ? l : r)++;
        }
        puts(l==4 || r==4 ? "YES" : "NO");
    }
}

Measured memory_bytes: 2788
#include <iostream>
using namespace std;
int main () {

	long long int x, y, z;
	cin >> x >> y;
	z = x;
	z *= y;
	z -= x;
	if (z % y == 0) {
		cout << -1;
		return 0;
	}
	cout << z;

	return 0;
}

Measured memory_bytes: 256
H,W,K=map(int, input().split())
S=[input()for _ in range(H)]
A=[[0]*W for _ in range(H)]
c=0
for i in range(H):
    d=0
    for j in range(W):
        if S[i][j]=="#":
            c+=1
            d=c
        A[i][j]=d
    p=0
    for j in range(W-1,-1,-1):
        if A[i][j]==0:
            A[i][j]=p
        p=A[i][j]
    if S[i].find("#")<0 and i!=0:
        A[i][:]=A[i-1]
for i in range(H-2,-1,-1):
    if all(a==0 for a in A[i]):
        A[i][:]=A[i+1]
for i in range(H):
    print(*A[i])

Measured memory_bytes: 7568
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vso(x) sort( x.begin() , x.end() )
#define vre(x) reverse( x.begin() , x.end() ) ;
#define aso(x) sort( x , x + x.size() )
#define are(x) reverse( x , x + x.size() )
#define print(x) cout << x << endl 
#define no cout << "NO\n" 
#define yes cout << "YES\n"
typedef long long ll ; 
typedef unsigned long long ull ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("problem_name.out", "w", stdout) ;
    //freopen("problem_name.in", "r", stdin) ;
    //ull h = 798568968205 ; srand(h) ;
    ll n ; cin >> n ;
    map < string , ll > m ;
    for ( int i = 0 ; i < n ; i++ )
    {
        string s ; cin >> s ;
        m[s]++ ;
    }
    cout << "AC x " << m["AC"] << endl ;
    cout << "WA x " << m["WA"] << endl ;
    cout << "TLE x " << m["TLE"] << endl ;
    cout << "RE x " << m["RE"] << endl ;
}

Measured memory_bytes: 3664
/*input
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
*/
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define f first
#define s second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int const mod = 1e9+7;
int power(int x, int y, int mod = 2e18){ int ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
int gcd(int a , int b){if(a==0)return b;return gcd(b%a,a);}
int a[1001][1001];
int dp[1001][1001];
int n,m;
int solve(int i,int j){

	if(i>=n || j>=m || i<0 || j<0 || a[i][j] ){
		return 0;
	} 
	if(i==n-1&& j == m-1)
		return 1;
	if(dp[i][j]!=-1)
		return dp[i][j];
	return dp[i][j] = (solve(i+1,j) + solve(i,j+1)) % mod;
}

signed main() {
	IOS;
	
	cin>>n>>m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++){
			char c;
			cin>>c;
			if(c=='#')
				a[i][j]=1;
			else
				a[i][j]=0;
		}

	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0)%mod<<endl;
return 0;
}

Measured memory_bytes: 16000
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, m] <- getIntList
    sss <- map tail <$> replicateM m getIntList
    ssps <-zip sss <$> getIntList
    let bss = sequence $ replicate n [False, True]
    print $ length [() | bs <- bss, solve bs ssps]

solve bs ssps = and $ map (check bs) ssps
check bs (ss, p) = (\i -> i `mod` 2 == p) . length . filter id $ map (\i -> bs !! (i - 1)) ss

Measured memory_bytes: 1020
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 110;
const int Maxm = 1010;
const int INF = (int) 1e7;

int g[Maxn][Maxn];
int a[Maxm], b[Maxm], c[Maxm];

int n, m;

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        fill(g[i], g[i] + n, INF);
        g[i][i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }

        }
    }

    int cnt = 0;
    for (int i = 0; i < m; ++i) {
        bool use = false;
        for (int j = 0; j < n; ++j) {
            if (g[j][b[i]] == g[j][a[i]] + c[i]) use = true;
        }
        if (use) cnt++;
    }

    cout << m - cnt << endl;
}

Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

n,k = map(int,stdin.readline().rstrip().split())
a = list(map(int,stdin.readline().rstrip().split()))
a = [0]+a
bunki = 0
now = a[1]
lip = [1]
se = set()
while True:
    bunki += 1
    if now in se:
        break
    se.add(now)
    lip.append(now)
    now = a[now]

tenki = lip.index(now)
lis = lip[tenki:]
roop = bunki-tenki

if k < tenki: 
    print(lip[k])
    exit()
k -= tenki

print(lis[k%roop])

Measured memory_bytes: 127148
n, a, b = (int(i) for i in input().split())
s=0
h=0
f=0
for i in range(1,n+1):
  j=0
  s=0
  f=i
  while j<5:
    s += i%10
    i = int(i/10)
    j=j+1
    #if i==0:
     # break
  if s>=a and s<=b:
    h = h + f
    
print(h)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int calc(map<int, bool> ids, int s, int k) {
    int res = 0;
    int bfr = -INF;
    for (auto id : ids) {
        if (!ids[id.fi-k]) {
            res += s;
        }
        else {
            ids[id.fi] = false;
        }
    }
    return res;
}

int main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;

    string t;
    cin >> t;

    map<int, bool> R, S, P;
    rep(i, n) {
        if (t[i] == 'r') R[i] = true;
        if (t[i] == 's') S[i] = true;
        if (t[i] == 'p') P[i] = true;
    }

    int ans = 0;
    ans += calc(R, p, k);
    ans += calc(S, r, k);
    ans += calc(P, s, k);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9472
import math

a, b, x = map(int, input().split())

if a * a * b >= 2 * x:
    y = ((x / a) / b) * 2
    print(math.degrees(math.atan(b/y)))
else:
    y = ((b * a - x / a) / a) * 2
    print(math.degrees(math.atan(y/a)))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  double a,b,c,d,e,f;
  double x,y; 
  while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){
    x=(c*e-b*f)/(a*e-b*d);
    if(x==-0){
      x=0;
    }
    y=(d*c-a*f)/(d*b-a*e);
    if(y==-0){
      y=0;
    }
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 1236
s = []
3.times { s << gets.strip }
temp = s[0]
while true
    check = temp.slice!(0)
    case check
        when "a"
            if s[0] == ""
                puts "A"
                exit
            end
            temp = s[0]
        when "b"
            if s[1] == ""
                puts "B"
                exit
            end
            temp = s[1]
        when "c"
             if s[2] == ""
                puts "C"
                exit
            end
            temp = s[2]
    end
end



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> l(n);
    REP(i,n)cin >> l[i];
    sort(ALL(l));
    int64 ans = 0;
    REP(i,n)FOR(j,i+1,n){
        ans += lower_bound(ALL(l),l[i]+l[j]) - upper_bound(ALL(l),abs(l[i]-l[j]));
        if(l[i] > abs(l[i]-l[j]))ans--;
        if(l[j] > abs(l[i]-l[j]))ans--;
    }
    ANS(ans/3);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

long MOD;

long pow(long a, long b, long mod) {
    long res = 1;
    while (b > 0) {
        if (b & 1) {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

// @author: pashka

long Q[3001][3001];
long C[3001][3001];

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    cin >> MOD;

    cerr << "1\n";
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0) {
                Q[i][j] = j == 0;
            } else if (j == 0) {
                Q[i][j] = 1;
            } else {
                Q[i][j] = (Q[i - 1][j - 1] + Q[i - 1][j] * (j + 1)) % MOD;
            }
//            cout << i << " " << j << " " << Q[i][j] << "\n";
        }
    }

    cerr << "2\n";

    for (int i = 0; i <= n; i++) {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; j++) {
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
        }
    }

    cerr << "3\n";

    long ans;
    for (int k = 0; k <= n; k++) {
        long z = pow(2, pow(2, k, MOD - 1), MOD);
        long p2 = 1;
        long dp = pow(2, k, MOD);
        for (int j = 0; j <= n; j++) {
            long w = p2;
            p2 = (p2 * dp) % MOD;
            w = (w * z) % MOD;
            w = (w * Q[n - k][j]) % MOD;
            w = (w * C[n][k]) % MOD;
//            cout << k << " " << j << " " << w << "\n";
            if ((n - k) % 2) {
                w = (MOD - w) % MOD;
            }
            ans = (ans + w) % MOD;
        }
    }

    cerr << "4\n";

    cout << ans;

    return 0;
}

Measured memory_bytes: 139264
#include<bits/stdc++.h>
using namespace std;
int a[105],n;
int cal(int x)
{
    int f=0,g=0;
    for(int i=1;i<=x;i++)
        f+=a[i];
    for(int i=x+1;i<=n;i++)
        g+=a[i];
    return abs(f-g);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int ans=1e9;
    for(int i=1;i<n;i++)
        ans=min(ans,cal(i));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll H,W;cin>>H>>W;
    char m[H][W];
    char M[H][W];
    REP(i,H){
        REP(j,W){
            cin>>m[i][j];
        }
    }
    ll K=8;
    ll dy[K]={-1,-1,-1,0,0,1,1,1};
    ll dx[K]={-1,0,1,-1,1,-1,0,1};
    REP(i,H){
        REP(j,W){
            if(m[i][j]=='#'){
                M[i][j]='#';
                continue;
            }
            ll cnt=0;
            REP(k,K){
                ll x=j+dx[k],y=i+dy[k];
                if(0<=x&&x<W and 0<=y&&y<H){
                    if(m[y][x]=='#')cnt++;
                }
            }
            M[i][j]=cnt+'0';
        }
    }
    REP(i,H){
        REP(j,W){
            cout<<M[i][j]<<(j==W-1?"\n":"");
        }
    }
}

Measured memory_bytes: 256
#include <vector>
#include <functional>
#include <deque>
#include <stdexcept>

template<typename T, typename Container = ::std::vector<T>, typename Compare = ::std::greater<typename Container::value_type>>
class sliding_window {
    using iterator_type = typename Container::const_iterator;
    using value_compare = Compare;
    using value_type = T;
    using const_reference = const value_type &;

    iterator_type right_bound, left_bound, end;
    value_compare comp;
    size_t length;
    ::std::deque<value_type> val;

public:
    void push() {
        //if (left_bound == end) {
        //    throw ::std::runtime_error("already reached to the end");
        //}
        const auto &tmp = *left_bound;
        while (!val.empty() && comp(val.back(), tmp))val.pop_back();
        val.push_back(tmp);
        ++left_bound;
        ++length;
    }

    void pop() {
        //if (right_bound == left_bound) {
        //    throw ::std::runtime_error("interval is empty");
        //}
        const auto &tmp = *right_bound;
        if (tmp == val.front())val.pop_front();
        ++right_bound;
        --length;
    }

    sliding_window(iterator_type _begin, iterator_type _end, const Compare &_comp = Compare()) : length(0),
                                                                                                 right_bound(_begin),
                                                                                                 left_bound(_begin),
                                                                                                 end(_end), comp(_comp),
                                                                                                 val({}) {}

    const size_t size() const {
        return length;
    }

    const_reference top() const {
        return val.front();
    }

    void resize(size_t n) {
        if (n < length) {
            while (n < length) {
                pop();
            }
        } else {
            while (n > length) {
                push();
            }
        }
    }

    void forward() {
        if (left_bound != end)push();
        pop();
    }

};

#include <iostream>
#include <algorithm>

int main() {
    unsigned long long N, M, K;
    scanf("%llu%llu%llu", &N, &M, &K);

    std::vector<unsigned long long> A(N), dp1(N), dp2(N);
    for (auto &i : A)scanf("%llu", &i);

    std::copy(A.begin(), A.end(), dp1.begin());

    for (unsigned long long i = 1; i != K; ++i) {
        sliding_window<unsigned long long, std::vector<unsigned long long>, std::less<>> slidingWindow(
                dp1.begin(), dp1.end());
        std::transform(A.begin(), A.end(), dp2.begin(), [&i](auto a) { return a * (i + 1); });

        for (unsigned long long j = 0; j != N; ++j) {
            if (j >= i)dp2[j] += slidingWindow.top();
            if (slidingWindow.size() == M)slidingWindow.pop();
            slidingWindow.push();
        }

        std::swap(dp1, dp2);
    }

    std::cout << *std::max_element(dp1.begin(), dp1.end()) << std::endl;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>

using namespace std;

int main() {
  int r, c;
  cin >> r >> c;
  std::vector<std::vector<int>> table;
  for (int i = 0; i < r; ++i) {
    std::vector<int> row;
    for (int j = 0; j < c; ++j) {
      int x;
      cin >> x;
      row.push_back(x);
    }
    table.push_back(row);
  }
  for (int i = 0; i < r; ++i) {
    int sum = 0;
    for (int j = 0; j < c; ++j) {
      sum += table[i][j];
    }
    table[i].push_back(sum);
  }

  {
    std::vector<int> row;
    for (int j = 0; j < c + 1; ++j) {
      int sum = 0;
      for (int i = 0; i < r; ++i) {
        sum += table[i][j];
      }
      row.push_back(sum);
    }
    table.push_back(row);
  }

  for (int i = 0; i < r + 1; ++i) {
    for (int j = 0; j < c + 1; ++j) {
      if (j != 0) {
        cout << " ";
      }
      cout << table[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 3128
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n, l;
	cin >> n >> l;
	int sum = 0;
	int a = 0;
	int min = 300;
	int i;
	for (i = 1; i <=  n; i++)
	{
		sum += l + i - 1;
		if (abs(l + i - 1) < min)
		{
			min = abs(l + i - 1);
			a = l + i - 1;
		}
	}
	cout << sum - a << endl;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

//Acceleration of Network
public class Main{

	long[] w;
	int[] t, x;
	Map<Integer, Set<Integer>> s0 = new HashMap<Integer, Set<Integer>>(), s1 = new HashMap<Integer, Set<Integer>>(), s2 = new HashMap<Integer, Set<Integer>>();
	Map<Integer, Set<Integer>> e0 = new HashMap<Integer, Set<Integer>>(), e1 = new HashMap<Integer, Set<Integer>>(), e2 = new HashMap<Integer, Set<Integer>>();

	void reg(Map<Integer, Set<Integer>> set, int day, int id){
		if(set.containsKey(day))set.get(day).add(id);
		else{
			Set<Integer> s = new HashSet<Integer>();
			s.add(id);
			set.put(day, s);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), Q = sc.nextInt(), L = 3652425;
		w = new long[N];
		t = new int[N]; x = new int[N];
		PriorityQueue<Integer> qw = new PriorityQueue<Integer>(N+1, new Comparator<Integer>() {
			public int compare(Integer o1, Integer o2) {
				return Long.signum(w[o1]-w[o2]);
			}
		});
		int[] res = new int[N];
		long[] y = new long[L+1];
		Arrays.fill(res, L+1);
		long d1 = 0, d2 = 0, dt1 = 0, dt2 = 0;
		int n0 = 0, n2 = 0;
		for(int i=0;i<N;i++){
			w[i] = sc.nextLong(); t[i] = sc.nextInt(); x[i] = sc.nextInt();
			if(w[i]==0){
				res[i] = 0;
				if(t[i]==0){
					reg(s0, 1, i);
					reg(e0, x[i]+1, i);
				}
				else if(t[i]==1){
					reg(s1, 1, i);
					reg(e1, x[i]+1, i);
				}
				else{
					reg(s2, 1, i);
					reg(e2, x[i]+1, i);
				}
			}
			else qw.add(i);
		}
		for(int i=1;i<=L;i++){
			y[i] = y[i-1]+1;
			if(s0.containsKey(i)){
				n0+=s0.get(i).size();
			}
			if(e0.containsKey(i)){
				n0-=e0.get(i).size();
			}
			y[i]+=n0;
			if(s1.containsKey(i)){
				dt1+=s1.get(i).size();
			}
			if(e1.containsKey(i)){
				dt1-=e1.get(i).size();
				for(int id:e1.get(i))d1-=x[id];
			}
			d1+=dt1;
			y[i]+=d1;
			if(s2.containsKey(i)){
				int D = s2.get(i).size();
				n2+=D;
				dt2-=D;
			}
			if(e2.containsKey(i)){
				int D = e2.get(i).size();
				for(int id:e2.get(i)){
					dt2-=2*x[id]-1;
					d2-=x[id]*x[id];
				}
				n2-=D;
			}
			dt2+=2*n2;
			d2+=dt2;
			y[i]+=d2;
			while(!qw.isEmpty() && w[qw.peek()]<=y[i]){
				int id = qw.poll();
				res[id] = i;
				if(t[id]==0){
					reg(s0, i+1, id);
					reg(e0, i+x[id]+1, id);
				}
				else if(t[id]==1){
					reg(s1, i+1, id);
					reg(e1, i+x[id]+1, id);
				}
				else{
					reg(s2, i+1, id);
					reg(e2, i+x[id]+1, id);
				}
			}
		}
		for(int i=0;i<N;i++)System.out.println(L<res[i]?"Many years later":res[i]);
		while(Q--!=0)System.out.println(y[sc.nextInt()]);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 42000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int a,b,c; cin >> a >> b >> c;
	int ans = a+b+c;
	ans += max({a,b,c}) * 10;
	ans -= max({a,b,c});
	cout << ans << endl;
	return (0);
}

Measured memory_bytes: 256
/*
 * Author - Abhas Jain
 * Code is inside the solve function
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
void solve() 
{
	ll n, d;
	cin >> n >> d;
	int count = 0;
	for (int i = 0; i < n; ++i) {
		ll a, b;
		cin >> a >> b;
		if (a * a + b * b <= d * d) count++;
	}
	cout << count << endl;
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct State {
  // d:??\??£???????????????
  int y, x, d, p, q, cost;
  State(){}
  State(int y, int x, int d, int p, int q, int cost):
    y(y), x(x), d(d), p(p), q(q), cost(cost){}
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};

int N, M, A;
char mas[101][101];
int sy, sx, gy, gx;
int mincost[4][11][11][101][101];

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

bool in(int y, int x) {
  return 0<=y&&y<N&&0<=x&&x<M;
}

int dijkstra() {
  rep(i, 4) rep(j, 11) rep(k, 11) {
    rep(y, 101) rep(x, 101) mincost[i][j][k][y][x] = inf;
  }
  priority_queue<State> que;
  que.push(State(sy, sx, 0, A, A, 0));
  mincost[0][A][A][sy][sx] = 0;
  while(!que.empty()) {
    State s = que.top(); que.pop();
    //cout<<s.y<<" "<<s.x<<" "<<s.d<<" "<<s.cost<<endl;
    if(s.y == gy && s.x == gx) return s.cost;
    if(mincost[s.d][s.p][s.q][s.y][s.x] < s.cost) continue;
    if(s.y == sy && s.x == sx) {
      if(s.cost > 0 && (s.d == 0 || s.d == 2)) continue;
      int ny = s.y+dy[(s.d+2)%4], nx = s.x+dx[(s.d+2)%4];
      if(in(ny, nx) && mas[ny][nx] != '#') {
	if(s.cost < mincost[s.d][s.p][s.q][ny][nx]) {
	  que.push(State(ny, nx, s.d, s.p, s.q, s.cost));
	  mincost[s.d][s.p][s.q][ny][nx] = s.cost;
	}
      }
      continue;
    }
    rep(i, 4) {
      if(s.d == i) continue;
      int np = s.p, nq = s.q, ncost = s.cost;
      if(s.d == 0) {
	if(i == 1) nq--, ncost++;
	else if(i == 3) np--, ncost++;
      } else if(s.d == 1) {
	if(i == 0) nq--, ncost++;
	else if(i == 2) np--, ncost++;
      } else if(s.d == 2) {
	if(i == 1) np--, ncost++;
	else if(i == 3) nq--, ncost++;
      } else if(s.d == 3) {
	if(i == 0) np--, ncost++;
	else if(i == 2) nq--, ncost++;
      }
      if(np < 0 || nq < 0) continue;
      int ny = s.y+dy[i], nx = s.x+dx[i];
      if(!in(ny, nx) || mas[ny][nx] == '#') continue;
      if(ncost < mincost[(i+2)%4][np][nq][ny][nx]) {
	//cout<<s.y<<" "<<s.x<<" "<<s.d<<" "<<ny<<" "<<nx<<" "<<(i+2)%4<<" "<<ncost<<endl;
	que.push(State(ny, nx, (i+2)%4, np, nq, ncost));
	mincost[(i+2)%4][np][nq][ny][nx] = ncost;
      }
    }
  }
  return -1;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M >> A;
  rep(i, N) rep(j, M) {
    cin >> mas[i][j];
    if(mas[i][j] == 'S') sy = i, sx = j;
    else if(mas[i][j] == 'G') gy = i, gx = j;
  }
  cout << dijkstra() << endl;

  return 0;
}

Measured memory_bytes: 42336
N = input()

DP_just = [0]
DP_plus = [1]

for c in N:
    d = int(c)
    last_just = DP_just[-1]
    last_plus = DP_plus[-1]
    DP_just.append(min(last_just + d, last_plus + 10 - d))
    d += 1
    DP_plus.append(min(last_just + d, last_plus + 10 - d))

print(DP_just[-1])

Measured memory_bytes: 84696
module SS = Set.Make(String);;

let _ =
  let n = read_int () and
      s = SS.empty
  in
  let rec read s = function
      0 -> ()
    | i ->
       let (op,key) =
         match read_line () |> Str.split (Str.regexp " ") with
           [h;t] -> (h,t)
         | _ -> ("","")
       in
       if op = "insert" then
         read (SS.add key s) (i-1)
       else if op = "find" then
         begin
           if SS.mem key s then print_endline "yes"
           else print_endline "no"
          ;read s (i-1)
         end
  in read s n;;

Measured memory_bytes: 37200
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(n) for (int i = 0; i < (n); ++i)
int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0, cnt = 1;
    while (cnt < b)
    {
        cnt += a-1;
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n,ans(0);
    string s;
    cin>>n>>s;
    map<char,int> m;
    for(auto x: s)
      m[x]++;

    int triples = m['R'] * m['G'] * m['B'];

    for (int i = 0; i < n; ++i)
    {
      for (int j = i+2; j < n; ++j)
      {
        if((j-i)%2==0&&s[i]!=s[j])
        {
          int k = (j+i)/2;

          if(s[j]!=s[k]&&s[i]!=s[k])
              ans++;
        }
      }
    }
    ans = triples - ans;
    cout<<ans;

    printclock;
    return 0;
}


Measured memory_bytes: 3796
from itertools import combinations, product
*_,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
ab=[]
for i,j in product(a,b):
    ab.append(i+j)
ab.sort(reverse=True)
ab = ab[:k]
abc = []
for i,j in product(ab,c):
    abc.append(i+j)

abc.sort(reverse=True)
print(*abc[:k],sep="\n")

Measured memory_bytes: 144584
import math

n, d = [int(i) for i in input().split()]
xs = []
for i in range(n):
    xs.append([int(j) for j in input().split()])

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        A = xs[i]
        B = xs[j]
        sum_ = 0
        for a, b in zip(A, B):
            sum_ += (a - b)**2
        decimal, integer = math.modf(math.sqrt(sum_))
        if decimal == 0:
            count += 1

print(count)


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int x[505];
int t[505];
int ans[252525];
int cnt[505];
int mk[252525];
bool cmp(const int &a,const int &b)
{
	return x[a]<x[b];
}
int n,nn;
bool jud()
{
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<=nn;i++)
	{
		cnt[ans[i]]++;
		if(mk[i])
			if(mk[i]!=ans[i]||cnt[ans[i]]!=mk[i])
				return false;
	}
	return true;
}
int main()
{
	int now=1,nd;
	scanf("%d",&n);
	nn=n*n;
	memset(ans,0,sizeof(ans));
	memset(mk,0,sizeof(mk));
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
		ans[x[i]]=i;
		mk[x[i]]=i;
		t[i]=i;
	}
	sort(t+1,t+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		nd=t[i]-1;
		while(nd)
		{
			while(ans[now])
				now++;
			ans[now]=t[i];
			nd--;
		}
	}
	for(int i=1;i<=n;i++)
	{
		nd=n-t[i];
		while(nd)
		{
			while(ans[now])
				now++;
			ans[now]=t[i];
			nd--;
		}
	}
	if(jud())
	{
		printf("Yes\n");
		for(int i=1;i<=nn;i++)
			printf("%d ",ans[i]);
	}
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
  #include <algorithm>
  #include <vector>
  #include <cmath>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <iomanip>
  #include <stack>
  #include <queue>
  #include <deque>
  using namespace std;

  int main()
  {
   //   freopen("inverse.in","r",stdin);
   //   freopen("inverse.out","w",stdout);
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
      long long a,b,c;
      cin>>a>>b>>c;
      long long ans=0;
      if(c<=b){
          cout<<b+c;
          return 0;
      }
      else{
          ans+=b+b;
          c-=b;
          ans+=min(a+1,c);
          cout<<ans;
          return 0;
      }
      return 0;
}


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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

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

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T &b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T &b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int mod = 1e9+7;

int main()
{
    int mem[3];
    memset(mem,-1,sizeof(mem));
    int N;cin >> N;
    LL ans = 1;
    _for(i,0,N){
        int a;cin >> a;
        int cnt = 0;
        _for(j,0,3) if(mem[j]+1 == a) cnt++;
        ans *= cnt;
        ans%=mod;
        _for(j,0,3) if(mem[j] +1 == a){
            mem[j]++;
            break;
        }
    }
    cout << ans <<endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int main () {
	ll i, j, n;
	ll m = 1;
	ll ret;
	
	cin >> n >> m;
	
	i = (m - 2*n)/2;
	j = (4*n - m)/2;

	if ( i < 0 || j < 0 || (i+j) != n ) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3628
s=input()

l=set()
for i in range(4):
    l.add(s[i])

ans='No'
if len(l)==2:
    if (s[0]==s[1] and s[2]==s[3]) or (s[0]==s[2] and s[1]==s[3]) or(s[0]==s[3] and s[1]==s[2]):
        ans='Yes'

print(ans)

Measured memory_bytes: 3064
n=int(input())
ans=[]
mins=55
a=[list(input()) for _ in range(n)]
for i in a:
  if mins > len(i):
    mins=min(mins,len(i))
    m=list(i)
for i in m:
  flg=0
  for j in a:
    if i not in j:
      flg=1
  if flg==0:
    ans.append(i)
    for j in a:
      j.remove(i)
ans.sort()
print(*ans,sep='')

Measured memory_bytes: 9216
import collections
N=int(input())
V=list(map(int,input().split()))
V1=collections.Counter(V[0::2]).most_common()
V2=collections.Counter(V[1::2]).most_common()
V1.append((0,0))
V2.append((0,0))
if V1[0]!=V2[0]:
    print(N-V1[0][1]-V2[0][1])
else:
    print(min(N-V1[0][1]-V2[1][1],N-V1[1][1]-V2[0][1]))


Measured memory_bytes: 20700
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE=200010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
  
  invinit();
  
  long long n,m,k;
  cin>>n>>m>>k;
  
  long long sx=0,sy=0;
  long long temp;
  for(long long dx=1;dx<n;dx++){
    temp = mod(mod((n-dx)*m)*m);
    temp = mod(temp*comb(n*m-2,k-2));
    temp = mod(temp*dx);
    sx = mod(sx + temp);
  }
  for(long long dy=1;dy<m;dy++){
    temp = mod(mod((m-dy)*n)*n);
    temp = mod(temp*comb(n*m-2,k-2));
    temp = mod(temp*dy);
    sy = mod(sy + temp);
  }
  
  long long ans;
  ans = mod(sx+sy);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5120