akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long F[2<<17],I[2<<17];
int N;
vector<int>G[2<<17];
int cc[2<<17];
long dp1[2<<17];
long dfs1(int u,int p)
{
	long ret=1;
	cc[u]=1;
	for(int v:G[u])if(v!=p)
	{
		ret=ret*dfs1(v,u)%mod;
		ret=ret*I[cc[v]]%mod;
		cc[u]+=cc[v];
	}
	dp1[u]=ret;
	return ret*F[cc[u]-1]%mod;
}
long ans[2<<17];
long dfs2(int u,int p,long pr)
{
	ans[u]=dp1[u]*pr%mod*I[N-cc[u]]%mod;
	for(int v:G[u])if(v!=p)
	{
		dfs2(v,u,ans[u]*F[cc[v]]%mod*power(dp1[v]*F[cc[v]-1]%mod,mod-2)%mod*F[N-cc[v]-1]%mod);
	}
	ans[u]=ans[u]*F[N-1]%mod;
}
main()
{
	cin>>N;
	F[0]=1;
	for(int i=1;i<=N;i++)F[i]=F[i-1]*i%mod;
	I[N]=power(F[N],mod-2);
	for(int i=N;i--;)I[i]=I[i+1]*-~i%mod;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs1(0,-1);
	dfs2(0,-1,1);
	for(int i=0;i<N;i++)cout<<ans[i]<<endl;
}


Measured memory_bytes: 23668
(defun f (a c d)
  (+ a (floor (/ a (/ (* c d) (gcd c d)))) (* -1 (+ (floor (/ a c)) (floor (/ a d))))))

(let ((a (read))
      (b (read))
      (c (read))
      (d (read)))
     (princ (+ (if (or (= 0 (rem a d)) (= 0 (rem a c))) 0 1) (- (f b c d) (f a c d)))))

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 5005;



int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    //S
    //    is Sunny, Cloudy, or Rainy.


    string s;
    cin >> s;


    bool f = true;
    for (i64 i = 0; i < s.size(); i++) {
        i64 c = s[i];
        if (c == 'U' || c == 'D') {
            continue;
        }
        if (i % 2 == 0) {
            if (c != 'R') {
                f = false;;
                break;
            }
        }
        else {
            if (c != 'L') {
                f = false;
                break;
            }
        }
    }

    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int box[200000];
  int N,max,i,v,min;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&box[i]);
  }
  
  max=-10000000000;
  min=box[0];
 
    for(i=1;i<N;i++){
      
       v=box[i]-min;
      if(v>max) max=v;
       if(min>box[i]) min=box[i]; 
    }
 
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define N 1000000007
 
ll fact(int x){
  ll ans = 1;
  for(int i=2;i<=x;i++){
    ans = ans * i % N;
  }
  return ans;
}
 
