akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int >PII;
const int MOD = 1e9+7;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

const int MAXH = 20;
int p[1<<MAXH];
int sm[1<<MAXH];

void jogKoro(int u, int upore) {
//    cout << "jog " << u << " " << upore << endl;
    while (u > 1) {
        upore = mul(upore, u);
        u >>= 1;
//        cout << "add " << upore << " to " << u << endl;
        sm[u] = sum(sm[u], upore);
    }
}
void biyogKoro(int u, int upore) {
    while (u > 1) {
        upore = mul(upore, u);
        u >>= 1;
        sm[u] = sub(sm[u], upore);
    }
}

int L;
int ans;

vector< PII >solve(int u, int l, int r) {
    if (l==r) {
        vector< PII >v = {{p[l]+L-1, u}};
        return v;
    }

    int mid = l+(r-l+1)/2;
    vector< PII >bam = solve(u*2, l, mid-1);
    vector< PII >dan = solve(u*2+1, mid, r);

//    cout << "at " << u << endl;
//    cout << "bam:";
//    for (int x : bam) cout << " " << x;
//    cout << endl;
//    cout << "dan:";
//    for (int x : dan) cout << " " << x;
//    cout << endl;

    for (PII q : bam) {
        jogKoro(q.first, q.second);
    }

    for (PII q : dan) {
//        cout << "for " << i << endl;
        int w = q.first;
        int upore = mul(q.second, mul(u, w));

        while (w > 1) {
            upore = mul(upore, w>>1);
//            cout << (w>>1) << " upore: " << upore << " bam: " << sub(sm[w>>1], mul(sm[w], w)) << endl;
//            cout << "adds: " << mul(upore, sub(sm[w>>1], mul(sm[w], w))) << endl;
            ans = sum(ans, mul(upore, sub(sm[w>>1], mul(sm[w], w))));
            w >>= 1;
        }
    }

    for (PII q : bam) {
        biyogKoro(q.first, q.second);
    }

    vector< PII >total;
    for (PII q : bam) total.emplace_back(q.first, mul(q.second, u));
    for (PII q : dan) total.emplace_back(q.first, mul(q.second, u));
    return total;
}

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

    int H;
    cin >> H;

    L = 1<<(H-1);
    for (int i = 1; i <= L; i++) cin >> p[i];
    solve(1, 1, L);

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 6400
s=input()
l=len(s)
count=0
ans=0
for i in range(l):
  if s[i]=='A' or s[i]=='G' or s[i]=='C' or s[i]=='T':
    count+=1
  else:
    if count>ans:
      ans=count
    count=0
if count>ans:
  ans=count
print(ans)

Measured memory_bytes: 3188
n = int(input())
x = [[int(i) for i in input().split()] for i in range(n)]
answer = 0
for i in range(n-1,-1,-1):
	if (x[i][0]+answer)%x[i][1]!=0: answer+=x[i][1]-((x[i][0]+answer)%x[i][1])
print(answer)

Measured memory_bytes: 21156
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;
using namespace std;

int main(void) {
  ll N; cin >> N;
  ll sum = 0;
  deque<ll> A;
  for (int i = 0; i < N; i++) {
    ll tmp; cin >> tmp;
    if (i % 2 == 0) {
      A.push_back(tmp);
    } else {
      A.push_front(tmp);
    }
  }

  if (N % 2 == 1)
    reverse(A.begin(), A.end());

  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i < N - 1)
      cout << " ";
  }
  cout << endl;
}


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

int N;
string s;
vector<int> a(111111);

bool solve(int L,int R){
	for(int i=0;i<N+2;i++)a[i]=0;
	a[N]=a[0]=R;
	a[1]=a[N+1]=L;
	for(int i=1;i<=N;i++){
		int x;
		x=(s[i-1]=='o' ? 1 : -1);
		if(a[i+1]==0)a[i+1]=a[i-1]*a[i]*x;
		else if(a[i+1]!=a[i-1]*a[i]*x)return false;
	}
	
	for(int i=0;i<N;i++){
		if(a[i+1]==1)cout << 'S';
		else cout << 'W';
	}
	cout << endl;
	return true;
}

