akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define sort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

int main()
{
    IOS;
    int n; 
    cin>>n;
    vector<ll> a(n,0);

    ll sum=0;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        sum=sum^a[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        ll v=sum ^ a[i];
        cout<<v<<" ";
    }
    
}

Measured memory_bytes: 4724
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
freq = Counter(a)
ordering = []
for i in range(n):
    right = n - i - 1
    left = i
    ordering.append(abs(right - left))
freq2 = Counter(ordering)
if freq != freq2:
    print(0)
else:
    result = 1
    for x in freq.values():
        result *= x
    print(result % (10 ** 9 + 7))

Measured memory_bytes: 64236
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

template <typename T>
T largest_rectangle(vector<T> h) {
  stack<int> st;
  h.push_back(0);
  vector<int> L(h.size());
  T ret = 0;
  for (int i = 0; i < h.size(); i++) {
    while (!st.empty() && h[st.top()] >= h[i]) {
      ret = max(ret, (i - L[st.top()] - 1) * h[st.top()]);
      st.pop();
    }
    L[i] = st.empty() ? -1 : st.top();
    st.emplace(i);
  }
  return ret;
}

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

  int N;
  cin >> N;
  vector<int> h(N);
  cin >> h;
  cout << largest_rectangle(h) << endl;

  return 0;
}


Measured memory_bytes: 5944
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int N, z[200000];

int main() {
    scanf("%d", &N);
    rep (_, N) {
        int a, b;
        scanf("%d%d", &a, &b);
        z[a]++;
        z[b+1]--;
    }
    int ans = 1, cur = 1;
    rep (i, N+2) {
        cur += z[i];
        if (cur >= i) ans = i;
    }
    printf("%d\n", ans-1);
    return 0;
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1) / b);}
template<class T> inline T round(T a, T b) {return T(a / b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template <class T> inline void out(T &a) { bool flag=true; for(auto&x:a){if(flag) {flag=false;} else{ cout << ' '; } cout<<x; } cout << endl; }



//----------------------------------------------------------------
int nmax=200000; // 2*(10^5)
vvec g(nmax);





void solve()
{
    
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }
    else{
        cout<<"safe"<<endl;
    }
    
}
//-----------------------------------------------------------------

signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15);
    int repeat = 1;
    // cin >> repeat;
    while(repeat--) solve();
}

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