int main(){
  int n, m;
  cin >> n >> m;
  if (abs(n-m) > 1){
    cout << 0 << endl;
    return 0;
  }
  ll fact_n, fact_m;
  fact_n = fact(n);
  fact_m = fact(m);
  if (n != m){
    cout << (fact_n * fact_m) % N << endl;
  }else{
    cout << (2 * fact_n % N) * fact_m % N << endl;
  }
  return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[305][305];

//! D問題別解
int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        REP(j, N)
        {
            cin >> A[i][j];
        }
    }

    ll sum = 0;
    REP(i, N)
    {
        FOR(j, N, i + 1)
        {
            //! i->jにいくのに近い道があるか
            bool e = false;
            REP(k, N)
            {
                if (k == i || k == j)
                    continue;
                if (A[i][j] > A[i][k] + A[j][k])
                {
                    cout << -1 << endl;
                    return 0;
                }

                if (A[i][j] == A[i][k] + A[j][k])
                {
                    e = true;
                    break;
                }
            }
            if (!e)
                sum += A[i][j];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s, t;
  cin >> s >> t;
  sort(all(s));
  sort(all(t), greater<char>());
  if(s.compare(t) < 0)
    cout << "Yes\n";
  else
    cout << "No\n";

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



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		FastScanner in= new FastScanner(System.in);
		PrintWriter out= new PrintWriter(System.out);
		
		
		int a= in.nextInt();
		int b= in.nextInt();
		int res= a + 2*(b-a);
		System.out.println(res);
		
	}
	static class p{
		int x;
		int y;
		public p(int a, int b) {
			x=a;
			y=b;
		}
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
			st = new StringTokenizer("");
		}

		public String next() throws IOException {
			if (!st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
				return next();
			}
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		public double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}
/*
4 6
1 1 1
1 3 1
4 2 1
4 3 1
2 4 1
2 3 1
*/

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  if (a + b >= 24)
    ans = a + b - 24;
  else
    ans = a + b;

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


Measured memory_bytes: 256
import math
def main(n,m,a):
    sikii = sum(a) / (4*m)
    a = [i for i in a if i >= sikii]
    return "Yes" if len(a) >= m else "No"

n,m = map(int, input().split())
a = list(map(int, input().split()))
print(main(n,m,a))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, k, tmp;
    long long sum=0;
    cin>>n>>k;
    vector <int> v;
    for(int i=0; i<n; i++) {
        cin>>tmp;
        v.push_back(tmp);
    }
    if(k>n) {
        cout<<0<<endl;
        return 0;
    }
    sort(v.begin(), v.end());
    for(int i=0; i<v.size()-k; i++) {
        sum+=v[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e5+5;
const ll INF=1e15;

struct edge{int to; ll cost;};
typedef pair<ll,int> P;
int N;
vector<edge> Gy[MAX], Gs[MAX];
ll dy[MAX],ds[MAX];

void dij_y(int s){
	priority_queue<P,vector<P>, greater<P>> quey;
	fill(dy+1, dy+N+1, INF);
	dy[s] = 0;
	quey.push(make_pair(0,s));
	
	while(!quey.empty()){
		P p = quey.top();quey.pop();
		int v=p.second;
		if(dy[v] < p.first) continue;
		for(int i = 0; i < Gy[v].size(); i++){
			edge e = Gy[v][i];
			if(dy[e.to] > dy[v]+e.cost){
				dy[e.to] = dy[v]+e.cost;
				quey.push(make_pair(dy[e.to], e.to));
			}
		}
	}
}

void dij_s(int s){
	priority_queue<P,vector<P>, greater<P>> ques;
	fill(ds+1, ds+N+1, INF);
	ds[s] = 0;
	ques.push(make_pair(0,s));
	
	while(!ques.empty()){
		P p = ques.top();ques.pop();
		int v=p.second;
		if(ds[v] < p.first) continue;
		for(int i = 0; i < Gs[v].size(); i++){
			edge e = Gs[v][i];
			if(ds[e.to] > ds[v]+e.cost){
				ds[e.to] = ds[v]+e.cost;
				ques.push(make_pair(ds[e.to], e.to));
			}
		}
	}
}

int main(){
	int M;
	cin>>N>>M;
	int s,t;
	cin>>s>>t;
	
	int u[MAX],v[MAX];
	ll a[MAX],b[MAX];
	rep(i,M){
		int u,v;
		ll a,b;
		cin>>u>>v>>a>>b;
		
		edge e={v,a};
		Gy[u].push_back(e);
		e={u,a};
		Gy[v].push_back(e);
		
		e={v,b};
		Gs[u].push_back(e);
		e={u,b};
		Gs[v].push_back(e);
	}
	dij_y(s);
	dij_s(t);
	
	ll d[MAX] ,dmin[MAX];
	for(int i=N;i>=1;i--){
		d[i]=dy[i]+ds[i];
		if(i==N)dmin[i]=d[i];
		else dmin[i]=min(d[i],dmin[i+1]);
	}
	rep1(i,N){
		cout<<INF-dmin[i]<<endl;
	}
}

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

struct edge{
    int to, cap, rev;
};

#define MAX_V 1002
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

// v...target vertex, t...end vertex, f...maximum flow 
int dfs(int v, int t, int f){
    if(v == t)  return f;

    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }

    return 0;
}

const int INF = 1<<29;

// maxflow from s to t
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0)  return flow;
        flow += f;
    }
}

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}

int main(){
    int m, n;
    while(cin >> m >> n, m+n){
        for(int i = 0; i < 1002; i++)   G[i].clear();
        vector<int> b(m), r(n);
        int SOURCE = 1000, SINK = 1001;
        for(int i = 0; i < m; i++)  cin >> b[i], add_edge(SOURCE,i,1);
        for(int i = 0; i < n; i++)  cin >> r[i], add_edge(i+m, SINK, 1);
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                if(gcd(b[i],r[j])>1)    add_edge(i, m+j, 1);
            }
        }
        cout << max_flow(SOURCE, SINK) << endl;
    }
    return 0;
}




