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

#define V vector
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define prec(x) cout<<fixed<<setprecision(x)
#define f(i,a) for(int i = 0 ; i < a ; i++)
#define ff first
#define ss second
#define all(x) (x).begin() ,(x).end()

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

ll binpow(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

void solve()
{
	ll n , k;
	cin >> n >> k;

	ll a[n];

	rep(i , 0 , n )
	cin >> a[i];

	ll p = 1;

	rep(i , 0 , k)
	{
		if (a[i] < (LLONG_MAX) / p)
			p *= a[i];
		else
			p = LLONG_MAX;
	}

	ll curr = p;

	rep(i , k , n)
	{
		if (a[i - k] < a[i])
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}


int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	int t = 1;
	//cin >> t;

	while (t--)
	{
		solve();
	}

	return 0;
}





Measured memory_bytes: 5216
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>


#define fs first
#define sc second

using namespace std;

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


int main(){
    int N, C;
    cin >> N >> C;
    ll D[30][30];
    int x[500][500];
    for(int i = 0; i < C; i++){
        for(int j = 0; j < C; j++){
            cin >> D[i][j];
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> x[i][j];
            x[i][j]--;
        }
    }

    ll res = LONG_LONG_MAX;

    ll cost[3][30];
    for(int j = 0; j < 3; j++){
        for(int i = 0; i < C; i++){
            ll cost_sum = 0;
            for(int k = 0; k < N; k++){
                for(int l = 0; l < N; l++){
                    if((k+l) % 3 == j){
                        cost_sum += D[x[k][l]][i];
                    }
                }
            }
            cost[j][i] = cost_sum;
        }
    }

    for(int i = 0; i < C*C*C; i++){
        int c1 = i % C;
        int c2 = (i / C) % C;
        int c3 = (i / (C * C)) % C;
        if(c1 == c2 || c2 == c3 || c3 == c1){
            continue;
        }

        res = min(res, cost[0][c1]+cost[1][c2]+cost[2][c3]);
    }

    cout << res << endl;



    return 0;

}


Measured memory_bytes: 1280
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int r; cin >> r;
  if (r < 1200) {
    cout << "ABC";
  } else if (r < 2800) {
    cout << "ARC";
  } else {
    cout << "AGC";
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=1e3+10;
int H,W,K;
char S[20][MAXN];
int sum[20][MAXN];
void read()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>H>>W>>K;
    for(int u=1;u<=H;u++){
        cin>>S[u]+1;
    }
}
void solve()
{
    read();
    for(int u=1;u<=H;u++){
        for(int v=1;v<=W;v++){
            sum[u][v]=sum[u][v-1]+S[u][v]-'0';
        }
    }
    int ans=0x3f3f3f3f;
    for(int v=0;v<(1<<(H-1));v++){
        int lst=0,acc=0,cut=0;
        bool flag=true;
        for(int cur=1;cur<=W;cur++){
            for(int b=1;b<=H;b++){
                acc+=sum[b][cur]-sum[b][lst];
                if(acc>K){
                    if(cur-lst==1){
                        flag=false;
                        break;
                    }
                    b=0,acc=0,lst=cur-1;
                    cut++;
                }
                if(b==H||v&(1<<(b-1)))acc=0;
            }
            if(!flag)break;
        }
        if(flag){
            int t=0;
            for(int u=0;u<H;u++){
                if((1<<u)&v)t++;
            }
            ans=min(ans,t+cut);
        }
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
const int N=1005;
int a[N];
int ans[N][N];
int main()
{
	int n,m,x,y;scanf("%d%d%d%d",&n,&m,&x,&y);
	if(n%x==0 && m%y==0){puts("No");return 0;}
	puts("Yes");
	if(m%y!=0)
	{
		rep(i,1,m)
		{
			if(i%y==1) a[i]=998244353;
			else a[i]=-((998244353/(y-1))+1);
		}
		rep(i,1,n){rep(j,1,m)printf("%d ",a[j]);puts("");}
	}
	else
	{
		rep(i,1,n)
		{
			if(i%x==1) a[i]=998244353;
			else a[i]=-((998244353/(x-1))+1);
		}
		rep(i,1,m)
		{
			rep(j,1,n)ans[j][i]=a[j];
		}
		rep(i,1,n){rep(j,1,m)printf("%d ",ans[i][j]);puts("");}
	}
	return 0;
}

Measured memory_bytes: 4736
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    m1, d1 = [int(i) for i in input().split()]
    m2, d2 = [int(i) for i in input().split()]
    if m1 == m2:
        print(0)
    else:
        print(1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
from collections import deque

N,M=map(int,input().split())
G=[[] for _ in range(N)]
for _ in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

group=[]
seen=[0]*N
ans=0
for i in range(N):
    if seen[i]: continue
    que=deque()
    seen[i]=1
    cnt=0
    que.append(i)
    while que:
        cnt+=1
        v=que.popleft()
        for nv in G[v]:
            if seen[nv]: continue
            seen[nv]=1
            que.append(nv)
    ans=max(ans,cnt)

print(ans)


Measured memory_bytes: 45224
#include<bits/stdc++.h>
using namespace std;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) lps(i,0,n)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define FDST int hogehogehoge;cin>>hogehogehoge

int main(){
  int n,rc=0,lc=0;
  string s;
  cin>>n>>s;
  if(s[0]=='>' || s[s.size()-1]=='<') cout<<n<<endl;
  else{
    for(int i=0;i<s.size();i++){
      if(s[i]=='<') rc++;
      else break;
    }
    for(int i=s.size()-1;i>=0;i--){
      if(s[i]=='>') lc++;
      else break;
    }
    cout<<n-min(lc,rc)<<endl;
  }
  return 0;
}



Measured memory_bytes: 3304
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; string s; cin >> n >> s;
	int right[2] = {}, left[2] = {}, ans = n;
	for(char c : s) right[c == 'E']++;
	rep(i, n){
		right[s[i] == 'E']--;
		ans = min(ans, left[0] + right[1]);
		left[s[i] == 'E']++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
	//freopen("input.txt","rt",stdin);
	double d,t,s;
	cin>>d>>t>>s;
	if(d/s <= t){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
}

Measured memory_bytes: 3720
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	int d, w, h;
	double a, b;
	int r;
	int n;

	while (true)
	{
		scanf("%d %d %d", &d, &w, &h);
		if (d == 0 && w == 0 && h == 0)
			break;

		if (d < w)
		{
			if (d < h) /* d < w ? h */
			{
				a = d / 2;
				b = (w < h) ? w / 2 : h / 2;
			}
			else /* h <= d < w ? */
			{
				a = h / 2;
				b = d / 2;
			}
		}
		else /* w <= d ? */
		{
			if (w < h) /* w <= d ? h */
			{
				a = w / 2;
				b = (d < h) ? d / 2 : h / 2;
			}
			else /* h <= w <= d ? */
			{
				a = h / 2;
				b = w / 2;
			}
		}

		scanf("%d", &n);
		while (n--)
		{
			scanf("%d", &r);
			if (a * a + b * b < r * r)
				printf("OK\n");
			else
				printf("NA\n");
		}
	}

	return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	long A = sc.nextLong();
    	long B = sc.nextLong();
    	long C = sc.nextLong();
    	long K = sc.nextLong();
    	sc.close();
    	long ans = 0;
    	if(A >= K){
    		ans += K;
    		System.out.println(ans);
    		return;
    	}else{
    		ans += A;
    		K -= A;
    	}
    	K -= B;
    	if(K <= 0){
    		System.out.println(ans);
    		return;
    	}
    	if(C >= K){
    		ans -= K;
    		System.out.println(ans);
    		return;
    	}else{
    		ans -= C;
    		K -= C;
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 35740
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{


    class Program
    {

        static long Solve(int N, int W, int[] weight, int[] value)
        {
            long[,] dp = new long[N + 1, W + 1];

            for(int j = 0; j <= W; j++)
            {
                dp[0, j] = 0;
            }

            for(int i = 1; i <= N; i++)
            {
                for(int w = 0; w <= W; w++)
                {
                    if (w - weight[i] < 0)
                    {
                        dp[i, w] = dp[i - 1, w];
                    }
                    else
                    {
                        dp[i, w] = Math.Max(dp[i - 1, w], dp[i - 1, w - weight[i]] + value[i]);
                    }                    
                }

            }
            
            return dp[N, W];
        }


        
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int W = int.Parse(input[1]);

            int[] w = new int[N + 1];
            int[] v = new int[N + 1];

            for(int i = 1; i <= N; i++)
            {
                input = Console.ReadLine().Split(' ');
                w[i] = int.Parse(input[0]);
                v[i] = int.Parse(input[1]);
            }

            Console.WriteLine(Solve(N, W, w, v));
        }
    }
}

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

int main(){
    ll n;
    string s, t;
    cin >> n >> s >> t;
    string ans;
    for(ll i = 0; i < n; i++){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
void merge(P&a,P b){
    vi t={a.fi,a.se,b.fi,b.se};
    sort(all(t));reverse(all(t));
    a=P(t[0],t[1]);
}
int main(){
    ll n;cin>>n;
    vi v(1<<n);
    rep(i,1<<n)cin>>v[i];
    vvp dp(1<<n,vp(n+1,P(-inf,-inf)));
    rep(i,1<<n){
        dp[i][0].fi=v[i];
        rep(j,n){
            dp[i][j+1]=dp[i][j];
            if(i>>j&1){
                merge(dp[i][j+1],dp[i&~(1<<j)][j]);
            }
        }
    }
    ll m=1<<n;
    vi res(m);
    rep(i,m)res[i]=dp[i][n].fi+dp[i][n].se;
    REP(i,1,m-1)chmax(res[i+1],res[i]);
    REP(i,1,m)out(res[i]);
}

Measured memory_bytes: 95232
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}


#define LLINF 1e18+7
#define N 250000
ll MOD=1e9+7;
main(){
    int n=in();
    vector<pll> v;
    rep(i,n){
        v.pb({in(),in()});
    }
    double M=300000.0;
    double pi=3.14159265358979;
    double m=2*pi/M;
    double ans=0;
    rep(i,M){
        double t=m*i;
        double tmp=0.0;
        rep(j,n){
            double T=cos(t)*v[j].first+sin(t)*v[j].second;
            if(T>0)tmp+=T;
        }
        ans=max(ans,tmp);
    }
    printf("%.15f",ans);
}


Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = S()

    s = N[-1]
    if s=='3':
        print('bon')
    elif s in ['0', '1', '6', '8']:
        print('pon')
    else:
        print('hon')

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 9148
// https://atcoder.jp/contests/abc129/tasks/abc129_a

#include <stdio.h>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int min = a + b + c;
    if (a + b < min)
        min = a + b;
    if (b + c < min)
        min = b + c;
    if (a + c < min)
        min = a + c;
    
    printf("%d\n", min);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> // accumulate
#include <queue>
#include <string>
#include <cmath> // sqrt
#include <map>
using namespace std;
typedef long long ll;

const int INF = 1000000010;
int dp[100010][3];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        vector<int> d(3);
        cin >> d[0] >> d[1] >> d[2];
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) continue;
                dp[i+1][j] = max(dp[i+1][j], dp[i][k] + d[j]);
            }
        }
    }
    int ans = 0;
    for (int k = 0; k < 3; k++) {
        ans = max(ans, dp[n][k]);
    }
    cout << ans << endl;
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int k;
long double ans;
long double res;
long double a[N];
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);

    cin >> n >> k;
    for(int i = 1; i <= n; i ++){
        cin >> a[i];
    }
    for(int i = 1; i <= k; i ++){
        res += ((a[i] * (a[i] + 1)) / 2.0) / a[i];
    }
    ans = res;
    for(int i = k + 1; i <= n; i ++){
        res -= ((a[i - k] * (a[i - k] + 1) / 2.0)) / a[i - k];
        res += ((a[i] * (a[i] + 1)) / 2.0) / a[i];
        ans = max(ans, res);
    }
    cout << fixed << setprecision(10) << ans << "\n";
}