int main(){
	cin >> N >> s;
	
	if(solve(1,1))return 0;
	if(solve(1,-1))return 0;
	if(solve(-1,-1))return 0;
	if(solve(-1,1))return 0;
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int n, m, i, j, k, x, y, z, ans, a[105], b[105], c[105];
int main(){
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
	}
	for(i=0; i<=100; i++){
		for(j=0; j<=100; j++){
			ans = m = -1;
			for(k=1; k<=n; k++){
				if(c[k] == 0) continue;
				m = c[k] + abs(a[k]-i) + abs(b[k]-j);
				if(ans < 0) ans = m;
				if(m != ans) break;
			}
			if(k <= n) continue;
			for(k=1; k<=n; k++){
				if(c[k]) continue;
				if(ans - abs(a[k]-i) - abs(b[k]-j) > 0) break;
			}
			if(k <= n) continue;
			x = i, y = j, z = ans;
			i = j = 101;
		}
	}
	printf("%d %d %d\n", x, y, z);
	return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;


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

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int N;
    cin >> N;
    vector<ll> V(N);
    REP(i, N) cin >> V[i];
    vector<ll> pref(N + 3), suff(N + 2);
    pref[0] = V[0];
    FOR(i, 1, N - 1) {
    	pref[i] = gcd(pref[i - 1], V[i]);
    }
    suff[N - 1] = V[N - 1];
    FORD(i, N - 2, 0) {
    	suff[i] = gcd(suff[i + 1], V[i]);
    }
    ll ans = max(suff[1], pref[N - 2]);
    FOR(i, 1, N - 2) {
    	ans = max(ans, gcd(suff[i + 1], pref[i - 1]));
    }
    cout << ans << "\n";


}

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

typedef long long LL;

const int N=100000,INF=(1<<30)-1;

int n,m,cm,a[N+9],b[N+9],c[N+9];
struct side{
  int y,next;
}e[N*2+9];
int lin[N+9],cs;

void Ins(int x,int y){e[++cs].y=y;e[cs].next=lin[x];lin[x]=cs;}
void Ins2(int x,int y){Ins(x,y);Ins(y,x);}

int deg[N+9];

void into(){
  scanf("%d%d",&n,&m);cm=m;
  for (int i=1;i<=m;++i){
	scanf("%d%d%d",&a[i],&b[i],&c[i]);
	Ins2(a[i],b[i]);
	cm-=a[i]==b[i];
	++deg[a[i]];
  }
}

int vis[N+9],d[N+9],cd;

void Dfs_d(int k){
  vis[d[++cd]=k]=1;
  for (int i=lin[k];i;i=e[i].next)
	if (!vis[e[i].y]) Dfs_d(e[i].y);
}

int id[N+9],opt[N+9];
int cnt;

void Get_opt(){
  for (int i=1;i<=n;++i){
	if (vis[i]) continue;
	cd=0;
	Dfs_d(i);
	int now=cd>1;
	for (int j=1;j<=cd;++j)
	  if (deg[d[j]]>1) now=2;
	if (now==1) ++cnt;
	for (int j=1;j<=cd;++j) id[d[j]]=now;
  }
  for (int i=1;i<=m;++i)
	switch (id[a[i]]){
	  case 0:opt[i]=0;c[i]-=2;break;
	  case 1:opt[i]=1;c[i]-=1;break;
	  case 2:opt[i]=2+(a[i]!=b[i]);c[i]-=1;break;
	}
}

vector<int>w[3];

int Get_ans(int x,int y){
  int res=INF,sum=x;
  for (int vs=w[0].size(),i=0;i<vs;++i) sum+=w[0][i];
  if (sum>=cnt) return cm+y+cnt;
  sum=cnt-sum;
  int now1=0,now2=0;
  for (int vs=w[2].size(),i=0;i<vs;++i)
	if ((now2+=w[2][i])>=sum) res=min(res,cm+cnt+y+(i+1<<1));
  for (int vs=w[1].size(),p1=0,p2=w[2].size()?w[2].size()-1:-1;p1<vs;++p1){
	now1+=w[1][p1];
	for (;p2>=0&&now1+now2-w[2][p2]>=sum;now2-=w[2][p2],--p2);
	if (now1+now2>=sum) res=min(res,cm+cnt+y+p1+1+(p2+1<<1));
  }
  return res;
}

int ans;

void Get_ans(){
  ans=INF;
  if (!cnt) {ans=cm;return;}
  for (int i=1;i<=m;++i)
	if (c[i]>0&&opt[i]>=2) w[opt[i]==2].push_back(c[i]);
  sort(w[0].begin(),w[0].end(),greater<int>());
  sort(w[1].begin(),w[1].end(),greater<int>());
  ans=min(ans,Get_ans(0,0));
  if (!w[0].size()&&!w[1].size()) return;
  int t=w[0].empty(),x=w[t][0];
  w[t].erase(w[t].begin());
  for (int i=1;i<=m;++i)
	if (c[i]>0&&opt[i]<=1) w[opt[i]?0:2].push_back(c[i]);
  sort(w[0].begin(),w[0].end(),greater<int>());
  sort(w[1].begin(),w[1].end(),greater<int>());
  sort(w[2].begin(),w[2].end(),greater<int>());
  ans=min(ans,Get_ans(x,t));
}

void work(){
  Get_opt();
  Get_ans();
}