Measured memory_bytes: 9408
x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)[:x]
q = sorted(list(map(int, input().split())), reverse=True)[:y]
r = sorted(list(map(int, input().split())), reverse=True)
print(sum(sorted(p+q+r, reverse=True)[:x+y]))





Measured memory_bytes: 22504
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
a = list(map(int, input().split()))
a.reverse()
cs = [0] * (N + 1)
cs2 = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]
for i in range(0, N, 2): cs2[i + 1] = a[i]
for i in range(N): cs2[i + 1] += cs2[i]
#print(cs, cs2)
for _ in range(Q):
  x = int(input())
  ok = 0
  ng = -(-N // 2)
  while ng - ok > 1:
    m = (ok + ng) // 2
    if a[m] + a[m * 2] >= 2 * x: ok = m
    else: ng = m
  res = cs[ok + 1]
  #print(x)
  if (ok + 1) * 2 <= N: res += cs2[-1] - cs2[(ok + 1) * 2]
  print(res)

Measured memory_bytes: 61420
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long long int ans = 0;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			for (int k=1;k<=n;k++)
			{
				ans++;
			}
		}
	}
	cout << ans;
	
	return 0;
} 

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#undef LOCAL
#include <bits/stdc++.h>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

#ifdef LOCAL
struct PrettyOS {
    ostream& os;
    bool first;
    template <class T> auto operator<<(T&& x) {
        if (!first) os << ", ";
        first = false;
        os << x;
        return *this;
    }
};
template <class... T> void dbg0(T&&... t) {
    (PrettyOS{cerr, true} << ... << t);
}
#define dbg(...)                                            \
    do {                                                    \
        cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \
        dbg0(__VA_ARGS__);                                  \
        cerr << endl;                                       \
    } while (false);
#else
#define dbg(...)
#endif

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

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

template <class T> struct Fenwick {
    int n;
    V<T> seg;
    Fenwick(int _n = 0) : n(_n), seg(n + 1) {}
    /// i番目の要素にxを追加する
    void add(int i, T x) {
        i++;
        while (i <= n) {
            seg[i] += x;
            i += i & -i;
        }
    }
    /// [0, i)のsum
    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += seg[i];
            i -= i & -i;
        }
        return s;
    }
    /// [a, b)のsum
    T sum(int a, int b) { return sum(b) - sum(a); }
    /// sum[0, idx) >= xなる最小のidx(sum[0, n) < x なら n+1)
    int sum_lower_bound(T x) {
        if (x <= 0) return 0;
        int res = 0, len = 1;
        while (2 * len <= n) len *= 2;
        for (; len >= 1; len /= 2) {
            if (res + len <= n && seg[res + len] < x) {
                res += len;
                x -= seg[res];
            }
        }
        return res + 1;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    V<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    Fenwick<ll> fw(1010);
    ll sm = 0;
    for (int a = 0; a < n; a++) {
        for (int b = a + 1; b < n; b++) {
            // last: [0, a)
            int up = min(1003, l[a] + l[b] - 1);
            int lw = max(1, max(l[a], l[b]) - min(l[a], l[b]) + 1);
            if (up < lw) continue;
            sm += fw.sum(lw, up + 1);
        }
        fw.add(l[a], 1);
    }
    cout << sm << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define INF 1e9

int n,m[N][N];

void dijk(){
  int i,u,v,min;
  int d[N],col[N];

  for(i=0;i<n;i++){
    d[i]=INF; col[i]=0;
  }

  d[0]=0; col[0]=1;
  while(1){
    min=INF; u=-1;
    for(i=0;i<n;i++){
      if(min>d[i] && col[i]!=2){
	u=i; min=d[i];
      }
    }
    if(u==-1) break;
    col[u]=2;
    for(v=0;v<n;v++){
      if(col[v]!=2 && m[u][v]!=INF){
	if(d[v]>d[u]+m[u][v]){
	  d[v]=d[u]+m[u][v]; col[v]=1;
	}
      }
    }
  }

  for(i=0;i<n;i++) printf("%d %d\n",i,(d[i]==INF ? -1:d[i]));
}

int main(){
  int i,j,k,c,u,v;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++) m[i][j]=INF;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      m[u][v]=c;
    }
  }

  dijk();

  return 0;
}



