akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  for(int i=0; i<N-1; i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> dist(N,-1);
  queue<int> que;
  que.push(0);
  dist[0] = 0;
  while(que.size()){
    int v = que.front();
    que.pop();
    for(int nv: G[v]){
      if(dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }
  int odd=0,even=0;
  for(int i=0; i<N; i++){
    if(dist[i]%2){
      odd++;
    }else{
      even++;
    }
  }
  vector<int> ans(N);
  int c1=1,c2=2,c3=3;
  if(odd > N/3 and even > N/3){
    for(int i=0; i<N; i++){
      if(dist[i]%2 and c1<=N){
        ans[i] = c1;
        c1 += 3;
      }else if(dist[i]%2==0 and c2<=N){
        ans[i] = c2;
        c2 += 3;
      }else{
        ans[i] = c3;
        c3 += 3;
      }
    }
  }else if(odd <= N/3){
    for(int i=0; i<N; i++){
      if(dist[i]%2){
        ans[i] = c3;
        c3 += 3;
      }else{
        if(c1<=N){
          ans[i] = c1;
          c1 += 3;
        }else if(c2<=N){
          ans[i] = c2;
          c2 += 3;
        }else{
          ans[i] = c3;
          c3 += 3;
        }
      }
    }
  }else{
    for(int i=0; i<N; i++){
      if(dist[i]%2){
        if(c1<=N){
          ans[i] = c1;
          c1 += 3;
        }else if(c2<=N){
          ans[i] = c2;
          c2 += 3;
        }else{
          ans[i] = c3;
          c3 += 3;
        }
      }else{
        ans[i] = c3;
        c3 += 3;
      }
    }
  }
  for(int i=0; i<N; i++){
    cout << ans[i] << (i!=N-1 ? " " : "\n");
  }
  return 0;
}


Measured memory_bytes: 15220
#include <vector>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

int main(){
	const string tmp(1048576, '0');

	istream_iterator<double> first(cin), last;
	vector<double> v(first, last);
	printf("%f", *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()));
	
	for(int i = 0; i < 8; ++i){
		fputs(tmp.c_str(), stdout);
		fflush(stdout);
	}
	
	puts("");
}

Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
const long double PI=acos(-1);
typedef long long int ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fo(i,n) for(int i=0;i<(int)n;i++)
#define fo1(i,n) for(int i=1;i<=(int)n;i++)
#define deb(x) cout<<#x<<"="<<x<<endl

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);int tc=1;
	vector<int> x;
	int c=0;
	fo1(i,100)
	{
		fo1(j,100)
		{
			fo1(k,100)
			{
				c=(i*i+j*j+k*k+i*j+i*k+j*k);
				if(c<=10000) x.push_back(c);
			}
		}
	}
	cin>>tc;
	fo1(t,tc)cout<<count(all(x),t)<<"\n";
	return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include <cstring>

using namespace std;

bool match(char r[2][8], char ad[2][8]){
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 8; j++){
			if(r[i][j] != '?' && r[i][j] != ad[i][j]) return false;
		}
	}
	return true;
}

