akhauriyash/Code-Regression huggingface dataset:
module S = Set.Make(struct type t = int * int let compare = compare end)

let rec for_fold a b f v = if a >= b then v else for_fold (a+1) b f (f v a)

let () =
  Scanf.scanf "%d" @@ fun n ->
  let a = Array.init (3*n) (fun _ -> Scanf.scanf " %d" ((+) 0)) in

  let s1 = for_fold 0 n (fun s i -> s + a.(i)) 0 in
  let st1 = for_fold 0 n (fun st i -> S.add (a.(i), i) st) S.empty in

  let s2 = for_fold (2*n) (3*n) (fun s i -> s + a.(i)) 0 in
  let st2 = for_fold (2*n) (3*n) (fun st i -> S.add (a.(i), i) st) S.empty in

  let l1 = for_fold n (2*n) (fun (m,ac,st) i ->
    let st' = S.add (a.(i), i) st in
    let le, j = S.min_elt st' in
    let st'' = S.add (a.(i),i) st' |> S.remove (le, j) in
    let m' = m + (a.(i) - le) in
    (m', m'::ac, st'')) (s1, [s1], st1)
    |> fun (_,l,_) -> List.rev l
  in

  let l2 = for_fold 0 n (fun (m,ac,st) i' ->
    let i = 2*n - 1 - i' in
    let st' = S.add (a.(i), i) st in
    let ma, j = S.max_elt st' in
    let st'' = S.add (a.(i),i) st' |> S.remove (ma, j) in
    let m' = m + (a.(i) - ma) in
    (m', m'::ac, st'')) (s2, [s2], st2)
    |> fun (_,l,_) -> l
  in

  List.combine l1 l2
  |> List.fold_left (fun v (a,b) ->
      max v (a-b)) (-s1-s2)
  |> Printf.printf "%d\n"

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  string s;
  rep (i, 4) {
    char c;
    cin >> c;
    s = s + c;
  }
  sort(all(s));
  if (s == "1479") {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
N = int(input())

def make_l(n):
    l = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            l.append(i)
            if i != n // i:
                l.append(n//i)
    return l

ans = 10**10
for a in make_l(N):
    ans = min(ans , max(len(str(a)) , len(str(int(N/a)))))
print(ans)


Measured memory_bytes: 3060
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}





int main(){
    long long A, B, C;
    scanf("%lu %lu.%lu", &A, &B, &C);
    std::cout << (A * (100*B + C)) / 100 << std::endl;
    return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define rep(i,n) for(int i=0; i<n; ++i)

int main()
{
	ll X, K, D; cin >> X >> K >> D;
	X = abs(X);
	ll k = X / D;

	if (k >= K) {
		cout << X - K * D << endl;
		return 0;
	}
	if ((K - k) % 2 == 0) {
		cout << X - k * D << endl;
	}
	else {
		cout << abs(X - (k+1) * D) << endl;
	}

}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
long long f[1000005];
long long g[100005];
long long inv[1000005];	
long long n,m;
long long ks(long long n,long long m)
{
	int res=1;
	while(m)
	{
		if(m%2==1)
		{
			res=(res*n)%MOD;
		}
		n=(n*n)%MOD;
		m/=2;
	}
	return res;
} 
 
void nzc()
{
	f[0]=1;
	inv[0]=1;
	for(long long i=1;i<=1000000;i++)	
	{
		f[i]=(f[i-1]*i)%MOD;
	}
	inv[1000000]=ks(f[1000000],MOD-2);
	for(long long i=1000000-1;i>0;i--)
	{
		inv[i]=(inv[i+1]*(i+1))%MOD;
	}
}
long long c(long long n,long long m)
{
	long long res=((f[n]*inv[n-m])%MOD*inv[m])%MOD;
	return res;
}
int main()
{
	nzc();

	cin>>n>>m;
	long long p=0;
	for(int i=2;i<=sqrt(m);i++)
	{
		if(m%i==0)
		{
			g[p]=0;
			while(m%i==0)
			{
				g[p]++;
				m=m/i;
			}
			p++;
		}
	}	
	long long ans=1;
	for(int i=0;i<p;i++)
	{
		ans=(c(g[i]+n-1,n-1)*ans)%MOD;
	}
	if(m!=1) ans=(ans*n)%MOD;
	cout<<ans<<endl;
} 

Measured memory_bytes: 16640
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll a, b;
	cin >> a >> b;
	map<ll, int> cnt;
	for(ll i = 2; (i * i) <= a; i++){
		if(a % i == 0) cnt[i] = 1;
		while(a % i == 0) a /= i;
	}
	if(a > 1) cnt[a] = 1;
	int ans = 0;
	for(ll i = 2; (i * i) <= b; i++){
		if(b % i == 0) if(cnt[i]) ans++;
		while(b % i == 0) b /= i;
	}
	if(b > 0) if(cnt[b]) ans++;
	cout << ans + 1 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 384
import fractions
import sys
n, m = map(int, input().split())
a = list(map(int, input().split()))
lcm = a[0]
for i in range(1, len(a)):
    lcm = lcm*a[i]//fractions.gcd(lcm,a[i])
for i in a:
    if(lcm//i)%2 == 0:
        print(0)
        sys.exit()
lcm //= 2
print(m//lcm-(m//(lcm*2)))

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

int main(void) {
  int n, i, j, k, ans = 0;
  scanf("%d", &n);
  int f[n][3];
  rep(i, n) rep(j, 3) f[i][j] = 0;
  rep(i, 3) {
    int x;
    scanf("%d", &x);
    rep(j, x) {
      int a;
      scanf("%d", &a);
      f[a - 1][i] = 1;
    }
  }
  /*rep(i, 3) {
    rep(j, n) printf("%d ", f[j][i]);
    printf("\n");
  }*/
  rep(i, n) if((!f[i][0] && f[i][2]) || (f[i][1] && f[i][2])) ++ans;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2708
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define fo(i,b,n) for(int i=b;i<n;i++)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sll(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define endl "\n"
#define PI 3.1415926535897932384626
const int mod = 1000000007;
/*===========================================================================*/


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, sum = 0; cin>>n;
  int temp = n;
  while(temp!=0){
    sum+=temp%10;
    temp/=10;
  }

  if (n%sum == 0) cout<<"Yes";
  else cout<<"No";






  return 0;
}


Measured memory_bytes: 256
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  let left, right, largest;
  const maxHeapify = (i) => {
    left = 2 * i + 1;
    right = 2 * i + 2;
    // if (left < n && arr[left] > arr[i]) largest = left;
    // else largest = i;
    // if (right < n && arr[right] > arr[largest]) largest = right;
    largest = [left, right].filter(idx => idx < n).reduce((max, idx) => max = arr[idx] > arr[max] ? idx : max, i);
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



Measured memory_bytes: 123200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

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

typedef pair<int, int> P;

const int MAX = 100010;

struct Union_find{
  int parents[MAX];
  int rank[MAX];
  int w[MAX];
  
  void init(int n){
    rep(i, n){
      parents[i] = i;
      rank[i] = 0;
      w[i] = 0;
    }
  }
  
  P find(int x){
    if(parents[x] == x) return P(x, 0);
    else{
      P tmp = find(parents[x]);
      parents[x] = tmp.first;
      tmp.second += w[x];
      w[x] = tmp.second;
      return tmp;
    }
  }
  
  void unite(int x, int y, int diff){
    P dx = find(x);
    P dy = find(y);
    
    x = dx.first;
    y = dy.first;
    
    //cout << "x = " << x << ", y = " << y << endl;
    
    diff = (diff - dx.second) + dy.second;
    
    //cout << "diff = " << diff << endl;
    
    if(x == y) return;
    
    if(rank[x] < rank[y]){
      parents[x] = y;
      w[x] = diff;
    }
    else{
      parents[y] = x;
      w[y] = -diff;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }
  
  bool same(int x, int y){
    return find(x).first == find(y).first;
  }

};

int main(){
  int N, Q;
  while(cin >> N >> Q, N|Q){
    Union_find uf;
    uf.init(N);
    char op;
    int a, b, w;
    while(Q--){
      cin >> op;
      if(op == '!'){
	cin >> a >> b >> w;
	a--, b--;
	uf.unite(a, b, w);
      }
      else if(op == '?'){
	cin >> a >> b;
	a--, b--;
	if(uf.same(a, b)){
	  cout << uf.find(a).second - uf.find(b).second << endl;
	}
	else{
	  cout << "UNKNOWN" << endl;
	}
      }
    }
  } 
  return 0;
}

Measured memory_bytes: 2332
#include <stdio.h>
 
int main(void){
long n,m,M,sum,c,d;
m=1000000;
M=-1000000;
sum=0;
scanf("%ld",&n);
for(c=1;c<=n;c++){
scanf("%ld",&d);
if(d<m){
    m=d;
}
if(d>M){
    M=d;
}
sum=sum+d;
}
 
printf("%ld %ld %ld\n",m,M,sum);
return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if(s[0]==s[1]&&s[1]==s[2]){
        cout << "No";
    }
    else{
        cout << "Yes";
    }

    return 0;
}

Measured memory_bytes: 3564
///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include<bits/stdc++.h>
using namespace std;
#define MAX 1e6+10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__  ios_base::sync_with_stdio(false);
using ll=long long int  ;
using dl =double;
const int N = 2e5 + 10;
ll aarray[200000+10];
ll magic[101][101];
vector<ll>primes;
bool prime[1000001];
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    makefast__
    string str;
    ll i,j,n,m,k,t;
    cin>>n;
    if(n>=30)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}




Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
 	cin.tie(NULL);	
	int n;
	cin>>n;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i]!=i+1)
			{
				sum++;
			}
		}
		if(sum==2 or sum==0)
			cout<<"YES";
		else 
			cout<<"NO";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int max(int *m, int n)
{
	int max = 0;	
	for (int i = 0; i < n; i++) {
		if (m[i] > max)
			max = m[i];
	}	
	return max;
}
int main()
{
	int n, a;
	vector<int> A;
	//int *L, *R, *M;
  	cin >> n;
  	for (int i = 0; i < n; i++) {
  		cin >> a;
  		A.push_back(a);
  	}
  	 int L[n+1];
  	 int R[n+2];
  	 int M[n+1]; 
  	 L[0] = R[n+1] = 0;
  	for (int i = 0; i < n; i++) {
  		L[i+1] = __gcd(L[i], A[i]);
  	}
  	 for (int i = n; i > 0; i--) {
  		R[i] = __gcd(R[i+1], A[i]);
  	}
  	 for (int i = 0; i < n; i++) {
  		M[i] = __gcd(L[i], R[i+1]);
  	}
	cout << max(M, n);
    return 0;
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

double getArea(Polygon p){
  double res=0;
  for(int i=1;i<p.size()-1;i++)res+=cross(p[i]-p[0],p[i+1]-p[0])/2.0;
  return res;
}

int main()
{
  int n,x,y;
  Polygon p;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    p.push_back(Point(x,y));
  }
  printf("%.1f\n",getArea(p));

  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
//Int mod = 998244353;
Int INF = 1e18;
double EPS = 0.00000001;

int main() {
    Int n;
    cin >> n;
    vector<double> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    double res = (a[0] + a[1]) / 2.0;
    for (Int i = 2; i < n; i++) {
        res = (a[i] + res) / 2.0;
    }
    printf("%.12lf\n", res);
    return 0;
}

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

using namespace std;

using ll = long long;

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

    ll n, h, a = 0;
    cin >> n >> h;
    vector<ll> b(n);
    for (ll i = 0, t; i < n; ++i) {
        cin >> t >> b[i];
        a = max(a, t);
    }

    sort(b.begin(), b.end(), greater<ll>());

    ll ans = (h + a - 1) / a;
    for (ll i = 0; 0 <= h && i < n; ++i) {
        h -= b[i];

        if (h <= 0) ans = min(ans, i + 1);
        else if (0 < h) ans = min(ans, (i + 1) + (h + a - 1) / a);
    }

    cout << ans << endl;

    return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int X,Y,Z;
    cin>>X>>Y>>Z;
    cout<<(X-Z)/(Y+Z)<<endl;
    return 0;
}


Measured memory_bytes: 256
def kaijou(a):
    kai = 1
    for i in range(a):
        kai = kai * (i+1)
    return kai

def main():
    N = int(input())
    S = []
    for i in range(N):
        S.append(input())

    count = [0,0,0,0,0]
    initial = "MARCH"

    for i in range(5):
        for s in S:
            if s[0] == initial[i]:
                count[i] += 1

    k = 3
    kumiawase = 0
    for i in range(len(initial)-(k-1)):
        for j in range(i+1, len(initial)-1):
            kumiawase += count[i]*count[j]*sum(count[j+1:])

    return int(kumiawase)

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 9904
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int len = s.length();
        while (true) {
            s = s.substring(0, s.length() - 2);
            len -= 2;

            boolean ok = true;
            for (int i = 0; i < s.length() / 2; i++) {
                if (s.charAt(i) != s.charAt(i + s.length() / 2)) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                System.out.println(len);
                return;
            }
        }
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007


ll n, s[210000], a = 0, b = 0,ans = 0;
bool used[30];
int main() {
	cin >> n;
	REP(i, n)cin >> s[i];
	REP(o, INF) {
		if (b == n)break;
		bool t = false;
		REP(i, 30) if (used[i] and s[b] & (1ll << i)) t = true;
		if (t) {
			if (a == b) {
				a++;
				b++;
				ans++;
			}
			else {
				REP(i, 30) if (s[a] & (1ll << i)) used[i] = false;
				a++;
			}
		}
		else {
			REP(i, 30) if (s[b] & (1ll << i)) used[i] = true;
			b++;
			ans += b - a;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	ll s;
	scanf("%lld",&s);
	if(s==1000000000000000000)
    {
        printf("1000000000 0 0 1000000000 0 0\n");
        return 0;
    }
	ll d=1000000000LL,b=s/1000000000,c=1+b,a=s%1000000000;
	printf("0 %lld %lld 0 %lld %lld\n",a,b,c,d);
	return 0;
}


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

using namespace std;

const int INF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    int n;
    string a, b;
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++)
        cout << a[i] << b[i];
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  int colors[8];
  for(int i=0;i<8;i++)colors[i]=0;
  int over_3200=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]<400)colors[0]=1;
    else if(a[i]<800)colors[1]=1;
    else if(a[i]<1200)colors[2]=1;
    else if(a[i]<1600)colors[3]=1;
    else if(a[i]<2000)colors[4]=1;
    else if(a[i]<2400)colors[5]=1;
    else if(a[i]<2800)colors[6]=1;
    else if(a[i]<3200)colors[7]=1;
    else over_3200+=1;
  }
  int number=0;
  for(int i=0;i<8;i++){
    if(colors[i]==1)number+=1;
  }
  cout << max(number,1) << ' ' << number+over_3200 << endl;
  return 0;
}


