akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0;i<(n);++i)
#define foor(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,n) for(int i=(n);i--;)
#define roof(i,b,a) for(int i=(b);i>=(a);--i)
#define all(x) x.begin(),x.end()
#define Sort(x) sort(all(x))
#define PQ priority_queue
#define print(x) cout<<(x)<<"\n"
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef pair<ll,int>pli;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
typedef vector<pli>vpli;
typedef map<int,int>mii;
typedef map<ll,ll>mll;
template<typename T>vector<T>&operator<<(vector<T>&v,const T t){v.push_back(t);return v;}
template<typename T>multiset<T>&operator<<(multiset<T>&m,const T t){m.insert(t);return m;}
template<typename T>set<T>&operator<<(set<T>&s,const T t){s.insert(t);return s;}
template<typename T,typename U>PQ<T,vector<T>,U>&operator<<(PQ<T,vector<T>,U>&q,const T t){q.push(t);return q;}
template<typename T,typename U>istream&operator>>(istream&s,pair<T,U>&p){return s>>p.first>>p.second;}
template<typename T>istream&operator>>(istream&s,vector<T>&v){fr(i,v.size()){s>>v[i];}return s;}
template<typename T,typename U>ostream&operator<<(ostream&s,const pair<T,U>p){return s<<p.first<<" "<<p.second;}
template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto a:v){s<<a<<endl;}return s;}
vpli dijkstra(const int N,const vpli E[],const int s,const ll inf){vpli d;fr(i,N)d<<pli{inf,i};d[s].first=0;PQ<pli,vpli,greater<pli>>pq;pq<<(d[s]=pli{0,s});while(pq.size()){pli a=pq.top();pq.pop();int v=a.second;if(d[v].first>=a.first){for(pli e:E[v]){if(d[v].first+e.first<d[e.second].first){d[e.second]=pli{d[v].first+e.first,v};pq<<pli{d[v].first+e.first,e.second};}}}}return d;}
ll gcd(ll a,ll b){return a?gcd(b%a,a):b;}

char S[601][601];
ll yoko[601][601],tate[601][601];
const ll M=1e9+7;
main(){cin.tie(0);ios::sync_with_stdio(false);
	int N;
	scanf("%d\n",&N);
	fr(y,N){
		fr(x,N){
			S[y+N][x+N]=S[y+N][x]=S[y][x+N]=S[y][x]=getchar();
		}
		getchar();
	}
	fr(y,N*2){
		ll h=0;
		fr(x,N*2){
			h=yoko[y][x]=(h*123457%M+S[y][x])%M;
		}
	}
	fr(x,N*2){
		ll h=0;
		fr(y,N*2){
			h=tate[y][x]=(h*123457%M+S[y][x])%M;
		}
	}
	ll p=1;
	fr(i,N){p=p*123457%M;}
	ll z=N*N;
	fr(y,N){
		fr(x,N){
			fr(i,N){
				if(
					(yoko[y+i][x+N]-yoko[y+i][x]*p%M+M)%M
					!=
					(tate[y+N][x+i]-tate[y][x+i]*p%M+M)%M
				){
					--z;
					break;
				}
			}
		}
	}
	print(z);
}