const int mod = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> s(n + 1);
	rep(i, n) s[i + 1] = s[i] + a[i];
	ll ans = 0;
	rep(i, n - 1) {
		ans += a[i] * ((s[n] - s[i + 1]) % mod);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6420
#include <stdio.h>

/*long gcd(long a,long b){
	long i;
	if(a>=b){
		for(i=b;i>=1;i--){
			if(a%i==0&&b%i==0){
				return i;
				break;
			}
		}
	}else{
		for(i=a;i>=1;i--){
			if(a%i==0&&b%i==0){
				return i;
				break;
			}
		}
	}
}
*/

long gcd(long a,long b){
	long i;
	if(a==1||b==1){
		i = 1;
	}else if(a>=b){
		if(a%b==0){
			i = b;
		}else{
			i = gcd(b,a%b);
		}
	}else{
		if(b%a==0){
			i = a;
		}else{
			i = gcd(a,b%a);
		}
	}
	return i;
}



int main()
{
	long a,b,g;
	while(scanf("%ld %ld",&a,&b)!=EOF){
		g = gcd(a,b);
		printf("%ld %ld\n",g,a*(b/g));
	}
	
	return 0;
}

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

int main() {

    int a,b,c;
    cin >>a>>b>>c;
    int sum = a+b+c;

    if(sum >=22) {
        cout << "bust" << endl;
    } else{
        cout << "win" << endl;
    }


	return 0;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define fi first
#define se second

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int e = a / d;
    if(a % d)
        e++;
    int f = c / b;
    if(c % b)
        f++;

    if(e >= f)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


Measured memory_bytes: 3648
import sys

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    sys.exit()
if K % 7 == 0:
    K //= 7
count = 1
mod = 1
sum = 1
while sum % K != 0:
    mod = (mod * 10) % K
    sum += mod
    sum = sum % K
    count += 1
print(count)


Measured memory_bytes: 63288
#include <bits/stdc++.h>
#include <cstring>
#include <map>
#include <set>
#define int long long int
#define cons 1000000007 
using namespace std;

signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
 
    string s;
    cin>>s;
    int ans[s.length()]={0};
    int l, r, i, start;
    for(i=0;i<s.length();){
        int len=0;
        start = i;
        while(s[i]=='R'){
            i++;
            len++;
        }
        r = i-1;
        l = i;
        while(s[i]=='L'){
            i++;
            len++;
        }
        if((r-start)%2==0)
        {
            ans[r]=(len+1)/2;
            ans[l]=len/2;
        }
        else{
            ans[l]=(len+1)/2;
            ans[r]=len/2;
        }
    }
    for(i=0;i<s.length();i++)
        cout<<ans[i]<<" ";
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 80

int a[N];

int main()
{
    canhazfast();

    int n, lo, hi;
    ll q = 0, r = 1000;

    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    lo = hi = a[0];
    for (int i = 1; i < n; ++i) {
        ctif(a[i] == a[i-1]);
        if (a[i] < a[i-1]) {
            q = r/lo;
            r %= lo;
            r += q*hi;
            lo = hi = a[i];
        } else {
            hi = a[i];
        }
    }
    if (lo < hi) {
        q = r/lo;
        r %= lo;
        r += q*hi;
    }
    cout << r << '\n';

    return 0;
}


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

int main() {
    int n, m, ret = 0;
    cin >>n >>m;
    int max_l = 1, min_r = n+1;
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >>l >> r;
        max_l = max(max_l, l);
        min_r = min(min_r, r);
    }
    cout << ( (max_l <= min_r) ? min_r - max_l + 1 : 0 ) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;

queue<int>Q;
int z[100][100], x[100][100], sum; char a;

void BFS(int col,int x1,int y1) {
	Q.push(x1 * 100 + y1);
	x[x1][y1] = col;
	int a, b;
	while (!Q.empty()) {
		a = Q.front() / 100;
		b = Q.front() % 100;
		if (z[a + 1][b] == 1 && x[a + 1][b] == 0) {
			Q.push(Q.front() + 100);
			x[a + 1][b] = col;
		}
		if (z[a - 1][b] == 1 && x[a - 1][b] == 0) {
			Q.push(Q.front() - 100);
			x[a - 1][b] = col;
		}
		if (z[a][b + 1] == 1 && x[a][b + 1] == 0) {
			Q.push(Q.front() + 1);
			x[a][b + 1] = col;
		}
		if (z[a][b - 1] == 1 && x[a][b - 1] == 0) {
			Q.push(Q.front() - 1);
			x[a][b - 1] = col;
		}
		Q.pop();
	}
}

int main() {
	while (cin >> a) {
		if (a == '1') { z[1][1] = 1; }
		sum = 0;
		for (int i = 1; i <= 12; i++) {
			for (int j = 1; j <= 12; j++) {
				if (i + j != 2) {
					cin >> a; if (a == '1') { z[i][j] = 1; }
				}
			}
		}
		for (int i = 1; i <= 12; i++) {
			for (int j = 1; j <= 12; j++) {
				if (x[i][j] == 0 && z[i][j] == 1) {
					sum++;
					BFS(sum, i, j);
				}
			}
		}
		cout << sum << endl;
		memset(x, 0, sizeof(x));
		memset(z, 0, sizeof(z));
	}
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int s=n%10;
    if(s==2 or s==4 or s==5 or s==7 or s==9)
    {
        cout<<"hon\n";
    }

    else if(s==0 or s==1 or s==6 or s==8)
    {
        cout<<"pon\n";
    }

    else
    {
        cout<<"bon\n";
    }

    exit(0);
}


Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

bool check1[26];
bool check2[26];

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

	int N; cin >> N;
	string S; cin >> S;
	int ans = 0;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < 26; j++) check1[j] = check2[j] = false;

		int num = 0;
		for (int j = 0; j < i; j++) check1[S[j] - 'a'] = true;
		for (int j = i; j < S.size(); j++) check2[S[j] - 'a'] = true;
		for (int j = 0; j < 26; j++) if (check1[j] && check2[j]) num++;
		ans = max(ans, num);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, k = na()
li = [ni() for i in range(n)]
li.sort()
ans = 100000000000000000
for i in range(n - k + 1):
    dif = li[i + k - 1] - li[i]
    ans = min(ans, dif)
    if ans == 0:
        break
print(ans)

Measured memory_bytes: 7824
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		
	 	StringTokenizer st = new StringTokenizer(bf.readLine());
	 	int n = Integer.parseInt(st.nextToken());
	 	int m = Integer.parseInt(st.nextToken());
	 	Map<Integer, Set<Integer>> graph = new HashMap<Integer, Set<Integer>>(); 	
	 	for(int j= 1;j<=n;j++){
	 		graph.put(j,  new HashSet<Integer>());
	 	}
	 	for(int j =0 ;j<m;j++){
	 		StringTokenizer st1 = new StringTokenizer(bf.readLine());
	 		int v1 = Integer.parseInt(st1.nextToken());
	 		int v2 = Integer.parseInt(st1.nextToken());
	 		graph.get(v1).add(v2);
	 		graph.get(v2).add(v1);
	 	}
	 	int max = 0;
	 	Set<Integer> seen = new HashSet<Integer>();
	 	for(int j = 1;j<=n;j++){
	 		
	 		if (!seen.contains(j)){
	 			
	 			Stack<Integer> dfs = new Stack<Integer>();
	 			dfs.add(j);
	 			Set<Integer> tempseen = new HashSet<Integer>();
	 			while(!dfs.isEmpty()){
	 				int vertex = dfs.pop();
	 				for(int child : graph.get(vertex)){
	 					if (!tempseen.contains(child))
	 						dfs.add(child);
	 				}
	 				tempseen.add(vertex);
	 				seen.add(vertex);
	 			}
	 			max = Math.max(max, tempseen.size());
	 		}
	 		
	 	}
	 	
	 	
 		out.println(max);
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 140636
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String s = scan.next();
        int out = 0;
        for(int i = 0; i < n - 2; i++){
            if(s.charAt(i) == 'A' && s.charAt(i + 1) == 'B' && s.charAt(i + 2) == 'C') out++;
        }
        System.out.println(out);
        scan.close();
    }
}