int main(){
	int n,m;
	cin >> n >> m;
	while(n+m){
		char c[100];
		cin.getline(c,sizeof c);
		char r[1024][2][8];
		bool p[1024] = {false};
		for(int i = 0; i < n; i++){
			cin.getline(c,sizeof c);
			int idx = 0;
			while(c[idx++] != ' ');
			p[i] = c[0] == 'p';
			for(int j = 0; j < 8; j++){
				r[i][0][j] = c[idx+j];
				r[i][1][j] = c[idx+9+j];
			}
		}
		int count = 0;
		char list[1024][100];
		for(int i = 0; i < m; i++){
			char packet[100];
			cin.getline(packet,sizeof packet);
			char ad[2][8];
			for(int j = 0; j < 8; j++){
				ad[0][j] = packet[j];
				ad[1][j] = packet[9+j];
			}
			for(int j = n-1; 0 <= j; j--){
				if(match(r[j],ad)){
					if(p[j]) strcpy(list[count++],packet);
					break;
				}
			}
		}
		cout << count << endl;
		for(int i = 0; i < count; i++){
			cout << list[i] << endl;
		}
		cin >> n >> m;
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		int ans = 0;
		for(int i = 1; i < N; ++i)
		{
			int sum = 0;
			for(int j = i; j < N; ++j)
			{
				sum += j;
				if(sum == N)
				{
					++ans;
					break;
				}
				else if(sum > N)
				{
					break;
				}
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(){
    int a,b,k;
    scanf("%d %d",&a,&b);
    if(a > b){
        for(k = b + 1;k <= a;k++){
            if(k - b == a - k){
                printf("%d\n",k);
                return 0;
            }
        }
        printf("IMPOSSIBLE\n");
    }
    else{
        for(k = a + 1;k <= b;k++){
            if(k - a == b - k){
                printf("%d\n",k);
                return 0;
            }
        }
        printf("IMPOSSIBLE\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for(int i=1; i<=n; i++) {
		int x;
		cin >> x;
		if (x >= k) ans++;
	}
	cout << ans << endl;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();

  bool flg = true;
  for (int i = 0; i < n; i++)
  {
    if(i%2==1){
      if(s[i]=='R') flg=false;
    }
    else{
      if(s[i]=='L') flg=false;
    }
  }
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

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

int main(void)
{
    string s;
    int num = 1000;
    cin >> s;
    rep(i, 3)
    {
        if (s[i] == 'x')
        {
            num -= 100;
        }
    }
    cout << num << endl;
    return 0;
}

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

typedef long long ll; 

int M=1e9+7; 

int sm(int a){
  int ans=0; 
  while(a){
    ans+=a%10; 
    a/=10; 
  }
  return ans; 
}

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

  int   n; cin>>n; 
  int ans=10000; 
  for(int i=1;i<n;i++){
    ans=min(ans,sm(i)+sm(n-i)); 
  }
  cout<<ans; 

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

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

    int n = S.size() - 1;

    // '+'の出現パターンを列挙
    ll sum = 0;  // 合計値の初期化
    for (int bit = 0; bit < (1<<n); ++bit) {

        // パターンに対応する計算
        ll stack = 0;  // スタックの初期化
        for (int i = 0; i < n+1; ++i) {

            // i番目の数をスタックに加算
            stack += S[i] - '0';
            if (bit & (1<<i) || i == n) {
                sum += stack;  // スタックを加算
                stack = 0;  // スタックを初期化
            } else {
                stack = stack * 10;  // スタックを10倍
            }
            //cout << stack << endl;
        }
    }

    cout << sum << endl;

}

Measured memory_bytes: 256
# include <iostream>
# include <vector>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1 || b == 1) {
		if (a == 1 && b != 1) {
			cout << "Alice" << endl;
		}
		else if (a != 1 && b == 1) {
			cout << "Bob" << endl;
		}
		else {
			cout << "Draw" << endl;
		}
	}
	else {
		if (a > b) {
			cout << "Alice" << endl;
		}
		else if (a < b) {
			cout << "Bob" << endl;
		}
		else {
			cout << "Draw" << endl;
		}
	}
}

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

const int inf = 1e9;
typedef pair<int,int> P;
typedef pair<int, P> PP;
int dy[] = {-1, 0, 0, 1};
int dx[] = {0, -1, 1, 0};
struct BFS_Maze{
	vector<vector<int> > d, a;
	int sy, sx, ey, ex, h, w;
	void init(int inputH, int inputW){
		h = inputH, w = inputW;
		d.resize(h+2);
		a.resize(h+2);
		for(int i = 0;i < h+2;i++){
			d[i].resize(w+2);
			a[i].resize(w+2);
		}
	}
	
	void insertion(int y, int x, int v){a[y][x] = v;}
	void start(int y, int x){sy = y;sx = x;}
	void end(int y, int x){ey = y;ex = x;}
	
	int calc(){
		for(int i = 0;i < h+2;i++)d[i].assign(w+2, inf);
		queue<P> q;
		q.push(P(sy, sx));
		d[sy][sx] = 0;
		while(!q.empty()){
			P p = q.front();q.pop();
			int y = p.first, x = p.second;
			if(y == 0 || x == 0)continue;
			if(y == h+1 || x == w+1)continue;
			for(int i = 0;i < 4;i++){
				int yy = y+dy[i], xx = x+dx[i];
				if(d[yy][xx] > d[y][x]+1 && a[yy][xx] == 0){
					d[yy][xx] = d[y][x]+1;
					q.push(P(yy, xx));
				}
			}
		}
		return d[ey][ex];
	}
};

#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = 1;i <= n;i++)
#define fi first
#define se second

char str[1010][1010];
int a[1010][1010];
int main(){
	BFS_Maze BM;
	int h, w, n;
	vector<PP> v;
	scanf("%d%d%d", &h, &w, &n);
	rep(i,h)scanf("%s", str[i]);
	BM.init(h, w);
	
	rep(i,h)rep(j,w){
		if(str[i][j] == 'S'){
			v.push_back(PP(0, P(i+1, j+1)));
		}else if(str[i][j] == 'X'){
			BM.insertion(i+1, j+1, 1);
		}else if(str[i][j] == '.'){
			BM.insertion(i+1, j+1, 0);
		}else{
			v.push_back(PP(str[i][j]-'0', P(i+1, j+1)));
		}
	}
	sort(v.begin(), v.end());
	
	int ans = 0;
	for(int i = 0;i < v.size()-1;i++){
		int y = v[i].se.fi, x = v[i].se.se;
		int yy = v[i+1].se.fi, xx = v[i+1].se.se;
		//M.init(h, w);
		BM.start(y, x);
		BM.end(yy, xx);
		int v = BM.calc();
		ans += v;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 11768
#include <stdio.h>

void renewMaxlen(int *a, int b);

int main() {
    char c[12] = {' '};
    int max_len = 0, len = 0;
    char ins[4] = {'A', 'C', 'G', 'T'};
    scanf("%s",c);
    for(int j = 0; j < 10; j++){
        for(int i = 3; i >= 0; --i){
            if (ins[i] == c[j]) {
                len++;
                break;
            }
            else if(i == 0){
                renewMaxlen(&max_len, len);
                len = 0;
            }
        }
        renewMaxlen(&max_len, len);
    }
    printf("%d\n",max_len);
    return 0;
}

void renewMaxlen(int *a, int b){
    if(*a < b) *a = b;
}

Measured memory_bytes: 128
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, a[N], b[N], c[N], dp[N][3];

int main() {
  init_ios();
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i] >> b[i] >> c[i];
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = a[i]+max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = b[i]+max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = c[i]+max(dp[i-1][0], dp[i-1][1]);
  }
  cout<<max(dp[n][0], max(dp[n][1], dp[n][2]))<<"\n";
}

Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
    long a, b, c, k;
    scanf("%ld %ld %ld %ld", &a, &b, &c, &k);
    if (k % 2 == 1)
        printf("%d\n", b - a);
    else
        printf("%d\n", a - b);
    return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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



signed main() {

    int N;
    cin >> N;
    if (N % 2 == 0) cout << 1.0 / 2 << endl;
    else cout << fixed << setprecision(15) << 1.0 * ((N+1) / 2) / N << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,f,l,i;
    cin>>n;
    map<pair<int,int>,int>mp;
    for(i=1;i<=n;i++)
    {
        x=i;
        while(x)
        {
          f=x;
          x=x/10;
        }
        l=i%10;
       // cout<<f<<" "<<l<<"\n";
        mp[{f,l}]++;
    }
    int ans=0;
    for(i=1;i<=n;i++)
    {
         x=i;
        while(x)
        {
          f=x;
          x=x/10;
        }
        l=i%10;
        ans=ans+mp[{l,f}];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
x, y, z, k = map(int,input().split())
a =list(map(int,input().split()))
b =list(map(int,input().split()))
c =list(map(int,input().split()))
c.sort(reverse=True)
ab = [0]*(x*y)
l = 0
for i in range(x):
    for j in range(y):
        ab[l] = a[i] + b[j]
        l += 1

ab.sort(reverse=True)
#print(ab)
q = 0
i = 0
j = 0
ans = [0]*(k*k)
l = 0
for i in range(min(k,x*y)):
    for j in range(min(k,z)):
        ans[l] = ab[i] + c[j]
        l += 1

ans.sort(reverse=True)
#print(ans)
for i in range(k):
    print(ans[i])

Measured memory_bytes: 159200
#include <iostream>
#include<string.h>
using namespace std;
int main()
{
    int a[100005],n,i,k=0,m;
    int x,y;
    memset(a,0,sizeof(a));
    cin>>n>>m;
    for(i=1; i<=m; i++)
    {
        cin>>x>>y;
        if(k==0)
        {
            k=x;
        }
        if(k>x)
        {
            k=x;
        }
        int s=a[x];
        if(s==0)
        {
            a[x]=y;
        }
        else if(s>y)
        {
            a[x]=y;
        }
    }
    int flag=1,c=a[k];
    for(i=1; i<=n; i++)
    {
        if(a[i]==0)
            continue;
        if(i>=c)
        {
            flag++;
            c=a[i];
        }
        else  if(c>a[i])
        {
            c=a[i];
        }
    }
    cout << flag << endl;
    return 0;
}


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

void warshall_floyd(const int n,
                    vector<vector<int64_t>>& cost) {
    // 辺が存在しない場合は(1LL << 60)で初期化する
    for (auto i = 0; i < n; i++) cost[i][i] = 0;
    for (auto k = 0; k < n; k++) {
        for (auto i = 0; i < n; i++) {
            for (auto j = 0; j < n; j++) {
                // 直接行く場合とkを経由する場合でより小さい距離を採用する
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
}

int main(){
    int h, w; cin >> h >> w;
    vector<vector<int64_t>> cost(10, vector<int64_t>(10));
    for (auto i = 0; i < 10; i++) for (auto j = 0; j < 10; j++) cin >> cost[i][j];
    warshall_floyd(10, cost);
    int64_t ans = 0;
    for (auto i = 0; i < h; i++) {
        for (auto j = 0; j < w; j++) {
            int a; cin >> a;
            if(a == -1) continue;
            ans += cost[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

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

class UnionFind{
  public:
  vector<int> Parent; 
  
  UnionFind(int N){
    Parent = vector<int>(N, -1);
  }
  
  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  int size(int A){
    return -Parent[root(A)]; 
  }
  
  bool connect(int A, int B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    
    if(size(A) < size(B)) swap(A, B);
    
    Parent[A] += Parent[B];
    Parent[B] = A;
    
    return true;
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,m; cin>>n>>m;
  vi X(m), Y(m), Z(m);
  rep(i,m) {
    cin>>X[i]>>Y[i]>>Z[i];
    X[i]--; Y[i]--; Z[i]--;
  }
  auto uf = UnionFind(n);
  rep(i,m){
    uf.connect(X[i],Y[i]);
  }
  map<int, int> ma;
  int ans=0;
  rep(i,n){
    int p=uf.root(i);
    if(ma[p]==0){
      ma[p]++;
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6528
import java.util.*;
 
public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int K = sc.nextInt();
      
        char[] list = S.toCharArray();
        char jd = list[K-1];
      
        for(int i = 0; i < list.length; i++){
          if(list[i] != jd){
            list[i] = '*';
          }
          
          System.out.print(list[i]);
        }
          System.out.println();
   }
}

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

int main(){
  int x,y,top=0;
  char s[100];
  int a[10000];
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      top--;
      x=a[top];
      top--;
      y=a[top];
      a[top]=x+y;
      top++;
    }
    else if ( s[0] == '-' ){
      top--;
      x=a[top];
      top--;
      y=a[top];
      a[top]=y-x;
      top++;
    }
    else if ( s[0] == '*' ){
      top--;
      x=a[top];
      top--;
      y=a[top];
      a[top]=x*y;
      top++;
    }
    else {
      x = atoi(s);
      a[top]=x;
      top++;
    }
  }

  printf("%d\n",a[top-1]);

  return 0;
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
typedef complex<ftype> point;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

const int MAXN = 1e5+5;
const int MOD = 1e9+7;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    double ans = 0;
    int N;
    cin >> N;
    fori(i,N) {
        double a; cin >> a;
        ans += 1/a;
    }

    cout << setprecision(10) << (1/ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for(int i=0;i<n;++i)

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int buf = 0;
    int ans = 0;
    for(int i=0;i<s.size();++i){
        if(s[i]!='A' && s[i]!='T' && s[i]!='G' && s[i]!='C'){
            ans = max(ans, buf);
            buf = 0;
        } else {
            ++buf;
            if(i==s.size()-1){
                ans = max(ans, buf);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,c;cin >>n >>c;
    vvl t(30,vl(100010,0));
    rep(i,n){
        ll a,b,ch;cin >> a >>b >>ch;
        a--;b--;ch--;
        t[ch][a]++;t[ch][b+1]--;
    }
    vl v(100010,0);
    rep(i,30){
        rep(j,100009){
            t[i][j+1]+=t[i][j];
        }
    }
    rep(i,30){
        rep(j,100010){
            if(t[i][j])t[i][j]=1;
        }
    }
    rep(i,30){
        rep(j,100010){
            v[j]+=t[i][j];
        }
    }
    ll ans=0;
    rep(i,100010)chmax(ans,v[i]);
    cout <<ans <<endl;
}

Measured memory_bytes: 24576
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	ll N;
	cin >> N;
	vector<ll> a(3 * N);
	for (int i = 0; i < 3 * N; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	ll res = 0;
	for (int i = 1; i <= N; i++) {
		res += a[3*N - i*2];
	}

	ll tmp = 0;
	for (int i = 1; i <= N; i++) {
		tmp += a[3*N - 1 - i*2];
	}

	res = max(res, tmp);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2560
N, M, X, Y = [int(elem) for elem in input().split(' ')]
x_list = [int(elem) for elem in input().split(' ')]
assert len(x_list)== N
y_list = [int(elem) for elem in input().split(' ')]
assert len(y_list) == M

max_x = max(x_list)
min_y = min(y_list)

for Z in range(X + 1, Y + 1):
    if (max_x < Z and Z <= min_y):
        print("No War")
        break
    else:
        continue
else:
    print("War")


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


void solve(long long W, long long H, long long x, long long y){
    auto b1 = (x*2== W), b2=(y*2 == H);
    cout << ((double)W*(double)H)/2.0 << " " << (b1&&b2 ? 1 : 0) << endl;
}

int main(){
    long long W;
    scanf("%lld",&W);
    long long H;
    scanf("%lld",&H);
    long long x;
    scanf("%lld",&x);
    long long y;
    scanf("%lld",&y);
    solve(W, H, x, y);
    return 0;
}


Measured memory_bytes: 256
import copy
s = list(input())
Ccnt = 0
if s[0] == 'A' :
	for i in copy.copy(s[2:-1]) :
		if i == 'C' :
			Ccnt += 1
			s.remove(i)
	s.remove(s[0])
	if Ccnt == 1 and ''.join(s) == ''.join(s).lower() :
		print('AC')
		exit()
print('WA')

Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF INT_MAX
const int N = 1010;
const int M = 1e9+7;
ll dp[N][N];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    vector<string> s;
    for(int i = 0; i < h; ++i)
    {
        string t;
        cin>>t;
        s.push_back(t);
    }
    for(int i = 0; i < h && s[i][0] == '.'; ++i)
        dp[i][0] = 1;
    for(int i = 0; i < w && s[0][i] == '.'; ++i)
        dp[0][i] = 1;
    for(int i = 1; i < h; ++i)
    {
        for(int j = 1; j < w; ++j)
        {
            if(s[i][j] == '#')
                continue;
           dp[i][j] = (dp[i-1][j] + dp[i][j-1])%M;
        }
    }
    cout<<dp[h-1][w-1]%M;
}


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

#define Online 1
// #define multitest 1
#define Debug
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
#define mp make_pair
const long long mod = 1000000007;
const long long High = 1e16;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

void solve()
{
    int a,b,c;
    cin >> a >> b >> c; 
    if(a==0) cout << "No";
    else{ 
        if(a==b)
        {
            if(a==c) cout << "Yes";
            else cout << "No";            
        }
        else cout << "No";
    }
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}


Measured memory_bytes: 256
#include <stdio.h>
typedef struct
{
    int one;
    int two;
    int three;
    int four;
    int five;
    int six;
} Dice;
int number(Dice d, char str[])
{
    while (*str)
    {
        int tmp;
        switch (*str)
        {
        case 'S':
            tmp = d.one;
            d.one = d.five;
            d.five = d.six;
            d.six = d.two;
            d.two = tmp;
            break;
        case 'N':
            tmp = d.one;
            d.one = d.two;
            d.two = d.six;
            d.six = d.five;
            d.five = tmp;
            break;
        case 'W':
            tmp = d.one;
            d.one = d.three;
            d.three = d.six;
            d.six = d.four;
            d.four = tmp;
            break;
        case 'E':
            tmp = d.one;
            d.one = d.four;
            d.four = d.six;
            d.six = d.three;
            d.three = tmp;
            break;
        }
        str++;
    }
    return d.one;
}
int main(void)
{
    Dice d;
    char str[101];
    scanf("%d %d %d %d %d %d", &d.one, &d.two, &d.three, &d.four, &d.five, &d.six);
    scanf("%s", str); //読み込みはきちんとできている

    printf("%d\n", number(d, str));

    return 0;
}


Measured memory_bytes: 2728
h_arr = []
w_arr = []
while true
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0
  h_arr.push(h)
  w_arr.push(w)
end

h_arr.zip(w_arr) do |h, w|
  w_num = 1
  h.times do
    num = 1
    w.times do
      if w_num % 2 == 1
        if num % 2 == 1
          print "#"
        else
          print "."
        end
      else
        if num % 2 == 1
          print "."
        else
          print "#"
        end
      end
      num = num + 1
    end
    w_num = w_num + 1
    puts ""
  end
  puts ""
end



Measured memory_bytes: 6876
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
a,b = LI()
print((a+b)%24)
#B

#C
"""
n = I()
ans = int(math.log10(n)+1)
for i in range(2,int(n**0.5)+1):
    if n%i == 0:
        ans = min(ans, max(int(math.log10(i)+1),int(math.log10(n//i)+1)))
print(ans)
"""

#D
"""
n,a,b = LI()
v = LI()
v.sort()
v = v[::-1]
ans = v[:a]
d = {}
d[ans[-1]] = 0
if ans[0] != ans[-1]:
    for i in ans:
        if i == ans[-1]:
            d[i] += 1
    k = d[i]
    d[i] = 0
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 1
    for j in range(min(k,d[ans[-1]]-k)):
        c *= d[ans[-1]]-j
        c //= j+1
else:
    for i in v:
        if i == ans[-1]:
            d[i] += 1
    c = 0
    for k in range(a,min(d[ans[-1]],b)+1):
        p = 1
        for j in range(min(k,d[ans[-1]]-k)):
            p *= d[ans[-1]]-j
            p //= j+1
        c += p
print(sum(ans)/a)
print(c)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
# include <iostream>
# include <vector>
# include <map>


using namespace std;
int n; vector<int> a;


int main() {
    cin >> n; a.resize(n);
    for (int i=0; i<n; ++i) cin >> a[i];

    map<int, int> count;
    for (int _a: a) {
        if (count.find(_a) == count.end()) count[_a] = 1;
        else count[_a]++;
    }

    bool has_answer = false;

    if (count.size() == 3)  {  // { ok if count[a] == count[b] == count[c] else ng }
        int size = -1;
        int _xor =  0;
        for (pair<int, int> _c: count) {
            if (size == -1) {
                size = _c.second;
                _xor = _c.first;
                continue;
            }
            _xor ^= _c.first;
            has_answer = (size == _c.second);  // something wrong
        }
        has_answer &= (_xor == 0);
    }

    if (count.size() == 2)  {  // { ok if 2*count[a] == count[0] }
        int size = -1;
        for (pair<int, int> _c: count) {
            if (size == -1) {
                size = (_c.first == 0) ? 2*_c.second: _c.second;
                continue;
            }
            has_answer = (size == _c.second);
        }
    }

    if (count.size() == 1)  {  // { ok if count[0] == n and n%3 == 0}
        has_answer = (count.find(0) != count.end());
    }

    cout << (has_answer ? "Yes": "No") << endl;
    return 0;
}



Measured memory_bytes: 4224
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long h, w;
    scan(h, w);
    auto mat = new string[](h);
    foreach (i; iota(h))
    {
        mat[i] = sread();
    }

    auto h_skip = new bool[](h), w_skip = new bool[](w);
    h_skip[] = true;
    w_skip[] = true;

    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            h_skip[i] &= (mat[i][j] == '.');
            w_skip[j] &= (mat[i][j] == '.');
        }
    }
    foreach (i; iota(h))
    {
        if (h_skip[i])
            continue;

        foreach (j; iota(w))
        {
            if (w_skip[j])
                continue;

            mat[i][j].write();
        }
        writeln();
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n, k;
        n = sc.nextInt();
        k = sc.nextInt();
        int[] height = new int[n];

        for(int ind = 0; ind < n; ind++) {
            height[ind] = sc.nextInt();
        }

        int[] dp = new int[n];

        for(int ind = 1; ind < n; ind++) {

            int i = ind - 1;
            int minCost = Integer.MAX_VALUE;
            while(i >= 0 && ind - i <= k) {
                minCost = Math.min(minCost, Math.abs(height[ind] - height[i]) + dp[i]);
                i--;
            }
            dp[ind] = minCost;
        }

        System.out.println(dp[n - 1]);
    }
}


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

using namespace std;

double n,d,x,y,dis,nr;

int main () {
  cin >> n >> d;
  for(int i=1; i<=n; i++) {
    cin >> x >> y;
    dis=sqrt(x*x + y*y);
    if(dis <= d) nr++;
  }
  cout << nr;
  return 0;
}


Measured memory_bytes: 3836
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		char[] list = new char[]{'0','1','2','3','4','5','6','7','8','9'};
		int count = 0;
		while(sc.hasNext()) {

			String a = sc.next();
			StringBuffer b = new StringBuffer();
			for(int i = 0; i < a.length(); i++) {
				if(Arrays.binarySearch(list,a.charAt(i)) >= 0) {
					b.append(a.charAt(i));
				}
				else {
					if(b.length() != 0) {
					count += Integer.parseInt(b.toString());
					b = new StringBuffer();
					}
				}
				if(i+1 == a.length() && b.length() != 0) {
					count += Integer.parseInt(b.toString());
				}
			}
			
			
			
		}
		out.println(count);
		out.flush();
	}

}
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

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

using namespace std;

typedef long long llint;

const int MAXN = 100005;

llint n, m, sol, dif, ea, eb;
llint p[MAXN], cik[MAXN], come[MAXN], siz[MAXN], col[MAXN], white[MAXN];
vector <int> v[MAXN], red;

int nadi (int x) {
    if (x == p[x]) return x;
    return p[x] = nadi(p[x]);
}

void dfs (int x) {
    for (auto sus : v[x]) {
        if (come[sus]) continue;
        come[sus] = x;
        dfs(sus);
    }
}

void mark_cycle (int from, int to) {
    come[from] = -1;
    dfs(from);
    while (to != -1) {
        cik[to] = 1;
        red.push_back(to);
        to = come[to];
    }
}

void calc (int x, int rod, bool flg) {
    siz[x] = 1;
    white[x] = !flg;
    col[x] = flg + ((x == ea || x == eb) ? -dif : 0);
    for (auto sus : v[x]) {
        if (sus == rod || cik[sus]) continue;
        if (x == ea && sus == eb || x == eb && sus == ea) continue;
        calc(sus, x, !flg);
        siz[x] += siz[sus];
        col[x] += col[sus];
        white[x] += white[sus];
    }
}

void even () {
    vector <llint> e;
    llint val = 0, flg = 0, black = 0;
    for (auto x : red) {
        calc(x, 0, flg);
        flg = !flg;
        val += col[x] * 2 - siz[x];
        black += col[x];
        e.push_back(val);
    }
    if (black * 2 != n) {
        sol = -1;
        return;
    }
    sort(e.begin(), e.end());
    llint med = e[e.size() / 2];
    for (auto x : e) sol += abs(med - x);
    for (int i = 1; i <= n; i++) {
        if (cik[i] == 0) sol += abs(2 * col[i] - siz[i]);
    }
}

void odd () {
    ea = red[0], eb = red[1];
    for (auto x : red) cik[x] = 0;
    calc(1, 0, 0);
    dif = 2 * col[1] - siz[1];
    if (dif % 2 != 0) {
        sol = -1;
        return;
    }
    dif /= 2;
    calc(1, 0, 0);
    for (int i = 1; i <= n; i++) {
        sol += abs(white[i] - col[i]);
    }
    sol += abs(dif);
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) p[i] = i;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
        int pa = nadi(a), pb = nadi(b);
        if (pa == pb) {
            mark_cycle(a, b);
        } else {
            p[pa] = pb;
        }
    }
    if (m == n - 1) {
        calc(1, 0, 0);
        if (col[1] * 2 != n) {
            cout << -1;
            return 0;
        }
        for (int i = 1; i <= n; i++) {
            if (cik[i] == 0) sol += abs(2 * col[i] - siz[i]);
        }
    } else if (red.size() % 2 == 0) {
        even();
    } else {
        odd();
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 17792
#include "stdio.h"

int main(){
	int H, W, i, j;
	for(;;){
		scanf("%d %d", &H, &W);	
		if(H==0 && W==0){
			break;
		}
		for(j=0;j<W;j++){
			printf("#");
		}
		printf("\n");
		for(i=1;i<H-1;i++){
			printf("#");
			for(j=1;j<W-1;j++){
				printf(".");
			}
			printf("#\n");
		}
		for(j=0;j<W;j++){
			printf("#");
		}
		printf("\n");
		printf("\n");
	}
	return 0;
}

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

int64_t	count(int N, const string &S, int j, char c,
			const vector<int> &cnt_vec_1, const vector<int> &cnt_vec_2)
{
	int64_t	cnt = 0;
	int64_t num_i;
	int64_t	num_k;
	num_i = cnt_vec_1.at(j - 1);
	num_k = cnt_vec_2.at(N - 1) - cnt_vec_2.at(j);
	cnt += num_i * num_k;
	num_i = cnt_vec_2.at(j - 1);
	num_k = cnt_vec_1.at(N - 1) - cnt_vec_1.at(j);
	cnt += num_i * num_k;
	int i, k;
	for (int diff = 1; diff < min(j + 1, N - j); ++diff) {
		i = j - diff;
		k = j + diff;
		if (S.at(i) != c && S.at(k) != c && S.at(i) != S.at(k))
			--cnt;
	}
	return (cnt);
}

int	main()
{
	int	N;
	string	S;
	string	color("RGB");
	cin >> N >> S;
	map<char, vector<int>> cnt_vec_map;
	for (char c : color)
		cnt_vec_map[c] = vector<int>(N, 0);
	++cnt_vec_map.at(S.at(0)).at(0);
	for (int i = 1; i < N; ++i) {
		for (char c : color)
			cnt_vec_map.at(c).at(i) = cnt_vec_map.at(c).at(i - 1);
		++cnt_vec_map.at(S.at(i)).at(i);
	}
	int64_t	sum = 0;
	for (int j = 1; j < N - 1; ++j) {
		if (S.at(j) == 'R') {
			sum += count(N, S, j, 'R',
					cnt_vec_map.at('G'),
					cnt_vec_map.at('B'));
		}
		if (S.at(j) == 'G') {
			sum += count(N, S, j, 'G',
					cnt_vec_map.at('B'),
					cnt_vec_map.at('R'));
		}
		if (S.at(j) == 'B') {
			sum += count(N, S, j, 'B',
					cnt_vec_map.at('R'),
					cnt_vec_map.at('G'));
		}
	}
	cout << sum << endl;	
}


Measured memory_bytes: 3648
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int a[5]; int k;
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    } cin >> k;
    if (a[4] - a[0] > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

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

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int64 sum = 0;
  for (int i = 1; i < n; ++i) {
    if (a[i] < a[i - 1]) {
      sum += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main()
{
	long long n,x;
	long long min,max,sum;
	
	cin>>n;
	cin>>x;min=max=sum=x;
	for(int i=1;i<n;i++){
		cin>>x;
		if(min>x) min=x;
		if(max<x) max=x;
		sum+=x;		
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3124
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 510;

int main()
{
    int n;
    while (cin >> n) {
        int ans = 0;
        FOR(a,1,n+1) if (a % 2 == 1) {
            int cnt = 0;
            FOR(d,1,n+1) if (a % d == 0)
                cnt++;
            if (cnt == 8) {
                /* cout << a << endl; */
                ans ++ ;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256