Measured memory_bytes: 6272
function main(p){
  'use strict'
  const nums = p.split('\n')[0].split(' ').map((n) => parseInt(n, 10))
  console.log(nums[0] > 9 || nums[1] > 9 ? -1 : nums[0]*nums[1])
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007


def main():

    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    if N == 2:
        d = abs(A[0]-A[1])
        print(min(d, K-d))
    else:
        max_d = K - A[N-1] + A[0]
        for i in range(N - 1):
            max_d = max(max_d, abs(A[i] - A[i+1]))
        print(K - max_d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25452
#include<stdio.h>
#define MAXN 100006
int memo[MAXN], flag[MAXN];

int main() {
	int m, n, x, y, ans = 0;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) memo[i] = 1, flag[i] = 0;
	flag[1] = 1;
	while (m--) {
		scanf("%d%d", &x, &y);
		if (flag[x] == 1) flag[y] = 1;
		memo[x]--, memo[y]++;
		if (memo[x] == 0) flag[x] = 0;
	}
	for (int i = 1; i <= n; i++) if (flag[i] == 1) ans++;
	printf("%d\n", ans);
	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

struct BIT2d{
	int ymx, xmx;
	vector<vector<int>> dt;
	BIT2d(int my, int mx): ymx(my), xmx(mx), dt(my+5,(vector<int>(mx+5))){};
	void add(int y, int x, int v){
		for(int i = y+1; i <= ymx+1; i += i & -i)
			for(int j = x+1; j <= xmx+1; j += j & -j) dt[i][j] += v;
	}
	int qsum(int y, int x){
		int res = 0;
		for(int i = y+1; i > 0; i -= i & -i)
			for(int j = x+1; j > 0; j -= j & -j) res += dt[i][j];
		return res;
	}
	int qsum(int y0, int x0, int y1, int x1){
		return qsum(y1, x1) - qsum(y0-1, x1) - qsum(y1, x0-1) + qsum(y0-1, x0-1);
	}
};

int main()
{
	
	int n, m, q;
	cin >>n >>m >>q;
	
	BIT2d bta(n+2, n+2);
	rep(i, m){
		int l, r; cin >>l >>r;
		bta.add(l, r, 1);
	}
	rep(i, q){
		int a, b; cin >>a >>b;
		cout << bta.qsum(a, a, b, b) <<"\n";
	}
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int N, K;
    while(cin >> N >> K){
        string S; cin >> S;
        vector<string> vs;
        string T = S;
        reverse(T.begin(), T.end());
        S += T;
        char best = 'z' + 1;
        int len = 0;
        int rep = 0;
        for(int i=0;i<N;i++){
            int curL = 0;
            for(int j=i;j<S.size();j++){
                if(S[i] == S[j]) ++curL;
                else break;
            }
            if(S[i] < best || (S[i] == best && curL > len)){
                vs.clear();
                best = S[i];
                len = curL;
                rep = len;
                for(int j=0;j<K-1 && rep < N;j++) rep *= 2;
                rep = min(N, rep);
            }
            if(S[i] == best && len == curL){
                vs.emplace_back(S.substr(i+len, N-rep));
            }
        }
        sort(vs.begin(), vs.end());
        cout << (string(rep, best) + vs[0]) << endl;
    }
}

Measured memory_bytes: 5120
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
struct node{int to,nxt;}sq[400200];
int all=0,head[200100],ans[200100];
int n,m1,m2,cnt=0;
pii col[200100];
bool vis[200100];
map<pii,int> mp;

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void add(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;
}

void dfs(int u,int op)
{
	if (op==0) col[u].fir=cnt;else col[u].sec=cnt;
	vis[u]=1;
	go(u,i)
	{
		int v=sq[i].to;
		if (!vis[v]) dfs(v,op);
	}
}

void init(int m,int op)
{
	all=cnt=0;
	memset(head,0,sizeof(head));
	memset(vis,0,sizeof(vis));
	rep(i,1,m)
	{
		int u=read(),v=read();
		add(u,v);add(v,u);
	}
	rep(i,1,n)
		if (!vis[i]) {cnt++;dfs(i,op);}
}

int main()
{
	n=read();m1=read();m2=read();
	init(m1,0);init(m2,1);
	rep(i,1,n) mp[col[i]]++;
	rep(i,1,n) ans[i]=mp[col[i]];
	rep(i,1,n) printf("%d ",ans[i]);
	return 0;
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

VL seq(int&,string&);
VL rep(int&,string&);
VL op(int&,string&);
LL number(int&,string&);

int N;
VL comp(const VL& f1, const VL& f2){
  VL res(N*N);
  REP(i,N*N) res[i] = f2[f1[i]];
  return res;
}

VL seq(int& i, string& s){
  VL res(N*N);
  REP(i,N*N) res[i] = i;

  while(i < SZ(s)){
	VL tmp;
	if(s[i] == '('){
	  tmp = rep(i, s);
	}
	else if(string("UDLR").find(s[i]) != string::npos){
	  tmp = op(i, s);
	}
	else{
	  break;
	}
	res = comp(res, tmp);
  }
  return res;
}
VL rep(int& i, string& s){
  ++i;
  VL tmp = seq(i, s);
  ++i;
  LL n = number(i, s);

  VL res(N*N);
  REP(i,N*N) res[i] = i;
  while(n>0){
	if(n&1)
	  res = comp(res, tmp);
	tmp = comp(tmp, tmp);
	n >>= 1;
  }

  return res;
}
VL op(int& i, string& s){
  char c = s[i];
  ++i;
  LL n = number(i, s);
  --n;

  VL res(N*N);
  REP(i,N*N) res[i] = i;
  switch(c){
  case 'R':
	REP(i,N-1) res[n*N+i] = n*N+i+1;
	res[n*N+N-1] = n*N;
	break;
  case 'L':
	REP(i,N-1) res[n*N+i+1] = n*N+i;
	res[n*N] = n*N + N-1;
	break;
  case 'U':
	REP(i,N-1) res[(i+1)*N+n] = i*N+n;
	res[n] = (N-1)*N + n;
	break;
  case 'D':
	REP(i,N-1) res[i*N+n] = (i+1)*N+n;
	res[(N-1)*N+n] = n;
	break;
  }

  return res;
}
LL number(int& i, string& s){
  LL n = 0;
  while(i < SZ(s) && '0' <= s[i] && s[i] <= '9'){
	n = n*10 + s[i] - '0';
	++i;
  }
  return n;
}

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

  int L;
  cin >> N >> L;
  string S;
  cin >> S;
  int i = 0;
  VL rot = seq(i, S);
  VVI ans(N, VI(N));
  REP(i,N*N){
	int tx = rot[i] % N, ty = rot[i] / N;
	ans[ty][tx] = i+1;
  }

  REP(y,N){
	REP(x,N) cout << (x?" ":"") << ans[y][x];
	cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 29364
#include <bits/stdc++.h>
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;

int main() {
	int t,n,i,j,k,l,a,b,c,d,flag=0;
	int a1[100001],a2[100001];
	char s[100001];
	vector<int> v;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	    scanf("%d",&a1[i]);
	    scanf("%d",&a2[i]);
	}
	for(i=0;i<n;i++)
	{
	    if(a1[i]==a2[i])
	    v.push_back(1);
	    else
	    v.push_back(0);
	}
	for(j=0;j<v.size()-2;j++)
	{
	    if(v[j]==1&&v[j+1]==1&&v[j+2]==1)
	    flag=1;
	}
	if(flag==1)
	printf("Yes");
	else
	printf("No");
	return 0;
}


Measured memory_bytes: 3796
str = gets.split
N,A,B = str[0].to_i, str[1].to_i, str[2].to_i
dif = (A-B).abs

if dif % 2 == 0
    answer = dif/2
    puts answer
else
    a1 = (A+B-1)/2
    a2 = (2*N-A-B+1)/2
    answer = a1 < a2 ? a1 : a2
    puts answer
end

Measured memory_bytes: 1788
//#define _GLIBCXX_DEBUG
#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 NP next_permutation
#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
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;

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 decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a*c %mod;}a=a*a %mod;b>>=1;}return c;}
vi calc(ll x){vi res; while(x>0){res.eb(x%10);x/=10;}reverse(all(res)); return res;}