void outo(){
  printf("%d\n",ans==INF?-1:ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 9256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int dx[5] = { -1, 0, 0, 0, 1 };
const int dy[5] = {  0,-1, 0, 1, 0 };
int stage[10][10];
int cnt[10][10];

int Color(int y, int x ){
	int tmp = stage[y][x];
	rep (i, 5 ){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx >= 10 || ny >= 10 || nx < 0 || ny < 0 ) continue;
		tmp += cnt[ny][nx];
	} // end rep

	return tmp%2;
}

int solve(){
	for (int y = 1; y < 10; y++)
		rep (x, 10 )
			if (Color(y-1, x ) ) cnt[y][x]=1;
	rep (i, 10 )
			if (Color(9, i ) ) return -1;

	int ret=0;
	rep (y, 10 ) rep (x, 10 ) ret+=cnt[y][x];

	return ret;
}

int ans[10][10];

void bit_dfs(){

	int res = -1;
	rep (i, 1<<10 ){
		memset (cnt, 0, sizeof (cnt ) );
		rep (j, 10 ) cnt[0][j]=(i>>j)&1;
		int t = solve();
		if (t >= 0 && (res < 0 || res > t ) ){
			res = t;
			memcpy (ans, cnt, sizeof(cnt ) );
		} // end if
	} // end rep
}

int main()
{
	int T; scanf("%d", &T );
	while (T--){
		memset (ans, 0, sizeof(ans ) );
		memset (cnt, 0, sizeof(cnt ) );
		memset (stage, 0, sizeof(stage ) );
		rep (y, 10 ) rep (x, 10 ) cin >> stage[y][x];
		bit_dfs();
		rep (y, 10 ) rep (x, 10 ) cout << ans[y][x] << (x < 9 ? ' ' : '\n' );
	} // end while
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long long> vll;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string A,B,C;
    cin>>A>>B>>C;
    char S=A[0]-('a'-'A');
    char S1=B[0]-('a'-'A');
    char S2=C[0]-('a'-'A');
    cout<<S<<S1<<S2<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
# ifdef __GNUC__
# if __cplusplus > 199711L
# include <unordered_set>
# include <unordered_map>
# else
# include <tr1/unordered_map>
# include <tr1/unordered_set>
using namespace tr1;
# endif
# else
# include <unordered_map>
# include <unordered_set>
# endif
using namespace std;

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
typedef unsigned char byte;
typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<llong, llong> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

const int MAXN = 2e5 + 10;
int N;
vector<int> edges[MAXN];
bool vis[MAXN];
const int EMPTY = 0;
const int BLACK = 1;
const int WHITE = 2;
int color[MAXN];

int dfs1(int cur, int dis)
{
    vis[cur] = true;
    if (cur == N)
        return dis;
    FO (i, edges[cur].size())
    {
        if (vis[edges[cur][i]])
            continue;
        int res = dfs1(edges[cur][i], dis + 1);
        if (res != -1)
        {
            if (dis <= res / 2)
                color[cur] = BLACK;
            return res;
        }
    }
    return -1;
}

void dfs2(int cur)
{
    color[cur] = WHITE;
    FO (i, edges[cur].size())
        if (color[edges[cur][i]] == EMPTY)
            dfs2(edges[cur][i]);
}

int main()
{
    while (cin >> N)
    {
        FO (i, N + 1)
            edges[i].clear();
        memset(color, EMPTY, sizeof(color));
        memset(vis, 0, sizeof(vis));
        color[1] = BLACK;
        color[N] = WHITE;
        FO (i, N - 1)
        {
            int a, b;
            cin >> a >> b;
            edges[a].push_back(b);
            edges[b].push_back(a);
        }
        dfs1(1, 0);
        dfs2(N);
        int wcnt = 0;
        for (int i = 1; i <= N; ++i)
            wcnt += color[i] == WHITE;
        cout << (wcnt >= (N / 2 + N % 2) ? "Snuke" : "Fennec") << endl;
    }
    return 0;
}

Measured memory_bytes: 13696
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define REP(i, n) FOR(i, 0, n - 1, 1)
#define REP1(i, n) FOR(i, 1, n, 1)
#define RREP(i, n) RFOR(i, n - 1, 0, 1)
#define RREP1(i, n) RFOR(i, n, 1, 1)
#define FOR(i, a, b, c) for (ll i = a; i <= (ll)b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= (ll)b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define MAX3(a, b, c) MAX(MAX(a, b), c)
#define MIN3(a, b, c) MIN(MIN(a, b), c)
#define SWAP(a, b) do { typeof(a) _t; _t = a; a = b; b = _t; } while (0)
#define SORT(a, n) qsort(a, n, sizeof(typeof(a)), ({ int _f (const void *_a, const void *_b) { return *(typeof(a) *)_a - *(typeof(a) *)_b; } _f; }))
#define RSORT(a, n) qsort(a, n, sizeof(typeof(a)), ({ int _f (const void *_a, const void *_b) { return *(typeof(a) *)_b - *(typeof(a) *)_a; } _f; }))
#define SUM(a, n) ({ typeof(*(a)) _s = 0; REP(_i, n) _s += (a)[_i]; _s; })
#define PROD(a, n) ({ typeof(*(a)) _p = 1; REP(_i, n) _p *= (a)[_i]; _p; })
#define CNT(x, a, n) ({ int _c = 0; REP(_i, n) if ((a)[_i] == x) _c++; _c; })
#define MAXI(a, n) ({ int _m = 0; REP(_i, n) if ((a)[_i] > (a)[_m]) _m = _i; _m; })
#define MAXM(a, n) a[MAXI(a, n)]
#define MINI(a, n) ({ int _m = 0; REP(_i, n) if ((a)[_i] < (a)[_m]) _m = _i; _m; })
#define MINM(a, n) a[MINI(a, n)]
#define INF 1073709056
#define LLINF 4611686016279904256LL
typedef long long ll;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    printf("%d\n", a + b + c - MAX3(a, b, c));
    return 0;
}

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

bool IsPrimeNumber(int num);

int main() {
    int n;
    cin >> n;
    int count = 0;
    int ans[n];
    int num = 2;
    while (count < n) {
        if (IsPrimeNumber(num) && num % 5 == 1) {
            ans[count] = num;
            count++;
        }
        num++;
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i];
        if (i + 1 == n) cout << endl;
        else cout << ' ';
    }

}

