akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args:Array<String>?): Unit {
    while(true){
        val (m, n) = readLine()!!.trim().split(' ').map(String::toInt)
        if (m == 0) return
        val queue: Queue<Int> = LinkedList<Int>()
        for (i in 1 .. m) queue.add(i)
        for (i in 1 .. n){
            val s = readLine()!!.trim()
            if (queue.size == 1) continue
            if (i % 15 == 0){
                if (s == "FizzBuzz") queue.add(queue.poll())
                else queue.poll()
            }else if (i % 5 == 0){
                if (s == "Buzz") queue.add(queue.poll())
                else queue.poll()
            }else if (i % 3 == 0){
                if (s == "Fizz") queue.add(queue.poll())
                else queue.poll()
            }else {
                if (i.toString() == s) queue.add(queue.poll())
                else queue.poll()
            }
        }
        println(queue.sorted().joinToString(" "))
    }
}


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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    int res = 0;
    char inp[6][6];
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j)
        {
            char ch;
            cin >> ch;
            inp[i][j] = ch;
        }
        
    for(int rMask = 0; rMask < (1 << h) - 1; ++rMask )
    {
        for(int cMask = 0; cMask < (1 << w) - 1; ++cMask)
        {
            int blk = 0;
            for(int i = 0; i < h; ++i)
            {
                for(int j = 0; j < w; ++j)
                {
                    if(((rMask >> i) & 1 ) == 0  &&((cMask >> j) & 1 ) == 0 && inp[i][j] =='#')
                    {
                        blk += 1;
                    }
                }
            }
            if(blk == k)
            res += 1;
        }
    }
    cout << res;
}

Measured memory_bytes: 3636
from collections import deque

s = input()
q = int(input())
isInversed = False
front = deque()
back = deque()
for _ in range(q):
    inp =  list(input().split())
    if inp[0] == '1':
        isInversed = not isInversed
    else:
        if inp[1] == '1':
            if not isInversed:
                front.appendleft(inp[2])
            else:
                back.append(inp[2])
        else:
            if not isInversed:
                back.append(inp[2])
            else:
                front.appendleft(inp[2])

front_str = ''.join(front)
back_str = ''.join(back)
ans = front_str + s + back_str

if not isInversed:
    print(ans)
else:
    print(ans[::-1])

Measured memory_bytes: 68696
//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int min(int a,int b){if(a<b){return a;}return b;}

long long nCr[64][64]={0};
void calcnCr(){
  nCr[0][0]=1;
  long long i,j;
  for(i=0;i<63;i++){
    for(j=0;j<=i;j++){
      nCr[i+1][j]+=nCr[i][j];
      nCr[i+1][j+1]+=nCr[i][j];
    }
  }
  return;
}

long long res=0,s,t,k;

void rep(int nb,int nv,int lis[],int c){
  int i,bd;
  if(nb==-1){
    long long ce=1;
    bd=min(c,k);
    if(nv&1){ce=-1;}
    for(i=1;i<=bd;i++){
      //printf("<%lld>\n",ce*nCr[c][i]);
      res+=(ce*nCr[c][i]);
    }
    return;
  }
  //printf("<%d %d>:",nb,nv);
  //for(i=0;i<c;i++){printf("[%d]",lis[i]);}printf("\n");
  rep(nb-1,nv,lis,c);
  if((s&(1<<nb))==(t&(1<<nb))){return;}
  int liz[64],lio[64],lzc=0,loc=0;
  for(i=0;i<c;i++){
    if((lis[i]&(1<<nb))){lio[loc]=lis[i];loc++;}
    else{liz[lzc]=lis[i];lzc++;}
  }
  rep(nb-1,nv+1,lio,loc);
  rep(nb-1,nv+1,liz,lzc);
}

int main(void){
  calcnCr();
  int i,j,n,a[64];
  int lis[64],c=0;
  scanf("%d%d%d%d",&n,&k,&s,&t);
  if((s&t)!=s){printf("0\n");return 0;}
  if((s|t)!=t){printf("0\n");return 0;}
  for(i=0;i<n;i++){scanf("%d",&a[i]);}
  for(i=0;i<n;i++){
    if((a[i]&s)!=s){continue;}
    if((a[i]|t)!=t){continue;}
    lis[c]=a[i];c++;
  }
  rep(17,0,lis,c);
  printf("%lld\n",res);
  return 0;
}


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

x = [-1]*n

x[0] = 0
for i in range(n):
    x[0] += (-1)**(i+2) * a[i]

for i in range(1,n):
    x[i] = 2*a[i-1]-x[i-1]

# print(x)

for i in range(n):
    print(x[i],end=" ")

Measured memory_bytes: 14028
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N,tmp;
	cin >> N;
	if (N == 1) {
		cout << "Yes" << endl;
		cout << 2 << endl;
		cout << 1 << " " << 1 << endl;
		cout << 1 << " " << 1 << endl;
		return 0;
	}
	bool F = false;
	REP(i, N) {
		if (i*(i + 1) == 2 * N) {
			F = true;
			tmp = i + 1;
			break;
		}
	}

	if (!F) {
		cout << "No" << endl;
		return 0;
	}


	vector<VI> ans(tmp);
	int a = 1;
	int b = 0;
	int sa = 2;
	do{
		REP(k, a-b) {
			ans[k].push_back(b + k+1);
		}
		eFOR(i, b + 1, a) {
			ans[sa-1].push_back(i);
		}
		b = a;
		a += sa;
		sa++;
		
	}while (sa*(sa - 1) <= 2 * N);


	cout << "Yes" << endl;
	cout << tmp << endl;
	REP(i, tmp) {
		cout << ans[i].size() << " ";
		REP(j, ans[i].size()) {
			cout << ans[i][j];
			if (j != ans[i].size() - 1)cout << " ";
		}
		cout << endl;
	}


	return 0;
}



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