Measured memory_bytes: 256
from math import sqrt


def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    for i in range(3, int(sqrt(x)) + 1, 2):
        if x % i == 0:
            return False

    return True


if __name__ == '__main__':
    N = int(input())
    prime_numbers = []
    for x in range(11, 55555 + 1, 10):
        if is_prime(x):
            prime_numbers.append(x)

        if len(prime_numbers) == N:
            break

    print(" ".join(map(str, prime_numbers)))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int[] l = new int[N];
    for (int i = 0; i < N; i++) l[i] = scanner.nextInt();

    int min = Integer.MAX_VALUE;
    for (int i = 0; i < 1 << N * 2; i++) {
      int[] assign = iToAssign(i, N);
      int[] cand = new int[3];
      int unused = 0;
      for (int j = 0; j < N; j++) {
        if (assign[j] < 3) cand[assign[j]] += l[j];
        else unused++;
      }
      if (cand[0] == 0 || cand[1] == 0 || cand[2] == 0) continue;
      int cost = Math.abs(a - cand[0]) + Math.abs(b - cand[1]) + Math.abs(c - cand[2]);
      cost += (N - unused - 3) * 10;
      min = Math.min(min, cost);
    }
    System.out.println(min);
  }

  private static int[] iToAssign(int num, int N) {
    int[] res = new int[N];
    int i = 0;
    while (num > 0) {
      res[i++] = num % 4;
      num /= 4;
    }
    return res;
  }
}


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