bool IsPrimeNumber(int num) {
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;
    int n = 3;
    int max = num/2;
    while (n < max) {
        if (num % n == 0) return false;
        n += 2;
    }

    return true;
}

//bool IsCompositeNum


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

int main(){
    int K;
    string S;
    cin >> K;
    cin >> S;
    if(S.size() <= K ){
        cout << S <<endl;
    }else{
        for(int i = 0; i < K; i++){
            cout << S[i];
        }
        cout << "...";
    }
}

Measured memory_bytes: 3628
N = int(input())

a = [int(i) for i in input().split()]
b = -1
count = 0
ans = 0
for a_ in a:
    if b == a_:
        count += 1
    else:
        ans += count //2
        count = 1
    b = a_

ans += count //2
print(ans)


Measured memory_bytes: 2940
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String str=scan.next();
		char a=str.charAt(0);
		int count=0;
		for(int i=1;i!=str.length();i++) {
			char b=str.charAt(i);
			if(a!=b) {
				count++;
			}
			a=str.charAt(i);
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 24392
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

int color[9];

inline void solve(){
    int n,a,ans=0,other=0; cin>>n; 
    while (n--){
        cin >> a;
        if (a>=3200) other++; 
        else if (a>=2800) color[8]=1; 
        else if (a>=2400) color[7]=1; 
        else if (a>=2000) color[6]=1; 
        else if (a>=1600) color[5]=1; 
        else if (a>=1200) color[4]=1; 
        else if (a>=800) color[3]=1; 
        else if (a>=400) color[2]=1; 
        else color[1]=1; 
    }
    for (int i=1;i<=8;i++)
        if (color[i]) ans++;
    cout << max(ans,1LL) << " " << ans+other<<endl;
    return;
}

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


Measured memory_bytes: 3592
import java.util.Scanner;

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

        while(true) {
            int n = sc.nextInt();
            int x = sc.nextInt();

            if (n == 0 && x == 0)
                break;

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}



Measured memory_bytes: 26336
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef long double Real;

Real eps = 1e-9;

Real add(Real a, Real b) {
    if (abs(a+b) < eps * (abs(a)+abs(b))) return 0;
    return a+b;
}

bool equal(Real a, Real b) {
    return add(a, -b) == 0;
}

struct P {
    Real x, y;
    P() {}
    P(Real x, Real y) : x(x), y(y) {}
    P operator+(P p) const {return P(add(x, p.x), add(y, p.y));}
    P operator-(P p) const {return P(add(x, -p.x), add(y, -p.y));}
    P operator*(Real d) const {return P(x*d, y*d);}
    Real dot(P p) const {return add(x*p.x, y*p.y);} // ??????
    Real det(P p) const {return add(x*p.y, -y*p.x);} // ??????
    Real dist(P p) const {return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y));} // ?????¢
    void normalize() {Real d = sqrt(x*x+y*y); x /= d; y /= d;} // ??£??????
    bool operator<(const P& rhs) const {
        if (x != rhs.x) return x < rhs.x;
        return y < rhs.y;
    }
    bool operator==(const P& rhs) const {
        return equal(x, rhs.x) && equal(y, rhs.y);
    }
};
const int MAXN = 333;
P pnt[MAXN];
int N;

