akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N,M,L[100000],R[100000],i,ML,mR;
	cin>>N;
	cin>>M;
	cin>>L[0];
	ML=L[0];
	cin>>R[0];
	mR=R[0];
	for(i=1;i<M;i++)
	{
		cin>>L[i];
		if(ML<L[i])
			ML=L[i];
		cin>>R[i];
		if(mR>R[i])
			mR=R[i];
	}
	if(mR>=ML)
		cout<<mR-ML+1;
	else
		cout<<0;
	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<algorithm>
#include<climits>
using namespace std;

#define NONE INT_MAX
enum Status{CANUSE,USING,USED};

int n,m;
double cost[100][100];

struct Data{
  int id,ticket;
  double cost;
  Data(){};
  Data(int i,double c,int t){id=i;cost=c;ticket=t;};
};
bool operator<(Data a,Data b){return !(a.cost!=b.cost?a.cost<b.cost:(a.ticket!=b.ticket?a.ticket<b.ticket:a.id<b.id));}

int Dijkstra(int start,int goal){
  int res=0;
  bool used[100][3]={0};
  priority_queue<Data>q;
  q.push(Data(0, 0.0, CANUSE));
  while(!q.empty()){
    Data now=q.top();
    q.pop();
    used[now.id][now.ticket]=true;
    if(now.ticket!=USING && now.id==goal){
      res=now.cost;
      break;
    }
    for(int i=0;i<n;i++){
      if(cost[now.id][i]==NONE)continue;
      Data next=now;
      next.id=i;
      switch (now.ticket){
      case CANUSE:
        next.cost+=cost[now.id][next.id];
        if(!used[next.id][next.ticket])q.push(next);
        next.cost=now.cost;
        next.ticket=USING;
        if(!used[next.id][next.ticket])q.push(next);
        break;
      case USING:
        next.ticket=USED;
        if(!used[next.id][next.ticket])q.push(next);
        break;
      case USED:
        next.cost+=cost[now.id][next.id];
        if(!used[next.id][next.ticket])q.push(next);
        break;
      }
    }
  }
  return res;
}

int main()
{
  int a,b;
  double c;
  while(cin>>n>>m,n|m){
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cost[i][j]=NONE;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      a--;b--;
      cost[a][b] = cost[b][a] = c;
    }
    cout<<Dijkstra(0,n-1)<<endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){

  int i,n,num,min,max;
  long total;
  min=1000000; max=-1000000; total=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&num);
    if(num>max) max=num;
    if(num<min) min=num;
    total+=num;
  }
    printf("%d %d %ld\n",min,max,total);
  return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int H,N;
    cin >> H >> N;
    vector<ll> A(N);
    ll sum = 0;
    rep(i,N){
        cin >> A[i];
        sum += A[i];
    }
    if(sum>=H)cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(void){
  int A,B,C,K;
  int i,max = 0,num[3];
  scanf("%d %d %d %d",&A,&B,&C,&K);
  num[0] = A;	num[1] = B;
  num[2] = C;
  
  for(i = 0;i < 3; ++i){
    if(max < num[i])	max = num[i];
  }
  printf("%d\n",A + B + C - max + max * (int)pow(2,K));
}

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

int main(void){
  long long a, b, c, d, x, y, ans;
  cin >> a >> b >> c >> d;
  
  x=max(a, b);
  y=max(c, d);
  
  
  ans = max(x*y,min(a, b)*min(c, d));
  ans = max(ans,min(a, b)*max(c, d));
  ans = max(ans,max(a, b)*min(c, d));        
  
  cout << ans;
} 

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int MOD = 1e9 + 7;

void add(int &x, int y) {
  x += y;
  if (x < 0) x += MOD;
  if (x >= MOD) x -= MOD;
}
int mul(int a, int b) {
  return (a * 1LL * b) % MOD;
}
int bp(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      res = mul(res, a);
    a = mul(a, a); n >>= 1;
  }
  return res;
}