Measured memory_bytes: 3456
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)



int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    if (N <= 2) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> rc(N);
    vector<int> bc(N);
    vector<int> gc(N);
    rep(i, N) {
        rc[i] = 0;
        bc[i] = 0;
        gc[i] = 0;
    }
    rc[s.size() - 1] = s.back() == 'R' ? 1 : 0;
    bc[s.size() - 1] = s.back() == 'B' ? 1 : 0;
    gc[s.size() - 1] = s.back() == 'G' ? 1 : 0;
    for (int i = s.size() - 2; i >= 0; --i) {
        if (s[i] == 'R') {
            rc[i] = rc[i + 1] + 1;
            bc[i] = bc[i + 1];
            gc[i] = gc[i + 1];
        }
        else if (s[i] == 'B') {
            bc[i] = bc[i + 1] + 1;
            rc[i] = rc[i + 1];
            gc[i] = gc[i + 1];
        }
        else if (s[i] == 'G') {
            gc[i] = gc[i + 1] + 1;
            bc[i] = bc[i + 1];
            rc[i] = rc[i + 1];
        }
    }
    ll sum = 0;
    rep(i, N - 2)repi(j, i + 1, N - 1) {
        if (s[i] == 'R') {
            if (s[j] == 'R') {
                continue;
            }
            else if (s[j] == 'B') {
                sum += gc[j + 1];
            }
            else if (s[j] == 'G') {
                sum += bc[j + 1];
            }
        }
        else if (s[i] == 'B') {
            if (s[j] == 'B') {
                continue;
            }
            else if (s[j] == 'R') {
                sum += gc[j + 1];
            }
            else if (s[j] == 'G') {
                sum += rc[j + 1];
            }
        }
        else if (s[i] == 'G') {
            if (s[j] == 'G') {
                continue;
            }
            else if (s[j] == 'B') {
                sum += rc[j + 1];
            }
            else if (s[j] == 'R') {
                sum += bc[j + 1];
            }
        }
        int k = 2 * j - i;
        if (k >= 0 && k < s.size() && s[i] != s[j] && s[j] != s[k] && s[k]!=s[i]) sum--;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3204
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, K = MI()
    A = LI()
    for i in range(K):
        B = [0] * N
        for idx, a in enumerate(A):
            l = max(0, idx - a)
            r = idx + a + 1
            # print(idx, a, l, r)
            B[l] += 1
            if N > r:
                B[r] -= 1
        # print(B)
        B = list(accumulate(B))
        # print(B)
        if all([j == N for j in B]):
            printlist(B)
            return
        A = B
    printlist(A)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 181388
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define inf LLONG_MAX
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6];
ll power(ll x,ll n){
    if(n==0) return 1;
    /*while(n){
        if(n%2) x=(((x*x)%M)*x)%M; 
        else x=(x*x)%M;
        n/=2;
    }*/
    if(n%2 == 0) return power((x*x),n/2);
    else return (x*power((x*x),(n-1)/2));
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=M6;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
ll n,m,ar[M6],vis[M6];
int main(){
    //buf; 
    //fact();
    ll i,j,r,k,l,test,flag,ans; string s;
    //cin>>test;
    test=1;
    while(test--){
    	cin>>n>>k;
    	for(i=1;i<=n;i++){
    		cin>>j; vis[j]++;
    	}
    	V v;
    	for(i=1;i<M6;i++) if(vis[i]) v.pb(vis[i]);
    	if(v.size()<=k) {cout<<"0"; continue;}
    	sort(v.begin(),v.end());
    	ans=0;
    	for(i=0;i<v.size()-k;i++) ans+=v[i];
    		cout<<ans;

    }
    return 0;
}

Measured memory_bytes: 6004
N,M = map(int,input().split())
ans_array = [-1] * N
for i in range(M):
    s,c = map(int,input().split())
    if ans_array[s-1] == -1:
        ans_array[s-1] = c
    elif ans_array[s-1] != c:
        print(-1)
        exit()

for i in range(N):
    if ans_array[i] == -1:
        if i != 0 or N == 1:
            ans_array[i] = 0
        else:
            ans_array[i] = 1
if ans_array[0] == 0 and N != 1:
    print(-1)
    exit()

ans = 0
base = 1
for n in ans_array[::-1]:
    ans += (base * n)
    base *= 10
print(ans)

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

int main() {
  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  vector<int> w(30);
  vector<int> s(30*E);
  w.at(0)=1,s.at(0)=1;
  for(int i=A;i<30;i++){
    w.at(i)+=w.at(i-A);
  }
  for(int i=B;i<30;i++){
    w.at(i)+=w.at(i-B);
  }
  for(int i=C;i<30*E;i++){
    s.at(i)+=s.at(i-C);
  }
  for(int i=D;i<30*E;i++){
    s.at(i)+=s.at(i-D);
  }
  vector<int> W;
  vector<int> S;
  for(int i=0;i<30;i++){
    if(w.at(i)!=0){
      W.push_back(i);
    }
  }
  for(int i=0;i<30*E;i++){
    if(s.at(i)!=0){
      S.push_back(i);
    }
  }
  int N=W.size();
  int M=S.size();
  int X=W.at(1),Y=0,a=0;
  for(int i=1;i<N;i++){
    if(W.at(i)*E>S.at(M-1)){
      break;
    }
    else{
      int b=lower_bound(S.begin(),S.end(),W.at(i)*E+1)-S.begin();
      for(int j=a;j<b;j++){
        if(W.at(i)*Y<X*S.at(j)&&W.at(i)*100+S.at(j)<=F){
          X=W.at(i),Y=S.at(j);
        }
      }
    }
  }
  cout<<100*X+Y<<" "<<Y<<endl;
        
      
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <utility>

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    int a, b;
    ll ans = 1;
    int cnt = 0;
    sort(v.begin(), v.end());
    for(int i=n-1;i>0;i--) {
        if(v[i] == v[i-1]) {
            ans *= v[i];
            cnt++;
            i--;
        }
        if(cnt >= 2)
            break;
    }
    if(cnt < 2)
        cout << 0 << endl;
    else
        cout << ans << endl;


}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
if(x->right!=NIL)return treeMinimum(x->right);
Node y=x->parent;
y=x->parent;
while(y!=NIL&&x==y->right){
  x=y;
  y=y->parent;
}
return  y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
if(z->left==NIL||z->right==NIL)
y=z;
else y=treeSuccessor(z);
if(y->left!=NIL)x=y->left;
else x=y->right;
if(x!=NIL)x->parent=y->parent;
if(y->parent==NIL)root=x;
else if(y==y->parent->left)y->parent->left=x;
else y->parent->right=x;
if(y!=z)z->key=y->key;


  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z =malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key<y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}