void solve() {
  ll k,s;
  cin>>k>>s;
  vi a;
  rep(x,k+1)rep(y,k+1) a.eb(x+y);
  sort(all(a));
  ll ans=0;
  rep(z,k+1) ans+=ub(a,s-z)-lb(a,s-z);
  out(ans);
}

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


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  string s;
  int r=0;
  cin>>s;
  for(int i=0;i<sz(s);i++)
  {
    r+=(s[i]-'0')%9;
  }
  if(r%9==0)
    yes;
  else
    no;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3740
// package Contest#176;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int x = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());

        // out.println(n / x);
        int time = (int) Math.ceil(1.0 * n / x);
        out.println(time * t);
        out.close();
    }
}

Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
 
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
using namespace std;

ll n,m;


int main() {
    cin >> n >> m;
    ll ans = 0;
    if(m >= n*2){
        ans += n;
        m -= n*2;
        n = 0;
    }
    else{
        ans += m/2;
        n -= ans;
        m -= ans*2;
    }
    
    ans += m/4;
    
    cout << ans << endl;
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0;i<n;i++) cin >> v[i];
    sort(v.begin(), v.end());
    double ans=v[0];
    for(int i=1;i<v.size();i++){
        ans = (v[i]+ans)/2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VI d[SIZE];
int main(){
    priority_queue<int>AA;
    int N,M;
    R(N,M);
    FOR(i,1,N){
        int x,y;
        R(x,y);
        d[x].PB(y);
    }
    LL an=0;
    FOR(i,1,M){
        for(int x:d[i])AA.push(x);
        if(!AA.empty()){
            an+=AA.top();
            AA.pop();
        }
    }
    W(an);
    return 0;
}


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

using namespace std;

int main()
{
    long long int a, b, k;

    cin >> a >> b >> k;

    if (a > k) {
        a -= k;
        k = 0;
    }
    else {
        k -= a;
        a = 0;
    }

    if (b > k) {
        b -= k;
        k = 0;
    }
    else {
        k -= b;
        b = 0;
    }

    cout << a << " " << b << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i]; 
    sort(a.begin(),a.end());
    vector<pair<int,int>> b;
    int cnt=1;
    rep(i,n-1) {
        if (a[i+1]!=a[i]) {
            b.push_back(make_pair(a[i],cnt));
            cnt=1;
        } else {
            ++cnt;
        }
    }
    b.push_back(make_pair(a[n-1],cnt)); 
    int ans=0;
    rep(i,b.size()) {
        if (b[i].second>=b[i].first) ans+=b[i].second-b[i].first;
        else ans+=b[i].second;
    }
    cout << ans << endl;

    return 0;
}

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

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