Measured memory_bytes: 27028
#include<bits/stdc++.h>
using namespace std;
int main()
{
      int l;
      cin>>l;

      double a,b,c;
      if(l % 3==0)
       {
         a=l/3.0;
         b=l/3.0;
         c=l/3.0;
       }
       else
       {
         a=l/3.0;
         b=l/3.0;
         c=l/3.0;
          a+=0.000001;
       }
        float h=a*b*c;
       std::cout<<std::setprecision(7)<<h;
}


Measured memory_bytes: 256
#include <stdio.h>

void selectionSort(int*, int);
int cnt=0;

int main()
{  
  int i;
  int A[100],N;

  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  selectionSort(A,N);
  for(i=0;i<N;i++){
    printf("%d",A[i]); 
    if(i != N-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);

  return 0;
}

void selectionSort(int *a, int n)
{
  int i,j,minj,temp;

  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(a[j] < a[minj]){
	minj = j;
      }	
    }
    if(minj != i){
    temp = a[i];
    a[i] = a[minj];
    a[minj] = temp;
    cnt++;
    }
  }
}

Measured memory_bytes: 604
from sys import stdin, setrecursionlimit
setrecursionlimit(10000000)

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()


def dfs(node, prev):
    for i in graph[node]:
        if i != prev:
            inc[i] += inc[node]
            dfs(i, node)


n, q = mi()
inc = [0 for i in range(n+1)]
graph = [[] for i in range(n+1)]
for i in range(n-1):
    a, b = mi()
    graph[a].append(b)
    graph[b].append(a)
for i in range(q):
    a, b = mi()
    inc[a] += b
dfs(1, -1)
print(*inc[1:])

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