void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
      if ( com[0] == 'f' ){
     scanf("%d", &x);
     Node t = treeSearch(root, x);
     if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      }
  if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
  } else if ( com[0] == 'd' ){
  scanf("%d", &x);
  treeDelete(treeSearch(root, x));
  }
  }

  return 0;
}



Measured memory_bytes: 20448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	while(n!=0){
		ans++;
		n/=k;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3572
import sys
input = sys.stdin.readline
n = int(input())
anslist = []

from math import sqrt
for i in range(1,n+1):
    ans = 0
    for x in range(1,int(sqrt(i))+1):
        for y in range(x,int(sqrt(i))+1):
            if (x+y)**2-4*(x*y+x**2+y**2-i) < 0:
                continue
            z = (-(x+y)+sqrt((x+y)**2-4*(x*y+x**2+y**2-i)))/2
            zz = int((-(x+y)+sqrt((x+y)**2-4*(x*y+x**2+y**2-i)))/2)
            if z == zz and zz >= y:
                if x == y and y == z and x == z:
                    ans += 1
                    #print(i,x,y,zz)
                elif x == y:
                    ans += 3
                elif y == z:
                    ans += 3
                else:
                    ans += 6
    anslist.append(ans)

for ans in anslist:
    print(ans)
            



Measured memory_bytes: 69668
#include<iostream>
#define LL long long
using namespace std;
int main()
{
    LL n,x;
    while(cin>>n>>x)
    {
        LL t=x;
        LL sum=n;
        x=min(t,n-t);//分析可知x于n-x答案相同（相当于旋转了）
        LL y=max(t,n-t);//这里只计算x小的那种情况
        while(x>=1)
        {
            if(y%x==0)//如果y能整除x刚好能射出
            {
                sum+=(y/x)*2*x;
                sum-=x;
                break;
            }
            else{              //否则的话更新反射后的x，y的值。
               sum+=(y/x)*2*x;
               LL te=x;
               x=y%x;
               y=te;
            }
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
using System;

namespace abc063_b
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] str = Console.ReadLine().ToCharArray();
            for (int i = 0; i < str.Length - 1; i++)
            {
                for (int j = i + 1; j < str.Length; j++)
                {
                    if (str[i] == str[j])
                    {
                        Console.WriteLine("no");
                        return;
                    }
                }
            }
            Console.WriteLine("yes");
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
int main(){
  char s[11];int i,a=0,l=0;
  scanf("%s",s);
  for(i=0;i<strlen(s);i++){
    if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){l++;a=(a<l?l:a);}
    else l=0;
  }
  printf("%d",a);
  return 0;
}


Measured memory_bytes: 1700
#include<stdio.h>
int main(void){
   char name[100];
   int a, b, n = 0, sum_men, sum_income;
   while (n < 9) {
      scanf("%s %d %d", name, &a, &b);
      sum_men = a + b;
      sum_income = a * 200 + b * 300;
      printf("%s %d %d\n", name, sum_men, sum_income);
      n++;
   }
   return 0;
}

Measured memory_bytes: 1860
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer []AN  = new Integer[N];
        Integer []BN = new Integer[N];
        List<Integer> list = new LinkedList<>();
        for (int i=0;i<N;i++){
            AN[i]=sc.nextInt();
            BN[i]=AN[i];
            //list.add(AN[i]);
        }
        list.addAll(Arrays.asList(BN));
        Arrays.sort(BN);


        //list.addAll(Arrays.asList(AN));
        Long cnt = 0L;

        for(int i=0;i<N;i++){
            int tmp = i + Arrays.binarySearch(BN, AN[i]);

            //System.out.println(AN[i]+" "+list.indexOf(AN[i])+" "+tmp);
            if (tmp%2!=0) cnt++;

        }
        System.out.println(cnt/2);

    }
 }


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}