int n, p;
vector <ill> A, B;
ll res;

int main()
{
	scanf("%d %d", &n, &p);
	for (int i = 0; i < n; i++) {
		int x, c; scanf("%d %d", &x, &c);
		if (x < p) A.push_back(ill(x, c));
		else B.push_back(ill(x, c));
	}
	reverse(A.begin(), A.end());
	while (A.size() > 0 && B.size() > 0) {
		res += B.back().first - A.back().first;
		if (A.back().second >= B.back().second)
			while (!B.empty() && A.back().second >= B.back().second) {
				A.back().second += B.back().second;
				B.pop_back();
			}
		else while (!A.empty() && A.back().second < B.back().second) {
			B.back().second += A.back().second;
			A.pop_back();
		}
	}
	if (A.empty()) res += B.back().first - p;
	else res += p - A.back().first;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2804
fun main(args: Array<String>){
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }

    val count = mutableMapOf<Int, Int>()
    A.forEach { a ->
        count[a] = (count[a] ?: 0) + 1
    }

    var ans = 0L
    for((key, c) in count){
        if(key < c){
            ans += (c - key)
        }
        if(key > c){
            ans += c
        }
    }
    println(ans)
}

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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,Q;

struct UF{
    vector<int>par,sz;
    void init(int n){
        par.resize(n);
        sz.resize(n);
        for(int i=0;i<n;i++){
            par[i]=i;
            sz[i]=1;
        }
    }
    int find(int x){
        return x==par[x]?x:par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return;
        sz[x]+=sz[y];
        par[y]=x;
    }
    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};

signed main() {
    cin>>N>>Q;
    UF uf;
    uf.init(N+1);
    int a,b,c;
    rep(i,0,Q){
        cin>>a>>b>>c;
        if(a)cout<<uf.same(b,c)<<endl;
        else uf.unite(b,c);
    }



    return 0;
}