int main(){
  int n, a, b, result=0;
  cin >> n >> a >> b;

  for(int i=0; i<10; i++){
    for(int j=0; j<10; j++){
      for(int k=0; k<10; k++){
        for(int l=0; l<10; l++){
          if((i*10*10*10+j*10*10+k*10+l)>n) break;
          if((i+j+k+l)>=a && (i+j+k+l)<=b){
            result += i*10*10*10+j*10*10+k*10+l;
          }
        }
      }
    }
  }
  if(n==10000) result += 10000;

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from functools import reduce

input = sys.stdin.readline

def gcd(a,b):
    if b>a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

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


ans = 0
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
    l[i+1] = gcd(l[i], a[i])
    r[n-i-1] = gcd(r[n-i], a[n-i-1])
for i in range(n):
    ans = max(ans, gcd(l[i], r[i+1]))
print(ans)

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

typedef long long ll;
typedef pair <int , int> pii;
typedef long double ld;

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   string s;
   cin >> n >> s;
   set <int> w , r;
   for(int i = 0 ; i < n ; i++){
      if(s[i] == 'W')
         w.insert(i);
      else
         r.insert(i);
   }
   int ans = 0;
   while(w.size() && r.size() && *w.begin() < *r.rbegin()){
      auto it = w.begin();
      int v1 = *it;
      w.erase(it);
      auto it2 = r.end();
      it2--;
      int v2 = *it2;
      r.erase(it2);
      w.insert(v2);
      r.insert(v1);
      ans++;
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 13032
#include<stdio.h>

int H;

void maxHeapify(int* A, int i){
  int left,right,largest,temp; 
  left = 2*i; 
  right = 2*i+1;
      
  if(left <= H && A[left] > A[i]) largest = left;
  else largest = i;
  
  if(right <= H && A[right] > A[largest])largest = right;

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int* A){
  int i;
  for(i=H/2;i>0;i--) maxHeapify(A, i);
}

int main(){
  int i,A[500000];
  scanf("%d",&H);
  for(i=1;i<H+1;i++) scanf("%d",&A[i]);

  buildMaxHeap(A);

  for(i=1;i<H+1;i++) printf(" %d",A[i]);
  printf("\n");
  
  return 0;
}



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

int main() {
  int n;
  cin >> n;
  
  int p, amount, max;
  max = 0;
  while(cin>>p){
    amount += p;
    
    if(max <= p){
      max = p;
    }
  }
  
  amount -= max / 2;
  
  cout << amount << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b+c>=22){
        puts("bust");
    }
    else{
        puts("win");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s;
int n, low, high, mid;
inline int ask(int x)
{
	cout << x << endl;
	fflush(stdout);
	cin >> s;
	if (s == "Vacant")exit(0);
	else return (s == "Male");
}
int main()
{
	cin >> n;
	low = 0;
	high = n-1;
	int s = ask(0);
	while (high - low >= 2){
		mid = low + high >> 1;
		int a = ask(mid);
		if (mid % 2 == low % 2){
			if (a == s)low = mid;
			else high = mid;
		}
		else{
			if (a != s)low = mid, s = a;
			else high = mid;
		}
	}
	for (int i = low; i <= high; ++i)ask(i);
	return 0;
} 

Measured memory_bytes: 880
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
const int N = 100'000;
const int M = 1'000'000'007;
int a[N + 1];
ll mem[N + 1][4];
ll C(int n, int chr) {
    ll& ans = mem[n][chr];
    if(ans == -1) {
        if(n == 0) {
            ans = chr == 0;
        } else {
            ans = (a[n] == 0 ? 3 : 1) * C(n - 1, chr) % M;
            if(chr > 0 and (a[n] == 0 or a[n] == chr)) {
                ans += C(n - 1, chr - 1);
                ans %= M;
            }
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    for(int i = 0; i < s.length(); i++) {
        a[i + 1] = s[i] == '?' ? 0 : s[i] - 'A' + 1;
    }
    memset(mem, -1, sizeof mem);
    cout << C(s.length(), 3) << endl;
    return 0;
}


Measured memory_bytes: 10192
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 3e5 + 10;
int n , m;
pii seg[N];

struct Fenwick {
  int a[N],n;
  void ini(int _n) {fill_n(a,(n=_n)+1,0);}
  void add(int x,int d) {
    for(;x<=n;x+=x&-x) a[x]+=d;
  }
  int sum(int x) {
    int r(0);
    for(;x>=1;x&=x-1) r+=a[x];
    return r;
  }
}fen;

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,n) scanf("%d%d",&seg[i].fi,&seg[i].se);
  sort(seg , seg + n , [&](pii a,pii b){return a.se-a.fi<b.se-b.fi;});
  fen.ini(m);
  int cur = 0;
  rep(i,1,m+1) {
    while(cur < n && seg[cur].se - seg[cur].fi + 1 < i) {
      fen.add(seg[cur].fi , 1);
      fen.add(seg[cur].se + 1 , -1);
      cur++;
    }
    int ans = n - cur;
    for(int j=i;j<=m;j+=i)
      ans += fen.sum(j);
    printf("%d\n",ans);
  }
  return 0;
}


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

using namespace std;
 
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
void fastscan(int &x)
 {
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    } 
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int inf = 2e18+5;
const int nax = 100010;
const int mod1 = 998244353;

signed main()
 {
   
int n,m;
  cin>>n>>m;
  int ways = n*(n-1)/2 + m*(m-1)/2;
  cout<<ways;
  
return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#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>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <random>
#include <cassert>
#include <limits>

using namespace std;

#define mp make_pair
#define pb push_back
#define repi(i, p, q) for (long i = p; i < q; i++)
#define repd(i, p, q) for (long i = p; i >= q; i--)
#define sz(x) x.size()
#define INF 2000000000
#define MOD 1000000007

typedef map<int, int> MI;
typedef pair<int, int> PI;
typedef long long int LLI;
typedef long int LI;
typedef int I;

int main()
{
    int n, i;
    cin >> n >> i;
    cout << n - i + 1;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            int ans = 0;
            int len = s.Length;
            for (int i = 0; i < len / 2; i++)
            {
                if (s[i] != s[len - i - 1])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 13140
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=5e5+4;
int n,m;
int root[N],sum[N*100],lc[N*100],rc[N*100];
int tim;
int nxt[N];
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void pushup(int rt) {
	sum[rt]=sum[lc[rt]]+sum[rc[rt]];
}
inline void build(int &rt,int l,int r) {
	rt=++tim;
	if (l==r) return ;
	int mid=l+r>>1;
	build(lc[rt],l,mid);
	build(rc[rt],mid+1,r);
}
inline void modify(int &rt,int pre,int l,int r,int pos,int val) {
	rt=++tim;
	lc[rt]=lc[pre];
	rc[rt]=rc[pre];
	sum[rt]=sum[pre]+val;
	if (l==r) return ;
	int mid=l+r>>1;
	if (pos<=mid) modify(lc[rt],lc[pre],l,mid,pos,val);
	else modify(rc[rt],rc[pre],mid+1,r,pos,val);
	pushup(rt);
}
inline int query(int rt,int l,int r,int L) {
	if (l==r) return sum[rt];
	int mid=l+r>>1;
	if (mid>=L) return sum[rc[rt]]+query(lc[rt],l,mid,L);
	else return query(rc[rt],mid+1,r,L);
}
int main() {
	//freopen("f3.txt","r",stdin);
	n=read(),m=read();
	build(root[0],1,n);
	for (register int i=1;i<=n;++i) {
		int x=read();
		if (!nxt[x]) {
			modify(root[i],root[i-1],1,n,i,1);
		} else {
			int temp;
			modify(temp,root[i-1],1,n,nxt[x],-1);
			modify(root[i],temp,1,n,i,1);
		}
		nxt[x]=i;
	}
	while (m--) {
		int x=read(),y=read();
		printf("%d\n",query(root[y],1,n,x));
	}
	return 0;
}

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

int32_t main(){
  int n;
  cin>>n;
  int a[n];
  int mx=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    mx+=a[i];
  }
  int dp[n][n];
  memset(dp,0,sizeof dp);
  for(int i=0;i<n;i++){
    dp[i][i]=a[i];
  }
  for(int s=2;s<=n;s++){
    for(int i=0;i<=(n-s);i++){
      int j=i+s-1;
      dp[i][j]=max(a[i]+min(dp[i+1][j-1],dp[i+2][j]),a[j]+min(dp[i][j-2],dp[i+1][j-1]));
    }
  }
  cout<<2*dp[0][n-1]-mx;


}


Measured memory_bytes: 70528
#pragma GCC optimize "O3"
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
template <class T> struct FenwickTree {
 
   vector<T> node;
   FenwickTree (int n) : node(n,0) {}
 
   void add(int idx, T val) {
      for (int i = idx; i < node.size(); i |= i + 1) {
         node[i] += val;
      }
   }
 
   T sum(int idx) {
      T ret = 0;
      for (int i = idx - 1; i >= 0; i = (i & (i + 1)) - 1) {
         ret += node[i];
      }
      return ret;
   }
 
};
 
int N,M;
vector< pair<int,int> > add;
vector<int> l,r;
FenwickTree<int> inst(100010);
 
int main() {
 
  cin >> N >> M;
  l.resize(N);
  r.resize(N);
 
  REP(i,N) {
    int lt,rt; cin >> lt >> rt;
    l[i] = lt;
    r[i] = rt;
    add.push_back(make_pair(rt - lt + 1, i));
  }
  
  sort(add.begin(),add.end());
 
  int j = 0;
  for(int i=1; i<=M; i++) {
    while(j < add.size()) {
      if(add[j].first >= i) break;
      int idx = add[j].second;
      inst.add(l[idx],1);
      inst.add(r[idx]+1,-1);
      j++;
    }
 
    int ans = N - j;
    for(int k=i; k<=M; k+=i) ans += inst.sum(k+1);
    cout << ans << endl;
  }
 
  return 0;
}

Measured memory_bytes: 9200
#include <stdio.h>

int expr(char **s);

int number(char **s) {
  int val = 0;
  while ('0' <= **s && **s <= '9') {
    val = val * 10 + **s - '0';
    (*s)++;
  }
  return val;
}

int factor(char **s) {
  if (**s == '(') {
    (*s)++;
    int val = expr(s);
    (*s)++;
    return val;
  }
  return number(s);
}

int term(char **s) {
  int val = factor(s);
  while (1) {
    if (**s == '*') {
      (*s)++;
      val *= factor(s);
    } else if (**s == '/') {
      (*s)++;
      val /= factor(s);
    } else {
      break;
    }
  }
  return val;
}

int expr(char **s) {
  int val = term(s);
  while (1) {
    if (**s == '+') {
      (*s)++;
      val += term(s);
    } else if (**s == '-') {
      (*s)++;
      val -= term(s);
    } else {
      break;
    }
  }
  return val;
}

int main() {
  int n;
  scanf("%d", &n);
  char s[101];
  while (n--) {
    scanf("%s", s);
    char *p = s;
    printf("%d\n", expr(&p));
  }
}

Measured memory_bytes: 1804
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n,m = map(int,input().split())
  Under = 1/(4*m)
  
  A = list(map(int,input().split()))
  SUM = sum(A)
  A = sorted(A,reverse=True)
  ANS = SUM * Under
  for i in range(m):
    if A[i] < ANS:
      print('No')
      exit()
  print('Yes')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int mat[201], n;
bool seen[201];
vector<int> con[201];

bool bpm(int u) {
	for (int i = 0; i < con[u].size(); i++) {
		int v = con[u][i];
		if (seen[v]) continue;
		seen[v] = true;
		if (mat[v] < 0 || bpm(mat[v])) {
			mat[v] = u;
			return true;
		}
	}
	return false;
}

int r[100][2], b[100][2];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &r[i][0], &r[i][1]);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &b[i][0], &b[i][1]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (r[i][0] < b[j][0] && r[i][1] < b[j][1]) {
				con[i].push_back(j + n);
				con[j + n].push_back(i);
			}
		}
	}
	memset(mat, -1, sizeof(mat));
	int res = 0;
	for (int i = 0; i < n; i++) {
		memset(seen, 0, sizeof(seen));
		if (bpm(i)) res++;
	}
	printf("%d\n", res);
	return 0;
}

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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    int i = S.size() - 1;
    while(i >= 0) {
        if (i > 3 && S.substr(i - 4, 5) == "dream") {
            i -= 5;
            continue;
        }
        if (i > 5 && S.substr(i - 6, 7) == "dreamer") {
            i -= 7;
            continue;
        }
        if (i > 3 && S.substr(i - 4, 5) == "erase") {
            i -= 5;
            continue;
        }
        if (i > 4 && S.substr(i - 5, 6) == "eraser") {
            i -= 6;
            continue;
        }
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
}

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

int	main()
{
	const static int	inf = 2e+9 + 1;
	int	V, E;
	cin >> V >> E;
	int	s, t, d;
	int	dist[100][100];
	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j)
			dist[i][j] = inf;
		dist[i][i] = 0;
	}
	for (int i = 0; i < E; ++i) {
		cin >> s >> t >> d;
		dist[s][t] = d;
	}
	for	(int k = 0; k < V; ++k) {
		for (int i = 0; i < V; ++i) {
			for (int j = 0; j < V; ++j) {
				if (dist[i][k] < inf && dist[k][j] < inf)
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	bool 	has_nega_cycle = false;
	for (int i = 0; i < V; ++i) {
		if (dist[i][i] < 0) {
			has_nega_cycle = true;
			break;
		}
	}
	if (has_nega_cycle) {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}
	for (int i = 0; i < V; ++i) {
		for (int j = 0; j < V; ++j) {
			if (dist[i][j] < inf)
				cout << dist[i][j];
			else
				cout << "INF";
			if (j < V - 1)
				cout << " ";
			else
				cout << endl;
		}
	}
	return 0;
}




Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int ans = INF;
    for(int bit = 0; bit < (1 << n); bit++) {
        int tmp = 1;
        for(int i = 0; i < n; i++) {
            if(bit & (1 << i)) {
                tmp *= 2;
            } else {
                tmp += k;
            }
        }
        chmin(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int d[10][2];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>d[i][0]>>d[i][1];
    }
    bool ok=false;
    for (int i = 0; i < n-2; i++)
    {
        
        
            if(d[i+0][0]==d[i+0][1] && d[i+1][0]==d[i+1][1] && d[i+2][0]==d[i+2][1])
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        
        
    }
    cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

const int N = 200;

int queue[N * N * N * 3];
int qs = 0, qf = 0;
int d[N][N][N];

bool Relax(int x, int y, int z, int v) {
	if(x == y && y == z) {
		d[x][y][z] = v + 1;
		return true;
	}
	if(d[x][y][z] == 0) {
		d[x][y][z] = v + 1;
		queue[qf++] = x;
		queue[qf++] = y;
		queue[qf++] = z;
	}
	return false;
}

void BFS(int x, int y, int z) {
	queue[qf++] = x;
	queue[qf++] = y;
	queue[qf++] = z;
	d[x][y][z] = 1;
	while(qs != qf) {
		x = queue[qs++];
		y = queue[qs++];
		z = queue[qs++];
		
		if(Relax(x + 2, y, z, d[x][y][z])) return;
		if(Relax(x, y + 2, z, d[x][y][z])) return;
		if(Relax(x, y, z + 2, d[x][y][z])) return;
		if(Relax(x + 1, y + 1, z, d[x][y][z])) return;
		if(Relax(x, y + 1, z + 1, d[x][y][z])) return;
		if(Relax(x + 1, y, z + 1, d[x][y][z])) return;
	}
}

int main() {
	int x, y, z;
	scanf("%d%d%d", &x, &y, &z);
	
	BFS(x, y, z);
	for(int i = 0; i <= N; i++) {
		if(d[i][i][i] != 0) {
			printf("%d\n", d[i][i][i] - 1); return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 17536
import java.util.*; 

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    char[] c = new char[n];
    String s = sc.next();
    c = s.toCharArray();
    
    char[] cln = {'R', 'G', 'B'};
    HashMap<Character, Integer> cl = new HashMap<>();
    for(int i = 0; i < 3; i++) {
      cl.put(cln[i], i);
    }
    
    int ar[][] = new int[n][3];
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 3; j++) {
        ar[i][j] = 0;
      }
    }
    for(int i = 0; i < n-1; i++) {
      for(int j = i+1; j < n; j++) {
        ar[i][cl.get(c[j])] += 1;
      }
    }
    
    long sum = 0;
    for(int i = 0; i < n-1; i++) {
      for(int j = i+1; j < n; j++) {
        if(c[i] != c[j]) {
          int id = 3;
          id -= cl.get(c[i]);
          id -= cl.get(c[j]);
          sum += ar[j][id];
          if(j+j-i < n && c[j+j-i] == cln[id]) sum -= 1;
        }
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 28468
import math
N,M=list(map(int,input().split()))
all=[list(map(int,input().split())) for k in range(N)]
cnt=0
for i in range(N-1):
  for t in range(i+1,N):
    ans=0
    for h in range(M):
      ans+=(all[i][h]-all[t][h])**2
    ans=math.sqrt(ans)
    if ans%1==0:
      cnt+=1
print(cnt)
  

Measured memory_bytes: 9224
X = int(input())

if X in range(400,600):
  print(8)
elif X in range(600,800):
  print(7)
elif X in range(800,1000):
  print(6)
elif X in range(1000,1200):
  print(5)
elif X in range(1200,1400):
  print(4)
elif X in range(1400,1600):
  print(3)
elif X in range(1600,1800):
  print(2)
else:
  print(1)

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n,d;
    cin>>n>>d;
    int ans=0;
    for(int i=0;i<n;i++){
        double x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
            ++ans;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3832
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize
    }
    let d = 1000000007;
    if (a + b) % 3 != 0 {
        println!("0");
        return;
    }
    let k = (a + b) / 3;
    let l = max(a, b) - min(a, b);
    if (k + l) % 2 != 0 || k < l {
        println!("0");
        return;
    }
    println!("{}", comb_m(k, (k + l) / 2, d));
}

fn prod_m(n: usize, m: usize, d: usize) -> usize {
    (n..m+1).fold(1, |ac, x| ac * x % d)
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}

fn comb_m(n: usize, r: usize, d: usize) -> usize {
    prod_m(n - r + 1, n, d) * inv_m(prod_m(1, r, d), d) % d
}


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

const int N = 1e5 + 5;
int n;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    vector<int> a(n+1), b(n);
    
    for (int i = 0; i < n+1; i++){
        cin >> a[i];
    }
    
    ll total = 0;
    int remain = 0;
    for (int i = 0; i < n; i++){
        cin >> b[i];
        int cancover = min(a[i], remain);
        a[i] -= cancover;
        total += cancover;
        
        int common = min(a[i], b[i]);
        
        total += common;
        remain = b[i] - common;
        
    }
    
    total += min(remain, a[n]);
    
    cout << total << "\n";
    
    
    
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<string>
#include<time.h>
#include<list>
#include<random>
#include<bitset>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;



int main() {
    ll n, y;
    cin >> n >> y;
    for (int a = 0; a <= n; ++a) {
        for (int b = 0; b <= n - a; ++b) {
            int c = n - a - b;
            if ((a * 10000) + (b * 5000) + (c * 1000) == y) {
                cout << a << " ";
                cout << b << " ";
                cout << c <<endl;
                return 0;
            }
        }
    }
    cout << -1 << " ";
    cout << -1 << " ";
    cout << -1 << endl;;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int partition(int[], int, int);

int main(){
  int A[100000], i, j, n, m;

  scanf("%d", &n);

  for(i = 0; i < n; i++) scanf("%d", &A[i]);

  m = partition(A, 0, n - 1);

  for(i = 0 ; i < n; i++){
    if(i) printf(" ");
    if(i == m) printf("[");

    printf("%d", A[i]);

    if(i == m) printf("]");
  }

  printf("\n");

  return 0;
}
  
int partition(int A[], int p, int r){
  int tmp, i, j, a;
  a = A[r];
  i = p-1;

  for(j = p; j < r; j++){
    if(A[j] <= a){
      i = i+1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;

  return i + 1;
}

Measured memory_bytes: 992
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let c: Vec<Vec<char>> = (0..3).map(|_| read::<String>().chars().collect()).collect();
    println!("{}{}{}", c[0][0], c[1][1], c[2][2]);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int a[maxn];

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

void solve() {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cnt += (a[i] & 1);
	}
	if (cnt & 1) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}

Measured memory_bytes: 1148
import heapq


n, m = map(int, input().split())
a = [-int(x) for x in input().split()]

heapq.heapify(a)

for i in range(m):
    t = -heapq.heappop(a)
    heapq.heappush(a, (t // 2) * (-1))

print(-sum(a))


Measured memory_bytes: 14180