#define deb(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define END '\n'
#define inf 9e18
#define ff first
#define ss second
#define pb push_back

void solve(){
    int a, b;
    cin >> a >> b;
    cout << ((a + b < 10) ? to_string(a + b) : "error");
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)

Measured memory_bytes: 285828
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a[111111],ans=0;
  cin>>n>>m;
  for(int i=0;i<m;i++) cin>>a[i];
  sort(a,a+m);
  for(int i=0;i<m-1;i++) a[i]=abs(a[i]-a[i+1]);
  sort(a,a+m-1,greater<int>());
  for(int i=n-1;i<m-1;i++) ans+=a[i];
  cout<<ans<<endl;
  return(0);
}


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

int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    ll ans;
    if (a != 0) {
        ans = b / x - (a - 1) / x;
    } else {
        ans = b / x + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<vector<pair<int, int>>> a(n);
	for( int i = 0; i < n; ++i ){
		int num; cin >> num;
		for( int j = 0; j < num; ++j ){
			int s, t; cin >> s >> t;
			a[i].push_back(make_pair(s-1, t));
		}
	}
	int ans = 0;
	for( int cond = 0; cond < (1<<n); ++cond ){
		int cnt = 0;
		bool flag = true;
		for( int i = 0; i < n; ++i ){
			if( cond & (1<<i) ){
				++cnt;
				for( auto k : a[i] ){
					if( (bool)( cond & (1<<(k.first)) ) != (bool)(k.second) ){
						flag = false;
					}
				}
			}
		}
		if( flag == true ){
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def power(n, m, cache)
  return 1 if m.zero?
  return n if m == 1
  if (cache[n])
    return cache[n][m] if cache[n].has_key?(m)
  else
    cache[n] = {}
  end
  t = power(n, m / 2, cache) % 1000000007
  cache[n][m] = (m % 2 == 1 ? t * t * n : t * t) % 1000000007
end

n, m = gets.split.map(&:to_i)
cache = {}
puts power(n, m, cache)



Measured memory_bytes: 6884
n = int(input())
strings = [input().strip() for i in range(n)]
counter = {}

for string in strings:
    counter[string] = counter.get(string, 0) + 1

res = sorted(list(counter.items()), key=lambda x: -x[1])

result2 = []

for string, count in res:
    if count == res[0][1]:
        result2.append(string)
    else:
        break
result2.sort()
print('\n'.join(result2))


Measured memory_bytes: 120020
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[2][12]={};
        for(int i=0;i<n;i++){
                cin>>ans[0][i];
                ans[1][i]=ans[0][i];
        }
        for(int i=0;;i++){
            int num[100]={};
            for(int j=0;j<n;j++)num[ans[0][j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                ans[0][j]=num[ans[0][j]];
                if(ans[0][j]!=ans[1][j])rever=0;
            }
            if(rever){
                cout<<i<<endl;
                for(int j=0;j<n-1;j++)cout<<ans[0][j]<<" ";
                cout<<ans[0][n-1]<<endl;
                break;
            }
            for(int j=0;j<n;j++)ans[1][j]=ans[0][j];
        }
    }
}

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

int main() {
  long X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  long best = X / D; // or (+1)
  if(best > K) {
    cout << X - K * D << endl;
  } else {
    int c = K - best;
    if(c % 2 == 0) cout << X - D * best << endl;
    else cout << abs(X - D * (best + 1)) << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    s = readline().strip()

    print(s.replace(',', ' '))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 8972
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll l,r,d;
    cin>>l>>r>>d;
    ll ans = 0;
    for(ll i=l; i<=r; i++)
    {
        if(i%d==0)
        {
            ans++;
        }
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    vector<int> cnt;
    
    for(int i = 0; i <= N; i++){
        int sum = 0;
        if(i * R > N)   break;
        
        for(int j = 0; j <= N; j++){
            if(i * R + j * G > N)   break;
            
            sum = i * R;
            sum += j * G;
            cnt.push_back(sum);
            
        }
    }
    
    for(int i = 0; i < cnt.size(); i++){
        if((N - cnt[i]) % B == 0)       ans++;
    }
    
    cout << ans << endl;
}

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

char field[102][102];

void dfs(int r,int c,char type);

int main()
{
	int h,w;
	int areanum;
	char buf[128];
	
	while(1)
	{
		std::cin>>h>>w;
		if(h==0&&w==0)break;
		std::cin.ignore();
		
		memset(field,0,sizeof(field));
		
		for(int i=1;i<=h;i++)
		{
			std::cin.getline(buf,128);
			for(int j=1;j<=w;j++)
			{
				field[i][j]=buf[j-1];
			}
		}
		
		areanum=0;
		for(int i=1;i<=h;i++)
		{
			for(int j=1;j<=w;j++)
			{
				if(field[i][j]!=0)
				{
					dfs(i,j,field[i][j]);
					areanum++;
				}
			}
		}
		std::cout<<areanum<<std::endl;
	}
	return 0;
}

void dfs(int i,int j,char type)
{
	field[i][j]=0;
	if(field[i][j-1]==type)dfs(i,j-1,type);
	if(field[i][j+1]==type)dfs(i,j+1,type);
	if(field[i-1][j]==type)dfs(i-1,j,type);
	if(field[i+1][j]==type)dfs(i+1,j,type);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

#define ll long long
#define rep(i, n) for (i = 0; i < n; i++)

int main()
{
  int N;
  cin >> N;
  ll ans = 0;
  for (int i = 1; i <= N; i++)
  {
    if (i % 3 == 0 || i % 5 == 0)
    {
      continue;
    }
    else
    {
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){
    string str;
    cin >> str;
    int res = 0;

    for( int i = 0 ; i < (str.size() + 1)/2 ; i++ ){
        if( str[i] != str[str.size() - 1 - i] ) res++;
    }

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 256
let s = read_line ()
let k = Scanf.sscanf (read_line ()) "%d" @@ fun k -> k

let s_len = String.length s

let () =
  let acc = 
    List.init s_len (fun i -> List.init (min 5 (s_len - i)) (fun j -> String.sub s i (j + 1)))
    |> List.flatten 
    |> List.sort_uniq compare in
  print_endline @@ List.nth acc (k - 1)
  

Measured memory_bytes: 7992
#include <cstdio>
#include <cstring>
#include <cassert>
#include <map>
#define MAXN 2010
#define MAXM 100010
using namespace std;

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXM<<1];

int n,numn;
int a[MAXN];
bool flag[10010];
int prime[10010],nump;
int g[MAXM],nume;
int d[MAXN][MAXN];
bool tag[MAXM],visit[MAXM],used[MAXM];
map<int,int> Sp;
int c[MAXM],numc;
int maxv[MAXN],totmax,totmax2;

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

int gcd(int x,int y){
	if(!y) return x;
	return gcd(y,x%y);
}

void init(){
	for(int i=2;i<10010;i++){
		if(!flag[i]) prime[++nump]=i;
		for(int j=1;j<=nump && i*prime[j]<10010;j++){
			flag[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
}

void pre_gao(int x,int v){
	int v0=v;
	for(int i=1;i<=nump && prime[i]*prime[i]<=v0;i++)
		if(v%prime[i]==0){
			while(v%prime[i]==0) v/=prime[i];
			if(!Sp.count(prime[i])) Sp[prime[i]]=++numn;
			addEdge(x,Sp[prime[i]]);
			addEdge(Sp[prime[i]],x);
		}
	if(v>1){
		if(!Sp.count(v)) Sp[v]=++numn;
		addEdge(x,Sp[v]);
		addEdge(Sp[v],x);
	}
}

void dfs(int x){
	visit[x]=1;
	c[x]=numc;
	if(tag[x] && a[x]<maxv[numc]) maxv[numc]=a[x];
	for(int i=g[x];~i;i=e[i].next)
		if(!used[e[i].to] && !visit[e[i].to]){
			dfs(e[i].to);
		}
}

int gao(int l){
	for(int i=1;i<=numn;i++) visit[i]=0;
	totmax2=totmax=numc=0;
	for(int i=1;i<=n;i++)
		if(!used[i] && !visit[i]){
			maxv[++numc]=1<<30;
			dfs(i);
			if(maxv[numc]>totmax){
				totmax2=totmax;
				totmax=maxv[numc];
			}else if(maxv[numc]>totmax2) totmax2=maxv[numc];
		}
	int minv=1<<30;
	for(int i=1;i<=n;i++)
		if(!used[i] && tag[i] && a[i]<minv){
			if(maxv[c[i]]==totmax && a[i]<totmax2) continue;
			if(maxv[c[i]]!=totmax && a[i]<totmax) continue;
			minv=a[i];
		}
	for(int i=1;i<=n;i++)
		if(!used[i] && tag[i] && a[i]==minv){
			used[i]=1;
			for(int j=1;j<=n;j++)
				if(tag[j] && a[j]>a[i]) 
					tag[j]=0;
			for(int j=1;j<=n;j++)
				if(!used[j] && !tag[j] && d[j][i]!=1)
					tag[j]=1;
			return minv;
		}
	assert(0);
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	init();
	scanf("%d",&n);
	numn=n;
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		pre_gao(i,a[i]);
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			d[i][j]=gcd(a[i],a[j]);
	for(int i=1;i<=n;i++) tag[i]=1;
	for(int i=1;i<=n;i++) printf("%d ",gao(i));
	return 0;
}


Measured memory_bytes: 18176
fun main(args: Array<String>) {
    val s = readLine() ?: return
    val count = s.groupBy { it }
        .map { entry ->
            val c = entry.key
            var count = 0
            var t = s.toCharArray().toMutableList()
            while (!t.all { a -> a == c }) {
                0.until(t.size - 1).forEach { i ->
                    if (t[i] == c || t[i + 1] == c) {
                        t[i] = c
                    }
                }
                count++
                t = t.dropLast(1).toMutableList()
            }
            count
        }.min()
    println(count.toString())
}

Measured memory_bytes: 37804
from sys import setrecursionlimit
#setrecursionlimit(10**5)
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納
        # par[x]=xの時そのノードは根　
        self.par = [i for i in range(n)]
        # rank
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        # 根の番号を返す(所属する集合を確認する)
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def check(self, x, y):
        # x,yが同じ集合に属するかどうか調べる
        return self.find(x) == self.find(y)


    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        # rankの小さいものを大きいほうにくっつける
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def count_group(self):
        return len({self.find(x) for x in range(n)})

n, m = map(int,input().split())
p = list(map(int,input().split()))

uf = UnionFind(n)
for i in range(m):
    x, y = map(int,input().split())
    uf.union(x - 1, y - 1)

#Xj = iなるjを考えたときにi,jが同じ集合に属している時pi = iにできる
cnt = 0
for i in range(n):
    if uf.check(i, p[i] - 1):cnt += 1
print(cnt)

Measured memory_bytes: 13812