N = int(input())
P = [None] + [int(x) for x in input().split()]
p_to_i = [None] * (N+1)
for i,x in enumerate(P[1:],1):
    p_to_i[x] = i

# 大きい数から挿入していく
# 左隣にあるインデックスを取得できるようにしておく
# そのために、[1,i]内で書き込んだ数の個数を獲得できるBITを持つ

# BITは一番最後の1ビットの位置が重要なので0ではなく1始まり。そのためNまでループする
def BIT_add(i):
    while i <= N:
        tree[i] += 1
        i += i&(-i)

def BIT_sum(i):
    s = 0
    while i:
        s += tree[i]
        i -= i&(-i)
    return s

def BIT_search(x):
    # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
    # i = 0
    # s = 0
    # step = 1<<(N.bit_length()-1)
    # while step:
    #     if i+step <= N and s + tree[i+step] < x:
    #         i += step
    #         s += tree[i]
    #     step >>= 1
    # return i+1
    left = 0
    right = N
    while right - left > 1:
        mid = (left + right) // 2
        if BIT_sum(mid) >= x:
            right = mid
        else:
            left = mid
    return right

tree = [0] * (N+1)
answer = 0
for x in range(N,0,-1):
    c = p_to_i[x]
    L = BIT_sum(c) # 左にある既に書き込んだ数の個数
    BIT_add(c)
    R = N-x-L # 右にある既に書き込んだ数の個数
    a = BIT_search(L-1) if L >= 2 else 0
    b = BIT_search(L) if L >= 1 else 0
    d = BIT_search(L+2) if R >= 1 else N+1
    e = BIT_search(L+3) if R >= 2 else N+1
    coef = 0
    if b != 0:
        # [b,c]を含むようにする。(a,b) と(c,d)が自由
        coef += (b-a) * (d-c)
    if d != 0:
        # [c,d]を含むようにする。
        coef += (e-d) * (c-b)
    answer += x * coef