using namespace std;
const int maxN = 105;
int n;
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int sum = 0;
    int mn = 105;
    for (int i = 1; i <= n; i++) {
        int s;
        cin >> s;
        sum += s;
        if (s % 10 != 0 && s < mn) mn = s;
    }
    if (mn == 105) mn = sum;
    if (sum % 10 != 0) cout << sum << endl;
    else cout << sum - mn << endl;
    return 0;
}


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

int main() {
    
    int a;
    
    scanf("%d", &a);
        
    int h=a/60/60;
    int m=a/60%60;
    int s=a%60;
    printf("%d:%d:%d\n", h, m, s);
    
    return 0;
}



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

int main(){
	vector<int> a;
	int n;

	for(int i=0 ; i<5 ; i++){
		cin >> n;
		a.push_back(n);
	}
	sort( a.begin(), a.end(), greater<int>());
	for(int i=0 ; i<=4 ; i++){
		cout << a[i];
		(i==4)? cout << endl : cout << " ";

	}
}

Measured memory_bytes: 1216
#ABC126 C

import math
N,K = map(int,input().split())
P = 0
for i in range(1,N+1):
    if i >= K:
        P += 1/N
    else:
        P += (1/N)*(0.5)**(math.ceil(math.log(K/i,2)))
        
print(P)

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int i = 0;
  while(i < s.size()) {
    if(s[i] != '0' && s[i] != '1') {
      if(i > 0) {
      	s.erase(i - 1, 2);
      	i --;
	  } else {
	  	s.erase(i, 1);
	  }
	} else {
		i ++;
	}
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int a[200000];
    for(int i=1;i<n+1;i++){
        cin>>a[i];
    }
    int count=0;
    int next=1;
    set<int> b={1};
    while(1){
        count++;
        next=a[next];
        if(next==2){
            cout<<count<<endl;
            return 0;
        }
        if(b.find(next)==b.end()){
            b.insert(next);
        }else{
            cout<<"-1"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  string m,n;
  cin>>a>>m>>n;
  for(int i=0;i<a;i++){
    char b = m[i];
    char c = n[i];
    cout<<b<<c;
  }
  return 0;
}

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

int main(){
  int A,B,C;
  cin >>A>>B>>C;
  set<int> P;
  P.insert(A);
  P.insert(B);
  P.insert(C);
  if(P.size()==2){
    cout <<"Yes"<<endl;
  }
  else{
    cout <<"No"<<endl;
  }
}


Measured memory_bytes: 256
import math

N = int(input())
P = []
for _ in range(N):
    P.append([int(n) for n in input().split()])

R2 = 0

for i in range(180):
    theta = 2 * math.pi * i / 180
    a, b = math.cos(theta), math.sin(theta)
    X, Y = 0, 0
    for x, y in P: 
        if a*x+b*y > 0: # 内積が正 ( = なす角度が鋭角 = そのベクトルを加えると距離が増加)
            X += x
            Y += y
    r2 = X**2+Y**2
    if r2 > R2:
        R2 = r2

print(math.sqrt(R2))

Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
const int mod=1e9+7;
int pp[maxn];
ll fac[maxn];
ll quick(ll a,ll b)
{
    ll ret=1;
    while(b)
    {
        if(b&1) ret=ret*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ret;
}
ll inv(ll a){return quick(a,mod-2);}
ll C(int n,int m)
{
    if(m>n) return 0;
    if(m<0) return 0;
    return fac[n]*inv(fac[m])%mod*inv(fac[n-m])%mod;
}
int main()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
    int n;
    cin>>n;
    vi a(n+1);
    memset(pp,-1,sizeof(pp));
    int tar=-1,pos1=-1,pos2=-1;
    for(int i=0;i<=n;i++) 
    {
        cin>>a[i];
        if(pp[a[i]]!=-1)
        {
            tar=a[i];
            pos1=pp[a[i]];
            pos2=i;
        }
        pp[a[i]]=i;
    }
    for(int i=1;i<=n+1;i++)
    {
        print((C(n+1,i)-C(n+1-(pos2-pos1),i-1)+C(n+1-(pos2-pos1-1)-2,i-2)+mod)%mod);
    }   
}

Measured memory_bytes: 2816
n, k=map(int, input().split())
a=list(map(int, input().split()))
ans=0
d={}
for ai in a:
    if ai in d:
        d[ai]+=1
    else:
        d[ai]=1
cnt=sorted(list(d.values()), reverse=True)
print(sum(cnt[k:]))

Measured memory_bytes: 32284
//Patwari26
//#include template<t> as mine
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,x,m;
    cin>>n>>x>>m;
    ll curr=x;
    ll ans[m];
    ll zz=0;
    ll tot=0;
    memset(ans,0,sizeof(ans));
    ll i=0;
    for(i=1;i<=m+1;i++){
        if(ans[curr]!=0) break;
        if(zz==n) break;
        zz++;
        tot+=curr;
        ans[curr]=i;
        curr=(curr*curr)%m;
    }
    if(zz==n){
        cout<<tot<<endl;
        return;
    }
    // cout<<curr<<" ";
    ll idx=curr;
    ll cc=0;
    ll totnew=0;
    for(i=1;i<=m+1;i++){
        if(zz==n) break;
        zz++;
        tot+=curr;
        totnew+=curr;
        cc++;
        curr=(curr*curr)%m;
        if(curr==idx) break;
    }
    if(zz==n){
        cout<<tot<<endl;
        return;
    }
    ll left=(n-zz);
    tot+=(left/cc)*totnew;
    left=left%cc;
    zz=0;
    for(i=1;i<=m+1;i++){
        if(zz==left) break;
        zz++;
        tot+=curr;
        curr=(curr*curr)%m;
    }
    cout<<tot<<endl;

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

Measured memory_bytes: 4312
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
bef = 100

for a in A:
  ans+=B[a-1]
  if a-bef == 1:
    ans+=C[a-2]
  bef = a
  
print(ans)

Measured memory_bytes: 9036
/*
    I was lying to myself
*/




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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int>pii;
typedef unsigned long long ull;

#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF          0x3f3f3f3f
#define inputfile    freopen("input.txt", "r", stdin)
#define outputfile   freopen("output.txt", "w", stdout)
#define appendfile   freopen("output.txt", "a", stdout)


struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);auto hash2 = hash<T2> {}(p.second);return hash1 ^ hash2;
    }
};