int calc(P center) {
	int ret = 0;
	for (int i = 0; i < N; i++) {
		P vec = pnt[i]-center;
		if (vec.dot(vec) < 1+eps) {
			ret++;
		}
	}
	return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> N) {
    	if (N==0) break;
    	for (int i = 0; i < N; i++) 
    		cin >> pnt[i].x >> pnt[i].y;
    	int ans = 1;
    	for (int i = 0; i < N; i++) for (int j = i+1; j < N; j++) {
    		if (pnt[i].dist(pnt[j]) > 2) continue;
    		// diff ?????????
    		P vec = pnt[j]-pnt[i];
    		// vec ????????´????????????????????????
    		P n = P(vec.y, -vec.x);
    		n.normalize();
    		vec = vec*0.5;
    		Real len = sqrt(1-vec.dot(vec));
    		P cand1 = pnt[i] + vec + n*len;
    		P cand2 = pnt[i] + vec - n*len;
    		ans = max(ans, calc(cand1));
    		ans = max(ans, calc(cand2));
    	}
    	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int a, b, c, k;
int cnt = 0;

int main() {
    cin >> a >> b >> c >> k;

    while (a >= b && (k--) > 0){
        b*=2;
    }

    while (b >= c && (k--) > 0){
        c*=2;
    }
    
    if (a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n, x;

  while(true) {
    cin >> n >> x;
    if(n == 0 && x == 0) {
      break;
    }

    int count = 0;
    repf(i, 1, n + 1) {
      repf(j, i + 1, n + 1) {
        repf(k, j + 1, n + 1) {
          if(i + j + k == x) {
            count++;
          }
        }
      }
    }

    cout << count << endl;
  }
}


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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
 string s; cin>>s;
 int ans=0;
 if(s[1]=='S'){
   if(s[0]=='R'||s[2]=='R')ans=1;
 }else{
   ans++;
   if(s[0]=='R') ans++;
   if(s[2]=='R') ans++;
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 3572
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
# ... 最小側の制約も確認した？
# ... オーバーフローしない？
s = input()
if s.islower(): print('a')
else: print('A')

Measured memory_bytes: 9320
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
typedef long long ll;
using namespace std;

const int N=500010;
int n,ans,a[N],b[N],c[N];
char s[N];

int main(){
	scanf("%d",&n); scanf("%s",s+1); ans=n+1;
	rep(i,1,n) if (s[i]=='W') a[i]=0; else a[i]=1;
	rep(i,1,n) if (!a[i]) b[i]=b[i-1]+1; else b[i]=b[i-1];
	for (int i=n+1; i; i--) if (a[i]) c[i]=c[i+1]+1; else c[i]=c[i+1];
	rep(i,1,n) ans=min(ans,b[i-1]+c[i+1]);
	printf("%d\n",ans);
	return 0;
}

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

r, g, b = 0, 0, 0
for c in S:
  if c == "R": r += 1
  if c == "G": g += 1
  if c == "B": b += 1

total = r*g*b

for i in range(N):
  for j in range(i+1, N):
    if S[i] == S[j]: continue

    k = 2*j - i
    if k >= N: continue
    if S[i] == S[k] or S[j] == S[k]: continue
    total -= 1

print(total)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> P;
typedef pair<int,P> E;
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n,q;cin>>n>>q;
  vector<E> v;
  rep(i,n){
    int a,b,c;cin>>a>>b>>c;
    v.push_back(E(a-c,P(-1,c)));
    v.push_back(E(b-c,P(0,c)));
  }
  rep(i,q){
    int c;cin>>c;
    v.push_back(E(c,P(1,i)));
  }
  sort(all(v));
  multiset<int> m;
  for(auto a:v){
    int x=a.first,y=a.second.first,z=a.second.second;
    if(y==-1)m.insert(z);
    else if(y==0)m.erase(m.lower_bound(z));
    else cout<<(m.empty()?-1:*m.begin())<<endl;
  }
}

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

int main() {

  double r;
  cin >> r;
  
  double s, l;
  
  l = 2*M_PI*r;
  s = M_PI*r*r;
  
  printf("%f %f\n", s, l);
  
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  string s;
  cin>>s;
  bool ja=true;
  if(s[0]!='A') ja=false;
  int C=0;
  for(int i=2;i<s.length()-1;i++){
    if(s[i]=='C') C++;
  }
  if(C!=1) ja=false;
  int cnt=0;
  rep(i,s.length()){
    if(s[i]>='A'&&s[i]<='Z') cnt++;
  }
  if(cnt!=2){
    ja=false;
  }
  if(ja){
    cout<<"AC"<<endl;
    return 0;
  }
  cout<<"WA"<<endl;
}

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

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

    string s;
    cin >> s;

    if(a >= 3200)
    {
        cout << s << endl;
    }

    else
    {
        cout << "red" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100LL
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
	int a,b,c;
	ll k;
	cin>>a>>b>>c>>k;
	k&=1;
	a-=b;
	if(k&1)a*=-1;
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
# from pprint import pprint
# import math
# import collections

# n = int(input())
n, m = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
a, b = [], []
for i in range(n):
    _a, _b = map(int, input().split(' '))
    a.append(_a)
    b.append(_b)
c, d = [], []
for i in range(m):
    _c, _d = map(int, input().split(' '))
    c.append(_c)
    d.append(_d)

move = [[0] * m for i in range(n)]

for i in range(n):
    for j in range(m):
        move[i][j] = abs(a[i] - c[j]) + abs(b[i] - d[j])

ans = [0] * n
for i in range(n):
    for j in range(m):
        _min = min(move[i])
        ans[i] = move[i].index(_min) + 1

for a in ans:
    print(a)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//-----------------------------------------------------------------------------

string s,t;

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

	cin>>s;
	t=s;
	reverse(ALL(t));
	REP(i,t.size()) {
		if(t[i]=='b') t[i]='d';
		else if(t[i]=='d') t[i]='b';
		else if(t[i]=='p') t[i]='q';
		else t[i]='p';
	}
	cout<<(s==t?"Yes":"No")<<endl;

	return 0;
}


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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int a[n + 1];
  a[0] = 0;
  a[n + 1] = 0;
  for(int i = 1;i <= n;i++)
    cin >> a[i];
  ll res = 0;
  for(int i = 1;i <= n + 1;i++){
    res += abs(a[i] - a[i - 1]);
  }
  for(int i = 1;i <= n;i++){
      cout << res + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]);
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
#define all(a) a.begin(), a.end()
#define mp(a, b) make_pair(a, b)

int INF = 100100100;
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep(i, 2, MAX){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll PERM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n-k] % MOD;
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll culc(ll a, ll b, ll c){
    return (((a*b)%MOD)*((c*c)%MOD))%MOD;
}

int main(){
    COMinit();
    int N;
    int M;
    cin >> N >> M;
    ll ans = 0;
    rep(i, 0, N+1){
        ll ret;
        ret = culc(COM(N, i), PERM(M, i), PERM(M-i, N-i));
        if (i%2 == 0){
            ans += ret;
        }
        else{
            ans += MOD;
            ans -= ret;
        }
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15512
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
vi a;
void calc(ll &mn) {
	for(int i = 1; i < n; i++) {
		if(mn%a[i]) {
			mn -= (mn%a[i]);
			mn += a[i];
		}
	}
}
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i;
	reverse(all(a));
	if(a[0]!=2) {
		return cout << -1, 0;
	}
	ll mn = 2, mx = 4;
	calc(mn), calc(mx);
	mx--;
	if(mn>mx) {
		return cout << -1, 0;
	}
	cout << mn << " " << mx;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int min(int a, int b) {
    if(a >= b) {
        return b;
    }
    else {
        return a;
    }
}

int max(int a, int b) {
    if(a > b) {
        return a;
    }
    else {
        return b;
    }
}

int max3(int a, int b, int c) {
    return max(max(a, b), c);
}

int main(void) {
    int N;
    scanf("%d", &N);
    int **a = (int**)malloc(N * sizeof(int*));
    int **dp = (int**)malloc((N+1) * sizeof(int*));

    int i, j, now, bef;
    for(i=0; i<N+1; i++) {
        dp[i] = (int*)malloc(3 * sizeof(int));
    }
    for(i=0; i<N; i++) {
        a[i] = (int*)malloc(3 * sizeof(int));
        scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
    }
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for(i=1; i<N+1; i++) {
        dp[i][0] = INT_MIN;
        dp[i][1] = INT_MIN;
        dp[i][2] = INT_MIN;

    }
    for(i=0; i<N+1; i++) {
        for(j=0; j<3; j++) {
        }
    }
    for(i=0; i<N; i++) {
        for(now=0; now<3; now++) {
            for(bef=0; bef<3; bef++) {
                if(now != bef) {
                    int temp = max(dp[i+1][now], dp[i][bef] + a[i][now]);
                    dp[i+1][now] = temp;
                }
            }
        }
    }

    printf("%d\n", max3(dp[N][0], dp[N][1], dp[N][2]));
    for(i=0; i<N+1; i++) {
        free(dp[i]);
        if(i<N) {
            free(a[i]);
        }
    }
    free(dp);
    free(a);
    return 0;
}

Measured memory_bytes: 7936
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x); 
        y = y>>1;
        x = (x*x); 
    } 
    return res; 
}