print(answer)





Measured memory_bytes: 92052
n = int(input())
s = input()
count = 0
f0,f1 = -1,-1
for ans in range(1000):
  f0,f1 = -1,-1
  ans_str = "{0:03d}".format(ans)
  for i in range(n):
    if s[i] == ans_str[0]:
      f0 = i
      break
  if f0 == -1:
    continue
  for j in range(f0+1,n):
    if s[j] == ans_str[1]:
      f1 = j
      break
  if f1 == -1:
    continue
  for k in range(f1+1,n):
    if s[k] == ans_str[2]:
      count += 1
      break

print(count)

Measured memory_bytes: 42972
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int c[105],t[105];
int main(void){
    int n,T; cin>>n>>T;
    int K=10000000;
    for(int i=0;i<n;i++){
        cin>>c[i]>>t[i];
        if(t[i]<=T&&c[i]<=K){
            K=c[i];
        }
    }
    if(K==10000000){
        cout<<"TLE"<<endl;
    }else{
        cout<<K<<endl;
    }
    
}


Measured memory_bytes: 256
while True:
    n,w,d=map(int,raw_input().split())
    if n==w==d==0:break
    D=[(w,d)]
    for i in range(n):
        p,s=map(int,raw_input().split())
        p-=1
        s%=D[p][0]+D[p][1]
        if s>D[p][0]:
            s-=D[p][0]
            D.append((D[p][0],s))
            D.append((D[p][0],D[p][1]-s))
        else:
            D.append((D[p][0]-s,D[p][1]))
            D.append((s,D[p][1]))
        del D[p]
        p=len(D)-1
        if D[p][0]*D[p][1]<D[p-1][0]*D[p-1][1]:
            D[p],D[p-1]=D[p-1],D[p]

    D=[i*j for i,j in D]
    D.sort()
    print " ".join(map(str,D))