Measured memory_bytes: 3252
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, C: int, K: int):
    a = sorted([A, B, C])
    print(a[0]+a[1]+a[2]*(2**K))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
const int MAX_V=210;
ll d[MAX_V][MAX_V];
int V;
void worshall_floyd(){
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
        }
    }
}



int main(){
   int n,m,r;
   cin>>n>>m>>r;
   V=n;
   VI R(r);
   rep(i,r){cin>>R[i];R[i]--;}
   sort(ALL(R));
   rep(i,n)rep(j,n)d[i][j]=INFTY;
   rep(i,n)d[i][i]=0;
   rep(i,m){
      ll a,b,c;cin>>a>>b>>c;
      a--;b--;
      d[a][b]=c;
      d[b][a]=c;
   }
   worshall_floyd();
    ll ans=INFTY;
    do{
      ll sum=0;
      rep(i,r-1)sum+=d[R[i]][R[i+1]];
      chmin(ans,sum);
    }while(std::next_permutation(ALL(R)));
    cout<<ans<<endl;
}

Measured memory_bytes: 3916
#include "bits/stdc++.h"

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//

unordered_set<ll> get_p(ll n) {
    ll s = sqrt(n) + 1;
    ll t = n;
    unordered_set<ll> res;
    res.insert(1);
    for (ll i = 2; i * i <= t; ++i) {
        while (t % i == 0) {
            res.insert(i);
            t /= i;
        }
    }
    if (t != 1) {
        res.insert(t);
    }
    return res;
}

int main() {
    IOS

    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    cout << get_p(g).size();

    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
	int n, m, a;
	while(scanf("%d%d", &n, &m), n){
		vector<pair<int,int> > v(m);
		for(int i = 0; i < m; ++i){
			v[i].second = i + 1;
		}
		for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j){
			scanf("%d", &a);
			v[j].first -= a;
		}
		sort(v.begin(), v.end());
		for(int i = 0; i < m; ++i){
			printf("%d%c", v[i].second, i + 1 == m ? '\n' : ' ');
		}
	}
}

Measured memory_bytes: 1032
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
 
int n,a[1 << 17],c;
set<int>s;
 
int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i];
		if(a[i] < 3200)
		{
			if(1 <= a[i] && a[i] <= 399) s.insert(1);
			if(400 <= a[i] && a[i] <= 799) s.insert(2);
			if(800 <= a[i] && a[i] <= 1199) s.insert(3);
			if(1200 <= a[i] && a[i] <= 1599) s.insert(4);
			if(1600 <= a[i] && a[i] <= 1999) s.insert(5);
			if(2000 <= a[i] && a[i] <= 2399) s.insert(6);
			if(2400 <= a[i] && a[i] <= 2799) s.insert(7);
			if(2800 <= a[i] && a[i] <= 3199) s.insert(8);
		}
		else c++;
	}
	rc(max(1,sz(s)) << ' ' << sz(s) + c);
}

Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let vs = buf.split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let cs = buf.split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();

    let mut ans: i32 = 0;
    for i in 0..n {
        let vc = vs[i] - cs[i];
        if vc > 0 {
            ans += vc;
        }
    }

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


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

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


Measured memory_bytes: 3628
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		double lim = Math.sqrt(n);
		long i = 2;
		long sub = n-1;
		long a = n;
		long b = 1;
		while(i <= lim) {
			long memo = n-i;
			if(n%i==0&&sub>memo) {
				a = n/i;
				b = i;
				sub = memo;
			}
			i++;
		}
		System.out.println(a+b-2);
	}	
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })


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

  ll H, W;
  ll mod = 1000000007;
  cin >> H >> W;

  vector<vector<char> > grid(H, vector<char>(W, ' '));

  FOR(i, 0, H)FOR(j, 0, W) cin >> grid [i][j];

  vvl dp(H+1, vl(W+1, 0));
  FOR(i, 1, H+1)FOR(j, 1, W+1){
    if(i == 1 && j == 1){
      dp[1][1] = 1;
      continue;
    }
    if(grid[i-1][j-1] == '#') continue;
    dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
  }

  cout << dp[H][W] << endl;
}