// const int N = 1e5 + 1;
// vector<int > graph[N];

// void bfs(int n, int s, int ans[]) {
//     ans[s] = 1;
//     queue<int> q;
//     q.push(s);
//     while(!q.empty()) {
//         int v = q.front();
//         q.pop();
//         // cout<<v<<" source\n";
//         for(int b: graph[v]) {
//             if(ans[b] == 0) {
//                 ans[b] = 1;
//                 q.push(b);
//             }
//         }
//     }
// }


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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    int n,m;
    cin>>n>>m;
    ll a[n];
    inp_arr(a,n);
    sort(a,a+n);
    vector<ll> v;
    vector<pair<ll,ll> > other;
    for(int i=0;i<n;++i) {
        v.push_back(a[i]);
    }
    for(int i=0;i<m;++i) {
        ll b,c;
        cin>>b>>c;
        other.push_back(make_pair(c,b));
    }
    sort(other.begin(),other.end());
    int count = 0;
    for(int i=other.size()-1; i>=0; --i) {
        if(count >= n) {
            break;
        }
        for(int j=0;j<other[i].second;++j) {
            if(count >= n)
                break;
            v.push_back(other[i].first);
            ++count;
        }
    }
    sort(v.begin(),v.end());
    count = 0;

    ll sum = 0;
    for(int i=v.size()-1;i>=0;--i) {
        if(count >= n) break;
        sum += v[i];
        ++count;
    }
    cout<<sum<<"\n";

    return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n);
  priority_queue<pair<ll, int>> q;
  rep(i, n) {
    cin >> A[i];
    q.push({A[i], i});
  }
  q.push({0, -1});
  vector<ll> ans(n);
  int cnt = 0;
  int mn = inf;
  while(!q.empty()) {
    auto top = q.top(); q.pop();
    cnt++;
    ll cur = top.first;
    if(cur == 0) break;
    chmin(mn, top.second);
    while(!q.empty() && q.top().first == cur) {
      chmin(mn, q.top().second);
      cnt++;
      q.pop();
    }
    auto next = q.top();
    ll diff = (cur - next.first) * cnt;
    ans[mn] += diff;
  }
  rep(i, n) cout << ans[i] << endk;
  return 0;
}