Measured memory_bytes: 4268
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
  long n, k;
  cin >> n >> k;
  long a[n];
  long ai;
  for(int i = 0;i <n;++i){
    cin >> ai;
    a[i] = ai-1;
  }
  vector<long> o(n,-1);
  set<long> s;
  size_t ls;
  o[0] = 0;
  s.insert(0);
  for(int i = 1; i < n;++i){
    ls = s.size();
    s.insert(a[o[i-1]]);
    if(s.size() == ls) break;
    o[i] = a[o[i-1]];
  }
  auto itr = std::find(o.begin(), o.end(), a[o[ls-1]]);
  long roop_f = itr - o.begin();
  long roop_l = (long)ls-1;
  long count;
  if(k < roop_f) count = k;
  else{
    count = (k - roop_f)%(roop_l -roop_f+1)+roop_f;
  }

  cout << o[count] + 1 << endl;
  
}


Measured memory_bytes: 15400
#include <stdio.h>
int main(){
  int N,i,kousuu,cnt,j,n;
  while(1){
    cnt=0;
    scanf("%d",&N);
    if(N==0){
      break;
    }
    for(i=1;i<=N;i++){
      for(j=i;j<=N;j++){
        kousuu=j-i+1;
        n=kousuu;
        if(n>=2 && (i*n+j*n)/2 == N){
          cnt++;
    }
      }
    }
  printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 1028
ls = list(map(int,input().split()))

p =  [ls[2]-ls[0],ls[3]-ls[1]]

b = [-p[1],p[0]]
c = [-b[1],b[0]]

p3 = [ls[2]+b[0],ls[3]+b[1]]
p4 = [p3[0]+c[0],p3[1]+c[1]]
print(p3[0],p3[1],p4[0],p4[1])

Measured memory_bytes: 38384
N = gets.chomp.to_i
S = gets.chomp

IDX = {"R"=>[], "G"=>[], "B"=>[]}

0.upto(N-1) do |i|
  IDX[S[i]] << i
end

ng = Hash.new(0)
IDX["R"].each do |i|
  IDX["G"].each do |j|
    a, b = [i, j].sort
    gap = b - a
    ng[(a+b)/2] += 1 if gap.even?
    ng[a-gap] += 1
    ng[b+gap] += 1
  end
end

ans = IDX["R"].size * IDX["G"].size * IDX["B"].size
IDX["B"].each do |k|
  ans -= ng[k]
end
puts ans


Measured memory_bytes: 15024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        boolean flag = true;
        int count = 0;
        while(flag){
            flag = false;
            for(int j = n-1; j >= 1; j--){
                if(a[j] < a[j-1]){
                    int x = a[j];
                    a[j] = a[j-1];
                    a[j-1] = x;
                    flag = true;
                    count++;
                }
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            sb.append(a[i]).append(" ");
        }
        sb.deleteCharAt(sb.length()-1);
        sb.append(System.lineSeparator());
        sb.append(count);
        
        System.out.println(sb);
    }
}


Measured memory_bytes: 26212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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(a>b){a=b;return 1;}return 0;}
using namespace std;
using P = pair<int, int>;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;cin>>n>>m;
	vector<int> a(n);
	rep(i, n){cin>>a[i];}
	sort(a.begin(), a.end());
	vector<P> p;
	rep(i, m){
		int b,c;cin>>b>>c;
		p.push_back(P(c, b));
	}
	sort(p.begin(), p.end(), greater<P>());
	int pos = 0;
	rep(i, m){
		rep(j, p[i].second){
			if(pos == n){break;}
			if(!chmax(a[pos], p[i].first)){
				break;
			}
			pos++;
			
		}
	}
	ll ans = 0;
	rep(i, n){
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1784
n = int(input())
a = []
b = []
for i in range(n):
  x, y = map(int, input().split())
  a.append(x)
  b.append(y)
ans = 0
a = a[::-1]
b = b[::-1]
for i in range(n):
  if (a[i] + ans) % b[i] == 0:
    next
  else:
    ans += b[i] - ((a[i]+ ans) % b[i])
print(ans)

Measured memory_bytes: 17712
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
   string a,b;
   cin>>a>>b;
   ll cc=0;
   if(a[0]==b[0])cc++;
   if(a[1]==b[1])cc++;
   if(a[2]==b[2])cc++;cout<<cc<<endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<bool> ok(200002);
    ok.at(0) = true;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (ok.at(a - 1)) {
            ok.at(a) = true;
        }
    }

    for (int i = 0; i < 200002; i++) {
        if (!ok.at(i)) {
            if (i == 1) {
                cout << -1 << endl;
                return 0;
            }
            
            cout << n - i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

n, m = map(int, input().split())
par = [i for i in range(n + 1)]
rank = [0] * (n + 1)
size = [1] * (n + 1)

def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def same(x, y):
    return find(x) == find(y)


def unite(x, y):
    x = find(x)
    y = find(y)
    if x != y:
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


ans = [0] * m
ans[m - 1] = n * (n-1) // 2

b = [list(map(int, input().split())) for _ in range(m)]

for i in range(m - 1, 0, -1):
    j, k = b[i]
    if same(j, k):
        ans[i - 1] = ans[i]
    else:
        ans[i - 1] = ans[i] - (size[find(j)] * size[find(k)])
    unite(j, k)

for an in ans:
    print(an)


Measured memory_bytes: 106272
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int N, Q;
  while(cin >> N >> Q) {
    if(N == 0) return 0;
    vector<int> data(111, 0);
    FOR(i,0,N) {
      int M;cin>>M;
      FOR(j,0,M) {
        int in;
        cin >> in;
        data[in]++;
      }
    }
    int ans = 0;
    int mx = 0;
    FOR(i,1,101) {
      if(data[i] >= Q) {
        if(data[i] > mx) {
          mx = data[i];
          ans = i;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3032
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector< vector<int> > g_matrix;
    g_matrix = vector< vector<int> >(n, vector<int>(n, 0));
    
    for(int i = 0; i < n; i++){
        int u, k;
        scanf("%d %d", &u, &k);
        u--;
        for(int j = 0; j < k; j++){
            int v;
            scanf("%d", &v);
            v--;
            g_matrix[u][v] = 1;
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n - 1; j++){
            printf("%d ", g_matrix[i][j]);
        }
        printf("%d", g_matrix[i][n - 1]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3260
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main () {
  int n,cnt = 0;
  cin >> n;
  string s = to_string(n);
  for (int i = 1; i <= n; i++){
    s = to_string(i);
    if (s.size() % 2 == 1){
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 3632
class SWAG():
    __slots__='unit','f','fold_r','fold_l','data_r','data_l'
    def __init__(self,unit,f,data):
        self.unit=unit
        self.f=f
        self.construct(data)
    def construct(self,data):
        self.fold_r=[self.unit]
        self.fold_l=[self.unit]
        self.data_r=[]
        self.data_l=[]
        sep=0--len(data)//2
        for t in data[sep:]:
            self.append(t)
        for t in data[sep-1::-1]:
            self.appendleft(t)
    def append(self,x):
        self.fold_r+=self.f(self.fold_r[-1],x),
        self.data_r+=x,
    def appendleft(self,x):
        self.fold_l+=self.f(self.fold_l[-1],x),
        self.data_l+=x,
    def pop(self):
        if not self.data_r:
            self.construct(self.data_l[::-1])
        if not self.data_r:
            return self.popleft()
        self.fold_r.pop()
        return self.data_r.pop()
    def popleft(self):
        if not self.data_l:
            self.construct(self.data_r)
        if not self.data_l:
            return False
        self.fold_l.pop()
        return self.data_l.pop()
    def fold_all(self):
        return self.f(self.fold_r[-1],self.fold_l[-1])
def main():
    from fractions import gcd
    n,*a=map(int,open(0).read().split())
    l,r=SWAG(0,gcd,[]),SWAG(0,gcd,a[1:])
    m=r.fold_all()
    for i in range(n-1):
        l.append(a[i])
        r.popleft()
        m=max(m,gcd(l.fold_all(),r.fold_all()))
    print(m)
main()

Measured memory_bytes: 16144
# -*- coding: utf-8 -*-
import sys

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	maps = [0] * (len(A))
	for i, val in enumerate(A):
		maps[i] = maps[i-1] + val
		
	maps.append(0)
	counts = {}
	for i, val in enumerate(maps):
		if val in counts:
			counts[val] += 1
		else:
			counts[val] = 1
	
	ans = 0
	#print(maps)
	for key, val in counts.items():
		if val == 1:
			continue
		for i in range(val-1, 0, -1):
			ans += i
	
	print(ans)
	
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 42204
#include <iostream>
#include <stack>
#include <vector>
#include <string>
using namespace std;

int ctoi(const char c)
{
    if ('0' <= c && c <= '9')
        return (c - '0');
    return -1;
}

int main()
{
    char a[4];
    cin >> a;

    int ans = 0;
    bool isFinished = false;

    for (int i = 0; i < 8; i++)
    {
        if (isFinished)
        {
            break;
        }

        ans = ctoi(a[0]);
        for (int j = 0; j < 3; j++)
        {
            if (i >> j & 1)
            {
                ans += ctoi(a[j + 1]);
            }
            else
            {
                ans -= ctoi(a[j + 1]);
            }
        }

        if (ans == 7)
        {
            isFinished = true;
            cout << a[0] << flush;
            for (int k = 0; k < 3; k++)
            {
                if (i >> k & 1)
                {
                    cout << '+' << flush;
                }
                else
                {
                    cout << '-' << flush;
                }
                cout << a[k+1] << flush;
            }
            cout << "=7" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
h,n=map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
dp = [0]*(h+1)
for i in range(h+1):
    dp[i]=1000000000
dp[h]=0
for i in range(h+1):
    now=h-i
    if dp[now]==1e9:
        continue
    for j in range(n):
        now2=max(now-a[j],0)
        dp[now2]=min(dp[now2],(dp[now]+b[j]))
print(dp[0])

Measured memory_bytes: 41708
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int k;
    cin >> k;
    int arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
        int m = 1e9 + 7;
    int dp[n + 1][k + 1];
    int ans = 0;
    memset(dp, 0, sizeof(dp));
   for(int i=0;i<=arr[0];i++)
    dp[0][i] = 1;
    for (int i = 1; i < n; i++)
    {  
         int pre[k+1] = {0,};
         pre[0] = dp[i-1][0];
    for(int j = 1;j<=k;j++)
        pre[j] = (pre[j-1] + dp[i-1][j]) % m;
        for (int j = 0; j <= k; j++)
        {   if(j > arr[i])
            dp[i][j] = (pre[j] + m - pre[j-arr[i] - 1])%m;
            else
            {
                dp[i][j] = pre[j];
            }
            
        }
    }
    cout << dp[n-1][k] << endl;
}

Measured memory_bytes: 43268
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli a=0ll,v=0ll,b=0ll,w=0ll,t=0ll;
    cin>>a>>v;
    cin>>b>>w;
    cin>>t;
    if(a==b)
    {
    	cout<<"YES"<<endl;
    	return 0;
    }
    if(v<=w)
    {
    	cout<<"NO"<<endl;
    	return 0;
    }
    if(a<b)
    {
    	cout<<((a+1ll*v*t>=b+1ll*w*t)?"YES":"NO");
    }
    else
    {
    	cout<<((a-1ll*v*t<=b-1ll*w*t)?"YES":"NO");
    }
    cout<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int a=0,b=200100;
int N,M;
int l[100100],r[100100];
int main(){
	cin >> N >> M;
	a=1;b=N;
	for(int i=0;i<M;i++){
		cin >> l[i] >> r[i];
		a = max(a,l[i]);
		b = min(b,r[i]);
	}
	cout << max(0,b-a+1) << endl;
	return 0;
}

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

using namespace std;

int main(){
	string str;
	cin >> str;
	vector<int> ans;
	int c = 0;
	for(auto x: str){
		if(x == 'R')c++;	
		if(x == 'S'){
			ans.push_back(c);
			c = 0;
		}
	}
	ans.push_back(c);
	cout << *max_element(ans.begin(), ans.end());
}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
ll sumDigit(ll x){
	ll ret = 0;
	while(true){
		if (x == 0) return ret;
		ret++;
		x = x / 10;
	}
	return 0;
}

int main(){
    int N,M;
    SCD2(N,M);

    VVI vec1;
    VVI vec2;
    static int index[100000] = {};

    REP(i,M){
        int P,Y; SCD2(P,Y);
        VI PYI = {P,Y,i+1};
        vec1.PB(PYI);
    }

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

    REP(i,M){
        int P = vec1[i][0];
        int Y = vec1[i][1];
        int l = vec1[i][2];

        index[P]++;

        VI IPX = {l,P,index[P]};

        vec2.PB(IPX);
    }

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

    REP(i,M){
        REP(j,6-sumDigit(vec2[i][1])){
            cout << "0";
        }
        cout << vec2[i][1];

        REP(j,6-sumDigit(vec2[i][2])){
            cout << "0";
        }
        cout << vec2[i][2] << "\n";

        //cout << vec2[i][1] << " " <<  vec2[i][2] << "\n";
    }
}

Measured memory_bytes: 14000
from itertools import product
n, m = (int(x) for x in input().split())
s = [[int(x) for x in input().split()[1:]] for _ in range(m)]
p = [int(x) for x in input().split()]
ans = 0
for combo in product([0, 1], repeat=n):
    for i, bulb in enumerate(s):
        on = 0
        for switch in bulb:
	        if (combo[switch-1] == 1):
                    on += 1
        if (on % 2) != p[i]:
            break
    else:
      ans += 1
print(ans)


Measured memory_bytes: 3064
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
struct Edge {
    int from;
    int to;
};
 
vector<vector<Edge>> graph;
vector<int> top_ordered;
vector<bool> visited;
 
void dfs(int now) {
    for (Edge e : graph[now]) {
        if (e.from == now && !visited[e.to]) {
            dfs(e.to);
        }
    }
    visited[now] = true;
    top_ordered.push_back(now);
}
 
int main() {
    int N, M;
    cin >> N >> M;
    graph.resize(N);
    for (int i = 0; i < N-1+M; i++) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(Edge{A, B});
        graph[B].push_back(Edge{A, B});
    }
    int root = 0;
    while (true) {
        int bak_root = root;
        for (Edge e : graph[root]) {
            if (e.to == root) {
                root = e.from;
                break;
            }
        }
        if (bak_root == root) {
            break;
        }
    }
    visited.resize(N, false);
    dfs(root);
    reverse(top_ordered.begin(), top_ordered.end());
    vector<int> top_order(N);
    for (int i = 0; i < N; i++) {
        top_order[top_ordered[i]] = i;
    }
    for (int i = 0; i < N; i++) {
    	if (i == root) {
    		cout << 0 << endl;
    	} else {
    		int max = numeric_limits<int>::min();
    		int par_idx = -1;
    		for (Edge e : graph[i]) {
    			if (e.to == i && top_order[e.from] > max) {
    				par_idx = e.from;
    				max = top_order[e.from];
    			}
    		}
    		cout << par_idx + 1 << endl;
    	}
    }
}
 

Measured memory_bytes: 11896
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;cin>>s;
    if(s.size()==1){
        cout<<"-1"<<" "<<"-1"<<endl;
        return 0;
    }
    if(s.size()==2){
        if(s[0]==s[1]){
            cout<<"1"<<" "<<"2"<<endl;
            return 0;
        }
        else{
            cout<<"-1"<<" "<<"-1"<<endl;
            return 0;
        }
    }
    for(int i=2;i<s.size();i++){
        if(s[i]==s[i-1]){
            cout<<i<<" "<<i+1<<endl;
            return 0;
        }
        else if(s[i]==s[i-2]){
            cout<<i-1<<" "<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<" "<<"-1"<<endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  if(s == "AAA"){
    cout << "No" << endl;
  }else if(s == "BBB"){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    ll n, m, v, p; cin>>n>>m>>v>>p;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

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

    // (ng, ok]
    int ng = -1, ok = n - 1;
    while(ok - ng > 1){
        int mid = (ng + ok) / 2;

        ll base = a[mid] + m;

        if((n - p) <= mid){
            ok = mid;
            continue;
        }

        if(base < a[(n - p)]){
            ng = mid;
            continue;
        }

        // 上位 P - 1 問、a[mid] より低い mid 問、a[mid] に M 人が 1 票入れる
        ll rest = v - (p - 1) - mid - 1;

        ll sum = 0;
        for(int i=0; i<n; i++){
            if(mid < i && i <= n - p && a[i] < base){
                sum += min(base - a[i], m);
            }
        }

        if(sum < rest * m) ng = mid;
        else ok = mid;
    }

    cout << (n - ok) << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

    cout << 2*r*3.14159265358979323846 << endl;
}

Measured memory_bytes: 3784