Measured memory_bytes: 2048
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if A[i] <= B[i]:
            B[i] -= A[i]
            ans += A[i]
            A[i] = 0
            if A[i+1] <= B[i]:
                B[i] -= A[i+1]
                ans += A[i+1]
                A[i+1] = 0
            else:
                A[i+1] -= B[i]
                ans += B[i]
                B[i] = 0
        else:
            A[i] -= B[i]
            ans += B[i]
            B[i] = 0
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81892
sx,sy,tx,ty = map(int, input().split())
ans = ""
ans += "U"*(ty-sy)
ans += "R"*(tx-sx)
ans += "D"*(ty-sy)
ans += "L"*(tx-sx)
ans += "L"
ans += "U"*(ty-sy+1)
ans += "R"*(tx-sx+1)
ans += "D"
ans += "R"
ans += "D"*(ty-sy+1)
ans += "L"*(tx-sx+1)
ans += "U"

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;

ll bit[200010];
//ll kai[3010];
ll Cnt[1000010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }



/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/



void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

void makePrimeList(ll x) {
	ll X = x;
	for (ll j = 2; j * j <= x; j++) {
		ll cnt = 0;
		while (X % j == 0) {
			cnt++;
			X /= j;
		}
		if (cnt) {
			Cnt[j] = max(Cnt[j], cnt);
		}
	}
	if (X != 1) Cnt[X] = max(Cnt[X], 1LL);
}

ll N, a[55], b[55];
map<P, ll> edge;
ll M, u[20], v[20];
bitset<56> ver[20];
vector<ll> E[55];
ll par[55];
ll wrong[1100000];
ll ans;

void makeParent(ll now, ll from) {
	par[now] = from;
	for (ll v : E[now]) {
		if (v == from) continue;
		makeParent(v, now);
	}
}

void path(ll now, ll pa, ll num) {
	if (now == pa) return;
	ver[num][edge[P(now, par[now])]] = 1;
	path(par[now], pa, num);
}

void solve() {
	cin >> N;
	rep(i, N - 1) {
		cin >> a[i] >> b[i];
		E[a[i]].pb(b[i]);
		E[b[i]].pb(a[i]);
		edge[P(a[i], b[i])] = i;
		edge[P(b[i], a[i])] = i;
	}
	cin >> M;
	rep(i, M) {
		rep(j, N) par[j + 1] = 0;
		cin >> u[i] >> v[i];
		makeParent(u[i], 0);
		path(v[i], u[i], i);
	}
	rep(i, (1LL << M)) {
		bitset<56> bs;
		ll numBit = 0;
		rep(j, M) if ((1LL << j) & i) {
			bs |= ver[j];
			numBit++;
		}
		ll sum = 0;
		rep(j, 55) sum += bs[j];
		wrong[i] = (1LL << (N - 1 - sum));
		if (numBit % 2 == 0) ans += wrong[i];
		else ans -= wrong[i];
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}

Measured memory_bytes: 10496
import re
import sys
import math
import itertools
from sys import stdin

def main():
    """
     解答をこちらに
    """
    while 1:
        b = int(input())

        if b==0:
            return
        ans1 = b
        ans2 = 1
        for l in range(1, b+1):
            p = (b - l *(l-1)/2 )/l

            if p <1:
                break
            if p % 1==0:
                ans1 = int(p)
                ans2 = l
        print(ans1, ans2)

        
if __name__ == "__main__":
    main()


Measured memory_bytes: 6548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pa;
ll go(ll x, ll y) {
	if (x > y) {
		return y;
	}
	else {
		return go(x, floor(y / x)) + y % x;
	}
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	ll n; cin >> n;
	ll s; cin >> s;
	for (ll i = 2; i * i <= n; i++) {
		if (go(i, n) == s) {
			cout << i << '\n'; return 0;
		}
	}
	if (n < s) {
		cout << -1 << '\n'; return 0;
	}
	if (n == s) {
		cout << n + 1 << '\n'; return 0;
	}
	else {
		ll tmp = n - s;
		vector<ll> v;
		for (ll i = 1; i*i <= tmp; i++) {
			if (tmp % i == 0) {
				v.push_back(i);
				v.push_back(tmp / i);
			}
		}
		sort(v.begin(), v.end());
		for (int i = 0; i < v.size(); i++) {
			if (go(v[i] + 1, n) == s) {
				cout << v[i] + 1 << '\n'; return 0;
			}
		}

		cout << -1 << '\n';
	}



}

Measured memory_bytes: 384
N,K = map(int, input().split())
X = list(map(int, input().split()))
ans = 1E20
for i in range(N-K+1):
  ans = min(ans, X[i+K-1]-X[i]+abs(X[i]))
  ans = min(ans, X[i+K-1]-X[i]+abs(X[i+K-1]))
print(ans)


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

using namespace std;

#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()

const int MX = (int)1e5 + 10;
// const int mod = (int)1e9 + 7;
const int mod = 998244353;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}