Measured memory_bytes: 6328
#約数が8個の時、数の素因数を2^a, 3^b, ...とすると(a+1)*(b+1)*... = 8となる
#Nまでの素数を出す
N = int(input())
N_MAX = 200
prime = [1 for i in range(N_MAX+1)]
prime[0], prime[1] = 0, 0
for i in range(2, N_MAX+1):
    if prime[i] == 1:
        for j in range(2*i, N_MAX+1, i):
            prime[j] = 0
prime[2] = 0
ps = []
for i in range(N_MAX+1):
    if prime[i] == 1:
        ps.append(i)
pl = len(ps)
ans = 0
for i in range(pl):
    for j in range(i+1, pl):
        if (ps[i]**3)*ps[j] <= N or ps[i]*(ps[j]**3) <= N:
            ans += 1
        for k in range(j+1, pl):
            if ps[i]*ps[j]*ps[k] <= N:
                ans += 1
print(ans)

Measured memory_bytes: 3064
//region trash
#ifndef LOCAL
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#else
#define DB(x){}
#endif
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>bool MA(X&a,Y b){if(a<b){a=b;return true;} return false;}
template<typename X, typename Y>bool MI(X&a,Y b){if(a>b){a=b;return true;} return false;}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
using namespace std;
int cond=0;
//endregion

int mode=0;

struct Solver {
  void solve() {
    int R,G,B,N;
    cin>>R>>G>>B>>N;

    VV<LL> SUM(N+1, 0);

    LL res = 0;
    FOR(r,0,3000) {
      FOR(g,0,3000) {
        LL sum = r * R + g * G;
        if (sum > N) continue;
        LL rem = N - sum;
        if (rem % B == 0) {
          res+=1;
        }
      }
    }
    cout<<res<<endl;
  }
};


int main(int argc,char** argv){
  struct Solver2 {
    void gen() {}
    void brute() {}
  };
  random_device rd{};
  uint64_t seed = (uint64_t)rd()
      ^ (uint64_t)std::chrono::steady_clock::now().time_since_epoch().count()
      ^ (uint64_t)__builtin_ia32_rdtsc()
      ^ (uint64_t)make_unique<char>().get();
  srand(seed); mt19937 rng(seed);

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(mode >= 1)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(mode == 2)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 333331/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1 + key%(M-1); }

int find(char str[]){
  long long key, i , h;
  key = getKey(str);
  for(i = 0; ; i++)
    {
      h = (h1(key) + i * h2(key))%M;
      if(strcmp(H[h],str) == 0)return 1;
      else if(strlen(H[h]) == 0)return 0;
    }
    
  return 0;
}