void solve() {
  int n; cin >> n;
  if (n == 1) {
    cout << 0; return;
  }
  int ans = bp(10, n);
  add(ans, -bp(9, n));
  add(ans, -bp(9, n));
  add(ans, bp(8, n));
  cout << ans;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


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

int n, m;
vector<vector<int>> g;
vector<bool> visited;
vector<int> ord;
vector<int> low;
vector<int> parent;
int timer = 0;
vector<pair<int,int>> bridge;

void dfs(int cur, int prev) {
    ord[cur] = low[cur] = timer++;
    visited[cur] = true;
    for (int next : g[cur]) {
        if (visited[next] == false) {
            parent[next] = cur;
            dfs(next, cur);
            low[cur] = min(low[cur], low[next]);
            if (ord[cur] < low[next]) {
                if (cur < next) bridge.push_back({cur,next});
                else bridge.push_back({next,cur});
            }
        } else if (next != prev) {
            low[cur] = min(low[cur], ord[next]);
        }
    }
}

void art_points() {
    set<int> ap;
    timer = 1;
    dfs(0, 1);
    int child = 0;
    rep(i, n) {
        if (i == 0) continue;
        if (parent[i] == 0) child++;
        else if (ord[parent[i]] <= low[i]) ap.insert(parent[i]);
    }
    if (child > 1) ap.insert(0);
}

int main() {
    cin >> n;
    cin >> m;
    g.resize(n);
    visited.resize(n, false);
    ord.resize(n);
    low.resize(n);
    parent.resize(n);
    rep(i, m) {
        int s, t ;
        cin >> s;
        cin >> t;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    dfs(0,1);
    sort(bridge.begin(), bridge.end());
    rep(i, bridge.size()) {
        printf("%d %d\n", bridge[i].first, bridge[i].second);
    }
}


Measured memory_bytes: 4692
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

class Main {

  public static void main(String[] args) {
    final FastScanner sc = new FastScanner();
    final PrintWriter writer = new PrintWriter(System.out);
    int n = sc.nextInt();
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = sc.nextInt();
    }
    int count = 0;
    int lookFor = 1;
    for (int i = 0; i < array.length; i++) {
      if (array[i] == lookFor) {
        lookFor++;
      } else {
        count++;
      }
    }
    if (count == array.length) {
      writer.println(-1);
    } else {
      writer.println(count);
    }
    writer.flush();
    writer.close();
  }

  // FastScanner --
  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public FastScanner() {
    }

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte())
        return buffer[ptr++];
      else
        return -1;
    }

    private boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr]))
        ptr++;
      return hasNextByte();
    }

    public String next() {
      if (!hasNext())
        throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext())
        throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
        throw new NumberFormatException();
      return (int) nl;
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

Measured memory_bytes: 22932
#include <iostream>
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	for (int a=1; a < 10; ++a)
	{
		for (int b=1; b < 10; ++b)
		{
			if (a*b == n)
			{	cout << "Yes";
			return 0;
			}
		}
	}
	cout << "No";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#include <cstdio>
#define ll long long int
#define endl '\n'
#define pb push_back
#define mp make_pair
// #define mod 998244353
#define rep(i,n) for(ll i=0;i<n;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define pll pair<ll, ll>
#define pint pair<int, int>
#define S second
#define F first
#define all(c) (c).begin(),(c).end()
using namespace std;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
const int N=1000001;
// vector<pair<ll, ll> > adj[N];
// bool vis[N];
ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } 
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
#define pi 3.14159265358979323846264338
using namespace std; 
ll max(ll a, ll b){ if(a>b)return a;return b;}
ll min(ll a, ll b){ if(a < b) return a;return b;}
ll inf = 100000000000000000;

void solve()
{
    string s;
    cin>>s;

    int p = 0;

    rep(i, s.size())
    {
        if(s[i] == 'p') p++;
    }

    cout<<(s.size()/2 - p)<<endl;

}
 
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        // cout<<"Case #"<<t<<":"<<' ';
        solve();
        // if(t<T)cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3956
N=int(input())
S=input()
all=S.count("R")*S.count("G")*S.count("B")

for i in range(N-1):
  for j in range(i,N):
    if 0<=2*i-j<N:
      if S[2*i-j]!=S[i]!=S[j]!=S[2*i-j]:
        all-=1