int bp(int x, int exp){
    int res = 1;
    while(exp){
        if(exp & 1) mul(res, x);
        exp >>= 1;
        mul(x, x);
    }
    return res;
}

int main(){

    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;

    int depth[n];
    int cnt[n + 1] = {};
    int mx = 0;
    for(int i = 0; i < n; ++i){
        cin >> depth[i];
        cnt[depth[i]]++;
        mx = max(mx, depth[i]);
    }

    int res = cnt[0] == 1 && depth[0] == 0;

    for(int i = 1; i <= mx; ++i) mul(res, bp(cnt[i - 1], cnt[i]));

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

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;




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

	int a,b;cin>>a>>b;

	int n= max(a,b);
	int s= min(a,b);

	for(int i=s; i<=n; i++){
		if(abs(a-i) == abs(b-i)){
			writeln(i);
			return 0;
 		}
	}
	writeln("IMPOSSIBLE");

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<set>
#include<bitset>
#define rep(i,a,b)  for(i=a;i<b;i++)
#define itrep(at)	for(auto it=at.begin();it!=at.end();it++)
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vb vector<bool>
#define vc vector<char>
#define vvll vector<vector<long long int> >
#define sll set<long long int>
#define mll map<long long int,long long int>
#define sllit set<long long int>::iterator
#define pll pair<long long int,long long int>
#define vpll vector<pair<long long int,long long int> >
#define db double
#define M 1000000007
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
lli min(lli a,lli b){return a<b?a:b;}
lli min(lli a,lli b,lli c){a=min(a,b);a=min(a,c);return a;}
lli max(lli a,lli b){return a>b?a:b;}
lli max(lli a,lli b,lli c){a=max(a,b);a=max(a,c);return a;}
lli power(lli a,lli b){lli res=1;while(b){if(b&1) res=res*a;a=a*a;b>>=1;}return res;}
lli mpower(lli a,lli b,lli m){lli res=1;a=a%m;while(b){if(b&1){res=(res*a)%m;}a=((a%m)*(a%m))%m;b>>=1;}return res;}
lli gcd(lli a,lli b){if(b==0) return a;if(a==0) return b;if(a>=b) return gcd(b,a%b);else return gcd(a,b%a);}
lli lcm(lli a,lli b){lli p=a*b;return p/gcd(a,b);}
lli dsum(lli n){lli ans=0;while(n){ans+=(n%10);n/=10;}return ans;}


/******************************START********************************/
int main()
{
	char ch1,ch2,ch3;
	string s1,s2,s3,str;
    lli i,j,k,a,b,c,t,d,n,m,sum=0,ans=0,temp;
    cin >> s1;
    rep(i,0,s1.length())	cout << "x";
    cout << endl;
    
    
    
    
    return 0;
}





















/* UJJWAL KESHRI */

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0;char c;
	for(c=getchar();c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n;
}
const int maxn=1e5+5;
int i,j,a[maxn],b[maxn],c[maxn],n,t1,t2;ll ans;
int main(){
	n=read();
	fo(i,1,n) a[i]=read();
	fo(i,1,n) b[i]=read();
	fo(i,1,n) c[i]=read();
	sort(a+1,a+1+n),sort(b+1,b+1+n),sort(c+1,c+1+n);
	t1=1,t2=1;
	fo(i,1,n) {
		for(;t1<=n&&a[t1]<b[i];t1++);
		for(;t2<=n&&c[t2]<=b[i];t2++);
		ans+=(ll)(t1-1)*(n-t2+1);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}
bool sorttowers (pair<int,pair<int,int>> p1, pair<int,pair<int,int>> p2)
{
    return (p2.first + p2.second.first) < (p1.first + p1.second.first);
}

int n;
vector<pair<int,pair<int,int>>> tower;
ll dp[3005][20005];

ll solve(int i, int stiff) {
    if (i == n)
        return 0;
    if (dp[i][stiff] != -1) return dp[i][stiff];
    if (tower[i].first <= stiff)
        return dp[i][stiff] = max(solve(i + 1, stiff), solve(i + 1, min(tower[i].second.first, stiff - tower[i].first)) + tower[i].second.second);
    return dp[i][stiff] = solve(i + 1, stiff);
}

int main() {
    IO;
    cin >> n;
    tower.resize(n);
    for (int i = 0; i < n; i++)
        cin >> tower[i].first >> tower[i].second.first >> tower[i].second.second;
    sort(tower.begin(), tower.end(), sorttowers);
    for (int i = 0; i < 3005; i++)
        for (int j = 0; j < 20005; j++)
            dp[i][j] = -1;
    cout << solve(0,20002   );
    return 0;
}


Measured memory_bytes: 470016
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	sort(a, a + 3);

	int ans = 0;
	int bit = 0;
	if ((a[2] - a[1]) % 2 == 1) {
		ans += (a[2] - 1 - a[1]) / 2;
		a[1] += ans * 2;
		bit = 1;
	}
	else {
		ans += (a[2] - a[1]) / 2;
		a[1] += ans * 2;
	}

	if ((a[1] - a[0]) % 2 == 1) {
		ans += (a[1] - 1 - a[0]) / 2;
		bit |= 2;
	}
	else {
		ans += (a[1] - a[0]) / 2;
	}

	switch (bit) {
	case 1:
		ans += 1;
		break;
	case 2:
		ans += 2;
		break;
	case 3:
		ans += 3;
		break;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*ll t,tcitr;
    cin>>t;
    tcitr=0;
    while(tcitr<t)
    {*/
        //cout<<"Case #"<<tcitr+1<<": ";
        ll n,m,i,j,k;
        cin>>n>>m;
        ll w;
        cin>>w;
        ll row[n]={},col[m]={};
        map<pair<ll,ll>,ll> mp;
        for(i=0;i<w;i++)
        {
            cin>>j>>k;
            mp[{j-1,k-1}]=1;
            row[j-1]++;
            col[k-1]++;
        }
        ll mxr=0,mxc=0;
        ll ridx,cidx;
        vector<ll> mxrow,mxcol;
        for(i=0;i<n;i++)mxr=max(mxr,row[i]);
        for(i=0;i<m;i++)mxc=max(mxc,col[i]);
        ll ans=mxr+mxc;
        for(i=0;i<n;i++)
        {
            if(mxr==row[i])mxrow.push_back(i);
        }
        for(j=0;j<m;j++)
        {
            if(mxc==col[j])mxcol.push_back(j);
        }
        bool flg=true;
        for(i=0;i<mxrow.size();i++)
        {
            for(j=0;j<mxcol.size();j++)
            {
                if(!mp.count({mxrow[i],mxcol[j]}))flg=false;
                if(!flg)
                {
                    i=M;
                    j=M;
                }
            }
        }
        if(flg)ans--;
        cout<<ans<<"\n";
        /*tcitr++;
    }*/
    return 0;
}


Measured memory_bytes: 35040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

string burger_gen ( int n ) {
    if ( n == 0 ) return "P";
    return "B"+burger_gen(n-1)+"P"+burger_gen(n-1)+"B";
}

int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> p_num(n+1);
    vector<ll> total_num(n+1);
    p_num[0] = 1;
    total_num[0] = 1;
    for ( int i = 1; i <= n; ++i ) {
        p_num[i] = p_num[i-1] * 2 + 1;
        total_num[i] = total_num[i-1] * 2 + 3;
    }
    ll ans = 0;
    for ( int i = n; i >= 0; --i ) {
        if ( x == 0 ) break;
        if ( x == total_num[i] ) {
            ans += p_num[i];
            break;
        }
        if ( x == 1 ) {
            break;
        }
        if ( x <= 1LL + total_num[i-1] ) {
            --x;
        }
        else {
            ans += 1LL + p_num[i-1];
            x -= 1LL + total_num[i-1] + 1LL;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def binary_patterns(size, patterns = [[true], [false]])
  return patterns if patterns[0].size == size
  ret = []
  patterns.each {|pattern|
    ret += binary_patterns(size, [pattern + [true]])
    ret += binary_patterns(size, [pattern + [false]])
  }
  ret
end

lines = $stdin.read.lines.map(&:chomp)
H, W, K = lines.shift.split(' ').map(&:to_i)
c = lines.map {|line| line.split(//) }
black = c.flatten.find_all {|x| x == '#' }.size

row_patterns = binary_patterns(H)
col_patterns = binary_patterns(W)

total = 0
row_patterns.each {|row|
  col_patterns.each {|col|
    red = 0
    0.upto(H - 1) {|i|
      0.upto(W - 1) {|j|
        red += 1 if (c[i][j] == '#') and (row[i] or col[j])
      }
    }
    total += 1 if black - red == K
  }
}
puts total


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

using namespace std;

long foo(long a, long b) {
  if (a < b) return foo(b, a);
  if (a % b == 0) return b;
  return foo(b, a % b);
}

int main(void) {
  long N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  long bar = N * M / foo(N, M);
  long dS = bar / N, dT = bar / M;

  long posS = 0, posT = 0;

  for (long i = 0, j = 0; i < N or j < M; ) {
    if (posS == posT) {
      if (S[i] != T[j]) {
        cout << -1 << endl;
        return 0;
      }
      i++;
      posS += dS;
      j++;
      posT += dT;
    }
    else if (posS < posT) {
      i++;
      posS += dS;
    }
    else {
      j++;
      posT += dT;
    }
  }
  cout << bar << endl;
  return 0;
}


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

int main(){
  long long n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  long long cnt = 0;
  const long long mod = pow(10,9) + 7;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      if(a.at(i) > a.at(j)) cnt++;
    }
  }
  long long ans = (cnt * k) % mod;
  
  cnt = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(a.at(i) > a.at(j)) cnt++;
    }
  }
  ans += (k * (k-1) / 2) % mod * cnt % mod;
  ans %= mod;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");

forn(i,5)
{

int x;
cin>>x;
if(x==0)cout<<i+1;
  }


    return 0;
  }


Measured memory_bytes: 3604
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var s = next();
  var rlist = new Array(N).fill(0);
  var glist = new Array(N).fill(0);
  var blist = new Array(N).fill(0);
  for(var i = N - 1; i > 0; i--){
    if(s[i] == "R"){
      rlist[i]++;
    }
    if(s[i] == "G"){
      glist[i]++;
    }
    if(s[i] == "B"){
      blist[i]++;
    }
    rlist[i - 1] += rlist[i];
    glist[i - 1] += glist[i];
    blist[i - 1] += blist[i];
  }
  //myerr(rlist);
  var output = 0;
  for(var i = 0; i < N - 2; i++){
    for(var j = i + 1; j < N - 1; j++){
      if(s[i] != s[j]){
        //i,jより右にある,s[i]でもs[j]でもないものをカウントする
        if(s[i] == "R" && s[j] == "B" || s[i] == "B" && s[j] == "R"){
          output += glist[j + 1];
          if(s[j + (j - i)] == "G"){
            output--;
          }
        }
        if(s[i] == "R" && s[j] == "G" || s[i] == "G" && s[j] == "R"){
          output += blist[j + 1];
          if(s[j + (j - i)] == "B"){
            output--;
          }
        }
        if(s[i] == "G" && s[j] == "B" || s[i] == "B" && s[j] == "G"){
          output += rlist[j + 1];
          if(s[j + (j - i)] == "R"){
            output--;
          }
        }
      }
    }
  }
  myout(output);
}


Measured memory_bytes: 36280
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var L = int.Parse(line[0]);
        var r = int.Parse(line[1]);
        var d = int.Parse(line[2]);
        var count = 0;
        for (int i = L; i <= r; i++)
            if (i % d == 0) count++;
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 27284
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	ll n;
	cin >> n;
	vector<P> a(n);
	REP(i, n) {
		cin >> a[i].first;
		a[i].second = i+1;
	}
	sort(all(a), greater<>());
	ll res = 0;
	set<ll> s;
	s.insert(0);
	s.insert(n + 1);
	REP(i, n) {
		ll t = a[i].second;
		ll l1, l2, r1, r2; //l1 <= l2 < i < r1 <= r2

		auto itr = s.lower_bound(t);
		r1 = *itr;
		++itr;
		if (itr == s.end()) {
			r1 = r2 = n + 1;
		} else {
			r2 = *itr;
		}
			
		itr--;
		l2 = *--itr;
		if (itr == s.begin()) {
			l1 = l2 = 0;
		} else {
			l1 = *--itr;
		}
		s.insert(t);
		
		res += a[i].first * (l2 - l1) * (r1 - t);
		res += a[i].first * (r2 - r1) * (t - l2);
		
	}
	put(res);
	return 0;
}


Measured memory_bytes: 6528
/*  -*- coding: utf-8 -*-
 *
 * b.cc: Ice Rink Game
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_K = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_K];

/* subroutines */

/* main */

int main() {
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; i++) scanf("%d", &as[i]);

  ll minn = 2, maxn = 2;
  for (int i = k - 1; i >= 0; i--) {
    int &ai = as[i];
    ll minn0 = (minn + ai - 1) / ai * ai;
    ll maxn0 = maxn / ai * ai + (ai - 1);
    minn = minn0, maxn = maxn0;

    if (minn > maxn) {
      puts("-1");
      return 0;
    }
  }

  printf("%lld %lld\n", minn, maxn);
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#define ll long long
#define pb push_back

int main(){
 std::string s;
  std::cin >> s;
  if(s[0]=='R' && s[1]=='R' && s[2]=='R')
     std::cout << "3" << "\n";
  else if(s[0]=='R' && s[1]=='R' && s[2]=='S')
     std::cout << "2" << "\n";
  else if(s[1]=='R' && s[2]=='R' && s[0]=='S')
     std::cout << "2" << "\n";
  else if(s[0]=='R' || s[1]=='R' || s[2]=='R')\
    std::cout << "1" << "\n";
  else
    std::cout << "0";
 return 0;
}


Measured memory_bytes: 3616
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, L;
	cin >> N >> L;

	int ret = 1e9;
	int sum = 0;

	REP(i, N){
		if(abs(L) < abs(ret))ret = L;
		sum += L;
		L++;
	}
	cout << sum - ret << endl;


	return 0;
}


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