int insert(char str[]){
  long long key, i, h;

  key = getKey(str);
  for(i = 0; ; i++)
    {
      h = (h1(key) + i * h2(key))%M;
      if(strcmp(H[h],str) == 0)return 1;
      else if(strlen(H[h]) == 0)
	{
	  strcpy(H[h],str);
	  return 0;
	}
    }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}




Measured memory_bytes: 6328
#include<stdio.h>
#include<string.h>

#define M 1006000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
	long long key,i,h;
	key = getKey(str);
	for(i=0;;i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int insert(char str[]){

	long long key, i, h;
	key = getKey(str);
	for(int i=0;;i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0) {
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
		scanf("%s %s", com, str);
		
		if ( com[0] == 'i' ){
		    insert(str);
		} else {
		    if (find(str)){
			printf("yes\n");
		    } else {
			printf("no\n");
		    }
		}
    }

    return 0;
}

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

int main() {
	map<int, int>mp;
	rep(i, 4) {
		int e; cin >> e;
		mp[e]++;
	}
	puts(mp.size() == 1 || (mp.size() == 2 && (*mp.begin()).second == 2 && (*mp.rbegin()).second == 2) ? "yes" : "no");
}

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

int main(){
  int N,M,a,b;
  cin>>N>>M;
  
  int P[10][10];//隣接行列
  int F[10];//訪問フラグ F[0] - F[N-1]
  
  //隣接行列初期化
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      P[i][j]=0;
    }
  }
  
  //隣接データ入力
  for(int i=0;i<M;i++){
    cin>>a>>b;
    a--;
    b--;
    P[a][b]=1;
    P[b][a]=1;
  }
  
  vector<int>vec(N-1,0);//* N-1 か　Nか
  for(int i=0;i<N-1;i++){
    vec.at(i)=i+1;
  }
  
  int ans=0;
   do {
    /*for(int k=0;k<N-1;k++){
      cout<<vec.at(k)<<endl;
    }*/
      
    //F初期化
    for(int i=0;i<N-1;i++){
      F[i]=0;
    }
    
    //パス確認
    if(P[0][vec.at(0)]==0){
      //cout<<"$"<<vec.at(0)<<endl;
      continue;
    }
    else{
      F[0]=1;
    }
    
    for(int i=0;i<N-2;i++){
      if(P[vec.at(i)][vec.at(i+1)]==1){ 
        F[i+1]=1;
        continue;
      }
      else{
        break;
      }
    }
    
    //全パス確認　ans++
    int flag=1;
    for(int i=0;i<N-1;i++){
      if(F[i]==0){
        //cout<<i<<"#"<<vec.at(0)<<endl;
        flag=0;
        break;
      }
    }
    if(flag){
      ans++;
    }
  } 
  while (next_permutation(vec.begin(), vec.end()));
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3600
n = int(input())
s= [input() for i in range(n)]
ans1=0
firstB=0
lastA=0
m=n
for i in s:
    ans1+=i.count("AB")
    if i[0]=="B":
        firstB+=1
    if i[-1]=="A":
        lastA+=1
    if i[0]!="B" and i[-1]!="A":
        m-=1
if min(firstB,lastA)==m:
    if m==0:
        print(ans1)
    else:
        print(ans1+m-1)
else:
    print(ans1+min(firstB,lastA))

Measured memory_bytes: 3700
import sys,math
input = sys.stdin.readline

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i in range(N):
  for j in range(N):
    num = 0
    if i < j:
      for k in range(D):
        num += pow(abs(X[i][k] - X[j][k]) ,2)
      if math.floor(math.sqrt(num)) ** 2 == num:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
using namespace std;
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main(){
    
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];

    int ans;

    if(N>2){
        
        int gcd_l[N];
        gcd_l[0] = 0;
        for(int i=1;i<N;i++){
            gcd_l[i] = __gcd(gcd_l[i-1],A[i-1]);
        }
        
        int gcd_r[N];
        gcd_r[N-1] = 0;
        for(int i=N-2;i>=0;i--){
            gcd_r[i] = __gcd(gcd_r[i+1],A[i+1]);
            
        }
        
        ans = 1;
        for(int i=0;i<N;i++){
            int tmp0 = gcd_r[i];
            int tmp1 = gcd_l[i];
            int tmp = __gcd(tmp0,tmp1);
            ans = max(tmp,ans);
            
        }
        
    }else{
        ans = max(A[0],A[1]);
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n,i,maxx=0,x;
    string str;
    map<string,int>mp;
    map<string,int>::iterator it;

    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>str;
        if(mp.count(str)==0)
        {
            mp.insert(make_pair(str,1));
        }
        else mp[str]++;
        maxx=max(mp[str],maxx);
    }
    for(it=mp.begin(); it!=mp.end(); it++)
    {
        x=it->second;
        str=it->first;
        if(x==maxx)cout<<str<<endl;

    }



    return 0;
}



Measured memory_bytes: 25216