ll t;
ll mod=N;
ll BigMod(ll base,ll pow,ll mod)
{
    if(pow==0||base==1)return 1;
    else if(pow==1)return base;
    else if(pow%2)return BigMod(base,pow-1,mod)*base%mod;
    else {ll x=(BigMod(base,pow/2,mod)%mod);x=(x*x)%mod;return x;}
}



vector<ll>v[100005];
ll in[100005],dp[100005];
queue<ll>q;

int main()
{
    fast;
    ll a,b,c,d,e,f,g,i,j;
    ll n,m,k;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        v[a].pb(b);
        in[b]++;
    }
    for(i=1;i<=n;i++)
    {
        if(in[i]==0)q.push(i);
    }
    while(!q.empty())
    {
        a=q.front();
        q.pop();
        for(i=0;i<v[a].size();i++)
        {
            b=v[a][i];
            in[b]--;
            dp[b]=max(dp[b],dp[a]+1);
            if(in[b]==0)
            {
                q.push(b);
            }
        }
    }
    f=0;
    for(i=1;i<=n;i++)
    {
        f=max(f,dp[i]);
    }
    cout<<f<<endl;
    return 0;
}



Measured memory_bytes: 10612
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[N];
  for(int i = 0;i<N;i++){
    cin>>a[i];
  }
  int ans = 0;
  for(int i = 0;i<N-2;i++){
    if(a[i]>a[i+1] && a[i+1] > a[i+2]){
      ans++;
    }
    else if(a[i]<a[i+1] && a[i+1]<a[i+2]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

vector<long> divisor(long n) {
  vector<long> ret;
  for(long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}

bool isPrime(int x); 
int gcd(int a, int b); 
vector<int> primeFactorization(int x); 
void forPrint(vector<long> list, string str); 


vector<long> pickPrime(vector<long> x) {
  vector<long> ans;

  for (int i = 0; i < x.size(); i++) {
    if (isPrime(x[i])) {
      ans.push_back(x[i]);
    }
  }
  
  return ans;
}

int main() {
  int n;
  cin >> n;
  cout << n * n << endl;
}

// 最大公約数
int gcd(int a, int b) {
  if (a%b == 0) {
    return b;
  } else return gcd(b, a%b);
}

bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;

  double num = sqrt(x);
  for (int i = 3; i <= num; i+=2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

vector<int> primeFactorization(int x) {
  vector<int> ans;
  int i = 2;
  while (i*i <= x) {
    if (x % i == 0) {
      ans.push_back(i);
      x /= i;
    } else {
      i++;
    }
  }
  ans.push_back(x);
  return ans;
}

void forPrint(vector<long> list, string str) {
  for (int i = 0; i < list.size(); i++) {
    cout << str << ": " << list[i] << endl;
  }
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] h = new int[n];

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

        boolean isAns = true;
        for (int i = n-1; i > 0; i--) {
            if (h[i] < h[i-1]) {
                h[i-1]--;
                if (h[i] < h[i-1]) {
                    isAns = false;
                    break;
                }
            }
        }

        System.out.println(isAns ? "Yes" : "No");
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 47120
A, B, C, X, Y = map(int, input().split())

C *= 2
ans = 0
if A + B <= C:
    ans += A * X + B * Y
else:
    min_num = min(X, Y)
    ans += min_num * C
    X -= min_num
    Y -= min_num
    if X > 0:
        if A > C:
            ans += X * C
        else:
            ans += X * A
    if Y > 0:
        if B > C:
            ans += Y * C
        else:
            ans += Y * B
print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<long long, long long>> robot(n);
    vector<pair<long long, int>> arms, smra;
    for (auto &&i : robot)
    {
        cin >> i.first >> i.second;
        arms.push_back(make_pair(i.first + i.second, i.first - i.second));
        smra.push_back(make_pair(arms.back().second, arms.back().first));
    }
    sort(begin(arms), end(arms));
    sort(rbegin(smra), rend(smra));
    int x = -1e9;
    int cnt = 0;
    for (auto &&i : arms)
    {
        if (x <= i.second)
        {
            cnt++;
            x = i.first;
        }
    }
    int ans = cnt;
    x = 2e9;
    cnt = 0;
    for (auto &&i : smra)
    {
        if (i.second <= x)
        {
            cnt++;
            x = i.first;
        }
    }
    ans = max(ans, cnt);
    cout << ans << "\n";
}

Measured memory_bytes: 5100
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <time.h>
#include <cstdio>
#include <queue>
using namespace std;


int memo[1000100];

int main(){
	int n,q;
	cin >> n >> q;
	priority_queue< pair<int,int> , vector< pair<int,int> > , greater< pair<int,int> > > Q;
	pair<int,int> ans(1e9,1e9);
	for(int i = 0 ; i < q ; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		memo[a] += b;
		Q.push(make_pair(-memo[a],a));
		while(-Q.top().first != memo[Q.top().second] ) Q.pop();
		cout << Q.top().second << " " << Q.top().first * (-1) << endl;
	}
}

Measured memory_bytes: 6052
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define a(i) a[(i+n)%n]
#define b(i) b[(i+n)%n]
using namespace std;
const int maxn=2000+5;
struct Data{
	int x,y;
	friend bool operator<(Data a,Data b){return a.x<b.x;}
}s[maxn];
int n,lft[maxn],rgt[maxn];
char a[maxn],b[maxn];
int main(){
	scanf("%s%s",a,b);
	n=strlen(a);
	bool allzero=1;
	for(int i=0;i<n;i++){
		a[i]-='0',b[i]-='0';
		if(b[i])allzero=0;
	}
	if(allzero){
		for(int i=0;i<n;i++)
		if(a[i]){printf("-1");return 0;}
		printf("0\n");return 0;
	}
	for(int i=0;i<n;i++){
		for(int k=0;k>-n;k--)if(b(i+k)){lft[i]=k;break;}
		for(int k=0;k<n;k++)if(b(i+k)){rgt[i]=k;break;}
	}
	int ans=1e9;
	for(int d=-n+1;d<=n-1;d++){
		int cnt=0,change=0;
		for(int i=0;i<n;i++){
			if(a(i)==b(i+d))continue;
			change++;
			if(d>=0&&rgt[i]>d)s[++cnt]=(Data){-lft[i],rgt[i]-d};
			if(d<0&&lft[i]<d)s[++cnt]=(Data){d-lft[i],rgt[i]};
		}
		sort(s+1,s+cnt+1);
		int maxy=0,res=cnt?1e9:0;
		for(int i=cnt;~i;i--){
			res=min(res,s[i].x+maxy);
			maxy=max(maxy,s[i].y);
		}
		ans=min(ans,res*2+abs(d)+change);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    if(n%2==0 && n!=2) {
        return false;
    }
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

ll binary_exp(ll x, ll n, ll mod)
{
    if (n == 0) {
        return 1;
    } else if (n == 1) {
        return x % mod;
    } else {
        ll temp = binary_exp(x, n / 2, mod);
        temp = (temp * temp) % mod;

        if (n % 2 == 0) {
            return temp;
        } else {
            return ((x % mod) * temp) % mod;
        }
    }
}

map<ll, ll> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        string s;
        cin >> s;
        int n=s.length();
        if(s[n-1]=='s') {
            s+="es";
        }
        else {
            s+="s";
        }
        cout << s << endl;
    }
}


Measured memory_bytes: 3032
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

#define EPS (1e-7)
#define IINF ((int)1e9)


MY_NAMESPACE(testbed)
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<ll>());

	ll res = 0;
	for (int i = 1; i < n; i++)
	{
		int idx = i / 2;
		ll this_a = a[idx];
		res += this_a;
	}
	cout << res << "\n";
	return 0;
}
MY_NAMESPACE_

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

int main() {
    int n,m,i,j,a;
    int sum = 0;
    cin >> n >> m;
    vector<vector<int> > vec1(n,vector<int>(m));
    vector<vector<int> > vec2(m,vector<int>(1));
    vector<vector<int> > vec3(n,vector<int>(1));
    
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            cin >> a ;
            vec1.at(i).at(j) = a;
        }
    }
    
    for(i = 0; i < m; i++){
        cin >> a ;
        vec2.at(i).at(0) = a;
    }
    
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            sum += vec1.at(i).at(j)*vec2.at(j).at(0);
        }
        vec3.at(i).at(0) = sum;
        sum = 0;
    }
    
    for(i = 0; i < n; i++){
        
        cout << vec3.at(i).at(0) << endl;
    }
}



