akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct die {
	int val[6];
	void N() {
		int tmp[6];
		for (int i = 0; i < 6; i++) {
			tmp[i] = val[i];
		}
		val[0] = tmp[1];
		val[1] = tmp[5];
		val[5] = tmp[4];
		val[4] = tmp[0];
	}
	void E() {
		int tmp[6];
		for (int i = 0; i < 6; i++) {
			tmp[i] = val[i];
		}
		val[2] = tmp[0];
		val[5] = tmp[2];
		val[3] = tmp[5];
		val[0] = tmp[3];
	}
	void W() {
		int tmp[6];
		for (int i = 0; i < 6; i++) {
			tmp[i] = val[i];
		}
		val[3] = tmp[0];
		val[5] = tmp[3];
		val[2] = tmp[5];
		val[0] = tmp[2];
	}
	void S() {
		int tmp[6];
		for (int i = 0; i < 6; i++) {
			tmp[i] = val[i];
		}
		val[0] = tmp[4];
		val[1] = tmp[0];
		val[5] = tmp[1];
		val[4] = tmp[5];
	}
	int find(int a, int b) {
		if ((val[3] == a && val[1] == b) || (val[1] == a && val[2] == b) || (val[2] == a && val[4] == b) || (val[4] == a && val[3] == b)) {
			return val[0];
		}
		if ((val[3] == a && val[5] == b) || (val[5] == a && val[2] == b) || (val[2] == a && val[0] == b) || (val[0] == a && val[3] == b)) {
			return val[1];
		}
		if ((val[0] == a && val[1] == b) || (val[1] == a && val[5] == b) || (val[5] == a && val[4] == b) || (val[4] == a && val[0] == b)) {
			return val[2];
		}
		if ((val[0] == a && val[4] == b) || (val[4] == a && val[5] == b) || (val[5] == a && val[1] == b) || (val[1] == a && val[0] == b)) {
			return val[3];
		}
		if ((val[0] == a && val[2] == b) || (val[2] == a && val[5] == b) || (val[5] == a && val[3] == b) || (val[3] == a && val[0] == b)) {
			return val[4];
		}
		if ((val[3] == a && val[4] == b) || (val[4] == a && val[2] == b) || (val[2] == a && val[1] == b) || (val[1] == a && val[3] == b)) {
			return val[5];
		}
	}
};

bool operator==(const die& l, const die& r) {
	for (int i = 0; i < 6; i++) {
		if (l.val[i] != r.val[i]) {
			return false;
		}
	}
	return true;
}