Measured memory_bytes: 9088
M,N = list(map(int,input().split()))
s = list(map(int,input().split()))
count = 0
kiroku = 0

t = [0 for i in range(M+1)]
for i in range(M):
    t[i+1] = t[i] + (1+s[i])/2


for i in range(N,M+1):
    count = max(count,t[i]-t[i-N])

print(count)

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

int main(){
    int x_1, y_1, x_2, y_2;
    cin >> x_1 >> y_1 >> x_2 >> y_2;

    int dx = x_2 - x_1;
    int dy = y_2 - y_1;

    int x_3 = x_2 - dy;
    int y_3 = y_2 + dx;
    int x_4 = x_3 - dx;
    int y_4 = y_3 - dy;

    cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << endl;
    return 0;
}

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

money = 1000
stock = 0

for i in range(N - 1):
    if A[i] < A[i + 1]:
        if money >= A[i]:
            stock += money // A[i]
            money = money % A[i]
        
        if i == N - 2:
            money += A[i + 1] * stock
    else:
        if stock != 0:
            money += A[i] * stock
            stock = 0

print(money)

Measured memory_bytes: 9164
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a;
  char s[LIMIT1];
  std::priority_queue<int> que;
  
  scanf("%lld %lld",&n,&m);
  rep(i,n){
    scanf("%d",&a);
    que.push(a);
    result+=(ll)a;
  }
  rep(i,m){
    a = que.top();
    que.pop();
    que.push(a/2);
    result -= (ll)ceil(a/2.0);
  }
  printf("%lld",result);
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int R=0; int B = 0;	
	for (int i = 0; i < N; ++i)
	{
		 if (S[i] == 'R'){
		 	R += 1;
		 }else B+=1;
	}
	string ans;
	if(R>B){
		ans = "Yes";
	}else ans = "No";

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}
void solve()
{
    int a, b;
    cin>>a>>b;
    cout<<a*b<<endl;


}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    auto clk=clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------
    int t=1;
    // cin>>t;
    for(int test=1;test<=t;test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;

    }

    // -------------------------------------Code ends here------------------------------------------------------------------


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
    return 0;
}


Measured memory_bytes: 3832
D=int(input())
c=input().split()
c=[int(a) for a in c]
S=[]
for _ in range(D):
    s=input().split()
    s=[int(a) for a in s]
    S.append(s)
T=[]
for _ in range(D):
    t=int(input())-1
    T.append(t)
M=int(input())
numbers=[]
for _ in range(M):
    d,q=map(int,input().split())
    numbers.append([d,q])
whole=sum(c)
for m in range(M):
    ans = 0
    held = [0 for _ in range(26)]
    e=numbers[m][0]-1
    q=numbers[m][1]-1
    a=T[e]
    T[e]=q
    wholes=0
    for d in range(D):
        s = S[d]
        place = T[d]
        ans += s[place]
        wholes+=whole
        wholes-=c[place]*((d+1)-held[place])
        held[place] = d + 1
        ans-=wholes
    print(ans)


Measured memory_bytes: 85896
def has_triples(dices):
    for i in range(len(dices) - 2):
        a1, b1 = dices[i]
        a2, b2 = dices[i+1]
        a3, b3 = dices[i+2]

        if a1 == b1 and a2 == b2 and a3 == b3:
            return True

    return False


n = int(input())
dices = []
for _ in range(n):
    a, b = map(int, input().split(" "))
    dices.append((a, b))

print("Yes" if has_triples(dices) else "No")