#define DEBUG 0
#define NINF -1
#define PINF 1E9+7

#define MAX_INPUT 100000
#define ATOZ 26

int n,count[ATOZ]={},species=0;
char *s;

int main()
{
	int i,j;
	long ans=0,tmp;

	scanf("%d",&n);
	s = (char *)malloc(sizeof(char) * (n+1));
	scanf("%s",s);

	for (i=0;i<n;i++) {
		if (count[s[i]-'a']==0) species++;
		count[s[i]-'a']++;
		
		tmp = 1;
		for (j=0;j<ATOZ;j++) {
			if (count[j]==0) continue;
			if (j==s[i]-'a') continue;

			tmp *= count[j]+1;
			tmp = fmod(tmp,PINF);
		}
		if (DEBUG) printf("tmp = %ld\n",tmp);
		ans = fmod(ans + tmp , PINF);
	}


	printf("%ld\n",ans);
	free(s);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int a, b;
	cin >> a >> b;
	if((a+b)&1){
		cout << "IMPOSSIBLE";
	    return 0;
	}else{
		cout << (a+b)/2 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,m,x;
  cin >>n>>m>>x;
  ll a[m];
  for(ll i=0;i<m;i++) cin >>a[i];
  sort(a,a+m);
  ll k=0,l=0;
  for(ll i=0;i<m;i++){
    if(a[i]<x) k++;
    else l++;
  }
  cout << min(k,l)<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;

int main()
{
    int n;
    cin >> n;
    int d[n];

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

    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S;
  cin >> S;
  bool flag = true;
  if(S[0]!='A') flag = false;
  int Ccnt=0;
  for(int i=1;i<(int)S.size();i++){
    if(S[i]=='C') {
      Ccnt++;
      if (i==((int)S.size()-1) || i==1) flag = false;
    }
    if(0 <= S[i]-'A' && S[i]-'A'<26 && S[i]!='C') flag = false;
  }
  if(Ccnt!=1)flag = false;
  if(flag) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}


Measured memory_bytes: 256