akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    int ans;
    if(S == "SUN"){
        ans = 7;
    }else if(S == "MON"){
        ans = 6;
    }else if(S == "TUE"){
        ans = 5;
    }else if(S == "WED"){
        ans = 4;
    }else if(S == "THU"){
        ans = 3;
    }else if(S == "FRI"){
        ans = 2;
    }else{
        ans = 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
Alist = list(map(int, input().split()))
count_4x = 0
count_2x = 0
for A in Alist:
    if A % 4 == 0:
        count_4x += 1
    else:
        if A % 2 == 0:
            count_2x += 1

if ((count_4x + int(count_2x / 2)) >= (N // 2)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
import bisect

import collections


n = int(input())
a = list(map(int, input().split()))
a_counter = collections.Counter(a)
a_keys = sorted(a_counter.keys(), reverse=True)

targets = []

t = 0
vt = 1
for v in a:
    while v >= vt:
        t += 1
        vt *= 2
        targets.append(vt)
targets.reverse()


cnt = 0
for key in a_keys:
    if a_counter[key] <= 0:
        continue
    for t in targets:
        if key >= t:
            break
        if key == t-key:
            p = max(0, min(a_counter[key], a_counter[t-key])) // 2
        else:
            p = max(0, min(a_counter[key], a_counter[t-key]))
        a_counter[key] -= p
        a_counter[t-key] -= p
        cnt += p
print(cnt)


Measured memory_bytes: 124668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
vector<int> A;
vector<int> B;
//=============================
void input()
{
    cin>>N>>K;
    A.resize(N);
    rep(i,N){
        int tmp;
        cin>>tmp;
        tmp--;
        A[i]=tmp;
    }
}
//=============================
void func(){}
//=============================
void solve()
{
    int ans= 1;
    N -= K;
    while (N > 0) {
        N -= (K-1);
        ++ans;
    }
    cout<<ans<<endl;
    
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c1, s1, f1 = map(int, input().split())
    C.append(c1)
    S.append(s1)
    F.append(f1)
    
for i in range(N-1):
    ans = 0
    for j in range(i,N-1):
        if ans <= S[j]:
            ans = S[j] + C[j]
        elif (ans - S[j]) % F[j] == 0:
            ans += C[j]
        else:
            ans += C[j] + F[j] - ((ans - S[j]) % F[j])
    print(ans)  
print(0)

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

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    
    int set_num_x = N / A;
    if (N % A != 0) {
        ++set_num_x;
    }
    
    int set_num_y = N / C;
    if (N % C != 0) {
        ++set_num_y;
    }

    int cost_x = set_num_x * B;
    int cost_y = set_num_y * D;

    if (cost_x < cost_y) {
        cout << cost_x << endl;
    }
    else {
        cout << cost_y << endl;
    }

    return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <math.h>
int isPrime(int n){
    for(int i = 2; i <= sqrt(n); i++){
        if(n%i == 0) {
            return 0;
        }
    }
    return 1;
}
int main(){
    int n;
    int cnt = 0;
    scanf("%d", &n);
    while(n--){
        int b;
        scanf("%d", &b);
        if(isPrime(b)){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 2040
import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		String s=scan.next().toUpperCase();
		char a[]=s.toCharArray();
		int count=0;
		int freq[]=new int[26];
		for(int i=0;i<a.length;i++)
		{
			freq[a[i]-'A']++;
		}
		for(int i=0;i<26;i++)
		{
			if(freq[i]==2 ||freq[i]==0) {
				
			}else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
	
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

            ll n;
            cin>>n;
            set <ll> s;
            ll x;
            fo(i,n)
            {
                cin>>x;
                if(s.count(x))
                    s.erase(x);
                else
                    s.insert(x);
            }
            cout<<s.size();
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 8300
import numpy as np
n = int(input())
lst = []
count = 0

for i in range(n):
    x,y = map(int, input().split())
    lst.append(np.array([x,y]))

for i in range(n):
    for j in range(i+1,n):
        count += np.linalg.norm(lst[i]-lst[j])

print(count*2/n)


Measured memory_bytes: 12504
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    string s;
    cin >> s;
    for (int i = 0; i < 3; ++i)
    {
        if (s[i] == '1' || s[i] == '9')
        {
            s[i] ^= '1' ^ '9';
        }
    }

    cout << s;
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    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;

int main(){
  int k, x;
  cin >> k >> x;
  for(int i = x-k+1; i < x+k; i++) cout << i << " ";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<string> ans;
    auto rec = [&](auto &&rec, int b, string s) -> void {
        if (s.size()==n) {
            ans.push_back(s);
            return;
        }
        rep(i,b+1) {
            string t = s;
            t += 'a'+i;
            // cout << t << " " << i << endl;
            if (i==b) rec(rec, b+1, t);
            else rec(rec, b, t);
        }
    };

    rec(rec, 1, "a");
    sort(ans.begin(), ans.end());
    rep(i,ans.size()) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define FOR(i, a, b) for(ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (b)-1; i >= (a); i--)
 
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll INF = 1000000000000000000LL;
 
#define VEI(w,e) ((E[e].u == w) ? E[e].v : E[e].u)
#define CAP(w,e) ((E[e].u == w) ? E[e].cap[0] - E[e].flow : E[e].cap[1] + E[e].flow)
#define ADD(w,e,f) E[e].flow += ((E[e].u == w) ? (f) : (-(f)))
 
struct Edge { int u, v; ll cap[2], flow; };
 
VI d, act;
 
bool bfs(int s, int t, VVI& adj, vector<Edge>& E, ll lim) {
  queue<int> Q;
  d = VI(adj.size(), -1);
  d[t] = 0;
  Q.push(t);
  while (not Q.empty() and d[s] == -1) {
    int u = Q.front(); Q.pop();
    for (int i = 0; i < int(adj[u].size()); ++i) {
      int e = adj[u][i], v = VEI(u, e);
      if (CAP(v, e) >= lim and d[v] == -1) {
        d[v] = d[u] + 1;
        Q.push(v);
      }
    }
  }
  return d[s] >= 0;
}
 
bool dfs(int u,int t,ll bot,VVI& adj,vector<Edge>& E, ll lim) {
  if (bot == 0) return false;
  if (u == t) return true;
  for (; act[u] < int(adj[u].size()); ++act[u]) {
    int e = adj[u][act[u]];
    if (CAP(u, e) >= lim and d[u] == d[VEI(u, e)] + 1) {
      ll inc=dfs(VEI(u,e),t,min(bot,CAP(u,e)),adj,E,lim);
      if (inc) {
        ADD(u, e, lim);
        return true;
      }
    }
  }
  return false;
}
 
ll maxflow(int s, int t, VVI& adj, vector<Edge>& E) {
  for (int i=0; i<int(E.size()); ++i) E[i].flow = 0;
  ll flow = 0;
  for(int lim = (1<<30); lim >= 1;) {
    if(!bfs(s,t,adj,E, lim)) {
      lim >>= 1;
      continue;
    }
    act = VI(adj.size(), 0);
    while (dfs(s,t,INF, adj, E, lim)) flow += lim;
  }
  return flow;
}
 
void addEdge(int u, int v, VVI& adj, vector<Edge>& E, ll cap){
	Edge e;
	e.u = u;
	e.v = v;
	e.cap[0] = cap;
	e.cap[1] = 0;
	e.flow = 0;
	adj[u].push_back(E.size());
	adj[v].push_back(E.size());
	E.push_back(e);
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
  }
long long ans = 0;
	vector<vector<int>> adj(n+2);
	vector<Edge> E;
	int S = 0, T = n+1;
	for(int i = 1; i < n+1; ++i) {
		if(v[i] <= 0) addEdge(S, i, adj, E, -v[i]);
		else {
addEdge(i, T, adj, E, v[i]);
ans += v[i];
}
		for(int j = 2; i*j < n+1; ++j) {
			addEdge(i, i*j, adj, E, INF);
		}
	}
	cout << ans - maxflow(S,T,adj,E) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
main(){
	int n;cin>>n;
	int r[4][3][10]={0};
	for(int a,b,c,d,i=0;i<n;i++){
		cin>>a>>b>>c>>d;
		r[a-1][b-1][c-1]+=d;
	}
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout<<" "<<r[0][i][j];
		}
		cout<<endl;
	}
	cout<<"####################"<<endl;
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout<<" "<<r[1][i][j];
		}
		cout<<endl;
	}
	cout<<"####################"<<endl;
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout<<" "<<r[2][i][j];
		}
		cout<<endl;
	}
	cout<<"####################"<<endl;
	for(int i=0;i<3;i++){
		for(int j=0;j<10;j++){
			cout<<" "<<r[3][i][j];
		}
		cout<<endl;
	}
	return 0;
}

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

const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

int n, s;
vector<int> arr;

void solve() {
  // dp[i][j]到n[i-1]为止有多少个加起来等于j的开始点
  vector< vector<int> > dp(n + 1, vector<int>(s + 1, 0));
  int res = 0;
  dp[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    dp[i][0] = 1;
    for (int j = s; j >= 0; --j) {
      dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
      if (j + arr[i-1] <= s) {
        dp[i][j+arr[i-1]] = (dp[i][j+arr[i-1]] + dp[i-1][j]) % MOD;
      }
    }
    res = (res + dp[i][s]) % MOD;
  }
  // for (int i = 0; i <= n; ++i) {
  //   for (int j = 0; j <= s; ++j) {
  //     cout << dp[i][j] << ',';
  //   }
  //   cout << endl;
  // }
  cout << res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  arr = vector<int>(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 35584
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N;
  cin >> N;
  char direc[N];
  REP(i, N) cin >> direc[i];

  int sum=0;
  int min;
  for(int i=1; i<N; ++i){
    if(direc[i] == 'E') ++sum;
  }
  min = sum;

  for(int i=1; i<N; ++i){
    if(direc[i] == 'E') --sum;
    if(direc[i-1] == 'W') ++sum;
    if(sum < min) min = sum;
  }

  cout << min;



  return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	int ans;
	if(a<1 || 9<a || b<1 || 9<b){
		ans = -1;
	}else{
		ans = a*b;
	}
	cout << ans << endl;
	return 0;
}

	


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int soma_digitos(int N) {
    int soma = 0;

    do {
        soma += N % 10;
        N /= 10;
    } while(N != 0);

    return soma;
}

int main() {
    int N, S;

    cin >> N;

    S = soma_digitos(N);

    if(N % S == 0) {
        cout << "Yes";
    }

    else {
        cout << "No";
    }

    cout << endl;

    return 0;
}

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


int main()
{
	int n; cin >> n;
	string s;
	map<string, int> m;
	m["AC"] = 0;
	m["WA"] = 0;
	m["TLE"] = 0;
	m["RE"] = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		m[s]++;
	}
	cout << "AC" << " x " << m["AC"] << endl;
	cout << "WA" << " x " << m["WA"] << endl;
	cout << "TLE" << " x " << m["TLE"] << endl;
	cout << "RE" << " x " << m["RE"] << endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<int> msp;

void pri_cal(){
	for(int i=2;i<=300000;i++){
		if(i%7==1||i%7==6){
			int flag=0;
			for(int j=0;j<msp.size()&&msp[j]*msp[j]<=i;j++){
				if(i%msp[j]==0){
					flag=1;
					break;
				}
			}
			if(flag==0){
				msp.push_back(i);
			}
		}
	}
}
int k;
int main(){
	pri_cal();
	while(1){
		scanf("%d",&k);
		if(k==1)break;
		printf("%d:",k);
		for(int i=0;i<msp.size();i++){
			if(k%msp[i]==0){
				printf(" %d",msp[i]);
			}
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;


typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll a, b, n;
    cin>>a>>b>>n;
    ll ans = 0;
    ll count = 0;
    count = 0;
    for(ll i=n;i>=0;i-=b){
        ll flag = (a*i/b) - a*(i/b);
        if(ans < flag){
            ans = flag;
            count = 0;
        }else{
            count++;
        }
        if(count > 10000000){
            break;
        }
    }
    count = 0;
    for(ll i=n;i>=0;--i){
        ll flag = (a*i/b) - a*(i/b);
        if(ans < flag){
            ans = flag;
            count = 0;
        }else{
            count++;
        }
        if(count > 10000000){
            break;
        }
    }
    ans = max(ans, (a*min(b-1, n)/b) - a*(min(b-1, n)/b));
    cout<<ans<<endl;
}

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

int main() {
  string CC = "abcdefghijklmnopqrstuvwxyz";
  char C;
  cin >> C;
  for(int i = 0; i < 25; i++){
    if(C != CC.at(i)){
      continue;
    }
    else if(C == CC.at(i)){
      cout << CC.at(i+1);
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#include <string>
#include <deque>
#include <map>
#include <algorithm>

using namespace std;
//--------------------
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

//------------
void func() {
    int N;
    cin >> N;
    if (N % 2 == 0) {
        cout << N << endl;
    } else {
        cout << (N << 1) / gcd(2,N) << endl;
    }
}

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

Measured memory_bytes: 256
while True:
	try:
		a = map(int, raw_input().split())
		b = map(int, raw_input().split())
		hit = 0
		blow = 0
		for na, nb in zip(a, b):
			if na == nb: hit += 1
			if nb in a: blow += 1
		blow = blow - hit
		print "{} {}".format(hit, blow)
	except EOFError:
		break

Measured memory_bytes: 4208
module S = Set.Make (struct type t = int let compare = compare end)

let () =
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let uv = Array.init m (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun u v -> u, v)) in
        let s, t = Scanf.sscanf (read_line ()) "%d %d" (fun s t -> s, t) in
        let u = Array.make (n + 1) S.empty in
        Array.iter (fun (uu, vv) -> u.(uu) <- S.add vv u.(uu)) uv;
        let visited = Array.make_matrix 3 (n + 1) (-1) in
        visited.(0).(s) <- 0;
        let rec loop step frontier =
            if S.cardinal frontier = 0 then (-1) else
                let curs  = step mod 3 in
                let frontier =
                    S.fold (fun e next_frontier ->
                        S.fold (fun f next_frontier ->
                            if visited.(curs).(f) >= 0 then next_frontier else (
                                visited.(curs).(f) <- step;
                                S.add f next_frontier
                            )
                        ) u.(e) next_frontier
                    ) frontier S.empty
                in
                if visited.(0).(t) >= 0 then visited.(0).(t) / 3 else loop (step + 1) frontier
        in
        let result = loop 1 (S.singleton s) in
        Printf.printf "%d\n" result
    in
    main ()

Measured memory_bytes: 18432
n,k = map(int,input().split())
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
print(len(str(Base_10_to_n(n,k))))

Measured memory_bytes: 2940
import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N,dtype=int)
for i in range(1,N):
    dp[i] = (dp[max(0,i-K):i] + np.abs(h[i]-h[max(0,i-K):i])).min()
print(dp[-1])

Measured memory_bytes: 22840
#include <bits/stdc++.h>
using namespace std;
#define freinput "input.txt","r",stdin
#define freoutput "output.txt","w",stdout
#define mp make_pair
#define fi first
#define sc second
#define pb push_back
#define ellapse printf("Time : %0.3lf\n",clock()*1.0/CLOCKS_PER_SEC);
typedef long long ll;
typedef unsigned long int uld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
struct comp {
       bool operator() (int a,int b) {
            return a>b;
       }
};

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


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

for i in range(1, n):
    v = a[i]
    j = i - 1
    print(' '.join(map(str, a)))
    while j >= 0 and a[j] > v:
        a[j+1] = a[j]
        j -= 1
    a[j+1] = v

print(' '.join(map(str, a)))



Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
using namespace std;
const static int DUP_LIMIT = 249;
short s[DUP_LIMIT + 2];
int main() {
  int n, h;
  cin >> n;
  long total_hp = 0;
  for (int i = 0; i < n; i++) {
    cin >> h;
    total_hp += h;
    s[min(h, DUP_LIMIT)]++;
  }
  for (int i = DUP_LIMIT; i > 0; i--) {
    s[i] += s[i + 1];
  }
  long r = total_hp;
  for (int i = 1; i <= DUP_LIMIT; i++) {
    r -= max(s[i] - i * 4, 0);
  }
  cout << r + 1 << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    while(n--) {
        int Y, M, D;
        cin >> Y >> M >> D;
        int ans = 0;
        while(true) {
            ans++;
            D++;
            //cerr << Y << " " << M << " " << D << endl;
            if(D == 20 && (Y % 3 != 0 && M % 2 == 0)) {
                D = 1;
                M++;
            }
            if(D == 21) {
                D = 1;
                M++;
            }
            if(M == 11) {
                M = 1;
                Y++;
            }
            if(Y == 1000) break;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,len,len2,sum=0;
	char str[201],str2[201];
	//memset(str,NULL,sizeof(str));
	memset(str2,NULL,sizeof(str2));
	cin>>n;
	cin>>str;
	len=strlen(str);
	for(int i=0;i<n;i++){//??????????????\???
		cin>>str2;
		len2=strlen(str2);
		for(int j=0;j<len2;j++){//???????????????????????????????????????????´¢
			if(str2[j]==str[0]){
				for(int y=1;y<len2;y++){
					for(int x=1;x<len;x++){
						if(str2[j+y*x]!=str[x]||j+y*x>len2){
							goto ruio;
						}
						if(x==len-1){
						   // cout<<str2<<endl;
							sum++;
							goto sugii;
						}
					}
					ruio:;
				}
			}
		}
		sugii:;
	}
	cout<<sum<<endl;
}		

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

constexpr int inf = 1.01e9;
constexpr i64 inf64 = 4.01e18;
constexpr double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename A, typename T, size_t size>
void fill(A (&ary)[size], const T &val) {
    fill((T *)ary, (T *)(ary + size), val);
}

void solve() {
    //constexpr i64 mod = 1'000'000'007;
    i64 N,D;
    cin >> N >> D;
    cout << (N+2*D+1-1)/(2*D+1) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> ans(4, 0);
  vector<string> ss = {"AC", "WA", "TLE", "RE"};
  rep(i, n){
    string s;
    cin >> s;
    rep(j, 4){
      if(ss.at(j) == s){
        ans.at(j)++;
      }
    }
  }
  rep(i, 4){
    cout << ss.at(i) << " x " << ans.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

class SuffixArray{
public:
    vec<int> SA;
    const string S;
    int N;
    SuffixArray(const string& S):S(S){
        N = S.size();
        SA.resize(N);
        iota(SA.begin(),SA.end(),0);
        sort(SA.begin(),SA.end(),[&](int i,int j){
            return S[i]==S[j]? i>j:S[i]<S[j];
        });
        vec<int> classes(N),C(S.begin(),S.end()),cnt(S.size());
        for(int len=1;len<N;len<<=1){
            for(int i=0;i<N;i++){
                if(i>0 && C[SA[i-1]]==C[SA[i]] && 
                SA[i-1]+len<N && C[SA[i-1]+len/2]==C[SA[i]+len/2]){
                    classes[SA[i]] = classes[SA[i-1]];
                }else{
                    classes[SA[i]] = i;
                }
            }
            iota(cnt.begin(),cnt.end(),0);
            copy(SA.begin(),SA.end(),C.begin());
            for(int i=0;i<N;i++){
                int sl = C[i]-len;
                if(sl>=0) SA[cnt[classes[sl]]++] = sl;
            }
            classes.swap(C);
        }
    }

    int operator[](int k)const{
        return SA[k];
    }

    int size()const{
        return N;
    }

    bool lt_substr(const string& T,int si=0,int ti=0){
        int sn = N,tn = T.size();
        while(si<sn && ti<tn){
            if(S[si]<T[ti]) return true;
            if(S[si]>T[ti]) return false;
            si++; ti++;
        }
        return si>=sn && ti<tn;
    }

    int lower_bound(const string& T,int si=0,int ti=0){
        int l = -1,r = N;
        while(l+1<r){
            int m = (l+r)>>1;
            (lt_substr(T,SA[m])? l:r) = m;
        }
        return r;
    }

    pair<int,int> lower_upper_bound(string& T){
        int id = lower_bound(T);
        int l = id-1,r = N;
        T.back()++;
        while(l+1<r){
            int m = (l+r)>>1;
            (lt_substr(T,SA[m])? l:r) = m;
        }
        T.back()--;
        return {id,r};
    }
};

class LongestCommonPrefixArray{
    const SuffixArray &SA;
    vec<int> LCP,rank;
    int N;
public:
    LongestCommonPrefixArray(const SuffixArray& SA):SA(SA),LCP(SA.size()){
        int N = SA.size();
        rank.resize(N);
        for(int i=0;i<N;i++) rank[SA[i]] = i;
        for(int i = 0, h = 0; i < SA.size(); i++) {
        if(rank[i]+1<SA.size()) {
            for(int j=SA[rank[i]+1]; max(i,j)+h<SA.size() && SA.S[i+h]==SA.S[j+h]; ++h);
                LCP[rank[i]+1] = h;
                if(h>0) --h;
            }
        }
    }

    int operator[](int k)const{
        return LCP[k];
    }

    int size()const{
        return N;
    }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    SuffixArray SA(S);
    LongestCommonPrefixArray LCP(SA);
    ll N = S.size();
    ll ans = N*(N+1)/2;
    for(int i=0;i<N;i++) ans -= LCP[i];
    cout << ans << "\n";
}

Measured memory_bytes: 12020
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N,A[100000];
  cin>>N;
  for(int i(0);i<N;i++){
    cin>>A[i];
  }
  int cnt(0);
  for (int i(0);i<N;i++){
    if (A[i]%4==0) cnt+=2;
    else if (A[i]%2==0) cnt++;
  }
  if (N/2 <= cnt/2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}




Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> R[i];
  }

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++)
  {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


Measured memory_bytes: 3900
import sys
input = sys.stdin.readline
from collections import Counter
from collections import deque


def main():
    N = int(input())
    C = []
    T = [[] for j in range(N + 1)]
    for i in range(N - 1):
        a, b = [int(x) for x in input().split()]
        T[a].append([b, i])
        T[b].append([a, i])
        C.append(a)
        C.append(b)
    
    c = Counter(C)
    print(c.most_common(1)[0][1])

    q = deque()
    q.append([1, 0])


    visited = set()
    ans = [0] * N

    while q:
        i, color = q.popleft()
        visited.add(i)
        now_color = 0
        for v, j in T[i]:
            if not v in visited:
                now_color += 1
                if now_color == color:
                    now_color += 1
                q.append([v, now_color])
                ans[j] = now_color
    
    for i in range(N - 1):
        print(ans[i])



    

    



if __name__ == '__main__':
    main()


Measured memory_bytes: 60412
#include<stdio.h>

typedef struct{
	char mark;
	int number;
}card;

void bubblesort( card c[] , int n );
void selectionsort( card c[] , int n );
int stablesort( card c1[] , card c2[] , int n );

int main( void ){
	
	card c1[36] , c2[36];
	int n;
	int i;
	
	scanf( "%d" , &n );
	
	for( i = 0; i < n; i++ ){
		scanf( " %c%d" , &c1[i].mark , &c1[i].number );
	}
	
	for( i = 0; i < n; i++ ){
		c2[i] = c1[i];
	}
	
	bubblesort( c1 , n );
	for( i = 0; i < n; i++ ){
		if( i > 0 ){ printf( " " ); } 
		printf( "%c%d" , c1[i].mark , c1[i].number );
	}
	printf( "\n" );
	printf( "Stable\n" );

	selectionsort( c2 , n );
	for( i = 0; i < n; i++ ){
		if( i > 0 ){ printf( " " ); } 
		printf( "%c%d" , c2[i].mark , c2[i].number );

	}
	printf( "\n" );
	
	if( stablesort( c1 , c2 , n ) == 1 ){
		printf( "Stable\n" );
	}else{
		printf( "Not stable\n" );
	}
	
	return 0;
}

void bubblesort( card c[] , int n ){
	
	card temp;
	int i , j;
	
	for( i = 0; i < n; i++ ){
		
		for( j = n - 1; j > i; j-- ){
			
			if( c[j].number < c[ j - 1 ].number ){
				temp = c[j];
				c[j] = c[j - 1];
				c[j - 1] = temp;
			}
		}
	}
}

void selectionsort( card c[] , int n ){
	
	card temp;
	int i , j;
	int min;
	
	for( i = 0; i < n; i++ ){
		
		min = i;
		
		for( j = i; j < n; j++ ){
			
			if( c[j].number < c[min].number ){
				min = j;
			}
		}
			
		temp = c[i];
		c[i] = c[min];
		c[min] = temp;
		
	}
}
	
int stablesort( card c1[] , card c2[] , int n ){
	
	int i;
	
	for( i = 0; i < n; i++ ){
		if( c1[i].mark != c2[i].mark ){ return 0; }
	}
	
	return 1;
}




Measured memory_bytes: 2144
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    A, B, C, K = lr()
    ans = 0
    if K <= A:
        ans += K
        print(ans)
        return
    ans += A
    K -= A
    if K <= B:
        print(ans)
        return
    K -= B
    ans -= K
    print(ans)
resolve()

Measured memory_bytes: 61724
N,K=map(int,input().split())
k=K
p=[0]*20
p[0]=10**5+1
for i in range(19):
    p[i+1]=k
    k=k/2

ans=0
for i in range(N):
    for j in range(19):
        if i+1<p[j] and i+1>=p[j+1]:
            ans+=(1/N)*((1/2)**(j))
print(ans)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

double ComputeEfficiency(int seed_price,
		      int seed2spear_duration,
		      int spear2leaflet_duration,
		      int leaflet2leaf_duration,
		      int leaf2flower_duration,
		      int flower2berry_duration,
		      int berry_per_seed,
		      int berry_price,
		      int seed2berry_limit){
  //ある種に対する収入は，その種から成った全ての実を売った金額から，種の値段を引いた値である．
  //また，その種の収入効率は，その収入を，種を植えてから全ての実が成り終わるまでの時間で割った値である．
  int income = (berry_price * berry_per_seed) * seed2berry_limit - seed_price;
  int time = seed2spear_duration
    + spear2leaflet_duration
    + leaflet2leaf_duration
    + seed2berry_limit * (leaf2flower_duration + flower2berry_duration);
  return (double)income/(double)time;
}

class Crop {
public:
  string name;
  double efficiency;

  Crop(string _name,double _efficiency) : name(_name),efficiency(_efficiency){}

  bool operator>(const Crop& c) const{
    if(efficiency - EPS <= c.efficiency
       && c.efficiency <= efficiency + EPS){
      return name < c.name;
    }
    return efficiency > c.efficiency;
  }
  
  bool operator<(const Crop& c) const{
    if(efficiency - EPS <= c.efficiency
       && c.efficiency <= efficiency + EPS){
      return name < c.name;
    }
    return efficiency < c.efficiency;
  }
  
};

int main(){
  int crop_num;
  
  while(~scanf("%d",&crop_num)){
    if(crop_num == 0) break;
    
    char crop_name[32];
    int seed_price,seed2spear_duration,
      spear2leaflet_duration,leaflet2leaf_duration,
      leaf2flower_duration,flower2berry_duration,
      berry_per_seed,berry_price,seed2berry_limit;

    vector<Crop> crops;
    for(int i=0;i<crop_num;i++){
      scanf("%s %d %d %d %d %d %d %d %d %d",
	    crop_name,
	    &seed_price,
	    &seed2spear_duration,
	    &spear2leaflet_duration,
	    &leaflet2leaf_duration,
	    &leaf2flower_duration,
	    &flower2berry_duration,
	    &berry_per_seed,
	    &berry_price,
	    &seed2berry_limit);
      double efficiency
	= ComputeEfficiency(seed_price,
			    seed2spear_duration,
			    spear2leaflet_duration,
			    leaflet2leaf_duration,
			    leaf2flower_duration,
			    flower2berry_duration,
			    berry_per_seed,
			    berry_price,
			    seed2berry_limit);
      crops.push_back(Crop(crop_name,efficiency));
    }

    sort(crops.begin(),crops.end(),greater<Crop>());
    for(int i=0;i<crops.size();i++){
      cout << crops[i].name << endl;
    }
    printf("#\n");
  }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

ll calc_ene(int P,int Xi){
    return (Xi-P)*(Xi-P);
}

int main() {
    int N;
    vector<int> X;
    cin >> N;
    int temp;
    rep(i,N){
        cin >> temp;
        X.push_back(temp);
    }

    int min = *min_element(X.begin(),X.end());
    int max = *max_element(X.begin(),X.end());
    ll ene = INF;
    for(int i=min;i<max+1;i++){
        ll sum = 0;
        for(int j=0;j<N;j++){
            sum += calc_ene(i,X[j]);
        }
        chmin(ene,sum);
        //printf("%d %lld %lld\n",i,ene,sum);
    }

    cout << ene << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

/* O(log n) */
struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n) : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v)
      return false;
    if (parent[u] > parent[v])
      swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool issame(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

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

  vector<int> K(N);
  vector<vector<int>> L(N);
  vector<bool> used(M, false);

  rep(i, N) {
    cin >> K[i];
    rep(j, K[i]) {
      int temp;
      cin >> temp;
      temp--;
      L[i].pb(temp);
      used[temp] = true;
    }
  }

  UnionFind U(M);
  rep(i, N) {
    rep(j, K[i] - 1) {
      U.unite(L[i][j], L[i][j + 1]);
    }
  }

  int r = -1;
  rep(i, M) {
    if (!used[i])
      continue;

    if (r == -1)
      r = U.root(i);
    else {
      if (r != U.root(i)) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}

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

int main() {
    int ret = 0, N; cin >> N;
    vector<int> A(N),B(N),C(N);

    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    for(int i = 0; i < N; i++){
        cin >> B.at(i);
    }
    for(int i = 0; i < N-1; i++){
        cin >> C.at(i);
    }
    for(int i = 0; i < N; i++){
        ret += B.at(A.at(i)-1);
    }
    for (int i = 0; i < N-1; i++){
        if((A.at(i) + 1) == A.at(i+1)){
            ret += C.at(A.at(i)-1);
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll N;cin>>N;
	string S;cin>>S;
    
	// 解法
	ll rgb[3];
	REP(i,3)rgb[i] = 0;
	REP(i,N){
		if (S.substr(i,1)=="R")rgb[0]++;
		if (S.substr(i,1)=="G")rgb[1]++;
		if (S.substr(i,1)=="B")rgb[2]++;
	}
	// REP(i,3)printf("%lld\n", rgb[i]);

	ll ans = 1;
	REP(i,3) ans *= rgb[i];
	// printf("%lld\n", ans);
	ll count = 0;
	REP(i,N){
		for (ll j = i+1; j < N; ++j){
			ll k = (j-i) + j;
			if (k>=N)continue;
			if (S[i]!=S[j] & S[j]!=S[k] & S[k]!=S[i]){
				// printf("%lld, %lld, %lld\n",i,j,k);
				count++;
			}
		}
	}
	ans -= count;

	//出力
	printf("%lld\n", ans);
}


Measured memory_bytes: 3736
#include<stdio.h>
#include<math.h>
int main()
{	int x,a,b,ax,bx;
	scanf("%d%d%d",&x,&a,&b);
	ax=a-x;
	bx=b-x;
	if(abs(ax)<abs(bx))
		printf("A\n");
	else printf("B\n");
	return 0;
}

Measured memory_bytes: 128
N = int(input())
sumN = N*(N+1)/2
sumFizz = ((N//3)*((N//3)+1))*3/2
sumBuzz = ((N//5)*((N//5)+1))*5/2
sumFizzBuzz = ((N//15)*((N//15)+1))*15/2
print(int(sumN - sumFizz - sumBuzz + sumFizzBuzz))

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,k;
	cin>>n>>k;
	vl a(n),b(n+1,0);
	rep(i,n){cin>>a[i];b[i+1]=a[i];}
	partial_sum(all(b),b.begin());
	vl s;
	rep(i,n+1)rep(j,i){
	    s.push_back(b[i]-b[j]);
	}
	sort(all(s));
	ll ans=0;
    for(int i=41;i>=0;i--){
        ll m=1ll<<i;
        vl s2;
        for(auto&d:s){
            if(d&m){
                s2.push_back(d);
            }
        }
        if(s2.size()>=k){
            s=s2;
            ans|=m;
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6512
fn main() {
    let n: usize = read();
    let mut an: Vec<usize> = read_vec();
    let mut bn: Vec<usize> = read_vec();
    let mut cn: Vec<usize> = read_vec();

    an.sort();
    bn.sort();
    cn.sort();

    let mut ans = 0;
    for b in bn.iter() {
        let idxa = bisect_left(&an, *b, cond);
        let count_a = idxa;

        let idxc = bisect_left(&cn, b + 1, cond);
        let count_c = n - idxc;

        ans += count_a * count_c;
    }

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

fn cond(seq: &Vec<usize>, idx: usize, key: usize) -> bool {
    seq[idx] >= key
}

fn bisect_left<T: Copy>(seq: &Vec<T>, key: T, condition: fn(&Vec<T>, usize, T) -> bool) -> usize {
    let (mut left, mut right) = (-1, seq.len() as i64);
    while left + 1 < right {
        let mid = left + (right - left) / 2;
        if condition(&seq, mid as usize, key) {
            right = mid;
        } else {
            left = mid;
        }
    }
    right as usize
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


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

int main() {
	int n, a, flag = false;
	map<int,int> m;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (m[a]++) flag = true;
	}
	cout << (flag?"NO":"YES") << endl;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

  int left = y[n / 2 - 1];
  int right = y[n / 2];

  for (int i = 0; i < n; i++) {
    if (x[i] <= left) {
      cout << right << endl;
    } else {
      cout << left << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
using namespace std;
using ld = long double;

int main() {
	int m, n;
	cin >> m >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum = min(m + 1, sum + x);
	}
	
	cout << max(-1, m - sum);
}

Measured memory_bytes: 3608
import numpy as np

n = int(input())
a = input().split(" ")
p = [int(i) for i in a]

count = 0
for i in range(n-2):
    ma = max(p[i],p[i+1],p[i+2])
    mi = min(p[i],p[i+1],p[i+2])
    if p[i+1] != ma and p[i+1] != mi:
        count += 1
print(count)

Measured memory_bytes: 21652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll K;
    cin >> K;
    ll tmp;
    ll cnt;
    if(K % 7 == 0){
        K = K / 7;
        K = K * 9;
        tmp = 10 % K;
        cnt = 1;
        for (ll i = 1; i <= K; i++) {
            if(tmp == 1 || K == 1) {
                printf("%lld\n", cnt);
                return 0;
            }
            tmp = tmp * 10 % K;
            cnt++;
        }
    }
    else{
        K = K * 9;
        tmp = 10 % K;
        cnt = 1;
        for (ll i = 1; i <= K; i++) {
            if(tmp == 1 || K == 1) {
                printf("%lld\n", cnt);
                return 0;
            }
            tmp = tmp * 10 % K;
            cnt++;
        }
    }
    printf("-1\n");
}

Measured memory_bytes: 3748
#include <iostream>
#include <string>

int main()
{
  std::string picture[100];
  int H, W;
  std::cin >> H >> W;

  for(int i = 0; i < H; i++)
  {
    std::cin >> picture[i];
  }
  
  for(int i = 0; i < W + 2; i++)
  {
    std::cout << "#";  
  }
  std::cout << "\n";  
  
  for(int i = 0; i < H; i++)
  {
    std::cout << "#" << picture[i] << "#\n";
  }

  for(int i = 0; i < W + 2; i++)
  {
    std::cout << "#";  
  }
  std::cout << "\n";  
  
  return 0;
}

Measured memory_bytes: 3140
#include<cstdio>
#include<cstring>
using namespace std;
char a[105],b[105];
int main(){
	scanf("%s",a);
	scanf("%s",b);
	int len1 = strlen(a);
	int len2 = strlen(b);
	if(len1 > len2) printf("GREATER");
	if(len1 < len2) printf("LESS");
	if(strlen(a) == strlen(b)){
		if(strcmp(a,b) > 0) printf("GREATER");
		else if(strcmp(a,b) < 0) printf("LESS ");
		else printf("EQUAL");
	}
}

Measured memory_bytes: 128
//105,135,165,195,189
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int ans=0;
  cin >> n;
  vector<int> da(5);
  da={105,135,165,195,189};
  for(int i=0;i<5;i++){
    if(da[i]<=n)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256