print(all)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
// #define test TEST 
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int num[maxn];

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n){
		for(int i=1;i<=n;i++){
			cin>>num[i];
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			if(i==num[i]){
				ans++;
				swap(num[i],num[i+1]);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    REP (i, N) cin >> P[i];
    int length = 1;
    set<int> st;
    REP (i, K) {
        st.insert(P[i]);
        if (i > 0) {
            if (P[i - 1] < P[i]) length++;
            else length = 1;
        }
    }
    int num_sort = (length == K), ans = N - K + 1;
    FOR (i, K, N) {
        if (P[i - 1] < P[i]) length = min(length + 1, K);
        else length = 1;
        st.insert(P[i]);
        if (length == K) {
            num_sort++;
        } else if (P[i - K] == *st.begin() && P[i] == *st.rbegin()) {
            ans--;
        }
        st.erase(P[i - K]);
    }
    if (num_sort) ans -= num_sort - 1;
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main() {
    int N;  cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) cin >> p[i];

    int ans = 0;
    int mini = 200009;
    for (int i = 0; i < N; ++i) {
        mini = min(mini, p[i]);
        if (mini >= p[i]) ++ans;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
import collections

n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr)
s=set()
cnt=collections.Counter(arr)

for i in range(n):
 if arr[i] in s:
   continue
 if cnt[arr[i]]>=2:
   s.add(arr[i])
 for j in range(2,10**6//arr[i]+1):
   s.add(arr[i]*j)
ans=0
for i in range(n):
 if arr[i] in s:
   continue
 ans+=1

print(ans)

Measured memory_bytes: 103244
import Data.Char

main = interact $ pureMain

pureMain :: String -> String
pureMain s = if f $ head $ lines $ s then "AC\n" else "WA\n"

f :: String -> Bool
f s = head s == 'A' && length (filter (== 'C') $ init $ drop 2 s) == 1 && length (filter isUpper s) == 2

Measured memory_bytes: 380
#include<bits/stdc++.h>
#include<stdio.h>
    
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007
    
using namespace std;
    
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;

    
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);
    
    string S;
    cin>>S;

    int dias_seguidos = 0;
    if('R' == S[0] && S[0] == S[1]) dias_seguidos++;
    if('R' == S[1] && S[1] == S[2]) dias_seguidos++;
    if(S[0] == 'R' || S[1] == 'R' || S[2] == 'R') dias_seguidos++;

    cout<<dias_seguidos<<endl;
    
    return 0;   
}

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

int main(){
	string S;
	cin >> S;
	
	if(S=="Sunny"){
		cout << "Cloudy" << endl;
	} else if(S=="Cloudy"){
		cout << "Rainy" << endl;
	} else {
		cout << "Sunny" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

struct red{
    int x;  
    int y;
    int flag;
};

struct blue{
    int x;  
    int y;
};

void quicksortr(struct red data[],int left,int right);
void quicksortb(struct blue data[],int left,int right);

int main()
{
	int n,i,j,k,ans=0;
	struct red rp[100]={0,0,0};
	struct blue bp[100]={0,0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&(rp[i].x),&(rp[i].y));
	}
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&(bp[i].x),&(bp[i].y));
	}
	quicksortr(rp,0,n-1);
	quicksortb(bp,0,n-1);
	for(i=0;i<n;i++)//blue
	{
		for(j=0;j<n;j++)//red
		{
			if(((bp[i].x>rp[j].x)&&(bp[i].y>rp[j].y))&&(rp[j].flag==0))
			{
				rp[j].flag=1;
				ans++;
				break;
			}
		}
	}
	printf("%d",ans);
}

void quicksortr(struct red data[],int left,int right)
{
	int i,j;
	struct red std,work;
	if(left<right)
	{
		i=left,j=right;
		std=data[(i+j)/2];//基準
		do
		{
			while(data[i].y > std.y)i++;
			while(data[j].y < std.y)j--;
			if(i<=j)
			{
				if(i<j)
				{
					work=data[i];
					data[i]=data[j];
					data[j]=work;
				}
				i++; j--;
			}
		}while(i<=j);
		if(left<j)quicksortr(data,left,j);
		if(i<right)quicksortr(data,i,right);
	}
}
void quicksortb(struct blue data[],int left,int right)
{
	int i,j;
	struct blue std,work;
	if(left<right)
	{
		i=left,j=right;
		std=data[(i+j)/2];//基準
		do
		{
			while(data[i].x < std.x)i++;
			while(data[j].x > std.x)j--;
			if(i<=j)
			{
				if(i<j)
				{
					work=data[i];
					data[i]=data[j];
					data[j]=work;
				}
				i++; j--;
			}
		}while(i<=j);
		if(left<j)quicksortb(data,left,j);
		if(i<right)quicksortb(data,i,right);
	}
}

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

using namespace std;

const int MOD=1e9+7;
const double PI=3.14159265359;

class SegmentTreeMax{
    public:
    int n;
    vector<long long> vect;
    SegmentTreeMax(int _n):n(_n){
        vect.resize(2*n);
        fill(vect.begin(), vect.end(), -MOD);
    }
    void modify(int p, long long value){
        for(vect[p+=n]=value; p>1; p>>=1){
            vect[p>>1]=max(vect[p],vect[p^1]);
        }
    }
    long long query(int l, int r){
        long long res=-MOD;
        for(l+=n, r+=n; l<r; l>>=1, r>>=1){
            if(l&1) res=max(res,vect[l++]);
            if(r&1) res=max(res,vect[--r]);
        }
        return res;
    }
    
};




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    long long c;
    cin>>n>>c;
    vector<long long> x(n), v(n), cs1(n), cs2(n);
    
    
    for(int i=0; i<n; i++){
        cin>>x[i]>>v[i];
    }
    
    SegmentTreeMax st1(n), st2(n);
    
    long long ans=0;
    //long long val1=0, val2=0, ans=0;
    for(int i=0; i<n; i++){
        if(!i){
            cs1[0]=v[0];
            cs2[0]=v[n-1];
        }
        else{
            cs1[i]=cs1[i-1]+v[i];
            cs2[i]=cs2[i-1]+v[n-1-i];
        }
        //cout<<cs1[i]<<endl;
        st1.modify(i,cs1[i]-2*x[i]);
        st2.modify(i, cs2[i]-2*(c-x[n-1-i]));
        ans=max(max(ans, cs1[i]-x[i]), cs2[i]-c+x[n-1-i]);
    }
    
    for(int i=0; i<n; i++){
        ans=max(ans, cs1[i]-x[i]+ st2.query(0,n-1-i));
        ans=max(ans, cs2[i]-c+x[n-1-i]+ st1.query(0,n-1-i));
    }
    
    cout<<ans;
    
    
    return 0;
    
    
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

map<ll,ll> memo;
ll dfs(ll h) {
    if(h == 1) return 1;
    if(memo.find(h) != memo.end()) return memo[h];
    return memo[h] = dfs(h/2)*2+1;
}

int main(void) {
    ll h;
    cin >> h;
    cout << dfs(h) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
 
const int N=505;
const int d=500;
 
int n,m,h,w,x,y,v;
int a[N][N];
 
int main(){
	int i,j;
	scanf("%d%d%d%d",&n,&m,&h,&w);
	x=n/h; y=m/w; v=-h*w;
	if (n%h==0&&m%w==0){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	for (i=1;i<=x;i++)
		for (j=1;j<=y;j++) a[i*h][j*w]=v*d+d-1;
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++)
			if (a[i][j]) printf("%d ",a[i][j]);
		else printf("%d ",d);
		printf("\n");
	}
	return 0;
} 

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for(auto& i: S) cin >> i;

  int ans = 0;
  for(auto j=0; j<N; ++j) {
    auto ok = true;
    for(auto y=0; y<N; ++y) for(auto x=0; x<N; ++x) if(S[0+y][(j+x)%N]!=S[0+x][(j+y)%N]) ok = false;
    if(ok) ans += N;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll res = 0;
    if(a > b) res = 0;
    else{
        res = max(0LL, (b-a)*(n-2)+1);
    }
    cout << res << ln;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        int C = scan.nextInt();
        int X = scan.nextInt();
        int answer = 0;
        for (int i = 0; i <= A; i++) {
            for (int j = 0; j <= B; j++) {
                int k = (X-(i*500 + j*100)) / 50;
                if (k < 0 || C < k) {
                    continue;
                }
                answer += 1;
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;


int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> cards(N + M);
	for (int i = 0; i < N; i++)
	{
		int temp = 0;
		cin >> temp;
		cards[i] = make_pair(temp, 1);
	}
	for (int i = N; i < M + N; i++)
	{
		int a, b;
		cin >> a >> b;
		cards[i] = make_pair(b, a);
	}
	sort(cards.begin(), cards.end());
	reverse(cards.begin(), cards.end());
	N = N;
	long long added = 0;
	long long sum = 0;
	int counter = 0;
	while (added != N)
	{
		//cards[looking]は、lookingが書かれたカードの枚数
		//card は カードに書かれた整数
		long long card = cards[counter].first;
		long long quantity = cards[counter].second;
		if (added + quantity < N)
		{
			if (quantity != 1)
			{
				added += quantity;
				sum += quantity * card;
			}
			else
			{
				added++;
				sum += card;
			}
		}
		else if (added + quantity == N)
		{
			added += quantity;
			sum += quantity * card;
			break;
		}
		else
		{
			long this_quantity = N - added;
			sum += this_quantity * card;
			break;
		}
		counter++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
l,r = map(int,input().split())
MOD = 2019
if r - l >=2019:
    print(0)
    exit()
l %=MOD
r %=MOD
if r <= l:
    r +=2019

ans = 2018
now = 0
for i in range(l,r+1):
    for j in range(i+1,r+1):
        now = (i*j)%MOD
        ans = min(ans,now)


print(ans)


Measured memory_bytes: 40428
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    MOD=10**9+7

    ans = pow(10,N,MOD)
    ans += pow(8,N,MOD)
    ans %= MOD
    ans -= 2 * pow(9,N,MOD)
    ans %= MOD

    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 61924
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"a,b,k=map(int,input().split());r=range(a,b+1);print(*sorted(set(r[:k])|set(r[-k:])))\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3280
import sys,fractions,math
A,B,C,D = map(int,input().split())
lcm = C * D // fractions.gcd(C,D)
def d_num(x):
    X = B//x
    Y = (A-1)//x
    return X - Y
print(B - A + 1 - (d_num(C)+d_num(D)-d_num(lcm)))


Measured memory_bytes: 5048
from heapq import heappush, heappop
from operator import itemgetter
import sys
input = sys.stdin.readline
#参考
#https://atcoder.jp/contests/abc128/submissions/15199101
class PseudoSet():
    def __init__(self):
        self.s = []  # set
        self.e = []  # erase candidate

    def insert(self, x):
        heappush(self.s, x)

    def erase(self, x):
        heappush(self.e, x)

    def get_min(self):
        while self.e and self.e[0] == self.s[0]:
            _ = heappop(self.s)
            _ = heappop(self.e)
        return self.s[0] if len(self.s) > 0 else None

def main():
    n,q=map(int, input().split())
    event = []
    end = []
    for i in range(n):
        s,t,x=map(int, input().split())
        event.append([s-x,1,x])
        event.append([t-x,0,x])

    for i in range(q):
        d = int(input())
        event.append([d,2,i])
    event.sort(key = itemgetter(0,1))
    res = [-1]*q
    ps = PseudoSet()
    for time,type,x in event:
        if(type==1):
            ps.insert(x)
        elif(type==0):
            ps.erase(x)
        else:
            k = ps.get_min()
            if k is not None:
                res[x]=k
    print(*res,sep="\n")

if __name__ == '__main__':
    main()


Measured memory_bytes: 235120
#include <iostream>
using namespace std;
int main(void){
    int c=0,b=0;
    string a;
    cin>>a;
    for(int i=0;i<a.size();i++){
        if(i%2==0){
            if(a[i]!='0'){
                b++;
            }
            else if(a[i]!='1'){
                c++;
            }}
            
            if(i%2==1){
            if(a[i]!='0'){
                c++;
            }
            else if(a[i]!='1'){
                b++;
            }    
        }
    }
    if(b>c){
        cout<<c<<endl;
    }
    else {
        cout<<b<<endl;
        
    }
 
}

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

int main(){
    string s;
    ll k;
    cin >> s >> k;
    for(int i=0;i<min(k,(ll)s.size());i++){
        if(s[i]>='2'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000

int n;
int a[2][MAXN];
int b[2][MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int k=0; k<2; k++)
		for (int i=0; i<n; i++)
			scanf("%d", &a[k][i]);
	return 1;
}

void init() {
}

int cnt(int *a, int n, int x, int s, int t) {
	int is = lower_bound(a, a+n, s-x)-a;
	int it = lower_bound(a, a+n, t-x)-a;
	return it-is;
}

long solve() {
	long ans = 0;
	for (int bit=0; bit<29; bit++) {
		int t = 1<<bit;
		for (int k=0; k<2; k++) {
			for (int i=0; i<n; i++)
				b[k][i] = a[k][i] % (2*t);
			sort(b[k], b[k]+n);
		}
		int r = 0;
		for (int i=0; i<n; i++) {
			r += cnt(b[0], n, b[1][i], 1*t, 2*t);
			r += cnt(b[0], n, b[1][i], 3*t, 4*t);
		}
		if (r%2) ans += t;
	}
	return ans;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 3328
#include <queue>
#include <iostream>
#include<cstring>
#include<stdio.h>
#define maxn 200050
#define MAX 1e18
using namespace std;
long long  a,b,c,k;
long long ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b>>c>>k;
    if(k&1)
        ans=b-a;
    else
    ans=a-b;
    if(ans>MAX||ans<-MAX)
        cout<<"Unfair"<<endl;
    else
        cout<<ans<<endl;


    return 0;
}

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

L = [float("inf") for i in range(N)]
L[0] = 0
L[1] = abs(h[0] - h[1])

for i in range(2, N):
    x = L[i - 2] + abs(h[i] - h[i - 2])
    y = L[i - 1] + abs(h[i] - h[i - 1])
    L[i] = min(x, y)

print(L[N - 1])

Measured memory_bytes: 13980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

int main()
{
    long long int n, m;
    long long int ans = 0;

    cin >> n >> m;

    if (m >= n*2) {
        ans += n;
        m -= n*2;
        n = 0;
    }
    else {
        ans += m/2;
        m = 0;
    }


    cout << ans+m/4 << endl;
}


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

void print( const vector<int>& a ) {
	size_t n = a.size();

	for( size_t i = 0; i < n; ++i ) {
		cout << a.at( i );

		if( i < n-1 ) { cout << ' '; }
	}

	cout << endl;
}

int selectionSort( vector<int>& A, int N ) {
	int count = 0;

	for( int i = 0; i < N; ++i ) {
		int minj = i;

		for( int j = i; j < N; ++j ) {
			if( A.at( j ) < A.at( minj ) ) {
				minj = j;
			}
		}

		if( i != minj ) {
			swap( A.at( i ), A.at( minj ) );
			count += 1;
		}
	}

	return count;
}

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

	vector<int> a( N );
	for( auto& v: a ) { cin >> v; }

	int count = selectionSort( a, N );
	print( a );

	cout << count << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    for(int i = 0; i < N; i++){
        cin >> m[i];
    }
    
    sort(m.begin(), m.end());
    
    int ans = 0;
    
    X -= accumulate(m.begin(), m.end(), 0);
    ans += N;
    
    while(X >= m[0]){
        X -= m[0];
        ans++;
    }
    
    cout << ans << endl;
}

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    
    string n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n.size(); i++)
        sum += n[i] - '0';
    if (sum % 9 == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    int x;
    cin >> x;
    if(x==0)cout << 1;
    if(x==1)cout << 0;
    return 0;
}

Measured memory_bytes: 3644
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
int N, M, K, H, W, L, R;


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

	cin >> N >> M;
	if (N == M)cout << N * 2 << endl;
	else cout << max(N, M) * 2 - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    x[i]-=i+1
x.sort()
if n%2==0:
    b = (x[n//2-1]+x[n//2])//2
else:
    b = x[(n-1)//2]
ans=0
for i in range(n):
    ans+=abs(x[i]-b)
print(ans)

Measured memory_bytes: 26836
def m():
    S = input()
    a, b, c, d = map(int, S)
    ope = [1, -1]
    sig_ope = ['+', '-']
    for w in range(2):
        for x in range(2):
            for y in range(2):
                ans = a + (b * ope[w]) + (c * ope[x]) + (d * ope[y])
                if ans == 7:
                    return "{0}{1}{2}{3}{4}{5}{6}=7".format(
                        a, sig_ope[w], b, sig_ope[x], c, sig_ope[y], d
                    )


print(m())


Measured memory_bytes: 3064
%:pragma GCC optimize("Ofast")
%:pragma GCC optimize("inline")
#include<bits/stdc++.h>
#define int long long
#define rint register int
using namespace std;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
namespace {
  const int mo = 1e9 + 7;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
  inline int pw(int a, int k) {
    int ans = 1;
    for (; k; k >>= 1, a = mul(a, a))
      if (k & 1) ans = mul(ans, a);
    return ans;
  }
  inline int inv(int n) {
    return pw(n, mo - 2);
  }
}

namespace binom {
  const int N = 6666;
  int fac[N], ifac[N];
  inline void init(void) {
    int m = 5000;
    fac[0] = 1;
    for (int i = 1; i <= m; i ++)
      fac[i] = mul(fac[i - 1], i);
    ifac[m] = inv(fac[m]);
    for (int i = m - 1; i >= 0; i --)
      ifac[i] = mul(ifac[i + 1], i + 1);
  }

  inline int C(int n, int m) {
    if (n < 0) return 0;
    else if (m == n || m == 0) return 1;
    else return mul(fac[n], mul(ifac[m], ifac[n - m]));
  }
}
using namespace binom;

#define pb push_back

int sz[N], dp[N];
vector <int> G[N];
int n, rt;
inline void dfs(int u, int fat) {
  sz[u] = 1;
  for (auto &v : G[u])
    if (v != fat) {
      dfs(v, u);
      dp[u] = max(dp[u], sz[v]);
      sz[u] += sz[v];
    }
  dp[u] = max(dp[u], n - sz[u]);
  if (!rt || dp[rt] > dp[u])
    rt = u;
}

inline void U(int &x, int y) {
  x = add(x, y);
}

inline vector <int> uni(vector <int> f, int k) {
  vector <int> g((int) f.size() + k);
  for (int i = 0; i < (int) f.size(); i ++)
    for (int up = 0; up <= k; up ++)
      U(g[i + up], mul(f[i], mul(fac[up], mul(C(k, up), C(k, up)))));
  return g;
}

inline void doit(int u) {
  // cout << "u = " << u << "\n";
  vector <int> son;
  for (auto &v : G[u]) {
    dfs(v, u);
    son.pb(sz[v]);
  }
  vector <int> dp(1);
  dp[0] = 1;
  for (auto &v : son) {
    dp = uni(dp, v);
    // for (auto i : dp)
    //   cout << i << " ";
    // cout << "\n";
  }
  int ans = 0;
  for (int i = 0; i < (int) dp.size(); i ++) {
    int t = mul(dp[i], fac[n - i]);
    if (i & 1) ans = sub(ans, t);
    else ans = add(ans, t);
  }
  cout << ans << "\n";
}

main(void) {
  init();
  read(n);
  for (int i = 2; i <= n; i ++) {
    int x, y; read(x); read(y);
    G[x].pb(y); G[y].pb(x);
  }
  dfs(1, 0);
  int cnt = 0;
  for (int i = 1; i <= n; i ++)
    if (dp[i] == dp[rt])
      ++ cnt;
  if (cnt == 2) {
    cout << mul(fac[n / 2], fac[n / 2]) << "\n";
  } else {
    doit(rt);
  }
}


Measured memory_bytes: 1024
// 'By Anki'

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define wr(i) cout<<#i<<" = "<<i<<",  ";
#define wre(i) cout<<#i<<"  =  "<<i<<endl;
#define all(v) v.begin(),v.end()
typedef long long ll;
#define lim 1000000007LL
// #define lim 10LL
#define M 1000006
 
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
 
ll fact(ll n)
{
    ll ans=1LL;
    while(n)
    ans*=(n--);
    return ans;

}

ll func(ll val,ll n,ll a,ll b,ll c,vector<ll>v){
    ll ans=0LL;
    if(a+b<=c){
        for(auto x:v){
            if(x>val)ans+=(x-val)*b;
            else ans+=(val-x)*a;
        }
    }
    else
    {
        int i=0,j=n-1;
        while(i<j){
            if(v[i]>val)break;
            if(v[j]<val)break;
            ll tmp=min(val-v[i],v[j]-val);
            v[j]-=tmp;
            v[i]+=tmp;
            ans+=tmp*c;
            if(v[j]==val)j--;
            if(v[i]==val)i++;
        }
        if(v[i]>val){
            for(;i<=j;i++)ans+=(v[i]-val)*b;
        }
        else if(v[j]<val){
            for(;j>=i;j--)ans+=(val-v[j])*a;
        }
    }
    // wr(ans);
    return ans;
}

ll ternary(ll l,ll r, vector<ll>v,ll n, ll a, ll b,ll c){
    while(r-l>2){
        ll m1=l+(r-l)/3;
        ll m2=r-(r-l)/3;
        // wr(m1)wre(m2)
        if(func(m1,n,a,b,c,v)<func(m2,n,a,b,c,v))r=m2;
        else l=m1;
    }
    ll ans=func(l,n,a,b,c,v);
    for(int i=l;i<=r;i++)ans=min(ans,func(i,n,a,b,c,v));
    return ans;
}

int main()
{
fast
ll t=1;
// cin>>t;
while(t--)
{
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)cout<<s<<"\n";
    else
    {
        for(int i=0;i<k;i++)cout<<s[i];
        cout<<"...\n";
    }
    
    
}
} 

Measured memory_bytes: 3540
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,a,b,c,dp1[100000],dp2[100000],dp3[100000];
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a >> b >> c;
    dp1[i]=max(dp2[i-1],dp3[i-1])+a;
    dp2[i]=max(dp1[i-1],dp3[i-1])+b;
    dp3[i]=max(dp1[i-1],dp2[i-1])+c;
  }
  cout << max({dp1[n-1],dp2[n-1],dp3[n-1]}) << endl;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(void) {
    long w, h, x, y;
    cin >> w >> h;
    cin >> x >> y;
    printf("%.6lf %d\n", (double)w * (double)h / 2, w == 2 * x && h == 2 * y);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int N;
string s,t;
ll dp[202][202];

int main(){
  cin>>N;
  rep(i,N){
    char c;
    cin>>c;
    s+=c;
  }
  rep(i,N){
    if(s[i]=='-')continue;
    t+=s[i];
  }
  s=t;
  N=s.size();
  dp[0][0]=1;
  rep(i,N){
    rep(j,N){
      if(s[i]=='U'){
        (dp[i+1][j]+=dp[i][j]*j%mod)%=mod;
        (dp[i+1][j+1]+=dp[i][j])%=mod;
      }else if(s[i]=='D'){
        if(j>0)(dp[i+1][j-1]+=dp[i][j]*j*j%mod)%=mod;
        (dp[i+1][j]+=dp[i][j]*j)%=mod;
      }
    }
  }
  cout<<dp[N][0]<<endl;
  return 0;
}



Measured memory_bytes: 3476
#include<stdio.h>
 #include<vector>
 #include<algorithm>
using namespace std;
 typedef long long ll;
 int main()
 {
 int a, b, x, y;
 scanf("%d%d%d%d", &a, &b, &x, &y);
 printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
 }

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = Integer.parseInt(sc.next());
    int[] height = new int[number];
    int[] cost = new int[number];
    for(int i = 0; i < number; i++) {
      cost[i] = Integer.MAX_VALUE;
      height[i] = Integer.parseInt(sc.next());
    }
    cost[0] = 0;
    cost[1] = Math.abs(height[1] - height[0]);
    for(int i = 2; i < number; i++) {
      cost[i] = Math.min(cost[i-2] + Math.abs(height[i] - height[i-2]), cost[i-1] + Math.abs(height[i] - height[i-1]));
    }
    System.out.println(cost[number-1]);
  }
}


Measured memory_bytes: 48116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define pi pair<ll,ll>
#define ss second
#define ll long long
#define MAXN 100005
using namespace std;
using namespace __gnu_pbds;  

ll n,cnt;
string s;
vector<ll> v[4]	;

void check(ll p, ll q, ll r)
{
	ll t,y;
	// cout<<p+r<<endl;
	if((s[p]=='R' && s[q]=='G') || (s[p]=='G' && s[q]=='R'))
	{
		t=lower_bound(v[2].begin(),v[2].end(),p+r)-v[2].begin();
		if(t<v[2].size() && v[2][t]==p+r) cnt--;
		y=upper_bound(v[2].begin(),v[2].end(),p)-v[2].begin();
		cnt+=(v[2].size()-y);
	}
	else if((s[p]=='R' && s[q]=='B') || (s[p]=='B' && s[q]=='R'))
	{
		t=lower_bound(v[1].begin(),v[1].end(),p+r)-v[1].begin();
		if(t<v[1].size() && v[1][t]==p+r) cnt--;
		y=upper_bound(v[1].begin(),v[1].end(),p)-v[1].begin();
		cnt+=(v[1].size()-y);
	}
	else if((s[p]=='B' && s[q]=='G') || (s[p]=='G' && s[q]=='B'))
	{
		t=lower_bound(v[0].begin(),v[0].end(),p+r)-v[0].begin();
		if(t<v[0].size() && v[0][t]==p+r) cnt--;
		y=upper_bound(v[0].begin(),v[0].end(),p)-v[0].begin();
		cnt+=(v[0].size()-y);
	}
}

void solve()
{
	cin>>n;
	cin>>s;
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='R') v[0].pb(i);
		else if(s[i]=='G') v[1].pb(i);
		else v[2].pb(i);
	}
	for(ll i=0;i<n-1;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			if(s[i]!=s[j])
			{
				check(j,i,j-i);
			}
		}
	}
	cout<<cnt<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	solve();
}


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

#define REP(w, n) for(int w=0;w<int(n);++w)

int main() {
    int n; cin >> n;
    double odd = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 != 0) odd += 1;
    }

    cout << odd / n << endl;
}