Measured memory_bytes: 9188
#include <iostream>
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(){
    int n;
    string s;
    cin>>n>>s;
    int a[100001]={0},b[100001]={0};
    int sum=0;
    FOR(i,0,n){
        a[i]=(s[i]=='o'?0:1);
        sum=(sum+a[i])%2;
    }
    if(n%3==0){
        b[0]=0; b[1]=0;
    }else{
        int t=(n%3==1?2:1);
        FOR(i,0,2){
            int k=0,j=i-t;
            while(j>=0){
                k=(k+a[j])%2;
                j-=3;
            }
            j=i+t;
            while(j<n){
                k=(k+a[j])%2;
                j+=3;
            }
            b[i]=(sum+k)%2;
        }
    }
    b[2]=(a[1]+b[0]+b[1])%2;
    FOR(i,3,n){
        b[i]=(b[i-3]+a[i-1]+a[i-2])%2;
    }
    if((b[n-2]+b[n-1]+b[0]+a[n-1])%2==0&&(b[n-1]+b[0]+b[1]+a[0])%2==0){
        FOR(i,0,n){
            cout<<(b[i]?"W":"S");
        }   
    }else{
        cout<<-1<<endl;
    }
    cout<<endl;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 2000000000
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
using namespace std;
 
int main(void){
  int N;
  cin >> N;
  int ans=floor(log2(N));
  cout << pow(2,ans) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cmath>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    double R;
    cin >> R;
    cout << M_PI * R * 2 << endl;
    return 0;
}

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

const double PI = acos(-1);

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) {
        if (s[i] == 'R') a[i] = 0;
        if (s[i] == 'G') a[i] = 1;
        if (s[i] == 'B') a[i] = 2;
    }
    // 'R''G''B'の数を数える
    vector<ll> cnt(3);
    rep(i, n) cnt[a[i]]++;
    
    // 第一条件を満たす組み合わせ数算出
    ll ans = 1;
    rep(i ,3) ans *= cnt[i]; 

    // 第一条件を満たしてかつ第二条件を満たさないものを差し引く
    rep(j, n)rep(i, j) {
        int k = j + (j - i);
        if (k < n) {
            if (a[i] == a[j]) continue;
            if (a[i] == a[k]) continue;
            if (a[j] == a[k]) continue;
            ans--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int a, b, c, d, x;
  int sum = 0;
  for (int i = 1; i <= N; i++){
    x = i;
    a = x / 10000;
    x = x % 10000;
    b = x / 1000;
    x = x % 1000;
    c = x / 100;
    x = x % 100;
    d = x / 10;
    x = x % 10;
    int total = a + b + c + d + x;
    if(total >= A && total <= B){
      sum += i;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import math


def read_input():
    n, d = map(int, input().split())

    points = []
    for i in range(n):
        point = list(map(int, input().split()))
        points.append(point)

    return n, d, points


def check_good_distance(p1, p2):
    dist = 0
    for e1, e2 in zip(p1, p2):
        temp = abs(e2 - e1)
        dist += temp ** 2

    dist = math.sqrt(dist)

    if dist == int(dist):
        return True
    else:
        return False


def submit():
    n, d, points = read_input()

    count = 0
    for i, p1 in enumerate(points):
        for p2 in points[i+1:]:
            if check_good_distance(p1, p2):
                count += 1

    print(count)




if __name__ == '__main__':
    submit()


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

#define ll long long int
const ll sz=2e5+100;
ll tree[4*sz];

void Update(ll l,ll r,ll id, ll val,ll pos)
{
    if(l==r && id==l){
        tree[pos]=(tree[pos], val);
        return ;
    }
    ll mid=(l+r)/2ll;
    ll lc=pos*2+1;
    ll rc=lc+1;
    if(id<=mid) Update(l,mid,id,val,lc);
    else Update(mid+1,r,id,val,rc);

    tree[pos]=max(tree[lc], tree[rc]);
}


ll query(ll l,ll r,ll p,ll q,ll pos)
{
    if(r<p || q<l) return 0;
    if(p<=l && r<=q) return tree[pos];
    ll mid=(l+r)/2ll;
    ll lc=pos*2+1;
    ll rc=lc+1;
    return max(query(l,mid,p,q,lc), query(mid+1,r,p,q,rc));
}

int main()
{
    ll n,m,p,q,x,y,i,j,k,l;

    cin>>n;
    ll ara[n], val[n];
    for(i=0;i<n;i++) cin>>ara[i];
    for(i=0;i<n;i++) cin>>val[i];

    ll mx=0;

    for(i=0;i<n;i++){
        ll pip=query(1,sz-1,1,ara[i]-1,0);
        mx=max(mx, val[i]+pip);
        Update(1ll,sz-1,ara[i],val[i]+pip,0ll);
    }

    mx=max(mx, query(1,sz-1,1,sz-1,0));

    cout<<mx<<'\n';

}


Measured memory_bytes: 10864
N = int(input())
A = map(int, input().split())
xyz,T = [0,0,0],1
for Ai in A:
  n_Ai = xyz.count(Ai)
  T = (T*n_Ai)%1000000007
  if n_Ai>0: xyz[xyz.index(Ai)] += 1
print(T)

Measured memory_bytes: 10712
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto X = s[0];
    auto Y = s[1];
    auto A = s[2];
    auto B = s[3];
    auto C = s[4];
    auto P = readln.split.map!(to!long).array;
    auto Q = readln.split.map!(to!long).array;
    auto R = readln.split.map!(to!long).array;
    P.sort!"a > b";
    Q.sort!"a > b";
    R.sort!"a > b";

    auto S = P[0..X].dup ~ Q[0..Y].dup ~ R;
    S.sort!"a > b";

    S[0..X+Y].sum.writeln;
}

Measured memory_bytes: 13384
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
bool cango(string s, int start, int end)
{
    int rock = 0;
    int space = 0;
    int retsp = 0;
    rep(i, start, end + 1)
    {
        if (s[i] == '#')
        {
            space = 0;
            rock++;
        }
        else
        {
            rock = 0;
            space++;
            retsp = max(retsp, space);
        }
        if (rock >= 2)
            return false;
    }

    return true;
}

bool canjump(string s, int start, int end)
{
    int space = 0;
    if (start > 0)
    {
        if (s[start - 1] == '.')
            space++;
    }
    rep(i, start, end + 2)
    {
        if (s[i] == '.')
            space++;
        else
            space = 0;
        if (space >= 3)
            return true;
    }
    return false;
}

int main(int argc, char const *argv[])
{
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;

    string s;
    cin >> s;
    if (c < d)
    {
        if (cango(s, a, c) && cango(s, b, d))
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        bool goa = cango(s, a, c), gob = cango(s, b, d);
        if (goa && gob && canjump(s, b, d))
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

using namespace std;

int diff(int a, int b) { return abs(a-b); }

int main(){
  int n; cin >> n;
  int vet[n];
  for(int i = 0; i < n; i++) cin >> vet[i];
  int dp[n+5];
  dp[0] = 0;
  dp[1] = diff(vet[0], vet[1]);
  for(int i = 2; i < n; i++)
    dp[i] = min(dp[i-1]+diff(vet[i], vet[i-1]), dp[i-2]+diff(vet[i],vet[i-2]));
  cout << dp[n-1] << endl; 
  return 0;
}

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

long long mod = 1e9+7, fac[200005], invfac[2000005], inv[2000005];
int h,w,a,b;

long long c(int n, int k)
{
    if(n<0 || k>n) return 0LL;
    return (((fac[n] * invfac[k]) % mod) * invfac[n-k]) % mod;
}

int main()
{
    cin >> h >> w >> a >> b;

    inv[1] = invfac[0] = fac[0] = 1;
    for(long long i = 1; i <= 200000; i++) fac[i] = (i*fac[i-1])%mod;
    for(long long i = 2; i <= 200000; i++) inv[i] = (mod - ((mod/i) * inv[mod%i]) % mod) % mod;
    for(long long i = 1; i <= 200000; i++) invfac[i] = (inv[i]*invfac[i-1])%mod;

    long long ans = c(h+w-2,w-1);
    for(int i = 1; i <= a; i++)
    {
        ans -= (c(h-a+i+b-2,b-1) * c(a-i+w-b-1,w-b-1)) % mod;
        ans = (ans + mod) % mod;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8064