Measured memory_bytes: 3176
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;

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

int main(void){
	ll x, y;
	cin >> x >> y;

	ll n = x;
	ll ans = 0;

	while(n <= y){
		n *= 2;
		ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int cnt = 0;
int n;

void dfs(string num){
  if(stoll(num) <= n){
    bool three = false, five = false, seven = false;
    rep(i, num.length()){
      if(num[i] == '3') three = true;
      if(num[i] == '5') five = true;
      if(num[i] == '7') seven = true;
    }
    if(three && five && seven){
      cnt++;
    }
 	dfs(num + "3");
    dfs(num + "5");
    dfs(num + "7");
  }
}

int main(){
  cin >> n;
  dfs("3");
  dfs("5");
  dfs("7");
  cout << cnt << endl;
  return 0;
}
  

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

int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  int x=-1;
  int y=-1;
  int z=-1;
  ll ans = 1;
  rep(i,n){
    int cnt=0;
    if(x+1==a[i])cnt++;
    if(y+1==a[i])cnt++;
    if(z+1==a[i])cnt++;
    if(x+1==a[i]){
      x=a[i];
    }else if(y+1==a[i]){
      y=a[i];
    }else if(z+1==a[i]){
      z=a[i];
    }
    ans *= cnt;
    ans %= MOD;
  }
  // int used = 0;
  // if(x!=-1)used++;
  // if(y!=-1)used++;
  // if(z!=-1)used++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <vector>

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

template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;

struct edge {
    ll to, fare, time;
    edge(int to, int fare, int time) : to(to), fare(fare), time(time){};
};

int main() {
    ll N, M, S;
    cin >> N >> M >> S;

    S = min(S, 2499ll);

    vector<vector<edge>> G(N);
    for (ll i = 0; i < M; ++i) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        --u;
        --v;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }

    vector<pll> C(N);
    for (ll i = 0; i < N; ++i) {
        ll c, d;
        cin >> c >> d;
        C[i] = make_pair(c, d);
    }

    vector<vector<ll>> dp(N, vector<ll>(2503ll, INF));

    priority_queue<pair<ll, pll>, vector<pair<ll, pll>>, greater<pair<ll, pll>>>
        que;

    dp[0][S] = 0;
    que.emplace(make_pair(0, make_pair(0, S)));

    while (!que.empty()) {
        auto P = que.top();
        que.pop();

        ll t = P.first;
        ll v = P.second.first;
        ll s = P.second.second;

        if (dp[v][s] < t) continue;

        if (s + C[v].first < 2500ll) {
            ll nt = t + C[v].second;
            ll ns = s + C[v].first;
            if (chmin(dp[v][ns], nt)) {
                que.emplace(make_pair(nt, make_pair(v, ns)));
            }
        }

        for (auto &e : G[v]) {
            if (s < e.fare) continue;
            ll nt = t + e.time;
            ll nv = e.to;
            ll ns = s - e.fare;
            if (chmin(dp[nv][ns], nt)) {
                que.emplace(make_pair(nt, make_pair(nv, ns)));
            }
        }
    }

    for (ll i = 1; i < N; ++i) {
        ll ans = INF;
        for (auto num : dp[i]) {
            chmin(ans, num);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 7252
n, m = map(int, input().split())

LRs = [list(map(int, input().split())) for i in range(m)]

under = 1
top = 10**6+10
for i in range(m):
    if LRs[i][0] > under:
        under = LRs[i][0]
    if LRs[i][1] < top:
        top = LRs[i][1]

if not top >= under:
    print(0)
else:

    print(top - under + 1)



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

int n, k, m1 = 0, m;
int p[200000];

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

	for (int i = 0; i < n; i++)
		cin >> p[i];

	for (int i = 0; i < k; i++)
		m1 += p[i];

	m = m1;

	for (int i = 0; i < n - k; i++) {
		m1 += p[k + i] - p[i];
		m = max(m, m1);
	}

	double a = (double)(m + k) / 2;

	printf("%.10f\n", a);

	return 0;
}

Measured memory_bytes: 1024
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    
    if (c - a - b < 0) {
        cout << "No" << endl;
        return 0;
    }
    
    cout << (4 * a * b < (c - a - b) * (c - a - b) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>   
#include<cstdio>  
#include<algorithm>
#include<queue>
#include<map>
#include<string>
using namespace std;
const int row = 4;
const int maxx = 16;
const int LIMIT = 100;
struct Puzzle {
	int f[maxx], space, MD;
	int cost;
	bool operator < (const Puzzle &p) const {
		for (int i = 0; i < maxx; i++) {
			if (f[i] != p.f[i])
				return f[i] < p.f[i];
		}
		return false;
	}
};

struct State {
	Puzzle puzzle;
	int estimated;
	bool operator < (const State &s) const {
		return estimated > s.estimated;
	}
};
const int dx[4] = { 0, -1, 0, 1 };
const int dy[4] = { 1, 0, -1 ,0 };
const char dir[4] = { 'r','u','l','d' };
int MDT[maxx][maxx];


int getAllMD(Puzzle pz) {
	int sum = 0;
	for (int i = 0; i < maxx; i++) {
		if (pz.f[i] != maxx)
			sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

int astar(Puzzle s) {

	priority_queue<State> PQ;
	s.MD = getAllMD(s);
	s.cost = 0;
	map<Puzzle, bool> V;
	Puzzle u, v;
	State initial;
	initial.puzzle = s;
	initial.estimated = getAllMD(s);
	PQ.push(initial);

	while (!PQ.empty()) {
		State st = PQ.top(); PQ.pop();
		u = st.puzzle;
		if (u.MD == 0)
			return u.cost;
		V[u] = true;
		int sx = u.space / row;
		int sy = u.space % row;
		for (int r = 0; r < 4; r++) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= row || ty >= row)
				continue;
			v = u;
			// 计算曼哈顿距离的差值，同时交换拼图
			v.MD -= MDT[tx * row + ty][v.f[tx * row + ty] - 1];
			v.MD += MDT[sx * row + sy][v.f[tx * row + ty] - 1];

			swap(v.f[tx * row + ty], v.f[sx * row + sy]);
			v.space = tx * row + ty;
			if (!V[v]) {
				v.cost++;
				State news;
				news.puzzle = v;
				news.estimated = v.cost + v.MD;
				PQ.push(news);
			}
		}
	}

	return -1;
}


int main()
{
	for (int i = 0; i < maxx; i++) {
		for (int j = 0; j < maxx; j++) {
			MDT[i][j] = abs(i / row - j / row) + abs(i % row - j % row);
		}
	}
	Puzzle in;
	for (int i = 0; i < maxx; i++) {
		cin >> in.f[i];
		if (in.f[i] == 0) {
			in.f[i] = maxx;
			in.space = i;
		}
	}

	printf("%d\n", astar(in));
	return 0;
}


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

	int a,b;
	cin >> a >> b;
	int x = 0;
	for (int i = 0; i < 2; i++) {
		if (a > b) {
			x = x + a;
			a--;
		}
		else {
			x = x + b;
			b--;
		}
	}
	cout << x << endl;
	return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
 ll n,sum = 0;
 cin >> n;
 for(ll i=1; i<n; i++)
 {
     ll d;
     if(n%i==0)
     {
          d = n/i - 1;

     }
     else
        d = n/i;
     sum += d;
 }
 cout << sum << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

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

    ll tmp = 0;
    for(ll i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            tmp = i;
        }
    }

    ll k = n / tmp;
    cout << tmp + k - 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;

int main() {
    //input
    long n; cin >> n;
    vector<int> v(n + 1);
    for(int i = 1; i < n + 1; i++) cin >> v[i];

    vector<int> e(100001,0);
	vector<int> em(100001,0);
    vector<int> o(100001,0);
	vector<int> om(100001,0);
    for(int i = 1; i < n + 1; i++) {
        if(i % 2 == 1){
            o[v[i]] += 1;
            om[v[i]] += 1;
        }else{
            e[v[i]] += 1;           
			em[v[i]] += 1;
        }
    }
 
    //compute
    int ans;
    sort(e.rbegin(),e.rend());
    sort(o.rbegin(),o.rend());

    bool p,q,r;
    p = (count(o.begin(),o.end(),o[0]) == 1);
    q = (count(e.begin(),e.end(),e[0]) == 1);
    r = (find(om.begin(),om.end(),o[0]) - om.begin() == find(em.begin(),em.end(),e[0]) - em.begin()); 
     
    if( p && q && r ){
      ans = n - max( o[0] + e[1],o[1] + e[0] );
    }else{
      ans = n - ( o[0] + e[0] );
    }
    
    //output
    cout << ans << endl;
}

Measured memory_bytes: 5052
fn main() {
	proconio::input!(n: usize, cities: [(i64, i64); n]);

	let mut edges = Vec::new();

	let mut by_x = (0..n).collect::<Vec<usize>>();
	by_x.sort_by_key(|&i| cities[i].0 );
	for i in 0..n-1 {
		let (a, b) = (by_x[i], by_x[i+1]);
		edges.push(((cities[a].0 - cities[b].0).abs(), a, b));
	}

	let mut by_y = (0..n).collect::<Vec<usize>>();
	by_y.sort_by_key(|&i| cities[i].1 );
	for i in 0..n-1 {
		let (a, b) = (by_y[i], by_y[i+1]);
		edges.push(((cities[a].1 - cities[b].1).abs(), a, b));
	}

	edges.sort_by_key(|&(c, _, _)| c );

	// クラスカル法をする
	let mut uf = UnionFind::new(n);
	let mut cost_sum = 0;
	for (c, a, b) in edges {
		if !uf.is_same(a, b) {
			uf.unite(a, b);
			cost_sum += c;
		}
	}

	println!("{}", cost_sum);
}

struct UnionFind(Vec<usize>, Vec<usize>);
impl UnionFind {
	fn new(size: usize) -> Self { Self((0..size).collect(), vec![0; size]) }
	fn unite(&mut self, i: usize, j: usize) { let (mut k, mut l) = (self.find(i), self.find(j)); if self.1[k] < self.1[l] { std::mem::swap(&mut k, &mut l) }; if self.1[k] == self.1[l] { self.1[k] += 1 }; self.0[l] = self.0[k]; }
	fn find(&mut self, mut i: usize) -> usize { let mut j = i; while i != self.0[i] { self.0[j] = self.0[i]; j = i; i = self.0[i] }; i }
	fn is_same(&mut self, i: usize, j: usize) -> bool { self.find(i) == self.find(j) }
}

Measured memory_bytes: 14148
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;

int main() {
    int N;
    string S={0};
    cin >> N >> S;

    string alpha={0};
    alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZA";
    //s[i]=alpha[0~25] [26~52][52~78] if i+N>25 ->13+13->0 20+20 14


    //cout << S[2]+2;
    string puts={0};
    //alpha2 = alpha[3]+2;

    //cout << alpha2;
    //S=CHD N=1 DIE D=C+1
    //abc...xyz(0~26)...abc(27 28 29...52)...abc(53) %26
    //N=13 Z=abcd...M Z(25)->A(0)
    int x=0;
    for(int i=0;i<S.size();i++){
      //x=alpha.index(S[i]);
      //x=find(alpha.begin(),alpha.end(),S[i]);
      x=alpha.find(S[i]);
      x=(x+N)%26;
      cout << alpha[x];//<<"\n";
      //puts[i]=S[i]+x;
      //cout << x;
      /*
          if(i+N>25){
            //if Z=25 +M=2 27%26=1
            puts[i]=S[i]-(26-N); //XYZ23 24 25 ABC012 X+3=A 26進数にする
          }
          else{
            puts[i] = S[i]+N;// alpha[3]+N;
          }




          for(int j=0;j<S.size();j++){
            cout <<puts[j];
          }

      */
    }


    //free();


    return 0;
}


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


int main(){
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	cout << H2*60 + M2 - (H1*60 + M1) - K << endl;
	return 0;
}









Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
int main(){
	int n,i,c=0;
	char a[100];
	scanf("%d",&n);
	getchar();
		
		
	for(i=0;i<n;i++){
		scanf("%c",&a[i]);
	}
	

	
	
	
		
	

	
	 
	for(i=0;i<n-2;i++){
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
		{
			c++;
		}
		
	
	}
	printf("%d",c);
/*	else{
		//printf("%c\n%c\n%c",a[0],a[1],a[2]); 
		if(a[0]=='A'&&a[1]=='B'&&a[2]=='C'){
			printf("1");}
		
	}*/
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
lint mod=998244353;
#define float double
int main()
{
   float s;
   cin>>s;
   float x=s/3;
   float ans=x*x*x;
   printf("%0.8f",ans);
    



}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	char s[10], c;

	while (scanf(" %9s ", s) != EOF) {
		if (s[0] != 's' && s[0] == s[1] && s[1] == s[2]) {
			c = s[0];
		}
		else if (s[3] != 's' && s[3] == s[4] && s[4] == s[5]) {
			c = s[3];
		}
		else if (s[6] != 's' && s[6] == s[7] && s[7] == s[8]) {
			c = s[6];
		}
		else if (s[0] != 's' && s[0] == s[3] && s[3] == s[6]) {
			c = s[0];
		}
		else if (s[1] != 's' && s[1] == s[4] && s[4] == s[7]) {
			c = s[1];
		}
		else if (s[2] != 's' && s[2] == s[5] && s[5] == s[8]) {
			c = s[2];
		}
		else if (s[0] != 's' && s[0] == s[4] && s[4] == s[8]) {
			c = s[0];
		}
		else if (s[2] != 's' && s[2] == s[4] && s[4] == s[6]) {
			c = s[2];
		}
		else {
			c = 'd';
		}
		printf("%c\n", c);
	}
	return 0;
}

Measured memory_bytes: 544
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char ss[4010];
int cnt[2][3];
inline int getid(char c)
{
	if(c=='R')return 0;
	else if(c=='G')return 1;
	else return 2;
}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
   	int n=read();long long ans=0;
   	scanf("%s",ss+1);
   	for(int i=2;i<n;i++)
   	{
   		memset(cnt,0,sizeof(cnt));
   		for(int j=1;j<i;j++)cnt[0][getid(ss[j])]++;
		for(int j=i+1;j<=n;j++)cnt[1][getid(ss[j])]++;
		for(int j=0;j<3;j++)
		{
			if(getid(ss[i])==j)continue;
			for(int k=0;k<3;k++)
			{
				if(getid(ss[i])==k || j==k)continue;
				ans+=cnt[0][j]*cnt[1][k];
			}
		}
   		for(int j=1;j<i;j++)
		{
			if(ss[j]==ss[i])continue;
			int k=2*i-j;
			if(k<=n && ss[k]!=ss[j] && ss[k]!=ss[i])ans--;
		}
   	}printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1732
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6+5 ;

int n ,arr[N] ,ans[N] ;
pair<int,int> mx2[N] ;

bool vis[N] ;
pair<int,int> solve(int i){
    if(vis[i]) return mx2[i] ;
    vis[i] = 1 ;
    auto&ret = mx2[i] ;
    ret = {i,0};
    for(int j=0;(1<<j)<=i;++j){
        if(i&(1<<j)){
            auto x = solve(i^(1<<j));
            set<pair<int,int>> v ;
            v.insert({arr[ret.first],ret.first});
            v.insert({arr[ret.second],ret.second});
            v.insert({arr[x.first],x.first});
            v.insert({arr[x.second],x.second});
            int a = v.rbegin()->second ;
            v.erase(*v.rbegin());
            int b = v.rbegin()->second ;
            ret = {a,b};
        }
    }
    return ret;
}
int main(){
    cin >> n ;
    n = 1<<n ;
    for(int i=0;i<n;++i){
        scanf("%d",arr+i);
        if(!i) continue ;
        mx2[i] = solve(i) ;
        ans[i] = arr[mx2[i].first]+arr[mx2[i].second] ;
        ans[i] = max(ans[i] ,ans[i-1]);
        printf("%d\n",ans[i]);
    }

    return 0;
}


Measured memory_bytes: 10496
import math
def calc_yakusu_num(n):
    num = 0

    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            if i == n // i:
                num += 1
            else:
                num += 2
    return num - 1
    
def calc_yakusu(n):
    yakusu = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            if i == n // i:
                yakusu.append(i)
            else:
                if i != 1:
                    yakusu.append(i)
                yakusu.append(n // i)
    return yakusu

if __name__ == "__main__":
    ans = 0
    n = int(input())

    ans += calc_yakusu_num(n - 1)
    
    y = calc_yakusu(n)
  

    for i in y:
        tmp = n
        while tmp % i == 0:
            tmp //= i
        if tmp % i == 1:
            ans += 1
    print(ans)


Measured memory_bytes: 3188
n = int(input())
a = []
for i in range(n):
    a += [int(input())]

cnt = 0

import math
def isprime(x):
  if x == 2:
    return True
  if x < 2 or x%2==0:
    return False
  i = 3
  while i <= math.sqrt(x):
    if x%i==0:
      return False
    i = i + 2
  return True
 
for i in range(n):
        if isprime(a[i]):
            cnt += 1
            
print(cnt)


Measured memory_bytes: 6012
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int c = x-a;
        int d = (c%b);

        System.out.println(d);

    }
}


Measured memory_bytes: 35824
n=int(input())

ESP=1e-10

for t in range(n):
  s=input()
  item=s.split()
  x=[]
  y=[]
  for i in range(4):
    x.append(float(item[i*2]))
    y.append(float(item[i*2+1]))
  if abs(x[0]-x[1])<=ESP or abs(x[2]-x[3])<=ESP:
    if abs(x[0]-x[1])<=ESP and abs(x[2]-x[3])<=ESP:
      print("YES")
    else:
      print("NO")
  else:
    if abs((y[0]-y[1])/(x[0]-x[1])-(y[2]-y[3])/(x[2]-x[3]))<=ESP:
      print("YES")
    else:
      print("NO")

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	ll n, m;
	cin >> n >> m;

	ll res;
	if (n == 1 && m == 1)
		res = 1;
	else if (n == 1 || m == 1)
		res = n * m - 2;
	else if (n > 2 && m > 2)
		res = (n - 2) * (m - 2);
	else
		res = 0;

	cout << res << endl;
	return 0;
}


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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n), y(n);
  vector<char> c(n);

  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> c[i];
  }
  for (int i = 0; i < n; i++) {
    if (c[i] == 'W') {
      x[i] += k;
    }
    x[i] %= 2 * k;
    y[i] %= 2 * k;
  }

  vector<vector<int> > vec(2*k + 5, vector<int>(2*k + 5, 0));
  for (int i = 0; i < n; i++) {
    vec[x[i]+1][y[i]+1]++;
  }

  for (int i = 1; i < 2*k + 1; i++) {
    for (int j = 1; j < 2*k + 1; j++) {
      vec[i][j] += vec[i-1][j];
    }
  }
  for (int i = 1; i < 2*k + 1; i++) {
    for (int j = 1; j < 2*k + 1; j++) {
      vec[i][j] += vec[i][j-1];
    }
  }

  int ans = -1e9;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int leftup = vec[i][j];
      int center = vec[i+k][j+k] - vec[i][j+k] - vec[i+k][j] + vec[i][j];
      int leftdw = vec[2*k][j] - vec[i+k][j];
      int rightup = vec[i][2*k] - vec[i][j+k];
      int rightdw = vec[2*k][2*k] - vec[2*k][j+k] - vec[i+k][2*k] + vec[i+k][j+k];
      int sum = leftup + center + leftdw + rightup + rightdw;
      ans = max(ans, max(sum, n-sum));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16896