Measured memory_bytes: 256
n=int(input())
a = list(map(int, input().split()))
b=[0]*60
ans=0
count=0
mod=10**9+7

for i in range(60):
    for j in range(n):
        if a[j]>>i&1==1:
            count+=1

    b[i]=count
    count=0

for i in range(60):
    ans+=2**i*(b[i]*(n-b[i]))
    ans%=mod


print(ans)

Measured memory_bytes: 122808
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


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

  sort(s.begin(), s.end());

  if (s == "abc") {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int K;
    cin >> K;
    
    set<int> A;
    int a = 0;
    int ans = 0;
    
    while (1) {
        ans++;
        a *= 10;
        a += 7;
        a %= K;
        if(a == 0) break;
        
        if(A.count(a)) {
            ans = -1;
            break;
        }
        A.insert(a);
    }
    
    cout << ans << endl;
    
    

    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int cnt  = 0;
	for(int i=0;i<s.size();i++) {
		if(i > s.size()-1-i)
		if(s[i] != s[s.size()-1-i]) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

int Prime_factorize(ll n) {
    int cnt=0;
    for (ll i=2; i*i<=n; i++) {
        int th = 1;
        int now = 0;
        while (n%i == 0) {
            now++;
            if (th == now) {
                cnt++;
                now = 0;
                th++;
            }
            n /= i;
        }
        if (i != 2) i++;
    }
    if(n != 1) cnt++;
    return cnt;
}

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

    int cnt = Prime_factorize(n);

    cout << cnt << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t ;
    cin >> s >> t ;
    int n = SZ(s) ;
    if(s==t.substr(0,n)){
        yes() ;
    }
    else{
        no() ;
    }
    

    return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
      
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int D=sc.nextInt();
		int E=sc.nextInt();
		int K=sc.nextInt();
		
		System.out.println(E - A <= K ? "Yay!":":(") ;
	
	}
}

Measured memory_bytes: 27112
#include<cmath>
#include<stdio.h>
//using namespace std;

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



Measured memory_bytes: 2668