int main()
{
	die a, b;
	vector<int> aa, bb;
	for (int i = 0; i < 6; i++) {
		cin >> a.val[i];
		aa.push_back(a.val[i]);
	}
	for (int i = 0; i < 6; i++) {
		cin >> b.val[i];
		bb.push_back(b.val[i]);
	}
	sort(aa.begin(), aa.end());
	sort(bb.begin(), bb.end());
	if (aa == bb) {
		bool flag = true;
		for (int i = 0; i < 6; i++) {
			for (int j = i + 1; j < 6; j++) {
				if (a.find(aa[i], aa[j]) != b.find(aa[i], aa[j])) {
					flag = false;
					cout << "No" << endl;
					break;
				}
			}
			if (!flag) break;
		}
		if (flag) cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF  2000000000
//#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
#define SUM(a, n) accumulate(a, a+n, 0)
#define VSUM(v) accumulate(ALL(v), 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 FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

int notin(int n, vi v){
    string s = to_string(n);
    AREP(a, v){
        if(s.find('0'+a) != string::npos) return 0;
    }
    return 1;
}

signed main(){ INIT;
    VAR(int, n, k);
    VEC(int, d, k);
    while(1){
        if(notin(n,d)){
            OUTL(n);
            RET;
        }
        n++;
    }
RET;}

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

int main() {
  string s;
  cin >> s;
  int n,c;
  n = s.length();
  int max = 0;
  c = 0;
  for (int i=0; i < n; i++){
    if (s[i] == 'A' || s[i] == 'C'){
      c++;
      continue;
    }else if (s[i] == 'G' || s[i] == 'T'){
      c++;
      continue;
    }else{
      if (max < c){
        max = c;
        c = 0;
      }else {
        c = 0;
      }
    }
  }
  if (max < c){
    max = c;
    c = 0;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES


#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>

#include <cmath>

using namespace std;

typedef long long LL;

int main() {
	int r, c;

	cin >> r >> c;

	int _temp;
	vector<vector<int>> table;
	for (int i = 0; i < r; ++i) {
		vector<int> _temp_vec;
		for (int j = 0; j < c; ++j) {
			cin >> _temp;
			_temp_vec.emplace_back(_temp);
		}
		table.emplace_back(_temp_vec);
	}

	for (auto&& t : table) {
		auto sum = accumulate(t.begin(), t.end(), 0);
		t.emplace_back(sum);
	}

	size_t len = table[0].size();
	vector<int> sums(len);
	for (auto&& t : table) {
		for (int i = 0; i < len; ++i) {
			sums[i] += t[i];
		}
	}
	
	table.emplace_back(sums);

	for (auto&& t : table) {
		for (int i = 0; i < len; ++i) {
			printf("%d", t[i]);
			if (i != (len - 1)) printf(" ");
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 3276
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int x_1, y_1, x_2, y_2; cin >> x_1 >> y_1 >> x_2 >> y_2;
    int diff_x = x_2 - x_1;
    int diff_y = y_2 - y_1;

    int x_3 = x_2 - diff_y;
    int y_3 = y_2 + diff_x;
    int x_4 = x_1 - diff_y;
    int y_4 = y_1 + diff_x;

    cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, c,n;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	n == 0;
	for (int x = a; x <= b; x++) {
		if (c%x == 0)
			n++;
	}
	printf("%d\n", n);

	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    bool prev = false;
    ll cnt = 0;
    ll ans = 0;
    vector<int> p(N);
    REP(i, N){
        int p;
        cin >> p;
        p--;
        if(i == p){
            cnt++;
        }else{
            if(cnt == 1){
                ans++;;
            }
            cnt = 0;
        }
        if(cnt == 2){
            ans++;
            cnt = 0;
        }
    }
    if(cnt == 1){
        ans++;
    }else if(cnt == 2){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
	vector<int> a,b;
	while(1){
		string str; cin >> str ;
		if(str=="0") break;
		int tmp_A=0,tmp_B=0; //score
		a.push_back(0), b.push_back(0);
		for(int i=1;i<str.size();i++){
			if(str[i]=='A') a[a.size()-1]++;
			else if(str[i]=='B') b[b.size()-1]++;
		}
		if(a[a.size()-1] > b[b.size()-1]) a[a.size()-1]++;
		else b[b.size()-1]++;
	}
	for(int i=0;i<a.size();i++) cout << a[i] << ' ' << b[i] << '\n' ;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL<<60;
const string YES = "Yes";
const string NO = "No";
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse!」
ll A,B,X;

int main() {
  int n,m;
  cin>>n>>m;
  char A[n+1];
  for(int i=0;i<=n;i++){
    cin>>A[i];
  }
  vec ans;
  int now=n;
  while(true){
    if(now<m){
      ans.push_back(now);
      break;
    }
    for(int i=m;i>=0;i--){
      if(i==0){
        cout<<-1<<endl;
        exit(0);
      }
      if(now-i>=0&&A[now-i]=='0'){
        now=now-i;
        ans.push_back(i);
        break;
      }
    }
    if(now<=0) break;
  }
  reverse(all(ans));
  for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 1020
while 1:
	w,h = map(int, raw_input().split())
	if w == h == 0:
		break
	count = 0
	cnt = 1
	lst = [list(raw_input()) for i in range(h)]
	queue = []
	for i in range(h):
		if "@" in lst[i]:
			wNow, hNow = lst[i].index("@"),i
	queue.append([hNow, wNow])
	while 1:
		hNow,wNow = queue[0][0],queue[0][1]
		queue.pop(0)
		if hNow < h-1:
			if lst[hNow+1][wNow] == ".":
				queue.append([hNow+1,wNow])
				lst[hNow+1][wNow] = "$"
				cnt += 1
		if wNow < w-1:
			if lst[hNow][wNow+1] == ".":
				queue.append([hNow,wNow+1])
				lst[hNow][wNow+1] = "$"
				cnt += 1
		if hNow > 0:
			if lst[hNow-1][wNow] == ".":
				queue.append([hNow-1,wNow])
				lst[hNow-1][wNow] = "$"
				cnt += 1
		if wNow > 0:
			if lst[hNow][wNow-1] == ".":
				queue.append([hNow,wNow-1])
				lst[hNow][wNow-1] = "$"
				cnt += 1
		if len(queue) == 0:
			break
	print cnt

Measured memory_bytes: 4696
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second


ll N, K, A, B, C;
ll arr[100005];
vector<ll> V;
string S;

int main() {
	scanf("%lld %lld %lld", &N, &A, &B);
	ll sum = A + B;
	ll temp = N / sum;
	ll rem = N % sum;
	ll ans = (N / sum) * A;
	if(rem <= A) {
		ans += rem;
	}
	else {
		ans += A;
	}
	printf("%lld\n", ans);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] B = new int[N];
            int[] C = new int[N];
            {
                string[] input = Console.ReadLine().Split(' ');
                for (var i = 0; i < N; i++)
                {
                    A[i] = int.Parse(input[i]);
                }
            }
            {
                string[] input = Console.ReadLine().Split(' ');
                for (var i = 0; i < N; i++)
                {
                    B[i] = int.Parse(input[i]);
                }
            }
            {
                string[] input = Console.ReadLine().Split(' ');
                for (var i = 0; i < N-1; i++)
                {
                    C[i] = int.Parse(input[i]);
                }
            }
            long ans = 0;
            int prev = -2;
            for (var i = 0; i < N; i++)
            {
                int e = A[i]-1;
                ans += B[e];
                if (prev + 1 == e) ans += C[prev];
                prev = e;
            }
            Console.WriteLine(ans);
        }
    }
}


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

class Program
{
  public static void Main(string[] args)
  {
    int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = s[0];
    int a = s[1];
    int b = s[2];
    int sum = 0;
    for (int i = 1; i <= n; i ++) {
      if (i < 10) {
        if (i >= a && i <= b) sum += i;
      }
      else {
        char[] Tmp = i.ToString().ToCharArray();
        int[] tmp = new int[Tmp.Count()];
        for (int j = 0; j < Tmp.Count(); j ++) {
          tmp[j] = int.Parse(Tmp[j].ToString());
        }
        if (tmp.Sum() >= a && tmp.Sum() <= b) sum += i;
      }
    }
    Console.WriteLine(sum);
  }
}


Measured memory_bytes: 15444
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int N;
int calc[100];
vector<string> def;
vector< set<string> > rhs;
int f(int idx){
  if(calc[idx] > 0) return calc[idx];

  set<string> s, er;
  for(auto& str: rhs[idx]){
	REP(i,N)
	  if(def[i] == str){
		f(i);
		s.insert(ALL(rhs[i]));
		er.insert(str);
	  }
  }

  rhs[idx].insert(ALL(s));
  for(auto& str: er)
	rhs[idx].erase(str);
  calc[idx] = SZ(rhs[idx]);
  return calc[idx];
}

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

  while(cin>>N,N){cin.ignore();
	fill(calc, calc+100, 0);
	def.clear();
	rhs.assign(N, set<string>());

	REP(i,N){
	  string line; getline(cin, line);
	  int j;
	  for(j=0;line[j]!=':';++j);
	  def.PB(line.substr(0, j++));
	  replace(ALL(line), ',', ' ');
	  replace(ALL(line), '.', ' ');
	  stringstream ss(line.substr(j));
	  string t;
	  while(ss>>t) rhs[i].insert(t);
	}
	cout << f(0) << endl;
  }
  
  return 0;
}

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

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    cout<<((long long)t*(v-w)>=abs(a-b)?"YES":"NO");

    return 0;
}   

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

int main(){
	int n;
	cin >> n;
	vector<int> a(0);
	int sum = 0;
	rep(i, n){
		sum += i;
		a.push_back(sum);
		if(sum >= n) break;
	}
	while(n != 0){
		int k = lower_bound(a.begin(), a.end(), n) - a.begin();
		cout << k << ' ';
		n -= k;
	}
	cout << endl;
	return 0;
}

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

int main(){
    int h, w; cin >> h >> w;
    char a[h+2][w+2];
    fill(a[0],a[h+2],'#');

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i <= h+1; i++){
        for(int j = 0; j <= w+1; j++){
            cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int arr[100005];
int dp[100005];
int main(){
	int n;
	cin>>n;

	for(int i =0;i<n;i++){
		cin>>arr[i];
	}
	ll mi=0;
	dp[0]=0;
	dp[1]=abs(arr[0]-arr[1]);
	for(int i =2;i<n;i++){
		dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
	}
	cout<<dp[n-1];
	

return 0;
}

Measured memory_bytes: 1024
IDENTIFICATION DIVISION.
PROGRAM-ID. 137B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP   PIC  X(100).
01 K     PIC  9(3).
01 X     PIC  9(3).
01 M     PIC S9(3).
01 P     PIC S9(3).
01 I     PIC S9(3).
01 J     PIC S9(3).
01 POS   PIC  9(3).
01 W1    PIC  ZZZ9.
01 W-R1  REDEFINES W1.
   03 W2 PIC ---9.
01 W-R2  REDEFINES W1.
   03 W  PIC X(1) OCCURS 4.
01 OUT   PIC  X(700).
*>  
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO K X.
*>
  COMPUTE M = X - K + 1.
  COMPUTE P = X + K - 1.
*>
  MOVE SPACE TO OUT.
  MOVE 1     TO POS.
  PERFORM VARYING I FROM M BY 1 UNTIL I > P
    IF (I < 0)
      MOVE I TO W2
    ELSE
      MOVE I TO W1
    END-IF  
    PERFORM VARYING J FROM 1 BY 1 UNTIL J > 4
      IF (W(J) NOT = ' ')
        MOVE W(J) TO OUT(POS:1)
        ADD 1     TO POS
      END-IF
    END-PERFORM  
    MOVE ' ' TO OUT(POS:1)
    ADD 1    TO POS
  END-PERFORM.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.


Measured memory_bytes: 384
//Ã¦ÂÂ¬Ã¦ÂÂ¥Ã£ÂÂ®Ã£ÂÂÃ£ÂÂÃ£ÂÂµÃ£ÂÂÃ£ÂÂ
//defineÃ£ÂÂ®Ã¥ÂÂ¤Ã£ÂÂÃ¥Â¤ÂÃ£ÂÂÃ£ÂÂÃ£ÂÂ N 10000
//Ã¦ÂÂ¬Ã¦ÂÂ¥Ã£ÂÂ®Ã¥Â¤ÂÃ£ÂÂªÃ£ÂÂ¨Ã£ÂÂ©Ã£ÂÂ¼
//c++Ã£ÂÂªÃ£ÂÂ®Ã£ÂÂ«gccÃ£ÂÂ§Ã£ÂÂ³Ã£ÂÂ³Ã£ÂÂÃ£ÂÂ¤Ã£ÂÂ«Ã£ÂÂÃ£ÂÂ¦Ã£ÂÂ

#include<cstdio>
#include<iostream>
#define N 1000
int W,Q,haba[N],koko=0,suei1[N],suei2[N];

using namespace std;



void habacalc(int,int);
void habacalc2(int);

int main(){
  int s[N][N],w[N],i,id[N],uei[N];
  char sw;
  
  for(i=0;i<N;i++){
    haba[i]=0;
  }
  while(1){
    
  cin >> W >> Q;
  if(W==0 && Q == 0)break;
  
  for(i=0;i<Q;i++){
    cin >> sw ;
    if(sw == 's'){
      cin >> id[i] >> uei[i];
      habacalc(id[i],uei[i]);
    }
    else if(sw == 'w'){
      cin >>  w[i];
      habacalc2(w[i]);
    }
    
    
  }
  cout << "END" <<endl;
  
 for(i=0;i<N;i++){
    haba[i]=0;
  }


  }
}


void habacalc(int id,int uei){
  int j,i,flag=1,count=0,fl[2],ok=0;
  
  fl[0]=-1;
  fl[1]=-1;
  for(j=0;j<W;j++){
    if(haba[j]==0){
      count+=1;
      if(fl[0]==-1){
	fl[0]=j; 
	suei1[id]=j;
	
      }
      if(count==uei){
	fl[1]=j;
	suei2[id]=j;
	
	ok=1;
	break;
      }
    }
    else{
      count=0;
      fl[0]=-1;
      fl[1]=-1;      
    }
  }
  if(ok==1){
    for(i=fl[0];i<=fl[1];i++){
      haba[i]=1;
     
    }
 cout << fl[0] << endl;
  }
  else{
    cout << "impossible" << endl;  
  }
  
}



void habacalc2(int w){
  int i;
  for(i=suei1[w];i<=suei2[w];i++){
    haba[i]=0;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int p,g,ans;
    p=g=ans=0;
    for (int i=0;i<a.size();i++){
        if (p<g){
            p++;
            if (a[i]=='g') ans++;
        } 
        else{
            g++;
            if (a[i]=='p') ans--;
        }
    }
    printf ("%d\n",ans);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
    ll S;
    cin >> S;
    ll N = 1e9;
    ll X = (N-S%N)%N,Y = (S+X)/N;
    cout << "0 0 1000000000 1 " << X << " " << Y << endl;
}

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

template<typename C>
inline void out_vector(const C& v){
  bool isFirst = true;
  for(const auto& e : v){
    if(isFirst) { isFirst = false; }
    else { cout << " "; }
    
    cout << e;
  }
  cout << endl;
}

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> v;
  
  for(int i = 0; i < n; i++){
    int64_t a;
    cin >> a;
    v.push_back(a);
  }
  
  double sum = 0.0;
  for(int64_t a : v){
    sum += 1/(double)a;
  }
  
  cout << setprecision(10) << 1/sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}
using namespace io;
char a[105],b[105],c[105];
int main(){
	int i,n,ans=0;
	read(n);
	scanf(" %s %s %s",a+1,b+1,c+1);
	for(i=1;i<=n;i++){
		if(a[i]!=b[i]&&b[i]!=c[i]&&a[i]!=c[i]) ans+=2;
		if(a[i]!=b[i]&&a[i]==c[i]) ans++;
		if(a[i]!=c[i]&&a[i]==b[i]) ans++;
		if(b[i]!=a[i]&&b[i]==c[i]) ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
//Wrong Answer
public class Main {
    private static int[] A = new int[2000001];
    private static int heapSize = 0;
    private static void maxHeapify(int k){
        int l = 2*k;
        int r = 2*k+1;
        int largest;
    
        if ((l <= (heapSize)) && (A[l] > A[k])){
            largest = l;
        }else{
            largest = k;
        }
        if ((r <= (heapSize)) && (A[r] > A[largest])){
            largest = r;
        }
        if (largest != k){
            swap(k, largest);
            maxHeapify(largest);
        }
    }
    private static void swap(int i, int j) {
        int tmp = A[i];
        A[i] = A[j];
        A[j] = tmp;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            String[] line = br.readLine().split(" ");
            String order = line[0];
            if (order.equals("insert")){
                heapSize++;
                //A[heapSize] = Integer.MIN_VALUE;
                int num = Integer.parseInt(line[1]);
                A[heapSize] = num;
                int i = heapSize;
                while (i > 1 && A[i/2] < A[i]) {
                    swap(i, i/2);
                    i = i/2;
                }
            }else if (order.equals("extract")){
                int max = A[1];
                A[1] = 0;
                swap(1, heapSize);
                heapSize--;
                maxHeapify(1);
                System.out.println(max);
            }else{ // end
                break;
            }
        }
    }
}

Measured memory_bytes: 186976
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <valarray>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>
#include <random>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int m, nmin, nmax;
  while (cin >> m >> nmin >> nmax, m || nmin || nmax)
  {
    vector<int> p(m);
    for (auto &e : p)
      cin >> e;
    sort(p.begin(), p.end(), greater<int>());
    int ans = 0, gap = 0;
    for (int n = nmin; n <= nmax; ++n)
    {
      if (gap <= p[n - 1] - p[n])
      {
        gap = p[n - 1] - p[n];
        ans = n;
      }
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3084
n= int(input())
ans= [0]*10001

for x in range(1,101):
    for y in range (1,101):
        for z in range(1,101):
            mul= x*x+y*y+z*z+x*y+y*z+z*x
            if  mul <= 10000:
                ans[mul]+=1

for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 9236
n = int(input())
a = list(map(int, input().split()))
a.sort()

cnt = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if a[k] < a[i] + a[j]:
                if a[i]!=a[j]:
                    if a[j]!=a[k]:
                        cnt += 1

print(cnt)

Measured memory_bytes: 68008
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main ()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
  	a = min(a,b);
    c = min(c,d);
    cout<<a+c<<endl;
    return 0;
}
/*
*/





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

int main()
{
	int n;
	cin>>n;
	vector<int>dist(n),val(n);
	fill(val.begin(),val.end(),1<<30);
	int i,j;
	for(i=0;i<n;i++) cin>>dist[i];
	val[0]=0;
	for(i=0;i<n;i++)
	{
		if(i+1<n)
		  val[i+1]=min(val[i+1],val[i]+abs(dist[i+1]-dist[i]));
		
		if(i+2<n)
		val[i+2]=min(val[i+2],val[i]+abs(dist[i+2]-dist[i]));
	}
	// for(i=0;i<n;i++)
	//  cout<<val[i]<<" ";
	//  cout<<endl;
	cout<<val[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define debug cout << __LINE__ << endl
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef pair<ut,pr> ppr;
typedef vector<ppr> Vppr;
typedef pair<ut,ut> prs;
inline void IN(ut &x){cin >> x;}
inline void INA(ut n,ut x[]){REP(i,n) cin >> x[i];}
inline void INE(ut m,VI edges[]){
	ut a,b;
	REP(i,m){
		cin >> a >> b;
		edges[a].PB(b);
		edges[b].PB(a);
	}
}
inline void INEC(ut m,Vpr edges[]){
	ut a,b,c;
	REP(i,m){
		cin >> a >> b >> c;
		edges[a].PB(pr(c,b));
		edges[b].PB(pr(c,a));
	}
}
const LL p=7+1e9;
const int SIZE=300005;
bool searched[SIZE];
LL val[SIZE];
LL parent[SIZE];
VI nums[SIZE];
VI edges[SIZE];
int main(){
	LL x,y;
	LL N,M;
	cin >> N;
	REP(i,N-1){
		cin >> x >> y;
		edges[x].PB(y);
		edges[y].PB(x);
	}
	stack<LL> st;
	st.push(1);
	while(!st.empty()){
		LL now=st.top();
		if(searched[now]){
			REP(i,nums[now].size()){
				LL next=nums[now][i];
				val[now]^=next;
			}
			nums[parent[now]].PB(val[now]+1);
			st.pop();
		}
		searched[now]=true;
		REP(i,edges[now].size()){

			LL next=edges[now][i];
			if(!searched[next]){
				st.push(next);
				parent[next]=now;
			}
		}
	}
	if(val[1]==0){
		cout <<"Bob" << endl;
	}
	else {
		cout <<"Alice" << endl;
	}

	return 0;
}

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

int main() {
   int N, K;
   cin >> N >> K;
   vector<int> p(N,0);
   for(int i = 0; i < N; ++i){
     cin >> p.at(i);
   }
   sort( p.begin(), p.end() );
   int sum = 0;
   for(int i = 0; i < K; ++i){
     sum += p.at(i);
   }
   cout << sum << endl;

   return 0;
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(v)              ((v).begin()), ((v).end())
#define allr(v)             ((v).rbegin()), ((v).rend())
#define MP                  make_pair
#define PI                  3.14159265359
#define SZ(v)				(int)v.size()
#define ull                 unsigned long long
#define ll                  long long
#define LD					long double
#define vi                  vector<int>
#define vl                  vector<ll>
#define vs                  vector<string>
#define vp                  vector<pair<int,int>>
#define OO                  (int)2e9
using namespace std;
const ll MOD = (int)1e9 + 7;
int dx[] = { 1,-1,0,0,1,-1,1,-1 };
int dy[] = { 0,0,-1,1,1,-1,-1,1 };
const int MAX = (int)1e5 + 10;
using namespace std;

/*void Ka8eeM()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
}*/
int main()
{
	//Ka8eeM();
	string s;
	cin >> s;
	for (int i = 0;i < SZ(s);i++)
	{
		if (i == 0)
			cout << '2';
		else if (i == 1)
			cout << '0';
		else if (i == 2)
			cout << '1';
		else if (i == 3)
			cout << '8';
		else
			cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
const int INF = 8101919;
const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = 10;
struct pt {
	int x;
	int y;
};
int h;
int w;
int n;
pt cheese[MAX_N];
queue<pt> nextsearch;
pt st;
int cost[MAX_H][MAX_W];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { -1,0,1,0 };
vector<string> field;
int mousehp = 1;
int bfs() {
	for (int i = 0; i < MAX_N; i++) {
		cheese[i].x = INF;
		cheese[i].y = INF;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cost[i][j] = INF;
			if (field[i][j] == 'S') {
				st.x = j;
				st.y = i;
				cost[i][j] = 0;
			}
			switch (field[i][j]) {
			case '1':
				cheese[1].x = j;
				cheese[1].y = i;
				break;
			case '2':
				cheese[2].x = j;
				cheese[2].y = i;
				break;
			case '3':
				cheese[3].x = j;
				cheese[3].y = i;
				break;
			case '4':
				cheese[4].x = j;
				cheese[4].y = i;
				break;
			case '5':
				cheese[5].x = j;
				cheese[5].y = i;
				break;
			case '6':
				cheese[6].x = j;
				cheese[6].y = i;
				break;
			case '7':
				cheese[7].x = j;
				cheese[7].y = i;
				break;
			case '8':
				cheese[8].x = j;
				cheese[8].y = i;
				break;
			case '9':
				cheese[9].x = j;
				cheese[9].y = i;
				break;
			default:
				break;
			}
		}
	}
	nextsearch.push(st);
	int searchCheese = 1;
	int allcost;
	while (nextsearch.size()) {
		pt queuefirst = nextsearch.front();
		nextsearch.pop();
		if (queuefirst.x == cheese[searchCheese].x && queuefirst.y == cheese[searchCheese].y && field[queuefirst.y][queuefirst.x] - '0' <= mousehp) {
			searchCheese++;
			mousehp++;
			field[queuefirst.y][queuefirst.x] = '.';
			if (searchCheese > n) {
				allcost = cost[queuefirst.y][queuefirst.x];
				break;
			}
			queue<pt> empty;
			swap(nextsearch,empty);
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (queuefirst.x == j && queuefirst.y == i) {
					} else {
						cost[i][j] = INF;
					}
				}
			}
		}
		for (int i = 0; i < 4; i++) {
			pt nextp;
			nextp.x = queuefirst.x + dx[i];
			nextp.y = queuefirst.y + dy[i];
			if (0 <= nextp.x && nextp.x < w && 0 <= nextp.y && nextp.y < h && field[nextp.y][nextp.x] != 'X' && cost[nextp.y][nextp.x] == INF) {
				nextsearch.push(nextp);
				cost[nextp.y][nextp.x] = cost[queuefirst.y][queuefirst.x] + 1;
			}
		}
	}
	return allcost;
}
int main() {
	cin >> h >> w >> n;

	string inputtmp;
	for (int i = 0; i < h; i++) {
		cin >> inputtmp;
		field.push_back(inputtmp);
	}
	cout << bfs() << endl;
	return 0;
}


Measured memory_bytes: 7864
<?php
$a = explode(" ",trim(fgets(STDIN)));
$s = str_split(trim(fgets(STDIN)));
$count = 0;

foreach ($s as $value) {
  if($value == "-") {
    ++$count;
  }
}

if($s[$a[0]] == "-" && $count == 1) {
  echo "Yes";
}else {
  echo "No";
}

Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int S,a,b,c,d,j;
  int count;
  int h,w;
  int check=0;
  string e;
  int map[12][12];
  while(1){
  for(int i=0;i<12;i++){
  for(j=0;j<12;j++){
	map[i][j]=2;
      }
    }
    cin>>e;
    if(e[0]=='#') break;
    w=0;
    h=0;
    for(int i=0;i<e.size();i++){
      if('0'<=e[i] && e[i]<='9'){
	S=e[i]-'0';
	for(j=0;j<S;j++){
	  map[h][w]=0;
	  w++;
	}
      }
	if(e[i]=='b'){
	  map[h][w]=1;
	  w++;
	}
	if(e[i]=='/'){
	  w=0;
	  h++;
	}
    }
    /* for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cout<<map[i][j];
      }
      cout<<endl;
      }*/
    cin>>a>>b>>c>>d;
    map[a-1][b-1]=0;
    map[c-1][d-1]=1;
    /*    for(int i=0;i<9;i++){
      for(int j=0;j<9;j++){
	cout<<map[i][j];
      }
      cout<<endl;
      }*/
    rep(i,12){
      count=0;
      for(j=0;j<12;j++){
	if(map[i][j]==0){
	  count++;
	  if(i!=0 && j==0) cout<<"/";
	}
	else if(map[i][j]==2){
	  if(count!=0) cout<<count;
	  count=0;
	  break;
	}
	else{
	  if(i!=0 && j==0) cout<<"/";
	  if(count!=0) cout<<count;
	  cout<<"b";
	  count=0;
	}
      }
      if(j==0) break;
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3160
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int N;
string s[50];

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> s[j];
    }

    int min_count[26];
    for (int j = 0; j < 26; ++j) { min_count[j] = 100; }

    for (int j = 0; j < N; ++j) {
        int count[26];
        fill(count, count+26, 0);
        for (int k = 0; k < s[j].size(); ++k) {
            ++count[s[j][k]-'a'];
        }
        for (int k = 0; k < 26; ++k) {
            min_count[k] = min(min_count[k], count[k]);
        }
    }

    for (int j = 0; j < 26; ++j) {
        for (int k = 0; k < min_count[j]; ++k) {
            cout << (char)('a'+j);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
r,p['   '],i;main(i,n){for(;i*i++<1e5;)if(!p[i])for(n=i+i;n<1e5;n+=i)p[n]=1;for(;i=scanf("%d",&n),n;r=!printf("%d\n",r))for(;i++<n/2;)r+=!p[i]&!p[n-i];exit(0);}

Measured memory_bytes: 800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n=0,c=0;
    cin>>s;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i]=='0')
        {
            n++;
        }
        else
        {
            c++;
        }
    }
    if(n==c && n!=0)
    {
        cout<<n*2<<endl;
    }
    else if(n > c && c!=0)
    {
        cout<<c*2<<endl;
    }
    else if(n < c && n!=0)
    {
        cout<<n*2<<endl;
    }
    else
    {
        cout<<"0\n";
    }

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int t, x;
  cin >> t >> x;

  double ans = (double) t / x;
  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a_500 in range(0,A+1):
    for b_100 in range(0,B+1):
        for c_50 in range(0,C+1):
            pay = 500*a_500 + 100*b_100 + 50*c_50
            if pay > 0:
                if X == pay:
                    cnt = cnt + 1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;
using ll = unsigned long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(5e5)+5;




int main()
{
    idfc;

    int i=1;
    while(true)
    {
        int e;
        cin>>e;
        if(e==0)
        {
            cout<<i;return 0;
        }
        i++;
    }



    return 0;
}

Measured memory_bytes: 3580
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
//#pragma comment(linker, "/vector:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 9999

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}
  private:
    bool first;
    string separator;
};

template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

ll a,b;

ll poww(ll a,ll b)
{
    ll res=1;
    for(;b;b>>=1)
    {
     if(b&1)res=(res*a);
     a=a*a;
    }
    return res;
}

int main(){
FAST_READ;
cin>>a>>b;
ll m=min(a,b);
ll ost=16-m*2;
ll st=max(a,b)-m;
//debt(ost,st);
//if(ost==0 || st==0)cout<<"Yay!"<<endl;
 if(st*2<=ost)cout<<"Yay!"<<endl;
else cout<<":("<<endl;



return 0;
}


Measured memory_bytes: 256
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().split("");
        sc.close();

        long r = 0;
        long g = 0;
        long b = 0;

        for (String s : S) {
            if (s.equals("R")) {
                r++;
            } else if (s.equals("G")) {
                g++;
            } else {
                b++;
            }
        }

        long total = r * g * b;
        long sum = 0;

        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (S[i].equals(S[j])) {
                    continue;
                }
                int k = 2 * j - i;
                if (k >= N || S[k].equals(S[i]) || S[k].equals(S[j])) {
                    continue;
                }

                sum++;
            }
        }

        System.out.println(total - sum);

    }
}


Measured memory_bytes: 36800
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(),v.end()



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

    while(n)
    {
       s+='a'+((n-1)%26ll);
       n=(n-1)/26;
    }

   //cout<<s<<endl;
   reverse(all(s));
   cout<<s<<endl;
   return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

vector<int> lung;
int n;
int dead[1100000];
int dp[1100000];
int ans;
void must_die();
void ok(){
    cout << "Yes" << endl;
    exit(0);
}

void ng(){
    cout <<  -1 << endl;
    exit(0);
}

int main(){
    cin >> n;
    for(int i = 0;i < (1<<n);i++){
        cin >> dead[i];
    }
    for(int i = 0;i < (1 << n);i++){
        if(dead[i]){
            bool need = true;
            for(int j = 0;j < n;j++){
                if(i & (1 << j)){
                    need &= (dead[i - (1 << j)] == 0);
                }
            }
            ans += need;
        }
        else{
            for(int j = 0;j < n;j++){
                if(i & (1 << j)){
                    if(dead[i - (1 << j)] == 1)ng();
                }
            }
        }
    }
    
    if(dead[0] == 1)ng();
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 7220
import math

n = int(input())
s = 1
frag = 0
a = list(map(int, input().split()))
if(0 in a):
    print(0)
else:
    for i in range(len(a)):
        s *= a[i]
        if(s > 10**18):
            frag = 1
            break
    if(frag):
        print(-1)
    else:
        print(s)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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



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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}


signed main(){
    int h, w;
    cin >> h >> w;
    vector<int> v(26);
    REP(i, h*w){
        char c;
        cin >> c;
        v[c - 'a']++;
    }

    int c1, c2, c4;
    c1 = (h*w%2 == 1 ? 1 : 0);
    c2 = (h/2)*(w%2) + (w/2)*(h%2);
    c4 = (h*w - c1 - c2*2) / 4;

    int cnt1 = 0, cnt2 = 0;
    for(auto i : v){
        if(i%2 == 1) cnt1++;
        if(i%4 == 2) cnt2++;
    }

    cout << ((cnt1 > c1 || cnt2 > c2) ? "No" : "Yes") << endl;

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int n = 0;
    cin >> n;
    int r = 0;
    r = n % 1000;
    int ans = 0;
    if(r > 0){
     ans = 1000 - r;
    }
    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  map<string, vector<pair<int, int>>> mp;
  rep (i, n) {
    string s;
    int tmp;
    cin >> s >> tmp;
    mp[s].push_back(make_pair(tmp, i + 1));
  }
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {

    sort(itr->second.rbegin(), itr->second.rend());
    rep (i, itr->second.size()) {
      P(itr->second[i].second);
    }
  }


  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,m;
    cin>>n>>m;
    int a[m];
    pair<int,int> c[n];
    rep(i,n){
        c[n].first=0;
        c[n].second=0;
    }
    int ans=0,con=0;
    string b[m];
    rep(i,m){
        cin>>a[i]>>b[i];
    }
    rep(i,m){
        if(c[a[i]-1].first==0&&b[i]=="AC"){
            con+=c[a[i]-1].second;
            c[a[i]-1].first++;
            ans++;
        }
        if(c[a[i]-1].first==0&&b[i]=="WA"){
            c[a[i]-1].second++;
        }
    }
    cout<<ans<<" "<<con<<endl;
}


Measured memory_bytes: 8064
N = int(input())
S = input()

cnt = S.count("R")*S.count("G")*S.count("B")
for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if(k >= N):
            break
        if(S[i] != S[j] and S[j] != S[k] and S[k] != S[i]):
            cnt -= 1
print(cnt)

Measured memory_bytes: 9184
lst = [('.',',','!','?',' '),
       ('a','b','c'),
       ('d','e','f'),
       ('g','h','i'),
       ('j','k','l'),
       ('m','n','o'),
       ('p','q','r','s'),
       ('t','u','v'),
       ('w','x','y','z')]

for i in range(int(input())):
    ans = ""
    x = raw_input().split("0")
    while '' in x: x.remove('')
    for j in range(len(x)):
        ans += lst[int(x[j])%10-1][(len(x[j])-1)%len(lst[int(x[j])%10-1])]
    print ans

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

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

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001LL;
constexpr double EPS = 1e-10;
using number = long long;




int main() {
    int n;
    string s;
    map<pair<string, string>, ll> C;

    cin >> n >> s;
    reverse(s.begin() + n, s.end());
    rep(i, 1 << n) {
        string a, b;
        rep(j, n) {
            if (i >> j & 1)a += s[j];
            else b += s[j];
        }
        ++C[mp(a, b)];
    }
    ll ans = 0;
    rep(i, 1 << n) {
        string a, b;
        rep(j, n) {
            if (i >> j & 1)a += s[n + j];
            else b += s[n + j];
        }
        ans += C[mp(a, b)];
    }
    cout << ans << endl;
}

Measured memory_bytes: 91904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  vector<int> x(a);
  int n=0;
  for(int i = 0;i < a;i++){
    cin >> x.at(i);
  n+=x.at (i);}
  sort(x.begin(),x.end());
  if(x.at(a-b)*4*b >= n){
  cout << "Yes" << endl;}
  else{cout << "No" << endl;}}

Measured memory_bytes: 256
N=int(input())
v=list(map(int, input().split()))

dct = sorted(v, reverse=False)

ans = 0
for i in range(N-1):
    if i == 0:
        ans = (dct[i] + dct[i+1]) / 2
    if i > 0:
        ans = ( ans + dct[i+1]) / 2
    
print(ans)


Measured memory_bytes: 2940