unittest
{
	assert( [ "happy,newyear,enjoy" ].parse.expand.solve == "happy newyear enjoy" );
	assert( [ "haiku,atcoder,tasks" ].parse.expand.solve == "haiku atcoder tasks" );
	assert( [ "abcde,fghihgf,edcba" ].parse.expand.solve == "abcde fghihgf edcba" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front;
	return tuple( s );
}

auto solve( string s )
{
	return s.replace( ",", " " );
}


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

long long N;
long long A[100];

int main(){
	cin >> N;
	for(long long i = 0; i < N; i++) {
		cin >> A[i];
	}

	long long ans = 1000;
	for(long long i = 0; i < N; i++) {
		while(i < N && A[i] < A[i+1]) {
			long long stock = ans/A[i];
			long long money = ans%A[i];
			ans = money + stock * A[i+1];
			i++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
n = int(input())
a = [int(input()) for i in range(n)]

from collections import deque
import bisect

d = deque()
for i in range(n):
    idx = bisect.bisect_left(d, a[i])
    if idx == 0:
        d.appendleft(a[i])
    else:
        d[idx-1] = a[i]

print(len(d))

Measured memory_bytes: 53720
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
	int n, m; 
	cin >> n >> m;
	vector<int> mati(n+1 , 0);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		mati[a]++;
		mati[b]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << mati[i] << endl;
	}

}

Measured memory_bytes: 3620